Skip to content

Commit

Permalink
Merge branch 'dev' into commandline-deprecate
Browse files Browse the repository at this point in the history
  • Loading branch information
peace-maker authored Dec 10, 2024
2 parents 72f6a61 + 74a300d commit 7e4044b
Show file tree
Hide file tree
Showing 18 changed files with 380 additions and 106 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ jobs:
set -x
pip install pylint
pip install --upgrade -e .
pylint --exit-zero --errors-only pwnlib -f parseable | cut -d ' ' -f2- > current.txt
run_pylint() { pylint --exit-zero --errors-only pwnlib -f parseable | cut -d ' ' -f2- | sed 's/line [0-9]\+/line XXXX/g'; }
run_pylint > current.txt
git fetch origin
git checkout origin/"$GITHUB_BASE_REF"
pylint --exit-zero --errors-only pwnlib -f parseable | cut -d ' ' -f2- > base.txt
run_pylint > base.txt
if diff base.txt current.txt | grep '>'; then
false
fi
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ The table below shows which release corresponds to each branch, and what date th
- [#2482][2482] Throw error when using `sni` and setting `server_hostname` manually in `remote`
- [#2478][2478] libcdb-cli: add `--offline-only`, refactor unstrip and add fetch parser for download libc-database
- [#2484][2484] Allow to disable caching
- [#2291][2291] Fix attaching to a gdbserver with tuple `gdb.attach(('0.0.0.0',12345))`
- [#2410][2410] Add `tube.upload_manually` to upload files in chunks
- [#2502][2502] Fix loading ELF files without valid .dynamic section
- [#2476][2476] Deprecate 'keepends' argument in favor of 'drop' in `tube.recvline*`
- [#2364][2364] Deprecate direct commandline scripts invocation and exclude nonsense ones

[2471]: https://github.com/Gallopsled/pwntools/pull/2471
Expand All @@ -97,6 +101,10 @@ The table below shows which release corresponds to each branch, and what date th
[2482]: https://github.com/Gallopsled/pwntools/pull/2482
[2478]: https://github.com/Gallopsled/pwntools/pull/2478
[2484]: https://github.com/Gallopsled/pwntools/pull/2484
[2291]: https://github.com/Gallopsled/pwntools/pull/2291
[2410]: https://github.com/Gallopsled/pwntools/pull/2410
[2502]: https://github.com/Gallopsled/pwntools/pull/2502
[2476]: https://github.com/Gallopsled/pwntools/pull/2476
[2364]: https://github.com/Gallopsled/pwntools/pull/2364

## 4.14.0 (`beta`)
Expand Down Expand Up @@ -143,6 +151,12 @@ The table below shows which release corresponds to each branch, and what date th
[2435]: https://github.com/Gallopsled/pwntools/pull/2435
[2437]: https://github.com/Gallopsled/pwntools/pull/2437

## 4.13.2

- [#2497][2497] Fix remote.fromsocket() to handle AF_INET6 socket

[2497]: https://github.com/Gallopsled/pwntools/pull/2497

## 4.13.1 (`stable`)

- [#2445][2445] Fix parsing the PLT on Windows
Expand Down
5 changes: 3 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ capstone
coverage[toml]
python-dateutil
doc2dash
docutils<0.18
docutils<0.18; python_version<'3'
docutils>=0.18; python_version>='3'
intervaltree
isort
mako>=1.0.0
Expand All @@ -18,6 +19,6 @@ psutil
requests>=2.5.1
ropgadget>=5.3
sphinx==1.8.6; python_version<'3'
sphinx>=4.5.0; python_version>='3'
sphinx>=7.0.0; python_version>='3'
sphinx_rtd_theme
sphinxcontrib-autoprogram<=0.1.5
3 changes: 3 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ def linkcode_resolve(domain, info):
else:
filename = info['module'].replace('.', '/') + '.py'

if isinstance(val, property):
val = val.fget

if isinstance(val, (types.ModuleType, types.MethodType, types.FunctionType, types.TracebackType, types.FrameType, types.CodeType) + six.class_types):
try:
lines, first = inspect.getsourcelines(val)
Expand Down
9 changes: 9 additions & 0 deletions docs/source/protocols.rst
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
.. testsetup:: *

from pwn import *


:mod:`pwnlib.protocols.adb` --- Protocol implementations
========================================================

.. automodule:: pwnlib.protocols.adb
:members:
6 changes: 3 additions & 3 deletions docs/source/shellcraft/riscv64.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
context.clear(arch='riscv64')

:mod:`pwnlib.shellcraft.riscv64` --- Shellcode for RISCV64
===========================================================
==========================================================

:mod:`pwnlib.shellcraft.riscv64`
-------------------------------
--------------------------------

.. automodule:: pwnlib.shellcraft.riscv64
:members:

:mod:`pwnlib.shellcraft.riscv64.linux`
---------------------------------------
--------------------------------------

.. automodule:: pwnlib.shellcraft.riscv64.linux
:members:
2 changes: 1 addition & 1 deletion docs/source/windbg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pwn import *

:mod:`pwnlib.windbg` --- Working with WinDbg
======================================
============================================

.. automodule:: pwnlib.windbg
:members:
8 changes: 4 additions & 4 deletions pwnlib/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ def quiet(self, function=None):
... log.debug("DEBUG")
... log.info("INFO")
... log.warn("WARN")
[DEBUG] DEBUG
[*] INFO
[!] WARN
[...] DEBUG
[...] INFO
[...] WARN
"""
level = 'error'
if context.log_level <= logging.DEBUG:
Expand Down Expand Up @@ -664,7 +664,7 @@ def verbose(self):
information is printed.
>>> with context.verbose: func()
[DEBUG] Hello
[...] Hello
"""
return self.local(log_level='debug')
Expand Down
8 changes: 4 additions & 4 deletions pwnlib/elf/corefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ class Corefile(ELF):
Registers can be accessed directly, e.g. via ``core_obj.eax`` and enumerated
via :data:`Corefile.registers`.
Memory can be accessed directly via :meth:`.read` or :meth:`.write`, and also
via :meth:`.pack` or :meth:`.unpack` or even :meth:`.string`.
Memory can be accessed directly via :meth:`pwnlib.elf.elf.ELF.read` or :meth:`pwnlib.elf.elf.ELF.write`, and also
via :meth:`pwnlib.elf.elf.ELF.pack` or :meth:`pwnlib.elf.elf.ELF.unpack` or even :meth:`.string`.
Arguments:
core: Path to the core file. Alternately, may be a :class:`.process` instance,
Expand Down Expand Up @@ -376,8 +376,8 @@ class Corefile(ELF):
>>> core.exe.data[0:4]
b'\x7fELF'
It also supports all of the features of :class:`ELF`, so you can :meth:`.read`
or :meth:`.write` or even the helpers like :meth:`.pack` or :meth:`.unpack`.
It also supports all of the features of :class:`ELF`, so you can :meth:`pwnlib.elf.elf.ELF.read`
or :meth:`pwnlib.elf.elf.ELF.write` or even the helpers like :meth:`pwnlib.elf.elf.ELF.pack` or :meth:`pwnlib.elf.elf.ELF.unpack`.
Don't forget to call :meth:`.ELF.save` to save the changes to disk.
Expand Down
9 changes: 5 additions & 4 deletions pwnlib/elf/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from elftools.elf.constants import P_FLAGS
from elftools.elf.constants import SHN_INDICES
from elftools.elf.descriptions import describe_e_type
from elftools.elf.dynamic import DynamicSection
from elftools.elf.elffile import ELFFile
from elftools.elf.enums import ENUM_GNU_PROPERTY_X86_FEATURE_1_FLAGS
from elftools.elf.gnuversions import GNUVerDefSection
Expand Down Expand Up @@ -1607,7 +1608,7 @@ def dynamic_by_tag(self, tag):
dt = None
dynamic = self.get_section_by_name('.dynamic')

if not dynamic:
if not dynamic or not isinstance(dynamic, DynamicSection):
return None

try:
Expand Down Expand Up @@ -2350,7 +2351,7 @@ def disable_nx(self):

@staticmethod
def set_runpath(exepath, runpath):
r"""set_runpath(str, str) -> ELF
r"""set_runpath(exepath, runpath) -> ELF
Patches the RUNPATH of the ELF to the given path using the `patchelf utility <https://github.com/NixOS/patchelf>`_.
Expand Down Expand Up @@ -2385,7 +2386,7 @@ def set_runpath(exepath, runpath):

@staticmethod
def set_interpreter(exepath, interpreter_path):
r"""set_interpreter(str, str) -> ELF
r"""set_interpreter(exepath, interpreter_path) -> ELF
Patches the interpreter of the ELF to the given binary using the `patchelf utility <https://github.com/NixOS/patchelf>`_.
Expand Down Expand Up @@ -2419,7 +2420,7 @@ def set_interpreter(exepath, interpreter_path):

@staticmethod
def patch_custom_libraries(exe_path, custom_library_path, create_copy=True, suffix='_remotelibc'):
r"""patch_custom_libraries(str, str, bool, str) -> ELF
r"""patch_custom_libraries(exe_path, custom_library_path, create_copy=True, suffix='_remotelibc') -> ELF
Looks for the interpreter binary in the given path and patches the binary to use
it if available. Also patches the RUNPATH to the given path using the `patchelf utility <https://github.com/NixOS/patchelf>`_.
Expand Down
16 changes: 15 additions & 1 deletion pwnlib/fmtstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ def fmtstr_payload(offset, writes, numbwritten=0, write_size='byte', write_size_
The overflows argument is a format-string-length to output-amount tradeoff:
Larger values for ``overflows`` produce shorter format strings that generate more output at runtime.
The writes argument is a dictionary with address/value pairs like ``{addr: value, addr2: value2}``.
If the value is an ``int`` datatype, it will be automatically casted into a bytestring with the length of a ``long`` (8 bytes in 64-bit, 4 bytes in 32-bit).
If a specific number of bytes is intended to be written (such as only a single byte, single short, or single int and not an entire long),
then provide a bytestring like ``b'\x37\x13'`` or ``p16(0x1337)``.
Note that the ``write_size`` argument does not determine **total** bytes written, only the size of each consecutive write.
Arguments:
offset(int): the first formatter's offset you control
writes(dict): dict with addr, value ``{addr: value, addr2: value2}``
Expand All @@ -857,6 +863,8 @@ def fmtstr_payload(offset, writes, numbwritten=0, write_size='byte', write_size_
>>> context.clear(arch = 'amd64')
>>> fmtstr_payload(1, {0x0: 0x1337babe}, write_size='int')
b'%322419390c%4$llnaaaabaa\x00\x00\x00\x00\x00\x00\x00\x00'
>>> fmtstr_payload(1, {0x0: p32(0x1337babe)}, write_size='int')
b'%322419390c%3$na\x00\x00\x00\x00\x00\x00\x00\x00'
>>> fmtstr_payload(1, {0x0: 0x1337babe}, write_size='short')
b'%47806c%5$lln%22649c%6$hnaaaabaa\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00'
>>> fmtstr_payload(1, {0x0: 0x1337babe}, write_size='byte')
Expand All @@ -872,6 +880,8 @@ def fmtstr_payload(offset, writes, numbwritten=0, write_size='byte', write_size_
b'%19c%12$hhn%36c%13$hhn%131c%14$hhn%4c%15$hhn\x03\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00'
>>> fmtstr_payload(1, {0x0: 0x00000001}, write_size='byte')
b'c%3$naaa\x00\x00\x00\x00'
>>> fmtstr_payload(1, {0x0: b'\x01'}, write_size='byte')
b'c%3$hhna\x00\x00\x00\x00'
>>> fmtstr_payload(1, {0x0: b"\xff\xff\x04\x11\x00\x00\x00\x00"}, write_size='short')
b'%327679c%7$lln%18c%8$hhn\x00\x00\x00\x00\x03\x00\x00\x00'
>>> fmtstr_payload(10, {0x404048 : 0xbadc0ffe, 0x40403c : 0xdeadbeef}, no_dollars=True)
Expand Down Expand Up @@ -999,7 +1009,7 @@ def write(self, addr, data):
Arguments:
addr(int): the address where you want to write
data(int): the data that you want to write ``addr``
data(int or bytes): the data that you want to write ``addr``
Returns:
None
Expand All @@ -1013,6 +1023,10 @@ def write(self, addr, data):
>>> f.write(0x08040506, 0x1337babe)
>>> f.execute_writes()
b'%19c%16$hhn%36c%17$hhn%131c%18$hhn%4c%19$hhn\t\x05\x04\x08\x08\x05\x04\x08\x07\x05\x04\x08\x06\x05\x04\x08'
>>> f2 = FmtStr(send_fmt_payload, offset=5)
>>> f2.write(0x08040506, p16(0x1337))
>>> f2.execute_writes()
b'%19c%11$hhn%36c%12$hhnaa\x07\x05\x04\x08\x06\x05\x04\x08'
"""
self.writes[addr] = data
Loading

0 comments on commit 7e4044b

Please sign in to comment.