← Back to Writeups
CUSTOMEasyMisc

Full Cycle

XESXOR9/2/20262 min read
#misc#custom#easy#byte-reversal-/-file-reconstru#file-header-analysis-(magic-by#jpeg-structure-understanding-(#ff-d9-end-markers)#linux

Full Cycle

Platform: hackerlab | Category: Misc | Type: Challenge | Difficulty: Easy | OS: Linux | Author: XESXOR | Date: 2025-12-23 | Status: Solved Techniques: Byte reversal / file reconstruction, File header analysis (magic bytes), JPEG structure understanding (FF D8 start, FF D9 end markers)

Summary

Task: Recover a broken JPEG image from full_cycle.zip. Solution: Reverse all bytes in the file - the JPEG was stored with bytes in reverse order (end marker at beginning, start marker at end).

Full Cycle — hackerlab.pro

Description

"Сэр, он снова прислал нерабочую картинку..." (Sir, he sent a broken image again...)

File: full_cycle.zip contains fullCycle.jpg

Analysis

1. Initial file check

bash
$ unzip full_cycle.zip
$ file fullCycle.jpg
fullCycle.jpg: data

The file is not recognized as an image — the file command shows just "data".

2. Hex dump analysis

bash
$ xxd fullCycle.jpg | head
00000000: d9ff 0a21 6f72 6220 ...

File beginning: D9 FF — this is the JPEG end marker FF D9, but the bytes are swapped! ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

bash
$ xxd fullCycle.jpg | tail
... d8ff

File end: D8 FF — this is the JPEG start marker FF D8, also in reverse order!

3. Hypothesis

The entire file is reversed — bytes are in reverse order. The name "Full Cycle" hints at this.

Normal JPEG structure:

  • Beginning: FF D8 (SOI — Start Of Image)
  • End: FF D9 (EOI — End Of Image)

Our file:

  • Beginning: D9 FF (reversed EOI)
  • End: D8 FF (reversed SOI)

Solution

python
#!/usr/bin/env python3
"""
Full Cycle - Byte Reversal
Restoring a reversed JPEG file
"""
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

with open('fullCycle.jpg', 'rb') as f:
    data = f.read()

# Reverse all bytes
reversed_data = data[::-1]

with open('fixed.jpg', 'wb') as f:
    f.write(reversed_data)

print(f"Original size: {len(data)} bytes")
print(f"Fixed file saved as: fixed.jpg")

Verifying the result

bash
$ python3 solve.py
Original size: 12345 bytes
Fixed file saved as: fixed.jpg

$ file fixed.jpg
fixed.jpg: JPEG image data, JFIF standard 1.01

The file is now recognized as JPEG!

Viewing the image

After opening fixed.jpg, the flag is visible on the image. ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Reference: JPEG Magic Bytes

MarkerHexDescription
SOIFF D8Start Of Image (file beginning)
EOIFF D9End Of Image (file end)
APP0FF E0JFIF marker
APP1FF E1EXIF marker

Alternative Solution (bash)

bash
# Using xxd and tac for reversal
xxd -p fullCycle.jpg | tr -d '\n' | fold -w2 | tac | tr -d '\n' | xxd -r -p > fixed.jpg

Or using a Python one-liner:

bash
python3 -c "open('fixed.jpg','wb').write(open('fullCycle.jpg','rb').read()[::-1])"

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍