pwnlib.libcdb
— Libc Database¶
Fetch a LIBC binary based on some heuristics.
- pwnlib.libcdb.get_build_id_offsets()[source]¶
Returns a list of file offsets where the Build ID should reside within an ELF file of the currently selected architecture.
- pwnlib.libcdb.search_by_build_id(hex_encoded_id, unstrip=True)[source]¶
Given a hex-encoded Build ID, attempt to download a matching libc from libcdb.
- Parameters
- Returns
Path to the downloaded library on disk, or
None
.
Examples
>>> filename = search_by_build_id('fe136e485814fee2268cf19e5c124ed0f73f4400') >>> hex(ELF(filename).symbols.read) '0xda260' >>> None == search_by_build_id('XX') True >>> filename = search_by_build_id('a5a3c3f65fd94f4c7f323a175707c3a79cbbd614') >>> hex(ELF(filename).symbols.read) '0xeef40'
- pwnlib.libcdb.search_by_md5(hex_encoded_id, unstrip=True)[source]¶
Given a hex-encoded md5sum, attempt to download a matching libc from libcdb.
- Parameters
- Returns
Path to the downloaded library on disk, or
None
.
Examples
>>> filename = search_by_md5('7a71dafb87606f360043dcd638e411bd') >>> hex(ELF(filename).symbols.read) '0xda260' >>> None == search_by_md5('XX') True >>> filename = search_by_md5('74f2d3062180572fc8bcd964b587eeae') >>> hex(ELF(filename).symbols.read) '0xeef40'
- pwnlib.libcdb.search_by_sha1(hex_encoded_id, unstrip=True)[source]¶
Given a hex-encoded sha1, attempt to download a matching libc from libcdb.
- Parameters
- Returns
Path to the downloaded library on disk, or
None
.
Examples
>>> filename = search_by_sha1('34471e355a5e71400b9d65e78d2cd6ce7fc49de5') >>> hex(ELF(filename).symbols.read) '0xda260' >>> None == search_by_sha1('XX') True >>> filename = search_by_sha1('0041d2f397bc2498f62aeb4134d522c5b2635e87') >>> hex(ELF(filename).symbols.read) '0xeef40'
- pwnlib.libcdb.search_by_sha256(hex_encoded_id, unstrip=True)[source]¶
Given a hex-encoded sha256, attempt to download a matching libc from libcdb.
- Parameters
- Returns
Path to the downloaded library on disk, or
None
.
Examples
>>> filename = search_by_sha256('5e877a8272da934812d2d1f9ee94f73c77c790cbc5d8251f5322389fc9667f21') >>> hex(ELF(filename).symbols.read) '0xda260' >>> None == search_by_sha256('XX') True >>> filename = search_by_sha256('5d78fc60054df18df20480c71f3379218790751090f452baffb62ac6b2aff7ee') >>> hex(ELF(filename).symbols.read) '0xeef40'
- pwnlib.libcdb.unstrip_libc(filename)[source]¶
Given a path to a libc binary, attempt to download matching debug info and add them back to the given binary.
This modifies the given file.
- Parameters
filename (str) – Path to the libc binary to unstrip.
- Returns
True
if binary was unstripped,False
otherwise.
Examples
>>> filename = search_by_build_id('69389d485a9793dbe873f0ea2c93e02efaa9aa3d', unstrip=False) >>> libc = ELF(filename) >>> 'main_arena' in libc.symbols False >>> unstrip_libc(filename) True >>> libc = ELF(filename) >>> hex(libc.symbols.main_arena) '0x219c80' >>> unstrip_libc(which('python')) False >>> filename = search_by_build_id('d1704d25fbbb72fa95d517b883131828c0883fe9', unstrip=True) >>> 'main_arena' in ELF(filename).symbols True