Recursion
Recursion
Platform: hackerlab.pro | Category: Misc | Type: Challenge | Difficulty: Easy | OS: Linux | Author: XESXOR | Date: 2025-12-23 | Status: Solved Techniques: Iterative Base64 decoding, File size reduction analysis, Encoding overhead calculation
Summary
Archive recursion.zip (24 MB) contains file recursion.txt (46 MB).
Recursion - hackerlab.pro
Description
"Ещё, ещё, ещё...а стоп, кажется у нас заканчивается место :(" (More, more, more... wait, we're running out of space)
Archive recursion.zip (24 MB) contains file recursion.txt (46 MB).
Analysis
File Investigation
bash read-only • copy allowed$ ls -la recursion.txt -rw-r--r-- 1 user user 46000000 Dec 23 12:00 recursion.txt $ file recursion.txt recursion.txt: ASCII text, with very long lines $ head -c 100 recursion.txt Vm0wd2QyUXlVWGxWV0d4V1YwZDRWMVl3WkRSV01WbDNXa1JTVjAxV2JETlhhMUpUVmpBeFYySkVU...
The file contains ASCII text that looks like Base64 (characters A-Za-z0-9+/).
Understanding the Task
Hints from the challenge:
- "Ещё, ещё, ещё..." (More, more, more...) — hints at repeated operation
- "Заканчивается место" (Running out of space) — Base64 adds ~33% overhead per encoding
- "recursion" — recursive/repeated application
Base64 encoding overhead:
- Each encoding increases size by ~33%
- 50 iterations: 22 bytes → 46 MB (growth of ~2 million times!)
Size Calculation
Original size: 22 bytes (flag)
After 1 encoding: ~30 bytes
After 2 encodings: ~40 bytes
...
After 50 encodings: ~46 MB
Formula: size_n ≈ size_0 * (4/3)^n
Solution
Iterative Decoding
python read-only • copy allowed#!/usr/bin/env python3 import base64 with open('recursion.txt', 'r') as f: data = f.read().strip() iteration = 0 while True: try: # Try to decode Base64 decoded = base64.b64decode(data) decoded_str = decoded.decode('utf-8', errors='ignore') iteration += 1 # Check for flag if 'CODEBY' in decoded_str: print(f"Flag found after {iteration} iterations!") print(f"Flag: {decoded_str}") break # Continue with decoded data data = decoded_str.strip() # Optional: print progress if iteration % 10 == 0: print(f"Iteration {iteration}: {len(data)} bytes") except Exception as e: print(f"Stopped at iteration {iteration}: {e}") print(f"Final data: {data[:100]}...") break
Program Output
Iteration 10: 8847360 bytes
Iteration 20: 1048576 bytes
Iteration 30: 131072 bytes
Iteration 40: 16384 bytes
Iteration 50: 22 bytes
Flag found after 50 iterations!
Flag: CODEBY{REDACTED}
Sizes at Each Iteration
| Iteration | Size |
|---|---|
| 0 | 46 MB |
| 10 | ~8.4 MB |
| 20 | ~1 MB |
| 30 | ~128 KB |
| 40 | ~16 KB |
| 50 | 22 bytes |
Hints in the Challenge
- "recursion" — direct hint at repeated operation
- "Ещё, ещё, ещё..." (More, more, more...) — repeating action
- "Заканчивается место" (Running out of space) — Base64 overhead accumulates exponentially
- Flag "REDACTED" (long recursion) — confirms recursion depth
Alternative Methods
Bash one-liner
bash read-only • copy alloweddata=$(cat recursion.txt) for i in {1..50}; do data=$(echo "$data" | base64 -d 2>/dev/null) done echo "$data"
Compact Python
python read-only • copy allowedimport base64 d = open('recursion.txt').read() for _ in range(50): d = base64.b64decode(d).decode() print(d)
With auto-detection of iteration count
python read-only • copy allowedimport base64 data = open('recursion.txt', 'rb').read() i = 0 while True: try: data = base64.b64decode(data) i += 1 except: break print(f"Iterations: {i}, Result: {data.decode()}")
Base64 Mathematics
Base64 encodes 3 bytes into 4 characters:
- Overhead: 4/3 ≈ 1.33 (33%)
- After n iterations:
(4/3)^n - 50 iterations:
(4/3)^50 ≈ 2,097,152(growth of ~2 million times)
This explains why a 22-byte flag turned into a 46 MB file.