Commit Graph

1280 Commits

Author SHA1 Message Date
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
CptGibbon 91505a47b1
Add `malloc_chunk` command tests for heuristic heap (#1234) 2022-10-06 10:52:25 -07:00
Gulshan Singh ebadd88220
Add --shell argument to pwndbg command (#1233) 2022-10-05 23:58:40 -07:00
Gulshan Singh 0d73e9d8c9
Cleanup requirements and run full setup in lint CI job (#1230) 2022-10-05 18:15:18 -07:00
lebr0nli 0237c1deff Make `CStruct2GDB` support `gdb.types.has_field()` 2022-10-05 03:39:57 +02:00
disconnect3d 32166d0ed3 fix #1221: ipi command multi-line inputs 2022-10-05 00:43:26 +02:00
Disconnect3d f56db46a59 Update README with GDB build steps 2022-10-04 23:49:48 +02:00
lebr0nli c67f6ea412 Make the heuristic compatible with new heap code 2022-10-04 19:15:10 +02:00
CptGibbon ef89d417d6 Add malloc_chunk command test 2022-10-04 19:14:10 +02:00
Amogh Desai 3be4559970
leakfind should default to $sp (#1218)
* leakfind should default to

* Fixing lint error

Co-authored-by: Amogh <adesai@cloudera.com>
2022-10-04 07:46:13 -07:00
Disconnect3d 3c8ee9bb37 Delete .sublime-settings 2022-10-03 06:29:41 +02:00
disconnect3d 3974364e6d improve bugreport text 2022-10-03 06:13:33 +02:00
disconnect3d ae9661b7f3 bugreport command: use code listings 2022-10-03 06:13:33 +02:00
disconnect3d 12d4012142 remove defcon.py 2022-10-03 06:13:26 +02:00
disconnect3d 86e4679f79 add show-flags and show-compact-regs to ctx regs banner
Hopefully his will improve the discoverability/UX for users who are not
aware of those options.

This is how the new registers banner looks like:
```
[ REGISTERS / show-flags off / show-compact-regs off ]
```

Fwiw it is 54 chars long (without "---" before and after) so its length
should be fine.
2022-10-03 05:39:51 +02:00
disconnect3d 55ab0ae091 fix pipe:X in test 2022-10-03 04:12:24 +02:00
disconnect3d e728fa8614 allow for pipe:X in test 2022-10-03 04:12:24 +02:00
disconnect3d b209ada229 Fix disable_colors formatting & test ctx disasm showing fds
This commit adds a test for context disasm showing of file descriptors
file paths in syscalls like read() or close().

It also fixes a small issue when Pwndbg is run with PWNDBG_DISABLE_COLORS=1

This issue was that executing:
```
pi '{a:2}'.format(a=pwndbg.color.context.prefix(pwndbg.config.code_prefix))
```

Failed when Pwndbg was run with disabled colors. It failed because our
generate color functions in pwndbg/color/* ended up not processing the
input argument -- which here is a Pwndbg config Paramater object -- so
that we got a very non obvious exception:
```
Exception occurred: context: unsupported format string passed to Parameter.__format__ (<class 'TypeError'>)
```

This issue could hypothetically also exist if our config value would be
empty I think. So with the fix in this commit, where we do str(x) over
the color funciton argument should fix this issue in all cases.
2022-10-03 04:12:24 +02:00
disconnect3d 21794a6ec4 tips: add set show-flags on tip 2022-10-03 04:11:17 +02:00
CptGibbon 4069400262 Revert Chunk.size meaning, add Chunk.real_size 2022-10-03 03:31:01 +02:00
CptGibbon 74f07b33c5 Integrate Chunk class into malloc_chunk command 2022-10-03 03:31:01 +02:00
CptGibbon 36aaaf5a16 Remove redundancy in malloc_chunk command 2022-10-03 03:31:01 +02:00
CptGibbon 1542949443 Add bk_nextsize property to Chunk class 2022-10-03 03:31:01 +02:00
CptGibbon a25cdfe976 Add fd_nextsize property to Chunk class 2022-10-03 03:31:01 +02:00
CptGibbon ef6a84e821 Add flags mask to Chunk.size 2022-10-03 03:31:01 +02:00
CptGibbon 9aafed82be Change Chunk.size to Chunk.size_field 2022-10-03 03:31:01 +02:00
CptGibbon 10117946f2 Remove unused variable in flags property 2022-10-03 03:31:01 +02:00
Disconnect3d 521514b204
fix #1190: telescope -r with addr as count (#1198)
Before:
```
pwndbg> telescope -r 3
Traceback (most recent call last):
  File "/home/gsgx/code/pwndbg/pwndbg/commands/__init__.py", line 145, in __call__
    return self.function(*args, **kwargs)
  File "/home/gsgx/code/pwndbg/pwndbg/commands/__init__.py", line 216, in _OnlyWhenRunning
    return function(*a, **kw)
  File "/home/gsgx/code/pwndbg/pwndbg/commands/telescope.py", line 191, in telescope
    telescope.offset += i
UnboundLocalError: local variable 'i' referenced before assignment
```

After:
```
pwndbg> telescope -r 3
00:0000│         0x7fffffffe2b0 ◂— 0x0
01:0008│         0x7fffffffe2b8 —▸ 0x7ffff7fe32ea (_dl_start_user+50) ◂— lea    rdx, [rip - 0x1a2b1]
02:0010│ r13 rsp 0x7fffffffe2c0 ◂— 0x1
```
2022-10-02 18:30:24 -07:00
syheliel f571d5ca84 fix lint 2022-10-03 03:28:09 +02:00
syheliel 26ec474eae fix lint 2022-10-03 03:28:09 +02:00
syheliel 5324ba1d2a fix test 2022-10-03 03:28:09 +02:00