All right. So Kyle and John are going to talk about process emulation. They're all the way in from Boston. So this is heat for them. Luckily they haven't melted. Let's give these gentlemen a big round of applause. Have a good time, boys. All right. Thank you. All right. Thanks, everyone, for coming. So like you said, this is about process emulation, in particular automating that process emulation at scale. So kind of like how we think about analyzing all the malware and all the binaries that we get. And in particular we have a fairly large ingestion pipeline and we need to be able to process all these samples quickly and efficiently. So when we think about a sample, what we think about is like every sample has some, you know, finite amount of total features or data that can extract out of it. And all of those pieces of information cost a little bit different or they have a different cost with each one. So when we talk about the cost, the reason that the cost is there is because it's a little bit more expensive than it is now. Because as you can see in the graph, we have static, the two domains of extracting information is, you know, static and dynamic. So static is obviously the cheapest and the fastest. And, you know, the primary reason is because you can just do that at scale very easily, throw it in Docker or your function as a service or whatever cloud provider. And you can just extract those features really quickly. Dynamic, of course, is kind of the opposite of that. It runs, you know, it's very slow. You have to spin up lots of machines. You have to configure them in particular ways. And it just increases our cost for getting information. So as we collect more samples, particularly when malware comes in, there's some problems with that, right? So when doing this research, we really have three problems that we want to solve, particularly with regard to malware. And the first one is obfuscation and packers and encryptors and to a lesser extent different types of installers. And what these have the effect to do is they actually limit the amount of information we're able to extract from static analysis. So they reduce that total set. And then what it forces us to do is push those samples because we're not getting all the information we want from them. We're forced to push those into the dynamic analysis domain. But the dynamic analysis domain, you know, it's more expensive. It increases our cost, which is not something that we like. But the dynamic analysis domain also has some problems, right? So there's, you know, anti-analysis techniques. Like no malware likes to be, like, run in a debugger or, like, on a different type of hypervisors. But effectively, there's this infinite set of, like, cat and mouse kind of things that you need to add to the machine to trick the malware into thinking to run. In addition, there are a number of features that we lost. So in addition, not all malware is, like, equal opportunity. It doesn't run on every machine equally. Some malware is targeted. So it won't run the same way on a Windows machine in English as it would, you know, a French machine or some other, you know, keyboard or any number of features in there. So, you know, with those three problems in mind, you know, our goal is to basically we have three goals in mind. First is we want to reduce the cost. We want to bring the static analysis features that we lost due to obfuscation. We want to remove those from the dynamic domain. And then we want to reduce the cost and bring those back into the static analysis domain. So that's kind of the key one. So we want to bring back parity of static analysis. Or at least the cost associated with that. And then the second thing we want to do, and this is, you know, we would hope to bring as much as we can, but what we really want to do is we want to take some of the features that you would find inside of a dynamic analysis domain and emulate those or bring those back into or bring those into the static analysis domain, increasing, like, the total set that we could actually extract via static analysis. Or at least more than traditionally you would accept. And then the last thing we want to do is we want to do all this at scale. So the static analysis kind of implies the scale, but we want to make sure that we can run all these things either inside of Docker or inside of, you know, function as a service. So with that, we came, explored several options and what we decided on was emulation. And if anyone's not aware, there's a really amazing emulator out there right now called Unicorn Engine. And this basically is a CPU architecture emulation, but they also emulate memory. And this is key. So what we want to do is we want to load up malware and we want to replicate the Windows process memory. So we want to replicate the memory inside of the emulator with as high fidelity as we can. And what this allows us to do with emulation in particular is we get full introspection into every single instruction on the system. We get full introspection into system calls so we can hook everything. And then what that also allows us to do is because we can hook everything and we can see everything, we can also mock out more of the system. And this was key and this is where we feel like we're adding a lot of value is we took kind of an idea from unit testing with software engineering where you're mocking out functions and services and we thought, well, why can't we just mock out, you know, large chunks of the OS to allow the malware to execute, you know, further than we would normally expect. So with that, there were other, you know, PE emulators that were out there. The three at the top were I found on the Unicorn website. And these are pretty nice, right? This is where we got some inspiration. And what they do is they'll actually take the PE file, they'll load up a bunch of DLLs and they'll actually throw it into the emulator space and execute them. And they do it pretty well. And they'll output, you know, you get the parameters for the function. You get the, you know, you get the, you know, the where they're called, what the function name is and the return values. And they work quite well. And we wanted to see, all right, using this as inspiration, how can we take this, like, the next step further? So with that kind of in mind, we had some requirements for when we decided what we wanted to build, right? So there is one extra requirement is we wanted the code to be simple. So we wanted to build this framework for executing. So we wanted the actual code to be very simple. And when we originally POC'd this, we did it in C and then we, you know, to make it even more accessible, we switched it to Golang. So that's just as a side note. But then the four core requirements to BINI were, one, we wanted to kind of formalize that mechanism for loading a PE file and all of its DLLs. So we, like, sync all of them up, get the imports working. And so when a call is made, it actually jumps to the real DLL within or the real function within the DLL that was called. So once we had that, then we can really build a good hooking framework. And this is the hooking framework is really the core part of BINI and it enables everything else. And we wanted this to also be as simple as possible. So when you want to define a hook, you just basically fill in a structure that defines the name of the hook, the parameters and then the implementation. And then the third thing, because of that, we want to, you know, extend the current research a little bit and then add, you know, mocking out some of the OS. So a lot of malware, you know, touches the file system, touches the registry, has threads, things like that. You know, what if we can actually mock that inside of the emulator and then make the malware think that it is actually running inside of a real PC. And this, what this really allows us to do is add more fidelity to some of the function calls and really kind of take the next step, we think, in the PE emulation space. And then lastly we want this to be highly configurable. So we want, with the problem with dynamic analysis, right, is that you have kind of an infinite array of cat and mouse and figuring out, you know, anti-analysis techniques and like the, whether malware will run on a machine. So what we want to do is we want to define a single configuration file that represents the entire environment of the machine. So the idea that then we can enumerate a bunch of different configuration files and then we can run BINI against a particular sample much faster against 100, you know, configuration files than we could spinning up 100 different enumerations of those machines. So the idea is, you know, you can change the keyboard, change the registries and then you can do this kind of very rapidly and then you can take, have the malware take different branches and then just really explore what it actually does. So with that, so now we'll talk about the implementation details of BINI and while we're going through this, a quick history on BINI is that it started as just like a side project. We were looking at those three examples that I showed you from the Unicorn website and then we were just kind of playing around with it, throwing the PE in the emulator and seeing what it would do. And then eventually we got to this point where we were actually getting interesting data or useful data and then we decided it was actually worth pursuing as a real project. And now it's actually living inside of our ingestion pipeline and everything goes through it. So this is, this talk will be from now on will kind of be like a little bit. We'll have some screenshots of some demo stuff. We'll do official real demos at the end. We'll have screenshots of that and explain what we were talking about, you know, in the slides prior. And then this will be kind of in chronological order of, you know, the different problems that we had while we were, you know, running different samples through it. So, you know, with that said, what's the first problem when you're building an emulator like this? So the first thing is you need to write a, you need a parser to parse the PE files and you need something to parse, you know, the DLLs and all the, get all the information out of there and you need to be able to link that up and throw it in the emulator. So the first thing we did is we, of course, wrote a parser. So we wrote a PE parser that would, you know, parse, you know, our PE file, all the DLLs. And then we added some, the reason we did, we wrote the parser is because we wanted to do all of the linking and the updating of like the base address and the imports and various other features. We wanted to do that all outside of the emulator. And the main reason to do that is because we want, once we get everything in the emulator, we only want to start the emulator once. You know, we don't want to interact with the emulator a bunch. It's just, it's more time consuming and kind of problematic. So, you know, writing our PE parser and getting that going, you basically, you know, you load the PE, you get its imports tables recursively and you go through and you load up all the PEs and then you update the base address of the DLLs. And then once those are all synced up, then you throw that in memory. And one other reason we wanted to do this outside of the emulator was because for every DLL, once we finish linking everything up, we go back through every DLL and we grab the exports. So we, now we know where the real image is for, or the address is for a particular function. And then we go back through that function in the memory space. And now we're going to build our own map outside of the emulator that has a map between, you know, the DLL, the function and where the address actually is in memory. And this is so we can enable the hooking. So when the emulator actually jumps to that address, we know to stop the emulator, run our hook, if there's a hook available and then move on. And you would think that this would work right away, right? But on modern binaries or modern Windows machines, there's these things called API sets. So when you compile a binary on Windows, you're going to have a service pack, anything after maybe Windows 7, I think, some service pack in there. You'll actually, when you pound to include a particular file and you do, like, load library in this case, as the screen shot indicates, you're not going to get the real DLL. So we didn't actually know what the DLL was. Fortunately, Jeff Chappelle has, you know, some amazing documentation. He's done a lot of RE work on this. And we were able to pull that implementation directly into BINI and add this to our PE parser. So now when we, you know, when our PE parser gets this kind of file, it grabs that, that full API set. And grabs the API set schema DLL, which is in, you know, every version of Windows, you know, beyond, I think, 7, which is the lookup table for the actual real DLL on disk. So now we can do the real linking and load all this into the memory space. So this was kind of the first problem that we had. So now, you know, we have the PE file inside of memory. We have all the DLLs linked up. We haven't quite hit go yet. But the next thing we want to be able to do is, you know, we're mocking kind of the system, right? We're doing unit testing of the memory. We're doing the malware effectively. So we don't need to implement, you know, all of the Windows, you know, subsystems, of course. That would obviously be painful. But we can implement subsets of it. But at the end of the day, what we really want is we want the malware to just think that this particular API was executed successfully. Like we don't really care that about, like, all the other details of the API. We just need, all right, does this function return a value? Is that value, what does that value need to be in order for the malware to continue executing? So in the case of, like, create file, all we really need here is we need to pop the, some values off of the stack. And then we need to put a, like, a valid address or a valid identifier into EAX. So basically just not negative one there. And then, you know, the malware will continue thinking that it was executed successfully. So that brings us to hooking. So I mentioned hooking, we want it to be incredibly simple. And, you know, we believe it is. So when you define a hook, as I said earlier, we have a mapping of all the hooks where the addresses actually are. And what you do is when you want to implement this, you want to define this inside of the framework, you just define a type of struct that, you know, describes your hook. And all you really need is the name of the function you want to hook, the parameters, which is just a string, an array of strings, and they also accept format string variables, which I'll explain on the next slide about, you know, display. And then the last two are optional function, or optional parameters. So if you define the function, this is the actual implementation that you would be overwriting. And then the return value. And if you don't, you know, if you don't have these, it will just assume its own default behavior. So with that, then, we ended up with two types of hooks. There's a full hook where we actually override the implementation in the DLL. So when Bini is executing inside of the PE, it goes to a function call. So in this case, it hits sleep. And then what will happen is it will call instruction to sleep and to, you know, Colonel 32, whatever, and it will go into that address in memory. And then what happens is when we hit that address, because we have them all, we have the lookup table, we'll hook that address, stop execution and run our implementation, which then can, you know, either override it in a full hook case or what I'll talk about in a second is partial hook. So looking at that, so we think this is fairly, the only way to define this hook is you just define the name, which is sleep, right? And then you define a pointer to the hook, which contains the parameters, which is the string, and then the function. And one thing that we think is pretty cool here is, particularly with malware, if it's doing, like, a sleep very early on, you know, sometimes it's trying to evade something. So sleep in this case, we can actually, you know, we can actually, you know, we can actually intercept the parameter. So with our function implementation, you get two parameters that are built into it, and those pass in the context of what the function is called. So basically the parameters that it's called and some other, you know, metadata. And what we can do is we can just increment the tick count of the CPU and then just return immediately. And then the malware is just like, okay, yeah, we must have executed successfully. We slept for five minutes or whatever, and it can go then call get tick count later, and then it will actually get an incremented tick count. So this will happen in real time and it's just right away. And it's just instant. So that's a full hook. But unfortunately we don't want to do, or fortunately we don't want to hook everything because this would just take forever. So we really only want to hook things that make a system call. So for everything else that doesn't actually make a system call and transition into kernel mode, we just want to do what we call a partial hook. And effectively what this does is this just gives us the details of the parameters in, like, a human readable form for that particular function. And so what happens here is when the function is called, it jumps into the DLL, the function within the DLL, and it literally emulates that function and then returns back to the DLL. So that's a full hook. But unfortunately, you can't just get it back to the PE file as normal. So as I mentioned, the parameters, this is a particularly important field and it actually does, like, three things. The first is it defines the string values, it sets the parameter names. So when you output, kind of in the bottom part of the screen shot, it will give you the human readable values to the screen. So this is information that we would capture in our data pipeline. The second thing it will do is it will dictate what gets popped off of the screen. So it will give you the data parameters that are in the stack. So when you return from a function, it will actually say, all right, we have some helper functions built in that, so if we go back a slide, the skip function standard call, that's built in. And that will recognize how many parameters are on this, in this list. And then it will pop those values off of the stack. And so it will do all of this for you. And then lastly, the parameters are what's used for when you call into that function and you want to access to those parameters to do your implementation, this is how you would reference that. So you might only be able to use it for a few different reasons. Like if there's a bug in the system that's on the system, you want to get rid of that bug, if there's a bug that 's not in the system, you want to chase it. So the API stands as a два. So if thatié's there, the API stands as the same thing. But then if it's not, it's not a driver of the worldview at all. So it has to be a identifier of the function that's in there, and then it sets up the function standard at the bottom. So it's the standard of the function that we want to read in that function. So it's getting the data that we want for each of the other functions. So that's our focus. And then the other thing that's slightly different So we've actually hooked it, right? And you can see it's at a different address. So we know that this is where the DLL was mapped. This is where that function is within that DLL. And then just next to the address there, because it's slightly different than where the PE is, just next to that address is an F. So this would indicate that it's a full hook versus the partial hook. And knowing this is actually very useful for debugging it when you're going through a malware and you're trying to get it to go to different branches. But that is that indication. And then you get the, you know, the actual name of the function and, you know, the parameters. And they can be in a human readable format. They take a format strings parameter. And then, of course, the return value, which is also pretty important. Perfect. All right. So now at this point, we basically have a PE parser. We're able to load in DLLs and actually get everything set up to a certain extent. You know, we actually have some hooks probably implemented. We have our hooking system implemented. And that's all great. And this is where we kind of hit the feature parity mark for some of the other emulators. That we were kind of describing earlier. And so we asked ourselves, are we done here? And of course not. So we're able to actually set an entry point and then start the emulator. Set everything up as Kyle had mentioned earlier and then press go and continue forward and hopefully get through most of the sample and have it terminate successfully. Well, in the case of some of what we were doing with partial hooking, it wasn't particularly working properly for us. In the case of, like, say get current process ID, as you can see on the screen here, we were partially hooking this mainly because it wasn't making a system call. And typically we only want to full hook functions that are making system calls ultimately. And so in the case of get current process ID, it was actually accessing Windows user land objects. And we did not have those set up at all. And so before we can actually go and set up these user land objects, we actually had to implement segment registers. And that was kind of a glaring oversight when we first set this all up. So fortunately, there's actually, and thank you, Kyle, thanks to Chris Eagle on that, there's actually a lot of examples on how to do that. And so we were able to kind of take the code that he had written and kind of take that and make it suited to our needs. So now that we actually had the segment registers, we were actually able to start building out Windows user land structures in particular. Most of what we've actually done is, like, the TIB and the PEB, which are the thread information block and the process environment block, respectively. And we actually were able to do a lot of things that we wanted to start filling those out. Because it turns out that malware actually, or any program, really, uses those extensively. Typically when the Windows loader actually starts up a process, it will actually populate a lot of these structures so that the, you know, whatever is running can actually reference that. And in many cases, it uses that information so it doesn't have to make, say, a context switch into kernel mode to get certain information. So we actually wanted to build these out. And much like the rest of the requirements of BIDI, BIDI, these are the things that we needed to be configurable. So with that, we actually started building out the TIB and the PEB. And at first, it was mainly just as we saw fit. We'd see samples that would hit a certain portion of these structures. And then from there, it would fail. And then we'd say, okay, we're missing this certain field. And so we actually built out the structures. And these structures are actually quite large. For those of you who have maybe seen it before, these structures are quite long. And every version of Windows, they keep adding more and more to this. So as we were kind of going through the Windows versions, making sure that we had all the information, these structures actually ballooned in size quite a bit. But the important takeaway on this is that we actually, again, only populated the fields that we needed at that current time. So most of what we did was usually lower in the structure, but higher level stuff we kind of ignored and would nop out. And so if we had an issue, we would then populate that and then move on. And again, much like we did with the PEs and the DLLs, we would populate that as well as when we were parsing. We were actually setting up the TIB and the PEB ahead of time and actually having it kind of in a semi-working state before we actually started the emulator itself. Typically that's done as the loader is going. But in this case, we, again, just kind of set up ahead of time with mock values that would kind of make the sample run and be happy and kind of go through what it needed to do. So now that we actually had something going, we were actually getting through some samples. It was great to see. We actually got through a few samples. We actually got through a few samples that we had, you know, example programs that we had written to test certain things out. We were going from start to finish. We were actually seeing the terminate process at the end, which was great to see. You know, really exciting stuff. So then we actually came to like a crossroads where we wanted to actually continue adding more to it, like Kyle mentioned with the requirements. There's a number of subsystems that we want to mock out, especially on the OS level. But before we can do that, we actually have to go and set up some more stuff that Windows would require. And for that reason, we actually, you know, actually started doing stuff with handles. Windows actually uses handles for a number of things. Basically anything that you can think of on like the lower level side of things, like especially like file access, registry stuff, anything with the threading. That's all done via handles, which are effectively just a memory pointer to some sort of information in memory. And so what we did was we basically created like a superstructure of all the types of handles that we might use and kind of put them in one place. And using that in information, we can then just abstract away most of what Windows would expect to have inside the handles. And we can then kind of hand wave and pretend that they're actually there and the malware can, or any sample that we put through it can actually go and continue forward and we can then build subsystems on top of that. So it's kind of a basic building block for us to kind of start building subsystems and mocking out the OS. And of course, you can't actually do anything with handles until we've actually made a proper memory manager. So, we've actually started to build a memory manager inside Bini itself that would be kind of separate from the emulator. And that we took like a normal heap implementation and then kind of built it up to kind of suit our needs a little bit more. So it does everything you would expect out of a heap memory manager and then we kind of built on top of that. The way we kind of handle the heap in this case is anything that references the heap, so say it's malloc or free, one of those function calls. What we would do is any library that was, you know, a library that was calling some style of memory management, we would partial hook. And ultimately what's going to happen is they're going to hit NTDLL. And when we hit NTDLL, then we're actually full hooking that memory management function and then we're passing it over to the Bini memory manager and then doing everything from there. And from there, we can then start doing more things than just, you know, just heap management, for example. Everything that's not on the stack, we're then just throwing into the heap and the memory manager is taking everything care of it. And then we can just take care of everything for us. So with that, we can actually start putting atomic IDs for our handles, which will point to our superstructures outside the emulator. And then from there, we can actually have those structures filled out and we can then from there build on top of it. So say we want to do file stuff, registry stuff, et cetera. So that's all now handled. Thank you. Okay. So now I feel like at this point when we were doing the development, this is where it kind of switched into where it was a real project and we were actually able ‑‑ we were confident that we were going to get useful information, whereas before it was kind of touch and go. But basically what that means is we've mimicked the user land space quite well, right? So we have, you know, as John was mentioning, we have a heap, which is, you know, critical, and then we have all of the user land processes and the hooking in place and things like that. So the next thing we want to do is, all right, let's see if we can actually capture some files. So if we have a piece of malware that writes a file, can we actually capture that and then save that and analyze it for later? So the first thing we want to do is, all right, let's see want to start implementing when we got into, you know, kind of the mocking of the OS was the file system. And the way we did that is we basically, Bini will have ‑‑ it kind of operates similar to Windows where when you're searching for a DLL when you load something, Bini will have several different paths where it looks for files. And the first path is its own kind of folder. So when you start Bini, you can give it a file path and that will be its root directory for where the file system is. And then from within there, you can actually copy in your DLLs or copy in all the other files that you would want. So when Bini actually does a copy of your DLLs, you can actually create a file. It will actually grab, you know, whatever that file actually is. And coming back to, you know, the hooking again, so what does the malware actually need, though? We just need a valid handle. So we have a mock file system that can support the handles and then the abstractions that go along with interacting with the system. So with that, the first thing that happens is, you know, first of all, all of the file functions, like create file, write file, all these things, they're all going to be fully hooked, right, because eventually these would make a system call. And we want to intercept that. So we want to intercept all of those things. So when we fully hook that, what happens is we're going to hit that address within the emulator. The emulator is going to know we're at some address that's fully hooked. It's going to pop out. So similar to the transition from, you know, user to kernel space, it's going to pop out to our own file system handler. And then what's going to happen is it's going to instantiate one of these new handles. It's going to pass in all the parameters from create file, so specifically the path and the permissions. And then with that, it's going to instantiate a file, create a handle, put that handle in Bini's lookup table, and then pass in all the parameters from create file, so specifically the path. Since Bini's getting a valid handle from the heap, which is just going to be an atomic address, it's going to pass that back as, you know, EAX back into the create file. So now when you run create file, it will actually get a real handle that the malware can then use or the file can then use. But the other thing we want to do is if we're running multiple samples within this file system, we want any rights, like we don't want to pollute the system, the file system or the registry or anything that we do, but any rights need to go to our sandbox location. So if the malware is like installing some persistence mechanism or whatever, we want to actually capture that so we can analyze it later. So if there's anything that's created, like a create file with any type of write bit set, Bini will actually understand that, hey, they're trying to write here, so let's, instead of going to the real path that they're trying to write to or the real file that they're opening, let's redirect that into the sandbox location. So as I said, so write file will get called. It'll get into, it'll get hooked, right, because we know the address. It'll go into the full, the Bini system handler, grab that handle and then write anything that we're writing to the file. And then we'll be able to get the file, it'll actually just redirect it to these bits. And then it'll just return however many bytes were written successfully and then the malware really doesn't know any different. And here's a little screen shot of that actually happening. So of course the two highlighted lines, the first one actually, you know, create file and we're getting, you know, the actual file and the path that it's located and the permissions. So this is super helpful when we're doing data analysis later because we're capturing all of this data. And this is the more of the human readable form if you're running in manual mode. There's also a dash J option where we can get all of this in JSON. So that's part of our ingestion pipeline. But the important thing here is we know the path, right? We know the permissions and then we know the return value. And the return value is the handle. So the malware actually gets a valid handle here, right? It doesn't get a negative one. So the malware is like, okay, yeah, we're good. So we're going to continue executing. We're not in a sandbox. And then at the end there, the last highlighted line is write file, right? So now we're, the first parameter here is our valid handle and then we know when we hit write file, Bini's going to execute or intercept that call and then we're going to be able to get the code and then run its implementation, its full hook. And then of course we're going to return a valid output for that which is going to be the number of bytes written. And then again, the malware, you know, doesn't really know any different. So just, you know, in the console, you know, you can LS the file and everything goes to this temp directory. You know, we created a mal.exe, mal file.exe. This is not a valid exe, of course. And then we just catted the bytes. So we can actually, this was kind of like, when we saw this, we're like, all right, yeah, we can definitely, you know, we can definitely do something with this. And of course this is a very trivial example and we'll show you how to do that. But we'll show you some more in the demos of real malware. So, you know, we're just kind of continuing on. And this whole process is very iterative. We just get a new sample of malware and we kind of execute it, see how far it goes. And it's like, oh, now we need to implement the file system. Oh, now we need to implement this. So the next one that we wanted to implement or we needed to implement was the registry. And similar to the file system, every registry call is eventually going to, you know, drop into a system or into kernel mode. So we want to full hook all of those. And then when we full hook those, you know, we built a registry within Bini that has a bunch of helper methods for, you know, accessing the different keys in the registry. And then one cool thing about this is we made it, we wanted to mimic being able to load any value from your Windows registry into the Bini registry. We want to make that as seamless as possible. So if you just export, you know, from regedit, you can actually import all of that data or that file that it exports that you saved to disk. You can just copy and paste those into our configuration file and then Bini will just read those and load those up. So this is really useful if malware is dependent on certain keys or you're trying to, you know, evaluate what it's actually storing in some keys. And then you can toggle these in kind of a real time and it's very fast. So, you know, all registry keys are going to, you know, get hooked. It's going to get into the, you know, the Bini subsystem for handling registry. You know, do whatever option or whatever function that that's required. And then just return valid data back to the malware. And again, the malware has no idea. So the next thing we want to do is configuration files. And as I mentioned, you know, these are directly copied. The registry keys here are directly copied. So we want to make sure they're copied from regedit, from the export. And then inside of Bini's registry, there's a handler that converts these to bytes for whatever the proper type is. So we've kind of abstracted that away so you don't really have to worry about that in the hook. And that will just copy the bytes back into the emulator and it just works, you know, as you would expect. And the other thing to note and kind of one of our requirements was this configuration file needs to be, you know, very easy to edit and very easy to understand and kind of all inclusive. So I've just kind of cherry picked a few values here. But, you know, there's obviously a lot more. The root file system, so this is how you would define where the actual files are located. And this is typically where we put all the DLLs in, like, NLS files and, you know, other files that we want that are supporting the execution. And then you can also have, like, code page identifiers. You can have, like, process IDs. You can have pretty much anything that would go in the TIB or the PEB or that would help the execution of the sample would go in this one file. And then, of course, the registry, you can just define it like this and it will parse everything properly and build the tree. So it's, you know, pretty efficient access. So, again, another quick sample. Looking at the registry key, we have three, you know, highlighted rows, you know, access to the registry key. You know, we get great insight into what's actually happening. And these are kind of the IOCs that we really want when we're doing some of our machine learning. And then, you know, the query of the values, you know, we can look at the particular, you know, the value name. And then next we can see what's actually getting set into those registry keys. And because this is, again, all returning back successfully, the malware doesn't really know. All right. So now that we actually have, you know, a few subsystems, we have file subsystem, registry subsystem, we have configuration files to kind of back all that up, we actually started running this against more and more samples. And we were finding some interesting results. In the case of a few samples, we were hitting some interesting threading stuff. And in some cases, we weren't actually doing anything with threading. And we wanted to. Bini, you know, by nature, because it's an emulation, didn't have any sort of thread management, so we actually implemented a thread manager. When we actually implemented this, we kind of treated it as like a global interpretation lock. So it's basically just a round robin scheduler. Everything is single threaded. And we time sliced out each of the threads. So, you know, it'll ‑‑ a certain thread will run for a certain instruction time. So say N instructions. And then it will move on to the next thread. And we can kind of hand wave away most of the threading issues that we were running into. And from there, we can actually allow malware to run through the thread. And when you think about what a malware actually wants, it just cares that there's threads running. And it didn't get an error with a thread, right? As long as it got a successful return value out of create thread, it just assumes the thread is running. And it's probably looking for information to be updated at some point. It doesn't really matter when. So that's where this round robin scheduler kind of really shined was because it was something so simple, but we were able to actually get stuff to run through completely even though it was multi‑threaded. And so here's just a quick example of that in action. Pay mostly attention to the left side of all those highlighted numbers. So in the numbers between the brackets, those are all the thread IDs. And this is like a standard output of all the function calls. So as you can see, as time goes on, the thread ID will change because we're context switching into a different thread. And then from there, it'll just kind of continue forward until it completes. All these threads are really doing and the highlighted lines are just creating threads and each thread is at some point printing something. So that's really cool. And you can actually see some of the print F stuff with the format strings right there. We have like on the first print F you can see like the percent D, et cetera. You can kind of see what's going to be put into that line when it's actually written to console. So another thing that we actually ran into when we were running samples against Bini was we saw some malware actually start dropping files. And in this case that would cause us to kind of pursue DL main stuff. And so we ran into a problem. And the first thing we saw was it was dropping DLLs to disk and then it was loading them up dynamically. And so we actually weren't doing anything with loading DLLs dynamically up until this point. In fact, we were just, all we were doing is just running a DLL, sorry, parsing a DLL and then while we were doing the parsing of the PEs. And then from there, it would, we would just kind of run it. We weren't actually running the DLL main of those DLLs themselves. So we actually went about trying to implement DLL main because that's something that's required for us to actually do the library properly and, you know, and we were able to do it. So, we were able to do it. And probably for implementing more stuff within the TIB and the PEB. In some cases, especially for some system level DLLs, it will actually populate some values for us for the TIB and the PEB. So we can actually go through and have those run and then it will populate most of those fields for us, which is great. We don't actually have to spend time with the fine tooth comb kind of going through and adding more value to those. And, you know, that would probably drive us crazy at some point. So what we ended up doing, we actually tried to do a lot of things. We tried to do a lot of things and we tried two ways of implementing DLL main. So for any DLL that we were loading up statically, as if we were pretending to be the loader, what we originally tried to do was just set the stack with the arguments that were required, set the entry point to the start of the DLL main if it did exist. If it didn't, we would skip over it. And then the return address from that would actually point to somewhere else in Bini's memory where we had actually put interrupts. And so the interrupts would pause the emulation and then we would then go and update the stack with the next DLL that needed to be ran. And then from there, if it also had a DLL main, we would just run through that again and so on and so forth. But it turns out that when we were actually pausing the DLL main, or we were pausing the emulator, it would actually kind of be a little bit more of an unclean state for the emulator itself. So we wanted to stick more to the press the button once when we're ready to go, load up everything ahead of time. And then we would then go and go. And the way we accomplished that is just through a ROP chain, essentially. So the idea behind this is that we wanted to set up the stack in a way such that when we actually started the emulation, the first entry point would be the first DLL that we needed to load. Typically this is NT DLL and then Colonel 32. So we would set the stack with the arguments that we needed for that and then we would actually put a return address on to the stack. But in this case, the return address for the first DLL is the same as the first DLL. It would be the entry point of the next DLL that needed to run. So we would just kind of keep chaining these together in the stack so that when we hit a return in a DLL, it would then pop the address of the next DLL into the instruction pointer. And then from there we can just go through all the DLLs until they're done. And then finally when we hit the last DLL in line, the return address for that will just be the entry point of the PE that we're actually testing against. So this was actually quite a great way to do it. We were able to hit the emulation start button once and then it was able to just continue through. And then we were able to just run the DLLs. We were actually getting some great results, a lot more fidelity, especially since we're having a lot more setup of the mock OS done by the DLLs themselves, which was great. And from there we could actually then take the same idea and apply it to, say, load library with like a full hook. We could then just obviously give it a few different arguments, argument values, and then from there we can do more from that. So I think that's about it. So yeah, now we have some demos. Let's switch over. Okay. All right. So the first, like, half of these demos are just kind of go through some of the, like, how you'd run this, like, at scale or how it would look at scale, I guess. And then we'll show some real malware. And I'll try and pause it. So in the beginning there's just, you know, there's a bunch of parameters. Probably the most notable ones are just the dash V and VV. Oh, yeah. So first one is, yeah, our API sets. So we just thought this was cool so we just added it in there. And it was super helpful when we were doing, when we were building this because, you know, we have to be able to resolve those quickly. But, you know, there's a verbose mode. So when you're doing verbose mode, like I said earlier, you'll get the instructions, which is, like, super helpful for R-ing things. But then if you do dash 2Vs, you'll also get the registers in the stack or at least a subset of the stack. And then there's another flag, which is, like, dash D. So you'll get the actual DLL that it's in. So you'll get DLL colon the function in the name. So just going through here. So this is a very simple kind of a printf example, basically, of a console application. And we actually start at the, you know, at the beginning, at the entry point, and we can go all the way through. And we're getting, you know, nice, you know, detailed information about the function parameters. So this is pretty cool where we're getting, you know, human readable stuff from like, as John was mentioning, like printf, you know, create file, write file. You know, we're getting really good data here. Let's continue forward. So now we're just showing some of the verbose mode. And again, so when you're doing the arguing of a piece of malware, like, having, obviously, the instructions is really helpful, especially when you're trying to manipulate the config file to maybe take a different branch. You can kind of just go through here and see what's actually happening after the function call, change and modify the configuration file, which changes the environment, and now the binary runs completely differently. And then, you know, we're getting a lot of data on here. We have the dash VV. Sort of the same thing, except, as I mentioned, you now will get the registers, and then a dump of the stack, as well. So useful, but not as useful as the other one. But it's interesting information, nonetheless, when you're particularly debugging by hand. So now we'll get to the need to know what the actual API set was. This is the reason we actually implemented the API set, the dash A and capital A within BINI because we were getting a lot of this and we need to know what API set is that, what DLL is that, what's the function we need to look at to see if it's a full hook or a partial hook or something like that. All right. So this is kind of looking at the data, create file, write file, you're getting all these IOCs, you're actually seeing what the malware is doing without actually executing anything. Okay. So this is a key piece right here. So the dash J flag, it converts all of this to JSON. So when we put this into our cluster and we get all of our samples, this is what we're getting back. So then we go through and we can parse these for all the different interesting functions that we're looking for. So in this case, we're looking at write file and we get the interesting part here is we get the parameters, right? So you get the string value of the parameters and then you also get the values that's being passed to it, right? So you'll know exactly what's happening. So, you know, this function is slightly less interesting but the malware that's coming next is a little bit more interesting. But again, you can parse all that data in real time and we can do this, you know, we can actually do this at scale because this will run, you know, it'll run on Linux, it'll run in Docker and it'll also run on Linux and it'll run on Docker and it'll run on whatever, you know, your function as a service is for your cloud provider. You know, so again, threading is, this is actually sort of simple to implement but it was really cool when we actually got it to work. It was just one of those kind of aha moments. All right. So now for some real malware. I'll pause it here quickly. So this first case is from the, I believe it's the orange worm variant, one of their samples and, you know, this would run all the way through and this is part of that family. I think there was maybe 30 samples in that family. And the interesting thing here is, you know, we get the, you know, we get the IOC so we know what service is actually trying to start. And we can do this without actually even running the sample. So now we know where to look if we're hunting, you know, in your environment and you're looking for a particular server or you're looking at a particular malware and now you can see some of these IOCs so now you can hunt in your environment and figure out, you know, where these things actually are. You know, and additionally there's this get proc address. So this is useful for getting around like some obfuscation and some packers. You know, if they hide all the, you know, from the imports table, you know, they are not going to get that statically but you can get that now dynamically. And this is a pretty useful feature for any of your statistics. So this next one, this was an interesting sample because basically it has multiple layers of packing and unpacking. And what it does is, you know, effectively, I like this. So this is particularly interesting because now we're getting, this was hidden previously by all of the, from the static analysis because it wasn't in the import table. But now we're actually getting this in real time. So we can add these to our. To our machine learning model and say, hey, this thing actually does use these imports. These are the functions. These are the names. This is the DLL. And then additionally you can see like actually right below it, you know, we're getting registry values. We're getting registry keys. But what's interesting about this sample is, you know, it's completely packed. And then what it also does is it unpacks a DLL in memory. And then it writes it to disk packed. And then it loads itself and then unpacks it again. And that's kind of this part where it's, you know, read file. So now we're getting all this. So we actually get the DLL that it's dumping. You know, we get the file name. You know, the naming scheme a little bit. And then, you know, again, you know, we can see the load libraries. We get proc address. You know, we're getting all of these IOCs. Now we're adding these. We're tagging this binary in our ingestion pipeline with all of these new IOCs. And then we're actually able to collect new ones. So now we have a new DLL. This thing was written to disk. But it was written and it was redirected into our temp location, our sandbox location. And now we can look at it later. So we're open sourcing it. Sorry. Quickly, we had a couple things that we want to work on next. But, yeah, we are open sourcing it. So we're more than happy to help anyone get involved and get started. So these are some of the things. So thank you.