관리 메뉴

Bull

[pwntools] 함수 및 모듈 정리 본문

Computer Science/System Hacking

[pwntools] 함수 및 모듈 정리

Bull_ 2023. 9. 27. 03:49

pwntools란?

드림핵에서 시스템해킹 트랙을 하기에 필수적인 파이썬 툴이다. 드림핵 뿐만 아니라 일반적으로 포너블에서 쉘을 따기위해 필요한 도구이다.

함수정리

remote()

r = remote("localhost", 8888)

원격주소에 nc 명령어 역할을 해준다.

process()

p = process("./실행파일")

실행파일을 연결해준다.

recv()

r = remote("localhost", 8888)
m = r.recv()
m = r.recv(10) # 10byte 만큼 받아온다.

receive의 단축말이다.
연결된 대상에서 데이터를 받는다.

recvline()

r = remote("localhost", 8888)
m = r.recvline()

연결된 대상에서 \n 까지 받는다. 즉 한 줄만 받는다.

recvuntil()

r = remote("localhost", 8888)
m = r.recvuntil("input :")

input : 까지 받은 상태로 만든다.

send()

r = remote("localhost", 8888)
r.send(data)

연결된 대상으로 데이터를 보낸다.

sendline()

r = remote("localhost", 8888)
r.senline(data)

연결된 대상으로 데이터를 보내고 한 줄을 보낸다.

p32()

m = p32(0x12345678) # \x78\x56\x34\x12

p32(value, endian='big') : 빅엔디안 방식
32bit 리틀엔디안 방식으로 패킹해준다.

p64()

m = p64(0x12345678) # \x00\x00\x00\x00\x78\x56\x34\x12

p64(value, endian='big') : 빅엔디안 방식
64bit 리틀엔디안 방식으로 패킹해준다.

u32()

m = u32(\x78\x56\x34\x12) # 305419896(0x12345678)

u32(number, sign, endian, ...)
return int형
32bit 리틀엔디안 방식으로 정수형으로 언패킹해준다.

u64()

m = u64(\x00\x00\x00\x00\x78\x56\x34\x12) # 305419896(0x12345678)

u64(number, sign, endian, ...)
return int형
64bit 리틀엔디안 방식으로 정수형으로 언패킹해준다.

intrective()

r = remote("localhost",8888)
r.interacrive()

/bin/sh와 같이 쉘 권한을 획득한 경우와 같은 상황에서 명령을 전송 수신할 수 있다.

ELF()

elf = ELF("./실행파일")
plt = elf.plt
got = elf.plt
symbols = elf.symbols

리눅스의 ELF에 바이너리를 인식시켜 적용되어 있는 보호기법을 보여준다. (딕셔너리 형태)

.plt : plt 링킹된 라이브러리 주소를 가져온다.
.got : got 링킹된 라이브러리 주소를 가져온다.
.symbols : 함수의 오프셋주소를 가져온다.
.address : 매핑된 시작주소

 

 


context.log_level = 'debug'

통신 과정으로 주고 받는 데이터를 보기 쉽게 보여줌.

 

github

https://github.com/Gallopsled/pwntools

 

GitHub - Gallopsled/pwntools: CTF framework and exploit development library

CTF framework and exploit development library. Contribute to Gallopsled/pwntools development by creating an account on GitHub.

github.com

document

https://docs.pwntools.com/en/stable/util/packing.html

 

pwnlib.util.packing — Packing and unpacking of strings — pwntools 4.11.0 documentation

Module for packing and unpacking integers. Simplifies access to the standard struct.pack and struct.unpack functions, and also adds support for packing/unpacking arbitrary-width integers. The packers are all context-aware for endian and signed arguments, t

docs.pwntools.com

 

'Computer Science > System Hacking' 카테고리의 다른 글

[System Hacking] PLT & GOT  (0) 2024.04.10
[System Hacking] NX & ASLR  (0) 2024.04.09
[System Hacking] Stack Canary  (0) 2024.04.06
[System Hacking] Return Address Overwrite  (0) 2024.04.05
[System Hacking] Shell Code 및 syscall  (2) 2024.03.31