Simple Encryptor
Author: 0xIDA
Platform: HTB · Category: rev · Difficulty: Very Easy
Platform: Hack The Box
Category: Rev
Difficulty: Very Easy
Flag: HTB{vRy_s1MplE_F1LE3nCryp0r}
Solvers
Summary
A ransomware-style challenge where a custom encryptor binary encrypts a flag file using srand(time(NULL)) seeded PRNG. The seed is written to the output file, making decryption trivial once you understand the algorithm.
Analysis
Given Files
- encrypt — ELF 64-bit binary (not stripped)
- flag.enc — 32-byte encrypted file
Reverse Engineering
Disassembly of main() revealed:
- Open
flag, determine size, read into buffer seed = time(NULL); srand(seed);- Loop over each byte:
r1 = rand() & 0xFF→ XOR with current byter2 = rand() & 0x7→ ROL current byte by r2 bits
- Write
[seed (4 bytes LE)][encrypted buffer]toflag.enc
File Structure
flag.enc (32 bytes):
[0x00-0x03] seed = 0x62b1355a (1655780698)
[0x04-0x1F] encrypted data (28 bytes)
Decryption Approach
Since the seed is embedded in the file header:
- Read the 4-byte seed (little-endian)
- Use
ctypes.CDLL('libc.so.6')→srand(seed)to reproduce exact rand() sequence - Per byte (reverse of encryption):
ROR(byte, rand() & 7)thenXOR (rand() & 0xFF)
Key insight: glibc's rand() uses the same algorithm as the binary, so ctypes.CDLL('libc.so.6') gives byte-identical output.
Tools Used
objdumpfor disassemblyctypes.CDLLfor calling glibc'ssrand()/rand()from Python
Lessons Learned
srand(time(NULL))encryption stores the seed in the file — always check for embedded seeds- ROL/ROR operations are trivially reversible when you know the rotation amount
ctypesis the easiest way to reproduce C'srand()sequence in Python