Commit Graph

1260 Commits

Author SHA1 Message Date
alufers 1c06c52b47
fix: make mprotect command truly multi-arch (#1162)
* fix: make mprotect command truly multi-arch

Added register saving based on reg_sets defined for each processor architecture, additionally shellcraft is used to generate the arch-specific shellcode.

Unfortunately this command is not currently tested on platforms other than x86_64.

* Update pwndbg/commands/mprotect.py

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>

* mprotect: Add parsing, alignment to the addr argument

This change makes sure that the addr argument is parsed as an gdb expression (so you can use registers for example) and aligns it to the nearest page boundary.

* mprotect: Clean up register saving, print the result

Cleaned up saving of registers and added printing of the results, as per disconnect's sugesstions.

* Simplify the test for mprotect

Simplify the code and remove the useless binary

* Update tests/test_mprotect.py

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
2022-10-18 02:12:10 +02:00
Disconnect3d c50ba4612e
Pwndbg configuration: do not set history expansion (#1292)
The `set history expansion on` setting we set seems to cause troubles if users want to execute a shell command by using the exclamation mark.

I do not like it, especially taking into account the recent shell command deprecation we did.
2022-10-18 01:46:05 +02:00
Gulshan Singh dac5340b18 Add tests for find_fake_fast --align 2022-10-16 13:18:47 -07:00
Gulshan Singh 9a783c08ce Cleanup find_fake_fast 2022-10-16 13:18:47 -07:00
Gulshan Singh e6574f447f
Add find_fake_fast test (#1286)
* Fix find_fake_fast test name

* Add more find_fake_fast tests
2022-10-16 11:31:47 +02:00
CptGibbon 1a0bbbf26a
Add multithreaded malloc_chunk tests (#1277)
* Add reset_on_thread decorator

* Apply reset_on_thread to Heap.multithreaded

* Add multithreaded malloc_chunk tests

* Clarify comment in C source

* Clarify expected thread number with assert in test
2022-10-16 10:53:23 +02:00
Gulshan Singh e5e73fa654 Fix symbol resolution 2022-10-13 21:16:18 -07:00
Alan Li b4cdcdfcfc
Unit tests and some bugs fix for the heap heuristics (#1283) 2022-10-13 21:07:07 -07:00
Gulshan Singh e456b317d7 Convert all vmmap references to pwndbg.gdblib.vmmap 2022-10-13 15:23:38 -07:00
Gulshan Singh 8b6deac4fd Move vmmap.py to gdblib 2022-10-13 15:23:38 -07:00
E. Rivas b5da3e8237
Add ignore command (from #1257) (#1276)
* Add ignore command (from #1257)

* Fix lint

* Apply changes suggested by disconnect3d on ignore command

* Add tests for ignore command
2022-10-14 00:07:02 +02:00
Gulshan Singh 026f3c0164 Fix reference to pwndbg.gdblib.config 2022-10-13 15:01:16 -07:00
Lonny Wong cf11443735 add test for max-visualize-chunk-size 2022-10-13 15:01:16 -07:00
Gulshan Singh 353c906a3f Move more gdb info commands to info.py 2022-10-13 14:14:13 -07:00
Gulshan Singh f792f00081 Move example strings to comments 2022-10-13 14:14:13 -07:00
Gulshan Singh 4647ccca57 Fix windbg test 2022-10-13 09:31:35 -07:00
Gulshan Singh 2220918866 Cleanup hexdump implementation 2022-10-13 09:31:35 -07:00
Gulshan Singh 084eb36813
Add a test for config triggers (#1225)
* Split config.py into lib/ and gdblib/

* Add test for config triggers
2022-10-13 14:54:45 +02:00
Gulshan Singh eabab316d2
Split config.py into lib/ and gdblib/ (#1134) 2022-10-13 14:50:20 +02:00
Gulshan Singh 2be84a9b4d Fix some mypy errors 2022-10-13 00:46:26 -07:00
Gulshan Singh fd5e722cbc Add hexdump test 2022-10-12 20:34:51 -07:00
Lonny Wong b218f34a36
add max display size for vis_heap_chunks (#1275) 2022-10-12 16:43:52 -07:00
Alan Li fbedf0b497
Add more comments about the changes in #1273 (#1274) 2022-10-12 14:17:35 +02:00
CptGibbon fc33d6fb7c
Develop Arena class (#1266)
* Develop Arena class

* Remove TODO comments

* Replace type() with isinstance()

* Use __slots__ in Chunk & Arena classes

* Remove unnecessary append()
2022-10-12 13:01:46 +02:00
Alan Li 42caec2552
Fix the bug in the heuristic for `main_arena` and `mp_` (#1273)
* Fix the bug when searching the struct of `main_arena` and `mp_` in the memory.
2022-10-12 12:32:07 +02:00
Alan Li 75ece8e2a8
Don't catch the error of the heap commands when `set exception-* on` (#1270)
* Don't catch the error of the heap commands for developers

* Use `pwndbg.config` and re-raise the error

See https://github.com/pwndbg/pwndbg/pull/1270#discussion_r992209956

* Update pwndbg/commands/__init__.py

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
2022-10-12 12:30:23 +02:00
Disconnect3d 8da9c5b9f9
Fix #1189: fixes patch command's arch=... value (#1269)
Before this commit we passed `pwndbg.gdblib.arch.current` as `arch=...`
keyword argument to pwnlib functions like `asm` and `disasm`.

Since pwnlib has a concept of "context" that holds variables like
currently set architecture or number of bits, this commit starts using
those for the `patch` command implementation as we started to set pwnlib
context recently in 9e84c18c44
2022-10-11 13:43:26 +02:00
Alan Li db3a86abb4
Fix #1271 (#1272) 2022-10-11 13:42:46 +02:00
Disconnect3d 478a569cb3
Fix #1256: fixes next cmds hangs on segfaults (#1268)
* Fix #1256: fixes next cmds hangs on segfaults

Before this commit the next/step commands like `nextret`, `stepret`,
`nextsyscall`, `nextproginstr` etc. would hang if they approach a
segfault. This commit fixes it by checking for ANY signals by executing
the GDB's `info prog` command and parsing its output.

* fix lint
2022-10-11 09:33:09 +02:00
Disconnect3d d42444274e
allow setting gdblib.regs.<reg>=<val> (#1267)
This commit allows for setting the selected thread's registers by using
the pwndbg.gdblib.regs.<register-name> = <new-value> expressions. Before
this commit invoking such Python code would set the internal Pwndbg
register value, but not really the inferior value. This could lead to
weird issues when the displayed context shows the new register value but
e.g. `info reg rax` displays the old value.
2022-10-11 08:08:31 +02:00
Gulshan Singh bfbb2b8652
Move symbol.py to gdblib (#1259)
* Move symbol.py to gdblib

* Renamed private methods

* Renamed pwndbg.symbol to pwndbg.gdblib.symbol

* Cleanup symbol.py

* Fix lint issues

* Handle tls error on symbol lookup

* Fix merge conflicts

* Remove old way of looking up symbols
2022-10-11 06:11:25 +02:00
CptGibbon ec8addd602
Build malloc_chunk tests with libpthread (#1265) 2022-10-10 01:32:26 +02:00
Alan Li d79dbb672c
Enhances the error handling of the heap heuristic (#1242)
* Enhance the error handling of the heap command

* Add a new method: `can_be_resolved()` to heap classes to check whether we can resolve the heap after the heap is initialized.

* Add a new function: `get_got_plt_address()` to `pwndbg.glibc`, by doing this, we can determine the location of the symbols without `_IO_list_all` by parsing the output of `info files`.

* Add a new subclass of Exception: `SymbolUnresolvableError` to handle the error when we can't resolve some symbols.

* If we didn't set the GLIBC version manually, we won't get the unnecessary Python error from this now, instead, we tell the user how to set it.

* If we didn't have enough information to resolve some symbols, we show which symbol we lack and tell the user how to set it manually instead of just executing it and showing a Python error.

* Avoid getting the wrong heap config

* List the symbols manually instead of using `locals()`

* Avoid the extra function call by `can_be_resolved`

* Enhance the error handling when finding TLS (#1237)

* Enhance the error handling for more cases

* Add support to use `gdb.lookup_static_symbol` in `pwndbg.symbol`

* Enhance the strategy when handling the heap-related symbols

* Use `pwndbg.symbol.static_linkage_symbol_address()` to get the address of the symbol first

e.g. Let's say we have a file called `FILENAME.c`:

```
void *main_arena = 0xdeadbeaf;
int main(){
    free(malloc(0x20));
    return 0;
}
```

If we compiled it with `gcc FILENAME.c -g`, the old heap command will fail because it thinks `main_arena` is this 0xdeadbeaf `main_arena`, not the "real" `main_arena` in GLIBC.

With this commit, it should work without this issue.

* Revert "Enhance the error handling when finding TLS (#1237)"

This reverts commit 7d2d1ae6b6.

* Enhance the error handling when finding TLS (#1237)

* Catch the error when reading the address of the static linkage symbol

* Bug fix for `thread_cache` under heuristic mode

* Bug fix for `static_linkage_symbol_address()`

* If `gdb.lookup_static_symbol(symbol)` is None, it will cause the
  error.

* Use new code after refactoring
2022-10-09 13:59:06 +02:00
Gulshan Singh 6856e9294c
Move elf.py to gdblib (#1260) 2022-10-08 23:16:57 -07:00
Gulshan Singh 63b988a997
Move file.py to gdblib and improve procinfo test (#1258) 2022-10-08 21:07:15 -07:00
Gulshan Singh bb342a9286
GDB Refactor [18/N]: Move proc to gdblib/proc.py (#1247) 2022-10-08 16:00:53 -07:00
Gulshan Singh 29c9d74f9b
Add flake8-builtins to linters (#1254)
* Add flake8-builtins linter

* Update flake8-builtins to 2.0.0
2022-10-09 00:03:22 +02:00
Gulshan Singh c3c8975b7a
GDB Refactor [19/N]: Move gdbutils/functions.py to gdblib (#1253) 2022-10-08 06:43:59 -07:00
Gulshan Singh 83a2fb0ba5
Move remote_files_dir into file.py (#1249) 2022-10-08 15:06:58 +02:00
Gulshan Singh 0bd3d3a37f
Remove unnecessary imports in __init__.py (#1252) 2022-10-08 11:30:09 +02:00
Gulshan Singh 13e1608ecd
Cleanup dependencies (#1251) 2022-10-08 04:48:28 +02:00
Gulshan Singh b0249dda6b
Cleanup load_gdblib() (#1248) 2022-10-07 16:37:58 -07:00
Gulshan Singh 8fdc423841
Move net.py to lib (#1246) 2022-10-08 01:17:33 +02:00
Gulshan Singh 6a40c09057
GDB Refactor [16/N]: Move tls.py to gdblib/tls.py (#1245) 2022-10-07 15:56:25 -07:00
Gulshan Singh 2eccf02b50
GDB Refactor [15/N]: Move stack.py to gdblib/stack.py (#1244) 2022-10-07 15:41:24 -07:00
Gulshan Singh 135ced5c9e Load commands and gdblib explicitly in __init__.py 2022-10-07 14:41:37 -07:00
Disconnect3d e5043535a3
Fix #1197: dont display ctx on reg/mem changes (#1239)
* Fix #1197: dont display ctx on reg/mem changes

This commit fixes a bug where we displayed context on registers or memory changes made by the user, so e.g. when user executed one of:

```
set *rax=1
set *(int*)0x<some address> = 0x1234
set *(unsigned long long*)$rsp+4=0x44444444
```

It fixes it by just... setting a flag after the context is displayed for
the first time and resetting it on a continue GDB event.

There was a previous attempt to fix this bug in #1226 but it was rather
a hack than a proper fix. This current commit should be a proper fix :P.

Below is some more explanation of this bug.

The fact that we displayed ctx on regs/mem changes was a result us clearing the cache of the `prompt_hook_on_stop` function:

```python
 @pwndbg.lib.memoize.reset_on_stop
 def prompt_hook_on_stop(*a):
     pwndbg.commands.context.context()
```

Where this function is called in `prompt_hook`, on each prompt display:

```python
def prompt_hook(*a):
    global cur

    new = (gdb.selected_inferior(), gdb.selected_thread())

    if cur != new:
        pwndbg.gdblib.events.after_reload(start=cur is None)
        cur = new

    if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped:
        prompt_hook_on_stop(*a)
```

So, since we cleared this function cache on each register/memory changes, it resulted in us displaying context on each prompt hook.

So how did we clear this function cache? Through the `memoize_on_stop` function:

```
 @pwndbg.gdblib.events.stop
 @pwndbg.gdblib.events.mem_changed
 @pwndbg.gdblib.events.reg_changed
 def memoize_on_stop():
     reset_on_stop._reset()
```

But why? We need this to make sure that all of the executed commands, when they read memory or registry, get proper new (not cached) values!

So it makes sense to keep reseting the stop caches on mem/reg changed events. Otherwise, we would use incorrect (old) values if user set a register/memory and then used some commands like `context` or other that depend on register/memory state.

* lint
2022-10-07 00:38:39 +02:00
Disconnect3d 59889f1330
events.py: remove unused Pause class (#1223)
* events.py: remove unused Pause class

* remove pause

* do not set debug-events flag
2022-10-06 20:59:22 +02:00
Gulshan Singh 23caabdb76 Split heap tests into their own files 2022-10-06 11:27:13 -07:00
Gulshan Singh 6c1ddb451c Moved heap tests into tests/heap 2022-10-06 11:27:13 -07:00