Description
This encoding is base as it gets. Convert between binary, octal, and hex quickly. Connect to the server with nc.
Setup
Connect to the challenge server.
nc <HOST> <PORT_FROM_INSTANCE>Solution
Walk me through it- Step 1Understand the challenge formatThe server sends you encoded strings one at a time in binary, octal, or hex format and asks you to convert them to the word they represent. You must respond correctly within a short time limit.
Learn more
The three bases you need to handle:
- Binary (base 2): digits 0 and 1. E.g., 01110000 = 112 = 'p'
- Octal (base 8): digits 0-7. E.g., 160 = 112 = 'p'
- Hexadecimal (base 16): digits 0-9 and a-f. E.g., 70 = 112 = 'p'
In Python:
int('01110000', 2)for binary,int('160', 8)for octal,int('70', 16)for hex. Thenchr()to get the character. - Step 2Write a pwntools script to automate responsesThe time limit is tight, so write a Python script using pwntools to automate the conversion. Read each encoded string, detect the base from context, convert it, and send the answer.bash
pip3 install pwntoolspythonpython3 << 'EOF' from pwn import * r = remote('<HOST>', <PORT_FROM_INSTANCE>) def decode_word(encoded, base): parts = encoded.strip().split() chars = [] for p in parts: chars.append(chr(int(p, base))) return ''.join(chars) for _ in range(3): line = r.recvuntil(b'?').decode() print(line) if 'binary' in line.lower(): encoded = r.recvline().decode().strip() answer = decode_word(encoded, 2) elif 'octal' in line.lower(): encoded = r.recvline().decode().strip() answer = decode_word(encoded, 8) else: encoded = r.recvline().decode().strip() answer = decode_word(encoded, 16) r.sendline(answer.encode()) r.interactive() EOFLearn more
pwntools is a Python library designed for CTF challenges involving network connections and binary exploitation. The
remote()function creates a TCP connection.recvuntil()reads until a specific byte sequence appears, andsendline()sends data followed by a newline. - Step 3Receive the flagAfter correctly converting all encoded strings, the server outputs the flag.
Learn more
Number base conversion is fundamental to computer science. Computers store all data in binary; hexadecimal is a compact human-readable notation for binary (each hex digit represents 4 bits); octal (each octal digit represents 3 bits) was common in early Unix systems.
Alternate Solution
Use the Number Base Converter on this site to quickly convert individual binary, octal, or hex values to their ASCII characters - useful for manual verification before scripting with pwntools.
Flag
picoCTF{...}
Automate binary/octal/hex to ASCII conversion using pwntools to respond within the server's time limit.