Cyber Crucible logocybercrucible
Video

IUP Cybersecurity Seminar Advanced Track: How to Reverse Engineer Ransomware Protocols

Learn how Cyber Crucible engineer Kyle Newman dynamically reverse engineers the Dharma ransomware protocol, examining real cipher text, key blobs, AES-256 and RSA-1024 encryption, and its two-step scan-and-ransom process.

Webinars & Keynotes45:58

Transcript

From the video's captions, lightly edited for reading.

Okay, everyone, I think we, we should be fine. Now, for those of you who just, joined, I would like to welcome all of you to our session here. And this is our fifth, annual IUB cybersecurity seminar. It's, very special here. And, we, are so glad that you are joining, our, event here today on November 5th. Just a quick introduction. My name is Dr. Farag.

I am the director of the Institute for Cybersecurity at IOB. I'm also professor of computer science, here. This is basically part of just many activities and, project that we are involved with, in and, cybersecurity program here at Indiana University of Pennsylvania. I just actually send, to every, probably let send it again. I just send it to you all guys here. Lemme do it. A link to our, websites if you would like to, check that.

Also, we have a visual booth, as I indicated the, those you who will heal at the time. Many of the sponsors have virtual posts, so you can access this through your app, all your web-based, interface. So I don't want to take more time from our presenter here. So it's my pleasure to introduce my, our first actually, session here in some morning, at 10:00 AM the session will be delivered by Mr.

Kyle, a Newman, from Al. The title of the session is How to Reverse Engineer and Some Real Protocols. Please join me welcoming, Mr. Newman. Good, Mr. Newman, you have the floor. Yep. Thanks. So, lemme make sure, yep, I'm unmuted. Okay. So, where we're gonna be talking about reverse engineering ransomware protocols, specifically the Dharma ransomware in this case. And, I'm calling it a dynamic analysis, even though some people will have a little bit of a different definitions there.

But just to differentiate it from static analysis. So jumping right into it, kind of who am I, why should you care about what I'm saying? Kyle Neiman, I'm from Cyber Crucible, primarily I'm a software engineer. And recently people have been, kind of throwing around the term ransomware expert, but kind of what have I done to earn that title? Mostly since I'm a software engineer, I do backend development and mostly low level kernel space type development.

But previously I've done some threat hunting and along with that, malware network protocol analysis. So, normal threat hunting, you might be looking at like, IP addresses and basic information from alerts, whereas I would be decrypting TCP streams and breaking them apart to see kind of, what's going on, what commands are being sent, what, what data is being sent back and forth. That kind of evolved into ransomware analysis, which is what we're gonna be seeing here in these slides.

And of course, with the ransomware analysis, lots and lots of encryption is going on. So what specifically is this presentation about? Well, first of all, it's very technical and we're gonna have to go pretty fast because there's a, a lot of information here, and I don't wanna go over too much, since we had a very, a slight delay. So I'm just kind of gonna be going fast and I would ask, if you have a quick question, perfectly fine, please interrupt me.

But if it's something you think might take longer, if you wouldn't mind holding it to the end, just so that everyone can, get the full depth of the slides. We're gonna mostly be talking about an explanation of the Dharma ransomware and kind of, going along the story of, how I reverse engineered this. It's gonna be kind of the same questions I had along the way. Obviously very sped up because, we, we have under an hour, and I'm not reverse engineering ransomware is an under an hour.

It's a, it's a very, lengthy experience. We're gonna be using real ransomware samples. You'll see actual cipher text and key blobs. They have been edited, such that the keys have been changed, even though there's encrypted data. And the, the files I'm showing are gonna be like XML files that don't actually have any information in them. I changed them just so there's no complaints from a client that like, that looks similar to my data or something.

So if you screenshot all these slides and try to decrypt it, it, it won't work. But the protocol is the exact same. What are we not seeing here? No static analysis. I'm not gonna be showing screenshots of Gira or IDA Pro. It, this obviously isn't the secret to free decryption or a one size fits all solution for all ransomware, because we're talking about one specific protocol to this one ransomware family.

And obviously we're gonna be talking about encryption. And if you don't know much about encryption, that's fine, because I'll explain it, but this isn't a substitute for learning, all the intricacies that go along with encrypting data. So Dharma specifically, what is it, right? It's a Windows ransomware. It's c plus plus statically compiled, which means that we're not referencing system DLLs, and we can't just open API mon up and run it and see what libraries it's calling because it was statically compiled.

This also means it could bring its own encryption. It could be doing some weird obfuscation things. We, we don't know, right? 'cause it, it brought its own libraries. It's very strongly encrypted, and we know this after the fact, not going in necessarily, but it uses a ES 2 56 to encrypt the files and RSA 10 24 to encrypt the keys. This is generally what most people would call military grade encryption, right?

It's considered to be unbreakable. If you don't have, the key data, you can't just intercept it and brute force it. Dharma uses a two step process. So it uses a file scanner. You, you scan your system, you submit the output to the attacker, they tell you how much ransom to pay, and then they provide you with a decryptor. It's pretty straightforward as far as ransomware goes. And on the right you'll see some JavaScript.

And I kind of found this just while I was looking for Creative Commons images to use, but it stood out to me because as we know, most ransomware aren't written in JavaScript. And if we look at this code, it's actually just a nested for loop calling an HT TP get. But it, it kind of shows how uneducated people are that someone, hopefully not the person who wrote the code, but someone thought this was ransomware because it's source code, so therefore it's malware, right?

So if we look in the actual ransom note from Dharma, it, it's pretty straightforward, tells you how to obtain Bitcoin. Because the ransom is in Bitcoin, it warns you that your files are encrypted and you have a specific identifier. Email this email address for more information. Don't tamper with your files because any tampered files, they might not decrypt successfully, and the attacker is not gonna care about that if you send them corrupted data or if they're decrypt or corrupts your data.

They're just, you know, they got their money, so why would they care? So if you're not incredibly familiar with a ES, we'll go over real quickly. What it is a s is a symmetric encryption algorithm. The 2 56 in this case refers to the 256 bit key or 32 bytes. The, even though it's a 2 56 bit key, we're always doing with 1 28 bit block ciphers. So every block is gonna be 16 bytes regardless of the key size.

And like I mentioned, it's super secure, considered to be military grade. It's very fast and there are actually some a s block cipher algorithms that are considered even quicker than CBC, but it's still very fast. So on the right we'll see what goes into, A-S-C-B-C encryption. We have our plain text, which gets xor with an initialization vector known as an iv. Then that kind of goes into the black box of encryption with the key.

And out comes the cipher text. So with CBC, there's this chaining going on that's CB, C is cipher block chaining. And it will take the cipher text output from the first block and then use that as the IV for the next block. X orientate with the plain text and repeating. So what we actually need to decrypt A-E-S-C-B-C would be the key, the iv obviously for the first iv and then padding because since it's a block site for algorithm, we, we need to encrypt blocks at a time.

And since a block is 16 bytes, if we were only given 10 bytes, you, you're not gonna have a good time trying to encrypt or decrypt that. So you have to use a padding scheme to actually make that 10 bytes into 16 bytes and then reverse the padding on the other end. And the specific padding scheme doesn't matter as long as the encrypter and decrypter both know it. Some people will use all zeros, some people use, you know, four fours or five fives or f you know, ffs.

But as long as it's known. So that's, those are the three things we need to look out for. What is RSA right? Well, RSA is asymmetric encryption, meaning that, there's a private public key pair. If you look on the right, it's a little bit difficult to see, but the one key on the left hand side has a, a red lock. And the other key has like a greenish lock.

So meaning that, the message hello was encrypted first with the private key, the red lock transmitted a cipher text and then decrypted with the public key. So this is, a much slower encryption scheme and it doesn't require an IV just that key and a padding. But it's also very, very secure. So what dharma actually does, and what a lot of ransomware recently have been doing as they grow more sophisticated is encrypt the files with faster asymmetric or faster symmetric encryption, then encrypt that symmetric key with asymmetric encryption.

And this lets them use thousands of keys because one symmetric key per file, but then maybe a specific, single use asymmetric key for decryption. Incredibly secure, very sophisticated. So if we wanna actually jump into what this ransomware does, what it looks like now that we've talked about the encryption, this is an encrypted file. And this is a relatively small file. So we have on the left hand side kind of the top of the file, and then on the right hand side, the bottom of the file, and in the middle is just all cipher text, right?

We are seeing very high entropy data. It's randomized, seemingly as encrypted data is, but at the end, we might notice that, we're seeing a string, a human readable string. And that's actually the name of the file driver installation log txt. So that, that's great. That gives us something to latch onto. We know that there are pending data at the end of the file, at the very least, and then there's some more data after that.

But we see that there's some sort of zero delimiter, which is great. That shows that there's, the, the data after is definitely intentional, but the rest of the data is kind of, more, more randomized. We still don't know what it means. We can't latch onto anything. So the easiest thing to do here is compare it to another file. So on the left we have the file we just looked at, and on the right we have a new file, Fon zero ico, and same thing, end of the file, we see the, the string, that's the file name.

And, if, if you look a little bit closer, you might notice that this string BBB zero YI five is actually repeated on both of them in the exact same place right after the file name. Now, this has nothing to do with the encryption, more as it's an identifier for the, attacker to identify these encrypted files. But if we look even closer, we might notice that, actually it, it doesn't end at that human readable string.

This, this entire block here on both files is the same, starting with, in hex 4, 2, 5, 6, and ending with 4 9 1 F. they're, they're identical, right? That can't be a coincidence. So this is what we're gonna refer to as kind of the header of the footer of the file. It's something that the ransomware can latch onto to identify that this is in fact a encrypted, encrypted, file.

That this has actually been something hit by the ransomware and not just some high entropy executable, but after that, they differ, right? They go back to being completely seemingly randomized, high entropy. So, not much we're gonna do there. We're not gonna brute force it, but since I mentioned that dharma is a two stage type of ransomware, we can look at it and say, okay, what about that file scanner I mentioned, right?

So Dhar Dharma's file scanner works in an interesting way. You open the decryptor that they provide you with, you hit scan pc and you can't give it any arguments. You can't tell it network shares to scan or anything like that. Regardless of what the ransomware actually would've tried to encrypt, which would be everything that it had access to it, the scanning PC is only gonna mount your local drives because it actually turns out that mounting, any, you know, samba share any network accessible storage, doesn't matter.

Very difficult using the, the WIN 32 Windows API, there's not native, calls for it. So I guess the attacker doesn't care, right? I mean, why would they? So you hit scan pc, it scans your C drive, maybe your D drive, whatever you have locally, and it returns you a base 64 output, which, the person that took this image wanted to cover it up. But, we kinda wanna look at it.

So here's a base 64 output. This is a real output from the ransomware. And, we'll, we'll go ahead and decode it, right, because it's base 64. So plug it into Cyber Cheff, which is a great tool if you haven't heard of it. Can do base 64 hex encryption, zipping tons of stuff. Not affiliated with me at all, but I highly recommend it. So input the basic 64 output, the HEXA decimal, it's great.

More hexa decimal, right? Well, if we look at it again, a little bit closer, we might notice, these four byte long seemingly integer, right? Because, 32 bits, and they're kind of, padded isn't the right word, but they're, they've got zeros around them in a little Indian type fashion. So they're four bytes, little Indian, probably integers just based on, you know, historically, that's kind of what's gonna be stored there.

And they're relatively evenly spaced, right? There's one at the beginning of the file. And then the next two kind of have the same amount of data after them, it looks like. So, they, they have about the same amount of data after them. That's great. Now, if we split them up, same, same data here, just new lines so that we can look at it a little bit easier. It doesn't really provide us with any more information, but it gives us kind of things that we can dig at.

Like, for example, what is that BD 1D three CD one at the top? It's obviously not the same as the other integers because it's not some smaller little Indian number. Now, if you break everything apart, we can look at first the two is probably the, the first thing we should really care about because it's, it's just a two. That's a very small number. It's very direct, right? So it turns out that two is actually the counter of the number of blobs.

We see the one is highlighted in blue, and then the one below that, if there were three blobs, that would be a three. If there were, you know, 15, it would be an F. that's just the counter. So the next part, the BD 1D, that's where it gets a little bit weird. It's actually the CRC 32 of the remainder of the file. And you might say, Kyle, how do you know that, right?

Like, you can't just pull that outta nowhere and say, that's what it is. Well, we can put it back into cyber chef and we can actually see the output there is the same. And we'll notice again, since we're doing little Indian, the output's a little bit reversed as we'd expect, that that's great. That shows that I'm really not making stuff up. And it actually is the CRC 32 in little Indian form.

We can focus on each integer next that we are seeing, in front of every blob and realize that that's actually the file counter. So, if we had, in this case, one, two B and Hex is the number of files that we're encrypted, with this specific blob, and then knowing that, knowing that it's associated to encryption, we can think, okay, well we have eight rows of 16 bytes, eight times sixteens 128.

Well, that's, that's an RSA 10 24 key, right? So, so far we've already kind of figured out, we know how many files are encrypted, we know how many keys were used, and we know what the at least public keys of the RSA key pairs are. That's great because we're really pretty good progress into, figuring out this ransomware already. So if we wanna verify that it's RSA, and where did those blobs actually come from?

Because theoretically scanning your computer, right? We can go back to the encrypted file on the right, that driver installation log, and we can actually see this AA five C in blue is the same from that file scanner output as it is on the tail end of that file. And, you might say, you know, what about the a s key? And we're not quite there yet, but we know that it's RSA at this point, right?

Because of the, the key size, and because, we know this is kind of what ransomware has been doing recently, we can make this educated guess, that this isn't just some randomly repeated 128 bytes they're sending back to the attacker, right? It's gotta be an RSA key pair. And as far the other stuff that you might notice, I skipped around a little bit in the file, skipped like 16 bytes or so.

We'll, we'll come back to that, I promise. So it's r to say, right, what now? Well, it's, it's r to say, so there's no free to cry. We're not gonna be able to use a one size fits all type key. In theory, if some two attacks occurred with the same RSA key, you could only, buy the decryptor for one and apply that private key to both attacks. But, with an attacker that's this sophisticated, which we know at this point, they're at least somewhat sophisticated, right?

You're, you're gonna have to pay per incident because they're not gonna reuse the key. Why would they be using RSA if they were planning on reusing the key, right? If, if they were that far behind in times they would be using like a static xora key or something. And if that was the case, there would be a free descriptor. But we know they're a little bit more sophisticated. So we do have to pay, is the downside.

But the upside is that that counter for the files, so we know the attacker is sending himself back, the, the counter of the, the number of files that were encrypted per key. And we need that key because it's RSA. But, why would the attacker send themself back that data? They don't actually need it to decrypt the RSA unless, they're using it as a way to determine how expensive the ransom should be.

So in, in that case, should we cheat, lower the number of files? I mean, make it like something reasonable, right? Like a hundred, not zero, but, maybe not in the thousands or hundreds of thousands depending on, what kind of maybe server got encrypted. And of course they're hackers, so they have no ethics. Why should we? But, you need to be careful because if they catch on, they might just take your money and run if they realize you're trying to jerk 'em around and not actually pay because they seem to be kind of finicky and they want you to cooperate 'cause they want their money.

Now, of course, are you sure that you counted all the files as a good question because it's a little bit separate from modifying the data. Modifying the data is maybe you get a lower ransom, but, if you notice that you have an entire file server with thousands and thousands of files that were encrypted, but this counter here only says 20 files, then that's not all of your data. And you can't actually be sure that you picked up all the RSA keys.

So you're gonna need to make sure that all your volumes are mounted properly, the scanner actually has access to them. And in this case, you're kind of already deep in the reverse engineering side, so you could maybe plant your own files, see if they get caught, to make sure that there's, directory access. But, you, you really need to make sure that you've got all your files counted because, especially in the case of like maybe a na, right?

We mentioned, or I mentioned how, the ransomware does not do a good job at network storage. So if you had network storage get encrypted, but you don't hit it in the file scanner, then it's not gonna get decrypted, right? You need to make sure that you're scanning every computer and you could concatenate this, base 64 data together. If you need to scan multiple computers at once, it kind of goes against what the attacker wanted because they probably want you to pay five ransoms for five computers, but they're not necessarily gonna know.

It kind of goes back to the whole ethics thing. So what happens if you do miss some files, right? If, if I missed an entire NAS or just a partition, or even just single directory, if, if that directory happened to use a separate RSA key, you're not getting those files back. You just, you can't, right? You didn't get the public key to send to the attacker, they're not gonna send you the private key back and you're gonna have to pay again.

Once you realize that you need those data, because you're gonna send an email to the attacker, Hey, I was messing around with your tool trying to trick you and I missed a directory, and can I please have my data for free? And they're gonna say, absolutely not. Actually, the ransoms doubled, right? So, kind of already mentioned this, but hackers aren't forgiving. Shotgun blasting power is very easy, and mapping storage is hard.

So the mapping storage is the decrypting side. The shotgun blasting malware is easy, right? I mean, whether it's a phishing attack, an RDP, an actual zero day, SSH access, whatever, however they got in, they're gonna gonna blast their ransomware wherever they can. They're not gonna be as forgiving on the other side.

And then, just with, with the verifying the files one, two B oh one or, or, one two B, does it seem right? What if it said zero or zero F right? So now it'll be paid.

It's a good question about paying the ransom. Just really quickly, there, there has been some guidance, no laws that I know of about paying ransom as far as like, benefiting terrorism and things. You can't really know who the attacker is. And it probably, if it's, if you're that worried about it, or in most cases you might wanna contact, law enforcement, right? To get them involved because they might actually have an ongoing case against a certain attacker, and they might use this as evidence.

They might give you some guidance on what to do, but in a lot of cases, you'll find that you can't actually decrypt the data without paying the ransom. So if you're not willing to pay the ransom, you're gonna have to come to terms with losing that data. If you don't have, some offline backups that you can restore from, because online backups we've seen plenty of times, the attacker is just gonna encrypt them as well, or delete them or actually embed them with more malware.

So when you go to try to deploy them, you're gonna get hit with more ransomware or a rat or something. So we paid, now what, right? Do I trust the attacker? I I wouldn't personally, can they reinfect you like we just spoke about? Yeah, of course they can. Well, they, who knows, right? I mean, they could send you a decryptor with more ransomware and it, they could have already reinfected you. They could have put a rat or a root kit or anything they want on your system.

They had access to execute ransomware, they could do anything. So you need to thoroughly, investigate and do some, do some real rebuilding and real analysis on your systems before you just throw them back online, especially if they're production.

But, so we paid what are the attackers send back, right? If we didn't pay, we're getting nothing back. Like I said, you got, you got a deal, sorry. More basic 64, right? It's decrypted or decode it. We've, we've been through this with cyber cheff before, and it should look pretty similar, right? We've got this, counter at the top for two. We've got CRC after the counter, more, more data after that, right?

And we can see actually this, on the right hand side is the, file that we just received back from the attacker. And on the left hand side is the file that we sent. We can see these blobs, match, right? The, the RSA public keys. So that's good. They're associating what we sent them with, more data coming back. And then what actually is the data coming back, right?

We know the key blobs are present, so that's great. They're followed by 32 bytes. In this case, we, I kind of already told you, it's a ES 2 56 that tells you this is probably the encryption key. But, even going into this, as someone who's reverse engineered this far, you're gonna recognize 32 bytes, coming back from the attacker. That's gonna be an encryption key, right? And you can always play around with it, figure out, is it a key, is it some other metadata?

If there's other data involved? Are there more counters? Are there delimiters? Are there file names? Whatever, right? But in this case, a S 2 56 keys. So, back to our encrypted files, right? We have the key. So this is great news. What else is present in the file besides that RA key, we already talked about the file name and of course the header of the footer. So we don't have a better word for that, but, that's just an identifier, right?

Then we have 16 bytes that we don't know what they are. This is before the RSA key, just 16 bytes thrown in there, perfectly spaced, and then some counter, right? Well, if we go back to the 16 bytes, since we know it's a ES at this point, we know we already have the key, the 16 bytes is gonna be a block, which is an IV in this case, they opted for having a randomized IV rather than a zeroed out one, which means that they need to store it somewhere.

If they used all zeros as the first IV for that first block, they don't necessarily have to store it. They just know that they used all zeros or static, iv, in which case some analysis you, you'll be able to figure that out as well. But they opted for randomized. Give them a little more security. They sort it here. And then, we've got some counter, right? And this counter in this case is actually the number of padding bytes that they used since we talked about how a a s is a block safer algorithm.

They need to use some padding and they could use something standardized like, pkc S seven or five or whatever. But in this case, they opted for more randomization, presumably because they thought it would be more obscure, which it kind of is. It's not the the standard, but whatever, right? So here we see that they used, e padding bytes, which is 14, which means that their, encrypted data was not block aligned or their, their plain text was not block aligned going into the encryption step.

They actually had their last block only have two bytes and they needed to pad it. So, okay, we've talked about the RSA key, the iv, everything that's in this file. What about afterwards? There's some other weird counter, right? It's kind of too big, but also too small at the same time. It's too big to be some form of padding, but it's can't be a file counter, right? It's much smaller than the other ones that we saw.

So what is it? And does it actually matter? And of course, the answer as we kind of have been the answer all along is, yeah, it, it kind of matters. This is actually, similar to a counter and we can figure out what it is by calculating the size of the footer. So we have a 26 byte header. That's the, the header of the footer. We talked about a 16 byte iv, a four byte padding count, a 128 byte RS aki, and these four weird bytes, we don't quite know what they are.

And if we add all that up, we're at 178 bytes, which means absolutely nothing to no one. It's not a standardized number, like 2 56, but, what's before those 178 bytes? It's the, it's the file name, right? If we count it all the way back, we get exactly to the file name. And then there's a bunch of weird data at the top. You can see all these zeros. Some metadata maybe we we're not quite sure, but it's obviously not cipher text because it's too low entropy with all those zeros.

Ciphertext is usually gonna look like some randomized kind of hexa decimal if you're looking at it, in a, in a hex V or like I am. So what is that? And it turns out that if we do some more quick math and we look at, this five eight at the bottom, zero x five eight is actually 88. Which if we add that to 178, which we calculated the foot, the size of the footer before we get 266 bytes, and what's 266 bytes from the end of the file?

The start of all that weird stuff, right? So this marks the actual end of the file, going in plain text, right? We don't wanna try to decrypt all these zeros because they're not gonna decrypt properly. They're not cipher texts. So, we have to be sure to cut off this footer at the right spot. Otherwise we're gonna get kind of garbled data at the end of our file.

And it might, depending on the file, corrupt the entire thing, if it's expecting some footer there or some, some end of file. So it's very important that even we look at these kind of seemingly random, things at the end, like the zero x five eight because, you know, if we didn't, we might not decrypt the file properly. Or, even worse, we might make an assumption about the offset, from the end based on the file name.

And if we got something with a really short or really long file name, that could be drastically different and corrupt the file even more. And we might find ourself in a really hard spot to recover from if we told the client that we had it figured out and then we really were just hard coding some data. 'cause we assumed it worked without testing. So that's great, right? We've talked about how to get the iv, how to get the key.

We know the file name, we know the padding, we know everything. So we're done. Or are we, 'cause there's another problem. We've decrypted this file in theory, but dharma's kind of smart in a kind of strange way. Bigger files actually have a totally different encryption protocol than this one. And when I say bigger, I mean, 24 bytes shifted, 16 times. So that's, 1.5 megs. Anything bigger than that is gonna be, totally different encryption protocol.

And when I say totally different, I really mean totally different. This is the beginning of the file. You can see the zero offset on the left. Looks nothing like the other files, right? They started out with ciphertext and this one's all zeros. So what are our first thoughts? Is it just a corrupted file? No. 'cause we can verify another big file. Does the same thing. Is it super low entropy?

Well, it is, but that doesn't tell us anything except that it's not encryption. And it's not compression because compression obviously would compress these zeros and there'd be some, you know, z lib header or something. A ES encryption or any encryption would not output this many zeros. Not on purpose at least. So what's going on and where do zeros actually end? Because if the entire file is zeros, I don't see how we could possibly recover.

But it turns out that the zeros actually end at zero x 4, 0 0, 0 0 into the file, which is kind of too perfect of an offset to be anything besides intentional. But, that, that's great, right? Okay, well, can we just continue going and, you know, assume that those zeros are just padded in the beginning for some reason, and the rest of the file's the same. And of course, nothing's ever that easy because, we, we, this is an encryption either and, it's kind of hard to notice on this file because I think this was a jpeg or something.

But this is actually low entropy data. And if we had like a textile something here, you'd notice words like English words. This is not encrypted data. It, it's plain text. And so of course then we'd come back to, well, it must be corrupt. No encryption is gonna not encrypt and then throw these zeros, but we can verify it actually. And, it, it is plain text and eventually the zeros come back.

So this is kind of the real head scratcher of the entire thing. Before this dharma was very similar to other ransomware. It used an RSA wrapped a ES, and it put everything on the footer. And, if you're familiar with a bunch of ransomware, you've been doing this for a while, you, you would've reversed engineered that in a matter of a couple days. It wouldn't have been this year long academic study, right?

But this is totally different. Starts with zeros, then it's plain text, then the zeros come back, and then they start again. And then they stop and they, they just repeatedly it, it, it just goes and goes and goes, and they're back again. And then, they're, they're everywhere, right? So they're, they're weird. They're zeroes, they're surrounded by plain text. There's three sets of them, start, and then plain text, and then zeroes, and then plain text, and then zeros.

And we have the ranges. But that doesn't really tell us anything immediately. But we know that they're looking at the ranges. 40,000 hex each, not 40,000 bytes, but 4 0, 0, 0, 0 and hex. And what's after the last set of zeros is a bunch of high entropy data, presumably back to ciphertext. So, you know, that's also strange, but at least we're dealing with ciphertext now, right?

Now, if we go back to the foot of the file, just like we did with the others, 'cause this is where the actual information came from, we can see, kind of the, the start of the file name. It's the p and g explains the, the data I was talking about, not being text, but being image data. And then, we're seeing the same, header, right? We still see the iv, we still see the file name, we still see the BV zero, YIF, but if we look right after the iv, we'll notice where before we saw that zero e padding bytes, now we're seeing 0, 0, 0, 0, meaning this is perfectly block aligned.

There's no padding and they didn't even have to worry about it. Which tells us something. I mean, it tells us it's block line, right? That's valuable information. So if we do a little bit more quick math, and we realize with the block line data that, we count it, there's exactly C 0, 0, 0, 0 bytes. And if we count those 4, 0, 0, 0, 0 zeros, of course, and multiplied by three, 'cause there's three of them, we could exactly see 0, 0, 0, 0, just perfect, right?

It tells us that that block of line data is in fact, the data that we were looking for. It is actually the, the, the encrypted data in this big blob at the end, just with those zeros put in there for some reason. So we know we have this total size of site for text, and we know that the maximum size for the, or the minimum size for this protocol is 24 bit shifted to the 16.

And, how I came up with that number was actually, honestly, I noticed the pattern in bigger files versus smaller files, and then I kind of did, did a little bit of an average, like a, a binary search almost figuring out, okay, well this one's too small, so this one's too big. And then narrowing it down until I found this number and I realized, well, that's a perfect number, 24 bit shifted, 16 times.

That's, that can't be random. So if we divide that number by two, we get C 0, 0, 0, 0. that also can't be coincidence, right? This is not an unintentional bug in the decryption program or the encryption program. Rather, this is something very smart by Dharma. And, you know, why, why do they do this? It's plain text and also encryption. Why wouldn't they just keep the same protocol, right?

Why would they mix it up? Speed, is really the reason. I mean, there's obfuscation involved. It, it confused us for a little bit. Especially if you build a decryptor for the first protocol and then you find out that it didn't work for the second protocol, because maybe you weren't provided the right data or, you know, maybe the client didn't have files that were that big, they only had smaller files that they encrypted, or they, maybe they just assumed, right?

Maybe they thought, well, you decrypted one, you can decrypt them all. The reason really though, is speed. This was not a bug. It's not an amateur hour buffer overflow. They, they really did this on purpose for speed. Because if you think about it, say, your personal computer, you might have photos and movies and things, but on a, a database or server, you might have a database, you might have, you know, large collections of files, whether it's embedded or, anything really.

It could be a web server. You might have terabytes of data. You, you might potentially have petabytes if this is actually a massive, storage facility. But, you're not gonna waste all this time as a ransomware actor encrypting terabytes, gigabytes, petabytes of data because, you know, by the time you get through a petabyte of data or even a terabyte, even if you're quick, someone's gonna notice if, everything goes down because the data's being encrypted.

So what they're doing is finding anything bigger than a specific size that they've decided is, you know, arbitrarily the right size. And instead of encrypting the entire file, they just corrupt it by encrypting, C 0 0 0 0 bytes of it. So this is really smart because it allows them to make the files totally unusable. And, you know, if anyone opens it up, they're gonna just see zero. So they're gonna assume it's totally destroyed because it is, but they don't have to waste the time encrypting this entire terabyte, petabyte, whatever of data because they only have to encrypt C 0, 0, 0, 0 bytes of it, and then it works, right?

They get their money. So are we done, right? Do we know everything about this second protocol as well? Of course. No. It, it's still not that easy, even though we know now, it uses the same RSA so that that part's done. We have the as keys, and we know kind of what the deal is, but we don't necessarily know that those, indexes where the zeros start and stop are always gonna be the same.

And in fact, they're not. And they seem to depend on the file size. They're not evenly spaced, even though they're evenly sized. Obviously the attacker must know, right? Because they can decrypt it. So, and the algorithm exists, obviously, it can't be random. They'd never be able to decrypt. So, you know, the algorithm exists, but not only does it exist, it's kind of right in front of our face. If we look at the ranges, zero to 4, 0, 0, 0, 0, 11 fb, five, five to 15 fb five five, we already kinda looked at these and we saw the sizes were the same, 4, 0, 0, 0, 0.

But did we notice where they came from? And no. 'cause we weren't really looking right? We were just trying to figure out what was going on. But they're right here, right in this, right at the, the start of this data or the end of this data, rather, before the ciphertext, they are right in front of us, our face, and then they're delimited by four bytes of zero. So you've got four bytes of zero, then the second four bytes of zero is actually the, the start index.

Then four bytes of zero delimiter, then the next start index, but in, little ndn form, four more bytes of zero delimiter, and then the next start index, right? Perfect, we've got 'em, but, are we done now? And of course, yes. And again, no, right? We, we know where they are, but are they always there? Well, we, we have to make sure we have to debug, we have to actually build the decryptor if we're building a decryptor.

And presumably we are because why else would we have reverse engineer this, right? Encryption is really hard. And I say this as someone who's written, my own implementations of encryption algorithms, use the, you know, open source ones because that's much easier. Use the ones that are provided by, you know, windows or, Java libraries, bouncy castle, c plus plus, libraries, like Boost whatever, right? I mean, I, I've used them all, but it's still hard.

If you mess up the iv, you mess up the padding, it, it can look right on a specific, test case, but then fail elsewhere. And you really, really need to test it if you're dealing with production data. And you know, you need to fill in your clients on all the data, all the details because they might not be as technically savvy as you are. They might not understand all this different, this bite count and this little NDN thing converts to base 64 and it, you know, concatenates to the key, but they can understand that encryption is scary and you have two different protocols and they need to be very careful because they might put all their faith in you.

And if you tell them you have a working decryptor, you give them all the warnings, they're like, okay, yeah, but you know, you're the, you're the IT guy, right? You're the encryption guy, you've got it. I'm just gonna deploy your production. And you know, please warn them against that because people do it. And if there's a small bug, or even if it's not your fault, even if the attacker, corrupted a file by accident, if that was a critical file and they just deleted the original copy and used your decryptor and you can't decrypt corrupt data, they're outta luck now, right?

And you're probably supporting these people versus the attacker, right? The attacker doesn't care, but you actually have a business run and you probably have a support contract. So you really need to be careful about this stuff. And of course, we talked about network shares. I'm gonna bring 'em up again because I've seen this time and time and time again with backups, but also just nas what, what happens, right?

And, and a server gets infected by itself. Sure. Then it's the same as any other workstation. But if a workstation gets infected and was currently, maybe had a user logged in accessing this nas, then that could spread, right? The, the server could become encrypted and, the, the file scanner we talked about might miss those files. So you need to be really careful. What if they were mounting in a very specific way that the attacker was able to latch onto during the infection because of the file access, but they can't easily map back?

Since we mentioned that those functions don't actually exist in a lot of, a lot of commonly used APIs like 1 32, they're not gonna bother trying to like remap your entire network to decrypt your files. It's gonna be up to you or your client, to provide the correct, mounting points and then run the file scanner and actually receive back that base 64. If it's running incorrectly, you're not gonna receive the right output.

And we already talked about that. You might have to pay again. So, yep, I'm, I'm wrapping up. So network shares, remember the missing files. What if, they were made in a specific way? We talked about that, or if, many workstations had access, it's gonna be even worse then because what if multiple encryptions are, you know, everyone's trying to encrypt the server all at once? You could have overwritten data, you could have if it's properly using like mute Texas, to make sure that they're not encrypting the same file at the same time.

You might still have different directories that are encrypted with totally different keys that you wouldn't normally see but occurred because of the certain way that this NAS was set up, whether it's different shares, different partitions, different directories, it's all very, very volatile and you need to be very careful with doing it because a single mistake with mounting it or not mounting it could cost lots and lots of money and will certainly lead to, files not being decrypted.

So now that I've kind of gone over all my warnings, I realize that I'm, kind of at the end. So if anyone has any more questions, I know, there's other things to get to in between talks. But hopefully I didn't go too fast. I know we were set back a a couple minutes, so I tried to speed through to make sure that everyone got the full content.

But yeah, if anyone's got any questions, please feel free to, reach out to me, send a message now in the chat if it's quick, reach out to my company. I know we have sort of contact information up on the sponsors page. I think we, we've got some emails going. We've got a Slack channel people can just shoot out quick messages at. So, yeah, thanks everybody. And, I guess I'll wait around a quick minute for any questions, but besides that, thanks for listening.

Okay, thank you very much. Kyle, so any questions if you would like to ask question, please raise, click this hand button. So while people are thinking about questions, I would like to remind everyone there's an end of session survey that you can, take, through the survey, icon on the app. Also, if you are requesting CBE credits, as I send in the chat to everyone, and I announced earlier in the session, please make sure you stay on all sessions.

And also you complete the end event, c before you leave the event. Yeah, someone is asking about recording. Yes. So announce at the beginning of the event the keynote, all our session will be recorded. We'll make them available after the event, is over.

It'll be on the same app, so the app will be accessible to you after the event. And the question again, for the someone asking in the chat about the recorded, sessions, it'll be posted on the app so you'll have them accessible using the same app on your phone or the web based version.

So any more questions, I know that, you know, just people, just Might be thinking about asking or thinking about the next session. But if you have any questions, please let us know because we're gonna have this session very soon, for you to join other session and for us also to start these other sessions.

Okay? So looks like there's no session. Okay. Thank you very much Kyle, very presentation and I appreciate it. And thank you very much for all of, our participants. Please check your schedule, to decide which session you would like to join next. And, we appreciate you joining our events. Have a nice day.

This video appears on: Intelligence Hub

The Future of Cybersecurity Isn't Forensic Analysis — It's Prevention.

See the difference for yourself. Schedule a live technical demo to witness realistic, zero-day attacks and AI data leaks neutralized autonomously in under 200 milliseconds.