Add the Features section (#3026)
* cwatch: move example from features to source * also mention syscall in dumpargs * move FEATURES.md to docs/ and factor out stuff * move integrations out * move disasm+emu/ redo heap section * pwndbg->Pwndbg, lldb, windbg, commands section, remove qemu-user section * commands section * clarify slab command * cleanup: readme link, formatting, del extra file * reduce some screenshot sizespull/3029/head
@ -1,321 +0,0 @@
|
||||
# pwndbg
|
||||
|
||||
Pwndbg has a great deal of useful features. You can a list all available commands at any time by typing the `pwndbg` command. It can also be configured: see `config` and `theme` commands. Below is a subset of them which are easy to capture in screenshots.
|
||||
|
||||
## GDB vs LLDB
|
||||
| **Functionality** | **GDB Command** | **LLDB Command** |
|
||||
|-----------------------------------------------|----------------------------------------|-------------------------------------------------------------|
|
||||
| **Start Debugging Program** | `gdb ./your-program` | `lldb ./your-program` |
|
||||
| **Set a Breakpoint** | `break <function-name>` | `breakpoint set --name <function-name>` |
|
||||
| **Set Breakpoint on Address** | `break *<address>` | `breakpoint set --address <address>` |
|
||||
| **Set Breakpoint at Line** | `break <filename>:<line-number>` | `breakpoint set --file <filename> --line <line-number>` |
|
||||
| **Set Hardware Breakpoint** | `hbreak <function-name>` | `breakpoint set --hardware --name <function-name>` |
|
||||
| **Set Hardware Breakpoint at Memory** | `hbreak *<memory-address>` | `breakpoint set --hardware --address <memory-address>` |
|
||||
| **List All Breakpoints** | `info breakpoints` | `breakpoint list` |
|
||||
| **Delete Breakpoints** | `delete <breakpoint-number>` | `breakpoint delete <breakpoint-number>` |
|
||||
| **Set Watchpoint** | `watch <variable>` | `watchpoint set variable <variable>` |
|
||||
| **Set Conditional Breakpoint** | `break <function-name> if <condition>` | `breakpoint set --condition "<condition>"` |
|
||||
| **Continue Execution** | `continue` | `process continue` |
|
||||
| **Next Instruction** | `next` | `thread step-over` |
|
||||
| **Step into a Function** | `step` | `thread step-in` |
|
||||
| **Step out of a Function** | `finish` | `thread step-out` |
|
||||
| **Print Threads** | `info threads` | `thread list` |
|
||||
| **Select Thread** | `thread <thread-id>` | `thread select <thread-id>` |
|
||||
| **Print Register Values** | `info registers` | `register read -a` |
|
||||
| **Print a Variable** | `print <variable>` | `print <variable>` |
|
||||
| **Display Variable on Every Stop** | `display <variable>` | `expression --watch <variable>` |
|
||||
| **Examine Memory (Hex)** | `x/<num>x <memory-address>` | `memory read --format x --count <num> <memory-address>` |
|
||||
| **Examine Memory (Integer)** | `x/<num>d <memory-address>` | `memory read --format d --count <num> <memory-address>` |
|
||||
| **Inspect Stack Trace** | `backtrace` | `thread backtrace` |
|
||||
| **Change Register Value** | `set $<register-name> = <value>` | `register write <register-name> <value>` |
|
||||
| **Check Program Status** | `info locals` | `frame variable` |
|
||||
| **Check Program Info** | `info functions` | `image lookup --functions` |
|
||||
| **Show Disassembly of Function** | `disas <function-name>` | `disassemble <function-name>` |
|
||||
| **Memory Dump (Hex)** | `x/<num>xh <memory-address>` | `memory read --format x --count <num> <memory-address>` |
|
||||
| **Memory Dump (Bytes)** | `x/<num>bx <memory-address>` | `memory read --format b --count <num> <memory-address>` |
|
||||
| **Show Process Information** | `info process` | `process status` |
|
||||
| **Quit Debugging** | `quit` | `quit` |
|
||||
| **Run Program with Arguments** | `run <arg1> <arg2> ...` | `process launch -- <arg1> <arg2> ...` |
|
||||
| **Show Current Function** | `info frame` | `frame info` |
|
||||
| **Set Sysroot** | `set sysroot <path-to-sysroot>` | `settings set target.sysroot <path-to-sysroot>` |
|
||||
| **Set Source Directory** | `directory <path-to-source-directory>` | `settings set target.source-map <remote-path> <local-path>` |
|
||||
| **Set Architecture** | `set architecture <arch>` | `target create --arch <arch> <executable-file>` |
|
||||
| **Show Settings** | `show <setting-name>` | `settings show <setting-name>` |
|
||||
| **Set File for Debugging** | `file <executable-file>` | `target create <executable-file>` |
|
||||
| **Start the Program and Run One Instruction** | `starti` | `process launch --stop-at-entry` |
|
||||
| **Enable ASLR** | `set disable-randomization off` | `settings set target.disable-aslr false` |
|
||||
|
||||
## Arguments
|
||||
|
||||
All function call sites are annotated with the arguments to those functions. This works best with debugging symbols, but also works in the most common case where an imported function (e.g. libc function via GOT or PLT) is used.
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Context
|
||||
|
||||
A useful summary of the current execution context is printed every time GDB stops (e.g. breakpoint or single-step), displaying all registers, the stack, call frames, disassembly, and additionally recursively dereferencing all pointers. All memory addresses are color-coded to the type of memory they represent.
|
||||
|
||||
The output of the context may be redirected to a file (including other tty) by using `set context-output /path/to/file` while leaving other output in place.
|
||||
|
||||

|
||||
|
||||
A history of previous context output is kept which can be accessed using the `contextprev` and `contextnext` commands.
|
||||
|
||||
### Splitting / Layouting Context
|
||||
|
||||
The context sections can be distributed among different tty by using the `contextoutput` command.
|
||||
Example: `contextoutput stack /path/to/tty true`
|
||||
|
||||
Python can be used to create a tmux layout when starting pwndbg and distributing the context among
|
||||
the splits.
|
||||
```python
|
||||
python
|
||||
import atexit
|
||||
import os
|
||||
from pwndbg.commands.context import contextoutput, output, clear_screen
|
||||
bt = os.popen('tmux split-window -P -F "#{pane_id}:#{pane_tty}" -d "cat -"').read().strip().split(":")
|
||||
st = os.popen(F'tmux split-window -h -t {bt[0]} -P -F '+'"#{pane_id}:#{pane_tty}" -d "cat -"').read().strip().split(":")
|
||||
re = os.popen(F'tmux split-window -h -t {st[0]} -P -F '+'"#{pane_id}:#{pane_tty}" -d "cat -"').read().strip().split(":")
|
||||
di = os.popen('tmux split-window -h -P -F "#{pane_id}:#{pane_tty}" -d "cat -"').read().strip().split(":")
|
||||
panes = dict(backtrace=bt, stack=st, regs=re, disasm=di)
|
||||
for sec, p in panes.items():
|
||||
contextoutput(sec, p[1], True)
|
||||
contextoutput("legend", di[1], True)
|
||||
atexit.register(lambda: [os.popen(F"tmux kill-pane -t {p[0]}").read() for p in panes.values()])
|
||||
end
|
||||
```
|
||||
If you like it simple, try configuration with [splitmind](https://github.com/jerdna-regeiz/splitmind)
|
||||
|
||||

|
||||
|
||||
Note above example uses splitmind and following configuration:
|
||||
|
||||
```python
|
||||
python
|
||||
import splitmind
|
||||
(splitmind.Mind()
|
||||
.tell_splitter(show_titles=True)
|
||||
.tell_splitter(set_title="Main")
|
||||
.right(display="backtrace", size="25%")
|
||||
.above(of="main", display="disasm", size="80%", banner="top")
|
||||
.show("code", on="disasm", banner="none")
|
||||
.right(cmd='tty; tail -f /dev/null', size="65%", clearing=False)
|
||||
.tell_splitter(set_title='Input / Output')
|
||||
.above(display="stack", size="75%")
|
||||
.above(display="legend", size="25")
|
||||
.show("regs", on="legend")
|
||||
.below(of="backtrace", cmd="ipython", size="30%")
|
||||
).build(nobanner=True)
|
||||
end
|
||||
```
|
||||
|
||||
#### GDB TUI
|
||||
The context sections are available as native [GDB TUI](https://sourceware.org/gdb/current/onlinedocs/gdb.html/TUI.html) windows named `pwndbg_[sectionname]`.
|
||||
|
||||
There are some predefined layouts coming with pwndbg which you can select using `layout pwndbg` or `layout pwndbg_code`.
|
||||
|
||||
To create [your own layout](https://sourceware.org/gdb/current/onlinedocs/gdb.html/TUI-Commands.html) and selecting it use normal `tui new-layout` syntax like:
|
||||
```
|
||||
tui new-layout pwndbg_custom {-horizontal { { -horizontal { pwndbg_code 1 pwndbg_disasm 1 } 2 { {-horizontal pwndbg_legend 8 pwndbg_control 2 } 1 pwndbg_regs 6 pwndbg_stack 6 } 3 } 7 cmd 3 } 3 { pwndbg_backtrace 2 pwndbg_threads 1 pwndbg_expressions 2 } 1 } 1 status 1
|
||||
layout pwndbg_custom
|
||||
```
|
||||
|
||||

|
||||
|
||||
Use `focus cmd` to focus the command window and have the arrow keys scroll through the command history again. `tui disable` to disable TUI mode and go back to CLI mode when running commands with longer output. `ctrl-x + a` toggles between TUI and CLI mode quickly. Hold shift to ignore the TUI mouse integration and use the mouse normally to select text or copy data.
|
||||
|
||||
### Watch Expressions
|
||||
|
||||
You can add expressions to be watched by the context.
|
||||
Those expressions are evaluated and shown on every context refresh.
|
||||
|
||||
An expression can be added via the `contextwatch` command (aliased `ctx-watch` and `cwatch`).
|
||||
|
||||
Per default an expression is parsed and evaluated in the debugged language and can be added with:
|
||||
```
|
||||
contextwatch BUF
|
||||
ctx-watch ITEMS[0]
|
||||
```
|
||||
|
||||
Alternatively one can provide an arbitrary gdb command to be executed and the result printed in the
|
||||
context by using the optional `cmd` parameter with the value `execute`:
|
||||
```
|
||||
contextwatch execute "ds BUF"
|
||||
cwatch execute "x/20x $rsp"
|
||||
```
|
||||
|
||||
### Ghidra
|
||||
|
||||
With the help of [radare2](https://github.com/radareorg/radare2) or [rizin](https://github.com/rizinorg/rizin) it is possible to show the
|
||||
decompiled source code of the ghidra decompiler.
|
||||
|
||||
However, this comes with some prerequisites.
|
||||
* First: you have to have installed radare2 or rizin and it must be found by gdb (within path)
|
||||
* Second: you have to install the ghidra plugin for radare2
|
||||
[r2ghidra](https://github.com/radareorg/r2ghidra) or install the ghidra plugin for rizin [rz-ghidra](https://github.com/rizinorg/rz-ghidra)
|
||||
|
||||
* Third: r2pipe has to be installed in the python-context gdb is using (or if you are using rizin, install rzpipe instead)
|
||||
|
||||
The decompiled source be shown as part of the context by adding `ghidra` to `set context-sections`
|
||||
or by calling `ctx-ghidra [function]` manually.
|
||||
|
||||
Be warned, the first call to both radare2/r2ghidra and rizin/rz-ghidra are rather slow! Subsequent requests for decompiled
|
||||
source will be faster. And it does take up some resources as the radare2/rizin instance is kept by r2pipe/rzpipe
|
||||
to enable faster subsequent analysis.
|
||||
|
||||
With those performance penalties it is reasonable to not have it launch always. Therefore it includes
|
||||
an option to only start it when required with `set context-ghidra`:
|
||||
* `set context-ghidra always`: always trigger the ghidra context
|
||||
* `set context-ghidra never`: never trigger the ghidra context except when called manually
|
||||
* `set context-ghidra if-no-source`: invoke ghidra if no source code is available
|
||||
|
||||
Remark: the plugin tries to guess the correct current line and mark it with "-->", but it might
|
||||
get it wrong.
|
||||
|
||||
## Disassembly
|
||||
|
||||
Pwndbg uses Capstone Engine to display disassembled instructions, but also leverages its introspection into the instruction to extract memory targets and condition codes.
|
||||
|
||||
All absolute jumps are folded away, only displaying relevant instructions.
|
||||
|
||||

|
||||
|
||||
Additionally, if the current instruction is conditional, Pwndbg displays whether or not it is evaluated with a green check or a red X, and folds away instructions as necessary.
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Emulation
|
||||
|
||||
Pwndbg leverages Unicorn Engine in order to only show instructions which will actually be emulated. At each debugger stop (e.g. breakpoint or single-step) the next few instructions are silently emulated, and only instructions which will actually be executed are displayed.
|
||||
|
||||
This is incredibly useful when stepping through jump tables, PLT entries, and even while ROPping!
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Heap Inspection
|
||||
|
||||
Pwndbg enables introspection of the glibc allocator, ptmalloc2, via a handful of introspection functions.
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## IDA Pro/Binary Ninja Integration
|
||||
|
||||
Pwndbg is capable of integrating with IDA Pro or Binary Ninja by installing an XMLRPC server in the decompiler as a plugin, and then querying it for information.
|
||||
|
||||
This allows extraction of comments, decompiled lines of source, breakpoints, symbols, and synchronized debugging (single-steps update the cursor in the decompiler).
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
See the [Binary Ninja integration guide](docs/binja_integration.md) for setup information.
|
||||
|
||||
## Go Debugging
|
||||
|
||||
Pwndbg has support for dumping complex Go values like maps and slices, including automatically parsing out type layouts in certain cases.
|
||||
|
||||
See the [Go debugging guide](docs/go_debugging.md) for more information.
|
||||
|
||||
## Configuration, customization
|
||||
|
||||
There are two commands to set various options:
|
||||
|
||||
* `theme` - to set particular output color/style
|
||||

|
||||
|
||||
* `config` - to set parameters like whether to emulate code near current instruction, ida rpc connection info, hexdump bytes/width (and more)
|
||||

|
||||
|
||||
Of course you can generate and put it in `.gdbinit` after pwndbg initialization to keep it persistent between pwngdb sessions.
|
||||
|
||||
This can be seen and achieved by `configfile`/`themefile` commands.
|
||||
|
||||
## QEMU Compatibility
|
||||
|
||||
Pwndbg is designed to work with minimally-implemented or otherwise debugger-hostile implementations of the GDB Serial Protocol. One such implementation is that used by QEMU User-Mode Emulation (`qemu-user`) which is frequently used by CTF players to execute and debug cross-architecture binaries.
|
||||
|
||||
Vanilla GDB, PEDA, and GEF all fail terribly in this scenario.
|
||||
|
||||
#### GEF
|
||||
|
||||

|
||||
|
||||
#### PEDA
|
||||
|
||||

|
||||
|
||||
#### Vanilla GDB
|
||||
|
||||

|
||||
|
||||
#### Pwndbg
|
||||
|
||||
However, Pwndbg works around the limitations of the GDB stub to give you the best debugger environment possible.
|
||||
|
||||

|
||||
|
||||
## Process State Inspection
|
||||
|
||||
Use the `procinfo` command in order to inspect the current process state, like UID, GID, Groups, SELinux context, and open file descriptors! Pwndbg works particularly well with remote GDB debugging like with Android phones, which PEDA, GEF, and vanilla GDB choke on.
|
||||
|
||||

|
||||
|
||||
## ROP Gadgets
|
||||
|
||||
Pwndbg makes using ROPGadget easy with the actual addresses in the process.
|
||||
|
||||
Just use the `rop` command!
|
||||
|
||||

|
||||
|
||||
## Search
|
||||
|
||||
Pwndbg makes searching the target memory space easy, with a complete and easy-to-use interface. Whether you're searching for bytes, strings, or various sizes of integer values or pointers, it's a simple command away.
|
||||
|
||||

|
||||
|
||||
## Finding Leaks
|
||||

|
||||
Finding leak chains can be done using the `leakfind` command. It recursively inspects address ranges for pointers, and reports on all pointers found.
|
||||
|
||||
|
||||
## Telescope
|
||||
|
||||
Inspecting memory dumps is easy with the `telescope` command. It recursively dereferences a range of memory, letting you see everything at once. As an added bonus, Pwndbg checks all of the available registers to see if they point into the memory range.
|
||||
|
||||
## Virtual Memory Maps
|
||||
|
||||
Pwndbg enhances the standard memory map listing, and allows easy searching.
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Windbg Compatibility
|
||||
|
||||
Pwndbg has a complete windbg compatibility layer. You can `dd`, `dps`, `eq`, and even `eb eip 90` to your heart's content.
|
||||
|
||||

|
||||
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 187 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 211 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 108 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 53 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 143 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 8.1 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 964 KiB After Width: | Height: | Size: 964 KiB |
|
After Width: | Height: | Size: 157 KiB |
|
Before Width: | Height: | Size: 346 KiB After Width: | Height: | Size: 346 KiB |
|
Before Width: | Height: | Size: 232 KiB After Width: | Height: | Size: 232 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 143 KiB |
|
After Width: | Height: | Size: 165 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 206 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 123 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 53 KiB |
@ -0,0 +1,158 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
<!--
|
||||
This document should give an overview of some of the most interesting
|
||||
features pwndbg has to offer. Use a lot of screenshots and recordings.
|
||||
Don't go too much in-depth - it is better to write a tutorial in another
|
||||
page of the docs and simply link to it.
|
||||
-->
|
||||
|
||||
# Features
|
||||
|
||||
Pwndbg has a great deal of useful features. You can a see all available commands at any time by typing the `pwndbg` command or by checking the [Commands section](commands/index.md) of the documentation. For configuration and theming see the [Configuration section](configuration/index.md). Below is a subset of commands which are easy to capture in screenshots.
|
||||
|
||||
## Disassembly and Emulation
|
||||
|
||||
Pwndbg leverages the [capstone](https://github.com/capstone-engine/capstone) and [unicorn](https://github.com/unicorn-engine/unicorn) engines, along with its own instrospection, to display, annotate and emulate instructions.
|
||||
|
||||
Operands of instructions are resolved, conditions evaluated, and only the instructions that will actually be executed are shown.
|
||||
|
||||

|
||||
|
||||
This is incredibly useful when stepping through jump tables, PLT entries, and ROPping.
|
||||
|
||||

|
||||
|
||||
## Context
|
||||
|
||||
A useful summary of the current execution context is printed every time the debugger stops (e.g. breakpoint or single-step), displaying all registers, the stack, call frames, disassembly, and additionally recursively dereferencing all pointers. All memory addresses are color-coded to the type of memory they represent.
|
||||
|
||||

|
||||
|
||||
A history of previous context output is kept which can be accessed using the `contextprev` and `contextnext` commands.
|
||||
|
||||
### Arguments
|
||||
|
||||
All function call sites are annotated with the arguments to those functions. This works best with debugging symbols, but also works in the most common case where an imported function (e.g. libc function via GOT or PLT) is used.
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
### Splitting / Layouting Context
|
||||
|
||||
The context sections can be distributed among different tty by using the `contextoutput` command. Thus, if you want to make better use of some of the empty space in the default Pwndbg output, you can split the panes in your terminal and redirect the various contexts among them.
|
||||
|
||||

|
||||
|
||||
See [Splitting the Context](misc/splitting-the-context.md) for more information.
|
||||
|
||||
### GDB TUI
|
||||
The context sections are available as native [GDB TUI](https://sourceware.org/gdb/current/onlinedocs/gdb.html/TUI.html) windows named `pwndbg_[sectionname]`. There are some predefined layouts coming with Pwndbg which you can select using `layout pwndbg` or `layout pwndbg_code`.
|
||||
|
||||

|
||||
|
||||
See [GDB TUI](misc/gdb-tui.md) for more information.
|
||||
|
||||
### Watch Expressions
|
||||
|
||||
You can add expressions to be watched by the context. Those expressions are evaluated and shown on every context refresh. For instance by doing `contextwatch execute "info args"` we can see the arguments of every function we are in (here we are in `mmap`):
|
||||
|
||||

|
||||
|
||||
See [`contextwatch`](commands/context/contextwatch.md) for more information.
|
||||
|
||||
## Integrations
|
||||
|
||||
### Ghidra
|
||||
|
||||
With the help of [radare2](https://github.com/radareorg/radare2) or [rizin](https://github.com/rizinorg/rizin) it is possible to show the decompiled source code of the ghidra decompiler.
|
||||
|
||||
See [Ghidra Integration](misc/ghidra-integration.md) for more information.
|
||||
|
||||
### IDA Pro/Binary Ninja
|
||||
|
||||
Pwndbg is capable of integrating with IDA Pro or Binary Ninja by installing an XMLRPC server in the decompiler as a plugin, and then querying it for information.
|
||||
|
||||
This allows extraction of comments, decompiled lines of source, breakpoints, symbols, and synchronized debugging (single-steps update the cursor in the decompiler).
|
||||
|
||||
{ style="width: 70%;" }
|
||||
|
||||
See the [Binary Ninja integration guide](misc/binja-integration.md) for setup information.
|
||||
|
||||
## Heap Inspection
|
||||
|
||||
Pwndbg provides commands for inspecting the heap and the allocator's state. Currently supported are:
|
||||
|
||||
+ [glibc malloc](commands/index.md#glibc-ptmalloc2-heap)
|
||||
+ [jemalloc](commands/index.md#jemalloc-heap)
|
||||
+ [linux's buddy allocator](commands/kernel/buddydump.md)
|
||||
+ [linux's SLUB allocator](commands/kernel/slab.md)
|
||||
|
||||
See *some* of the commands for glibc malloc:
|
||||
{ style="width: 70%;" }
|
||||
{ style="width: 70%;" }
|
||||

|
||||
{ style="width: 70%;" }
|
||||
|
||||
## LLDB
|
||||
|
||||
While most other GDB plugins are well *GDB plugins*, Pwndbg's implementation is debugger-agnostic. You can use Pwndbg with LLDB!
|
||||
|
||||
{ style="width: 70%;" }
|
||||
|
||||
## Windbg Compatibility
|
||||
|
||||
For those coming from a Windows background, Pwndbg has a complete Windbg compatibility layer. You can `dd`, `dps`, `eq`, and even `eb $rip 90` to your heart's content.
|
||||
|
||||
{ style="width: 70%;" }
|
||||
|
||||
## Go Debugging
|
||||
|
||||
Pwndbg has support for dumping complex Go values like maps and slices, including automatically parsing out type layouts in certain cases.
|
||||
|
||||
See the [Go debugging guide](misc/go-debugging.md) for more information.
|
||||
|
||||
## So many commands
|
||||
|
||||
Go take a look at [Commands](commands/index.md)! Here is some cool stuff you can do to get you started.
|
||||
|
||||
### Process State Inspection
|
||||
|
||||
Use the [`procinfo`](commands/process/procinfo.md) command in order to inspect the current process state, like UID, GID, Groups, SELinux context, and open file descriptors! Pwndbg works particularly well with remote GDB debugging like with Android phones.
|
||||
|
||||

|
||||
|
||||
### ROP Gadgets
|
||||
|
||||
Tools for finding rop gadgets statically don't know about everything that will be loaded into the address space and they can make mistakes about which addresses will actually end up executable. You can now rop at runtime with Pwndbg's [`rop`](commands/integrations/rop.md) and [`ropper`](commands/integrations/ropper.md).
|
||||
|
||||
{ style="width: 70%;" }
|
||||
|
||||
### Search
|
||||
|
||||
Pwndbg makes [`search`](commands/memory/search.md)ing the target memory space easy, with a complete and easy-to-use interface. Whether you're searching for bytes, strings, or various sizes of integer values or pointers, it's a simple command away.
|
||||
|
||||

|
||||
|
||||
### Finding Leaks
|
||||
Finding leak chains can be done using the [`leakfind`](commands/memory/leakfind.md) command. It recursively inspects address ranges for pointers, and reports on all pointers found.
|
||||
|
||||

|
||||
|
||||
### Telescope
|
||||
Inspecting memory dumps is easy with the [`telescope`](commands/memory/telescope.md) command. It recursively dereferences a range of memory, letting you see everything at once. As an added bonus, Pwndbg checks all of the available registers to see if they point into the memory range.
|
||||
|
||||
{ style="width: 70%;" }
|
||||
|
||||
### Virtual Memory Maps
|
||||
Pwndbg enhances the standard memory map listing and allows easy searching with [`vmmap`](commands/memory/vmmap.md).
|
||||
|
||||
{ style="width: 70%;" }
|
||||
{ style="width: 70%;" }
|
||||
@ -0,0 +1,45 @@
|
||||
# GDB vs LLDB
|
||||
|
||||
For users who are migrating from one debugger to another, here is a table comparison of some of the most common actions and how to do them in GDB and LLDB. Note that both debuggers offer shorthands for typing these commands.
|
||||
|
||||
| **Functionality** | **GDB Command** | **LLDB Command** |
|
||||
|-----------------------------------------------|----------------------------------------|-------------------------------------------------------------|
|
||||
| **Start Debugging Program** | `gdb ./your-program` | `lldb ./your-program` |
|
||||
| **Set a Breakpoint** | `break <function-name>` | `breakpoint set --name <function-name>` |
|
||||
| **Set Breakpoint on Address** | `break *<address>` | `breakpoint set --address <address>` |
|
||||
| **Set Breakpoint at Line** | `break <filename>:<line-number>` | `breakpoint set --file <filename> --line <line-number>` |
|
||||
| **Set Hardware Breakpoint** | `hbreak <function-name>` | `breakpoint set --hardware --name <function-name>` |
|
||||
| **Set Hardware Breakpoint at Memory** | `hbreak *<memory-address>` | `breakpoint set --hardware --address <memory-address>` |
|
||||
| **List All Breakpoints** | `info breakpoints` | `breakpoint list` |
|
||||
| **Delete Breakpoints** | `delete <breakpoint-number>` | `breakpoint delete <breakpoint-number>` |
|
||||
| **Set Watchpoint** | `watch <variable>` | `watchpoint set variable <variable>` |
|
||||
| **Set Conditional Breakpoint** | `break <function-name> if <condition>` | `breakpoint set --condition "<condition>"` |
|
||||
| **Continue Execution** | `continue` | `process continue` |
|
||||
| **Next Instruction** | `next` | `thread step-over` |
|
||||
| **Step into a Function** | `step` | `thread step-in` |
|
||||
| **Step out of a Function** | `finish` | `thread step-out` |
|
||||
| **Print Threads** | `info threads` | `thread list` |
|
||||
| **Select Thread** | `thread <thread-id>` | `thread select <thread-id>` |
|
||||
| **Print Register Values** | `info registers` | `register read -a` |
|
||||
| **Print a Variable** | `print <variable>` | `print <variable>` |
|
||||
| **Display Variable on Every Stop** | `display <variable>` | `expression --watch <variable>` |
|
||||
| **Examine Memory (Hex)** | `x/<num>x <memory-address>` | `memory read --format x --count <num> <memory-address>` |
|
||||
| **Examine Memory (Integer)** | `x/<num>d <memory-address>` | `memory read --format d --count <num> <memory-address>` |
|
||||
| **Inspect Stack Trace** | `backtrace` | `thread backtrace` |
|
||||
| **Change Register Value** | `set $<register-name> = <value>` | `register write <register-name> <value>` |
|
||||
| **Check Program Status** | `info locals` | `frame variable` |
|
||||
| **Check Program Info** | `info functions` | `image lookup --functions` |
|
||||
| **Show Disassembly of Function** | `disas <function-name>` | `disassemble <function-name>` |
|
||||
| **Memory Dump (Hex)** | `x/<num>xh <memory-address>` | `memory read --format x --count <num> <memory-address>` |
|
||||
| **Memory Dump (Bytes)** | `x/<num>bx <memory-address>` | `memory read --format b --count <num> <memory-address>` |
|
||||
| **Show Process Information** | `info process` | `process status` |
|
||||
| **Quit Debugging** | `quit` | `quit` |
|
||||
| **Run Program with Arguments** | `run <arg1> <arg2> ...` | `process launch -- <arg1> <arg2> ...` |
|
||||
| **Show Current Function** | `info frame` | `frame info` |
|
||||
| **Set Sysroot** | `set sysroot <path-to-sysroot>` | `settings set target.sysroot <path-to-sysroot>` |
|
||||
| **Set Source Directory** | `directory <path-to-source-directory>` | `settings set target.source-map <remote-path> <local-path>` |
|
||||
| **Set Architecture** | `set architecture <arch>` | `target create --arch <arch> <executable-file>` |
|
||||
| **Show Settings** | `show <setting-name>` | `settings show <setting-name>` |
|
||||
| **Set File for Debugging** | `file <executable-file>` | `target create <executable-file>` |
|
||||
| **Start the Program and Run One Instruction** | `starti` | `process launch --stop-at-entry` |
|
||||
| **Enable ASLR** | `set disable-randomization off` | `settings set target.disable-aslr false` |
|
||||
@ -0,0 +1,13 @@
|
||||
# GDB TUI
|
||||
|
||||

|
||||
|
||||
The context sections are available as native [GDB TUI](https://sourceware.org/gdb/current/onlinedocs/gdb.html/TUI.html) windows named `pwndbg_[sectionname]`. There are some predefined layouts coming with pwndbg which you can select using `layout pwndbg` or `layout pwndbg_code`.
|
||||
|
||||
Use `focus cmd` to focus the command window and have the arrow keys scroll through the command history again. `tui disable` to disable TUI mode and go back to CLI mode when running commands with longer output. `ctrl-x + a` toggles between TUI and CLI mode quickly. Hold shift to ignore the TUI mouse integration and use the mouse normally to select text or copy data.
|
||||
|
||||
To create [your own layout](https://sourceware.org/gdb/current/onlinedocs/gdb.html/TUI-Commands.html) and selecting it use normal `tui new-layout` syntax like:
|
||||
```
|
||||
tui new-layout pwndbg_custom {-horizontal { { -horizontal { pwndbg_code 1 pwndbg_disasm 1 } 2 { {-horizontal pwndbg_legend 8 pwndbg_control 2 } 1 pwndbg_regs 6 pwndbg_stack 6 } 3 } 7 cmd 3 } 3 { pwndbg_backtrace 2 pwndbg_threads 1 pwndbg_expressions 2 } 1 } 1 status 1
|
||||
layout pwndbg_custom
|
||||
```
|
||||
@ -0,0 +1,27 @@
|
||||
# Ghidra Integration
|
||||
|
||||
With the help of [radare2](https://github.com/radareorg/radare2) or [rizin](https://github.com/rizinorg/rizin) it is possible to show the decompiled source code of the ghidra decompiler.
|
||||
|
||||
However, this comes with some prerequisites.
|
||||
|
||||
* First: you have to have installed radare2 or rizin and it must be found by gdb (within path)
|
||||
* Second: you have to install the ghidra plugin for radare2
|
||||
[r2ghidra](https://github.com/radareorg/r2ghidra) or install the ghidra plugin for rizin [rz-ghidra](https://github.com/rizinorg/rz-ghidra)
|
||||
* Third: r2pipe has to be installed in the python-context gdb is using (or if you are using rizin, install rzpipe instead)
|
||||
|
||||
The decompiled source be shown as part of the context by adding `ghidra` to `set context-sections`
|
||||
or by calling `ctx-ghidra [function]` manually.
|
||||
|
||||
Be warned, the first call to both radare2/r2ghidra and rizin/rz-ghidra are rather slow! Subsequent requests for decompiled
|
||||
source will be faster. And it does take up some resources as the radare2/rizin instance is kept by r2pipe/rzpipe
|
||||
to enable faster subsequent analysis.
|
||||
|
||||
With those performance penalties it is reasonable to not have it launch always. Therefore it includes
|
||||
an option to only start it when required with `set context-ghidra`:
|
||||
|
||||
* `set context-ghidra always`: always trigger the ghidra context
|
||||
* `set context-ghidra never`: never trigger the ghidra context except when called manually
|
||||
* `set context-ghidra if-no-source`: invoke ghidra if no source code is available
|
||||
|
||||
Remark: the plugin tries to guess the correct current line and mark it with "-->", but it might
|
||||
get it wrong.
|
||||
@ -0,0 +1,54 @@
|
||||
# Splitting / Layouting Context
|
||||
|
||||
i.e. doing this:
|
||||

|
||||
|
||||
In Pwndbg, the context sections can be distributed among different tty by using the [`contextoutput`](../commands/context/contextoutput.md) command. Example:
|
||||
```
|
||||
contextoutput stack /path/to/tty true
|
||||
```
|
||||
|
||||
If you use a terminal or multiplexer that supports scripted pane splitting, you can write a Python script that will create the panes and distribute them to your liking whenever you start pwndbg.
|
||||
|
||||
For instance, for tmux, you could write something like this:
|
||||
```python
|
||||
python
|
||||
import atexit
|
||||
import os
|
||||
from pwndbg.commands.context import contextoutput, output, clear_screen
|
||||
bt = os.popen('tmux split-window -P -F "#{pane_id}:#{pane_tty}" -d "cat -"').read().strip().split(":")
|
||||
st = os.popen(F'tmux split-window -h -t {bt[0]} -P -F '+'"#{pane_id}:#{pane_tty}" -d "cat -"').read().strip().split(":")
|
||||
re = os.popen(F'tmux split-window -h -t {st[0]} -P -F '+'"#{pane_id}:#{pane_tty}" -d "cat -"').read().strip().split(":")
|
||||
di = os.popen('tmux split-window -h -P -F "#{pane_id}:#{pane_tty}" -d "cat -"').read().strip().split(":")
|
||||
panes = dict(backtrace=bt, stack=st, regs=re, disasm=di)
|
||||
for sec, p in panes.items():
|
||||
contextoutput(sec, p[1], True)
|
||||
contextoutput("legend", di[1], True)
|
||||
atexit.register(lambda: [os.popen(F"tmux kill-pane -t {p[0]}").read() for p in panes.values()])
|
||||
end
|
||||
```
|
||||
If you're using tmux specifically, you can use [pwnmux](https://github.com/joaogodinho/pwnmux) as a prebuilt layout or [splitmind](https://github.com/jerdna-regeiz/splitmind) to easily configure the layout you want.
|
||||
|
||||
!!! example
|
||||
|
||||
The above example uses splitmind and following configuration:
|
||||
```python
|
||||
python
|
||||
import splitmind
|
||||
(splitmind.Mind()
|
||||
.tell_splitter(show_titles=True)
|
||||
.tell_splitter(set_title="Main")
|
||||
.right(display="backtrace", size="25%")
|
||||
.above(of="main", display="disasm", size="80%", banner="top")
|
||||
.show("code", on="disasm", banner="none")
|
||||
.right(cmd='tty; tail -f /dev/null', size="65%", clearing=False)
|
||||
.tell_splitter(set_title='Input / Output')
|
||||
.above(display="stack", size="75%")
|
||||
.above(display="legend", size="25")
|
||||
.show("regs", on="legend")
|
||||
.below(of="backtrace", cmd="ipython", size="30%")
|
||||
).build(nobanner=True)
|
||||
end
|
||||
```
|
||||
|
||||
If you're using kitty, you may check out [kittydbg](https://github.com/k4lizen/kittydbg) for a prebuilt layout.
|
||||