본문 바로가기

CTF

TAMUctf 18 Pwn 1~4 Write Up

Pwn 1  (Local Variable overflow)


nc pwn.ctf.tamu.edu 4321



11 Line 에서 입력 값 검증을 받지 않기 때문에 Overflow가 발생한다.

s를 입력받지만 v5(=var_c) 의 값이 0xf007ba11일 경우 flag 를 출력한다.


s 의 크기는 0x23, v5 의 크기는 0xC



23 Byte의 크기를 덮으면 var_c에 접근 가능


Exploit code : https://github.com/malhyuk97/ctfs/blob/master/TAMUctf2018/pwn1.py



Pwn 2 (Function Overwrite Overflow)

nc pwn.ctf.tamu.edu 4322



main에서 echo 함수를 호출한다.



5 Line 에서 gets 함수를 사용하기 때문에 Overflow가 발생한다.




0xef=239



Payload = s [239 Byte] + EBP [4 Byte] + EIP [print_flag Address(4 Byte)]


Exploit code : https://github.com/malhyuk97/ctfs/blob/master/TAMUctf2018/pwn2.py



Pwn 3 (Remote Code Execution)


nc pwn.ctf.tamu.edu 4323




echo 함수를 호출




s = 238 Byte

5 Line 에서 s 주소를 출력

7 Line 에서 Overflow 발생



ASLR 적용으로 인해 s 주소 랜덤

recv로 받은 뒤 EIP 를 s 의 주소로 Overwrite


Payload = s[238 Byte] + EBP[4 Byte] + EIP[s Address(4 Byte)]


Exploit code : https://github.com/malhyuk97/ctfs/blob/master/TAMUctf2018/pwn3.py


Pwn 4 (Return To Library)

nc pwn.ctf.tamu.edu 4324



NX Mitigation이 적용되어 있어 Stack에 실행 권한이 없다.

RTL, ROP 로 우회 가능



reduced_shell 함수 호출



s 크기 0x1c (28 Byte)

9 Line 에서 Overflow 발생



ls, cal, pwd, whoami 함수에서 같은 주소의 system 함수 호출




system 함수의 plt 값은 변경되지 않으므로 이것을 이용하면 된다.



data 영역에 secret 이라는 변수가 있음


Payload = s[28 Byte] + EBP[4 Byte] + system@plt[4 Byte] + Dummy[4 Byte] + secret(/bin/sh)[4 Byte]


Exploit code : https://github.com/malhyuk97/ctfs/blob/master/TAMUctf2018/pwn4.py