Python Challenge - Level 20

Problem

The clue states:

but inspecting it carefully is allowed.

Inspecting the HTTP headers of the image http://www.pythonchallenge.com/pc/hex/unreal.jpg reveals HTTP Range header support:

Content-Range: bytes 0-30202/2123456789

The declared file size is over 2 GB (2,123,456,789 bytes), but only the first 30,203 bytes are returned in the image.

Solution

We probe the file using HTTP Range requests:

  1. Forward probing from offset 30203: Requests yield short messages:

    • "Why don't you respect my privacy?"
    • "we can go on in this way for really long time."
    • "stop this!"
    • "invader! invader!"
    • "ok, invader. you are inside now." (ends at 30346) The user's nickname is invader.
  2. Backward probing from the end (2123456789): Requesting Range: bytes=2123456788-:

    • "esrever ni emankcin wen ruoy si drowssap eht" → "the password is your new nickname in reverse". Password: redavni (invader reversed).
  3. Finding the hidden archive: Requesting the preceding range:

    • "and it is hiding at 1152983631."
  4. Downloading the payload: Requesting Range: bytes=1152983631- returns a ZIP file (level21.zip). Unzipping with password redavni extracts package.pack and readme.txt.

Python

import base64
import re
import urllib.request

url = "http://www.pythonchallenge.com/pc/hex/unreal.jpg"
auth = "Basic " + base64.b64encode(b"butter:fly").decode()

# 1. Forward scan
pos = 30203
while True:
    req = urllib.request.Request(url, headers={"Authorization": auth, "Range": f"bytes={pos}-"})
    try:
        resp = urllib.request.urlopen(req)
        body = resp.read().decode()
        cr = resp.headers.get("Content-Range")
        print(f"[{cr}] -> {body.strip()}")
        m = re.search(r"bytes \d+-(\d+)/", cr)
        pos = int(m.group(1)) + 1
    except Exception as e:
        break

# 2. Check the reverse end
req = urllib.request.Request(url, headers={"Authorization": auth, "Range": "bytes=2123456743-"})
resp = urllib.request.urlopen(req)
print("End hint:", resp.read().decode().strip())
# "and it is hiding at 1152983631."

# 3. Download the hidden zip archive
req = urllib.request.Request(url, headers={"Authorization": auth, "Range": "bytes=1152983631-"})
data = urllib.request.urlopen(req).read()
with open("level21.zip", "wb") as f:
    f.write(data)
print("Saved level21.zip!")

Go

package main

import (
	"encoding/base64"
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	client := &http.Client{}
	url := "http://www.pythonchallenge.com/pc/hex/unreal.jpg"
	auth := "Basic " + base64.StdEncoding.EncodeToString([]byte("butter:fly"))

	fetchRange := func(rangeHeader string) ([]byte, http.Header) {
		req, _ := http.NewRequest("GET", url, nil)
		req.Header.Set("Authorization", auth)
		req.Header.Set("Range", rangeHeader)
		resp, err := client.Do(req)
		if err != nil {
			panic(err)
		}
		defer resp.Body.Close()
		body, _ := io.ReadAll(resp.Body)
		return body, resp.Header
	}

	// Read message at offset 2123456743
	body, _ := fetchRange("bytes=2123456743-")
	fmt.Printf("Hint: %s\n", string(body)) // "and it is hiding at 1152983631."

	// Download zip payload at 1152983631
	zipData, _ := fetchRange("bytes=1152983631-")
	os.WriteFile("level21.zip", zipData, 0644)
	fmt.Println("Saved level21.zip")
}

Rust

use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let url = "http://www.pythonchallenge.com/pc/hex/unreal.jpg";
    let auth = format!("Basic {}", base64::encode("butter:fly"));

    // Read hint from near the end
    let hint = ureq::get(url)
        .set("Authorization", &auth)
        .set("Range", "bytes=2123456743-")
        .call()?
        .into_string()?;
    println!("Hint: {hint}");

    // Download the zip archive
    let mut reader = ureq::get(url)
        .set("Authorization", &auth)
        .set("Range", "bytes=1152983631-")
        .call()?
        .into_reader();

    let mut zip_bytes = Vec::new();
    reader.read_to_end(&mut zip_bytes)?;
    fs::write("level21.zip", zip_bytes)?;
    println!("Saved level21.zip");

    Ok(())
}

Language Comparison

Feature Python Go Rust
HTTP Range Requests headers={'Range': 'bytes=...'} via urllib.request req.Header.Set("Range", ...) via net/http .set("Range", ...) via ureq/reqwest
HTTP Status 206 Partial Content Handled transparently by urlopen as success Handled transparently as valid HTTP response Handled transparently as 2xx success
Base64 Encoding base64.b64encode() stdlib base64.StdEncoding.EncodeToString() stdlib base64::encode() crate

Key insight: HTTP Range requests (RFC 7233) allow arbitrary byte offsets to be inspected without downloading gigabytes of dummy data. All three languages implement standard header mutation cleanly; Go's standard library provides both HTTP client and Base64 encoding without third-party crates.

Next Level

The password for level21.zip is redavni (invader reversed). Unzipping begins Level 21.