Back to writeups
HTBrevVery Easysolved

Simple Encryptor

3 Jul 2026 · by 0xIDA

Solvers

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

  1. encrypt — ELF 64-bit binary (not stripped)
  2. flag.enc — 32-byte encrypted file

Reverse Engineering

Disassembly of main() revealed:

  1. Open flag, determine size, read into buffer
  2. seed = time(NULL); srand(seed);
  3. Loop over each byte:
    • r1 = rand() & 0xFF → XOR with current byte
    • r2 = rand() & 0x7 → ROL current byte by r2 bits
  4. Write [seed (4 bytes LE)][encrypted buffer] to flag.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:

  1. Read the 4-byte seed (little-endian)
  2. Use ctypes.CDLL('libc.so.6')srand(seed) to reproduce exact rand() sequence
  3. Per byte (reverse of encryption):
    • ROR(byte, rand() & 7) then XOR (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

  • objdump for disassembly
  • ctypes.CDLL for calling glibc's srand()/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
  • ctypes is the easiest way to reproduce C's rand() sequence in Python