So we had some good feedback from the video
On WannaCryptor
but, some questions about basically what it is,
what it does, from an encryption point of view.
and that, actually is a quite interesting topic
because what it does is similar; obviously slightly different.
but similar to what most of the other ransomware does, as well.
So I thought we'd cover, pretty much
sort of the basics of what it is that ransomware does
beyond it just has a private key and encrypts your data.
which is obviously, sort of, the assumption
We'll perhaps start with a
look at a really rubbish one that I'm making up as I go along and we'll kind of build it up into a system that
Kind of makes sense, and you'll see hopefully how it uses both symmetric and asymmetric or public key cryptography
combined to try and
produce an effective exploit. Okay, so let's imagine that I wanted to write a
Piece of Ransomware - which I don't, I should add?
I don't think people should be writing ransomware, but
But knowing a bit about how it works is quite a good way of understanding a bit about how cryptography works. There's really two major
types of cryptography that we see a lot of like symmetric encryption and asymmetric encryption
[I] will put hash functions aside for one for one day
so symmetric encryption quite simply have one key for
Encryption and the same key for decryption. All right? So a AES is a good example of an
symmetric block cipher that people use a lot of at the moment.
Asymmetric Encryption or public key cryptography is where we have a separate key for encryption and another key for decryption?
And that has numerous benefits in some circumstances and drawbacks in other circumstances
So what WannaCryptor does
is combine both of these things to try and get a solution that first of all will run offline,
so if they're not connected to their command and control servers they can still encrypt your disk and
theoretically decrypt it later - although the jury's out whether they actually will bother.
So let's imagine that we're writing to some ransomeware, right? The first thing
we could do is we could choose an
Symmetric Encryption cipher like AES, right? We could say what we're going to use AES and to do that
We need a symmetric key, so I could developer. I'm programming this up
I could write a piece of code that
Searches through all the files on someone's hard disk and for files of a certain type
I could replace that file with a copy of that file
That's been passed through this cipher
so I need to come up with a key so I generate the key. So let's call it Ks for the symmetric key.
The difficulty here is if I'm going to use this key to encrypt people's data. It needs to have access to it
So either this needs to be sent to the malware as it's running
in which case there's going to be a compromise that the the keys been sent over network
Hopefully people (researchers) could find it on the network, and then use it to decrypt someone's files without having to pay any money
Alternatively, it's a very naive approach you could just bury it inside the code. People do this a lot. There are actual
ransom wares that have done this it's not the best approach
So you basically put this string Ks
somewhere in the code
And then the ransomware is able to encrypt it and - when it wants to - decrypt the files. All right now obviously
that's not a good solution because
Anyone disassembling this code - and researchers do this within minutes of code being released -
Will immediately find this string and then tell everyone: "Oh look, the keys in this file"
Well, let's just decrypt it this way. And then write another tool which uses the same function and the same key
So that's not a good solution. To improve on this slightly, we can bring asymmetric encryption in. So this is our first attempt
I'm working my way towards something competent, so don't judge me yet.
So in asymmetric encryption we have two keys: We have a public key and a key private
Now, as long as the private key is kept secret
then in some ways we can encrypt everyone's files with the public key
And when they play the Ransom give them the private key. That's kind of a general idea.
So early ransom ware worked this way.
So when when the ransomware started it would generate a public and private key pair
It would send the private key off to a server somewhere
To hold it for Ransom and then it would encrypt everything with the public key. This usually uses RSA there are other options?
We won't talk about the mathematics of RSA
Except to say that it's being very very difficult to calculate this private Key given only this one
so if you're not watching this when it gets installed
This private key is gone and all you can see is the public key, and then you're in a bit of trouble now
There's a few downsides to this the first is that
Asymmetric Encryption is quite slow right the mathematics involved in RSA is
It's not too bad on a computer
But we do it generally for smaller messages. If you were trying to include a lot of someone's files with this it would take quite
a long time
And also you have to have a connection to your commander control server if you're
Malware is running and let's say
They're temporarily not on a wi-Fi or something like this, then what happens is it tries to upload this private key?
And it can't so one [of] two things happens, [then] either. It has to stop or it just encrypts everything with the public key and
we lose the private key or
The private key has to be temporarily stored on a disk
which isn't going to work well for holding it for Ransom, right? None of these solutions are very very good, so
That isn't a very good solution either. It's a bit slow
And there's an issue of trying to upload this to a command control server, and how we're going to do that
so what modern
Ransomware does - and this is not exclusive to Ransom where lots of encryption schemes work this way -
is a hybrid encryption scheme where the majority of the encryption so the actual
encryption of your files will be done with AES or some symmetric cipher and that key will be protected by public key cryptography, so
You're holding [one] of these private keys for Ransom and when you get it back you can then unencrypt Ks and unencrypt the files
That's the idea
So this is what WannaCryptor does. So WannaCryptor, when it's off in a directory,
it starts undertaking lots of different tasks. One of the tasks
It does is start up threads for trying to spread itself using the eternal blue exploit
But the majority of the work in terms of Encryption is separate to that. And what it will do from inside its own
Executable it will extract a zip file
Which is also encrypted it would decrypt this using a password and then [it] will extract those files
Now they hold things like hard coded bitcoin addresses that we know about that
You're supposed to be paying this ransome, hard coded public keys of the server (which I'll talk about in a moment)
the addresses, the tor addresses of the server for the tor hidden services
It extract all of these things and then it gets to work, encrypting your files
So the first thing it does is it generates an RSA key pair.
[If I start a new page, then then we won't be confused with my terminology
that essentially I'm making up as we go along, so...]
[Did you solve that Rubik's cube since we were here?]
[I changed a couple of pieces around
I haven't solved the rubics cube yet,
I could but I like to annoy people with having it unsolved on the shelf it also takes me quite a long time]
So okay, so when WannaCryptor installs itself and it starts running
It needs to generate some keys, that it's going to use to encrypt your files
The first thing it does is generate a public and private key pair for this infection. And these are for the client all right?
So let's call them C_pub and C_private it. So we've generated a public key and a private key right?
Now these are 2048bit RSA Keys
Skipping over the math a little bit to try and calculate the private key if we didn't have it
We would have to solve a very large
integer factorization problem
which is not happening, sufficed] to say.
Normally, what a ransom-ware would do now is, with this private key off to a command-and-control server,
Delete it so that we never get it back unless we pay a ransom and then encrypt everything with this public key.
but in a hybrid encryption scheme we work slightly differently
Stored inside the executable is a server's public key, this is a command and control server
So this that we have here is S_pub. Now this public key has an associated private key
But we have no idea what it is, right?
it's stored somewhere on one [of] those command and control servers or all of those command and control servers and these were generated [when] the
Ransomware was created a while ago [End of manually checked subtitles]
So the client public and private keys are generated on the fly
[for] every time it installs itself on anyone's machine the server's public key is stored inside the executable and it's always the same
and it's
Associated with a service private key hidden somewhere else that we haven't got access [to] if only we did it's worth mentioning at this point
That if we could find the server and get this private key that would be good news right we could decrypt everyone's around
Ransoms files perfect
it's hidden on the dark web, [right] so the onion addresses that are supplied hard coded into one a krypter point to
servers somewhere on the Planet
But we don't really know where right
We will deal with hidden services on another video because I think it's a real interesting topic what the client then does what one equipped?
Er does it's got to try and protect this
Key so that it can hold it to Ransom so what it does is it encrypts it with the server's public key
So let's say it takes these down here and it produces [f] pub of C
Private like this is my strange notation [that]. I'm sort of making up. This is kind of [right] business
So this is encryption right and we've encrypted this private key with the public key all right. So now it's totally useless
It's completely mangled
We can't use it remember that in RSA these perform the opposite tasks
so for example if I had all my files encrypted with C pub I
Could decrypt them all again with C private right so that needs to [preserve]
So the malware needs to stop me from getting to that file. Which is done now by encrypting it
We can't decrypt it again because we don't have the server's private key
That's the issue here right, so then what happens is for all files the client will generate a f key which will call
KF4 file right and
Encrypt the file with [kf] then so we're going to store in essence C pub of k f and
K f okay, so let's look at what I've just written here each client has its own public and private key pair right now
that's important because theoretically if one person paid the Ransom and they said them let's say the
Shared private and public key pair, then everyone you seem to pay the Ransom [one's] problems [going] away, right?
That's not a foolproof solution. So what we do we generate an [okay]. We generate a kf aes key
For every single file then we encrypt the file
With that so let's just draw that in so it makes it makes it sense [kf] file, right so we encrypt the file with kf
then we
Store that file on disk and we attach to it that key so that it can be undone
But we hold it to Ransom by encrypting it with our clients public key
So let me run this which files are all in encrypted with a smash it key, so they're encrypted quickly [yep]
But then that symmetric key is been encrypted with a brand new generated asymmetric key pair
yeah, which is encrypted with the
Public-key, so that only the server can be tricked exactly right?
So there's a kind of chain [of] decryption here that we would have to solve if we wanted to undo all this and get our
Files back would return us. Just one file on the disk to get our file back
We need to decrypt it with kf right, which is a symmetric key
unfortunately kf has been
Encrypted with this public key here for the client so [we] need to work out what the private key for the client is
Unfortunately again the private key has been encrypted with the public key of the server
So the only way we can find this private key is to ask the server for its private key or more likely
Ask the server to decrypt it for us and send it back
So you can imagine a situation where you paid your ransom?
Like someone on the other end decided that was [ok] and you were going to have you're going to get your files back
So to be clear you shouldn't pay the ransom
Because it encourages crime, and there's no guarantee
They'll do this and in fact [we've] want to click - it looks like they're not really bothering right?
I don't partly because there's a few implementation issues. It's not clear whose bitcoins
you're paying - it should have had you should have had a
So most ransomware will have a bitcoin assigned for your client, so when it generates these keys it will also generate a bitcoin address
right so theoretically this is [all] automated [you] would pay the ransom and then theoretically they would choose to
They look at that bitcoin address and go okay. Yes. [someone's] paid [will] send them back the private key their private key
Not the case here right it seems to be kind of manual and in lock come is anyone's actually doing it
But I can sympathize with [people] who have had their files encrypted [right]? It's one thing to say don't do it
Don't do it
But you can imagine if you were in a [situation] where your family photos have been encrypted you might be quite desperate to get in
the back um
so
Hypothetically [if] someone paid a Ransom and it was going to give it [back]
What would happen is the client would send off this encrypted private key right? Which it doesn't know anymore?
to the server and the server
Would decide okay?
they're allowed their files back for whatever reason and
Would decrypt this with their private key so s proof right which I'll put in here s private
Spr. B. Right so they decrypt our
Client private key with their server private key and send it back [over] the network like this is all happening
Tor by the way nothing going over the open network
We then have this private key back again which we can use to decrypt our k f which
We can use to decrypt our file
And then it just iterates through all the files doing that process so you can see that the thing
They're actually holding to Ransom is the fact [that] we don't know this private key
And they've encrypted our private key the benefit of this [approach] is you get the speed of aes?
Which over a bunch of files on a disk is unbelievably quick?
Somewhere around I think seven hundred megabits per second of encryption rate. I think on on a decent intel machine with
Aes instructions on it
You get that benefit?
but you also have the benefit that
the private Key but sort of the master key as it were it held only on the server and never needs to be sent to
Anyone and the only way to undo all of this encryption is to know what that is and the other bonus is but you don't
Have to be online to do any of this some man somewhere
If it can't connect to the command and control server will immediately shut down which is nice of them
I suppose because it means they're not going to encrypt your files if they know you can't get them back
But this doesn't do anything like that this encrypts your files first ask questions of a server later
So if the command and control [server] disappear there is no hope because this private key is gone. That's the idea
Surely at some point this aes key is in the clear because it's dead again
Yeah, and so is this private key right so at some point
While it's running this private key will exist and before. It's encrypted it will be in memory now
There's a few problems [with] first of all it's way too late for most people, right?
But theoretically if antivirus [is] being vigilant that might help but but not really
the other thing is that
it's quite hard to access memory for other processes because of
Fairly good security measures in windows and [Linux] and any other operating system
But separate out processes from one another [so] really this is operating in its own address space
it's quite hard for anything else to sort of get in there and quickly look at the keys and
stick them in a file in that time period so really that isn't I don't think an avenue of research in terms of trying to
fix this problem
[much] better to do things like the web-based sinkhole that stopped it running completely and then keep a vigilant eye out for new
Variants show up. You know Daily now
Is there any way of working out how [its] [generating] those keys and using that technique? If it was using a poor?
Encryption library right, then maybe there will be a weakness that you could use right as it is to generate these keys
It's using the windows standard Encryption library which is not bought. It's like. It's perfectly good
[so] that's a that's going to be a problem
The best bet at this stage of getting your files back is not paying a ransom
It's hoping that someone will find this server the real location of it and extract this master key at that point
Everyone else [a] [tool] will be released within a day, but just does all this put it reverse process and solve the whole problem
[this] has happened in the past to ransomware that's been brought down
I believe Cryptolocker for example was an early ransomware
But when they finally brought down the server they also extracted the master key and [were] able to Publish tools to undo everything
[there's] no guarantee that will happen in this case right the dark web makes it quite hard to find these servers
Especially if for example the massive publicity surrounding this has caused them to essentially just do a runner
[maybe] not even I mean I think the servers are still running
But you know I don't know but what the end game for this is we don't know will they find the servers won't they will
This just all to disappear and unfortunately some people have lost some files. We'll have to wait and see
How doing backups yes? What was the best way to back up then okay?
Hang on [you] put me on the spot now
So the best way to do backups is multi-location
Right so not a single hard disk because it might die
But also not [to] hard disk sitting next to each other in case your house falls down and smashes [our] hard this cloud storage is
Very good because they have this
[multi-site] that done as we built in if you don't mind giving your file to them and paying their costs right so some common
I use some combination [of] Cloud storage and
Hard disks and burning to Blu-ray and things like this