HTB Cyber Apocalypse CTF 2025: Tales from Eldoria - AI ML - Crystal Corruption
Unveiling the Hidden Payload in resnet18.pth: A Forensic Model Analysis
Challenge: Analyze a corrupted magical machine learning model (resnet18.pth) from the Library of Loria, tampered with by Malakar's followers. Uncover the hidden payload and extract the flag to dispel the dark magic. The flag format is HTB{REDACTED}.
Workflow: We will investigate resnet18.pth using a forensic approach, starting with file format analysis, progressing to code extraction and finally, payload recovery using steganographic techniques.
Step-by-Step Analysis:
Initial File Inspection and Format Identification:
Purpose: Determine the file type and basic characteristics of
resnet18.pth.Action: Use a Python script to read the first few bytes of the file and check for known magic numbers.
import binascii file_path = 'resnet18.pth' with open(file_path, 'rb') as f: header = f.read(4) print(f"[+] First 4 bytes of file (hex): {binascii.hexlify(header)}")Observation: The output reveals the header
504b0304, which is the magic number for a ZIP archive. This indicates thatresnet18.pthis not a standard PyTorch model file but a ZIP archive in disguise.
Analyzing the File as a ZIP Archive:
Purpose: Explore the contents of the ZIP archive to understand its internal structure.
Action: Use Python's
zipfilemodule to list the files within the archive and inspect their names and sizes.import zipfile file_path = 'resnet18.pth' with zipfile.ZipFile(file_path, 'r') as zf: print("[+] Files in ZIP archive:") zf.printdir() file_list = zf.namelist() for file_name in file_list: print(f"[*] Reading {file_name}...") with zf.open(file_name, 'r') as f: header = f.read(16) # Read first 16 bytes as header example print(f" First bytes (hex): {binascii.hexlify(header)}")Observation: The ZIP archive contains a directory named
resnet18and files within it, includingdata.pkl, several files nameddata/XX(where XX are numbers), andversion. This structure resembles a saved PyTorch model, where weights and potentially code are serialized. Thedata.pklfile is a strong indicator of pickled Python objects.