πŸ”’μ •λ³΄λ³΄μ•ˆ/μ‹œμŠ€ν…œ λ³΄μ•ˆ

μ‹œμŠ€ν…œ λ³΄μ•ˆ - pwntools

Janger 2023. 3. 25. 01:07
728x90

 

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

 

 

https://tekiter.tistory.com/4

 

Pwntools κΈ°λ³Έ μ‚¬μš©λ²•

Pwntools μ†Œκ°œ Pwntools λŠ” λ¦¬λˆ…μŠ€ ν™˜κ²½μ—μ„œ μ΅μŠ€ν”Œλ‘œμž‡μ„ μ§œλŠ” 것을 μ‰½κ²Œ ν•  수 있게 ν•΄μ£ΌλŠ” 파이썬 λΌμ΄λΈŒλŸ¬λ¦¬λ‹€. 곡식 Github μ£Όμ†Œ : https://github.com/Gallopsled/pwntools 곡식 λ¬Έμ„œ μ£Όμ†Œ : http://docs.pwntools.com

tekiter.tistory.com

 

 

https://lclang.tistory.com/90

 

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

 

728x90