Writeups PicoCTFWebMD5Hash Collision

It Is My Birthday Writeup - PicoGym

Writeup for the It Is My Birthday challenge from PicoCTF PicoGym.

Contents

Category: Web Exploitation

Difficulty: Medium

Points: 100

Description

The server lets you upload two PDF files. It grants the flag only if both files have the same MD5 hash but different contents. This requires exploiting a known weakness in the MD5 algorithm.

Overview

Background: MD5 Collision

Solution

Step 1: Obtain a Collision Pair

Step 2: Upload Both Files

from requests_toolbelt import MultipartEncoder

mp_encoder = MultipartEncoder(fields={
    "file1": ("hello.pdf", open("hello.pdf", "rb"), "application/pdf"),
    "file2": ("hello.pdf", open("erase.pdf", "rb"), "application/pdf"),
    "submit": "Upload",
})

r = requests.post(url, data=mp_encoder,
                  headers={"Content-Type": mp_encoder.content_type})

Step 3: Extract the Flag

soup = BeautifulSoup(r.text, "html.parser")
result = [c for c in soup.get_text(separator="\n").splitlines()
          if "picoCTF{" in c][0]

Flag

picoCTF{c0ngr4ts_u_r_1nv1t3d_73b0c8ad}

← Back to Blog