Pwntools 기본 사용법
익스플로잇 대상 지정
process('./test') = #로컬 바이너리 'test'를 대상으로 익스플로잇 실행
remote('example.com', 31337) # 'example.com'의 31337 포트에서 실행중인 프로세스를 대상으로 익스플로잇 실행
입력
send 함수
p = process('./test')
p.send('A') # ./test에 'A'를 입력
p.sendline('A') #./test에 'A' + '\n'을 입력
p.sendafter('hello', 'A') # ./test가 'hello'를 출력하면, 'A'를 입력
p.sendlineafter('hello', 'A')# ./test가 'hello'를 출력하면, 'A' + '\n'을 입력
값 변경
s32 = 0x41424344
s64 = 0x4142434445464748
print(p32(s32))
print(p64(s64))
s32 = "ABCD"
s64 = "ABCDEFGH"
print(hex(u32(s32)))
print(hex(u64(s64)))
-----결과-----------
b'DCBA'
b'HGFEDCBA'
0x44434241
0x4847464544434241
셸 획득, 입출력 확인
p.interactive()
Elf 헤더 확인
e = ELF('./test')
puts_plt = e.plt['puts'] # ./test에서 puts()의 PLT주소를 찾아서 puts_plt에 저장
read_got = e.got['read'] # ./test에서 read()의 GOT주소를 찾아서 puts_plt에 저장
디버그
context.log_level = 'error' # 에러만 출력
context.log_level = 'debug' # 대상 프로세스와 익스플로잇간에 오가는 모든 데이터를 화면에 출력
context.log_level = 'info' # 비교적 중요한 정보들만 출력
아키텍쳐 지정
context.arch = "amd64" # x86-64 아키텍처
context.arch = "i386" # x86 아키텍처
context.arch = "arm" # arm 아키텍처
셸코드 지정
context.arch = 'amd64' # 대상 아키텍처 x86-64
code = shellcraft.sh() # 셸을 실행하는 셸 코드
print(code)
어셈블
context.arch = 'amd64' # 익스플로잇 대상 아키텍처 'x86-64'
code = shellcraft.sh() # 셸을 실행하는 셸 코드
code = asm(code) # 셸 코드를 기계어로 어셈블
print(code)