๐ฃ PIE TIME
A detailed write-up of the Pwn challenge 'PIE TIME' from PicoCTF - 2025
๐ Challenge Overview
Category Details Additional Info ๐ Event PicoCTF - 2025 Event Link ๐ฐ Category Pwn ๐ฃ ๐ Points 75 Out of 500 total โญ Difficulty ๐ข Easy Personal Rating: 1/10 ๐ค Author Darkraicg492 Profile ๐ฎ Solves (At the time of flag submission) 1.914 solve rate ๐ Date 15-03-2025 PicoCTF - 2025 ๐ฆพ Solved By mH4ck3r0n3 Team:
๐ Challenge Information
Can you try to get the flag? Beware we have PIE!
๐ฏ Challenge Files & Infrastructure
Provided Files
Files:
๐ Initial Analysis
First Steps
As a first step, as a good practice, I always analyze the security flags of the binary:
And as we can see, it indeed has
PIE (Position Independent Executable)
enabled. This means that memory addresses are randomized on each execution and differ from the local ones. We are also given the source code directly, so we donโt need to analyze it withghidra
. As we can see, it leaks the address of themain
function:
1
printf("Address of main: %p\n", &main);
This program takes an address as input and performs a
jmp
(jump) to that address. Reading the source, there is a function calledwin
that reads theflag.txt
file where the flag is stored. However, this function is obviously not called, we need to use thejmp
to jump to the function via its address, and since we know that the distance (offset
) between two functions is fixed, we can calculate it locally and then, once we get the address ofmain
remotely, subtract the offset and consequently jump to thewin
function containing the flag.
๐ฏ Solution Path
Exploitation Steps
Initial setup
As a first step, I calculate the local offset by doing
main address - win address
. I did it directly frompwngdb
with the commandp/x &main - &win
:As we can see, the offset is
0x96
, let’s proceed with the exploitation.
Exploitation
I then connected with
nc
and obtained the address of the main0x56a08049a33d
. Then I openedpwndbg
again and ranp/x 0x56a08049a33d - 0x96
to calculate the address of thewin
function, obtaining:0x56a08049a2a7
. Once entered as input when asked for the address we want to jump to, I obtained the flag.
Flag capture
๐ ๏ธ Exploitation Process
Approach
The exploit uses
pwntools
andregex
to extract the address of the main, calculate the offset, and send the address of thewin
function as done previously. Then it extracts the flag from the response using a regex and prints it.
๐ฉ Flag Capture
FlagpicoCTF{b4s1c_p051t10n_1nd3p3nd3nc3_00dea386}
Proof of Execution
๐ง Tools Used
Tool Purpose pwnGDB Debugging Python Exploit
๐ก Key Learnings
Time Optimization
- Use
p/x &foo - &boo
directly insidepwngdb
to calculate the offset in hex.
Skills Improved
- Binary Exploitation
- Reverse Engineering
- Web Exploitation
- Cryptography
- Forensics
- OSINT
- Miscellaneous
๐ References & Resources
Learning Resources
๐ Final Statistics
Metric | Value | Notes |
---|---|---|
Time to Solve | 00:05 | From start to flag |
Global Ranking (At the time of flag submission) | 1176/10517 | Challenge ranking |
Points Earned | 75 | Team contribution |
Created: 15-03-2025 โข Last Modified: 15-03-2025 *Author: mH4ck3r0n3 โข Team: *