text
stringlengths
0
2.35k
[1021.04 --> 1024.16] to store something else later, which makes total sense.
[1024.16 --> 1026.24] I mean, do not use more memory than you need to, right?
[1026.24 --> 1028.72] But the Go compiler is totally right in doing this.
[1028.72 --> 1034.00] But for me, it's really, really a problem because what I do in IDA Pro is I try to figure out where
[1034.00 --> 1035.84] the local variables are in the stack.
[1035.84 --> 1039.44] I name those positions by saying, okay, this is the error variable.
[1039.44 --> 1044.72] This is the, I don't know, this is the integer that represents an iteration count or whatever.
[1044.72 --> 1047.36] And I name or rename everything I can.
[1047.36 --> 1052.48] And then eventually stuff starts to make sense because I know what represents what on the stack
[1052.48 --> 1054.88] and I know what the variables are, et cetera.
[1054.88 --> 1060.08] But the thing is, if one position on the stack does not consistently represent a specific variable,
[1060.08 --> 1062.00] then I cannot rename things anymore, right?
[1062.00 --> 1063.60] There's just no way for me to do this.
[1063.60 --> 1068.08] And the tools that we have, such as IDA and Pritcher Ghidra is going to function the same way.
[1068.08 --> 1072.88] It's not going to allow me to say, okay, up to this point, this variable should be named like this.
[1072.88 --> 1077.92] And then from there on, then it should have another name and then yet another, et cetera.
[1077.92 --> 1082.88] So this is like a very, very difficult thing for us is that, you know, trying to track down variables
[1082.88 --> 1086.64] and return values, even arguments is something extremely complex.
[1086.64 --> 1090.32] And basically this is the normal flow of how you analyze a program.
[1090.32 --> 1094.16] You try to figure out what the variables are, try to look at the functions and how they are called,
[1094.16 --> 1095.60] what they return and that kind of stuff.
[1095.60 --> 1100.08] And just, you know, doing those simple things that would be the basic operations and building blocks
[1100.08 --> 1105.12] of trying to understand what is going on in some random program are in themselves,
[1105.12 --> 1110.88] extremely complex operations due to like optimizations that were performed by the Go compiler.
[1110.88 --> 1116.00] Now, the last thing I can mention is that since version probably 16.1 or something like this,
[1116.00 --> 1120.08] or 1.16, I guess, in Go, the calling convention actually changed.
[1120.56 --> 1125.36] And they do things even smarter now, which is pass some arguments through the registers and not through
[1125.36 --> 1129.36] the stack. So for me, it doesn't change that much. Actually, it makes things a little bit easier
[1129.36 --> 1133.44] because at least, you know, I know argument one is in ECX, argument two is in EDX from memory.
[1133.44 --> 1137.52] It might not be that one, but, you know, generally it's going to be in a fixed register,
[1137.52 --> 1141.04] at least for the two first arguments. And so I know where they are, but that's way better.
[1141.60 --> 1146.00] But, you know, overall, this doesn't change this bigger game of renaming things, which is not
[1146.00 --> 1151.04] possible anymore. And then when it comes to the quick and easy mode, which is, you know, getting my
[1151.04 --> 1156.08] super expensive IDEP Pro license that comes with a decompiler, then, you know, I just open the program,
[1156.08 --> 1160.24] press F5 and hopefully you can read whatever's going on in the program. Well, that just doesn't
[1160.24 --> 1164.08] work because, you know, the constructs that are generated by the Go compiler, especially,
[1164.08 --> 1169.60] I think when it comes to function calls, is totally alien to IDA. And, you know, every time you try to
[1169.60 --> 1176.16] decompile code that comes from the Go language, you just end up with something that makes absolutely
[1176.16 --> 1183.12] no sense. Because again, IDA tries to recreate pseudo C code and pseudo C code has just no way of
[1183.12 --> 1190.00] representing concepts like multiple return values or that kind of stuff. So this is the way that Go
[1190.00 --> 1193.44] breaks everything that we hold dear in the reverse engineering world.
[1193.44 --> 1198.56] For anybody who didn't watch the video or is not familiar with how to do reverse engineering, I can,
[1199.28 --> 1204.96] in simple words, say that roughly you look at the instructions and then you try to kind of see
[1204.96 --> 1210.56] entry point is usually main. So this is probably function main. This is one thing that's being returned.
[1210.56 --> 1216.08] And then you kind of try to follow that. Basically, this is what you do when you reverse engineer.
[1216.08 --> 1221.12] Yeah. Actually, maybe I can say a few words about what reverse engineering is for people that, you
[1221.12 --> 1226.24] know, might not be familiar with it. The general idea is that we try to understand what a program
[1226.24 --> 1230.64] does, even though we do not have access to the source code. But this is the typical case for malware,
[1230.64 --> 1234.64] because, you know, we cannot call up malware authors and tell them, okay, please show me the code,
[1234.64 --> 1238.16] because I don't really understand what's going on there. They just, we don't know where they are.
[1238.16 --> 1242.64] They don't want to be found and they don't want to give us their code anyway. So what we have to do
[1242.64 --> 1248.16] then is like, we have no other solution, but to look at the program and see what instructions the
[1248.16 --> 1254.08] program is sending to the CPU and then try to figure out from there, based on those instructions
[1254.08 --> 1260.00] that are working at the CPU level, what the higher level line of code that might have generated this type
[1260.00 --> 1265.04] of instruction might have been. So it's not really, it's not entirely a guessing game because it's sort of a
[1265.04 --> 1271.20] mostly exact science, but also it's a very unnatural operation to perform because this
[1271.20 --> 1277.68] CPU language was really made for CPUs and machines. And for us humans, like it's extremely difficult to
[1277.68 --> 1282.32] understand. Like it's really, it's really not something natural for human beings to read that,
[1282.32 --> 1286.96] those instructions. It doesn't make sense to us. And it really requires a lot of effort to figure out
[1286.96 --> 1292.16] what the programmer intent was just by looking at those instructions. And so this is why actually we are
[1292.16 --> 1296.72] looking for reverse engineers. I mean, not just at Kaspersky, just the whole industry is looking for
[1296.72 --> 1301.60] people that are able to do this because it's something that is, that most people find unpleasant.
[1301.60 --> 1305.68] And I have to say myself, I do find it unpleasant most of the times, but you know, at the end of the
[1305.68 --> 1309.84] day, when I am able to figure out what was actually happening in the program, I feel very good about
[1309.84 --> 1316.32] myself. And so this is the reason why I still do this job, but overall, this is kind of a difficult
[1316.32 --> 1321.52] thing to do and it's kind of painful and takes a lot of time to be able to figure out even the
[1321.52 --> 1324.88] simplest programs. Especially when the tooling is not even there for you.
[1324.88 --> 1331.68] Yes. Just for some reference, like the ratio between lines of say, Go to assembly,
[1331.68 --> 1335.84] do you know what that ratio is? Just like a rough, it's like one to a hundred, one to a thousand, one to...
[1335.84 --> 1339.04] It's a good question. It would depend on the complexity of the line. You know, in Go, I'm
[1339.04 --> 1343.44] pretty sure that you can do function calls that are chained together in a pretty like in long lines.
[1343.44 --> 1348.24] Maybe I'm not sure if it's like the compliant to the official Go styling code or something like this,
[1348.24 --> 1353.44] but if you were to do this, then you would have a... I mean, let's take it from the other way. If you
[1353.44 --> 1358.40] have some normal looking Go code, like a hello world or something like this, it would probably translate
[1358.40 --> 1364.32] into 10 or 15 lines of assembly. So I would say the default would be 15 lines of assembly for one
[1364.32 --> 1371.12] line of actual Go code. But then if you get up into lines of codes that are a bit more complex or that
[1371.12 --> 1376.16] check or that return multiple return values or function calls, then this can get a bit bigger,
[1376.16 --> 1380.16] but this is still going to be the right ballpark. Okay. Yeah. That gives me a good idea.
[1380.16 --> 1384.32] What is it for other languages? Like, is it a lot more? Is it a lot less? Is it roughly the same?
[1384.32 --> 1391.60] I would say it's probably going to be mostly the same. C++ tends to be very, like, tends to
[1391.60 --> 1397.60] generate a lot of codes. It's very comparable to us to Go. C might be a bit more direct. Like the
[1397.60 --> 1402.72] translation between C and assembly is going to be a bit more, how would I say it in English? The
[1402.72 --> 1407.76] correspondence between C code and the assembly is going to be a bit more direct. That's it. But
[1407.76 --> 1413.36] otherwise I would say this is like a common ratio for languages. The problem is not that Go generates
[1413.36 --> 1417.60] more assembly. The problem is that the assembly generates, like, is not the one that we are used
[1417.60 --> 1422.56] to seeing. And we don't like that. Interesting to see if in one or two years from now, it will be more
[1422.56 --> 1428.64] supported and more pattern recognition working. Well, that's the thing, right? It kind of depends on the
[1428.64 --> 1434.48] attackers. Like, if we do end up seeing more and more Go tools out there in the wild, then there
[1434.48 --> 1440.96] is going to be pressure on the tool authors like IDAF, like Ghidra, etc. to implement better detection
[1440.96 --> 1445.52] and, you know, better support for those languages. I'm pretty sure that since last time I tried using
[1445.52 --> 1450.96] the compiler on some Go program, IDA has made improvements and it's probably not as broken as it
[1450.96 --> 1456.56] used to be. But if you keep seeing offensive tools running in Go, then I'm pretty sure that the tools will get better.
[1456.56 --> 1461.76] We will still have to figure out how the Go assembly works, especially if it changes again in the future.
[1461.76 --> 1466.48] But overall, at least the support in the last years has improved tremendously.
[1466.48 --> 1472.24] And I think it will continue to do so, although also in the future, if there is a need to. And I would
[1472.24 --> 1476.40] guess that Go is only going to become more prevalent when it comes to offensive software.
[1476.40 --> 1478.08] Because of all the reasons that you mentioned.
[1478.08 --> 1479.84] Yeah, exactly.
[1479.84 --> 1485.92] Some specific questions. You mentioned that you were kind of thinking out loud about the behavior you see
[1486.56 --> 1492.88] in IDA Pro when you were looking at the Go code that you loaded there, or the binary of it that you