start	end	text
0	6860	Good afternoon DEF CON. Today we have a talk on automobiles, alcohol, blood, sweat and
6860	14160	creative reversing of obfuscated car moding tool. And with our speaker Atlas.
14940	23800	Thank you sir. Thank you Pauls. I'm sorry, True. Hi everyone, welcome. How many of you
23800	30580	came because it had the word automotive in it? All right. Good. Obfuscation. Who came
30580	37860	because it said obfuscation? Excellent. Well, thank you all. I don't care why you came.
37860	42400	You're here. I'm very grateful for you. I hope that we have a lot of fun today. As per
42400	47420	usual, if you've come to a talk of mine, I've crammed in way too much stuff and we're going
47420	54840	to see just how well and how much we can fit in. And because of timing, I'm going to
54840	59400	probably just come out here and look at the slides that you're seeing because I, yeah,
59400	66640	whatever. So who is this Atlas dork? Hi. This is my home. I was created here at DEF CON in
68360	77080	2013. And this is my family. I'm a hacker of things. I ride a motorcycle. I've got three
77080	86880	amazing daughters who have nothing to do with technology. If you dare, there is a QR code
86880	92360	that has all sorts of ways to get a hold of me. I'll leave that up for about ten more
92360	103430	seconds. So I work in R&D and cyber physical systems for a company called Grim. And Grim is
103430	112570	represented. Stand up. My dear friends down here wore huge Grim T-shirts. Ask how many of
112570	125830	them work for Grim. A lot of love here. All right. So my job is to break into things. And I
126790	132330	set many goals. Some of them attainable in the near term. Many of them long-term goals. Some
132330	137770	of them, like, if I do these three projects that are year long, then I'll achieve this thing. So
137770	144150	I think in these many different ways. But my ultimate goal typically is remote code execution
144150	153110	on a device thing in a running program. For cars, and particularly the small ECUs that run your
153110	159590	cars, my favorite way to gain code execution on an ECU, like your brake controller or your power
159590	168990	steering controller, is through the update process or diagnostics process. Your tool plugs
168990	176750	in, I'm sorry, runs on Windows, there's some software, have a hardware tool plugs into the OBD2
176750	186190	port on your car and then talks over the vehicle CAN network to tell the car things what to do.
186190	194090	Now, for that, for the really cool stuff that we really like to do, there's an authentication
194090	200930	mechanism. So the tool says, no, I'm not just some Joe Schmo, I'm supposed to be doing this. Give
200930	205230	me all the goods, let me do all the cool things. Now, there are a couple different ways that this
205230	209330	is done. Well, a number of different ways. But two primary standards of the way that this is
209330	214510	done. But it generally comes with some sort of back and forth, a seed key exchange or some sort
214510	222730	of authentication mechanisms like what you might like. And then, I won't get into exactly how I
222730	228650	gain code execution at that point but there are many different cool things that you can do. Set
228650	235010	diagnostics level is the way that you tell an ECU to go into a certain mode. Sometimes you can
235010	242530	change parameters, sometimes you can update firmware. But then there's a security access hex
242530	249010	27 or an authentication hex 29. These are the service numbers that are used in the messages. And
249010	259870	that sets up the back and forth authentication process. So it could be simple key exchange and we
259870	273250	just walked through that basically. Moving right along. All right. So the goal for me in this
273250	280450	project that I'm talking about is to gain access to the code that calculates the seed key
280450	285370	exchange or the authentication mechanism. There are many different things that can go into that
285370	292330	but I don't care. I want them all. This all started a couple years ago when one manufacturer that we
292330	303230	already had access to added a new authentication mechanism that we didn't have access to. And so
303230	310090	I made the decision to use this as a mentoring tool. Instead of going hog wild after it, I leaned
310090	315150	into other people who were very capable, very skilled, very passionate and I allowed them to
315730	324650	think on it, stew on it and work with me. But it did slow things down quite a bit. So I don't
324650	331150	know if you can see this. If you can't, I apologize. Basically this is showing an obfuscated
331150	338130	program. So when you install this tool, I'm not going to mention who, the tool has one
338130	344830	executable program on a Windows system and as soon as you load it up in your favorite
344830	351550	disassembler, the entry code does some weird stuff. It pushes a value onto the stack, it makes
351710	358690	a call and then it has a return. Well, that call is literally a return. It's a no op call. So
358690	365230	what happens when you push something on the stack and then you return? Well, that's a jump.
365230	370810	It's very common to, it's a common thing to use to obfuscate what you're trying to do. Malware
370810	377650	does this, software does this. And it's the makings of a very long day. Now there are a number
377650	383810	of ways to deal with obfuscated programs. More than I listed here, but these are the two that
383810	389490	hit my brain. They tickle my fancy. I like to emulate through things and do analysis through
389490	395050	emulation. You probably heard a talk or two from me on that. And what I'm calling snatch and
395050	399150	grab and that's actually what we're going to talk about here today. From an emulator
399150	404410	perspective, you might spin up QMU. QMU allows you to do all sorts of cool emulation things
404410	411710	and it builds in a GDB debugger component where you can halt something and do twiddle and all
411710	419070	sorts of fun stuff. Maybe kernel debugging, if we ever get to a point where we're anti-debugging
419070	425410	is really good enough to stop me from using this type of mechanism, then kernel debugging
425410	430650	will be another option. Vivisection has a lot of cool stuff, a tool that I released
430650	437310	and actually spoke about last week at Black Hat. But not this time. No emulation in the
437310	441210	initial things anyway. Emulation plays into pretty much everything that I do, but not
441210	452110	for this. So snatch and grab, basically you start up the program, you run it, you connect
452110	457970	it to the vehicle, you get all the functionality that you're really into and you make sure
457970	464190	that it's all working, it's all obviously able to be executed. You attach with a debugger
464190	474110	and there are issues that go around this, but anti-debugging, who's heard of it? Anybody
474110	481130	tried to get around anti-debugging techniques? Well, we're not even going to worry about
481130	485410	it. We attach, it is very difficult to make it so you can't attach. If you can't, if you
485410	492870	actually can't attach, then kernel debugging becomes a thing. Then we grab all the data
492870	500650	and we store it and analyze it. I mean, it sounds simple, right? So for this I used a
500650	506730	tool called Vivisect, my favorite reversing tool. It has a built-in vulnerability debugger
506730	513670	so we use VDB, attach to the running program, dump what the reason I wanted to use VDB is
513670	518810	because VDB has a V snapshot. V plays into everything. It's kind of like V for Vendetta
518810	530380	but Visigoth. And then magic happens. So here's a picture. If that's too much in my
530380	535660	chart, here's a closer picture. Basically it's just an attach and we say as soon as
535660	542960	the attach is done, run snapshot and it dumps all the memory maps out to a file including
542960	549220	processor state and so on and so forth so that we can easily analyze the full system
549220	559380	state at that point. And here's the actual, I had to zoom in yet again. So snapshot target.vsnap.
564500	570000	The next step was to import the data from the snapshot into a Vivisect work space. Vivisect
570000	575420	work space is basically holds all the things that you're analyzing when working with Vivisect
575420	581060	doing reverse engineering. And you can use this for many, many things including symbolic
581060	585840	analysis and emulation but we won't get there right now. It's basically, it was a manual
585840	596700	process when I started this. It's continued to take shape. This will be wrapped into Vivisection
596700	606420	shortly. Like within a week or two. I will be releasing next week. So basically we copy
606420	613900	all of the memory maps. Show of hands, who has done debugging before and understands
613900	621440	what a memory map is? If you do like info proc maps in GDB or cat in a Linux system
621440	628320	with a proc file system, cat slash proc slash PID slash maps and it will list. Here are
628320	632780	the different memory maps that exist. These four or five are from this program or this
632780	638680	library and whatnot and so forth. That's what I'm talking about. So we just take, that's
638680	644660	all been snapshotted away. We grab the snapshot memory maps. We copy them into a Vivisect
644660	654160	work space and then we do a little magic that says we have all the data, the PE that's been
654160	660020	loaded into memory has all of its own data, symbol data, names, things like that. And we
660500	667040	tell the work space to just steal that data. I'm giving you eye charts. We're skipping
667040	677520	over quite a few slides here. Because at the end of the day, this was stolen from the built
677520	684420	in Vivisect parser. We just removed a few things that loaded the memory maps back in
684420	688700	again. And that's the thing that I'm going to be wrapping into Vivisection. Reach out
688700	693000	to me if you want it. You've got contact information for me on the slides. The slides
693000	701120	should be available online. Okay. So there are a number of different ways that obfuscation
701120	708300	is generally done. Any malware reverse engineers here? How about malware forward
708300	716920	engineers? So there are three primary ones that I run into when I've done malware
716920	724560	reversing or obfuscation. The first one is unpack or decrypt in place. So the program loads
725220	733120	up, the loader creates these memory maps and the initial part of the code does a lot of
733120	739960	really annoying things. But then it gets to a point where it decrypts itself into the existing
739960	745560	memory maps. So that's one thing to be looking for. Because we're always looking for what's
745560	749760	important. What are we interested in? The next one is to unpack or decrypt into new memory
749760	755600	maps. So it just calls basically give me a new memory map, I will shit my stuff into it and
755600	760120	then we'll execute from there. So anonymous memory maps may be very interesting as well. You
760120	767360	have named memory maps, you have anonymous memory maps. And then process hollowing or some
767360	773200	variation thereof. So let's say you've got your malware or your obfuscated thing, starts
773200	779760	another process and then decrypts its stuff across into that other process much like a
779760	784580	debugger would. So these are all interesting things we're looking for. There are many
784580	792080	variations on it. And determine very quickly by comparing what I had dumped into the
792080	797820	Vivisect workspace to what the original binary loaded in the Vivisect workspace. And this
797820	805640	was a decrypt in place binary. So that gives me an understanding of at least where I do need
805640	812160	to focus, maybe not cutting out where I don't. So let's go searching for things. Reverse
812760	821050	engineering, you load a thing up into Ghidra or Ida or Binja and you want to do things, how
821050	828630	do you do those things? I want to go find hex UDS things, hex 29, hex 27 as immediate
828630	836330	constants. Uh-oh. You see, we don't know anything about what we just dumped into the
836330	842270	workspace. There's no code that's been identified. There are no strings that have been
842270	850370	identified. You can manually go through the 30 meg of memory maps and manually look for
850370	860230	strings, but, yeah, I don't have that kind of time. So here actually is a picture of
860230	866190	Vivisect where I'm looking at a string that I want to find. But it's not identified as a
866190	875070	string. In fact, nothing is except stuff that the loader told me was a string by going
875070	882490	through the magic that we did before. So here's a different view of it. Maybe you prefer
882490	890850	this view. And, of course, my laser pointer cannot show up on the screen. So on the
890850	895250	right-hand side, if you can see this slide and you have great eyes, you can see near the
895250	900650	bottom, there starts to be some ASCII string looking things. Okay. Really nifty.
900650	905470	Including security array. I'm very interested in security array. Anything that starts in
905470	911710	security is very interesting to me. But, unfortunately, Viv doesn't know that that's a
911710	918210	string yet. When I first did this, I actually just saved the workspace out and the
918210	924650	workspace is unencrypted. And I just ran strings literally on the workspace to get an
924650	930510	idea of what was there. Because they were decrypted. They were de-obfuscated. And when I
930510	936330	found an interesting thing, and there are millions of strings, when I found an
936330	942430	interesting thing, I went back into Vivisect and found... Hi, there. I held down the
942430	1003290	wrong button. Are we back? No? Not yet? What? Probably see it just as easily, too. New
1003290	1021460	pointer. I apologize. Not used to it yet. Okay. It does go fast, though. So once I found a
1021460	1024860	string that was interesting, I'd go into the Vivisect CLI. There's a command line at the
1024860	1027840	bottom and I just type search and I look for that string. It shows up and I can start
1028300	1037040	turning it into strings by pressing S. All right. About a week ago, I wrote a Vivisection
1037040	1041920	plug-in component that allows me just to do that and make that available to you guys as
1041920	1050260	well. The Vivisection scan for strings. It brings up a starting memory map, an ending memory
1050260	1055500	map and if that's not granular enough, a starting address and an ending address, do you
1055500	1059500	want to apply the strings when you find them? Like shove them into the workspace? And I
1059500	1068160	said no. Because it turns out strings captures a whole bunch of binary code that just kind
1068160	1073360	of happens to be alphanumeric. So let's take a look at this. I'm looking for ASCII strings. I
1073360	1078560	can look for you in a code and it allows you to set the minimum size. Defaults to five
1078560	1084620	characters. That's generally good for me. So when we're done, if you can see this over
1084620	1092520	here, because I told it not to apply the strings, it popped up a widget that just printed
1092520	1097080	out. Here's the location. Here's the strings. I did not make it so that you could click on
1097080	1104640	the location yet. That's coming next week. It's been very busy. So I get an idea and I'm
1104640	1108800	able to scroll through and go, oh, this chunk of code is actually ‑‑ or this chunk of
1108800	1118050	strings is really not strings. So I don't want all the strings. So I zero in on a memory
1118050	1123350	address range where I'm confident that those strings are what I want and they are real
1123350	1136290	strings. So now I have strings. Look, security access is right there. DPF, automotive stuff. If
1136290	1141670	that makes you happy, that makes you happy. But I see some interesting things that aren't
1141670	1149790	strings and I'm curious about them. We'll come back to it. X86, 32 or 64 bit, doesn't matter.
1149790	1157190	It's a variable length instruction set and it's really important that we get it right so that
1157190	1164750	when we call something code, it is code indeed. So if you get off by one byte, you can tank an
1164750	1174770	entire understanding of a segment of code. So how do we accurately identify code? Well, it
1174770	1181610	turns out there are 12 stack areas. All right. I gave you a hint. Actually, I'm taking
1181610	1194350	hands. How do I identify known good code? Yell it out. Look, do you know how many things are
1194350	1207550	good op codes that are not real? What's that? Ding, ding, ding. Give Travis a big hug. I'll
1207550	1216670	get you later. Yes. So with the hint, he didn't need it. We have 12 stacks identified. One for
1216670	1223690	each thread that's running in the system. Each one has its own stack. In the stack, what's
1223690	1230710	stored there? Return pointers. And a whole bunch of other fucking pointers that are very
1230710	1239530	annoying and they're all large, but it's a great teaching thing. How do I know if a pointer is a
1239530	1245690	return? Well, first of all, we go to the pointer. And on the top, you see a 32 bit
1245690	1255450	representation of stuff around the stack. At this address, 3F7FDD4, we see an address 5143A6.
1255450	1263490	It's blue because that's a valid memory address. And we back up. Two bytes. And see if it
1263490	1267730	disassembles. And now we're into what you're saying, but it's ‑‑ we're into what you were
1267730	1274410	saying a second ago, but there's more to it. So sorry if I shut you down too quickly. So we back
1274410	1281790	up two bytes. Why? Because the smallest call in x86 is two bytes long. The longest call is like
1281790	1288310	eight bytes. So we back up two bytes. Does it disassemble into a call? Yes. Okay. Cool. Now
1288950	1297490	wait. Does that call stop? Because everyone's got its own size. Does it stop at the pointer that
1297490	1302950	we're trying to investigate? No. Shit. Go back. Okay. Three bytes. Four bytes. Five. Six
1302950	1309670	bytes. Whatever. We get a call. The instruction itself ends at the boundary where the pointer
1309670	1314550	is pointing. Because that's what the ‑‑ that's what a return call is, is to go to the next
1314550	1324410	thing. And that is a pretty good likelihood that that's a return pointer. So I go to that
1324410	1332350	location and I say C to make code. And sure enough we have a call to this address which is also
1332350	1341170	valid. We have a jump after that. And then basically a drop down to a RET. So this is looking
1341170	1351770	very much like very good code. But that is a fuck ton of work. And after letting my mentee stew on
1351770	1356850	it for a day, I gave her a script and said, so here's a script that will kind of do that
1356850	1361770	manually or automatically for you. And that script I was going to include in the deck here, I
1361770	1365670	am not because I wrapped it into Vivisection. You'll get to see that when I cut the next
1365670	1377210	release. But, whoops, here's the problem. When I did that, code started getting identified.
1377370	1386920	Cross references, strings, like magic was happening and then boom, out of memory. I ended
1386920	1393940	up analyzing this overnight on a machine where I gave myself an 80 gig swap space just to see
1393940	1404400	if it would work. Binja did the same thing. Barfed. And most of my work ended up being on a
1404400	1409460	500 plus megabyte work space. Which I don't know about you or how big your work spaces are,
1409460	1415620	but this takes ten minutes to load. And if I'm doing it over a network, because Vivisect has a
1415620	1422020	Vivisect server and client mode, it takes 45 minutes to load. Okay. Need to work on this one.
1422020	1430920	And we're in uncut territory here. That's fine, I guess. So, it also makes function recon
1431520	1435960	completely useless. I don't know, I just released function recon in Vivisection so you might
1435960	1442680	not have had a chance to use it. But function recon basically straps in a specialized partial
1442680	1451460	emulator into a function. And it follows every code path exactly once. And then every call, it
1451460	1457020	does that, too. And it keeps going and going and going until it runs out of code to hit. And
1457020	1461800	it captures things like what strings did I run into? What function calls did I run to? What
1461800	1468080	named functions did I call? Basically, reconnaissance on what a given subset of a program
1468080	1477780	is going to do. Function recon is worthless on this binary. Or on this work space. Because I
1477780	1483140	analyzed all of NTDLL and user 32 and kernel 32 and all the things that I really don't give a
1483140	1489240	shit about. Because it turns out we know what that is. That's not obfuscated. That would be a
1489240	1499070	really dirty trick. But I did check. This is legitimate NTDLL and whatnot. So, sometime by next
1499070	1506030	week I could probably get done with function recon. But I think I'd like to make a change and
1506030	1514510	not do that. Oh, and I broke the Viv server. Didn't not just work, it literally broke it where
1515910	1523090	it would not try to send the data over the network. So, I ended up fixing that. That was months
1523090	1535620	ago. So, I did wrap this into Vivisection because the goal of Vivisection is to kill all TDM and
1535620	1541600	brain drain. We need your brains to be able to chew on the more important things, not just do
1541600	1549680	these tedious horrible things. And we focus on starting maps and ending maps for stack. So, we
1549680	1555840	look for the pointers here. And we can restrict where the pointers can point to that we care
1555840	1565140	about. So, that we can skip NTDLL. We can skip kernel 32 DLL. Then I have a pull request in for
1565140	1574200	the proper to allow us to turn on what's called one library. So, that when you analyze a
1574200	1581060	function and it hits outside that library, it jumps or it calls into NTDLL, for example, it just
1581060	1590140	stops. Because the NTDLL is going to have a name and that's kind of how we do reversing, right?
1590140	1597600	So, next, once we found strings, we have this one problem. There's no cross references. So, the
1597600	1601500	idea is we go to a string and then we have code that references the string and so the code is
1601500	1606960	instantly interesting to me. Nothing is referring to these strings. We just told them that it was
1606960	1617040	strings. Okay. Now what? Well, while doing this particular tool, I noticed that around these
1617040	1622560	groupings of strings that were very interesting to me were a whole bunch of non-strings and it
1622560	1628460	didn't look like code either. I started seeing a pattern in them. It was number, number,
1628460	1637420	number, zero. Number, number, number, zero. Number, number, number, zero. And in this area of
1637420	1652220	code, the address space is held within 24 bits. It is look at the address is 0075D289. In fact,
1652220	1660880	the target binary starts at 400,000 hex and ends at like 80A000. That was really interesting to
1660880	1671420	me. And as you can see, these little byte groupings are valid pointers into this target binary
1671420	1677760	address space. So, I started going through and just hitting, going to one and hitting P. Make it
1677860	1681880	a pointer. And suddenly, that P goes through the analysis process for the pointer and it
1681880	1687680	says, oh, suddenly I'm pointing at a function. Because it starts with a name sub. Oh, that's
1687680	1695460	curious. So, I did that with a whole bunch of them and they were all functions. So much so that I
1695460	1700360	ended up writing a Vivisection, actually, no, I think I wrapped this into Vivisect itself.
1701880	1705360	Writing code that just allows you to make pointers and you just say, here's the start, here's the
1705360	1716120	stop, just make them all pointers. Turns out there are vast arrays of pointers to a whole ton of
1716120	1725260	code. They end up being virtual function tables for C++. Is that familiar with anyone? C++
1725260	1733940	reversing. Kudos to you. It's not fun. So, we end up with these tables of functions that are used
1733940	1742120	so when you have the class object ball and you want to call the function bounce or get color or
1742120	1749540	change color, they're just held in this table here and the code knows that bounce is offset 4 into
1749540	1757820	this table. Make sense? And all of a sudden, while I'm digging through here, making all sorts of
1758580	1769460	pointers, I started seeing cross references to my strings. So, now I know some code is referring to
1769460	1777380	security array. I'm getting better. Getting happier. And then I made this, so here's the Vivisect
1777380	1784200	code or functionality to create a pointer array. Actually, if you just hold down shift and hit P,
1784200	1789140	capital P is pointer array, pops up a dialogue, here's a starting address, here's a stop address,
1789140	1795700	or if you'd rather, this many. So, you can put in a number into the count and it will ignore the
1795700	1800660	stop address. It will just do that many. And then if we run into a null pointer, do we care and do
1800660	1806820	we keep going or do we call that the end? So, these are all useful to me and so I put them in
1806820	1815870	here. So, the V table entries, I don't know if you can see that, but the first entry in most
1815950	1826050	virtual tables is called a destructor. C++ programmers? Again? Okay, a number of you. When you
1826050	1831990	create a class, you write code for a constructor and a destructor. When you instantiate the
1831990	1840310	object, it runs the constructor which basically tells, it sets up the different data structures in
1840310	1845750	place, create strings, create sub objects, other things like that. A destructor is tasked with
1845750	1852410	making sure that everything gets cleaned up appropriately. So, if you have a C++ class that has
1852530	1858250	a bunch of strings in it, your destructor will roll through and say, all right, do this
1858250	1865330	destructor thing for the strings here, strings there, strings here and otherwise or other C++
1865330	1876930	objects that are wrapped in. So, the destructor is a highly valuable resource. How much time do
1876930	1885950	I have? I'm going faster than I thought. No blood dripping out of your ears? I'm doing good.
1885950	1894190	All right. So, when we get involved in C++ analysis, no, don't worry, I'm not going to take you
1894190	1901330	too far down that road. I didn't warn you enough. And it is, actually, I did, it's another talk. I
1901330	1908330	need to give another talk on this particular thing. C++ objects, what creates them? It's really
1908330	1913670	important because once you create a C++ object, you just kind of tote it around. You know, I make
1913670	1920670	the function call over here, here's the C++ object and the C++ objects, the goal for object
1920670	1926470	oriented programming is that that virtual function table maintains all the logic about how to do
1926470	1932130	everything necessary with that object. So, it's kind of self contained. And then I just say, call
1932130	1938010	this function on here's my ball, you know, or whatever the object is. And then that function says,
1938010	1944410	I know that a ball can do a bounce. I don't have to know what that thing is, you know, what goes
1944410	1950570	into bouncing that ball. I know that I can call bounce on that ball and it will be good. So,
1951990	1959050	tracing V tables, very, very interesting. So, about a dozen years ago I spent some time writing
1959050	1966850	symbolic analysis for structures and building in structure reconstitution, basically. Using a set
1966850	1974790	of code and symbolic data about what the code is doing. And it's a simple or difficult way of
1974790	1984350	saying the symbolic data is this is this pointer plus 12. Instead of this pointer and then a bunch
1984350	1990610	of instructions that modify what that register is doing. The symbolic analysis just traces that
1990610	2003100	and makes it easy for me to say, oh, this is offset 12 into that structure, all golden. So, the
2003100	2009080	first thing that I'm wanting to do when I do C++ structure analysis is to go through all the
2009080	2014640	functions in the V table because the V table lists all functions that know how to do that thing
2014640	2025420	with that ball. Or that diagnostics utility. I then analyze how this pointer is being accessed
2026220	2032740	and I can identify what things go where in memory. That becomes really important when I'm
2032740	2045870	looking at other code so that I know what offset 12 really means. Other things, as I said, the
2045870	2051010	destructor is very, very powerful. And I don't know if you can see that. This is the first
2051890	2058910	function in one of the V tables we looked at earlier. And it looks really simple. It calls free
2058910	2065530	object, that's what I call it. This is sub underscore some number. So, free object, this object
2065530	2073070	and I like to name things by the address of the virtual function table. And then down here based
2073070	2079130	on what's returned or actually based on the arg one, we decide whether or not to decrement and
2079130	2086130	free that object. Okay. Seems simple enough. But free object is where all the really fun magic
2086130	2094830	happens. So, free object goes through whatever this class or this object is and does the real
2094830	2102210	dirty magic. You'll notice here something that is often found in dealing with C++ code. At the
2102210	2109830	top of this little box, there's a move D word. So, ESI is being used as this pointer right now.
2110010	2119470	And the very first pointer in that object is a pointer to a virtual function table. And one
2119470	2130530	thing that you'll notice is that as C++ code is used in different ways. So, for example, we
2130530	2135610	have a subclass that inherits from it called basketball. And then another one that is very
2135610	2139810	different that inherits from ball called football. If you don't know what the difference is
2139810	2145690	there, try to bounce them both. So, they both have their own bounce functions, but they're both a
2145690	2152790	ball. So, sometimes what we'll do is we'll say, yeah, no, I really want the ball version of
2152790	2159730	bounce. I don't actually want the basketball to have this control. So, oftentimes code will
2160790	2167710	jam in the appropriate virtual function table for that when your code asks for that. So, as
2167710	2173810	we're going through, this free object, ignore the top. It's basically just memory protection
2173810	2180290	things. So, we jam in this virtual table. I just called it 6 because I didn't know what to do
2180290	2188630	with it at that point. We then move 16 into EDI. That will be important very shortly. We
2188630	2199530	compare EDI to this, this plus 608, this 608 offset. I'll tell you in advance, spoilers, it's a
2199530	2209820	string. It's a C++ string, which is not like your ASCII string. We then move 7 into a local
2209820	2219840	variable and move on. And based on whether or not this offset into that, this string basically, the
2219840	2228360	size of the string is being compared against 16. If the string is 16 bytes or more, C++ will
2228360	2236320	create a new object of the right size or something that's flexible and move the string into that. If
2236320	2242360	the string is less than 16 bytes, then there's enough room in the C++ structure for a string to
2242360	2248280	just house the string. So, this is why I know this is a string and that's a very common element
2248280	2257300	for C++ reversing. So, we come down here. If it's greater, if it's 16 bytes or greater, then I know
2257300	2263940	that I have a pointer to the thing that actually holds the ASCII string. So, I free that. And then
2263940	2272420	I move down to the next thing and I compare 15 or I move 15 into EBP and I shove that all over to
2272420	2278580	make sure that this string that we are in the process of deconstructing doesn't ever do that
2278580	2285420	again. So, as soon as we free that memory, we say, okay, it's 15. That's not true. Actually, it's
2285420	2291480	going to be zero. We're going to delete it. But, so, it moves down, compare EDI against another
2291480	2299000	offset. So, some other string. We go down because EDI is still 16. So, we actually see in this
2299000	2311960	particular object multiple points of clearly this is a string. In fact, we then run into another
2311960	2317300	embedded object that's special and we call some code to clean it up. I won't go into it right
2317300	2325260	now. But then we do another thing. Compare this thing against EDI. EDI is still 16. And if it's
2325260	2339350	greater than 16, call decrement and free. And so on and so forth. So, just to recap C++
2341390	2351370	reconstitution approach, look for a whole bunch of function pointers. All grouped together. Look
2351370	2360570	for cross references to the start of the branch. Is that the beginning of a bunch of pointers? Is
2362610	2370430	that the end of a bunch of pointers? Analyze those functions for how they deal with the this
2370430	2376670	pointer that's handed in. And every call and convention on every architecture has its own this
2376670	2382630	pointer argument. Typically it's the first one. On 32 bit, you see a lot of this call that's ECX.
2382630	2387850	That's why you're seeing that here. So, analyze the first function in the virtual function table.
2391220	2396660	If it's a destructor, it will tell you almost everything else that you really need to know. And
2396660	2406740	then make good use of it. I hope you didn't come here expecting Oday. That wasn't my bent. I'm a
2406740	2414420	mentor. Hopefully I've taught you how to fish. Go fish for yourself. So, the real conclusion. Think
2414420	2421160	outside the box. Make your tools do new things. If your tools are incapable of doing new things,
2421160	2429400	make your own tools. Understand why things work the way they do. Because that leads you to be
2429400	2436140	more powerful. Then go hunting. Figure out what you think the code or the behavior should look
2436140	2444400	like. And use your brain to create new tooling. Use the existing tooling in creative new ways.
2445420	2449560	Because you're the real power. Go forth and do great things.
