start	end	text
0	2580	Okay. How's everybody doing?
3800	7560	All right. Let's give a big hand and welcome our presenters here.
7560	10200	Danny Quist and Laurie LeBrock.
15850	20610	Thank you very much. So this is Reverse Engineering by Crayon.
20610	23670	I'm going to talk a little bit about some hypervisor-based malware analysis
23670	27390	and visualization tools that I've developed here.
27650	31450	So my name is Danny Quist. I founded Offensive Computing.
31450	35470	Also a PhD candidate at New Mexico Tech. I do reverse engineering
35470	37430	and I teach reverse engineering.
38490	42350	And I'm Laurie LeBrock. I guess I need a mic.
42370	46810	I'm Laurie LeBrock. I'm an associate professor and fortunately get to work with Danny,
46810	50090	run the scholarship for service program at New Mexico Tech.
50370	55110	And Danny's going to present essentially all of this because it's really his work.
57590	58630	Okay.
58630	63010	Wow. 30 seconds into the talk and there's already booing. Thanks guys.
63650	66430	I do have a fire extinguisher here I was told not to use.
66430	67790	That makes me want to use it.
69530	74730	Okay. So what we're going to talk about is get started talking about
74730	78690	the reverse engineering process. Then I'll talk a little bit about hypervisors.
78790	83150	And then specifically Xen and Ether, which are pretty awesome.
83390	86850	And how we modify the reverse engineering process to work
86850	89930	with these. And then I'll show my visualization tool Vera.
90270	93650	And then I'll show you some real reversing that I did with this.
93790	98870	And then some results of this process. Okay. So let's get started by looking at
98870	102390	the reverse engineering process. The first step with this is
103070	106750	and this is just my process and the one that I teach and the one that I've had
106850	110710	a lot of good luck with. It's by no means everybody's one.
110710	114690	But this is just what I use when I'm doing it. So that's the big caveat there.
114690	118730	So the first thing that I do is I set up an isolated environment. This is something like
118730	122470	VM wearers and virtual PCs. Some sort of dedicated hardware.
122710	126350	Then we get into the initial analysis. And this is using the real high level tools
126350	130430	like Sysinternals to look for system calls and monitoring any sort of
130430	134850	operating system state change. The next one is removing deobfuscation
134850	138670	and dearmoring a program. So this is unpacking using
138670	141910	debuggers, Saffron or Ether. Then we get into
142950	145690	disassembly. So this is with Idapro or Olidebug or
145690	150030	Dumpbin if you're so inclined. And then the next part is
150030	153630	identifying relevant and interesting features. And so this is where
154410	157630	a lot of newbies have trouble with the process and something that I wanted
157630	161670	to address. So the two things that we're going to talk about here
161670	165610	are specifically going to be addressed is that we're going to look at dearmoring or
165610	169970	deobfuscation. And this is using a tool called Ether, which is
169970	174290	completely cool. And are Paul and Artem here?
175010	177810	Oh, okay. All right. So good. I know Artem
177810	181990	embarrasses you. And then identifying the interesting features is the thing
181990	186050	that the visualization tool is going to do. Okay. So setting
186050	190090	up an isolated runtime environment. The point of this is just to protect yourself
190090	193990	from the code. And this is, you know, assuming that it's pretty
193990	197930	difficult to actually break out of the VM. It also makes a
197930	201990	known good baseline environment to allow you to do backtracking if something bad
201990	206090	happens. So execution initial analysis.
206090	209870	This is just to get the extremely high-level overview of what code's doing without looking at
209870	214050	assembly. And so this is looking for changes on the file system, changes in the behavior
214050	217310	of the system, network traffic, and overall performance.
218710	222450	Okay. So now removing software armoring.
222450	225970	Software armoring are just protections to prevent reverse engineering or
225970	229870	make the program smaller or protect it in some manner. And this is done via
229870	234330	packers, which are just self-modifying code. And there's a whole lot of research out there on this.
234390	238150	Alibone, Saffron, Polyunpack, Renovo, Ether, and Azure.
238250	240310	So this research is going to use Ether.
241750	246190	Okay. So let's talk a little bit about the packing problem. All a packer is is it's a
246190	250590	self-modifying portion of code. It has a small decoder stub that
250590	253790	decompresses the main executables and then restores the imports and then allows the program to
253790	257050	execute normally. And this just plays tricks with the
257930	261870	executable. It does the bare minimum amount of work to get things loaded up
262970	265910	and hides imports and that sort of stuff. And it's basically
265910	269710	just to trip up any of the tools. So the way this looks
269710	273750	is that we'll have a PE file right here and you'll have a normal unpacked file
273750	277810	and you apply a packer to it and what happens is that you get the compressed
277810	281350	or obfuscated code with a small decoder stub on the right.
282110	285470	Okay. There's some other troublesome protections.
285470	288490	The first one is virtual machine detection. You can get
288490	290990	some of these things that are put out.
293510	297030	Also we developed a tool called OCVM detect.
297610	301590	But generally detecting that you're inside of a VM is very, very easy.
301590	305650	And so there was an excellent paper that if you haven't read it yet, you should.
305650	309110	It's called Attacks on Virtual Machine Emulators by Peter Ferry.
309110	312510	What this does is it goes through every single VM that
313110	316850	was available at the time and he gives roughly 10
316850	321010	assembly instructions about how to detect all of them. It's all for 16-bit
321010	325070	mode of a DOS program, but it's pretty easy to translate into the 32-bit
325070	329070	equivalent. Debugger detection. This is just looking
329070	332110	at the process execution block and checking to see if the
332730	337150	is being debugged flag is set. And also the eflags trap flag is going to be set
337150	341730	there. Timing attacks deal with the time step counter.
341730	345130	And the time step counter, you just take a, you pull it before
345130	349710	and then run some instructions and pull it after and then see if things are inordinately large.
349870	352130	And so this turns out to be a very effective tool.
353710	357270	Okay, so all this is very annoying for the reverser and
357270	361350	there's basically two methods for circumvention. The first one is that you can know about all the possible
361350	365130	protections and get into the cat and mouse game of trying to remove those
365130	369230	or you can make yourself invisible. So the second one is
369350	372890	a lot less work. So being a good grad student, I chose the lazy way.
374830	377290	So there's been a couple...
377290	381490	Sorry? I just have water here, so...
381490	384950	Can we get security here? This guy's causing problems.
386330	387470	Thanks, honey.
391790	393010	Okay, so
393010	396810	software-based VMs... I always wanted to be that guy at DEF CON, too.
396850	400990	All right, so software-based virtual machines.
401050	405150	These are things like Renovo and PolyUnpack and the Dynamics Box Unpacker.
405850	408910	The problems with these is that they get into issues where detecting
408910	413070	these is actually pretty easy. So the Intel CPU is never really meant
413070	417370	to support virtualization and they don't emulate these bug for bug.
418850	421070	Okay, so OS integrated debugging.
421070	424990	This is Saffron and Olibone. Both of these systems abuse the
424990	428730	page fault handler and sets a supervisor bit on running pages
429350	433290	so that you can actually get some sort of idea of the execution
433290	437090	inside of there. The problems with these and one of the problems I had with
437090	441010	Saffron is it destabilized the system. It was very good at unpacking
441010	445010	something once, but if you wanted to run the system or do anything else
445010	448950	with it, you basically had to reboot and do the process again. So it wasn't very
448950	452690	flexible for implementing an automated unpacking system.
453470	457110	The other problem with that is that you couldn't actually do any sort of
457110	461030	fine grain monitoring. You basically got things on the page boundaries.
463110	465010	Okay, so now we get
465010	468950	into the awesome. So there's a fully hardware virtualization monitoring
468950	472870	system called Ether. It was built by Artem Dynaburg and
472870	476650	Paul Royal from Georgia Tech. This is a Zen based
476650	480910	hypervisor system. Ether has a couple of things
480910	484530	that monitor for system calls, instruction traces, memory
484530	488570	writes, and basically all the interaction with the OS is done via the
488570	492810	shadow page table inside of the Zen hypervisor.
493790	496770	So the problem is, which isn't really a problem,
496770	500450	is that it requires dedicated hardware, but what it buys you is that you get an actual
500450	505210	VM environment that you can use to restore a lot of this too. So it's actually very flexible.
506390	509590	Okay, so back to the reverse engineering process.
509930	513070	Disassembly and code analysis, this is one of the most nebulous portions
513070	517070	of the process. And when I'm teaching this, this is the one that the students get
517310	521390	a little bit frustrated at because this is something that you only get after you've done a lot of reversing.
521390	523950	So how do you get a lot of reversing experience? By reversing.
524570	529150	And it largely depends on intuition. And you get into this issue
529150	533170	where a lot of times you focus too much on the actual assembly code and not
533170	537130	the overall view of the program. So fighting analyst fatigue
537130	541110	is something I like to address. Get to the meat of the problem before it's
541110	545170	so you can avoid the issues. Okay, and
545170	549410	finding interesting and relevant portions of the program. So just like the disassembly
549410	553090	portion, this requires a lot of experience. Some typical starting
553090	557310	points is looking for interesting strings, looking for API calls, and
557310	561230	looking at any sort of interaction with the operating system. And so this
561230	565170	is a fundamentally imprecise process and beginners
565170	569150	typically have problems with this because until you get to where you understand this a little bit, it's
569150	573210	hard to know where to start. Okay, so let's
573210	576030	talk about hypervisors for a little bit.
581640	585020	There's been a lot of hype about this over the last few years and I'm
585020	589100	not trying to propel this anymore even though the talk title probably
589100	593120	suggests it. But one of the things
593120	597200	is that a lot of the new hypervisor-based root kits, like BluePill
597200	601100	and that sort of thing, have led a lot of the defensive tools. And just like
602720	605280	always, the offensive need to hide
605280	609920	yourself from a running process or from any sort of introspection from a
609920	613380	piece of code inside the operating system works well in this environment. So
613380	617440	that's what we're going to utilize here.
617440	621200	And one big feature that we're trying to take advantage of is the detection of hardware-based
621620	625660	virtualization is not widely implemented. That's not to say it's impossible,
625660	628960	it's just that I don't see too much of that out in the wild.
631040	632420	Okay, so there are a couple of
633700	637700	hypervisor implementations. VMware ESX server, I've had some good luck running.
638260	640600	This is a commercial solution from VMware
641160	644360	and it mostly avoids a lot of the VM detection issues.
644980	649020	Linux kernel virtual machines, this is what I use as my base environment
649020	653120	when I'm basically reverse engineering. And that's just to
653120	657120	prevent me from running malware on my home system. Which, not to say
657120	660140	that never happens. Or my base system.
660440	664980	And then Xen. Xen is really nice because it's got an excellent set of tools
664980	668940	for introspection. And a lot of this has really been led by Georgia Tech, so
668940	672900	hats off to you guys there. But what's nice about Xen
672900	676960	is it uses a standard QEMU image format that's been set up a long time before.
676960	680640	And it's an API that's fully controlled via Python.
680660	682540	So you can integrate into tools.
687160	688900	Okay, so let's talk about
688900	693020	Xen and Ether. So Ether is a set of patches
693020	697080	to the Xen hypervisor that's used to instrument a Windows system.
697300	701080	And so it has a bunch of base modules that allow you to do instruction tracing,
701080	704960	API tracing, and unpacking. And so one of the best papers
704960	708840	I've read in a couple years is this Ether malware extensions via hardware
708840	712820	virtualization extensions. And this was, again, written by
712820	716760	Artem and Paul and a couple other people at the ACM CCS conference.
716760	720740	So if you haven't read this, it's extremely high quality and very useful.
720820	724880	Especially compared to other academic research. So you should
724880	729020	definitely check this out. So Ether's
729020	732920	event tracing. This is what it's using to detect events on the system.
732920	736840	So we talked about system call execution, instruction execution, memory
736840	740980	writes, and context switching. But what's nice about it is it also gives you
740980	744840	covert monitoring. So there's no modifications to the base system, which
744840	749040	means that it's very hard to detect. So instruction
749040	753000	tracing inside of Ether is implemented by setting the trap flag inside of the E flags
753000	756740	register. And then modifications to that is handled via the
756740	760920	push F and pop F instructions. So these are intercepted by the hypervisor and
760920	765100	used for watching that. So modifications to the single
765100	768780	stepping process to look and see if it's being single stepped is effectively
768780	773180	hidden. Okay. Memory and system calls.
773180	776800	Memory writes are tracked by manipulating a shadow page table.
776880	780820	So this gives you access to all the read to and written memory. System
780820	785080	calls. This modifies the sys enter EIP register to point to a
785080	789200	non-page address. And when any sort of access is hit to that, Ether logs that.
789200	794660	And also logs the instruction to catch the older system calls.
796000	800020	Okay. So the this architecture, you start out with a Linux DOM
800020	803160	zero management system. This is basically a Linux system that you run
803160	807140	all your tools on. This is going to have the VM disk image and Ether
807140	810280	management tools. And then it's going to work with the Zen hypervisor,
810280	813640	which will have the Ether patches. And then work with an instrumented
813640	819180	Windows XP service pack 2. Okay. So I made a couple of extensions
819180	823420	to Ether. The first thing is I moved some of the unpacking code
823420	827820	from the hypervisor into user space. I put a little bit more
827820	831400	user mode analysis in this. And I also repaired the portable
831400	835380	executable rebuilding system. And this is just to allow you to
835380	839720	actually disassemble it inside of IDA. And then there's a lot of
839720	843000	other monitoring for executables that will be released a little
843000	849800	bit later. So the user mode unpacking, what this is, is all
849800	853460	we're trying to do is watch for and monitor all the memory writes
853460	857700	and executions. And so we keep all the memory writes inside of a
857700	860880	hash table. Whenever we see a execution inside of one of those
860880	864320	memory writes, we assume that it's a candidate original entry
864760	868620	point and then take a dump of the image. This isn't perfect, but
868740	871360	it's a decent solution. And it certainly helps you to get some
871980	875200	unpacked code. The other nice thing about moving this out of
875200	878280	the hypervisor was that there's a little bit of scaffolding for
878280	884300	future modifications. PE repairs, to implement this, this is,
884300	886700	there were a couple issues. First of all, the sections weren't
886700	890600	aligned. The address of the entry point was invalid. And it
890600	893400	wouldn't load inside of IDA correctly. So basically all I
893400	896940	did is I took the code from ollie dump and used that to fix the
896940	900480	section offsets and repair the resources as much as possible.
900480	903560	And then setting the address of the original entry point to the
903560	908580	correct place allowed it to be loaded inside of IDA. Okay? So
908580	911320	the results from this is that you get it close to a truly
911320	915680	covert analysis system. Ether is nearly invisible. It's still
915680	919560	subject to blue pill detection. So we can start playing that
919560	922640	game. But I think it's a game that's worth playing. So get
922640	925780	started with that. The next thing that we get is fine grain
925780	929240	resolution of program execution. And since you get memory
929240	933000	monitoring, we can start doing some cool stuff with it. So we
933000	936480	can start looking at these files inside of IDA and a lot of
936480	941160	other tools. Okay. So I want to give a quick demo of how ether
941160	956600	works. Or at least the unpacking portion. Okay. So we're going
956600	961180	to start by loading the file up inside of IDA. And just to
961180	963960	verify that this is actually a packed executable, we can see
963960	966880	that the, we get the standard warning about the import
966880	970640	segments being destroyed. And if we allow IDA to continue
970640	975940	executing, we can see that it's generally not finding anything.
975940	979580	The start function is pretty miserable. It's missing strings.
979760	984860	So there's not actually stuff inside of here. And the
984860	987700	functions are pretty much nonexistent. And the import
987700	991640	address, it just has the suspicious get proc address and
991640	995060	load library. So in this case, things are pretty bad. Also,
995060	997880	this top visualization bar inside of IDA doesn't have a lot
997880	1000820	of blue codes. That's a good indication that things are all
1000820	1007890	hosed. Okay. So what we're going to do is actually start
1007890	1011590	running this inside of ether. To do that, this is just going
1011590	1017410	to be a Linux box here. So this is my ether system. And I'm
1017410	1020830	just going to mount the QEMU image. This handy command and
1020830	1025810	the 3G driver for NTFS you can use to copy the file over. So
1025810	1031570	this is pretty straightforward. So we get that copied in. And
1033110	1035730	even though this is a video, you can see how slow I type.
1038610	1044230	Okay. So we're copying this over. Once we get the file
1044230	1048070	copied over, what we want to do is we actually want to start
1048070	1050910	the virtual machine up. So what I'm going to do is use the
1050910	1054310	standard Zen commands to get this started. So this is going
1054310	1057330	to be XM create and then you give it the config file of what
1057330	1065530	you're looking for. Okay. So once I get started, you get
1065530	1069150	this message. And once you've got that, you should be able to
1069150	1072670	open up a VNC image and we can see here that our Windows
1072670	1079970	machine has actually started. Yeah. All right. So Windows.
1081390	1085930	Wait for it. Okay. So once we have that, we actually get the
1085930	1088070	screen and everything's happy and we've got our virus right
1088070	1091630	here. So everything's ready to go. So one thing when you're
1091630	1094470	using Ether that you want to be careful of is you want to be
1094470	1098950	able to load the task manager so that you can actually kill
1098950	1102730	execution of the program when it's running. So this turns out
1102730	1105350	to be a pretty important thing to do unless you like your box
1105350	1108950	rebooting. Okay. So what we're going to do is do an XM list to
1108950	1114450	get the ID out of here. So in this case, it's nine. And then
1114450	1117510	we're going to actually start running the Ether tool. So this
1118170	1122450	will be Ether. Give it the ID that you want. The user mode
1122450	1128190	unpack code. The executable that you want to watch for. And
1128190	1131530	then a local copy of that executable. And so once you've
1131530	1137130	got that up and running, we can see that this is a good sign
1137130	1139830	that Ether's happy. It's at the filter name to be mu under bar
1139830	1141930	net bowl. So whenever it sees a context switch into this
1141930	1148300	process, it's going to pull it out. And at this point, what
1148300	1151940	we're going to go over and do is over on this system, we're
1151940	1156340	going to run the virus. So we're running net bowl. And we can
1156340	1159060	see that net bowl's going to start taking about 100% of the
1159060	1163100	CPU and it gets a little bouncy. Or like it gets a little
1163100	1166760	sluggish inside of there. So in this case, we fixed the dump
1166760	1172900	image to have an RVA of this 421340. So this is a good
1172900	1176960	candidate dump. And we'll allow this to execute a little bit
1176960	1180860	longer until we see the actual icon for the program pop up. So
1180860	1183680	one of the reasons I use net bowl so often is it's pretty
1183680	1186980	benign. But it's still got the malicious component to it so you
1186980	1190020	can watch and see that things are executing. So this actually
1190020	1192780	takes a little bit of time. So I am a little bit of time
1192780	1197200	dilation to go on. All right. So the next thing we get is a
1197200	1204180	fixed dump image to have an OEP of RVA BBO8 or 40BBO8. And so
1204180	1208280	this is actually the original entry point for the program that
1208280	1212080	I verified by manually reversing this. Okay. So it's very
1212080	1214560	important to kill the process inside of Windows before you
1214560	1219900	stop Ether. Otherwise, hilarity ensues. So we've got that
1219900	1227180	going. Then we stop Ether. And then inside of this, we should
1227180	1229840	have a listing of directories. And then for each one of these
1229840	1232920	files, there's the original address. So we've got new net
1232920	1235880	bowl image and then the address that it stopped. And then this
1235880	1241300	dash fixed is the corrected image inside of here. Okay. So
1241300	1244200	now what we can do is we can take this image and load it up
1244200	1248420	inside of IDA pro and we should start seeing some good things
1248420	1250960	here. So what we're going to do is pull the fixed image up.
1253080	1257860	Fixed. Load that up inside of IDA. And then once we start
1257860	1261080	loading it, we can see that things are a little bit happier.
1261380	1264300	So IDA is making noises like it's found the right compiler
1264880	1268060	signatures that it's used to. It's found a lot of the
1268060	1271640	unpacking code and that sort of stuff. So we get actual
1271640	1275420	visualization. The functions exist inside of here. We get our
1275420	1280760	references and everything that we come to expect from this. So
1280760	1283980	we get these functions. Strings, this is a good indication
1283980	1287260	that we've got net bowl unpacked. So in this case, we've
1287260	1289780	got the HRH's net bowl, which I presume is what the AV
1289780	1296060	companies named the virus after and all this other stuff. Okay.
1297740	1300580	So again, we can follow links and that sort of stuff. All of
1300580	1307340	that works and we're all set to go there. Okay. So this is an
1307340	1312520	example of Mew's net bowl. And one person brought up a point
1312520	1316500	like, so what? It's Mew. It's easy to do. But this unpacker
1316920	1320120	is really awesome. It works on pretty much everything. So I
1320120	1324700	ran the media through this and it does a great job. So if we
1324700	1327420	could just like clap for Artem right now. It's pretty cool.
1333700	1341540	Thank you. All right. So with that said, we'll talk a little
1341540	1344680	bit more about what's going on. So there are a couple of open
1344680	1348220	problems. The unpacking process produces a lot of candidate
1348220	1351560	dump files. So this algorithm that we have is a little bit
1351560	1355440	imprecise. So what we want to do is we want a better way to
1355440	1358560	find the original entry point. The other thing is that import
1358560	1361540	rebuilding is still an issue. That's something I'm working on
1361540	1363600	at this point, but I haven't had a chance to integrate it in
1363600	1367800	yet. And so the other thing I'd like to do is do some analysis.
1367800	1371480	So this is going to be the next thing here. So we can integrate
1371480	1375440	this into our process by allowing somebody to figure out
1375440	1377740	to know what to look for inside of here. Because this is the
1377740	1380820	thing that people have trouble with most of the time. So once
1380820	1383360	you have an idea of the execution flow of a program,
1383360	1386280	it's really nice to be able to look at this. So software
1386280	1390100	armoring is pretty much made to be a trivial process and is
1390100	1394320	extremely easy. Okay. So let's get to the visualization
1394320	1399700	portion. One of the goals I set out with when I was doing this
1399700	1402740	visualization is to be able to quickly subvert the software
1402740	1406240	armoring process. So in the case of Netbull, we only had two
1406240	1409380	images that we were trying to detect there, our two candidate
1409380	1413580	dump files. But what I'd like to do are in other samples,
1413580	1416100	especially with more complex packers, you end up getting
1416100	1418780	thousands of them. So we want to make that process a little
1418780	1423580	easier. The other thing is for various portions and phases of
1423580	1427500	the program, I wanted to identify initialization, main
1427500	1430060	loops, and the end of the unpacking code. So figure out
1430060	1432960	where the self-modifying code ends, which is the OEP
1432960	1435920	detection, and figure out some of the dynamic runtime behavior
1435920	1437880	of the program, and also integrate it with some of the
1437880	1443680	tools that we're used to, like IDA. So I made this program
1443680	1446260	called Vero, which is visualization of executables for
1446260	1450200	reversing an analysis. But really it was just a contrived
1450200	1453740	name to name something after Jane's gun in Firefly, and so
1453740	1456580	I was finally glad to have a program that I could do that.
1457740	1462440	So when you're looking at this, it's... the code's pretty
1462440	1465540	simple. It's kind of a Fisher-Price, my first MFC and
1465540	1469420	OpenGL application. But generally, it uses a lot of the
1469420	1472740	OpenGL rendering and integrates with IDA Pro, and it's fast,
1472740	1478000	small, and has a low memory footprint. Okay. So with that,
1478000	1479200	I'll turn it over to Lori.
1480320	1484120	So this is just a graph preview, which on... you know, the
1484120	1486360	fortunate part is there's now a graph in here at the beginning
1486360	1490160	instead of without one. The bad news is it's zoomed out so far
1490160	1494600	you can't see nodes versus edges. But the idea here is that
1494600	1497960	we're going to use a graphical representation so that you can
1497960	1501500	see what the different phases of computation are and where
1501500	1506920	your time is being spent. So the vertices here actually
1506920	1510940	represent addresses. It could be the address of a specific
1510940	1514140	instruction, or it could be, as you see at the bottom, the
1514140	1516580	address of the beginning instruction in a basic block,
1516580	1521600	either one of the two. And the edges represent a... an
1521600	1525080	execution on a path. So you're going from one instruction to
1525080	1528460	the next. What path did you take? That's an execution. The
1528460	1533100	more time some... a transition happens, the heavier the weight
1533100	1536140	on the edge. So that gives you an idea of how... where you're
1536140	1540480	spending your time in the execution. The basic blocks, for
1540480	1543520	any of you who have done the low-level compiler stuff and
1543520	1546080	that sort of thing, you see those are just... it's straight
1546080	1549240	line code. So no transfer of control except from one
1549240	1553360	instruction to the next in the stream. There's no conditionals,
1553360	1557980	none of that stuff. So basic blocks give you a real simple
1557980	1560980	way of getting a hold on a little bit more code at a time
1560980	1565060	than a single instruction. That makes this potentially useful
1565060	1568320	for commercial codes. But as you're going to see, some of
1568320	1572040	the next steps in this will be looking at doing functions and
1572040	1576560	handling function-level sorts of things because you, again,
1576560	1579600	you still get... you saw that... that graph is actually a
1579600	1583500	very small graph compared to what graph theorists look at,
1583500	1587360	but they get kind of big and complex. So the basic blocks
1587360	1591000	give you a way of compressing some of this. The instruction
1591000	1593100	view, where you're looking at every single instruction
1593100	1596780	becomes a node in the graph. Gives real pretty graphs.
1596780	1599300	Danny likes those nice big swoopy graphs, as he calls
1599300	1602800	them. So they may have some aesthetic value because they're
1602800	1606420	pretty to look at, but again, any kind of commercial code
1606420	1609060	and they're just too big to be able to figure out what's
1609060	1615360	going on. So again, those transitions between addresses,
1615360	1619220	they're going to give us more information about where we're
1619220	1623080	spending time in the graph. But there's an assumption
1623080	1626780	here that I just need to point out, and that is the
1626780	1630500	assumption is that during this single execution, so this
1630500	1633060	is for a single execution of the code, during that single
1633060	1635780	execution of the code, the thing you're looking for
1635780	1641100	happened. So if you get something that every 50th time
1641100	1644760	it's executed, it does something, you're not likely to
1644760	1648000	find that using this approach. And so some future work
1648000	1651620	can look at doing more statistical base, where are
1651620	1653960	executions different when you don't change the input
1653960	1657560	file sort of thing. But at the moment, you run it once,
1657560	1660140	you get these graphs, they tell you where things are
1660140	1665240	executed more. So looking at these edges, wherever you
1665240	1669440	see from one node coming out multiple lines, that means
1669440	1671220	there was a decision point there and there are multiple
1671220	1676900	paths you can go to the next instruction. The thing that's
1676900	1680500	really interesting, although somewhat arbitrary, is how
1680500	1682980	the colors are assigned and what they mean. So I'm going
1682980	1685900	to have Danny step back up here and talk about what
1685900	1689620	these different colors in the graph mean when you're
1689620	1691520	trying to find information.
1694130	1696830	Okay, so again, these colors were chosen sort of
1696830	1700830	arbitrarily. And what these represent are the relation
1700830	1707190	of the file that has been dumped from Ether to what's
1707790	1711610	actually on disk. So in this case, we're trying to
1711610	1714930	identify execution into sections where code doesn't
1714930	1719690	exist or that sort of stuff. So what yellow is going to
1719690	1722070	be, this is going to be the standard, normal compiler
1722070	1725210	generated code. Dark green is going to be where the
1725210	1728810	sections are present in the pack version, so this would
1728810	1732530	be something like executing inside of the P header. Light
1732530	1736050	purple is where the memory has been allocated for run time
1736050	1740110	but isn't present in the actual executable. And dark red
1740110	1742310	is one that I wanted to really point out, which is
1742310	1745330	actually the high entropy version of the code. So this
1745330	1750130	would be sort of execution inside of compressed or
1750130	1753350	encoded or encrypted or whatever you want to call it.
1753430	1755390	The other thing that I wanted to point out is light
1755390	1759050	red. These instructions are not in the pack executable
1759050	1762810	at all. And then line green, this is where the operands
1762810	1766370	aren't going to actually match. So this would be any
1766370	1770090	sort of shifting decode frame type attack where you're
1770090	1775350	executing code over and over. Okay, so these colors
1775350	1778730	were chosen arbitrarily. I kind of like that they, I
1778730	1781510	think that they look good, but I did show them to one
1781510	1784390	of my friends, Kazmir, and he looked at it and he
1784390	1786390	says, that's great, Danny, but why are all your colors
1786390	1790430	brown? So it turns out he's red-green color blind. And
1790430	1796370	so I sat down with Kazmir and he was really nice enough
1796370	1799350	to help me go over things and pick out a set that
1799350	1802370	looked okay. But I didn't really like the way they
1802370	1805470	looked. So inside the code there's actually a set of
1805470	1808270	instructions that are available for color blind people
1808270	1810630	and I'm also going to make this available, but for
1810630	1815130	right now it's not compiled by default. So any feedback
1815130	1817470	on this would be really appreciated, so I do want
1817470	1819870	to make sure that it's a useful tool all around.
1820750	1823730	Okay, so the architecture is we've got the ether
1823730	1827650	analysis system, which plugs into a program that takes
1827650	1831130	those trace files and generates the graphs with the
1831130	1835570	OGDF, or Open Graph Display Framework. And Open Graph
1835570	1837550	Display Framework is the thing that makes the decisions
1837550	1840250	about where to actually place the vertices and locate
1840250	1842490	them and that sort of stuff. So this is a really
1842490	1845550	awesome library and if you get a chance to use it,
1845550	1848830	it's, I highly recommend it. It's very similar to
1848830	1852070	GraphViz, but what's nice about this over GraphViz is
1852070	1854890	it works with a large data set. So I've had millions
1854890	1857630	and millions of vertices inside of here and it hasn't
1857630	1859910	choked on it, but it will take all your memory.
1860750	1861730	But that's okay.
1862570	1865850	Finally, we get to Vera, and Vera is the OpenGL
1865850	1868670	component to this program. And so what Vera's going
1868670	1872410	to do is actually display this and allow you to
1872410	1874070	start analyzing it.
1874910	1877470	Okay, so the basic steps are to run an instruction
1877470	1880710	trace with ether, transfer that trace file to the
1880710	1883990	analysis box, then run gen graph on that output,
1883990	1886890	and then those resulting GML files, or the graph
1886890	1889250	language files, are going to be open inside of
1889250	1891030	Vera, and then you can use that to actually
1891030	1892410	correlate instructions.
1893450	1895270	Okay, so let's go ahead and do a demo.
1904460	1907380	Okay, so we start back at our same place with
1908020	1910720	the ether instruction. So the VM's already started,
1910720	1912340	so what I'm going to do is an instruction trace
1912340	1914240	and give it the name of the executable to look
1914240	1917160	for, and then just redirect the output of this
1917160	1922200	to a trace file. So this is going to run,
1922200	1925360	and then over on the VM side, I'm just going
1925360	1927400	to start executing the program, and again, I want
1927400	1929060	to make sure that I have that task manager up
1929060	1931520	so that I can stop this here.
1932760	1936780	Okay, so Netbull gets executed, gets started,
1936780	1938600	and then we wait for a little bit of time
1938600	1942300	to elapse, and so it might not be easy to see,
1942300	1943720	but when you move the mouse around, it gets
1943820	1945220	a little jumpy, so you know that's actually
1945220	1948000	the case where things are going on. But
1948000	1949480	generally, when you get this icon down here,
1949480	1954520	it means it's running. Okay. So now we can
1954520	1961800	stop it from executing. Close this. Stop ether,
1961800	1963260	and then at this point, we can look at the
1963260	1967200	trace file and see how big it is. It's roughly
1967200	1970600	about 250 megs, and so at this point, what we
1970600	1972380	want to do is transfer it to our analysis
1972380	1977440	system. And so this is a good reason to point
1977440	1977980	out that, you know, when you're running a
1977980	1979400	live demo, I know live demos are the way
1979400	1982200	to do it, but I decided to save you all
1982200	1985040	the intrigue of watching 250 megs transfer
1985040	1988700	over the network. So that's why I did this.
1988740	1995980	You're welcome. Okay. So it's copying. It's
1995980	1999820	done. It's the world's fastest network. We
1999820	2002700	run gen graph on the program, so gen graph
2002700	2004520	just handles the graph layout and builds the
2004520	2007020	GML files. So we give it the trace file
2007020	2010060	that we copied over, the original executable,
2010060	2012160	so it can do its analysis, and also the
2012160	2014280	output that we want to put this at. So
2014280	2016060	this, too, takes a little bit of time to
2016060	2018600	run, and in this time, I'm generating two
2019700	2021800	basic implementations. The first one is the
2021800	2023520	instruction base graph, and then the next
2023520	2026600	one is the basic blocks. So once this gets
2026600	2030460	done, what's this? Okay. Yes. It's actually
2030460	2032820	going backwards. So from there, what we want
2032820	2034300	to do is actually load this inside of
2034300	2038000	Vera now. And so this is the actual
2038460	2040940	interface right here. So to navigate and
2040940	2043360	move around and look at this graph, you
2043360	2045280	simply just drag the same way you would
2045280	2046760	with Google maps and use your scroll
2046760	2050640	wheel to go in and out. The initial
2050640	2052520	execution is going to be at this blue
2053540	2056380	address right here. And then any sort of
2056380	2058460	transition is going to move around inside
2058460	2059880	of there. So what we're looking at right
2059880	2064200	now is the basic block view. So we can
2064200	2066720	zoom in, look at these sort of things, and
2066720	2068880	any sort of line, the thicker the line
2068880	2071100	between these, that's going to indicate
2071100	2072960	the loops that are executing. So thin
2072960	2074940	lines mean there's only one transition.
2075520	2077540	And so it turns out that Mew actually
2077540	2080180	has two stages of unpacking. So this
2080800	2082780	initial loop that we were looking at is
2082780	2085920	actually going to be the first one, which
2085920	2090120	was identified via the unpacking process.
2090120	2091680	And then the secondary decoding, which
2091680	2093060	actually brings the rest of the program
2093060	2095620	out, will identify more. And so what
2095620	2097720	we're looking for are transitions in
2097720	2100380	colors. So when we see a color change
2100380	2104080	here, especially from this green to
2104080	2106440	purple, this purple here is going to be
2106440	2108500	representative of the address. So this
2108500	2110760	is the basic block view. This should be
2110760	2112060	the original entry point that we're
2112060	2114280	looking for, but this is pretty close.
2114280	2116520	So the original one was BB08 and this
2116520	2119680	is BB8B. And if you're some kind of
2119680	2121220	math genius, you can calculate that in
2121220	2124420	your head. So then we get over to the
2124420	2127340	actual execution of the program. And
2127340	2128580	inside of here, these are all the
2129000	2132240	transitions that the program makes. So
2132240	2133360	the next thing that we're going to do
2133360	2136760	is I want to show you the all instruction
2136760	2143240	trace. And so this is a little bit more
2143240	2144600	laid out. So one of the comments that
2144600	2147460	we got when we showed this and did a
2147460	2149440	user study is that it was a little bit
2149440	2152920	dense information. So this is the actual
2152920	2154420	instruction base level. So we see that
2154420	2157660	first set of loops inside of here. We
2157660	2159420	come to the central section and inside
2159420	2162020	of this, we can see that there's one
2162020	2163300	function inside of here that's making a
2163300	2165080	lot of the decisions about what the
2165080	2166900	program's doing. So this is this address
2166900	2170820	right here. So if you're looking for the
2170820	2172780	main decision point of a piece of malware
2172780	2174000	or something like that, you can find
2174000	2176320	that. But once we zoom in here, we can
2176320	2177900	see that this address is actually going
2177900	2179340	to be the original entry point that we
2179340	2181640	were looking for. And so we validated it
2181640	2183760	and looked at this. But just by doing a
2183760	2185780	quick glance at this, we can figure out
2185780	2189480	what the OEP is just by looking at this.
2190100	2191620	But as far as the overall functionality
2191620	2194280	of a program, any time we see this sort
2194280	2197860	of long lines of single execution, this
2197860	2200020	is a good indication that this is the
2200020	2202560	initialization phase of the program. And
2202560	2203980	any time that we get these branching
2203980	2206360	operations right here, this is actually
2206360	2207940	going to be the part where it's making
2208080	2209720	a decision or actually doing the
2209720	2213900	branching. But what's nice about Netbull
2213900	2216220	is that it's got these features inside
2216220	2218660	of it that are pretty common. So it's
2218660	2220260	always got that three-way branch at the
2220260	2222440	beginning and the little pigtail up
2222440	2225140	there. This internal side right here,
2225140	2226960	this is the main loop that the Trojan
2226960	2230300	uses to execute and basically control
2230300	2235380	the system. So just moving around inside
2235380	2237440	of here, the next thing that we can do
2237440	2240240	is we can actually zoom in and we can
2240240	2242000	take these instructions right here and
2243640	2246780	then open up IDA and we can use this to
2246780	2249600	start correlating things. So once we
2249600	2250940	find some interesting portion of
2250940	2253400	execution, we can use that to find the
2253400	2254680	address that we're looking for. So in
2254680	2257860	this case it was 403C80 and if we zoom
2257860	2260440	in and just find those addresses, we'll
2260440	2262200	find that there. So you can use that to
2262720	2264480	correlate back and forth with IDA.
2264620	2266220	Eventually there will be an IDA module
2266220	2268060	but I ran into a couple bugs that
2268060	2269920	prevented me from releasing it on time.
2270460	2272740	But you can use this as an initial
2272740	2279220	stopgap solution, stopgap. Okay. So
2279220	2295880	that's Vera. Let's go here. Thank you.
2296740	2300160	Okay. So now I, the next thing that I
2300160	2301920	did is I took a bunch of pictures which
2301920	2305060	were basically the different version or
2305060	2306660	the same version of Netbull packed with
2306740	2308400	a whole bunch of packers. But in this
2308400	2312520	case, this is Netbull and it has the
2314100	2316960	same structure. So we saw this initialization
2316960	2319840	portion here, this branch structure and
2319840	2321840	then this tight knot of execution inside
2321840	2324840	of here. So zooming in, this is the same
2324840	2326680	view that we were looking at in the demo.
2327480	2329420	So now we get into some of the packers.
2329420	2332460	So this is UPX and UPX starts out with
2332460	2335180	some, this red region or the dark red
2335180	2336820	region which is this highly compressed
2336820	2340040	code area. And then we transfer into this
2340040	2343460	light purple or lavender. Okay. I'm not
2343460	2347380	good with colors but... So lavender is
2347380	2349680	actually means it's a size of data zero.
2350020	2351300	So this is where the code is actually
2351760	2353500	unpacking itself and then running the
2353500	2356480	program. We see that the original entry
2356480	2358320	point is immediately after the high
2358320	2360860	entropy code and we get into the size
2360860	2365100	of data zero. Next is ASPAC here. We
2365100	2367020	start out with the blue instruction
2367860	2369140	right here. It goes into these yellow
2369140	2371920	instructions and then it unpacks itself
2371920	2373820	and then we get a transition into this
2373820	2376120	red portion of the program which is
2376120	2377540	where the unpacker was compressing
2377540	2379020	itself. So this is a good way to
2379020	2382040	profile these sort of things. Okay.
2382040	2384060	Same thing with FSG. It's got a smaller
2384060	2385920	or more compressed set of instructions
2385920	2388660	and then we transition to the higher
2388660	2390700	portion of the program. And this graph
2390700	2392880	here looks a little bit different. And
2392880	2394480	the reason it looks different from the
2394480	2395660	other ones is that there's a
2395660	2399660	non-deterministic portion of the OGDF
2399660	2401100	rendering system. But you can still
2401100	2403820	pull out some of the various features
2403820	2408180	here. Okay. Mew. Mew is really nice.
2408180	2409040	This is the one that we looked at
2409040	2411480	right there. It's got a whole bunch
2411480	2412720	of different transitions of colors
2412720	2414900	but the general same format. And
2414900	2417980	then TLock. TLock actually has a long
2417980	2420000	set of instructions and I'm assuming
2420000	2421600	that it uses some shifting decode
2421600	2423940	frame to actually encrypt itself and
2423940	2427900	rerun a lot of these executions. Okay.
2429040	2430780	So one of the things that I did with
2430780	2432460	this is I took a sample from OC's
2432460	2435880	collection and called Mebroot, which is
2436100	2438160	a pretty hardcore virus, and analyzed
2438160	2440100	it inside of Vera. And so when I was
2440100	2441420	initially looking at this, it seemed
2441420	2443600	to be idling for long periods of time.
2443600	2448360	So actually executing this, I knew it
2448360	2451020	was actually executing because my friend
2451020	2452300	and I'm really glad I made friends with
2452300	2454300	him, the network manager at my school
2454300	2455780	said, hey, do you know you've got
2455780	2458640	malware on your box? He's like, yes.
2459220	2461320	But thank you, that validated that.
2461620	2463800	So what Mebroot is, is it's a hybrid
2463800	2465780	user mode and kernel-based malware.
2465780	2468280	So when I initially executed it for
2468280	2471080	maybe 30 seconds and stopped it, I saw
2471080	2473300	that there was this basic execution right
2473300	2475360	here where it just sat inside of this,
2475360	2476920	but it wasn't really doing anything.
2477640	2479540	So essentially it just sits in here
2479540	2481240	for 30 minutes waiting for us to get
2481240	2484960	bored. So I accidentally left it running
2484960	2488580	overnight and tried to look for any
2488580	2490280	sort of unpacking program that it was
2490280	2493000	running after. So once it got through
2493000	2494720	that unpacking program, it transitioned
2494720	2496680	into this main area of execution, which
2496680	2500240	was the top portion of this loop, and
2500240	2502820	got going. So this is the entire graph
2502820	2505200	of execution. We start out with the
2505200	2506980	initialization, this is the 30-minute
2506980	2509400	busy loop, secondary initialization
2509400	2510800	right here, and then there are three
2510800	2513240	main portions of the program. So reverse
2513240	2515180	engineering it, this was the main
2515180	2517520	unpacking loop, and these are two other
2517520	2519820	secondary decoders that I didn't figure
2519820	2522260	out, but this kernel code insertion
2522260	2524180	actually occurs at this point, and that's
2524180	2526340	when the executable stops and your
2526340	2530320	system's then infected. Okay.
2534520	2537060	Okay, so Danny's been teaching these
2537060	2539600	reverse engineering classes using the
2539600	2540940	more traditional approach, not using
2540940	2543140	Vera, but using this traditional, sort of
2543140	2544800	traditional approach, it's his version of
2544800	2547000	it anyway, for quite a while. And
2547000	2549660	recently at one of his classes, after
2549660	2551600	having taught the class for, you know,
2551600	2553600	spending a week on reverse engineering,
2553600	2558180	he took Vera to show these people that
2558180	2559800	were in the class and see what they
2559800	2562540	thought of it. So the first comment in
2562540	2565200	this is it's a very small user study, in
2565200	2567600	part because there's not a lot of really
2567600	2569260	good reverse engineers out there you can
2569260	2570880	get together for a reverse
2570880	2573840	engineering user study, okay. The second
2573840	2576820	thing is this was a training class, so
2576820	2579000	you might say, well, but you're taking all
2579000	2581000	newbies to do this. Well, there were two
2581000	2582820	people in the class that hadn't done
2582820	2585400	reverse engineering before. There were, I
2585400	2586960	think, two people that had a lot of
2586960	2589020	experience, and the other two had quite
2589160	2592260	a reasonable amount. So this is, although
2592400	2593900	a very small sample, it's a pretty good
2593900	2597240	representation of what we would expect
2597240	2600120	in the reverse engineering community. So
2600120	2602600	he had them analyze two different
2602600	2606100	packed versions of NetBull, and I'm just
2606100	2607120	going to go through this very quickly
2607120	2610120	because we're about out of time. Basically
2610120	2613000	trying to see if the things that he's
2613000	2614380	just walked you through doing in the
2614380	2617660	demo, whether new users, whether this
2617660	2620460	helps them or not. They're supposed to
2620460	2623560	find the original entry point, then find
2623560	2625840	these different parts of interest, the
2625840	2627520	packer code, the initialization, the main
2627520	2630920	loops, and if they can, that's great.
2630920	2633220	Especially if it's a little faster. So
2633220	2635500	original entry point, you'll see users 1
2635500	2638720	and user 3 were the two
2638720	2641200	newbies who had never before this week
2641200	2644280	done any reverse engineering. And one of
2644280	2645540	them, you know, we've got the two
2645540	2646820	different packers, one of them with one
2646820	2649540	packer finds the OEP, the other one
2649540	2652900	doesn't find it with either one. For the
2652900	2655720	initialization, in one case they all
2655720	2658840	recognize it, in one case the two new
2658840	2660440	people can't find the initialization
2660440	2663440	code. Main loops, a little better
2663440	2665480	performance. We have one person with one
2665480	2667340	packer can't find the main loops of the
2667340	2670520	program, which I find hard to believe.
2671960	2674280	Then overall evaluation, they were asked
2674280	2676220	were they likely to use this again, and
2676220	2678960	that's in the light lavender, and would
2678960	2681660	they recommend it to others, and that's
2681660	2685780	in the pink. So both for the new people
2685780	2686980	and for people with a lot more
2686980	2688620	experience, they thought this worked
2688620	2691080	pretty well and they would recommend it.
2692320	2695880	The basic gist that comes out of this is
2695880	2699060	there's more work to be done. Yay PhD
2699060	2701320	students. Talk about the work you need to
2701320	2702140	do yet.
2704480	2710160	Okay. Thank you. So we basically need a
2710160	2711660	better way to identify the beginning and
2711660	2713440	ends of loops. That was a good
2713440	2716120	observation. A lot of these loops became
2716120	2718980	overlapped and were a little bit
2718980	2720360	convoluted, and it would really be nice
2720360	2722380	to be able to search for these memory
2722380	2724820	addresses and see the basic blocks it
2724820	2726220	matched. So the future work that we're
2726220	2728700	going to get into is general GUI and
2728700	2730800	bug fixes. Right now it's pretty
2730800	2731520	unsophisticated, so I want to make that
2731600	2733260	a little bit better. I'd like to start
2733260	2735380	doing some memory access visualization.
2735580	2737220	Ether provides an awesome way to do that,
2737220	2738680	so I definitely want to get there.
2739000	2740860	Integrate system calls, look at the
2740860	2742800	function call boundaries, and then get a
2742800	2744340	little bit of more interactivity with
2744340	2747260	the unpacking process. The other nice
2747260	2749380	thing that would be cool is that it'd
2749380	2750600	be really nice if you could use
2750600	2753160	something like WinDebug or Ali or Ida's
2753160	2755600	debugger inside of the Ether system and
2755600	2757620	all the functionalities there. It's just
2757620	2760460	a matter of making it together. So
2760460	2762880	conclusions. Visualization makes it easy
2762880	2765420	to identify the OEP. There's no actual
2765420	2768520	statistical analysis needed. You can
2768520	2770660	actually identify program phases. The
2770660	2772500	graphs are pretty simple, and the
2772500	2774940	preliminary user study shows that other
2774940	2778720	people don't think we're full of it. Okay,
2778720	2780640	there are some tripping hazards that are
2780640	2784080	right here. Basically, use 64-bit version
2784080	2787420	of Debian Sarge. Follow the instructions
2787420	2789080	that Artem and Paul have worked so hard
2789080	2792860	on to the letter. I was guilty of not
2792860	2794880	doing this, and then I reread it, and it
2794880	2798420	was much easier. So anyway, it has to be
2798600	2801460	a 32-bit Windows XP service pack 2 image,
2801460	2803960	and you have to disable DEP, large pages,
2803960	2807040	multiple CPUs, and for God's sake,
2807040	2808540	whatever you do, kill the program before
2808540	2811160	inside of Windows before stopping Ether.
2812280	2814460	Okay, so closing thoughts, Ether's
2814460	2817240	awesome. Many, many thanks to Artem and
2817240	2819160	Paul. This is some excellent, excellent
2819160	2821340	work. If you get anything out of this, I
2821340	2822680	think that more people should be using
2822680	2824300	Ether because it's just so completely
2824300	2828140	cool. Source code tools and the latest
2828140	2830640	slides are on offensivecomputing.net. I
2830640	2833060	do have an initial version of this out.
2833060	2836500	Source code will be up later. If you use
2836500	2838260	this tool, please give me some feedback,
2838260	2839900	and a more formal treatment of this is
2839900	2844240	going to be at VISSEC 2009. So, again,
2844920	2847660	okay. And then thanks to all these people,
2847660	2849280	they were very instrumental in making
2849280	2853940	this whole thing happen. So, with that, I
2853940	2855480	believe we're going to the Q&A room,
2855480	2860580	which is 106. Goon? Yeah, okay. So, Q&A
2860580	2862180	room 106, and then we'll be available
2862180	2864500	after the talk for a little bit to talk
2864500	2865820	to you. So, thank you very much for coming
2865820	2866300	out.
2866300	2866780	you
