170 Commits
Author SHA1 Message Date
peace-maker fb35a123b4 Fix some global type hint errors (#2736)
* Fix some global type hint errors

Errors in global scope should be fixed before we're enabling strict mode in mypy and tackle the local problems.

* Remove pwnlib.util.pairwise since it's in itertools now

pairwise was added to itertools itself in 3.10.
https://docs.python.org/3/library/itertools.html#itertools.pairwise
2026-05-28 17:16:27 +02:00
RocketDev bf68cc1e36 Refactor zsh completion script and deprecate -e in pwn asm (#2689)
* refactor: optimize completion script

And deprecate an interface

* chore: update changelog

* refactor: full patch of zsh comp script

* fix: add missing message in output

* fix: a typo and a missing help

* feat: allow -l to match multiple arguments

* feat: optimize completion logic

1. move all complicated functions in front of pwn()
2. add file completion for libcdb subcommands
3. add completion for pwn errno
2026-04-29 07:29:49 +02:00
Arusekk a58534382a Use format strings and raw strings (#2554) 2026-03-21 11:09:46 +01:00
RocketDev 5161b5ef23 Cleanup Python 2 legacy (#2680)
* Cleanup Python 2 legacy

* chore: update changelog
2026-02-20 10:48:42 +01:00
Th3S 01f8160a05 fix(libcdb-cli): return early if no matched libc found (#2646)
* Fix: return early if no matched libc found

* Update CHANGELOG
2025-11-22 13:22:20 +01:00
Lê Nam Khánh 3525980677 Fix typos in some files (#2648) 2025-11-06 23:26:06 +01:00
Arusekk 289bc8ede4 template: error message and fallback on no docker 2025-11-06 09:24:47 +01:00
peace-maker a85ad0390b Abort on libcdb file libc.so --unstrip if eu-unstrip is not installed (#2608)
* Abort on `libcdb file libc.so --unstrip` if eu-unstrip is not installed

Fixes #2586

* Update CHANGELOG
2025-09-04 17:00:57 +02:00
Peace-Maker 3677514a71 Merge branch 'beta' into dev 2025-08-06 14:49:12 +02:00
Chaitanya RahalkarandPeace-Maker 004a6dab88 Add automatic detection of statically linked binaries in detect_missing_binaries function. (#2570)
* Add automatic detection of statically linked binaries in `detect_missing_binaries` function.

* Add entry for PR #2570 to CHANGELOG.md: fix `pwn template` for statically linked binaries.

* Remove partial test implementation

The commands should be tested end-to-end instead of using doctests (later).

---------

Co-authored-by: Peace-Maker <[email protected]>
2025-07-11 13:10:40 +02:00
ArusekkandPeace-Maker 328b2cd447 Drop six (#2547)
Co-authored-by: Peace-Maker <[email protected]>
2025-02-28 12:15:04 +01:00
tesujiandpeace-maker 78d416ba61 checksec: Do NOT error when passing directory arguments to commandline tool (#2530)
I often use `checksec *` to lazily avoid typing filenames in a directory.
If the directory contains any other sub-dirs, the command fails.
With this patch, checksec will silently skip dir paths. There's still
TOCTOU issue but I don't think checksec do anything important enough
to explicitly use try/catch to account for that.

Co-authored-by: peace-maker <[email protected]>
2025-01-27 00:03:05 +01:00
fb2ee19b90 Deprecate direct commandline scripts invocation and exclude nonsense ones (#2364)
* deprecate direct commandline scripts invocation and exclude nonsense ones

* Don't deprecate all commandline tools

---------

Co-authored-by: Arusekk <[email protected]>
Co-authored-by: Peace-Maker <[email protected]>
2024-12-10 22:47:47 +01:00
Peace-Maker 61804b169b Merge branch 'beta' into dev 2024-10-24 23:28:53 +02:00
Peace-Maker 04e90bc754 Merge branch 'stable' into beta 2024-10-24 23:28:20 +02:00
Peace-Maker 8926a3a2bc Fix checksec commandline output after Python 3.12 fixes
This reverts #2346 which apparently didn't do what was expected. The logger has to be initialized for the checksec output to show up, so some other file imported * from pwn before too.
With the double registration of subparsers removed in f28d3ebb6c this didn't happen anymore making checksec print nothing.
2024-10-24 23:24:43 +02:00
Th3Sandpeace-maker fa14663243 libcdb-cli: add --offline-only, refactor unstrip and add fetch parser for download libc-database (#2478)
* Add `return_raw` for `search_by_symbol_offsets`

* Add `--offline-only` and unstrip libc as default behavior

* Add short arg name for `--download-libc`

* Fix bugs

* Add fetch parser

* Fix bugs

* file parse not unstrip default

* Update function docs

* Update CHANGELOG

* Edit dest of `--no-strip`

* Update CHANGELOG

* Unstrip before `return cache`

* Revert `--unstrip` help

* Improve `libcdb fetch` default behavior

* Perf fetch command

* Fix fetch command `-u`

---------

Co-authored-by: peace-maker <[email protected]>
2024-10-24 16:11:07 +02:00
Peace-Maker c68c00c316 Merge branch 'beta' into dev 2024-10-12 18:01:08 +02:00
Peace-Maker 2e86d8afe2 Merge branch 'stable' into beta 2024-10-12 17:48:59 +02:00
peace-maker f28d3ebb6c Test Python version >= 3.10 in CI and fix tests on Python 3.12 (#2486)
* Bump tested python version to >= 3.10

Some workflows were using 3.8 still. Start testing on 3.12 too.

* Fix installing rpyc in CI on ubuntu 24.04

`ubuntu-latest` now points to 24.04 which requires the --break-system-packages dance.

* Test Python 2 on Ubuntu 22.04

Ubuntu 24.04 dropped the python2.7 packages.

* Test on android-34

* Fix ARM binutils disassembly output test expectation

It used to print "; 0x4" but changed to "@ 0x4" in some version.

* Skip QEMU LD_PREFIX path test

Ubuntu 24.04 seemed to have switched the qemu-user --help output to show `/usr/gnemul/qemu-$ARCH` instead of `/etc/qemu-binfmt`. Ignore the actual path in the test.

* Fix x86 ascii shellcode encoder test

The alphabet was using `\` escape sequences badly.

<stdin>:1: SyntaxWarning: invalid escape sequence '\]'

* Fix mips xor encoder unaligned memory access

qemu throws a SIGBUS error when the shellcode tries to access unaligned memory since some version. Align the "stack" properly.

* Fix util.lists.partition test output on Python 3.12

The __repr__ output of OrderedDict was changed to look like ordinary {} dicts.

* Fix safeeval test on Python 3.12

There is a 151 RESUME opcode in Python 3.12 now.

* Fix registering commandline subparsers multiple times for Python 3.11

Python 3.11 added a sanity check to argparse to prevent registering the same subparser multiple times.

argparse.ArgumentError: argument command: conflicting subparser: cyclic

Avoid importing the command twice.
`python -m pwnlib.commandline.cyclic` failed on Python 3.11 triggered in CI when running the commandline tools while collecting coverage.

* Fix pip cache in CI
2024-10-12 17:48:12 +02:00
Lorenzo Cian cfc021d88e Extract libraries from Docker image (#2479)
* feat: extract libraries from Docker image

* docs: update CHANGELOG.md

* fix: python2.7 compatibility

* address comments

* address linter
2024-10-07 11:46:05 +02:00
tesuji d7817a7eac Nicely handle non ELF files in checksec (#2457) 2024-09-11 11:22:13 +02:00
CocoaandArusekk 736cf9d112 feat: multi shellcraft cmd (#2398)
* added support for multiple shellcraft commands

* updated CHANGELOG.md

* fix `pwn shellcraft -l shellcode`

* fix `get_template`

* strip strings after spliting by the delimiter

* fix `pwn shellcraft --show shellcode`

* added some tests in ci

* better handling for splitting by delimiter

---------

Co-authored-by: Arusekk <[email protected]>
2024-06-23 16:51:23 +02:00
peace-maker c17f835b3e pwn template: Don't search for challenge binary when already given (#2354) 2024-02-21 15:21:57 +01:00
Peace-Maker f5a119ffe5 Fix checksec commandline wrapper invocation 2024-02-09 10:56:14 +01:00
Disconnect3d 604b98c035 Fix pwn constgrep when it matches a non-constant type (Fixes #2344) (#2345)
* Fix pwn constgrep when it matches a non-constant type

This commit fixes the following issue:

```
root@pwndbg:~# pwn constgrep a
Traceback (most recent call last):
  File "/usr/local/bin/pwn", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/pwnlib/commandline/main.py", line 58, in main
    commands[args.command](args)
  File "/usr/local/lib/python3.10/dist-packages/pwnlib/commandline/constgrep.py", line 110, in main
    for _, k in sorted(out):
TypeError: '<' not supported between instances of 'Constant' and 'type'
```

Note that it was caused because of the following type object being matched and fetched from the module object:

```
ipdb> out[25:27]
[(Constant('CS', 0xd), 'CS'), (<class 'pwnlib.constants.constant.Constant'>, 'Constant')]
ipdb> sorted(out[24:27])
*** TypeError: '<' not supported between instances of 'type' and 'Constant'
```

* Add test for `pwn constgrep C` to the CI

* Add changelog entry
2024-02-08 10:17:47 +01:00
Disconnect3d 3fbd21a6e4 checksec.py: import ELF instead of * (#2346) 2024-02-08 10:15:29 +01:00
vsylandPeace-Maker 5805f5e9d7 Speed up disasm with color (#2334)
* Speed up disasm with color

* Update CHANGELOG

---------

Co-authored-by: Peace-Maker <[email protected]>
2024-01-17 21:44:52 +01:00
peace-makerandArusekk 5f5554fa1c Detect challenge binary and libc in pwn template (#2309)
* Detect challenge binary and libc in `pwn template`

When the `args.exe` or `args.libc` arguments are missing, look for the
files in the current working directory.
This allows to quickly get a template by just running `pwn template`
(and maybe --host --port for remote instances).

This is inspired by https://github.com/io12/pwninit

* Update CHANGELOG

* Add --no-auto argument to disable automatic detection

Allow to keep the old static template behavior.

* Add logging about detection outcome

Inform the user that we're looking for the binaries and if we found one.

* Be more strict about libc filename detection

Check about common name patterns instead of plainly the presence of "libc" in the name.

Co-authored-by: Arusekk <[email protected]>

* Change --no-auto argument to reduce double negation

Co-authored-by: Arusekk <[email protected]>

---------

Co-authored-by: Arusekk <[email protected]>
2023-12-12 19:02:13 +01:00
Michal AmbrozandPeace-Maker a8f4093695 Fix pwn libcdb file crashing if "/bin/sh" string was not found (#2307)
* next fails if string is not found in binary

fixes #2306

* Only display "str_bin_sh" symbol if it's available

* Update CHANGELOG

---------

Co-authored-by: Peace-Maker <[email protected]>
2023-11-29 22:29:35 +01:00
Michal AmbrozandPeace-Maker 4ef4746243 Remove python2 shebang lines from commandline tools (#2301)
* remove python2 shabangs

* Remove execute bit from commandline implementation

---------

Co-authored-by: Peace-Maker <[email protected]>
2023-11-24 13:37:29 +01:00
Michal Ambrozandpeace-maker 77957b4b41 Fix SyntaxWarning in Python 3.12 (#2302)
* libcdb.py - python 3.12

Python 3.12 would complain if the \d atom is not escaped in the binary string.

/usr/lib/python3.12/site-packages/pwnlib/commandline/libcdb.py:224: SyntaxWarning: invalid escape sequence '\d'
  libc_version = re.search(b'libc[ -](\d+\.\d+)', exe.data)

* Use raw string

---------

Co-authored-by: peace-maker <[email protected]>
2023-11-24 13:32:08 +01:00
Hannes WeissteinerandHannes Weissteiner 8b86cc3ba6 Allow creating custom templates in user-config directory (#2257)
* Allow creating custom templates in user-config directory

* Update changelog

* add cmdline parameter for template

* direct template file selection, added more help

* added template path to help string

* remove testing template

* allow crash on invalid template file

* python2 compatibility

* improved documentation for template

---------

Co-authored-by: Hannes Weissteiner <[email protected]>
2023-09-13 18:03:29 +02:00
peace-makerandArusekk 3e4e8b7055 Add --libc libc.so argument to pwn template (#2212)
* Add ELF.set_runpath()

Shells out to the `patchelf` tool to patch the ELF's RUNPATH. This lets the dynamic loader look for needed shared libraries in the given path first before the system libraries when running the binary.

* Add ELF.set_interpreter()

Shells out to the `patchelf` tool to patch the ELF's PT_INTERP segment. This allows to change the ld.so used when running the binary.

* Add convenience wrapper to set runpath & interpreter

A helper function to patch the ELF such that it uses the dynamic loader and other libraries in the given folder.

* Add method to download libraries matching a libc

Download the matching libraries for the given libc binary and cache them in a local directory using `libcdb.download_libraries()`. The libraries are looked up using libc.rip and fetched from the official package repositories if available.

Only .deb and .pkg.tar.* packages are currently supported (Debian/Ubuntu, Arch).

* Add --libc argument to pwnup template

This generates code into the template which allows you to run the binary using the given libc.

The foreign libc is used by default, but you can choose to run the binary against your system's local libc using the `LOCAL_LIBC` command line argument when executing the exploit script.

* Work around Python 2 tarfile not supporting xz

* Fix crash when libc wasn't found on libc.rip

* Update README

* Use subprocess.check_output instead of pwnlib.process

* Special case Python 2 instead of 3

* Only catch Exceptions instead of everything

Co-authored-by: Arusekk <[email protected]>

* Check launchpad.net for Ubuntu libcs

This mimics the way io12/pwninit obtains the ld.so.
If the download from libc.rip fails, try launchpad.net.

* Hide comment in template when --quiet

* Please confused pylint in PY2 context

Co-authored-by: Arusekk <[email protected]>

---------

Co-authored-by: Arusekk <[email protected]>
2023-07-26 13:58:32 +02:00
91be8af121 Add -p (--prefix) and -s (--separator) arguments to hex command (#2117)
* Add formats for hex

* Add formats for hex coverage

Relates to #2117. Adding coverage as requested.

* Use util.lists.group

* Update CHANGELOG

* Fix Python 2 support

* Simplify hex formatting

Co-authored-by: Arusekk <[email protected]>

---------

Co-authored-by: marcan2020 <[email protected]>
Co-authored-by: carydrew <[email protected]>
Co-authored-by: Peace-Maker <[email protected]>
Co-authored-by: Arusekk <[email protected]>
2023-06-04 22:23:11 +02:00
Arusekk 78196db658 Merge branch 'stable' into beta 2023-05-21 15:07:18 +02:00
peace-makerandArusekk 123f68f096 Fix highlight of unaligned nullbyte in disasm cmd (#2182)
"1001" would highlight the "00" even though it's not a null byte in the
input. Group the bytes correctly to look for real null bytes and
newlines only ignoring accidental matches of adjacent bytes.

Co-authored-by: Arusekk <[email protected]>
2023-05-21 12:42:05 +00:00
Arusekk 21131bd5e8 Merge branch 'beta' into dev 2022-12-28 22:34:59 +01:00
Arusekk a76c7b0ca1 Defer import of optional dependency 2022-12-28 22:29:50 +01:00
Lasne OlivierandArusekk e63e685bc7 make pwn cyclic -l work with entry larger than 4 bytes (#2062)
* make pwn cyclic -l work with entry larger than 4 bytes

* Do not assume py3, do not assume little-endian

* Update changelog

* pack all bytes instead

Co-authored-by: Arusekk <[email protected]>
2022-08-07 16:47:37 +02:00
peace-makerandArusekk 4b067d2ec5 Add libcdb commandline tool (#1975)
* Add libcdb commandline tool

Allows to dump information about a local libc binary or lookup matching libc versions based on a build hash or symbol offsets (querying https://libc.rip).

It's possible to download and unstrip a matching libc binary from the command line.

* Fix Python 2 compatibility

* Remove main_arena heuristic

* Update CHANGELOG

Co-authored-by: Arusekk <[email protected]>
2022-04-20 16:35:36 +02:00
Arusekk da8bf2667d Fix CI failures (#1997)
Ubuntu, why are you doing this to us?
I seriously mean that Ubuntu is the most silly distro.

Like, they probably updated their docker (or VM) images last week,
then Github got it, and we started getting failures.
They totally changed the behaviour of that 'apport' thing,
and it now drops core files in /var/lib/apport/coredump
instead of the current working directory.

Why is that even... ugh.  Nevermind.  It works now, at least.
But for how long?
2021-11-15 12:14:18 +01:00
Heap Crash 29fd2fe1c1 Fix warning that bytes != string (#1893)
* Fix warning that bytes != string

* Update CHANGELOG
2021-05-17 09:32:02 -05:00
Heap Crash 3c85afdbf5 Silence SIGPIPE error for phd (#1892)
* Silence SIGPIPE error for phd

* Update CHANGELOG
2021-05-17 08:43:24 -05:00
Arusekk 4b196c7d96 Cleanup unconditional imports (#1753)
* Cleanup unconditional imports

This may aid #1725

* Import explicitly

* Add good ol' SIGALRM-based debugs for tests

* Fix py2 GDB tests somehow

XXX: see why this matters

* Update CHANGELOG.md
2021-04-29 11:23:09 +02:00
Arusekk 835bc6ad56 Address code review from #1861 (#1866)
* Address code review from #1861

Review by @heapcrash

* Fix regression
2021-04-19 09:06:46 +02:00
Arusekk 3121f68e39 Try to catch more errors by using python -bb (#1861)
* Try to catch more errors by using python -bb

* Apply changes to travis dockerfiles as well

* Introduce context._need_bytes and context._need_text

...and resolve many issues
2021-04-15 12:04:56 +02:00
martinclauss 9066a68879 fix #1803 and #1860 (#1864)
* fix #1803 and #1860

* bring back Python2 shebang and imports
2021-04-15 12:03:20 +02:00
Heap Crash aa7b6f77a5 Add description= to subcommand parsers (#1814)
The help= does not show up in docs.pwntools.com, but description= does.
2021-02-24 04:16:42 -05:00
152334H 153b35ba68 Remove eval from cli (#1758)
* Remove eval from cli

* fix changelog

* shut up pylint
2021-01-10 16:25:58 +01:00