The idea
Ishaan is handling an incident for Elmgrove Dental, a small clinic. On Monday morning the receptionist's PC flagged a file in its temp folder. Opened in an editor, the file is a solid wall of base64, made unreadable on purpose. The clinic wants to know what it does and whether any other machine talked to it.
The wrapping is obfuscation: base64, then hex, then a short XOR. Base64 and hex need no key at all, and the XOR's key is tiny. That is encoding, not encryption. It hides the content from a glance and from a scan for a known string, but not from someone who sits down to peel it. You'll take the layers off one at a time, down to the marker and the beacon host the script carried.
You work the sample statically: decode it, never run it. The payload here is an inert stand-in that says so in its own text. A real dropped script only ever runs in a sandbox built for it, never on your own machine.
Steps
-
The file from the reception PC
You're on your analyst machine,
workstation, with the sample saved at/evidence/stage.txt. Read it before you touch it. The characters a file uses tell you which encoding wraps it, and so which tool to pick next.Look for a single long line made of letters, digits,
+and/, ending in=. That alphabet, with the=padding at the end, is the mark of base64: a way to write any bytes using only 64 safe characters.workstation:~# cat /evidence/stage.txt
-
Peel the base64: hex underneath
Take the outer layer off.
base64 -dreads the file and prints what is underneath. It needs no key and no password, which is why base64 protects nothing.Before you call it done, read what comes out. A payload would read as text. A long run of only
0–9anda–fis something else: hex, which writes each byte as two of those characters.workstation:~# base64 -d /evidence/stage.txt
-
Decode the hex: scrambled text is a XOR tell
Take the hex layer off too.
xxd -r -preads a plain hex string and writes the bytes it stands for. The pipe,|, hands the output ofbase64 -dstraight to it, so you peel both layers in one line.This time the output is almost text: letters and punctuation, but no words. Bytes that are all printable yet spell nothing are the usual sign of a single-byte XOR. XOR flips bits in each byte against a key, and here every byte was flipped against the same one-byte key.
workstation:~# base64 -d /evidence/stage.txt | xxd -r -p
-
Brute the one-byte XOR: the payload appears
XOR with a key is a cipher, not an encoding. But one byte holds only 256 values, so a one-byte key leaves only 256 keys to try. A computer tries all of them in well under a second.
The short Python script below does that. It XORs the bytes against each key from
0to255, and prints the result only when every character is printable and there are real spaces in it: the shape of a sentence. Pipe the decoded bytes into it.workstation:~# base64 -d /evidence/stage.txt | xxd -r -p | python3 /evidence/unxor.py
-
What the dropper was, and the indicators to block
The recovered line is what Ishaan came for. Each string in it is an indicator of compromise: something concrete to block and search for. The marker names the tool. The beacon host is where the script would have called home, so it goes on the firewall's block list and into a search of the clinic's proxy logs, to find any other machine that already talked to it.
Save the recovered line next to the sample, so the case file holds the result as well as the evidence, and read it back.
workstation:~# base64 -d /evidence/stage.txt | xxd -r -p | python3 /evidence/unxor.py > /evidence/payload.txt workstation:~# cat /evidence/payload.txt
Run these steps on real machines