Commit Graph

1154 Commits

Author SHA1 Message Date
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
Disconnect3d b7ddf3a070
fix #1111 errno command edge case (#1126)
* fix #1111 errno command edge case

This commit fixes the case when errno command causes a binary to
segfault when the `__errno_location` symbol was defined but its .plt.got
entry was not filled yet by the dynamic loader (ld.so), so e.g. when the
glibc library was not loaded yet.

In such a case, us triggering a call to `__errno_location` function
triggered a jump to an unmapped address. Now, we dereference that
.plt.got symbol and see if it lives in mapped memory.

* add tip about errno command

* errno: fix case when __errno_location@got.plt is missing

* fix lint

* fix sh lint

* fix errno test
2022-09-05 14:56:37 +02:00
Gulshan Singh cc50024417
Format shell scripts with shfmt (#1123)
* Add lint.sh script

* Format shell scripts with shfmt and add to lint.sh

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
2022-09-05 13:24:52 +02:00
Gulshan Singh 2b62259d7e
GDB Refactor [2/N]: move some modules to lib/ (#1118)
* Don't exclude pwndbg/lib in .gitignore

* Move which.py to lib/which.py

* move funcparser.py and functions.py to lib/

* moved version.py to lib/

* Move tips.py to lib/

* Update pwndbg/lib/version.py

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
2022-09-05 13:23:20 +02:00
Gulshan Singh bbf1397a2b
Add lint.sh script (#1122) 2022-09-05 13:18:40 +02:00
Gulshan Singh 77380eb63c
GDB Refactor [1/N]: Split arch.py and related files into lib/ and gdb/ (#1114)
* Split arch.py and related files into lib/ and gdb/

* Rename pwndbg.gdb to pwndbg.gdblib
2022-09-05 04:14:40 +02:00
Disconnect3d 42f32d7cc7
fix errno command (#1112)
* fix errno command

* fix isort

* try to fix CI

* Update test_command_errno.py
2022-09-05 02:46:51 +02:00
Gulshan Singh 9755a40d7b
Build docker in CI (#1117) 2022-09-05 02:19:55 +02:00
Disconnect3d 1d9c95d07a
Fix Dwarf Errors with old GDBs in docker
This should fix things like:
> tests/test_heap.py::test_try_free_invalid_next_size_fast Dwarf Error: DW_FORM_strx1 found in non-DWO CU [in module /pwndbg/tests/binaries/heap_bugs.out]
2022-09-05 01:59:56 +02:00
Alan Li 69d357633c
Some updates about Heap heuristics (#1075)
* Fix some bugs of the aarch64 heuristic and a bug about tcache

* Some orders of the aarch64 assembly instructions might have a little bit different, so I make it more general. Some bugs of the older version can reproduce by the libc here (https://github.com/perfectblue/ctf-writeups/tree/master/2019/insomnihack-teaser-2019/nyanc/challenge)

* If we didn't find the correct tcache symbol address via heuristic, we will now use our fallback strategies for it.

* Refactor the code in a cleaner way

See https://github.com/pwndbg/pwndbg/pull/1029#discussion_r945934337

* Update the fallback solution of finding `main_arena`

* Since the arenas are a circular linked list, we can iterate it to check the address we guess is `main_arena` or not (https://github.com/pwndbg/pwndbg/pull/1029#discussion_r945335543)

* Update the boundaries of the address we might guess to avoid some unneeded tests

* Remove guard code for `mp_` before we test the fallback solution

Fix https://github.com/pwndbg/pwndbg/pull/1029#discussion_r945338469

* Refactor TLS features and fix a bug about fsbase/gsbase

* Move TLS features into an external module, and now the user can use the `tls` command to get its address (https://github.com/pwndbg/pwndbg/pull/1029#discussion_r945336737)

* Avoid `ValueError: Bad register` when trying to access fsbase/gsbase if the current arch is i386

* Fix a bug about tls finding for i386: `__errno_location` not always in `libc.so.6`, sometimes it will also in `libpthread-*.so`

* Update the comments about finding tcache

* Use `exit` event to avoid unnecessary reset

* Add a paramter for GLIBC version

* Update some strategies of heuristic

* Try to resolve heap via debug symbols even when using the heuristic
(By doing this, the binary compiled with `--static` flag can work with the heuristics by setting the GLIBC version manually)

* Try to avoid false positives when finding the symbol address and TLS base via heuristic

* Refactor some useless code

* Update the descriptions of the heap config

* Update the tips for the heap heuristics features

* Raise error when user set the GLIBC version in the wrong format

* Use `reset_on_start` with `glibc._get_version`

See https://github.com/pwndbg/pwndbg/pull/1075#discussion_r957899458

* Remove some unnecessary information in the hint message

See https://github.com/pwndbg/pwndbg/pull/1075#discussion_r957900468

* Use black to fix the format

* Fix indent

* Use black to fix the format
2022-09-04 19:01:29 +02:00
Gulshan Singh b32c5e052e
Set security_opt to seccomp:unconfined in docker-compose.yml (#1116) 2022-09-04 18:35:46 +02:00
Gulshan Singh 301a0c1502
Add dev-requirements.txt to Docker image (#1115) 2022-09-04 18:34:30 +02:00
Gulshan Singh 2d483fcb12
Add smoke test (#1113) 2022-09-02 03:35:28 +02:00
Disconnect3d 099c766342
improve start and entry commands description (#1109)
* improve start and entry commands description

Now, those commands will display proper description, describing when
they actually stop and what else can you do (e.g. run `starti` command
if u need to stop on first stop!).

* Update start.py
2022-08-31 02:44:31 +02:00
Disconnect3d d12b6ecefc
ArgparsedCommand: fix `help cmd` and `cmd --help` behavior (#1108)
* ArgparsedCommand: fix `help cmd` and `cmd --help` behavior

Before this commit there was always a mismatch of what was displayed
when the user did `<command> --help` or `help <command>`.

With those changes, we fetch the help string from the argument parser
and render it as the command object's `self.__doc__`, so that it will be
displayed during `help <command>`.

Previously, we only displayed the command description during help.

* fix the pwndbg [filter] command that was broken in previous commit
2022-08-31 02:28:13 +02:00
Disconnect3d 299f30be73
vmmap: use pwndbg.info.auxv instead of gdb.execute (#1107)
This may or may not fix the issue described in https://github.com/pwndbg/pwndbg/issues/954#issuecomment-1231486726
2022-08-30 21:44:39 +02:00
syheliel 7e8c999795
Fix IDE's auto-complete support (#1106)
Co-authored-by: syheliel <syheliel@gmail.com>
2022-08-30 20:46:16 +02:00
Lonny Wong e92a45ca26
support riscv:rv64 without capstone (#1096)
* add riscv:rv64 registers

base on https://github.com/pwndbg/pwndbg/pull/829 by Tobias Faller <faller@endiio.com>

* disassemble without capstone to support other architectures

* ignore gdb.error on context_backtrace
2022-08-30 20:45:28 +02:00
Gulshan Singh 340dd2d43b
Minor linter/formatter configuration changes (#1105)
* Don't format gdb-pt-dump with black

* Move isort configuration into pyproject.toml

* Exclude gdb-pt-dump from flake8

* Set flake8 max line length to 100
2022-08-30 20:45:10 +02:00