Contents

🌐 Cookies

A detailed write-up of the Web challenge 'Cookies' from PicoCTF - 2022

/images/PicoGym/PicoCTF-2022/Cookies/challenge_presentation.png
Challenge Presentation

📊 Challenge Overview

Category Details Additional Info
🏆 Event PicoGym Event Link
🔰 Category Web 🌐
💎 Points Out of 500 total
⭐ Difficulty 🟢 Easy Personal Rating: 1/10
👤 Author madStacks Profile
🎮 Solves 77.985 solve rate
📅 Date 30-01-2025 PicoGym
🦾 Solved By mH4ck3r0n3 Team:

📝 Challenge Information

Who doesn’t love cookies? Try to figure out the best one. http://mercury.picoctf.net:54219/

🎯 Challenge Files & Infrastructure

Provided Files

1
Files: None

🔍 Initial Analysis

First Steps

Initially, the website appears as follows:

/images/PicoGym/PicoCTF-2022/Cookies/site_presentation.png
Site Presentation

The first thing I did was click the search button to see what would happen. However, the only thing I received was an invalid search, so, as suggested by the challenge title, I decided to inspect the cookies from that invalid search.

/images/PicoGym/PicoCTF-2022/Cookies/invalid_search.png
Invalid Search Cookies

As we can see, the cookie name=-1 immediately stands out. From there, I thought there might be n cookies saved, and that I needed to find the correct one. In fact, after trying to search for snickerdoodle, which was the placeholder content in the input box, I got a valid search.

/images/PicoGym/PicoCTF-2022/Cookies/snickerdoodle.png
Snickerdoodle

/images/PicoGym/PicoCTF-2022/Cookies/snickerdoodle_search.png
Snickerdoodle Search

When I tried inspecting the cookies again using ChromeDevTools, I noticed that the name cookie had changed its value to 0.

/images/PicoGym/PicoCTF-2022/Cookies/name0.png
Name 0

So, I immediately tried changing the value of the cookie to 1, and by refreshing the page with F5, I got this:

/images/PicoGym/PicoCTF-2022/Cookies/name1.png
Name 1

As we can see, we performed a search for another cookie since the name of the cookie at the center of the page changed from snickerdoodle to chocolate. Now that we understand how the page works, all we need to do is find the correct index of the flag cookie to extract it. Let’s move on to the exploitation.

🎯 Solution Path

Exploitation Steps

Initial setup

The first thing I did, instead of doing it manually, was extract the index by writing a Python script. The script makes a maximum of 100 requests to the /check route, passing name=request_number. This way, the value of the name cookie changes with each iteration of the loop: the first request has 0, the second has 1, and so on. I then added a regex check, so that once the response to the request was obtained, if the regex matched the response, it would print the request index and break out of the loop.

Exploitation

So, for the exploitation, I just ran the script:

1
python3 exploit.py

And I waited to get the correct name cookie value (the one that contained the flag). Once I obtained it, I changed the name value to 18 (since that was the valid index), and after refreshing the page, I found the flag.

Flag capture

/images/PicoGym/PicoCTF-2022/Cookies/manual_flag.png
Manual Flag

🛠️ Exploitation Process

Approach

The exploit was based on setting a maximum limit of 100 POST requests, changing the value of the name cookie with the index from the request loop. Once I found the correct index (18) that contained the flag, I extracted it from the response using a regex and broke the loop.

🚩 Flag Capture

Flag

Proof of Execution

/images/PicoGym/PicoCTF-2022/Cookies/automated_flag.png
Automated Flag
Screenshot of successful exploitation

🔧 Tools Used

Tool Purpose
Python Exploit

💡 Key Learnings

Time Optimization

If there is a placeholder, try the input suggested by the placeholder as the first input to understand how the web application works.

Skills Improved

  • Binary Exploitation
  • Reverse Engineering
  • Web Exploitation
  • Cryptography
  • Forensics
  • OSINT
  • Miscellaneous

📊 Final Statistics

Metric Value Notes
Time to Solve 00:03 From start to flag
Global Ranking Challenge ranking
Points Earned Team contribution

Created: 30-01-2025 • Last Modified: 30-01-2025 *Author: mH4ck3r0n3 • Team: *