WEBVTT

00:00.000 --> 00:03.100
Good afternoon DEF CON.

00:03.280 --> 00:12.140
Today we have a talk on automobiles, alcohol, blood, sweat and creative reversing of obfuscated car moding tool.

00:12.500 --> 00:14.160
And with our speaker Atlas.

00:14.940 --> 00:16.320
Thank you sir.

00:16.420 --> 00:17.720
Thank you Pauls.

00:18.620 --> 00:20.200
I'm sorry, True.

00:20.560 --> 00:22.220
Hi everyone, welcome.

00:23.100 --> 00:25.920
How many of you came because it had the word automotive in it?

00:27.580 --> 00:28.300
All right.

00:28.300 --> 00:28.780
Good.

00:29.640 --> 00:30.120
Obfuscation.

00:30.120 --> 00:32.160
Who came because it said obfuscation?

00:35.260 --> 00:35.700
Excellent.

00:35.700 --> 00:36.620
Well, thank you all.

00:36.620 --> 00:37.860
I don't care why you came.

00:37.860 --> 00:38.360
You're here.

00:38.360 --> 00:39.840
I'm very grateful for you.

00:39.900 --> 00:41.320
I hope that we have a lot of fun today.

00:41.740 --> 00:50.540
As per usual, if you've come to a talk of mine, I've crammed in way too much stuff and we're going to see just how well and how much we can fit in.

00:52.780 --> 01:00.040
And because of timing, I'm going to probably just come out here and look at the slides that you're seeing because I, yeah, whatever.

01:00.920 --> 01:02.420
So who is this Atlas dork?

01:02.420 --> 01:03.120
Hi.

01:03.880 --> 01:05.240
This is my home.

01:05.240 --> 01:09.240
I was created here at DEF CON in 2013.

01:11.740 --> 01:13.140
And this is my family.

01:14.160 --> 01:15.440
I'm a hacker of things.

01:15.440 --> 01:16.560
I ride a motorcycle.

01:16.560 --> 01:21.060
I've got three amazing daughters who have nothing to do with technology.

01:24.440 --> 01:29.800
If you dare, there is a QR code that has all sorts of ways to get a hold of me.

01:30.860 --> 01:33.260
I'll leave that up for about ten more seconds.

01:37.790 --> 01:42.030
So I work in R&D and cyber physical systems for a company called Grim.

01:42.250 --> 01:44.170
And Grim is represented.

01:44.170 --> 01:45.090
Stand up.

01:48.530 --> 01:51.850
My dear friends down here wore huge Grim T-shirts.

01:51.850 --> 01:55.050
Ask how many of them work for Grim.

01:57.290 --> 01:58.830
A lot of love here.

01:59.610 --> 02:00.490
All right.

02:00.650 --> 02:05.350
So my job is to break into things.

02:05.350 --> 02:08.310
And I set many goals.

02:08.310 --> 02:10.550
Some of them attainable in the near term.

02:10.550 --> 02:12.190
Many of them long-term goals.

02:12.190 --> 02:17.630
Some of them, like, if I do these three projects that are year long, then I'll achieve this thing.

02:17.630 --> 02:19.790
So I think in these many different ways.

02:21.090 --> 02:27.590
But my ultimate goal typically is remote code execution on a device thing in a running program.

02:28.090 --> 02:46.930
For cars, and particularly the small ECUs that run your cars, my favorite way to gain code execution on an ECU, like your brake controller or your power steering controller, is through the update process or diagnostics process.

02:47.590 --> 03:06.190
Your tool plugs in, I'm sorry, runs on Windows, there's some software, have a hardware tool plugs into the OBD2 port on your car and then talks over the vehicle CAN network to tell the car things what to do.

03:06.190 --> 03:14.970
Now, for that, for the really cool stuff that we really like to do, there's an authentication mechanism.

03:14.970 --> 03:20.150
So the tool says, no, I'm not just some Joe Schmo, I'm supposed to be doing this.

03:20.570 --> 03:23.190
Give me all the goods, let me do all the cool things.

03:23.710 --> 03:25.690
Now, there are a couple different ways that this is done.

03:25.690 --> 03:26.750
Well, a number of different ways.

03:26.750 --> 03:29.630
But two primary standards of the way that this is done.

03:29.710 --> 03:37.490
But it generally comes with some sort of back and forth, a seed key exchange or some sort of authentication mechanisms like what you might like.

03:39.390 --> 03:45.970
And then, I won't get into exactly how I gain code execution at that point but there are many different cool things that you can do.

03:48.150 --> 03:54.330
Set diagnostics level is the way that you tell an ECU to go into a certain mode.

03:54.330 --> 03:58.290
Sometimes you can change parameters, sometimes you can update firmware.

03:59.050 --> 04:04.770
But then there's a security access hex 27 or an authentication hex 29.

04:04.770 --> 04:07.570
These are the service numbers that are used in the messages.

04:08.450 --> 04:12.970
And that sets up the back and forth authentication process.

04:14.550 --> 04:21.730
So it could be simple key exchange and we just walked through that basically.

04:22.870 --> 04:24.410
Moving right along.

04:29.250 --> 04:30.010
All right.

04:30.010 --> 04:42.910
So the goal for me in this project that I'm talking about is to gain access to the code that calculates the seed key exchange or the authentication mechanism.

04:43.390 --> 04:46.330
There are many different things that can go into that but I don't care.

04:46.330 --> 04:47.310
I want them all.

04:48.430 --> 04:58.270
This all started a couple years ago when one manufacturer that we already had access to added a new authentication mechanism that we didn't have access to.

05:00.290 --> 05:06.710
And so I made the decision to use this as a mentoring tool.

05:06.710 --> 05:18.790
Instead of going hog wild after it, I leaned into other people who were very capable, very skilled, very passionate and I allowed them to think on it, stew on it and work with me.

05:19.730 --> 05:22.110
But it did slow things down quite a bit.

05:23.890 --> 05:26.110
So I don't know if you can see this.

05:26.110 --> 05:28.210
If you can't, I apologize.

05:28.250 --> 05:31.970
Basically this is showing an obfuscated program.

05:32.310 --> 05:49.470
So when you install this tool, I'm not going to mention who, the tool has one executable program on a Windows system and as soon as you load it up in your favorite disassembler, the entry code does some weird stuff.

05:49.470 --> 05:53.750
It pushes a value onto the stack, it makes a call and then it has a return.

05:54.290 --> 05:56.390
Well, that call is literally a return.

05:56.390 --> 05:57.670
It's a no op call.

05:58.250 --> 06:03.070
So what happens when you push something on the stack and then you return?

06:03.990 --> 06:05.230
Well, that's a jump.

06:05.230 --> 06:10.550
It's very common to, it's a common thing to use to obfuscate what you're trying to do.

06:10.550 --> 06:13.210
Malware does this, software does this.

06:13.610 --> 06:16.650
And it's the makings of a very long day.

06:16.770 --> 06:20.850
Now there are a number of ways to deal with obfuscated programs.

06:21.890 --> 06:24.830
More than I listed here, but these are the two that hit my brain.

06:24.830 --> 06:26.510
They tickle my fancy.

06:26.510 --> 06:30.390
I like to emulate through things and do analysis through emulation.

06:30.390 --> 06:32.990
You probably heard a talk or two from me on that.

06:33.650 --> 06:37.590
And what I'm calling snatch and grab and that's actually what we're going to talk about here today.

06:38.170 --> 06:41.570
From an emulator perspective, you might spin up QMU.

06:41.570 --> 06:52.890
QMU allows you to do all sorts of cool emulation things and it builds in a GDB debugger component where you can halt something and do twiddle and all sorts of fun stuff.

06:53.050 --> 07:07.050
Maybe kernel debugging, if we ever get to a point where we're anti-debugging is really good enough to stop me from using this type of mechanism, then kernel debugging will be another option.

07:07.050 --> 07:13.830
Vivisection has a lot of cool stuff, a tool that I released and actually spoke about last week at Black Hat.

07:13.990 --> 07:15.570
But not this time.

07:16.290 --> 07:18.450
No emulation in the initial things anyway.

07:18.450 --> 07:22.070
Emulation plays into pretty much everything that I do, but not for this.

07:23.290 --> 07:42.530
So snatch and grab, basically you start up the program, you run it, you connect it to the vehicle, you get all the functionality that you're really into and you make sure that it's all working, it's all obviously able to be executed.

07:42.710 --> 07:53.250
You attach with a debugger and there are issues that go around this, but anti-debugging, who's heard of it?

07:53.670 --> 07:57.250
Anybody tried to get around anti-debugging techniques?

07:58.230 --> 08:01.410
Well, we're not even going to worry about it.

08:01.410 --> 08:04.190
We attach, it is very difficult to make it so you can't attach.

08:04.190 --> 08:08.450
If you can't, if you actually can't attach, then kernel debugging becomes a thing.

08:09.590 --> 08:15.890
Then we grab all the data and we store it and analyze it.

08:15.890 --> 08:17.230
I mean, it sounds simple, right?

08:18.910 --> 08:23.270
So for this I used a tool called Vivisect, my favorite reversing tool.

08:23.570 --> 08:35.670
It has a built-in vulnerability debugger so we use VDB, attach to the running program, dump what the reason I wanted to use VDB is because VDB has a V snapshot.

08:36.570 --> 08:37.810
V plays into everything.

08:37.810 --> 08:40.110
It's kind of like V for Vendetta but Visigoth.

08:43.150 --> 08:44.830
And then magic happens.

08:45.630 --> 08:46.770
So here's a picture.

08:49.300 --> 08:52.460
If that's too much in my chart, here's a closer picture.

08:52.460 --> 09:10.800
Basically it's just an attach and we say as soon as the attach is done, run snapshot and it dumps all the memory maps out to a file including processor state and so on and so forth so that we can easily analyze the full system state at that point.

09:13.000 --> 09:15.820
And here's the actual, I had to zoom in yet again.

09:17.020 --> 09:19.380
So snapshot target.vsnap.

09:24.500 --> 09:29.700
The next step was to import the data from the snapshot into a Vivisect work space.

09:29.700 --> 09:36.680
Vivisect work space is basically holds all the things that you're analyzing when working with Vivisect doing reverse engineering.

09:37.240 --> 09:43.740
And you can use this for many, many things including symbolic analysis and emulation but we won't get there right now.

09:44.100 --> 09:47.600
It's basically, it was a manual process when I started this.

09:49.940 --> 09:52.320
It's continued to take shape.

09:52.420 --> 09:57.720
This will be wrapped into Vivisection shortly.

09:57.760 --> 10:00.160
Like within a week or two.

10:00.160 --> 10:01.760
I will be releasing next week.

10:04.000 --> 10:08.020
So basically we copy all of the memory maps.

10:08.480 --> 10:15.280
Show of hands, who has done debugging before and understands what a memory map is?

10:16.300 --> 10:28.020
If you do like info proc maps in GDB or cat in a Linux system with a proc file system, cat slash proc slash PID slash maps and it will list.

10:28.060 --> 10:30.420
Here are the different memory maps that exist.

10:30.420 --> 10:34.940
These four or five are from this program or this library and whatnot and so forth.

10:35.420 --> 10:37.220
That's what I'm talking about.

10:37.360 --> 10:40.120
So we just take, that's all been snapshotted away.

10:40.120 --> 10:42.180
We grab the snapshot memory maps.

10:42.180 --> 10:58.860
We copy them into a Vivisect work space and then we do a little magic that says we have all the data, the PE that's been loaded into memory has all of its own data, symbol data, names, things like that.

10:59.200 --> 11:03.800
And we tell the work space to just steal that data.

11:05.320 --> 11:06.680
I'm giving you eye charts.

11:06.680 --> 11:12.060
We're skipping over quite a few slides here.

11:12.300 --> 11:18.760
Because at the end of the day, this was stolen from the built in Vivisect parser.

11:18.760 --> 11:25.200
We just removed a few things that loaded the memory maps back in again.

11:25.780 --> 11:28.380
And that's the thing that I'm going to be wrapping into Vivisection.

11:28.380 --> 11:29.960
Reach out to me if you want it.

11:30.180 --> 11:32.640
You've got contact information for me on the slides.

11:32.640 --> 11:34.580
The slides should be available online.

11:36.100 --> 11:36.800
Okay.

11:36.800 --> 11:43.120
So there are a number of different ways that obfuscation is generally done.

11:43.580 --> 11:45.660
Any malware reverse engineers here?

11:47.120 --> 11:49.260
How about malware forward engineers?

11:52.040 --> 11:59.040
So there are three primary ones that I run into when I've done malware reversing or obfuscation.

11:59.280 --> 12:02.340
The first one is unpack or decrypt in place.

12:02.660 --> 12:14.740
So the program loads up, the loader creates these memory maps and the initial part of the code does a lot of really annoying things.

12:15.100 --> 12:21.060
But then it gets to a point where it decrypts itself into the existing memory maps.

12:21.860 --> 12:23.840
So that's one thing to be looking for.

12:23.840 --> 12:26.200
Because we're always looking for what's important.

12:26.200 --> 12:27.440
What are we interested in?

12:27.440 --> 12:30.200
The next one is to unpack or decrypt into new memory maps.

12:30.200 --> 12:36.960
So it just calls basically give me a new memory map, I will shit my stuff into it and then we'll execute from there.

12:36.960 --> 12:39.920
So anonymous memory maps may be very interesting as well.

12:39.920 --> 12:43.620
You have named memory maps, you have anonymous memory maps.

12:45.060 --> 12:48.620
And then process hollowing or some variation thereof.

12:48.620 --> 13:00.580
So let's say you've got your malware or your obfuscated thing, starts another process and then decrypts its stuff across into that other process much like a debugger would.

13:00.880 --> 13:03.520
So these are all interesting things we're looking for.

13:03.520 --> 13:05.320
There are many variations on it.

13:06.560 --> 13:16.800
And determine very quickly by comparing what I had dumped into the Vivisect workspace to what the original binary loaded in the Vivisect workspace.

13:16.800 --> 13:20.320
And this was a decrypt in place binary.

13:20.640 --> 13:29.060
So that gives me an understanding of at least where I do need to focus, maybe not cutting out where I don't.

13:30.380 --> 13:31.900
So let's go searching for things.

13:31.900 --> 13:42.010
Reverse engineering, you load a thing up into Ghidra or Ida or Binja and you want to do things, how do you do those things?

13:42.010 --> 13:49.710
I want to go find hex UDS things, hex 29, hex 27 as immediate constants.

13:50.370 --> 13:51.310
Uh-oh.

13:52.570 --> 13:57.110
You see, we don't know anything about what we just dumped into the workspace.

13:57.710 --> 14:01.030
There's no code that's been identified.

14:01.030 --> 14:02.790
There are no strings that have been identified.

14:02.790 --> 14:13.630
You can manually go through the 30 meg of memory maps and manually look for strings, but, yeah, I don't have that kind of time.

14:17.710 --> 14:23.690
So here actually is a picture of Vivisect where I'm looking at a string that I want to find.

14:24.330 --> 14:26.670
But it's not identified as a string .

14:28.030 --> 14:36.530
In fact, nothing is except stuff that the loader told me was a string by going through the magic that we did before.

14:38.890 --> 14:40.930
So here's a different view of it.

14:41.210 --> 14:43.450
Maybe you prefer this view.

14:44.410 --> 14:47.450
And, of course, my laser pointer cannot show up on the screen.

14:50.170 --> 14:59.330
So on the right-hand side, if you can see this slide and you have great eyes, you can see near the bottom, there starts to be some ASCII string looking things.

14:59.690 --> 14:59.930
Okay.

14:59.930 --> 15:00.650
Really nifty.

15:00.650 --> 15:02.350
Including security array.

15:02.410 --> 15:04.550
I'm very interested in security array.

15:04.550 --> 15:08.150
Anything that starts in security is very interesting to me.

15:09.710 --> 15:12.470
But, unfortunately, Viv doesn't know that that's a string yet.

15:14.790 --> 15:19.490
When I first did this, I actually just saved the workspace out and the workspace is unencrypted.

15:19.590 --> 15:25.370
And I just ran strings literally on the workspace to get an idea of what was there.

15:25.370 --> 15:26.950
Because they were decrypted.

15:26.990 --> 15:28.990
They were de-obfuscated.

15:29.850 --> 15:40.410
And when I found an interesting thing, and there are millions of strings, when I found an interesting thing, I went back into Vivisect and found... Hi, there.

15:41.670 --> 15:43.130
I held down the wrong button.

16:07.540 --> 16:08.260
Are we back?

16:08.260 --> 16:08.500
No?

16:08.500 --> 16:09.120
Not yet?

16:10.180 --> 16:10.840
What?

16:29.820 --> 16:31.660
Probably see it just as easily, too.

16:42.890 --> 16:43.750
New pointer.

16:43.750 --> 16:44.790
I apologize.

16:45.510 --> 16:46.830
Not used to it yet.

16:49.190 --> 16:49.990
Okay.

16:52.710 --> 16:54.410
It does go fast, though.

17:00.560 --> 17:03.980
So once I found a string that was interesting, I'd go into the Vivisect CLI.

17:03.980 --> 17:06.820
There's a command line at the bottom and I just type search and I look for that string.

17:06.820 --> 17:10.640
It shows up and I can start turning it into strings by pressing S.

17:14.640 --> 17:14.980
All right.

17:14.980 --> 17:22.460
About a week ago, I wrote a Vivisection plug-in component that allows me just to do that and make that available to you guys as well.

17:22.840 --> 17:25.100
The Vivisection scan for strings.

17:27.320 --> 17:37.540
It brings up a starting memory map, an ending memory map and if that's not granular enough, a starting address and an ending address, do you want to apply the strings when you find them?

17:37.540 --> 17:39.320
Like shove them into the workspace?

17:39.320 --> 17:40.680
And I said no.

17:41.960 --> 17:49.900
Because it turns out strings captures a whole bunch of binary code that just kind of happens to be alphanumeric.

17:50.660 --> 17:51.980
So let's take a look at this.

17:51.980 --> 17:53.280
I'm looking for ASCII strings.

17:53.280 --> 17:57.140
I can look for you in a code and it allows you to set the minimum size.

17:57.780 --> 17:59.340
Defaults to five characters.

18:00.440 --> 18:01.700
That's generally good for me.

18:02.060 --> 18:13.100
So when we're done, if you can see this over here, because I told it not to apply the strings, it popped up a widget that just printed out.

18:13.100 --> 18:14.200
Here's the location.

18:14.420 --> 18:15.560
Here's the strings.

18:15.620 --> 18:19.340
I did not make it so that you could click on the location yet.

18:19.440 --> 18:20.960
That's coming next week.

18:20.960 --> 18:21.920
It's been very busy.

18:23.460 --> 18:30.560
So I get an idea and I'm able to scroll through and go, oh, this chunk of code is actually ‑‑ or this chunk of strings is really not strings.

18:33.230 --> 18:35.410
So I don't want all the strings.

18:35.650 --> 18:44.190
So I zero in on a memory address range where I'm confident that those strings are what I want and they are real strings.

18:48.550 --> 18:50.990
So now I have strings.

18:50.990 --> 18:52.870
Look, security access is right there.

18:52.870 --> 18:56.170
DPF, automotive stuff.

18:56.170 --> 18:57.870
If that makes you happy, that makes you happy.

18:59.050 --> 19:03.730
But I see some interesting things that aren't strings and I'm curious about them.

19:03.850 --> 19:04.950
We'll come back to it.

19:06.790 --> 19:09.790
X86, 32 or 64 bit, doesn't matter.

19:09.790 --> 19:21.690
It's a variable length instruction set and it's really important that we get it right so that when we call something code, it is code indeed.

19:21.910 --> 19:27.430
So if you get off by one byte, you can tank an entire understanding of a segment of code.

19:29.310 --> 19:32.930
So how do we accurately identify code?

19:34.450 --> 19:38.290
Well, it turns out there are 12 stack areas.

19:39.710 --> 19:40.110
All right.

19:40.110 --> 19:40.870
I gave you a hint.

19:40.870 --> 19:42.810
Actually, I'm taking hands.

19:42.870 --> 19:47.550
How do I identify known good code?

19:48.350 --> 19:49.470
Yell it out.

19:51.290 --> 19:56.130
Look, do you know how many things are good op codes that are not real?

19:59.020 --> 19:59.900
What's that?

20:04.050 --> 20:04.810
Ding, ding, ding.

20:04.810 --> 20:07.430
Give Travis a big hug.

20:07.430 --> 20:08.390
I'll get you later.

20:09.110 --> 20:10.070
Yes.

20:10.270 --> 20:13.450
So with the hint, he didn't need it.

20:14.270 --> 20:16.230
We have 12 stacks identified.

20:16.230 --> 20:18.910
One for each thread that's running in the system.

20:20.130 --> 20:22.450
Each one has its own stack.

20:22.450 --> 20:24.750
In the stack, what's stored there?

20:25.630 --> 20:26.690
Return pointers.

20:27.830 --> 20:37.310
And a whole bunch of other fucking pointers that are very annoying and they're all large, but it's a great teaching thing.

20:37.690 --> 20:39.970
How do I know if a pointer is a return ?

20:40.770 --> 20:42.710
Well, first of all, we go to the pointer.

20:43.050 --> 20:48.190
And on the top, you see a 32 bit representation of stuff around the stack.

20:49.090 --> 20:55.450
At this address, 3F7FDD4, we see an address 5143A6.

20:55.450 --> 20:58.430
It's blue because that's a valid memory address.

20:59.950 --> 21:01.550
And we back up.

21:01.610 --> 21:02.770
Two bytes.

21:03.090 --> 21:04.390
And see if it disassembles.

21:04.390 --> 21:10.490
And now we're into what you're saying, but it's ‑‑ we're into what you were saying a second ago, but there's more to it.

21:10.490 --> 21:13.450
So sorry if I shut you down too quickly.

21:13.890 --> 21:15.350
So we back up two bytes.

21:15.350 --> 21:15.770
Why?

21:15.770 --> 21:20.010
Because the smallest call in x86 is two bytes long.

21:20.270 --> 21:22.790
The longest call is like eight bytes.

21:23.350 --> 21:24.290
So we back up two bytes.

21:24.290 --> 21:26.070
Does it disassemble into a call?

21:26.810 --> 21:27.470
Yes.

21:27.470 --> 21:27.810
Okay.

21:27.810 --> 21:28.210
Cool.

21:28.210 --> 21:29.650
Now wait.

21:30.130 --> 21:32.870
Does that call stop?

21:32.950 --> 21:34.870
Because everyone's got its own size.

21:34.870 --> 21:38.850
Does it stop at the pointer that we're trying to investigate?

21:39.110 --> 21:39.570
No.

21:39.570 --> 21:39.990
Shit.

21:39.990 --> 21:40.630
Go back.

21:40.630 --> 21:40.870
Okay.

21:40.870 --> 21:41.610
Three bytes.

21:41.610 --> 21:42.130
Four bytes.

21:42.130 --> 21:42.610
Five.

21:42.610 --> 21:43.510
Six bytes.

21:43.510 --> 21:44.210
Whatever.

21:44.610 --> 21:45.870
We get a call.

21:46.310 --> 21:50.670
The instruction itself ends at the boundary where the pointer is pointing.

21:51.330 --> 21:55.250
Because that's what the ‑‑ that's what a return call is, is to go to the next thing.

21:57.450 --> 22:00.830
And that is a pretty good likelihood that that's a return pointer.

22:02.930 --> 22:07.430
So I go to that location and I say C to make code.

22:08.750 --> 22:13.110
And sure enough we have a call to this address which is also valid.

22:13.610 --> 22:15.590
We have a jump after that.

22:16.130 --> 22:19.670
And then basically a drop down to a RET.

22:19.670 --> 22:23.330
So this is looking very much like very good code.

22:24.490 --> 22:26.730
But that is a fuck ton of work.

22:27.770 --> 22:38.830
And after letting my mentee stew on it for a day, I gave her a script and said, so here's a script that will kind of do that manually or automatically for you.

22:39.050 --> 22:44.030
And that script I was going to include in the deck here, I am not because I wrapped it into Vivisection.

22:44.030 --> 22:46.510
You'll get to see that when I cut the next release.

22:47.690 --> 22:52.230
But, whoops, here's the problem.

22:52.610 --> 22:57.210
When I did that, code started getting identified.

22:57.370 --> 23:02.750
Cross references, strings, like magic was happening and then boom, out of memory.

23:06.180 --> 23:14.560
I ended up analyzing this overnight on a machine where I gave myself an 80 gig swap space just to see if it would work.

23:14.560 --> 23:15.700
Binja did the same thing.

23:15.700 --> 23:16.500
Barfed.

23:19.580 --> 23:26.480
And most of my work ended up being on a 500 plus megabyte work space.

23:26.580 --> 23:32.220
Which I don't know about you or how big your work spaces are, but this takes ten minutes to load.

23:32.880 --> 23:39.440
And if I'm doing it over a network, because Vivisect has a Vivisect server and client mode, it takes 45 minutes to load.

23:39.660 --> 23:40.320
Okay.

23:40.640 --> 23:42.020
Need to work on this one.

23:42.020 --> 23:44.720
And we're in uncut territory here.

23:44.920 --> 23:46.340
That's fine, I guess.

23:47.640 --> 23:52.700
So, it also makes function recon completely useless.

23:52.700 --> 23:57.780
I don't know, I just released function recon in Vivisection so you might not have had a chance to use it.

23:57.900 --> 24:04.960
But function recon basically straps in a specialized partial emulator into a function.

24:05.540 --> 24:09.340
And it follows every code path exactly once.

24:09.920 --> 24:12.320
And then every call, it does that, too.

24:12.320 --> 24:16.860
And it keeps going and going and going until it runs out of code to hit.

24:16.980 --> 24:19.700
And it captures things like what strings did I run into?

24:19.760 --> 24:21.560
What function calls did I run to?

24:21.560 --> 24:23.840
What named functions did I call?

24:24.000 --> 24:29.180
Basically, reconnaissance on what a given subset of a program is going to do.

24:29.420 --> 24:33.120
Function recon is worthless on this binary.

24:33.120 --> 24:34.420
Or on this work space.

24:34.480 --> 24:43.900
Because I analyzed all of NTDLL and user 32 and kernel 32 and all the things that I really don't give a shit about.

24:44.080 --> 24:46.120
Because it turns out we know what that is.

24:46.120 --> 24:47.420
That's not obfuscated.

24:48.340 --> 24:49.880
That would be a really dirty trick.

24:49.880 --> 24:51.560
But I did check.

24:51.560 --> 24:53.920
This is legitimate NTDLL and whatnot.

24:57.350 --> 25:02.290
So, sometime by next week I could probably get done with function recon.

25:03.430 --> 25:07.130
But I think I'd like to make a change and not do that.

25:07.650 --> 25:09.770
Oh, and I broke the Viv server.

25:10.950 --> 25:21.070
Didn't not just work, it literally broke it where it would not try to send the data over the network.

25:21.150 --> 25:22.310
So, I ended up fixing that.

25:22.310 --> 25:23.830
That was months ago.

25:28.740 --> 25:36.720
So, I did wrap this into Vivisection because the goal of Vivisection is to kill all TDM and brain drain.

25:37.240 --> 25:43.560
We need your brains to be able to chew on the more important things, not just do these tedious horrible things.

25:44.760 --> 25:49.320
And we focus on starting maps and ending maps for stack.

25:49.420 --> 25:51.320
So, we look for the pointers here.

25:51.420 --> 25:56.320
And we can restrict where the pointers can point to that we care about.

25:56.320 --> 25:57.880
So, that we can skip NTDLL.

25:57.880 --> 26:00.040
We can skip kernel 32 DLL.

26:01.060 --> 26:11.000
Then I have a pull request in for the proper to allow us to turn on what's called one library.

26:11.980 --> 26:21.620
So, that when you analyze a function and it hits outside that library, it jumps or it calls into NTDLL, for example, it just stops .

26:21.700 --> 26:26.160
Because the NTDLL is going to have a name and that's kind of how we do reversing, right?

26:29.580 --> 26:34.740
So , next, once we found strings, we have this one problem.

26:35.060 --> 26:36.740
There's no cross references.

26:37.160 --> 26:42.880
So, the idea is we go to a string and then we have code that references the string and so the code is instantly interesting to me.

26:44.140 --> 26:45.840
Nothing is referring to these strings.

26:45.840 --> 26:47.420
We just told them that it was strings.

26:48.480 --> 26:49.180
Okay.

26:49.180 --> 26:50.220
Now what?

26:50.680 --> 27:03.820
Well, while doing this particular tool, I noticed that around these groupings of strings that were very interesting to me were a whole bunch of non-strings and it didn't look like code either.

27:03.820 --> 27:05.840
I started seeing a pattern in them.

27:06.940 --> 27:10.440
It was number, number, number, zero.

27:10.900 --> 27:13.860
Number, number, number, zero.

27:14.060 --> 27:15.700
Number, number, number, zero.

27:15.700 --> 27:25.220
And in this area of code, the address space is held within 24 bits.

27:25.940 --> 27:31.280
It is look at the address is 0075D289.

27:31.280 --> 27:39.180
In fact, the target binary starts at 400,000 hex and ends at like 80A000.

27:39.440 --> 27:41.680
That was really interesting to me.

27:41.760 --> 27:52.800
And as you can see, these little byte groupings are valid pointers into this target binary address space.

27:52.920 --> 27:57.500
So, I started going through and just hitting, going to one and hitting P.

27:57.500 --> 27:58.320
Make it a pointer.

27:58.320 --> 28:04.600
And suddenly, that P goes through the analysis process for the pointer and it says, oh, suddenly I'm pointing at a function.

28:05.080 --> 28:06.840
Because it starts with a name sub.

28:06.920 --> 28:08.480
Oh, that's curious.

28:09.300 --> 28:13.520
So, I did that with a whole bunch of them and they were all functions.

28:14.580 --> 28:20.360
So much so that I ended up writing a Vivisection, actually, no, I think I wrapped this into Vivisect itself.

28:21.880 --> 28:27.020
Writing code that just allows you to make pointers and you just say, here's the start, here's the stop, just make them all pointers.

28:31.540 --> 28:36.700
Turns out there are vast arrays of pointers to a whole ton of code.

28:37.580 --> 28:42.860
They end up being virtual function tables for C++.

28:42.860 --> 28:44.760
Is that familiar with anyone?

28:44.880 --> 28:46.360
C++ reversing.

28:47.140 --> 28:48.100
Kudos to you.

28:48.100 --> 28:49.160
It's not fun.

28:50.700 --> 29:10.600
So, we end up with these tables of functions that are used so when you have the class object ball and you want to call the function bounce or get color or change color, they're just held in this table here and the code knows that bounce is offset 4 into this table.

29:10.620 --> 29:12.040
Make sense?

29:13.780 --> 29:23.180
And all of a sudden, while I'm digging through here, making all sorts of pointers, I started seeing cross references to my strings.

29:24.980 --> 29:31.740
So, now I know some code is referring to security array.

29:32.060 --> 29:33.620
I'm getting better.

29:33.620 --> 29:34.780
Getting happier.

29:35.160 --> 29:41.820
And then I made this, so here's the Vivisect code or functionality to create a pointer array.

29:41.820 --> 29:52.300
Actually, if you just hold down shift and hit P, capital P is pointer array, pops up a dialogue, here's a starting address, here's a stop address, or if you'd rather, this many.

29:52.600 --> 29:56.220
So, you can put in a number into the count and it will ignore the stop address.

29:56.220 --> 29:57.340
It will just do that many.

29:57.660 --> 30:03.420
And then if we run into a null pointer, do we care and do we keep going or do we call that the end?

30:03.560 --> 30:07.340
So, these are all useful to me and so I put them in here.

30:10.250 --> 30:20.270
So, the V table entries, I don't know if you can see that, but the first entry in most virtual tables is called a destructor.

30:20.310 --> 30:22.030
C++ programmers?

30:22.250 --> 30:23.230
Again?

30:23.950 --> 30:25.430
Okay, a number of you.

30:25.470 --> 30:30.950
When you create a class, you write code for a constructor and a destructor.

30:30.950 --> 30:44.330
When you instantiate the object, it runs the constructor which basically tells, it sets up the different data structures in place, create strings, create sub objects, other things like that.

30:44.330 --> 30:48.950
A destructor is tasked with making sure that everything gets cleaned up appropriately.

30:48.950 --> 31:06.890
So, if you have a C++ class that has a bunch of strings in it, your destructor will roll through and say, all right, do this destructor thing for the strings here, strings there, strings here and otherwise or other C++ objects that are wrapped in.

31:08.950 --> 31:14.750
So, the destructor is a highly valuable resource.

31:16.170 --> 31:17.490
How much time do I have?

31:21.430 --> 31:22.990
I'm going faster than I thought.

31:23.610 --> 31:25.090
No blood dripping out of your ears?

31:25.090 --> 31:25.950
I'm doing good.

31:25.950 --> 31:26.590
All right.

31:27.470 --> 31:35.610
So, when we get involved in C++ analysis, no, don't worry, I'm not going to take you too far down that road.

31:35.610 --> 31:36.770
I didn't warn you enough.

31:37.590 --> 31:41.110
And it is, actually, I did, it's another talk.

31:41.110 --> 31:43.910
I need to give another talk on this particular thing.

31:44.830 --> 31:47.750
C++ objects, what creates them?

31:47.750 --> 31:52.450
It's really important because once you create a C++ object, you just kind of tote it around.

31:52.730 --> 32:08.290
You know, I make the function call over here, here's the C++ object and the C++ objects, the goal for object oriented programming is that that virtual function table maintains all the logic about how to do everything necessary with that object.

32:08.290 --> 32:09.690
So, it's kind of self contained.

32:10.270 --> 32:16.070
And then I just say, call this function on here's my ball, you know, or whatever the object is.

32:16.490 --> 32:20.610
And then that function says, I know that a ball can do a bounce.

32:21.170 --> 32:26.010
I don't have to know what that thing is, you know, what goes into bouncing that ball.

32:26.010 --> 32:28.950
I know that I can call bounce on that ball and it will be good.

32:29.890 --> 32:34.890
So, tracing V tables, very, very interesting.

32:34.890 --> 32:46.090
So, about a dozen years ago I spent some time writing symbolic analysis for structures and building in structure reconstitution, basically.

32:46.110 --> 32:52.090
Using a set of code and symbolic data about what the code is doing.

32:52.090 --> 33:01.770
And it's a simple or difficult way of saying the symbolic data is this is this pointer plus 12.

33:01.770 --> 33:08.370
Instead of this pointer and then a bunch of instructions that modify what that register is doing.

33:08.370 --> 33:16.290
The symbolic analysis just traces that and makes it easy for me to say, oh, this is offset 12 into that structure, all golden.

33:21.320 --> 33:35.800
So, the first thing that I'm wanting to do when I do C++ structure analysis is to go through all the functions in the V table because the V table lists all functions that know how to do that thing with that ball.

33:36.180 --> 33:39.520
Or that diagnostics utility.

33:40.560 --> 33:51.080
I then analyze how this pointer is being accessed and I can identify what things go where in memory.

33:51.460 --> 33:59.760
That becomes really important when I'm looking at other code so that I know what offset 12 really means.

34:00.520 --> 34:08.170
Other things, as I said, the destructor is very, very powerful.

34:08.430 --> 34:09.870
And I don't know if you can see that.

34:10.050 --> 34:14.890
This is the first function in one of the V tables we looked at earlier.

34:15.670 --> 34:17.550
And it looks really simple.

34:17.770 --> 34:20.630
It calls free object, that's what I call it.

34:20.630 --> 34:23.110
This is sub underscore some number.

34:23.850 --> 34:29.910
So, free object, this object and I like to name things by the address of the virtual function table.

34:31.230 --> 34:40.430
And then down here based on what's returned or actually based on the arg one, we decide whether or not to decrement and free that object.

34:40.790 --> 34:41.090
Okay.

34:41.090 --> 34:42.350
Seems simple enough.

34:43.790 --> 34:47.050
But free object is where all the really fun magic happens.

34:47.390 --> 34:56.090
So, free object goes through whatever this class or this object is and does the real dirty magic.

34:56.350 --> 35:01.210
You'll notice here something that is often found in dealing with C++ code.

35:01.510 --> 35:05.430
At the top of this little box, there's a move D word.

35:05.730 --> 35:09.830
So, ESI is being used as this pointer right now.

35:10.010 --> 35:18.730
And the very first pointer in that object is a pointer to a virtual function table.

35:19.230 --> 35:26.070
And one thing that you'll notice is that as C++ code is used in different ways.

35:26.070 --> 35:33.870
So, for example, we have a subclass that inherits from it called basketball.

35:34.130 --> 35:38.090
And then another one that is very different that inherits from ball called football.

35:38.390 --> 35:41.370
If you don't know what the difference is there, try to bounce them both.

35:42.390 --> 35:45.950
So, they both have their own bounce functions, but they're both a ball .

35:45.950 --> 35:52.910
So, sometimes what we'll do is we'll say, yeah, no, I really want the ball version of bounce .

35:52.910 --> 35:56.090
I don't actually want the basketball to have this control.

35:57.970 --> 36:06.950
So, oftentimes code will jam in the appropriate virtual function table for that when your code asks for that.

36:07.010 --> 36:10.970
So, as we're going through, this free object, ignore the top.

36:10.970 --> 36:14.650
It's basically just memory protection things.

36:15.910 --> 36:18.330
So, we jam in this virtual table.

36:18.330 --> 36:22.030
I just called it 6 because I didn't know what to do with it at that point.

36:22.790 --> 36:25.170
We then move 16 into EDI.

36:25.170 --> 36:27.250
That will be important very shortly.

36:28.410 --> 36:36.090
We compare EDI to this, this plus 608, this 608 offset.

36:36.290 --> 36:39.870
I'll tell you in advance, spoilers, it's a string .

36:39.870 --> 36:44.130
It's a C++ string, which is not like your ASCII string.

36:46.820 --> 36:51.320
We then move 7 into a local variable and move on.

36:51.320 --> 37:02.800
And based on whether or not this offset into that, this string basically, the size of the string is being compared against 16.

37:03.360 --> 37:15.960
If the string is 16 bytes or more, C++ will create a new object of the right size or something that's flexible and move the string into that.

37:15.960 --> 37:24.020
If the string is less than 16 bytes, then there's enough room in the C++ structure for a string to just house the string.

37:24.020 --> 37:30.200
So, this is why I know this is a string and that's a very common element for C++ reversing.

37:31.220 --> 37:32.680
So, we come down here.

37:33.820 --> 37:41.780
If it's greater, if it's 16 bytes or greater, then I know that I have a pointer to the thing that actually holds the ASCII string.

37:41.900 --> 37:43.260
So, I free that.

37:43.520 --> 37:59.040
And then I move down to the next thing and I compare 15 or I move 15 into EBP and I shove that all over to make sure that this string that we are in the process of deconstructing doesn't ever do that again.

37:59.040 --> 38:03.140
So, as soon as we free that memory, we say, okay, it's 15.

38:04.060 --> 38:05.020
That's not true.

38:05.020 --> 38:05.960
Actually, it's going to be zero.

38:05.960 --> 38:07.040
We're going to delete it.

38:07.060 --> 38:12.200
But, so, it moves down, compare EDI against another offset.

38:12.460 --> 38:13.920
So, some other string.

38:13.920 --> 38:16.520
We go down because EDI is still 16.

38:17.580 --> 38:24.640
So, we actually see in this particular object multiple points of clearly this is a string.

38:28.080 --> 38:36.400
In fact, we then run into another embedded object that's special and we call some code to clean it up.

38:36.400 --> 38:38.020
I won't go into it right now.

38:38.480 --> 38:39.740
But then we do another thing.

38:39.740 --> 38:41.420
Compare this thing against EDI.

38:41.420 --> 38:43.140
EDI is still 16.

38:44.320 --> 38:50.020
And if it's greater than 16, call decrement and free.

38:50.820 --> 38:53.480
And so on and so forth.

38:57.750 --> 39:06.490
So, just to recap C++ reconstitution approach, look for a whole bunch of function pointers.

39:06.490 --> 39:07.830
All grouped together.

39:10.790 --> 39:13.910
Look for cross references to the start of the branch.

39:13.910 --> 39:17.810
Is that the beginning of a bunch of pointers?

39:19.990 --> 39:23.870
Is that the end of a bunch of pointers?

39:25.350 --> 39:31.570
Analyze those functions for how they deal with the this pointer that's handed in.

39:31.570 --> 39:37.770
And every call and convention on every architecture has its own this pointer argument.

39:37.770 --> 39:39.010
Typically it's the first one.

39:39.230 --> 39:42.630
On 32 bit, you see a lot of this call that's ECX.

39:42.630 --> 39:43.930
That's why you're seeing that here.

39:44.370 --> 39:47.850
So, analyze the first function in the virtual function table.

39:51.220 --> 39:56.060
If it's a destructor, it will tell you almost everything else that you really need to know.

39:56.220 --> 39:59.180
And then make good use of it.

40:00.540 --> 40:03.040
I hope you didn't come here expecting Oday.

40:03.620 --> 40:05.940
That wasn't my bent.

40:06.040 --> 40:07.180
I'm a mentor .

40:08.280 --> 40:09.740
Hopefully I've taught you how to fish.

40:09.740 --> 40:10.960
Go fish for yourself.

40:12.180 --> 40:14.260
So, the real conclusion.

40:14.260 --> 40:15.600
Think outside the box.

40:15.940 --> 40:18.160
Make your tools do new things.

40:18.420 --> 40:22.360
If your tools are incapable of doing new things, make your own tools.

40:23.140 --> 40:25.860
Understand why things work the way they do.

40:26.980 --> 40:30.640
Because that leads you to be more powerful.

40:31.220 --> 40:32.260
Then go hunting.

40:32.780 --> 40:36.960
Figure out what you think the code or the behavior should look like.

40:37.500 --> 40:41.040
And use your brain to create new tooling.

40:41.640 --> 40:44.400
Use the existing tooling in creative new ways.

40:45.420 --> 40:47.220
Because you're the real power.

40:47.620 --> 40:49.560
Go forth and do great things.

