2. Stack Overflow with ROP
- Due date: 11:59pm, 11/01/2026
- Lead TA: Jonguk Cheong (sysprog26@compsec.snu.ac.kr)
Late submissions will not be accepted. Please complete and submit your assignment well before the deadline.
Challenge Overview
In this challenge, your goal is to exploit a buffer overflow vulnerability in a simple C program and use a technique called Return-Oriented Programming (ROP) to obtain the contents of the flag.txt file. The program does not provide a win() function that directly reveals the flag. Your task is to overflow the buffer and chain together small pieces of code (called gadgets) to control the program's execution and obtain a shell to read flag.txt.
Return-Oriented Programming (ROP)
Return-Oriented Programming (ROP) is an advanced exploitation technique that allows an attacker to control the flow of a program by chaining together small sequences of existing code, known as gadgets. These gadgets, which are already present in the program’s memory, typically end with a ret instruction. By carefully controlling the stack, an attacker can execute these gadgets in a specific order to perform complex tasks, such as calling functions with specific arguments, without needing to inject new code into the program.
To use ROP effectively, you need to understand the calling convention. The calling convention tells you how a program passes arguments to functions and how it returns results. This is important because when you're using ROP gadgets to call a function, you need to know (1) where to put the arguments, and (2) what to put as arguments.
For example, in the x86-64 calling convention:
- The first argument is placed in the rdi register.
- The second argument is placed in the rsi register.
- The third argument is placed in the rdx register.
In this challenge, the helper function takes pointer arguments.
A pointer identifies data in memory, and the function's parameter
types determine how that data is interpreted. A string and an array
of string pointers, for example, have different memory layouts.
Also, a gadget may modify multiple registers or adjust the stack layout by manipulating the rsp register.
To solve this challenge, understand the types of the function arguments and the side effects of gadgets. Then, chain the gadgets properly to obtain a shell.
Download
You can download the challenge from our CTF server. (http://sivir.snu.ac.kr:10000/)
Submission
Once you've obtained the flag, please submit it to our CTF server. Then, submit both your exploit code and a 1-page report through ETL. Your report should briefly explain the code you used to get the flag and how you solved the challenge. Please do not cheat, share your flag, or disclose your solutions. Ensure that your report is strictly limited to 1 page.
Before submitting, use this command to compress your files:
zip report.zip solve.py report.pdf. Make sure to rename your
exploit code to solve.py and your report to report.pdf before
running this command. Finally, submit report.zip through ETL.