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