Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#2419][2419] riscv: avoid compressed instructions (if you need compressed, use .option rvc)
- [#2551][2551] Detect when kitty is being used as terminal
- [#2519][2519] Drop Python 2.7 support / Require Python 3.10
- [#2588][2588] Drop newline in `tube.recvline` by default
- [#2507][2507] Add `+LINUX` and `+WINDOWS` doctest options and start proper testing on Windows
- [#2522][2522] Support starting a kitty debugging window with the 'kitten' command
- [#2524][2524] Raise EOFError during `process.recv` when stdout closes on Windows
Expand Down Expand Up @@ -107,6 +108,7 @@ The table below shows which release corresponds to each branch, and what date th
[2419]: https://github.com/Gallopsled/pwntools/pull/2419
[2551]: https://github.com/Gallopsled/pwntools/pull/2551
[2519]: https://github.com/Gallopsled/pwntools/pull/2519
[2588]: https://github.com/Gallopsled/pwntools/pull/2588
[2507]: https://github.com/Gallopsled/pwntools/pull/2507
[2522]: https://github.com/Gallopsled/pwntools/pull/2522
[2524]: https://github.com/Gallopsled/pwntools/pull/2524
Expand Down
6 changes: 3 additions & 3 deletions docs/source/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ For example, remote connections via :mod:`pwnlib.tubes.remote`.
>>> conn.send(b'USER anonymous\r\n')
>>> conn.recvuntil(b' ', drop=True)
b'331'
>>> conn.recvline()
>>> conn.recvline(drop=False)
b'Please specify the password.\r\n'
>>> conn.close()

Expand All @@ -65,7 +65,7 @@ Interacting with processes is easy thanks to :mod:`pwnlib.tubes.process`.
>>> sh.recvline(timeout=1)
b''
>>> sh.recvline(timeout=5)
b'hello world\n'
b'hello world'
>>> sh.close()

Not only can you interact with processes programmatically, but you can
Expand All @@ -91,7 +91,7 @@ a ``process`` tube.
>>> sh.recvline(timeout=1)
b''
>>> sh.recvline(timeout=5)
b'hello world\n'
b'hello world'
>>> shell.close()

Packing Integers
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/adb/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def __do_deferred_initialization(self):
r.recvuntil('OK')
r.recvline() # Rest of the line
r.sendline('avd name')
self.avd = r.recvline().strip()
self.avd = r.recvline()
except:
pass

Expand Down
2 changes: 1 addition & 1 deletion pwnlib/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def make_elf(data,
>>> p = process(filename)
>>> p.sendline(b'echo Hello; exit')
>>> p.recvline()
b'Hello\n'
b'Hello'
"""
retval = None

Expand Down
2 changes: 1 addition & 1 deletion pwnlib/elf/corefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class Corefile(ELF):
>>> io = process(elf.path, env=env)
>>> io.sendline(b'echo hello')
>>> io.recvline()
b'hello\n'
b'hello'

The process is still running, but accessing its :attr:`.process.corefile` property
automatically invokes GDB to attach and dump a corefile.
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/encoders/amd64/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class amd64DeltaEncoder(i386DeltaEncoder):
>>> p = run_shellcode(encoded)
>>> p.sendline(b'echo hello; exit')
>>> p.recvline()
b'hello\n'
b'hello'
"""
assembly = '''
base:
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/encoders/arm/xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ArmXorEncoder(Encoder):
>>> p = run_shellcode(encoded)
>>> p.sendline(b'echo hello; exit')
>>> p.recvline()
b'hello\n'
b'hello'
"""

arch = 'arm'
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/encoders/i386/xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class i386XorEncoder(Encoder):
>>> p = run_shellcode(encoded)
>>> p.sendline(b'echo hello; exit')
>>> p.recvline()
b'hello\n'
b'hello'
>>> encoders.i386.xor.encode(asm(shellcraft.execve('/bin/sh')), avoid=bytearray([0x31]))
b'\xd9\xd0\xd9t$\xf4^\xfcj\x07Y\x83\xc6\x19\x89\xf7\xad\x93\xad1\xd8\xabIu\xf7\x00\x00\x00\x00h\x01\x01\x01\x00\x00\x00\x00\x01\x814$\x00\x00\x00\x00.ri\x01\x00\x00\x00\x00h/bi\x00\x00\x00\x01n\x89\xe30\x00\x01\x00\x00\xc90\xd2j\x00\x00\x00\x00\x0bX\xcd\x80'
"""
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/encoders/mips/xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class MipsXorEncoder(Encoder):
>>> p = run_shellcode(encoded)
>>> p.sendline(b'echo hello; exit')
>>> p.recvline()
b'hello\n'
b'hello'
"""

arch = 'mips'
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/filesystem/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def mkdir(self, mode=0o777, parents=False, exist_ok=True):
>>> f = SSHPath('dirA/dirB/dirC', ssh=ssh_conn)
>>> f.mkdir(parents=True)
>>> ssh_conn.run(['ls', '-la', f.absolute().path], env={'LC_ALL': 'C.UTF-8'}).recvline()
b'total 8\n'
b'total 8'
"""
if exist_ok and self.is_dir():
return
Expand Down
36 changes: 18 additions & 18 deletions pwnlib/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def debug_assembly(asm, gdbscript=None, vma=None, api=False):
>>> assembly = shellcraft.echo("Hello world!\n")
>>> io = gdb.debug_assembly(assembly)
>>> io.recvline()
b'Hello world!\n'
b'Hello world!'
"""
tmp_elf = make_elf_from_assembly(asm, vma=vma, extract=False)
os.chmod(tmp_elf, 0o777)
Expand Down Expand Up @@ -229,7 +229,7 @@ def debug_shellcode(data, gdbscript=None, vma=None, api=False):
>>> shellcode = asm(assembly)
>>> io = gdb.debug_shellcode(shellcode)
>>> io.recvline()
b'Hello world!\n'
b'Hello world!'
"""
if isinstance(data, str):
log.error("Shellcode is cannot be unicode. Did you mean debug_assembly?")
Expand Down Expand Up @@ -485,7 +485,7 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por

>>> io.sendline(b"echo hello")
>>> io.recvline()
b'hello\n'
b'hello'

Interact with the process

Expand All @@ -509,7 +509,7 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por

>>> io.sendline(b"echo hello")
>>> io.recvline()
b'hello\n'
b'hello'

Interact with the process

Expand All @@ -521,7 +521,7 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por
>>> io = gdb.debug(args=[b'\xde\xad\xbe\xef'], gdbscript='continue', exe="/bin/sh")
>>> io.sendline(b"echo $0")
>>> io.recvline()
b'\xde\xad\xbe\xef\n'
b'\xde\xad\xbe\xef'
>>> io.close()

Demonstrate that LD_PRELOAD is respected
Expand Down Expand Up @@ -567,15 +567,15 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por
>>> io = gdb.debug(args=[b'\xde\xad\xbe\xef'], gdbscript='continue', exe="/bin/sh", ssh=shell)
>>> io.sendline(b"echo $0")
>>> io.recvline()
b'$ \xde\xad\xbe\xef\n'
b'$ \xde\xad\xbe\xef'
>>> io.close()

Using an empty args[0] on a remote process

>>> io = gdb.debug(args=[], gdbscript='continue', exe="/bin/sh", ssh=shell)
>>> io.sendline(b"echo $0")
>>> io.recvline()
b'$ \n'
b'$ '
>>> io.close()


Expand Down Expand Up @@ -612,12 +612,12 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por

>>> io.gdb.continue_nowait()
>>> io.recvline()
b'foo\n'
b'foo'
>>> io.close()

>>> ssh_io.gdb.continue_nowait()
>>> ssh_io.recvline()
b'foo\n'
b'foo'
>>> ssh_io.close()
>>> shell.close()
"""
Expand Down Expand Up @@ -979,7 +979,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
... quit
... ''')
>>> io.recvline()
b'Hello from process debugger!\n'
b'Hello from process debugger!'
>>> io.sendline(b'echo Hello from bash && exit')
>>> io.recvall()
b'Hello from bash\n'
Expand All @@ -1003,7 +1003,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
Observe the forced line

>>> io.recvline()
b'Hello from process debugger!\n'
b'Hello from process debugger!'

Interact with the program in a regular way

Expand All @@ -1027,7 +1027,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
... quit
... ''')
>>> io.recvline()
b'Hello from remote debugger!\n'
b'Hello from remote debugger!'
>>> io.sendline(b'echo Hello from bash && exit')
>>> io.recvall()
b'Hello from bash\n'
Expand All @@ -1048,12 +1048,12 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
... end
... ''')
>>> gdbserver.recvline(timeout=10) # doctest: +ELLIPSIS
b'Remote debugging from host 127.0.0.1, ...\n'
b'Remote debugging from host 127.0.0.1, ...'
>>> gdbserver.recvline(timeout=10)
b'Hello from gdbserver debugger!\n'
b'Hello from gdbserver debugger!'
>>> gdbserver.sendline(b'echo Hello from bash && exit')
>>> gdbserver.recvline(timeout=10)
b'Hello from bash\n'
b'Hello from bash'
>>> gdbserver.close()

Attach to processes running on a remote machine via an SSH :class:`.ssh` process
Expand All @@ -1067,10 +1067,10 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
... quit
... ''')
>>> io.recvline(timeout=5) # doctest: +SKIP
b'Hello from ssh debugger!\n'
b'Hello from ssh debugger!'
>>> io.sendline(b'This will be echoed back')
>>> io.recvline()
b'This will be echoed back\n'
b'This will be echoed back'
>>> io.close()

To attach to remote gdbserver, assume you have a socat server delivering gdbserver
Expand All @@ -1091,7 +1091,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
... io.recvline()
... io.close()
... server.close()
b'Hello\n'
b'Hello'
"""
if context.noptrace:
log.warn_once("Skipping debug attach since context.noptrace==True")
Expand Down
4 changes: 2 additions & 2 deletions pwnlib/rop/ret2dlresolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
>>> p = elf.process() # doctest: +LINUX
>>> p.sendline(fit({64+context.bytes*3: raw_rop, 200: dlresolve.payload})) # doctest: +LINUX
>>> p.recvline() # doctest: +LINUX
b'pwned\n'
b'pwned'

You can also use ``Ret2dlresolve`` on AMD64:

Expand All @@ -61,7 +61,7 @@
>>> if dlresolve.unreliable: # doctest: +LINUX
... p.poll(True) == -signal.SIGSEGV
... else:
... p.recvline() == b'pwned\n'
... p.recvline() == b'pwned'
True
"""

Expand Down
2 changes: 1 addition & 1 deletion pwnlib/rop/rop.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
>>> time.sleep(1)
>>> p.sendline(b'echo hello; exit')
>>> p.recvline()
b'hello\n'
b'hello'
"""
from __future__ import absolute_import
from __future__ import division
Expand Down
10 changes: 5 additions & 5 deletions pwnlib/rop/srop.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
>>> p = process(binary.path)
>>> p.send(bytes(frame))
>>> p.recvline()
b'Hello, World\n'
b'Hello, World'
>>> p.poll(block=True)
0

Expand All @@ -75,7 +75,7 @@
>>> p = process(binary.path)
>>> p.send(bytes(frame))
>>> p.recvline()
b'Hello, World\n'
b'Hello, World'
>>> p.poll(block=True)
0

Expand All @@ -101,7 +101,7 @@
>>> p = process(binary.path)
>>> p.send(bytes(frame))
>>> p.recvline()
b'Hello, World\n'
b'Hello, World'
>>> p.wait_for_close()
>>> p.poll(block=True)
0
Expand All @@ -128,7 +128,7 @@
>>> p = process(binary.path)
>>> p.send(bytes(frame))
>>> p.recvline()
b'Hello, World\n'
b'Hello, World'
>>> p.poll(block=True)
0

Expand All @@ -154,7 +154,7 @@
>>> p = process(binary.path)
>>> p.send(bytes(frame))
>>> p.recvline()
b'Hello, World\n'
b'Hello, World'
>>> p.poll(block=True)
0

Expand Down
2 changes: 1 addition & 1 deletion pwnlib/shellcraft/templates/aarch64/darwin/cat.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Example:
>>> write(f, 'This is the flag\n')
>>> shellcode = shellcraft.cat(f) + shellcraft.exit(0)
>>> run_assembly(shellcode).recvline()
b'This is the flag\n'
b'This is the flag'
</%docstring>
<%
if fd == 'x0':
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/shellcraft/templates/aarch64/darwin/cat2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Example:
>>> write(f, 'This is the flag\n')
>>> shellcode = shellcraft.cat2(f) + shellcraft.exit(0)
>>> run_assembly(shellcode).recvline()
b'This is the flag\n'
b'This is the flag'
</%docstring>
<%
if fd == 'x0':
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/shellcraft/templates/aarch64/linux/cat.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Example:
>>> write(f, 'This is the flag\n')
>>> shellcode = shellcraft.cat(f) + shellcraft.exit(0)
>>> run_assembly(shellcode).recvline()
b'This is the flag\n'
b'This is the flag'
</%docstring>
<%
if fd == 'x0':
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/shellcraft/templates/aarch64/linux/cat2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Example:
>>> write(f, 'This is the flag\n')
>>> shellcode = shellcraft.cat2(f) + shellcraft.exit(0)
>>> run_assembly(shellcode).recvline()
b'This is the flag\n'
b'This is the flag'
</%docstring>
<%
if fd == 'x0':
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/shellcraft/templates/aarch64/linux/echo.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Writes a string to a file descriptor
Example:

>>> run_assembly(shellcraft.echo('hello\n', 1)).recvline()
b'hello\n'
b'hello'

</%docstring>

Expand Down
2 changes: 1 addition & 1 deletion pwnlib/shellcraft/templates/aarch64/linux/stage.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Example:
>>> p.pack(len(sc))
>>> p.send(sc)
>>> p.recvline()
b'Hello\n'
b'Hello'
</%docstring>
<%
protection = C.PROT_READ | C.PROT_WRITE | C.PROT_EXEC
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/shellcraft/templates/amd64/linux/stage.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Example:
>>> p.pack(len(sc))
>>> p.send(sc)
>>> p.recvline()
b'Hello\n'
b'Hello'
</%docstring>
<%
protection = C.PROT_READ | C.PROT_WRITE | C.PROT_EXEC
Expand Down
Loading
Loading