welcome to netwrkspider

Monday, May 15, 2017

WannaCry DLL operations

Reversing WannaCry DLL operations.


1) Checks to see if task already running by attempting to open mutex with name MsWinZonesCacheCounterMutexA

If already exists, app exits

2) Obtains name of current directory.

3) Reads 780 bytes of information from c.wnry which it expects in current directory. This has
bitcoin and TOR info.

4) Checks if running as LocalSystem. Sets a flag used later when running @wanadecryptor@.exe

5) Resolves api from advapi32.dll

  CryptAcquireContextA
  CryptImportKey
  CryptDestroyKey
  CryptEncrypt
  CryptDecrypt
  CryptGenKey

6) Resolves api from kernel32.dll

  CreateFileW
  WriteFile
  ReadFile
  MoveFileW
  MoveFileExW
  DeleteFileW
  CloseHandle

7) Initializes names of files

00000000.res   - C2 communications
00000000.pky   - Public key used by the ransomware to encrypt the generated AES keys that are used to encrypt the user’s files
00000000.eky   - Encryption key for the t.wnry file which stores the actual file encryption component used by the ransomware.
                 It is encrypted using the public key that belongs to a private key embedded inside the ransomware.


8) creates mutex with name MsWinZonesCacheCounterMutexA and sets the security
ACL to allow EVERYONE full access


9) tries to open 00000000.dky. if available, will import key into Crypto API object.
presumably this would be decryption key from the authors of ransomware..


10) if cannot open *.dky file, will generate new RSA key pair of 2048-bits.
Public key is exported as blob and saved to 00000000.pky
Private key is exported as blob and encrypted with ransomware public key before being saved to 00000000.eky

The RSA public key used to encrypt the users RSA key pair is embedded inside the DLL.

unsigned char wc_key1[] =
{
  0x06, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53,
  0x41, 0x31, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
  0x75, 0x97, 0x4C, 0x3B, 0x84, 0x46, 0xDE, 0x2C, 0x2A, 0xF4,
  0x95, 0xA8, 0x5D, 0xC0, 0xCD, 0x6D, 0xDA, 0xD7, 0xD4, 0x92,
  0x1E, 0x13, 0x82, 0x34, 0x6A, 0x70, 0x8D, 0x8F, 0x7C, 0xF7,
  0x04, 0x92, 0x55, 0x7F, 0xF1, 0xA2, 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, 0x42, 0x8E, 0xDF, 0xE5,
  0xDE, 0xA1, 0x72, 0xD9, 0x3B, 0xFB, 0xE5, 0x9D, 0x30, 0x11,
  0x69, 0x92, 0xCD, 0x60, 0x2B, 0xE2, 0xD5, 0x46, 0x3C, 0x28,
  0xCF, 0x9D, 0x30, 0x4A, 0xF7, 0xAD, 0xB9, 0xFB, 0x0F, 0x91,
  0xFE, 0x2E, 0xBE, 0x18, 0xF1, 0xCE
};

The AES-128 key generated for each file is derived from CryptGenRandom  which
is cryptographically secure and is not known to have any weakness.

The AES keys are encrypted using the users public key in *.pky.
In order to decrypt, we need the users private key which is
encrypted using a public key owned by the ransomware authors.

Presumably what authors do is decrypt the users private key in *.eky file
using their private key and then send the user a *.dky file
to decrypt files.

WANNACRY RSA keys in PEM format 


-----BEGIN PRIVATE KEY-----
MIIEzAIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDvz+6DC3rbkfGw
yN1gNs9NhfJkNpzMAIRR7ZYg/x6kvtxmcsfWA3TeoygGW8lSpSf53/wPhEVgbYGE
VbBeTI/3zNZtEbHkyCSo7qHyYQoSWbJqbDqFZ3aRjFAnXAaXZGkDN5ZI5Zar16jw
0XcwLdMToKOfzf6R34YKjJ8KiPVOuF0COglhPLEMT2eJHY83gMmJNgHJnMFsDdVe
iGS+jXG8G2MBYBixAoLCqpuC3sRoCpOQyvaJKJ4nE18F1lIdbSVxQ26r++Ov5/ET
IS4/E51wO/1q1RSrHBhhgFt3tsmD9rRYBVYnsOx7UecV9FAazuHvqTLtX9oen9kK
nAQrTStDAgMBAAECggEBAMeL6PbIJanxDgDBk1vNH8BtNd3nh59EytX1cZfxUYla
e8EPv3M4mxXrA5IO7D3FybblhzNOKABt/nikaMZ+xMk4fDBzqegqFj8vmjg6QQw1
8P0XI7b/+axw6f1mWOG+npcbuQTdbft9z0jbs2a2qs3JPH3sBelR6pJ6opg8kIq3
x+DwTGw0XZbFBArggCXtC/nhBeZbFjaGNdeWhQKwyR5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KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA78/ugwt625HxsMjdYDbP
TYXyZDaczACEUe2WIP8epL7cZnLH1gN03qMoBlvJUqUn+d/8D4RFYG2BhFWwXkyP
98zWbRGx5MgkqO6h8mEKElmyamw6hWd2kYxQJ1wGl2RpAzeWSOWWq9eo8NF3MC3T
E6Cjn83+kd+GCoyfCoj1TrhdAjoJYTyxDE9niR2PN4DJiTYByZzBbA3VXohkvo1x
vBtjAWAYsQKCwqqbgt7EaAqTkMr2iSieJxNfBdZSHW0lcUNuq/vjr+fxEyEuPxOd
cDv9atUUqxwYYYBbd7bJg/a0WAVWJ7Dse1HnFfRQGs7h76ky7V/aHp/ZCpwEK00r
QwIDAQAB
-----END PUBLIC KEY-----





5 comments:

Blogger said...

Did you think about using the #1 Bitcoin exchange company - YoBit.

Blogger said...

Can a criminal be using your ID? Protect yourself with IdentityForce. Enroll now.

Blogger said...

If you are trying to BUY bitcoins online, Paxful is the best source for bitcoins as it allows buying bitcoins by 100's of different payment methods, such as MoneyGram, Western Union, PayPal, Credit Card and even exchanging your gift cards for bitcoins.

Blogger said...

Claim free bitcoins over at Easy Bitcoin. 11 to 33 satoshis every 10 mins.

Blogger said...

BitKong is a verifiably fair online bitcoin guessing game.

TIP: Claim bitcoins every 10 mins from the faucet.