So it's 20 minutes. There's a lot of information. There's links in the slides at the end for, well, the whole version. Thank you all for coming. Table of contents for today. We'll be looking at Ghidra and some related info to that, mostly. So first I'll introduce myself and then I'll give you some background information. We'll go a bit more into the nitty gritty details and I want to end a bit with the methodology and then in the end there might be time for Q&A. If not, find me afterwards or run to a microphone if there is time. So my name is Max Hersta. I go by the nickname of Libra. I work for Trellix within the advanced research team. We do research into all kinds of malware related things that can be something new, can be a trend, can be anything that piques interest. And one of the things we do is outreach and share that with the community such as, here. Now, the talk itself is about symbols or rather the lack thereof in binaries and how to recover them, right? But before diving into that, I want to share a bit what is a symbol and this slide should show you exactly what it's not, right? So a symbol is normally the function name from a reversing perspective and normally when you have symbols they should be recognizable, they should be self-explanatory and it should be unambiguous. Unlike the symbols I used here, this would be more useful for you to recognize something with. So binaries consist of multiple types of code. Now, this is no official definition but it's more to what I adhere to and it will make more sense down the road. So in terms of types of code, I'm going to be making a difference between the runtime, libraries and user code. Now, there's some gray areas in between, it obviously has room for discussion but in this case the purpose is mainly to focus on the big aspects that they each have, right? So for runtime, I'm going to use Golang as an example. The runtime is statically compiled within your binary or at least the part that you use, meaning that if you have 10 different Golang binaries of the same Golang version, you will have a lot of overlap of code. Now, that's not to say that those 10 binaries are related to each other other than the fact that they share the same Golang runtime. But if you have zero functions or function names within your binary, it's kind of hard to find out what the function does even though your tools might say there's overlap. Now, the same kind of goes for the libraries but libraries might give you more of an indication, right? If you're searching for a specific version of a library or if you're tracking a piece of malware based on the library that they use, you might be very interested in the library but to do so you would need to know where to find it and what library is included. And then as a last part, we have the user code and the user code would be anything that the user writes. So the user code generally calls functions within the runtime and the library or consists of purely user code itself, right? You make a minimalistic C binary and you use no external software then your binary will be very small and you'll just have your user code. Now, the user code is obviously of interest from my perspective as a malware researcher because if I can find that in other binaries, it will tell me that this is likely a shared piece of code and the user code is generally relatively unique to the extent that we can say these binaries overlap. So to recover symbols, we have multiple ways and three of them are what I'm going to be focusing on. So you have metadata in your binaries that you might be able to use. Golang is another great example of this where you have the PCLN tab and the information within so you can recover the function names. Obviously, using this is of great benefit. However, not all binaries have this. You have a stripped C++ binary, you're going to have a hard time, right? Now, Ghidra has two features that you can use to recover symbols. One is specifically made for this, which is function ID. For those using IDA, that would be flirt signatures, but then Ghidra is equivalent. And it has a hash of a function and a function name. So it hashes your function, cutting some corners here, but the gist of it is that you have a hash and if the hash is found in another place, you can compare the hash and take the name from the mapping that you already have. And then there's bsim, which stands for behavioral similarity. This was recently released by the NSA, recently being the day before last Christmas. And what you can do is you have the decompiler, produces intermediate language called p-code, and based on the high p-code vectors and some other things are calculated, based on which you can find functions that overlap code. Within Ghidra, you have the advantage that you have the decompiler of your match and of your original function side by side. So say you're patch diffing a file, you can very nicely see the differences. In order to do that, you do need to retain access to the Ghidra project and the files therein which you're using, or where the match is found as well as your program that you're analyzing. The script I have is kind of shoehorning that where we do not use the last part, meaning we have less data required and we can also automate the process because in the end it's code that you can use for this. So for the function ID databases, I wrote a script that you can automate. First the ingestion, you can run Ghidra headless to just import your files, and then this script will make for each unique architecture and what Ghidra calls a language ID, it will make a different function ID database that you can use later on. A language ID, very briefly put, is a PE file, 32 bits, for Windows for a specific compiler, and then we do that for each. This allows you to have the files that you can share with colleagues, either internally or externally, and this is the quickest way of recovering the symbols. As a case study, I have a Qubit Stealer sample which is Golang-based, and it has a lot of functions, but it has no real names, and we'll get more statistics on this in a bit. But just to showcase function ID, the first top screenshot is a screenshot that is post-default analysis from Ghidra. Right, so it just has fun underscore, which is the equivalent in IDA of saying sub underscore. So these are just functions that have no names. Now in the bottom screenshot, we can see that the P256 sub-internal function has been recognized and subsequently been renamed, which saves you time as the analyst, right? This is part of your default analysis, because the function ID is an analyzer which runs within. For the sake here, I first ran it without the function ID library which contains these functions, and then the one after. So for bsim, I already mentioned it's a bit shoehorned, because we're not going to be using the GUI to do this, and we're also not relying on the fact that you need access to the Ghidra project. Meaning that if I make a bsim database and I give it to you, then you can still use those databases with this script, even though you do not have access to the Ghidra project and the files therein, which I used to create it. So these are, along with function ID databases and some more information, all available on GitHub afterwards. So it's not necessarily using bsim as intended, but since the screenshot on top is relatively readable, I think, on screen, you can see that it has a function name, which is within the fdesc, right? Function description XML object. And within there, you can see that there are some vectors and calls being made to other functions, which is what bsim uses to identify this. The fact that you can automate this doesn't mean it's fully magically working for you. You still need to specify what your threshold is for the similarity, which is a value between zero, meaning no overlap, and one being an exact match. You also need to specify how many results do you want from the bsim database to match or to be collected for use, right? So you can do one, meaning if you have the first match it finds, it will say, well, it's this. But especially if you're not relying on an exact match, but rather, say, 75% or more of overlap, you might be interested in what other functions might be matching as well. Now, obviously, if all those functions have the exact same name, it's pretty clear that based on the database that you use, there's only one match. But you can also have the case that you have multiple functions, different names that match, which requires you to do a bit more research. To automate this in the script, you have identical matches. So these are renamed as is, right? Identical meaning there's only one name matched, even if you have multiple functions. The information, the metadata that's still available in the signatures is added to that function within Kedra. And it will show you the original file, the similarity for the match based on the function you're looking at. The significance, which tends to be based on your function size. And the architecture, right? It should only match the architecture that you have, though bsim has specifics. So since it's based on a decompiler, you can make databases that are known specifically for the bitness of your architecture. So say you have a Intel-based binary, 132-bit version and 164-bit version. The size of an integer, for example, is different, right? It's four versus eight bytes. What you can tell bsim to do when making the or importing the signatures in a database is you can give it a no-size database, meaning that it will ignore certain values and allow you to find matches of code from a 64-bit binary in a 32-bit binary or vice versa. So the information here will allow you to more accurately decide if this matches. And given the original file name, right? This says empty project go 1.9, for example, and you can see 1.14, 1.13. So these are the go versions where this function was also found in when making signatures. So this gives you an indication as to which Golang version it might be. And it will also tell you it's a Golang function on its own. Obviously, the original file name is based on what you use as a file name in Ghidra when making the signatures. So if you give it useful names, that's great. If not, then it might not be as great. Having said that, there's also a generic match, right? Because we want to automate this. You can have functions with thousands of, well, unknown functions within your binary. So there's also what I call a generic match, meaning there is more than one unique name that has been returned from the database. Now, not renaming these at all will not help you, right? Because you can make these databases for very specific purposes. Say, right, this is my database for the Golang runtime. Then any match that I have based on my similarity threshold will be Golang runtime related, or at least be very likely to be related to it. So in this case, we have two functions and we can see that the package name within Go has changed over time. Yet the function name itself is the same. Now, obviously, we could add a lot more logic as to how do we identify this between strings. But that is a future work. But also kind of depends on what you're using, right? If it's multiple versions of the same runtime, that works. But maybe you have a database where you put in not only Golang, but a lot more. It gets a lot harder to do the differentiation. So instead, I opted to rename all those functions that match generically with a prefix. And you can provide this prefix when running the script headless so that any match is then renamed. And if you run it over multiple databases, right? So the script, unless you change it, uses only one database at a time. What you can do is simply provide the prefix. And any function that has the non-default function naming scheme is not included in subsequent runs, right? So if a function starts with fun underscore or thunk underscore fun underscore, it's included in the search. However, if you have this function right now, it's Golang underscore whatever. If I now run it on another database I have for bsim, then this function is not going to be included anymore. So your subsequent runs will A, be faster, but also likely more accurate depending on the order you run it and how you structure your databases. So to continue with our case study, we have the top screenshot, which is after function ID, right? And I would recommend you first run function ID because it's faster and it is designed literally for this purpose. And bsim is a bit misused for this purpose, yet it works. And then we see in the bottom one, we see that the different functions are now renamed to Golang underscore, right? So these are all generic matches. Now looking at this function, and it's a bit of a spoiler alert, it is just a function within the Golang runtime that I used as an example. But you would also guess that it is, given that there's only calls to the Golang runtime within. So aside from making these scripts, I decided that making this invoke would A, be a good test case, but it would also save CPU cycles for others as soon as we share this, right? So I downloaded hundreds of gigabytes of benign binaries, mostly runtimes and libraries, compiled them if need be. And I ended up with 117 gigabytes of signatures for bsim. And the data doesn't necessarily say much, but there's not a lot of exact details I have for the bsim part. I do, however, for function ID, because you get a lot of detailed information in return. So 60% is Golang based as to what I created. And then we have 35 related to Boost, right? The C++ library, which contains a lot and it's used a lot. And then there's, well, other. Now, what is other? You might ask the 5%. So here I have the signature generation with the unique number of signatures within each. So for Golang, that was any runtime available that I had at the time. For Boost, it's roughly the last 10 years of Boost. And then we have, say, LibXML, OpenSSL, other libraries that are used. Now, depending on how big they are, you have more or less functions. But overall, this is, well, I would say a decent amount of functions that now you don't have to reverse or make signatures for anymore. So to put that in a broader perspective for the Qubits dealer, when you do the default Gitter analysis, it will find 2016 functions, out of which one has a name, right? The entry function. If we then run function ID, one function is merged, right? The total goes down one, but we recover about 40% of the function names. If we then use bsim with a 75%, right? 0.75 threshold for similarity, we recover another 16%, leaving us at 58. Now, that doesn't necessarily sound too much. So why is that? Now, we had access to the Qubit dealer source code, and it imports a library. And there's no signatures for Golang libraries in this corpus. So if you make this, you will have even more matches. So as a methodology, I would suggest you use, feedback is obviously welcome, that you identify metadata within the binary if you can. You can utilize that if you find it. You want to identify the runtimes and libraries used within your binary. You might need to make signatures for them if you don't have them yet, right? Maybe you identified something. So you first make the signatures, you apply them, and you do that process both for function ID and for the behavior signatures. Once that's done, you can have any other further logic that you can use, right? A lot of people are using LLMs to help rename functions without looking at them necessarily. So you can apply more scripts. And you can all do this from importing a binary, running function ID, bsim, and your other logic within the headless execution. So essentially, you can do that at night. When you wake up, everything is ready for you to analyze. That leaves room for questions. There's two minutes left. Either ask them now or find me off stage. The GitHub link here, I will activate them after the talk, has the GitHub scripts for this talk that I created. It has function ID databases and it has the bsim databases. Additionally, there is about 66 gigabytes of Golang binaries. It's an empty main function and contains the entire runtime of that version. And if you want to make signatures, play around with them, then feel very much free to as well. So the URL is at the top and then you have the slash for each of the sub options or just go there and find the repositories. Thank you very much. You have a microphone in the front. All right, if you just shout, I'll repeat the question. So the question is, how good is bsim when matching functions compiled with different compilers? I haven't tested this myself. It's a relatively new feature within Kedra. I think it does relatively well because it uses the decompiler. Some of the abstractions are moved away. And I think it also depends if Kedra knows the used calling conventions and such. Hi, so in a similar vein, how do you deal with different compiler options? Things like f-function sections, all the moving symbols around. What of those kind of break this process? Yes and no. It's the standard engineering answer, right? It depends. So if you say, use an unoptimized compiler run versus a very optimized, you will have differences in code, meaning there's differences within the signatures as well. For bsim, it might break it because it does match certain things. But if the match isn't matching well enough, it will not find a hit. For bsim, you can tweak how much it should look alike. If you are aware that something specific is used and you have a database for this, it might help. But if it changed too much, then you need to lower your threshold too much and you will probably get too many hits to make sense of it. So I think the best option is to compile the target libraries in all options and then make signatures for all, which is obviously a lot more work. But I think that is the most accurate option that you have. Thank you. All right. Thank you very much.