From b24c499fb1dbc1e03cbbc749d69985ae35a9f8cc Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Sun, 31 Dec 2023 00:08:46 +0100 Subject: [PATCH 1/2] 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 --- pwnlib/libcdb.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pwnlib/libcdb.py b/pwnlib/libcdb.py index 0fb186b7f..142c95d23 100644 --- a/pwnlib/libcdb.py +++ b/pwnlib/libcdb.py @@ -5,6 +5,7 @@ from __future__ import division import os +import time import six import tempfile @@ -29,6 +30,9 @@ urls = os.environ['DEBUGINFOD_URLS'].split(' ') DEBUGINFOD_SERVERS = urls + DEBUGINFOD_SERVERS +# Retry failed lookups after some time +NEGATIVE_CACHE_EXPIRY = 60 * 60 * 24 * 7 # 1 week + # https://gitlab.com/libcdb/libcdb wasn't updated after 2019, # but still is a massive database of older libc binaries. def provider_libcdb(hex_encoded_id, hash_type): @@ -109,6 +113,10 @@ def search_by_hash(hex_encoded_id, hash_type='build_id', unstrip=True): cache, cache_valid = _check_elf_cache('libcdb', hex_encoded_id, hash_type) if cache_valid: return cache + + # We searched for this buildid before, but didn't find anything. + if cache is None: + return None # Run through all available libc database providers to see if we have a match. for provider in PROVIDERS: @@ -141,6 +149,10 @@ def _search_debuginfo_by_hash(base_url, hex_encoded_id): cache, cache_valid = _check_elf_cache('libcdb_dbg', hex_encoded_id, 'build_id') if cache_valid: return cache + + # We searched for this buildid before, but didn't find anything. + if cache is None: + return None # Try to find separate debuginfo. url = '/buildid/{}/debuginfo'.format(hex_encoded_id) @@ -191,8 +203,11 @@ def _check_elf_cache(cache_type, hex_encoded_id, hash_type): data = read(cache) if not data.startswith(b'\x7FELF'): - log.info_once("Skipping unavailable ELF %s", hex_encoded_id) - return cache, False + # Retry failed lookups after some time + if time.time() > os.path.getmtime(cache) + NEGATIVE_CACHE_EXPIRY: + return cache, False + log.info_once("Skipping invalid cached ELF %s", hex_encoded_id) + return None, False log.info_once("Using cached data from %r", cache) return cache, True From 1f5be93453c9d7a8894932e8cd569e53bed29110 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Sun, 31 Dec 2023 00:12:37 +0100 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06d16837c..1e2fc06f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ The table below shows which release corresponds to each branch, and what date th - [#2309][2309] Detect challenge binary and libc in `pwn template` - [#2308][2308] Fix WinExec shellcraft to make sure it's 16 byte aligned - [#2279][2279] Make `pwn template` always set context.binary +- [#2323][2323] Retry failed lookups after one week in libcdb [2242]: https://github.com/Gallopsled/pwntools/pull/2242 [2277]: https://github.com/Gallopsled/pwntools/pull/2277 @@ -89,6 +90,7 @@ The table below shows which release corresponds to each branch, and what date th [2309]: https://github.com/Gallopsled/pwntools/pull/2309 [2308]: https://github.com/Gallopsled/pwntools/pull/2308 [2279]: https://github.com/Gallopsled/pwntools/pull/2279 +[2323]: https://github.com/Gallopsled/pwntools/pull/2323 ## 4.12.0 (`beta`)