Skip to main content

A Python library for the debugging of binary executables.

Project description

logo

libdebug DOI

libdebug is an open source Python library for programmatic debugging of userland binary executables.

libdebug provides a comprehensive set of building blocks designed to facilitate the development of debugging tools for different purposes, including reverse engineering and exploitation. Build Your Own Debugger!

With libdebug you have full control of your debugged executable. With it you can:

  • Access process memory and registers
  • Control the execution flow of the process
  • Handle and hijack syscalls
  • Catch and hijack signals
  • Interact with stdin, stdout, and stderr of the debugged process
  • Debug multithreaded and multiprocess applications with ease
  • Seamlessly switch to GDB for interactive analysis
  • Debug on Linux systems based on AMD64, AArch64, and i386

When running the same executable multiple times, choosing efficient implementations can make the difference. For this reason, libdebug prioritizes performance.

Project Links

Homepage: https://libdebug.org
Documentation: https://docs.libdebug.org

Installation

python3 -m pip install libdebug

Install from another branch

If you want to stay up to date with the most cutting-edge features (and you don't mind being on an unstable branch) you can install from a different branch (e.g., dev).

python3 -m pip install git+https://github.com/libdebug/libdebug.git@dev

Please visit the build guide for more information on how to manually build libdebug from source.

Your first script

Now that you have libdebug installed, you can start using it in your scripts. Here is a simple example of how to use libdebug to debug a binary:

from libdebug import debugger

def my_callback(thread, bp) -> None:
	# This callback will be called when the breakpoint is hit
	print(f"RDX is {hex(thread.regs.rdx)}")
	print(f"This is the {bp.hit_count} time the breakpoint was hit")

d = debugger("./test")

# Start the process
# By default, the process will stop at the entry point
io = d.run()

my_breakpoint = d.breakpoint("function", hardware=True, file="binary")
my_callback_breakpoint = d.breakpoint("function2", callback=my_callback, file="binary")

# Continue the execution
d.cont()

# Interact with the process
io.sendline(b"Hello world!")
io.recvuntil(b"libdebug is like sushi")

# Print RAX. This will execute as soon as the process is stopped
print(f"RAX is {hex(d.regs.rax)}")

# Write to memory
d.memory[0x10ad, 8, "binary"] = b"Hello!\x00\x00"

# Continue the execution
d.cont()

The above script will run the binary test in the working directory and set two breakpoints: one at the function function and another at function2.

The first breakpoint has no callback, so it will just stop the execution and wait for your script to interact with the process. When the process stops at this breakpoint, you can read and write memory, access registers, and so on. In the example, we print the value of the RAX register and write a string to memory. Then, we continue the execution of the process.

The second breakpoint has a callback that will be called when the breakpoint is hit. Inside a callback, you can interact with the process, read and write memory, access registers, and so on. At the end of the callback, libdebug will automatically continue the execution of the process.

There is so much more that can be done with libdebug. Please read the documentation to find out more.

The cool stuff

libdebug offers many advanced features. Take a look at this script doing magic with signals:

from libdebug import debugger, libcontext

libcontext.terminal = ['tmux', 'splitw', '-h']

# Define signal catchers
def catcher_SIGUSR1(thread, catcher) -> None:
    thread.signal = 0x0
    print(f"SIGUSR1: Signal number {catcher}")

def catcher_SIGINT(thread, catcher) -> None:
    print(f"SIGINT: Signal number {catcher}")

def catcher_SIGPIPE(thread, catcher) -> None:
    print(f"SIGPIPE: Signal number {catcher}")

def handler_geteuid(thread, handler) -> None:
	thread.regs.rax = 0x0

# Initialize the debugger
d = debugger('/path/to/executable', continue_to_binary_entrypoint=False, aslr=False)

# Start the process
io = d.run()

# Register signal catchers
catcher1 = d.catch_signal("SIGUSR1", callback=catcher_SIGUSR1)
catcher2 = d.catch_signal("SIGINT", callback=catcher_SIGINT)
catcher3 = d.catch_signal("SIGPIPE", callback=catcher_SIGPIPE)

# Register signal hijackings
d.hijack_signal("SIGQUIT", "SIGTERM")
d.hijack_signal("SIGINT", "SIGPIPE", recursive=True)

# Define which signals to block
d.signals_to_block = ["SIGPOLL", "SIGIO", "SIGALRM"]

# Register a syscall handler
d.handle_syscall("geteuid", on_exit=handler_geteuid)

# Register a breakpoint
bp = d.breakpoint("function", hardware=True, file="binary")

# Continue execution
d.cont()

# Interact with the process
io.sendlineafter(b"libdebug is like provola", b"Hello world!")

# Wait for the process to stop
d.wait()

# Disable the catchers after execution
catcher1.disable()
catcher2.disable()
catcher3.disable()

# Register a new breakpoint
bp = d.breakpoint(0xdeadc0de, hardware=True)

d.cont()
d.wait()

d.gdb()

Auto Interrupt on Command

libdebug also allows you to make all commands execute as soon as possible, without having to wait for a stopping event. To enable this mode, you can use the auto_interrupt_on_command=True

from libdebug import debugger

d = debugger("/path/to/executable", auto_interrupt_on_command=True)

io = d.run()

bp = d.breakpoint("function", file="binary")

d.cont()

# Read shortly after the cont is issued
# The process is forcibly stopped to read the register
value = d.regs.rax
print(f"RAX is {hex(value)}")

system_offset = d.symbols.filter("system")[0].start
libc_base = d.maps.filter("libc")[0].base

system_address = libc_base + system_offset

d.memory[0x12ebe, 8, "libc"] = int.to_bytes(system_address, 8, "little")

d.cont()
d.wait()

# Here we should be at the breakpoint

# This value is read while the process is stopped at the breakpoint
ip_value = d.regs.rip

print(f"RIP is {hex(ip_value)}")

d.kill()

Attribution

We've published a poster on libdebug. If you use libdebug in your research, you can cite the associated poster paper:

@inproceedings{10.1145/3658644.3691391,
	author = {Digregorio, Gabriele and Bertolini, Roberto Alessandro and Panebianco, Francesco and Polino, Mario},
	title = {Poster: libdebug, Build Your Own Debugger for a Better (Hello) World},
	year = {2024},
	isbn = {9798400706363},
	publisher = {Association for Computing Machinery},
	address = {New York, NY, USA},
	url = {https://doi.org/10.1145/3658644.3691391},
	doi = {10.1145/3658644.3691391},
	booktitle = {Proceedings of the 2024 on ACM SIGSAC Conference on Computer and Communications Security},
	pages = {4976–4978},
	numpages = {3},
	keywords = {debugging, reverse engineering, software security},
	location = {Salt Lake City, UT, USA},
	series = {CCS '24}
}

If you intend to use libdebug in your projects, you can also cite the software using the following bibtex:

@software{libdebug_2024,
	title = {libdebug: {Build} {Your} {Own} {Debugger}},
	copyright = {MIT Licence},
	url = {https://libdebug.org},
	publisher = {libdebug.org},
	author = {Digregorio, Gabriele and Bertolini, Roberto Alessandro and Panebianco, Francesco and Polino, Mario},
	year = {2024},
	doi = {10.5281/zenodo.13151549},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libdebug-0.9.0.tar.gz (175.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

libdebug-0.9.0-cp312-abi3-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ x86-64

libdebug-0.9.0-cp312-abi3-musllinux_1_2_i686.whl (1.8 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ i686

libdebug-0.9.0-cp312-abi3-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

libdebug-0.9.0-cp312-abi3-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

libdebug-0.9.0-cp312-abi3-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ ARM64

libdebug-0.9.0-cp312-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (1.2 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ i686

libdebug-0.9.0-cp311-cp311-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

libdebug-0.9.0-cp311-cp311-musllinux_1_2_i686.whl (1.8 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ i686

libdebug-0.9.0-cp311-cp311-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ ARM64

libdebug-0.9.0-cp311-cp311-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

libdebug-0.9.0-cp311-cp311-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

libdebug-0.9.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686

libdebug-0.9.0-cp310-cp310-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

libdebug-0.9.0-cp310-cp310-musllinux_1_2_i686.whl (1.8 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ i686

libdebug-0.9.0-cp310-cp310-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ ARM64

libdebug-0.9.0-cp310-cp310-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

libdebug-0.9.0-cp310-cp310-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

libdebug-0.9.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ i686

File details

Details for the file libdebug-0.9.0.tar.gz.

File metadata

  • Download URL: libdebug-0.9.0.tar.gz
  • Upload date:
  • Size: 175.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for libdebug-0.9.0.tar.gz
Algorithm Hash digest
SHA256 ae4d82abb62937fcf9df42c017358a9b5237de3db8aec48a6d057b133bf9137e
MD5 fc0815e4c785bd9836395d23d663c5c8
BLAKE2b-256 1359a6168bc8eac75a425d713cacce9ba8874d57233818698550103eed59d175

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8dd8c567dc7093abf70ccebc4696a3f081fedd4bc86509bb60b98ca1de8ec668
MD5 41b917fe65898f6f28c68c1a4bf3c7c6
BLAKE2b-256 e566a0eced74eaade8d50748cbec8a12018d3c6ccffd22109136a0015c98a1fe

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp312-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp312-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 06e020e796a164c8cfd9fc7dbe81afff3563640a777c9c9d394e3573657525eb
MD5 1639fccc3f2e5a6329dcafbe10b02244
BLAKE2b-256 d64bfcf462edb875fc72b25de00e6030326bc53f8bbbe302507e5c42d1a90ae9

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 13da7b7280b4c2bd61b1b1a192f434a87494e85c4cc836c955c0dc6f3d7b8088
MD5 5258da79d0c33bd609cdf75cf2a68546
BLAKE2b-256 63651cb0cf16a4262024fe44b34b54653f5dc7bf4fb894ccb542dd9a7a7c0775

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 42fe2c144eda2a12fab30247676d5a283de9096fb038c6e7fa5aef6b1929d878
MD5 45321ca5b074b0b7c56ad3ecf226c45b
BLAKE2b-256 af742f013c7ea1f86a191debf9d363a6d9b2b0c8a806281850ddd286d5b5444e

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp312-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 21df85cd824bfcbb801b1a21534f872760b23a2e42203f155447f68769276459
MD5 1cc666e2e3d066aa32c3b5103c2b22f9
BLAKE2b-256 2913142128d7a6eb20af6ed75166cf9554740b4fa2bf09995b603edac57a8edd

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp312-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp312-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 a43dc6c8e47317634d0a2f20ec08f01ba7b09b2006ae0c60e3dbd5e49927464f
MD5 0425d28ce391a8108cb8da8c656f2d4d
BLAKE2b-256 32115fda0372b33bb52acf27d9c17bce6ebe7e74acd9ec4bd8161bce246c66e6

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f1312d0f89705e67d80338d6fd123de0e9967740a0758e35eb1cdeebc20b5fb8
MD5 6a0b1589d3122c6ea069055a12249ce7
BLAKE2b-256 41e50d7a3e6e600f3c8b33d1fe7a0286b6f131007d9166740fc737d257fea603

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp311-cp311-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 82824c1ee938186187b8fb87bd5646be2b03fea1741cf8cd2ffb56b78336a77b
MD5 bc858650dbacbf5ec93c1c24fd390d4c
BLAKE2b-256 79db05d1e0a44c9aedf4f303a997050571ae8e82a700bf3dc3e81cf0af3d032e

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp311-cp311-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cd127eb4a6a1d7cf0b5bd256aed5cf77f2cdb28456082385210c033d9e284fad
MD5 bad2537824945ecd57a565b870ea160b
BLAKE2b-256 f10f98e19547d1d11ccc2c6e39e1da09331c254f5ab8ad52cf772aba2ffc01d9

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5b38d33e42ebe344f9403d6067346254694c7c801d28e39559adbe9abd170879
MD5 0a6d4c32e035f941944ecc1c1a27a050
BLAKE2b-256 9e2e0b30f2bed909becd2646cb249d53bec2b4fc30f8f48858bcde04286d0eea

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bad692b3948130f74eb83515a59986eb1c7671770e375264531f28a37748af74
MD5 9a0b3135b787c0c7e2e0fa92be266a5d
BLAKE2b-256 589333175ee70a1af9cc12e4ce08e699c8d13ae0487ff3ed157e1cf2aa664b81

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 342dabafa092e64f182133a02e89df373642849bb7e2b5edccd400ee824169ef
MD5 835142dd6ca7dd4a6ded771a73d52926
BLAKE2b-256 4a13f1761e84ef09f95defd2e12b5e7e05f934e2699245f43f43af69183e1eac

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6f16c1c5a30094480c5ed744869e12b7af7ef572a069b02537781f4ff1203238
MD5 a3baf182b752427bb662496be7f2f4a4
BLAKE2b-256 43c707e5b6f94708cfaa1e253849cd4836ddfe6c3d40be409abc7d3037207a17

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp310-cp310-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 5d668b3d2a428632a68f0f9b70ef42571c1dcf77df30510cf6a1485e72a0caff
MD5 f1c30ae0e19e337f3cebbd1195d97842
BLAKE2b-256 da0a4af72a0c34411bf95d93778fbd2fc06b8966ca2854dbc4c7dfb7c02c3a81

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp310-cp310-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp310-cp310-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 11af33b59037e0a7fd254e0c929b0fe3e95323ac9726f7a25ef889286335163b
MD5 3c97c0782cdc305f9bd8f8bc49857a4f
BLAKE2b-256 cf4c0518eee20dc9e7dbb748453624e928a0bbdad2551890b64bdac8c85124ec

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d476d518fba4fc9542161a771c242266ed98fe511f0f3520c219fbd44af33658
MD5 801085b8529373880caf2e4414b9a2ca
BLAKE2b-256 a28771abbf5edb40a4fe012ba1eb0f7bc8d58b0dde7208a8398f9a719617842d

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d59b8bd2bbbb80561ed7b13afa05464bf45c16cc720465bed65a475f0e028549
MD5 cabe0b75d7affbe73435a8061e67c0c9
BLAKE2b-256 dc13601b2715f64421414f96fe3ee2146a396aa76f7356d639d40a3558a295a0

See more details on using hashes here.

File details

Details for the file libdebug-0.9.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for libdebug-0.9.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 899f8cf0df90689ce9809121f931dbaa1482326991258e17f26b974522e31f05
MD5 f634b9d5460ddb8c2529305cf5ddbe5c
BLAKE2b-256 ee78dc90afc378a9c06e052b4111112e16884b9c615cf7b8b2743fdb59c11b9c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page