Commit Graph

1172 Commits

Author SHA1 Message Date
Miles Liu 8d184a9e8e Upload codecov report only from Ubuntu22.04
Also update GitHub action dependencies.
2022-09-29 12:47:22 +02:00
Disconnect3d 3043c748fe
Remove badges from docs/index.md 2022-09-29 03:52:16 +02:00
lebr0nli c7a72e226f Restore `sys.excepthook` after leaved IPython 2022-09-29 03:19:56 +02:00
lebr0nli 33d9e35b0f Avoid invoking a function of property when auto-completing
See https://github.com/pwndbg/pwndbg/pull/1170#issuecomment-1259041809
2022-09-29 03:19:56 +02:00
lebr0nli 6a3faa0a17 Support starting the Ipython prompt with `ipi` 2022-09-29 03:19:56 +02:00
CptGibbon df26a11b57 Remove `template_heap_command` 2022-09-29 00:39:07 +02:00
CptGibbon a138f7f890 More versatile chunk field name matching 2022-09-29 00:39:07 +02:00
CptGibbon 6e16c51edf More convenient access to individual chunk flags 2022-09-29 00:39:07 +02:00
CptGibbon 1a27176058 Lint 2022-09-29 00:39:07 +02:00
CptGibbon 1b3ac5ceac Add Chunk class & template_heap_command 2022-09-29 00:39:07 +02:00
disconnect3d 1ca4d2d33c Enhance heap with for static-linked binaries & remove typeinfo bloat
This commit enhances the heap commands UX for statically linked binaries
and removes typeinfo module bloat.

The typeinfo module had this typeinfo.load function that was looking up a given type.
If it didn't find the type, it fallbacked to compiling many many system
headers in order to add a symbol for a given type into the program. This was
supposed to be used for missing glibc malloc symbols like malloc_chunk.

However, the exact reason it was used: the struct malloc_chunk was never
defined in a header file and was always defined in a malloc.c or another
.c file in glibc sources.

Another place the typeinfo.load logic of compiling headers was/is used
is the `dt` command, which is a windbg alias for getting struct layout
type information, e.g.:
```
pwndbg> dt 'struct malloc_chunk'
struct malloc_chunk
    +0x0000 mchunk_prev_size     : size_t
    +0x0008 mchunk_size          : size_t
    +0x0010 fd                   : struct malloc_chunk *
    +0x0018 bk                   : struct malloc_chunk *
    +0x0020 fd_nextsize          : struct malloc_chunk *
    +0x0028 bk_nextsize          : struct malloc_chunk *
pwndbg>
```

However, the whole big issue with typeinfo.load compilation of headers
was that most of the time it didn't work because e.g. some headers
defined in other paths were missing or that two different headers used
the same struct/function name and the compilation failed.

Since this logic almost never gave good results, I am removing it.

Regarding UX for statically linked binaries: we use `info dll` command
to see if a binary is statically linked. While this method is not
robust, as it may give us wrong results if the statically linked binary
used `dlopen(...)` it is probably good enough.

Now, if a heap related command is executed on statically linked binaries, it
will inform the user and set the resolving of libc heap symbols via
heuristics. Then, it also says to the user they have to set the glibc
version and re-run the command.
2022-09-28 14:03:57 +02:00
disconnect3d ea98cfae77 silence heap_bugs.c build warnings 2022-09-28 00:27:32 +02:00
lebr0nli 4ad2d76327 Show less error when trying to load a non-exist type 2022-09-27 17:26:37 +02:00
disconnect3d 3b2f7796d6 Fix #1165: set context-clear-screen on resetting scrollback
This commit tries to fix the issue of our `set context-clear-screen on`
option resetting the scrollback buffer on some terminals like
gnome-terminal (fwiw it did not happen on terminator or on tmux).

It also adds info to tips about that option.
2022-09-26 01:42:09 +02:00
Albert Koczy 30cd4c7372 fix: lint 2022-09-24 05:02:10 +02:00
Albert Koczy 9e84c18c44 fix: mprotect command and add tests for it
Turns out the mprotect command didn't ever work, as it was amd64 only, but used x86 syscall numbers to call mprotect. I have refactored the command to use shellcraft to generate the shellcode that calls mprotect. I have also unit-tested this command.
2022-09-24 05:02:10 +02:00
disconnect3d d2ba9955b5 fix lint 2022-09-24 02:47:23 +02:00
disconnect3d f322fae4a2 Show arch and emulation status on disasm banner 2022-09-24 02:47:23 +02:00
disconnect3d 02eb8e6dd7 fix libc objfile name in tests 2022-09-23 02:40:45 +02:00
disconnect3d 11f878977e add nextproginstr tests 2022-09-23 02:40:45 +02:00
disconnect3d 703a7bdab9 Fix #1153 nextproginstr command
Fixes the `nextproginst` command and adds two simple tests for it.

The command had two following issues:
1) It assumed that the program vmmap was always the first vmmap with
   proc.exe objfile name -- this assumption has two flaws. First, newer
linkers will create the first memory page for the binary file as
read-only. This is because you do not need the ELF header content to be
executable, and that was the case in old linkers or linux distributions.
As an example, see those vmmap from a simple hello world binary compiled
on Ubuntu 18.04 vs Ubuntu 22.04:

Ubuntu 18.04:
```
  pwndbg> vmmap
  LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
      0x555555554000     0x555555555000 r-xp     1000 0      /home/dc/a.out
      0x555555754000     0x555555755000 r--p     1000 0      /home/dc/a.out
      0x555555755000     0x555555756000 rw-p     1000 1000   /home/dc/a.out
      [...]
```

Ubuntu 22.04:
```
  pwndbg> vmmap
  LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
      0x555555554000     0x555555555000 r--p     1000 0      /home/user/a.out
      0x555555555000     0x555555556000 r-xp     1000 1000   /home/user/a.out
      0x555555556000     0x555555557000 r--p     1000 2000   /home/user/a.out
      0x555555557000     0x555555558000 r--p     1000 2000   /home/user/a.out
      0x555555558000     0x555555559000 rw-p     1000 3000   /home/user/a.out
```

So, before this commit on Ubuntu 22.04 we ended up taking the first
vmmap which was non-executable and we compared the program counter
register against it after each instruction step executed by the
nextproginstr command. As a result, we ended up never getting back to
the user and just finishing the debugged program this way!

Now, after this commit, we will grab only and all the executable pages for
the binary that we debug and compare and compare against them.

2) The second problem was that we printed out the current Pwndbg context
   after executing nextproginstr succesfully. This does not seem to make
much sense because the context should be printed by the prompt hook.
(Without removing this, we ended up printing the context twice)
2022-09-23 02:40:45 +02:00
ntsleep 96d90d18a5 Added test for procinfo command before binary srat 2022-09-23 00:33:35 +02:00
ntsleep e27c25f54a Added test for procinfo command 2022-09-23 00:33:35 +02:00
disconnect3d b1772f166b fix test.sh lint issue 2022-09-23 00:26:45 +02:00
disconnect3d 75aa5a4316 add -h --help to tests.sh 2022-09-22 23:42:34 +02:00
NT Sleep 560e1fc1e2
Fixed android check in procinfo (#1156) 2022-09-22 22:54:07 +02:00
Disconnect3d 446f5d5ae2
add patch command (#1150)
* add patch command

This commit adds the `patch`, `patch_list` and `patch_revert` commands
and adds the `pwntools==4.8.0` as Pwndbg dependency.

The current implementation could be further improved by:
- adding tests :)
- maybe moving `patch_list` and `patch_revert` to `patch --list` and
  `patch --revert` flags?
- better handling of incorrect args/pwnlib exceptions

* lint
2022-09-20 00:30:45 +02:00
Disconnect3d cc3f86d5bc
Improve vmmap on coredump files (#1149)
* Improve vmmap on coredump files

With this commit we now recognize coredumps better and also finally have
a simple test for vmmap commands on:
- a running binary
- on a loaded coredump file with loaded binary
- on a loaded coredump file without a loaded binary

We also stop saving vmmaps for `maintenance info sections` sections
which have a start address of 0x0. While there could potentially be a
coredump file from a binary with start=0x0, this should work in most
cases.

We could in theory do a slighty better: we could take the vmmap at 0 and
try to read memory from it. However, I am not sure if it is a good idea
to try such memory read?

* remove unused import

* add missing crash_simple.asm

* fix vmmap coredump test on different ubuntu mem layouts

* use /proc/$pid/maps for vmmap tests

* fix formatting

* fix import

* fix test

* fix test

* fix test

* fix lint

* fix test

* fix test

* fix test

* fix test

* fix lint

* another fixup for ubuntu 22.04

* another fixup for ubuntu 22.04

* lint
2022-09-17 12:26:04 +02:00
Disconnect3d f125afc9aa
fix qemu vmmap showing coredump mappings (#1148) 2022-09-16 03:37:58 +02:00
CptGibbon 636db8b25f
Add regression test for `find_fake_fast` command (#1147)
* Add a regression test for find_fake_fast

The test program creates a fake chunk size field in its .data section
with a set NON_MAIN_ARENA flag. The Python test runs the find_fake_fast
command on an address succeeding the fake chunk. A gdb.MemoryError
indicates regression - issue #1142

* Make linter happy
2022-09-16 03:37:40 +02:00
Disconnect3d 88c610116e
fix distance command (#1146)
* fix distance command

* fix unused imports
2022-09-14 18:35:52 +02:00
CptGibbon 8dae55490b
Add gdb.MemoryError check to get_heap() (#1145)
Call fetch_lazy() on the gdb.Value acquired in get_heap() and wrap it in
a try/except block. Return None if gdb.MemoryError is raised.

Let get_arena_for_chunk() handle None returned by get_heap().

Fixes #1142
2022-09-14 18:01:15 +02:00
syheliel dea9a691d4
add color for modified registers (#1127)
* add color for modified registers

* use color defined in theme

Co-authored-by: syheliel <syheliel@gmail.com>
2022-09-14 16:29:14 +02:00
syheliel 2296999ed9
add type for `./pwndbg/lib` (#1135)
* add type for `./pwndbg/lib`

* add more type hints

Co-authored-by: syheliel <syheliel@gmail.com>
2022-09-12 15:50:06 +02:00
Gulshan Singh ffdff0f966
Move argv.py to gdblib (#1141) 2022-09-09 22:48:56 +02:00
Gulshan Singh 6af4753d8e
Add support for formatting the code directly from lint.sh (#1140) 2022-09-09 22:45:18 +02:00
Gulshan Singh ccc56b9a58
Remove unused imports (#1139) 2022-09-09 04:56:26 +02:00
Gulshan Singh 40c4bf17da
Add types for some modules in lib/ (#1137) 2022-09-09 04:47:22 +02:00
Gulshan Singh 544ea0eab7
Linting/formatting improvements (#1138)
* Fix flake8 F403 warnings

* Fix more flake8 errors and warnings

* Run isort on the root directory
2022-09-09 04:46:46 +02:00
Gulshan Singh bf37c03d8d
Move elftypes to lib/ (#1132) 2022-09-08 00:38:50 +02:00
Gulshan Singh 84bba1b4de
GDB Refactor [11/N]: Move stdio.py to lib/ (#1133)
* Move elftypes to lib/

* move stdio.py to lib/
2022-09-08 00:38:24 +02:00
Gulshan Singh 2ea32b089a
Move qemu.py and remote.py to gdblib (#1130) 2022-09-07 14:15:07 +02:00
Gulshan Singh 8e212b46ef
Move strings.py and dt.py to gdblib (#1129) 2022-09-07 02:31:04 +02:00
Gulshan Singh 512db53edd
Split memory into lib/ and gdblib/ (#1128) 2022-09-07 01:27:46 +02:00
Gulshan Singh 869366bbf7
Fix incorrect import (#1131) 2022-09-06 11:57:50 +02:00
Gulshan Singh 6d573290ac
Move some modules into gdb/ (#1125) 2022-09-05 21:03:19 +02:00
Gulshan Singh eba90ee56b
GDB Refactor [6/N]: Move gcc.py into lib/ (#1124)
* Split regs.py into lib/ and gdblib/

* Move gcc.py to lib/
2022-09-05 20:47:00 +02:00
Gulshan Singh a002e29bc1
Split regs.py into lib/ and gdblib/ (#1121) 2022-09-05 20:42:56 +02:00
Gulshan Singh 692c4b82f6
GDB Refactor [4/N]: Split abi into lib/ and gdblib/ (#1120)
* Remove tips.py

* Split android.py into lib/ and gdb/

* Split abi.py into lib/ and gdblib/
2022-09-05 19:58:57 +02:00
Gulshan Singh 36aa539f62
GDB Refactor [3/N]: Split android into lib/ and gdblib/ (#1119)
* Remove tips.py

* Split android.py into lib/ and gdb/
2022-09-05 19:56:26 +02:00