WEBVTT

00:00.880 --> 00:02.580
So it's 20 minutes.

00:02.900 --> 00:04.780
There's a lot of information.

00:04.840 --> 00:09.160
There's links in the slides at the end for, well, the whole version.

00:09.200 --> 00:10.460
Thank you all for coming.

00:11.280 --> 00:13.220
Table of contents for today.

00:13.220 --> 00:18.900
We'll be looking at Ghidra and some related info to that, mostly.

00:19.460 --> 00:24.080
So first I'll introduce myself and then I'll give you some background information.

00:24.080 --> 00:32.680
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.

00:32.680 --> 00:36.780
If not, find me afterwards or run to a microphone if there is time.

00:37.700 --> 00:39.220
So my name is Max Hersta.

00:39.220 --> 00:40.840
I go by the nickname of Libra.

00:40.840 --> 00:44.180
I work for Trellix within the advanced research team.

00:44.180 --> 00:53.020
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.

00:53.180 --> 00:59.240
And one of the things we do is outreach and share that with the community such as, here.

01:00.400 --> 01:08.740
Now, the talk itself is about symbols or rather the lack thereof in binaries and how to recover them, right?

01:08.740 --> 01:16.380
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?

01:16.380 --> 01:27.940
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.

01:28.460 --> 01:35.440
Unlike the symbols I used here, this would be more useful for you to recognize something with.

01:38.060 --> 01:41.620
So binaries consist of multiple types of code.

01:41.620 --> 01:48.660
Now, this is no official definition but it's more to what I adhere to and it will make more sense down the road.

01:48.840 --> 01:57.560
So in terms of types of code, I'm going to be making a difference between the runtime, libraries and user code.

01:57.560 --> 02:10.540
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?

02:10.540 --> 02:14.740
So for runtime, I'm going to use Golang as an example.

02:15.220 --> 02:29.260
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.

02:29.280 --> 02:36.720
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.

02:36.800 --> 02:47.140
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.

02:47.540 --> 02:53.100
Now, the same kind of goes for the libraries but libraries might give you more of an indication, right?

02:53.100 --> 03:08.280
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.

03:08.760 --> 03:14.620
And then as a last part, we have the user code and the user code would be anything that the user writes.

03:14.620 --> 03:22.980
So the user code generally calls functions within the runtime and the library or consists of purely user code itself, right?

03:22.980 --> 03:33.800
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.

03:33.800 --> 03:53.760
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.

03:55.160 --> 04:03.200
So to recover symbols, we have multiple ways and three of them are what I'm going to be focusing on.

04:03.200 --> 04:07.480
So you have metadata in your binaries that you might be able to use.

04:07.480 --> 04:15.020
Golang is another great example of this where you have the PCLN tab and the information within so you can recover the function names.

04:15.040 --> 04:17.660
Obviously, using this is of great benefit.

04:17.660 --> 04:19.860
However, not all binaries have this.

04:19.860 --> 04:24.880
You have a stripped C++ binary, you're going to have a hard time, right?

04:25.080 --> 04:29.980
Now, Ghidra has two features that you can use to recover symbols.

04:30.380 --> 04:33.700
One is specifically made for this, which is function ID.

04:33.700 --> 04:38.420
For those using IDA, that would be flirt signatures, but then Ghidra is equivalent.

04:38.940 --> 04:42.940
And it has a hash of a function and a function name.

04:42.940 --> 04:55.860
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.

04:56.160 --> 04:59.380
And then there's bsim, which stands for behavioral similarity.

04:59.640 --> 05:05.980
This was recently released by the NSA, recently being the day before last Christmas.

05:06.440 --> 05:21.680
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.

05:21.960 --> 05:31.700
Within Ghidra, you have the advantage that you have the decompiler of your match and of your original function side by side.

05:31.700 --> 05:36.660
So say you're patch diffing a file, you can very nicely see the differences.

05:37.940 --> 05:49.620
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.

05:50.780 --> 06:06.100
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.

06:06.720 --> 06:14.060
So for the function ID databases, I wrote a script that you can automate.

06:14.100 --> 06:29.740
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.

06:29.740 --> 06:40.060
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.

06:40.160 --> 06:50.100
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.

06:52.120 --> 07:03.640
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.

07:03.640 --> 07:11.940
But just to showcase function ID, the first top screenshot is a screenshot that is post-default analysis from Ghidra.

07:11.960 --> 07:17.940
Right, so it just has fun underscore, which is the equivalent in IDA of saying sub underscore.

07:18.180 --> 07:21.140
So these are just functions that have no names.

07:21.220 --> 07:30.340
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?

07:30.340 --> 07:37.180
This is part of your default analysis, because the function ID is an analyzer which runs within.

07:37.480 --> 07:45.400
For the sake here, I first ran it without the function ID library which contains these functions, and then the one after.

07:47.400 --> 07:56.980
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.

07:56.980 --> 08:11.460
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.

08:11.660 --> 08:19.640
So these are, along with function ID databases and some more information, all available on GitHub afterwards.

08:20.420 --> 08:35.160
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?

08:35.160 --> 08:37.860
Function description XML object.

08:37.980 --> 08:46.200
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.

08:46.740 --> 08:52.340
The fact that you can automate this doesn't mean it's fully magically working for you.

08:52.340 --> 09:02.860
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.

09:02.940 --> 09:13.660
You also need to specify how many results do you want from the bsim database to match or to be collected for use, right?

09:13.660 --> 09:18.540
So you can do one, meaning if you have the first match it finds, it will say, well, it's this.

09:18.820 --> 09:30.500
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.

09:30.500 --> 09:39.300
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.

09:39.760 --> 09:48.160
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.

09:50.420 --> 09:54.660
To automate this in the script, you have identical matches.

09:54.740 --> 09:57.060
So these are renamed as is, right?

09:57.060 --> 10:01.500
Identical meaning there's only one name matched, even if you have multiple functions.

10:02.680 --> 10:09.360
The information, the metadata that's still available in the signatures is added to that function within Kedra.

10:09.620 --> 10:16.240
And it will show you the original file, the similarity for the match based on the function you're looking at.

10:16.240 --> 10:21.220
The significance, which tends to be based on your function size.

10:21.220 --> 10:23.100
And the architecture, right?

10:23.100 --> 10:28.720
It should only match the architecture that you have, though bsim has specifics.

10:28.720 --> 10:37.160
So since it's based on a decompiler, you can make databases that are known specifically for the bitness of your architecture.

10:37.160 --> 10:43.820
So say you have a Intel-based binary, 132-bit version and 164-bit version.

10:43.820 --> 10:46.680
The size of an integer, for example, is different, right?

10:46.680 --> 10:48.340
It's four versus eight bytes.

10:48.840 --> 11:07.360
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.

11:08.820 --> 11:15.340
So the information here will allow you to more accurately decide if this matches.

11:15.400 --> 11:17.620
And given the original file name, right?

11:17.620 --> 11:24.080
This says empty project go 1.9, for example, and you can see 1.14, 1.13.

11:24.080 --> 11:28.760
So these are the go versions where this function was also found in when making signatures.

11:28.820 --> 11:33.400
So this gives you an indication as to which Golang version it might be.

11:33.400 --> 11:37.340
And it will also tell you it's a Golang function on its own.

11:37.360 --> 11:44.200
Obviously, the original file name is based on what you use as a file name in Ghidra when making the signatures.

11:44.220 --> 11:46.840
So if you give it useful names, that's great.

11:46.840 --> 11:50.580
If not, then it might not be as great.

11:52.020 --> 11:55.140
Having said that, there's also a generic match, right?

11:55.140 --> 11:56.540
Because we want to automate this.

11:56.540 --> 12:02.120
You can have functions with thousands of, well, unknown functions within your binary.

12:02.400 --> 12:10.800
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.

12:10.920 --> 12:16.220
Now, not renaming these at all will not help you, right?

12:16.220 --> 12:19.480
Because you can make these databases for very specific purposes.

12:20.100 --> 12:23.880
Say, right, this is my database for the Golang runtime.

12:23.880 --> 12:36.280
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.

12:36.380 --> 12:45.340
So in this case, we have two functions and we can see that the package name within Go has changed over time.

12:45.340 --> 12:47.880
Yet the function name itself is the same.

12:47.900 --> 12:52.260
Now, obviously, we could add a lot more logic as to how do we identify this between strings.

12:52.380 --> 12:55.340
But that is a future work.

12:55.400 --> 12:57.840
But also kind of depends on what you're using, right?

12:57.840 --> 13:00.640
If it's multiple versions of the same runtime, that works.

13:00.640 --> 13:04.860
But maybe you have a database where you put in not only Golang, but a lot more.

13:04.860 --> 13:07.180
It gets a lot harder to do the differentiation.

13:08.200 --> 13:15.000
So instead, I opted to rename all those functions that match generically with a prefix.

13:15.000 --> 13:20.580
And you can provide this prefix when running the script headless so that any match is then renamed.

13:20.840 --> 13:23.480
And if you run it over multiple databases, right?

13:23.480 --> 13:28.200
So the script, unless you change it, uses only one database at a time.

13:28.200 --> 13:32.840
What you can do is simply provide the prefix.

13:32.840 --> 13:40.360
And any function that has the non-default function naming scheme is not included in subsequent runs, right?

13:40.360 --> 13:47.500
So if a function starts with fun underscore or thunk underscore fun underscore, it's included in the search.

13:47.500 --> 13:53.100
However, if you have this function right now, it's Golang underscore whatever.

13:53.100 --> 14:02.360
If I now run it on another database I have for bsim, then this function is not going to be included anymore.

14:02.360 --> 14:11.600
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.

14:13.040 --> 14:19.660
So to continue with our case study, we have the top screenshot, which is after function ID, right?

14:19.660 --> 14:26.700
And I would recommend you first run function ID because it's faster and it is designed literally for this purpose.

14:27.440 --> 14:31.520
And bsim is a bit misused for this purpose, yet it works.

14:32.120 --> 14:38.940
And then we see in the bottom one, we see that the different functions are now renamed to Golang underscore, right?

14:38.940 --> 14:41.300
So these are all generic matches.

14:42.420 --> 14:50.520
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.

14:50.520 --> 14:58.060
But you would also guess that it is, given that there's only calls to the Golang runtime within.

15:00.080 --> 15:11.980
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?

15:11.980 --> 15:21.960
So I downloaded hundreds of gigabytes of benign binaries, mostly runtimes and libraries, compiled them if need be.

15:22.160 --> 15:28.750
And I ended up with 117 gigabytes of signatures for bsim.

15:30.900 --> 15:37.460
And the data doesn't necessarily say much, but there's not a lot of exact details I have for the bsim part.

15:37.600 --> 15:42.680
I do, however, for function ID, because you get a lot of detailed information in return.

15:42.700 --> 15:47.420
So 60% is Golang based as to what I created.

15:47.420 --> 15:50.120
And then we have 35 related to Boost, right?

15:50.120 --> 15:54.880
The C++ library, which contains a lot and it's used a lot.

15:54.880 --> 15:56.660
And then there's, well, other.

15:56.660 --> 15:57.580
Now, what is other?

15:57.580 --> 15:58.760
You might ask the 5%.

15:59.660 --> 16:04.920
So here I have the signature generation with the unique number of signatures within each.

16:05.080 --> 16:09.440
So for Golang, that was any runtime available that I had at the time.

16:09.440 --> 16:13.340
For Boost, it's roughly the last 10 years of Boost.

16:13.380 --> 16:18.800
And then we have, say, LibXML, OpenSSL, other libraries that are used.

16:18.880 --> 16:21.980
Now, depending on how big they are, you have more or less functions.

16:22.220 --> 16:30.260
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.

16:31.160 --> 16:41.900
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?

16:41.900 --> 16:43.080
The entry function.

16:43.740 --> 16:46.700
If we then run function ID, one function is merged, right?

16:46.700 --> 16:52.180
The total goes down one, but we recover about 40% of the function names.

16:52.180 --> 16:57.100
If we then use bsim with a 75%, right?

16:57.100 --> 17:05.140
0.75 threshold for similarity, we recover another 16%, leaving us at 58.

17:05.200 --> 17:07.840
Now, that doesn't necessarily sound too much.

17:07.840 --> 17:09.140
So why is that?

17:09.140 --> 17:16.380
Now, we had access to the Qubit dealer source code, and it imports a library.

17:16.380 --> 17:20.380
And there's no signatures for Golang libraries in this corpus.

17:20.380 --> 17:24.920
So if you make this, you will have even more matches.

17:26.000 --> 17:37.600
So as a methodology, I would suggest you use, feedback is obviously welcome, that you identify metadata within the binary if you can.

17:37.620 --> 17:40.800
You can utilize that if you find it.

17:40.800 --> 17:44.680
You want to identify the runtimes and libraries used within your binary.

17:44.680 --> 17:48.820
You might need to make signatures for them if you don't have them yet, right?

17:48.820 --> 17:50.240
Maybe you identified something.

17:50.240 --> 17:56.580
So you first make the signatures, you apply them, and you do that process both for function ID and for the behavior signatures.

17:56.980 --> 18:01.320
Once that's done, you can have any other further logic that you can use, right?

18:01.320 --> 18:05.900
A lot of people are using LLMs to help rename functions without looking at them necessarily.

18:05.900 --> 18:07.900
So you can apply more scripts.

18:08.080 --> 18:18.120
And you can all do this from importing a binary, running function ID, bsim, and your other logic within the headless execution.

18:18.120 --> 18:19.780
So essentially, you can do that at night.

18:19.780 --> 18:23.320
When you wake up, everything is ready for you to analyze.

18:25.080 --> 18:27.220
That leaves room for questions.

18:27.360 --> 18:29.340
There's two minutes left.

18:29.360 --> 18:33.460
Either ask them now or find me off stage.

18:33.600 --> 18:41.840
The GitHub link here, I will activate them after the talk, has the GitHub scripts for this talk that I created.

18:41.840 --> 18:46.220
It has function ID databases and it has the bsim databases.

18:46.220 --> 18:50.490
Additionally, there is about 66 gigabytes of Golang binaries.

18:50.840 --> 18:55.020
It's an empty main function and contains the entire runtime of that version.

18:55.240 --> 19:00.800
And if you want to make signatures, play around with them, then feel very much free to as well.

19:00.820 --> 19:08.970
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.

19:09.900 --> 19:11.280
Thank you very much.

19:33.310 --> 19:36.310
You have a microphone in the front.

19:44.380 --> 19:47.300
All right, if you just shout, I'll repeat the question.

19:52.280 --> 19:59.140
So the question is, how good is bsim when matching functions compiled with different compilers?

20:00.140 --> 20:02.300
I haven't tested this myself.

20:02.300 --> 20:07.400
It's a relatively new feature within Kedra.

20:07.400 --> 20:12.360
I think it does relatively well because it uses the decompiler.

20:12.360 --> 20:15.320
Some of the abstractions are moved away.

20:15.900 --> 20:21.260
And I think it also depends if Kedra knows the used calling conventions and such.

20:25.310 --> 20:31.270
Hi, so in a similar vein, how do you deal with different compiler options?

20:31.270 --> 20:36.310
Things like f-function sections, all the moving symbols around.

20:36.310 --> 20:39.230
What of those kind of break this process?

20:41.550 --> 20:43.290
Yes and no.

20:44.570 --> 20:46.770
It's the standard engineering answer, right?

20:46.770 --> 20:47.870
It depends.

20:48.090 --> 20:59.050
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.

20:59.050 --> 21:02.750
For bsim, it might break it because it does match certain things.

21:02.750 --> 21:08.630
But if the match isn't matching well enough, it will not find a hit.

21:09.030 --> 21:12.530
For bsim, you can tweak how much it should look alike.

21:12.530 --> 21:18.290
If you are aware that something specific is used and you have a database for this, it might help.

21:19.590 --> 21:27.770
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.

21:27.810 --> 21:38.270
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.

21:38.730 --> 21:43.290
But I think that is the most accurate option that you have.

21:43.710 --> 21:44.710
Thank you.

21:48.270 --> 21:48.970
All right.

21:48.970 --> 21:50.030
Thank you very much.

