12 ms·
WannaCry in-memory key recovery for Windows XP
- giis 9y agoLooks interesting, anyone tried these steps? Did it work for you?
- IntelMiner 9y agoIt's only been tested on Windows XP? surprising they couldn't/didn't set up a 7/8/10 VM to try and replicate the results
- genesee 9y agoIt looks like Microsoft's documentation suggests it will only work on older versions of Windows. From the README: > Indeed, for what I've tested, under Windows 10, CryptReleaseContext does cleanup the memory (and so this recovery technique won't work). It can work under Windows XP because, in this version, CryptReleaseContext does not do the cleanup. Moreover, MSDN states this, for this function : "After this function is called, the released CSP handle is no longer valid. This function does not destroy key containers or key pairs.". So, it seems that there are no clean and cross-platform ways under Windows to clean this memory. I'd be curious where the change happened between XP and 10.
- dafrankenstein2 9y ago.NET
- dmitrygr 9y agoFrom the TFA: This is not really a mistake from the ransomware authors, as they properly use the Windows Crypto API. Indeed, for what I've tested, under Windows 10, CryptReleaseContext does cleanup the memory (and so this recovery technique won't work). It can work under Windows XP because, in this version, CryptReleaseContext does not do the cleanup. Moreover, MSDN states this, for this function : "After this function is called, the released CSP handle is no longer valid. This function does not destroy key containers or key pairs.". So, it seems that there are no clean and cross-platform ways under Windows to clean this memory. If you are lucky (that is the associated memory hasn't been reallocated and erased), these prime numbers might still be in memory. That's what this software tries to achieve.
- maxerickson 9y agoThe Twitter says that it has been adapted to work on 7. The readme points out that CryptReleaseContext works better in 10 and thus the recovery doesn't work.
- t3f 9y agoThe variant for 7: https://github.com/gentilkiwi/wanakiwi https://github.com/gentilkiwi/wanakiwi
- tty7 9y agoYou would be welcome to also give it a shot and publish your results
- gpvos 9y agoCut them some slack, this was published a day ago or so. In a case like this, fast publication is more important: both to help people, and so other people can do things like replicating stuff on other OSs while you sleep.
- mr_overalls 9y agoYou've got to admit it's a little funny when an OS's security flaws prevent even targeted malware from working properly.
- avaer 9y agoHeh. Since this only works before a reboot and Windows 10, by design, destructively reboots with no recourse, I could imagine this ironic farce: a) security holes lead to a ransom, b) security holes let you reverse the ransom, but c) forced reboots kill any hope you have of recovering with this kind of hack.
- josteink 9y agoBut Windows 10 was for the same reason largely not affected: it was patched and rebooted.
- nthcolumn 9y agoAnd Windows XP was not targeted at all by WannaCry.
- marksomnian 9y agoIn that case, Microsoft wouldn't have released an emergency patch for XP, three years after end of support. But they did [0]. [0]: https://blogs.technet.microsoft.com/msrc/2017/05/12/customer-guidance-for-wannacrypt-attacks/ https://blogs.technet.microsoft.com/msrc/2017/05/12/customer...
- r721 9y agoXP could be targeted theoretically, the bug is there. But the particular WannaCry variant (which Kevin Beaumont looked at) didn't work under XP: https://twitter.com/GossiTheDog/status/863339558364229634 https://twitter.com/GossiTheDog/status/863339558364229634 https://twitter.com/GossiTheDog/status/863100619242053632 https://twitter.com/GossiTheDog/status/863100619242053632
- campuscodi 9y agoSince WannaCry is somewhat neutered at the moment (thanks to the killswitch), and this tool stops working after a reboot, I'd say this tool is somewhat useless, with no intention to insult the man who created it. It's just the circumstances. After a week, almost all victims have rebooted their PCs or the memory has been re-written with other data.
- milankragujevic 9y agoIt's not actually neutered because there are variants without a kill switch.
- sp332 9y agoRebooting doesn't stop the ransomware.
- TazeTSchnitzel 9y agoIt's hilarious that it uses public-key crypto, yet lets the client know the private key. What's even the point, then?
- soared 9y agoI mean a technical user capable of this solution is not very likely to get hit by this in the first place. The hacker probably doesn't care if x% of people defeat the encryption.. as long as x% pay the ransom.
- kybernetikos 9y agoGiven the infrastructure and health victims that have been hit, I certainly hope that some serious people are looking into this. Given the relatively small sums of money we've seen flowing into the bitcoin addresses, if I were the perpetrator, I would not think I'd got a particularly good deal - exchanging 40k or so for interest from a number of heavy hitting actors just doesn't seem worth it.
- jamiek88 9y agoIt probably does to a pair of 16 year olds in eastern Europe. The problem with these tools being made and leaked is it lowers the bar of technical expertise needed to run a scheme like this. If it still took massive knowledge and experience the likelihood is that person could earn more legitimately thus there is a smaller pool of potential attackers.
- closeparen 9y agoIf the infrastructure and health victims can be compromised by generic Windows hardware not even targeting them in particular & can't recover from backups, I'd argue they aren't heavy hitters. Though maybe they'll bring some in now.
- deleted 9y ago[deleted]
- gregmac 9y ago
- sergior 9y agoThat is nice! But... It really hurts my eyes to read "dump_hex" and "normalizedEntropy" in one file. Is there actually any viable code style guide that one can follow when writing C++ application?
- sjroot 9y agohttps://google.github.io/styleguide/cppguide.html https://google.github.io/styleguide/cppguide.html https://www.cert.org/downloads/secure-coding/assets/sei-cert-cpp-coding-standard-2016-v01.pdf https://www.cert.org/downloads/secure-coding/assets/sei-cert...
- gpvos 9y agoThis is fast-published code, probably using code cut-and-pasted from elsewhere. Completely acceptable for cases like this where publishing fast is more important than esthetics.
- matchagaucho 9y agoThe sad fact is that the prevailing response to a potential worm is "shut down the computer" (hence losing the encryption keys held in memory).
- brazzledazzle 9y agoI assume disconnecting the ethernet and/or wireless is too much of a rat's nest for your average office occupants. Better to cut off the appendage to stop the spread I guess.
- Dylan16807 9y agoThat's still the correct response to a potential worm, shut it down before it can do damage.
- dec0dedab0de 9y agoI'm probably going to show my ignorance of RNGs here, but if we know the machine, the algorithm used, and the time the key was generated, doesnt that limit the number of possible choices? Could we check when the file was encrypted and brute force the possible keys?
- varenc 9y agoThis would work if time was the only thing that went into the seed for the random number generator. Relatively insecure generators do use time, but nothing serious should be using it exclusively. Here's the remark from the Windows Crypto API on how they create the seed. To form the seed for the random number generator, a calling application supplies bits it might have—for instance, mouse or keyboard timing input—that are then combined with both the stored seed and various system data and user data such as the process ID and thread ID, the system clock, the system time, the system counter, memory status, free disk clusters, the hashed user environment block. This result is used to seed the pseudorandom number generator (PRNG). details: https://msdn.microsoft.com/en-us/library/windows/desktop/aa379942(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...
- mikeash 9y agoIt depends on how granular your clock is, too. If you seed with a number of seconds then it's pretty easy to brute-force that. If you seed with nanoseconds it'll be a lot harder.
- kaoD 9y ago> If you seed with nanoseconds it'll be a lot harder. Not really. Or rather, a lot of zero is zero.
- mikeash 9y agoCan you elaborate? I'm assuming the nanosecond-precision lock seeding the RNG is based on wall clock time or system uptime, so as long as the clock is actually that precise (and why not, when the base clock signal in the CPU is ticking a couple of times each nanosecond) you'll get that many digits.
- murbard2 9y agoThe attackers seem to have a poor grasp on cryptography. The entire point of RSA is that they don't have to generate the key locally. Just ship your ransomware with the attacker's public key, generate a symmetric key K locally, encrypt the data with K, encrypt K with the public key, offer to decrypt K for a ransom. There seems to be an inverse correlation between smart and evil in human beings which is reassuring, but only mildly.
- wand3r 9y agoThat's fair but should note that smart != depth of cryptographic knowledge. I am not saying that these are geniuses, programmers or even necessarily evil but (so far) they haven't been caught. So if these were poor teenagers who mostly copy pasted code and built the rest on the fly then as long as (opportunity cost < ransom > (chance of getting caught * penalty)) then it was "smart". That's what is good and bad these days; powerful tools empower motivated people. > There seems to be an inverse correlation between smart and evil Hopefully you're right.
- murbard2 9y agoOf course smart != depth of cryptographic knowledge, but smart => acquiring said cryptographic knowledge when building a tool that deals with cryptography. If they were just teenagers, maybe you have a point.
- DaiPlusPlus 9y agoWith your approach the (symmetric) key used to encrypt the files is still unprotected in memory for at least a short period of time. I'm surprised ransomware doesn't use the TPM to protect their private keys - given that more computers have it now.
- martinko 9y agoNo. Encryption is done with the public key only. No knowledge of the private key is required. The private key is only used for decryption and can be delivered to the victim after payment is made.
- xen2xen1 9y agoSo if this spreads across a network, do they all share the same key? Can you use the XP key on a 10 machine?
- limeblack 9y agoDoes anyone know what would have happened if my laptop was encrypted with wannacry and my laptop hard drive was basically full?
- chii 9y agomy blind guess would be that they'd delete the original file, which frees up some space, and write the encrypted version in its place (which, if the encrypted version is somehow bigger, would fail, or get truncated). It's unlikely that the malware would stop encrypting.
- kutkloon7 9y ago"So, it seems that there are no clean and cross-platform ways under Windows to clean this memory." Well, finally Microsofts incompetence amounts to something good.