WEBVTT

00:00.480 --> 00:04.110
Hi everybody welcome to the final part of the show a little deeper into the Windows operating system.

00:04.110 --> 00:13.690
So we're going to be going over P E files and DL ls in this video so was a p file P file or portable

00:13.690 --> 00:18.880
executable is a format that Windows uses for an executable object.

00:18.880 --> 00:26.200
Now an executable object can be in most cases it's a dot e XY and in the next slide we'll talk about

00:26.210 --> 00:36.490
deals in a deal is a p e file as well p p e file format is what this is is a data structure that contains

00:36.490 --> 00:42.050
the necessary information for the windows w loader to use the rapt executable code.

00:42.160 --> 00:49.900
So p file is a wrapped executable application which will make more sense when we go over the structure

00:49.900 --> 00:51.980
of it now.

00:51.980 --> 00:55.460
DL It is a p e file as well as we just talked about so.

00:55.490 --> 00:58.760
DL L stands for a dynamically linked library file.

00:58.760 --> 01:04.620
It is a module of compiled code that can be used and referenced to perform specific tasks.

01:04.790 --> 01:11.720
So normally these DL ls will have functions which we have already actually looked at when we were looking

01:11.720 --> 01:13.880
at the Windows API calls.

01:13.880 --> 01:22.910
What we were actually seeing when we saw kernel 32 that is a DL out so the shell exact w shell execute

01:22.910 --> 01:31.740
W which is one of the API calls we looked at in previous videos is nothing more than a specific task

01:31.920 --> 01:36.530
or a function that the DL provided to the application.

01:37.680 --> 01:47.490
Now if we do a quick high level look of the P structure now this is not a fully as deep as it can go

01:48.570 --> 01:49.890
structure.

01:49.890 --> 01:57.090
This is more of a higher level so you can understand the generic sections of it and what the main flow

01:57.090 --> 01:59.250
of the structure is.

01:59.250 --> 02:08.130
So we're starting off with the dos MSE header followed by the DOS stub then the p header where the actual

02:08.130 --> 02:14.780
P file begins then we're going over the section table that contains the data directories and then the

02:14.780 --> 02:16.840
sections which contains the rest of the file.

02:16.970 --> 02:20.010
So we're gonna go over each step of these right now.

02:20.720 --> 02:29.470
So the DOS M.C. header it is the first 64 bytes of each P file and it contains the code 50 for a D in

02:29.470 --> 02:35.930
hex which equates to the letters MSE in ASCII or normal text.

02:35.950 --> 02:37.620
Now this is done for.

02:37.960 --> 02:41.600
So that dos can identify it as an executable.

02:41.620 --> 02:47.950
Now DOS is a disk operating system which is the underlined OS for Windows.

02:47.950 --> 02:52.720
So back in the day it used to just be dos there wasn't windows.

02:52.720 --> 02:56.470
So this is still the core of how Windows runs.

02:56.500 --> 03:02.890
And for it to identify an executable it's looking for that 50 for 80 in hex which again translates to

03:02.890 --> 03:04.160
empty.

03:04.270 --> 03:10.200
Now the DOS stub this is pre pretty short it contains code to be able to print the.

03:10.630 --> 03:12.280
This program cannot be run endorsement.

03:12.280 --> 03:17.770
So if you have an application that was not meant to run as a DOS application or on the command line

03:18.820 --> 03:26.880
it will it'll stop right there and then kick this out and if it is a DOS application meant for the command

03:26.880 --> 03:32.930
line then obviously this part would not run it will still be there but it won't run now the P E header

03:33.350 --> 03:38.810
so this contains fields that will tell the Windows OS loader with the rest of the files going to look

03:38.810 --> 03:45.080
like because the rest of the file passes point can change based on its size and a few other factors

03:45.090 --> 03:47.000
so the first thing we have is a signature.

03:47.300 --> 03:55.940
So a signature for a p file is p dot e followed by two zeros which in hex is going to be no bytes then

03:55.940 --> 03:57.200
it's something called machine.

03:57.230 --> 04:02.810
So this identifies the type of system that it was developed for us or at least compiled for.

04:02.840 --> 04:08.940
So this could be Intel Hamdi etc. the number of sections.

04:09.050 --> 04:16.190
Now this is going to tell us the size of the section's table which follows this particular header which

04:16.190 --> 04:21.320
is important because then it needs to be able to know where the P header stops because there are a few

04:21.320 --> 04:25.320
other options on the P header that I'm not listing here.

04:25.370 --> 04:31.010
However feel free to look up the P header in more detail or the p file structure again in more detail

04:31.820 --> 04:37.840
if you want a more deep dive on bite by bite bit by bit type analysis of it.

04:38.420 --> 04:43.730
But for now just note that this keeps the track of the number of sections so it can know where the end

04:43.730 --> 04:51.310
of this header is so the next part which is data directories which is if we look back up is our section

04:51.310 --> 04:55.860
table so our data directories contains a few things.

04:55.990 --> 05:04.720
It contains an export table import table resource table and probably 10 or 15 other different types

05:04.720 --> 05:09.910
of tables and resource allocations and other things like that.

05:09.970 --> 05:11.250
So the export table.

05:11.490 --> 05:17.850
So what this happens is deal ls are imported from the import table and loaded.

05:18.130 --> 05:21.870
Then once the Windows OS loader grabs a hold of the addresses so on.

05:21.920 --> 05:25.930
So as we show the shell execute w that is a function.

05:25.930 --> 05:33.100
So the OS sort of grabs the address of that function in memory where the DL ls happened to be and then

05:33.670 --> 05:36.640
adds it to the export table to be patched in.

05:36.670 --> 05:38.760
So it's patched into the main application.

05:38.830 --> 05:47.500
This is done during compile time compiling linking which we have an entire section over how programs

05:47.620 --> 05:51.070
are compiled and linked and how all this stuff happens.

05:51.130 --> 05:52.540
So take this as you will.

05:52.780 --> 05:59.500
It's just know that those those functions that we were looking at get patched into the application so

05:59.500 --> 06:00.670
it can be more of a standalone.

06:01.330 --> 06:07.840
Now import table which shows the deals in libraries that will be imported based on what the application

06:07.840 --> 06:08.860
needs.

06:08.860 --> 06:14.410
So this is when you're writing code and you import another module.

06:14.560 --> 06:16.870
That's again what you're going to see here.

06:16.870 --> 06:29.950
Now the resource table is a table of icons and images could be Cursor cursor images any type of image

06:29.950 --> 06:38.060
or icon is going to end up in this resource table so the next is these sections which is the main part

06:38.060 --> 06:43.460
of the P file which is essentially all of the rest of the actual file that you're trying to use so all

06:43.460 --> 06:51.840
the code and everything so it's splitting the multiple sections dot text dot yes our data data our source

06:52.110 --> 06:53.890
e data and data.

06:53.970 --> 07:00.540
Now we're gonna hit each one of these coming up now so the DOT text section this is where all of the

07:00.540 --> 07:01.820
code lids.

07:01.830 --> 07:08.090
So the code for the application all the compiled code for how the application actually functions.

07:08.100 --> 07:12.110
Now this is also commonly referred to at the DOT code section as well.

07:12.120 --> 07:15.600
So if you see Dot tech stock code it's gonna be generally the same thing.

07:15.660 --> 07:20.700
Now the entry point of the application which is in the P E header again what you will see.

07:20.720 --> 07:27.770
An example this in a little bit but the entry points are where the application starts X code execution

07:28.370 --> 07:31.590
is also here next section is dot B.

07:31.590 --> 07:31.840
Yes.

07:31.860 --> 07:35.940
So this is for on initialized data the application.

07:35.940 --> 07:41.110
So for anybody who's familiar with any sort of programming when you initialize a variable such as in

07:41.130 --> 07:47.910
i in this example we don't provided a value so there's no equal sign with a with a number or if this

07:47.910 --> 07:53.000
is a string it's not it doesn't have a string attached to it depending on the language it might append

07:53.000 --> 07:55.130
a string an empty string by default.

07:55.560 --> 08:01.260
But assuming we're not initializing any data to a variable it ends up in here.

08:01.470 --> 08:04.170
And this would show up in the BSA section.

08:04.170 --> 08:08.870
Now our data contains only the read only data.

08:08.880 --> 08:11.370
So this is normally strings or constants.

08:11.370 --> 08:15.960
Now strings are just standard text standard asking unicode.

08:16.020 --> 08:22.420
However constants can be integers floats can be anything as long as the.

08:22.830 --> 08:30.170
It doesn't change which is why it's read only the DOT data section is the opposite of our data.

08:30.200 --> 08:37.010
So when you have an application that you've done a let's say int i is equal to one or two I's equal

08:37.010 --> 08:43.370
to 20 since it's gotten initialized variable or a value of twenty or whatever it might be.

08:43.430 --> 08:44.750
It ends up in this dot data.

08:44.780 --> 08:47.180
So this is for you programming folks out there.

08:47.180 --> 08:53.660
This is the static the global and the local scope variables all end up in here as long as they are initialized

08:55.230 --> 08:59.120
so the our source this contains the resource data.

08:59.130 --> 09:00.470
So the actual images.

09:00.480 --> 09:05.390
So the resource table contained addresses and names for the images and icons.

09:05.400 --> 09:08.650
This is where the data of the actual image is stored.

09:10.520 --> 09:12.370
So we have e data.

09:12.370 --> 09:17.810
I'd add it contains the export table information that we talked about in the previous slide.

09:17.860 --> 09:22.300
This is not always present depending on how the application was designed and what its functions are

09:22.660 --> 09:31.000
but know that the the E table or the the export table contains the resource the names and the addresses.

09:31.090 --> 09:36.940
This is where it contains the actual data and this is data.

09:36.960 --> 09:37.920
This is the opposite.

09:37.920 --> 09:41.850
So this handles the import table again names and addresses of functions.

09:42.300 --> 09:52.590
And what we're gonna do now is go over and take a look at the an executable PBX executable so we're

09:52.590 --> 09:54.730
using something called P explore.

09:54.750 --> 10:03.210
Now this has a hundred and eighty or one hundred and thirty day trial available for anybody who wants

10:03.210 --> 10:03.910
to use it.

10:04.050 --> 10:09.210
Again if you run out of that and you're still testing blow out the virtual machine rebuild it and then

10:09.210 --> 10:15.810
you can reinstall it without having to deal with any license only for if you're testing purposes anyway

10:16.650 --> 10:20.670
don't use it in the business or for professional use that violates licenses.

10:20.670 --> 10:25.060
So again this is linked the link to download it is above this video.

10:25.450 --> 10:26.900
So we're gonna go ahead and open this up.

10:27.850 --> 10:29.450
Oh this is a 30 day valuation.

10:29.460 --> 10:33.270
Sorry about that bigger.

10:33.370 --> 10:39.280
So we're gonna go ahead and open the calc dot XY so this is just standard one that comes in.

10:40.360 --> 10:48.330
So what we're looking at here is the P E header so we can see the machine where we talked about up here

10:49.740 --> 10:52.170
under P here or I don't know if you can you can see that.

10:52.170 --> 11:02.440
So we see machine a number of sections so we've got a number of sections which again is in hex and then

11:02.440 --> 11:05.980
we've got the machine which is ice 386.

11:06.190 --> 11:10.810
And what's also interesting to keep a note of is the time date stamp.

11:10.810 --> 11:18.730
So when it was compiled and then we have our magic number for P E instead of 0 0 we have 32 here which

11:18.730 --> 11:20.390
is fine.

11:20.530 --> 11:24.520
The next thing we're going to do is pull this back up so we can reference this.

11:24.550 --> 11:26.960
So we want to do the data directories.

11:26.960 --> 11:27.720
Right.

11:27.790 --> 11:32.800
So we want to take a look and see what the data directories hold so we can see here we have our export

11:32.800 --> 11:36.160
table import table so in this particular case there's no export table.

11:36.160 --> 11:37.320
There is an import.

11:37.450 --> 11:40.220
We do have resources which will go over in a second.

11:40.300 --> 11:42.900
A few of these others we're not going to go into.

11:43.030 --> 11:47.930
But feel free to look them up if you if you want some extra learning.

11:48.020 --> 11:54.730
They're always good to have a general idea of how how each table works especially if you plan on doing

11:55.270 --> 12:01.470
malware reversing or anything along those lines this is going to be very good information to know.

12:01.750 --> 12:06.940
The next is we have the sections but before we do that I want to take one quick short and go over the

12:06.940 --> 12:07.580
import.

12:07.900 --> 12:13.390
So I don't know if you guys know but I think this looks familiar from based on a previous video we can

12:13.390 --> 12:13.660
see.

12:13.660 --> 12:15.960
Shell 32 shell exactly.

12:16.030 --> 12:17.270
Execute W.

12:17.530 --> 12:18.850
So this is keeping.

12:18.880 --> 12:22.640
So this is exactly what we were looking at before.

12:22.690 --> 12:24.190
So that's what we're looking at before.

12:24.190 --> 12:26.550
Again like I said is the import table.

12:26.640 --> 12:28.850
So that's that's kind of interesting to know.

12:28.960 --> 12:31.140
And then we have our resources.

12:31.240 --> 12:32.680
So we'll do a quick resource look.

12:32.710 --> 12:38.750
So we have icons so we can see here as the calculator icons that were that were used to.

12:39.310 --> 12:45.050
We'll just leave it with the icons for now but if you had other images they would show up here so next

12:45.050 --> 12:46.690
thing is the sections.

12:46.730 --> 12:57.240
So in this case we have our text which contains all of our code we've got our data I data our source

12:58.050 --> 12:59.090
and relax.

12:59.100 --> 13:00.990
So this is the relocation table.

13:00.990 --> 13:03.370
We're not going to worry about that just now.

13:03.390 --> 13:07.590
However if you want to take a quick look.

13:07.620 --> 13:09.000
So it's all gonna be in hex.

13:09.000 --> 13:12.780
However you can take a quick look at some of the some of the data here.

13:12.780 --> 13:18.960
So if we look at the text document you can see that where this is straight hex but we can see some interesting

13:18.960 --> 13:26.940
characters so calculator package you can see calculate package verification successful calculators started

13:27.410 --> 13:30.130
you can see a few bits of information.

13:30.270 --> 13:33.300
Take a look at data doesn't look like we have too much in there.

13:34.610 --> 13:36.760
Those are the import table so we'll see.

13:36.760 --> 13:45.680
We can see Arrigo shell 32 just and that Shell execute w so we can see how it's been it's being pulled.

13:46.960 --> 13:52.330
This is their resource table which contains our images which you can actually sort of see the B I found

13:52.330 --> 13:58.620
of the ah the outline of the calculator icon there and then the relocation table we'll leave that alone.

13:59.530 --> 14:02.770
So this is a piece of file structure.

14:02.770 --> 14:10.410
Now just just to prove that the DLR was of the same so if we grab a random yellow and we continue we're

14:10.420 --> 14:12.390
going to see a very similar structure.

14:12.400 --> 14:16.710
This is I thirty six P E file we have a.

14:16.790 --> 14:22.810
The difference here is we have an export table now of what some of the functions are that it's able

14:22.810 --> 14:23.110
to do.

14:23.110 --> 14:30.010
So these are some of the functions that the comp l DL l file happens to have.

14:30.100 --> 14:31.060
That's kind of interesting.

14:31.150 --> 14:38.410
And then we have our import table so it does import from LTL and TDM well so it looks like we have some

14:39.040 --> 14:43.520
stuff around events trace flags.

14:43.800 --> 14:45.270
Interesting.

14:45.400 --> 14:47.920
And do we have any resources.

14:47.920 --> 14:48.880
No.

14:48.880 --> 14:54.490
Since it's the DLF there's probably not a need for it to have images but we still have Section headers.

14:54.520 --> 15:00.070
So there's still going to be text there's still gonna be data so we take a quick look here.

15:00.210 --> 15:06.150
Interesting and then we have our dock text which this is all compiled so it's gonna be a little bit

15:06.150 --> 15:10.070
more information than just seeing strings because it's a deal.

15:10.140 --> 15:12.910
It's not meant to just be ran normally.

15:13.530 --> 15:20.820
So this has been the P files and DL ls again feel free to kind of dive a little deeper into it if you

15:20.820 --> 15:21.920
have any questions.

15:22.080 --> 15:25.520
Definitely go to the Facebook group everybody is there to help.

15:25.860 --> 15:27.600
I'm always there I'm always checking up on it.

15:28.170 --> 15:33.280
So go ahead and dive deeper in this mess around with P explorer.

15:33.360 --> 15:37.820
At least until the licence expires and then see what other stuff you can kind of come up with.

15:37.830 --> 15:40.680
Remember always research stuff that you don't understand.

15:40.680 --> 15:43.130
So understanding what this particular one does.

15:43.140 --> 15:48.600
I don't know this off the top of my head so I would go and search it understanding that at least knowing

15:48.600 --> 15:55.110
that you've seen it before and a general idea about something always allows you to be able to research

15:55.110 --> 16:01.050
it later because nobody can remember everything unless you're some of those people that just have instant

16:01.050 --> 16:01.960
memory.

16:02.100 --> 16:03.270
I'm not one of them.

16:03.330 --> 16:04.900
Chances are you aren't either.

16:05.100 --> 16:08.430
But if that's not the case then research research research.
