Loading...
BICS77{b1t_m4nipul4t10n_is_fun_q73WaL}We are provided with a network service (pods.shibirsec.qzz.io 38197) that performs a custom encoding on input strings.
On connection, the service:
FLAG and prints the hex result.Our goal is to recover the original flag from the initial hex output.
Connecting to the service using nc:
$ nc pods.shibirsec.qzz.io 38197
1188136411cc...[hex string]...
Encoded flag: ...
String to encode (max size: 128 bytes):
The service immediately gives us the encrypted flag in hexadecimal format.
Testing with simple inputs revealed the encoding nature:
A -> Output: 1144B -> Output: 1188AAA -> Output: 114411441144Key findings:
Since the service allows us to encode arbitrary data after showing us the encrypted flag in the same session, we can perform a Chosen Plaintext Attack.
The strategy is:
{ hex_string: char }.The following Python script implements this strategy:
import socket
import string
import time
import sys
# Configuration
HOST = 'pods.shibirsec.qzz.io'
PORT = 38197
def solve():
print(f"Connecting to {HOST}:{PORT}...")
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10)
s.connect((HOST, PORT))
except Exception as e:
print(f"Connection failed: {e}")
return
# Read banner and flag
buffer = b""
try:
while b"String to encode" not in buffer:
chunk = s.recv(4096)
if not chunk: break
buffer += chunk
except socket.timeout:
pass
# Extract the flag hex string from the banner
lines = buffer.decode(errors='ignore').split('\n')
flag_hex = ""
for line in lines:
line = line.strip()
# Heuristic: Find the long line with only hex characters
if len(line) > 50 and all(c in string.hexdigits for c in line):
flag_hex = line
break
if not flag_hex:
print("Could not find flag hex in banner.")
return
print(f"Encrypted Flag Hex: {flag_hex}")
# Build mapping
print("Building character mapping...")
charset = string.printable.strip().replace('\n', '').replace('\r', '')
mapping = {}
count = 0
total = len(charset)
for char in charset:
try:
s.sendall(char.encode() + b'\n')
resp_buffer = b""
while b"String to encode" not in resp_buffer:
chunk = s.recv(4096)
if not chunk: break
resp_buffer += chunk
# Parse hex response
lines = resp_buffer.decode(errors='ignore').split('\n')
found_hex = None
for line in lines:
line = line.strip()
if len(line) > 0 and all(c in string.hexdigits for c in line):
if "Encoded" not in line:
found_hex = line
break
if found_hex:
mapping[found_hex] = char
count += 1
if count % 20 == 0:
print(f"Mapped {count}/{total} chars...", end='\r')
except Exception as e:
print(f"\nError mapping '{char}': {e}")
break
print(f"\nMapped {count} characters.")
# Decode flag using the mapping
print("Decoding flag...")
decoded_flag = ""
current_hex = flag_hex
while len(current_hex) > 0:
match = None
match_len = 0
# Find the matching hex prefix in our map
for hex_val, char in mapping.items():
if current_hex.startswith(hex_val):
if len(hex_val) > match_len:
match = char
match_val = hex_val
match_len = len(hex_val)
if match:
decoded_flag += match
current_hex = current_hex[match_len:]
else:
decoded_flag += "?"
print(f"Failed to match prefix of: {current_hex[:10]}...")
break
print("\n" + "="*40)
print(f"FLAG: {decoded_flag}")
print("="*40)
s.close()
if __name__ == "__main__":
solve()
Running the script successfully recovered the flag:
FLAG: BICS77{b1t_m4nipul4t10n_is_fun_q73WaL}