Pwntools 사용법 정리

1. 연결

1-1. NC
p = remote(‘host’, port)
ex) p = remote(‘pinkjelly.cat’, 1234)

1-2. Local
p = process(‘file’)
ex) p = process(‘./pwnme’)

1-3. SSH
conn = ssh(‘user’, ‘host’, port = port, password = ‘password’)
p = conn.run(‘file’)
ex) conn = ssh(‘p1nkjelly’, ‘pinkjelly.cat’, port=1234, password=’p@ssw0rd’)
p = conn.run(‘./pwnme’)

1-4. Interactive
p.interactive()

2. 데이터 받기, 보내기

2-1. recv
p.recv(len)
ex) print(p.recv(1024)) – 1024만큼 데이터를 받아서 출력

2-2. recvline
p.recvline
ex) print(p.recvline()) – 한 줄만큼(\n까지) 데이터를 받아서 출력

2-3. recvuntil
p.recvuntil(‘str’)
ex) print(p.recvuntil(‘ ‘)) – 공백 까지 받아와서 출력

2-4. send
p.send(‘str’)

2-5. sendline
p.sendline(‘str’) – 뒤에 \n 붙여서 전송

3. 패킹, 언패킹

3-1. p32
p32(int) –
ex) p32(0x12345678) -> \x78\x56\x34\x12

3-2. p64
p64(int)
p32와 기능 같으나 64bit

3-3. u32
u32(‘str’)
ex) u32(‘\x78\x56\x34\x12’) -> 0x12345678

3-4. u64
u64(‘str’)
u32와 기능 같으나 64bit

4. ELF

4-1. ELF
e = ELF(‘file’)
file에 ELF나 libc 파일 이름 넣으면 됨

4-2. symbols
e.symbols[‘func name’] – 딕셔너리 type
ex) test = hex(e.symbols[‘test’])

4-3. plt
e.plt[‘func name’] – 딕셔너리 type
ex) puts_plt = hex(e.plt[‘puts’])

4-4. got
e.got[‘func name’] – 딕셔너리 type
ex) printf_got = hex(e.got[‘printf’])

4-5. search
e.search(‘str’).next()
ex) binsh = e.search(‘/bin/sh’).next()

5. ETC…

5-1. fmtstr_payload
fmtstr_payload(offset, {덮을 주소, 덮을 값})
ex) exit_got = e.got[‘exit’]
getshell = e.symbols[‘getshell’]
payload = fmtstr_payload(1, {exit_got, getshell})

5-2. context.log_level
context.log_level = ‘debug’, context.log_level = ‘error’

5-3. shellcraft
asm(shellcraft.i386.sh()) – 32bit 쉘코드
asm(shellcraft.amd64.sh(), arch=’amd64′) – 64bit 쉘코드
공부가 좀 더 필요함


To be continued…

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 항목은 *(으)로 표시합니다