60 Commits
Author SHA1 Message Date
Rogdham d9eff01662 Use compression.zstd (PEP-784) (#2769)
* Use compression.zstd (PEP-784)

* Add changelog entry
2026-08-28 13:54:23 +02:00
d41db1ff27 feat(libcdb): use local debuginfod client cache before hitting servers (#2623) (#2726)
* feat(libcdb): use local debuginfod client cache before hitting servers (#2623)

If gdb / eu-debuginfod-find / abrt has already downloaded the matching
debuginfo for our libc's build-id (cached at $DEBUGINFOD_CACHE_PATH or
$XDG_CACHE_HOME/debuginfod_client/ or ~/.cache/debuginfod_client/),
unstrip_libc() now reuses it directly instead of doing another network
round-trip via debuginfod servers. Validated by ELF magic so non-ELF
junk in the cache is ignored.

Closes #2623

* Update CHANGELOG.md for #2726

* Check our own cache before looking at debuginfod-client

---------

Co-authored-by: Chris (ChrisJr404) <[email protected]>
Co-authored-by: Peace-Maker <[email protected]>
2026-08-16 21:07:10 +02:00
peace-maker b309e102ba Support paginated libc.rip API requests (#2767)
* Support paginated libc.rip API requests

libc.rip used to truncate the result set but supports pagination now. Fetch all results reliably now by requesting all pages.

Fixes #2651

* Update CHANGELOG
2026-08-16 11:30:55 +02:00
Peace-Maker 86cafce196 Disable debuginfod tests in libcdb.unstrip_libc
The external debuginfod servers are really slow or won't respond at all like debuginfod.ubuntu.com.
The caching in CI doesn't help since we only cache it for 3 month and the query fails afterwards most of the time. We cache the negative response too which doesn't help if the service is flakey itself :D
2026-07-05 23:22:27 +02:00
peace-maker 6221f41a45 Fix libcdb CI cache not forwarding URI path (#2749)
The nginx docs say that you have to specify the $request_uri manually when a variable is used in the `proxy_pass` value.
Since we just put `/` at the end, all requests were rewritten to `/` instead of the intended e.g. `/api/find` endpoints.

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

This broke in #2718 but didn't manifest right away since the responses were still cached in CI. Now after the cache expired the fetch failed.
2026-06-22 19:16:52 +02:00
4e1780781f feat(libcdb): add extra_mirrors arg + PWN_EXTRA_LIBC_MIRRORS env to download_libraries (#2666) (#2725)
* feat(libcdb): add extra_mirrors arg + PWN_EXTRA_LIBC_MIRRORS env to download_libraries (#2666)

When the libc.rip URL points at a deb.debian.org / archive.ubuntu.com /
security.debian.org URL whose package has been pulled (e.g. older
vulnerable libc versions like 'GLIBC 2.36-9+deb12u6'), download_libraries
now also tries the same /pool/... path against any user-supplied mirror
prefix(es). Mirrors can be passed via the new keyword argument
extra_mirrors=... (str or list) or the comma/whitespace-separated
PWN_EXTRA_LIBC_MIRRORS environment variable.

Closes #2666

* Update CHANGELOG.md for #2725

* Rename environment variable to `PWNLIB_EXTRA_LIBC_MIRRORS`

All our other user-facing environment variables are `PWNLIB_` instead of `PWN_`.

* Move `import re` to toplevel

* Add type hints to touched functions

* Add example usage for download_libraries with extra_mirrors parameter

* Fix envvar in CHANGELOG

---------

Co-authored-by: Chris (ChrisJr404) <[email protected]>
Co-authored-by: Peace-Maker <[email protected]>
2026-05-07 18:17:22 +02:00
Arusekk a58534382a Use format strings and raw strings (#2554) 2026-03-21 11:09:46 +01:00
peace-maker 081b84927f Fix typo causing doctests not getting skipped (#2681)
Downloading all those libcs slowed down the CI a lot.
2026-02-20 12:49:39 +01:00
RocketDev 5161b5ef23 Cleanup Python 2 legacy (#2680)
* Cleanup Python 2 legacy

* chore: update changelog
2026-02-20 10:48:42 +01:00
peace-maker 7ba52cceed Remove leftover six references (#2613)
Some six usage sneaked by in #2547
2025-09-06 15:38:16 +02:00
Peace-Maker 3677514a71 Merge branch 'beta' into dev 2025-08-06 14:49:12 +02:00
Peace-Maker dd3a5f6974 libcdb: Fix cache handling of debuginfo
When trying multiple debuginfod servers, the first one to fail would save the failed attempt and block the remaining servers to be tried.

Only save that we couldn't find the debuginfo if we tried all the configured servers.
2025-08-06 14:32:08 +02:00
Peace-Maker 1c28222fe6 Merge remote-tracking branch 'stable' into beta-staging 2025-08-05 21:47:13 +02:00
peace-maker 425221fb30 Add Ubuntu and Debian debuginfod servers (#2595)
* Add Ubuntu and Debian debuginfod servers

Most CTF challenges are hosted on Ubuntu or Debian [citation needed], so check their debuginfod servers before trying the federating one as a fallback.

This is required since the elfutils.org server seems down for maintenance occasionally.

* Update CHANGELOG
2025-08-05 13:02:00 +02:00
ArusekkandPeace-Maker 328b2cd447 Drop six (#2547)
Co-authored-by: Peace-Maker <[email protected]>
2025-02-28 12:15:04 +01:00
Peace-Maker ec6b8cd87c Merge branch 'stable' into beta 2025-01-26 23:47:08 +01:00
peace-maker e9d9bd9ddb Fix installation on Python 3.5 and lower on stable (#2533)
* Fix installation on Python 3.5 and lower on stable

The unix-ar package requires Python 3.6. Only install it on Python 3.6 then and use the Python 2 fallback for Python <= 3.5 too.

* Update CHANGELOG
2025-01-26 23:18:16 +01:00
peace-maker 6748a7801d Drop Python 2.7 support / Require Python 3.10 (#2519)
* Drop Python 2.7 support / Require Python 3.10

Only test on Python 3 and bump minimal required python version to 3.10.

* Update CHANGELOG

* Allow to install on Python 3.4

* State intend to not artifially raise the required Python version
2025-01-26 22:11:07 +01:00
peace-maker 57b9eb9107 Fix loading ELF files without valid .dynamic section (#2502)
* Fix loading ELF files without valid .dynamic section

This allows to load separate debuginfo files and access their symbols.

* Update CHANGELOG
2024-12-10 21:36:33 +01:00
peace-maker ec262d8d01 Update sphinx for Python 3.13 support (#2503)
* Fix sphinx warnings in docstrings

* Update sphinx for Python 3.13 support

Could not import extension sphinx.builders.epub3 (exception: No module named 'imghdr')

`imghdr` was removed in Python 3.13.
2024-12-08 21:16:39 +01: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 d2253110bd Add caching proxy for libcdb debuginfod files to CI (#2487) 2024-10-24 15:59:24 +02:00
Th3Sandpeace-maker ee63072930 libcdb: improve the search speed of search_by_symbol_offsets (#2413)
* Add `hash_type` for `search_by_symbol_offsets`

* Add docs

* Update CHANGELOG

* Allow search `id` in search_by_hash

* Fix py2.7 test

* Rename `hash_type` to `search_type`

* Rename `TYPES['id']` to `TYPES['libs_id']`

* Rename part `hex_encoded_id` to `search_target`

* Turbofast extract build id

* Fix docs

* Add a map for types key

* Extract proper buildid

* Fix docs

* Fix E0606

* Simplify get `mapped_type`

* Add `search_by_libs_id` to `__all__`

* Modify docs

* Fix py2.7

* Fix reference

---------

Co-authored-by: peace-maker <[email protected]>
2024-09-29 01:53:06 +02:00
Th3Sandpeace-maker 51e8eb09ee libcdb: add offline_only to search_by_symbol_offsets (#2388)
* Add `offline_only` for `search_by_symbol_offsets`

* Fix bug

* Update CHANGELOG

* Remove redundant code

* Update

---------

Co-authored-by: peace-maker <[email protected]>
2024-05-23 16:57:19 +02:00
Th3S 4ac98cd11a Add offline parameter for libcdb.search_by_hash series function (#2360)
* Add offline parameter

* Add CHANGELOG

* Rename `offline` to `offline_only`
2024-03-29 15:27:38 +01:00
Swastik Sarkar 75cc3c3d5c libcdb.unstrip_libc: debug symbols are fetched only if not present (#2374)
* libcdb.unstrip_libc: debug symbols are fetched only if not present

* Usage of `ELF.debuginfo` to check if debug symbols exist

closes #2324

---------

Signed-off-by: sswastik02 <[email protected]>

* Add CHANGELOG

Signed-off-by: sswastik02 <[email protected]>

---------

Signed-off-by: sswastik02 <[email protected]>
2024-03-24 13:19:31 +01:00
Th3S 3b4b261b5a Add local libc database provider for libcdb (#2356)
* Add local libc database provider for libcdb

* Remove unnecessary assert

* Add docstring for local_libcdb

* Suppress warning output while `context.libdb` sets default

* Testing the local system's libc first

* Set falsely `context.lcoal_libcdb` to turn off local libc-database integration

* Fix docstring

* Make path check in validator

* Fix doctests

* Add CHANGELOG
2024-03-01 13:01:09 +01:00
peace-maker 2b7ec5e77a Fix gdb and other doctests (#2355)
* Fix gdb.debug doctests

* Accept bytes in ssh.which

But still return a `str` return for backwards-compatibility.

* CI: Make rpyc visible in gdb's python

* Fix not running all doctests

They appear to have to be a free standing block of `>>>` with an empty line above.

* Remove unnecessary text type check in ssh.which
2024-02-22 18:30:23 +01:00
peace-maker 27bc31e978 Match against local system libc first in libcdb (#2325)
* Match against local system libc first in libcdb

Don't do any requests if the libc currently in use on the system
running the exploit matches already. This is a small short circuit
optimization when the remote target uses the same libc as the
local one.

This looks at the libc loaded by the local shell binary. This appears
more dynamic than hardcoding library paths.

Refs #983

* Update CHANGELOG

* Handle missing SHELL envvar

* Fix hash lookup
2024-01-30 12:20:20 +01:00
peace-maker 993f590ac2 Retry failed lookups after one week in libcdb (#2323)
* Retry failed lookups after one week in libcdb

The libc databases might be updated to include the searched version,
so a request that failed once might work in the future.

Refs #983

* Update CHANGELOG
2024-01-30 11:29:31 +01:00
Arusekk e608a46490 Merge branch 'beta' into dev 2023-08-20 20:54:18 +02:00
Arusekk fa2d47753b Merge branch 'stable' into beta 2023-08-20 20:53:42 +02:00
Arusekk 6ff74256d8 plt: remove stale MIPS workaround (#2256)
Fixes #2042
2023-08-20 18:49:35 +00: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
Arusekk 1f63615085 Merge branch 'stable' into beta 2023-06-24 02:20:19 +02:00
peace-maker 23ef84e45a Fix Python 2 CI (#2210)
* Fix Python 2 CI

* Fix python symlink related tests
2023-06-24 02:16:53 +02:00
Arusekk cb5b8af5f3 Merge branch 'beta' into dev 2023-05-21 15:18:06 +02:00
Arusekk 78196db658 Merge branch 'stable' into beta 2023-05-21 15:07:18 +02:00
peace-maker 0499631429 Fix failing libcdb.unstrip_libc tests (#2196)
* Fix libcdb.unstrip_libc tests

The old debugsymbols seem to have been pruned.
Update hashes to recent Ubuntu 22.04 libcs.

* Switch wget test to httpbingo.org

httpbin.org is very slow to respond.

Cherry-picked from 1998ff0920
2023-05-21 14:02:13 +02:00
peace-maker 1998ff0920 Fix failing libcdb.unstrip_libc tests (#2196)
* Fix libcdb.unstrip_libc tests

The old debugsymbols seem to have been pruned.
Update hashes to recent Ubuntu 22.04 libcs.

* Switch wget test to httpbingo.org

httpbin.org is very slow to respond.
2023-05-18 17:59:16 +02:00
peace-makerandArusekk aa48227781 Add search for libc binary by leaked function addresses (#2103)
* libcdb: Add option to search by function offsets

When you're able to leak addresses of the libc library, use `libcdb.search_by_symbol_offsets()` to find and download the matching libc library from https://libc.rip.

If there are multiple matches, the user is prompted to select one interactively. The selection can be saved in the code for future executions of the script.

Fixes #1867

* libcdb: Handle multiple results when looking up by hash

Sometimes the same library appears to be indexed multiple times (see 0b52d2e713d243f0f65d808fcd3fbe372bb3cd32). Handle that situation by selecting the first in the list, since they should all be identical given the same hash value.

* Update CHANGELOG

* Fix off-by-one when pre-selecting a libc

* Do .json() only once

---------

Co-authored-by: Arusekk <[email protected]>
2023-03-22 12:26:39 +01:00
peace-maker 7d1dae1071 Update libcdb debuginfod default URL to federating server (#2101)
* Switch to federated debuginfod service

elfutils.org offers a federating proxy server which forwards the requests to all other debuginfod servers of the different linux distributions.

https://sourceware.org/elfutils/Debuginfod.html

Use that instead by default to increase our successrate and potentially include new servers automatically once the distro sets one up.

* Use DEBUGINFOD_URLS envvar for server selection

The `DEBUGINFOD_URLS` environment variable is what you use for your normal debuginfod setup to tell it where to look for debug symbols.

Parse it as well and prepend it to the list of servers to try to allow for dynamic adjusting of the target servers.
2022-09-25 14:56:19 +02:00
peace-maker 762591bf35 Fix CI after Groovy Gorilla went away for libc unstrip test (#2025)
* Fix CI after Groovy Gorilla went away for libc unstrip test

Build elfutils 0.181 from source since we can't use builds
from a newer ubuntu version anymore.

* Install python wheels in CI
2022-01-28 11:58:23 +01:00
peace-makerandArusekk 92911cbabd libcdb: Load debug info and unstrip libc binary (#1828)
* libcdb: Load debug info and unstrip libc binary

The debug info is obtained from a debuginfod server maintained by systemtap.org. elfutils is used to unstrip the binary and merge the debug info back.

Try to unstrip every libc binary downloaded by the libcdb module by default. #1818

* Install elfutils on CI

* Update CHANGELOG.md

* Add more tests

* Fix negative test

* Raise an exception when eu-unstrip fails

This will hopefully get logged during doctests.

* Install elfutils 0.181 from groovy

Use APT Pinning to select the newer elfutils version from groovy instead of the buggy 0.176 version available in focal.

* Fix missing import of requests

pylint?

Co-authored-by: Arusekk <[email protected]>
2021-10-03 10:51:30 +02:00
Heap Crash 12af84f19f Defer import of requests and urllib (#1906)
* Defer import of requests and urllib

This saves 100ms-150ms of startup time on "from pwn import *"

* Update CHANGELOG

* More deferred imports to save ~20ms
2021-05-31 15:30:58 -05:00
peace-makerandArusekk 545f8dddd4 Try libc.rip for libc lookup (#1704)
* Try libc.rip for libc lookup

As of #1171 the libcdb repository isn't seeing any updates anymore. When looking up a libc by a hash or build_id try the libc database maintained by @niklasb as well.

The database uses a REST api documented at https://github.com/niklasb/libc-database/blob/master/searchengine/api.yml

* Catch exceptions properly

* Update CHANGELOG

* Add doctests

Co-authored-by: Arusekk <[email protected]>
2020-10-24 13:53:50 +02:00
peace-maker cde51065bf Update libcdb buildid offsets (#1703)
* Update libcdb buildid offsets

Recent libcs from Debian and Ubuntu have different offsets for the build id.

* Update CHANGELOG
2020-10-20 11:52:33 +02:00
Arusekk ad0da0a675 Improvements in examples 2020-05-07 13:01:27 +02:00
Andreas Oberritter dbf0549213 Make DynELF().libc work on current Debian 10 (amd64) (#1340)
* libcdb: Add another offset for amd64

Tested with libc6_2.28-10_amd64.deb from Debian 10.

* dynelf: Improve status message when looking for build id
2019-12-08 15:27:33 +01:00
Arusekk adaba022e6 Pretty docstrings and libcdb fix 2019-12-06 11:30:55 +01:00