pwntools 工具手册
一、连接
1. process
- 建立一个本地连接
class process( argv: Any | None = None, shell: bool = False, executable: Any | None = None, cwd: Any | None = None, env: Any | None = None, stdin: int = PIPE, stdout: PTY = PTY, stderr: int = STDOUT, close_fds: bool = True, preexec_fn: () -> None = lambda : None, raw: bool = True, aslr: Any | None = None, setuid: Any | None = None, where: str = 'local', display: Any | None = None, alarm: Any | None = None, *args: Any, **kwargs: Any )
- 使用例:
process("./passcode")
2. remote
- 建立一个远程 socket
class remote( host: str, port: int, fam: str = "any", typ: str = "tcp", ssl: bool = False, sock: Any | None = None, ssl_context: Any | None = None, ssl_args: Any | None = None, sni: bool = True, *args: Any, **kwargs: Any )
- 使用例:
remote('ftp.debian.org',21)
3. ssh
- 远程建立 ssh 连接
class ssh( user: Any | None = None, host: Any | None = None, port: int = 22, password: Any | None = None, key: Any | None = None, keyfile: Any | None = None, proxy_command: Any | None = None, proxy_sock: Any | None = None, level: Any | None = None, cache: bool = True, ssh_agent: bool = False, ignore_config: bool = False, raw: bool = False, *a: Any, **kw: Any )
- 使用例:
ssh(host='pwnable.kr', port=2222, user='passcode', password='guest')
二、IO 模块
sh.send(data) # 发送数据
sh.sendline(data) # 发送一行数据,相当于在数据后面加\n
sh.recv(numb = 2048, timeout = dufault) # 接受数据,numb指定接收的字节,timeout指定超时
sh.recvline(keepends=True) # 接受一行数据,keepends为是否保留行尾的\n
sh.recvuntil("Hello,World\n",drop=fasle) # 接受数据直到设置的标志出现
sh.recvall() # 一直接收直到EOF
sh.recvrepeat(timeout = default) # 持续接受直到EOF或timeout
sh.interactive() # 直接进行交互,相当于回到shell的模式,在取得shell之后使用
三、数据打包与解包
- pack:
p32
,p64
- unpack:
u32
,u64
- 使用例
fflush_got = 0x804a004 padding = b'A' * 96 + p32(fflush_got)
- 注意:由于 python3 不允许不同类型字符串直接相加,因此数据在打包和解包以及拼接的过程中要注意
bytes
和str
类型的区分和转换。- 字符串转字节可以使用
encode("iso-8859-15")
或使用b""
标志(如b"abc"
) - 字节转字符串可以使用
decode("iso-8859-15")
- 字符串转字节可以使用