WannaCry ransomware looks for and executes DLLs in its current directory. Therefore, we can hijack a DLL to execute our own code in order to control and terminate the malware pre-encryption. The exploit DLL checks if the current directory is "C:\Windows\System32" and if not we grab our process ID and terminate. We do not need to rely on hash signatures or third-party products, the malware vulnerability does the work for us. Endpoint protection systems and or antivirus can potentially be killed prior to executing malware, but this method cannot as there is nothing to kill the DLL that just lives on disk waiting. From a defensive perspective you can add the DLLs to a specific network share containing important data as a layered approach. All basic tests were conducted successfully in a virtual machine environment.
75c864ef881d1530855d950ce35620da320dafb0cebe2d176ad34757f23f3194
Discovery / credits: Malvuln - (John Page aka hyp3rlinx) (c) 2022
Original source: https://malvuln.com/advisory/84c82835a5d21bbcf75a61706d8ab549.txt
Contact: [email protected]
Media: twitter.com/malvuln
ISR: ApparitionSec
Threat: Ransom.WannaCry
Vulnerability: Code Execution
Description: WannaCry looks for and executes DLLs in its current directory. Therefore, we can hijack a vuln DLL, execute our own code, control and terminate the malware pre-encryption. The exploit dll checks if the current directory is "C:\Windows\System32", if not we grab our process ID and terminate. We do not need to rely on hash signatures or third-party products, the malwares flaw does the work for us. Endpoint protection systems and or antivirus can potentially be killed prior to executing malware, but this method cannot as there's nothing to kill the DLL just lives on disk waiting. From a defensive perspective you can add the DLLs to a specific network share containing important data as a layered approach. All basic tests were conducted successfully in a virtual machine environment.
Family: WannaCry
Type: PE32
MD5: 84c82835a5d21bbcf75a61706d8ab549
Vuln ID: MVID-2022-0582
Disclosure: 05/03/2022
Video PoC URL: https://www.youtube.com/watch?v=AXD8Lo2jCc0
Exploit/PoC:
1) Compile the following C code as "MSVCP60.dll" 32bit
2) Place the DLL in same directory as the ransomware
3) Optional - Hide it: attrib +s +h "MSVCP60.dll"
4) Run the malware
#include "windows.h"
//By malvuln
//Purpose: Code Execution - Block Encryption
//Target: Ransom.WannaCry
//MD5: 84c82835a5d21bbcf75a61706d8ab549
/** DISCLAIMER:
Author is NOT responsible for any damages whatsoever by using this software or improper malware
handling. By using this code you assume and accept all risk implied or otherwise.
**/
//gcc -c MSVCP60.c -m32
//gcc -shared -o MSVCP60.dll MSVCP60.o -m32
BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved){
switch (reason) {
case DLL_PROCESS_ATTACH:
MessageBox(NULL, "Code Exec", "by malvuln", MB_OK);
TCHAR buf[MAX_PATH];
GetCurrentDirectory(MAX_PATH, TEXT(buf));
int rc = strcmp("C:\\Windows\\System32", TEXT(buf));
if(rc != 0){
HANDLE handle = OpenProcess(PROCESS_TERMINATE, FALSE, getpid());
if (NULL != handle) {
TerminateProcess(handle, 0);
CloseHandle(handle);
}
}
break;
}
return TRUE;
}
Disclaimer: The information contained within this advisory is supplied "as-is" with no warranties or guarantees of fitness of use or otherwise. Permission is hereby granted for the redistribution of this advisory, provided that it is not altered except by reformatting it, and that due credit is given. Permission is explicitly given for insertion in vulnerability databases and similar, provided that due credit is given to the author. The author is not responsible for any misuse of the information contained herein and accepts no responsibility for any damage caused by the use or misuse of this information. The author prohibits any malicious use of security related information or exploits by the author or elsewhere. Do not attempt to download Malware samples. The author of this website takes no responsibility for any kind of damages occurring from improper Malware handling or the downloading of ANY Malware mentioned on this website or elsewhere. All content Copyright (c) Malvuln.com (TM).