μμ€ν 보μ - pwntools
pwntoolsλ 리λ μ€ νκ²½μμ μ€ν νλ‘κ·Έλ¨μ μ΅μ€νλ‘μμ μμ±νλλ‘ λμμ μ£Όλ νμ΄μ¬ λΌμ΄λΈλ¬λ¦¬μ΄λ€. CTFμμλ μ μ©νκ² μ¬μ©λ μ μλ€.
pip μ€μΉ λͺ λ Ήμ΄
python3 -m pip install --upgrade pwntools
μ¬μ© μμ
>>> conn = remote('ftp.ubuntu.com',21)
>>> conn.recvline() # doctest: +ELLIPSIS
b'220 ...'
>>> conn.send(b'USER anonymous\r\n')
>>> conn.recvuntil(b' ', drop=True)
b'331'
>>> conn.recvline()
b'Please specify the password.\r\n'
>>> conn.close()
nc(NetCat), FTP κ°μ 리λͺ¨νΈ μ°κ²°λ κ°λ₯νλ€.
>>> from pwn import *
>>> sh = process('/bin/sh')
>>> sh.sendline(b'sleep 3; echo hello world;')
>>> sh.recvline(timeout=1)
b''
>>> sh.recvline(timeout=5)
b'hello world\n'
>>> sh.close()
μ£Όμ κΈ°λ₯λ€
proc = process('/bin/sh') # νλ‘μΈμ€ μ€ν ν μνΈμμ©(μ
μΆλ ₯) κ°λ₯
proc.send("echo hello world!;") # νλ‘μΈμ€λ‘λΆν° "echo hello world!;" μ λ¬
proc.sendline("echo hello world!") # νλ‘μΈμ€λ‘λΆν° "echo hello world!\n" μ λ¬
proc.recv(4) # νλ‘μΈμ€λ‘λΆν° 4λ°μ΄νΈ λ¬Έμμ΄ κ°μ Έμ€κΈ°
proc.recvline(timeout=1) # νλ‘μΈμ€λ‘λΆν° ν λΌμΈμ λ΄μ©μ κ°μ Έμ¨λ€. (νμμμ μ§μ κ°λ₯)
proc.recvuntil('abcd') # νλ‘μΈμ€λ‘λΆν° "abcd" λ¬Έμμ΄κΉμ§ λ΄μ©μ κ°μ Έμ¨λ€.
proc.interactive() # μ¬μ©μκ° μ§μ νλ‘μΈμ€ μ‘°μμ΄ κ°λ₯νλ€.
proc.close() # νλ‘μΈμ€ μ’
λ£
ν¨νΉ(Packing)
p32: 32bit Little endian Packing
ex) p32(0x12345678) => \x78\x56\x34\x12
λΉ μλμ λ°©μ: p32(0x12345678, endian='big')
p64: 64bit Little endian Packing
ex) p64(0x12345678) => \x00\x00\x00\x00\x78\x56\x34\x12
λΉ μλμ λ°©μ: p64(0x12345678, endian='big')
μλμ° μ μ© pwntools(winpwn)
pwntoolsλ νκ²½ λ¬Έμ λ‘ μλμ°μμλ μ¬μ©μ΄ μλλλ° μλμ° μ μ© pwntools(winpwn)λ μλ€.
https://github.com/Byzero512/winpwn
GitHub - Byzero512/winpwn: CTF windows pwntools
CTF windows pwntools. Contribute to Byzero512/winpwn development by creating an account on GitHub.
github.com
pip μ€μΉ λͺ λ Ήμ΄
pip install winpwn
μ¬μ© λ°©λ²μ κΉνλΈμμ μ§μ μ°Έμ‘°
μ°Έκ³ :
https://docs.pwntools.com/en/stable/intro.html#tutorials
Getting Started — pwntools 4.8.0 documentation
To get your feet wet with pwntools, let’s first go through a few examples. When writing exploits, pwntools generally follows the “kitchen sink” approach. This imports a lot of functionality into the global namespace. You can now assemble, disassemble
docs.pwntools.com
Pwntools κΈ°λ³Έ μ¬μ©λ²
Pwntools μκ° Pwntools λ 리λ μ€ νκ²½μμ μ΅μ€νλ‘μμ μ§λ κ²μ μ½κ² ν μ μκ² ν΄μ£Όλ νμ΄μ¬ λΌμ΄λΈλ¬λ¦¬λ€. 곡μ Github μ£Όμ : https://github.com/Gallopsled/pwntools 곡μ λ¬Έμ μ£Όμ : http://docs.pwntools.com
tekiter.tistory.com
Pwntools κΈ°λ³Έμ μΈ μ¬μ©λ² - 2
μ΄λ²μλ μ΅μ€ν λ μ£Όλ‘ μ¬μ©νλκ²μ μ¨λ³Όκ²λλ€ λ¨Όμ ν¨νΉ κ΄λ ¨ ν¨μλ€ μ λλ€. 1. packing 1-1. p32 32bit little endian μΌλ‘ packing ν΄μ£Όλ ν¨μμ λλ€. p32(int) / return str ex ) p32(0x12345678) => \x78\x56\x34\x12
lclang.tistory.com