247CTF - Encrypted USB Drive
Encrypted USB Drive
An important USB drive containing sensitive information has been encrypted by some new ransomware variant. Can you reverse the ransomware encryption function and recover the files?
1. Initial Analysis
We are provided with a BitLocker-encrypted USB image
(encrypted_usb.dd) and a large list of potential recovery
keys (recovery_keys_dump.txt).
1 | ❯ file encrypted_usb.dd |
The goal is to find the correct recovery key, mount the image, and then deal with the "ransomware" that has encrypted the files inside.
2. BitLocker Decryption
Attempting John the Ripper
First, I tried using bitlocker2john to extract the hash
and then cracked it with the provided recovery keys.
1 | ❯ bitlocker2john -i encrypted_usb.dd > hash |
John didn't seem to find the key directly (possibly due to format
mismatch or configuration). Instead of debugging the hash format, I
moved to a more direct approach: brute-forcing the mount command using
dislocker.
Brute-forcing with Dislocker
I wrote a simple bash script to iterate through the
recovery_keys_dump.txt and attempt to mount the image.
1 |
|
Running the script successfully identified the key:
1 | [+] Recovery Key Found: 334565-564641-129580-248655-292215-551991-326733-393679 |
3. Ransomware Analysis
Inside the mounted drive, we find several encrypted files and the ransomware binary itself:
1 | ❯ ls -lh /mnt/unlocked_usb/ |
The ransom.txt claims to use a "secure XOR encryption
algorithm".
1 | Your files have been encrypted using a secure xor encryption algorithm and are completely unrecoverable! |
4. Recovery (Known Plaintext Attack)
Since the files are PNGs, we can perform a Known Plaintext
Attack. We know that PNG files always start with the same
8-byte magic header: 89 50 4E 47 0D 0A 1A 0A.
By XORing the first 8 bytes of an encrypted file with this known PNG header, we can recover the XOR key.
Using CyberChef:
- Input the first few bytes of
do_not_open.png.xxx.crypt. - XOR with the PNG magic bytes
89 50 4E 47 0D 0A 1A 0A. - The result reveals the key repeats as
66 63 6f 79(ASCII:fcoy).
Applying the XOR key fcoy to the entire file
do_not_open.png.xxx.crypt recovers the original image
containing the flag.
5. Deep Dive: Reversing
the cryptor Binary
I was curious about how the binary actually worked, so I threw it into IDA Pro.
Main Logic
The program expects a 4-character key as a command-line argument. It
then iterates through the current directory, looking for files with the
.xxx extension.
1 | __int64 __fastcall main(int a1, char **a2, char **a3) |
Encryption Function
The encryption is indeed a simple byte-by-byte XOR using the 4-byte key provided.
1 | unsigned __int64 __fastcall encrypt_file(char *source, char *dest, char *key) |
The analysis confirms the Known Plaintext Attack was the correct approach, as the key length was short (4 bytes) and applied cyclically.