Commit Graph

1280 Commits

Author SHA1 Message Date
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
disconnect3d cf2c3eede8 bump version 2022-08-30 04:39:27 +02:00
Disconnect3d d4850beecc
fix #1098: dX cmds trunc out on x86 binaries (#1104)
* fix #1098: dX cmds trunc out on x86 binaries

* fix black
2022-08-30 04:06:41 +02:00
Gulshan Singh 1df714d700
Fix PEP8 violations and add flake8 to CI (#1102)
* Add flake8 config to setup.cfg

* Fix W291 PEP8 warnings

* Fix W605 PEP8 warnings

* Fix E711 PEP8 error

* Fix E713 PEP8 errors

* Fix E262 PEP8 errors

* Fix E714 PEP8 error

* Fix E712 PEP8 errors

* Add flake8 to CI
2022-08-30 03:19:30 +02:00
Disconnect3d b3a560eff0
black all da code (#1103) 2022-08-30 02:53:00 +02:00
Gulshan Singh d8b589d823
Add black to CI (#1101)
* Add black to CI

* Rename linter step
2022-08-30 02:34:34 +02:00
disconnect3d 015888684b Fix test_vis_heap_chunk_command on Ubuntu 18.04 2022-08-30 02:20:09 +02:00
disconnect3d 697c32e84b Move pytest to dev-requirements 2022-08-28 23:12:00 +02:00
Gulshan Singh 2bde0cc1d8
Update CI to test 18.04, 20.04, and 22.04 (#1100)
* Fix requirements.txt for Python 3.6

* Install coverage from setup-test-tools.sh

* Update CI to test Ubuntu 18.04, 20.04, and 22.04
2022-08-28 23:11:16 +02:00
Gulshan Singh 7c53bdeaa8
Minor test cleanup (#1099)
* Silence nonnull warning when building heap_vis.c

* Fix checking ptrace_scope in test_attachp.py

* Fix .gitignore

* tests.sh cleanup

* Fixed coverage generation
2022-08-25 16:57:16 +02:00
NT Sleep 5d358585b1
Add support for telescope to show previous addresses #1047 (#1094)
* Added -r argument to telescope command (#1047)

* Added tests for telescope command (#1047)
2022-08-24 00:31:20 +02:00
Disconnect3d 890e314f2f
tests.sh: add [filter] and --pdb (#1092) 2022-08-24 00:05:57 +02:00
alufers c0b3f88f53
Fix zig not being installed when installed system-wide (#1093) 2022-08-24 00:05:43 +02:00
Disconnect3d e8109b98c1
Remove QuietSloppyParsedCommand once and for all (#1091)
This commit cleans up the commands/__init__.py a bit by removing the
`QuietSloppyParsedCommand` that we do not use anymore.

The last command that used it was `brva` which was just an alias for
`breakrva`, so now we just set it as an alias using the
`ArgparsedCommand` as it should be done.
2022-08-23 23:06:39 +02:00
Artur Czepiel 4ee225b115
Make ZIGPATH configurable and provide defaults (#1090)
* Make ZIGPATH configurable and provide defaults

Mostly fixes docker/docker-compose environment where building zig into
$pwd/.zig doesn't work well because it is later overwritten by mounting
the volume in /pwndbg.

With current approach during the docker build zig is put in /opt/zig
instead, and when you run it without docker it's possible to configure a
different path (with sane defaults)

* remove Makefile

* add ZIGPATH to tests.sh for CI

* move ZIGPATH setting before make in tests
2022-08-23 23:02:12 +02:00
alufers 36ee7d238d
tools: change zig to install from a tarball (fixes: #1085) (#1089)
* tools: change zig to install from a tarball

Migrate from using snap, we install from a cheksumed tarball

* fix: add sudo

* fix: install zig to .zig in PWD

Co-authored-by: Albert Koczy <albert.koczy@asseco.pl>
2022-08-23 21:43:17 +02:00
Disconnect3d d111c8ddcf
Fix heap test binaries build (#1087)
* Fix heap test binaries build

* Compile some heap test binaries with zig cc
2022-08-23 03:53:51 +02:00
Disconnect3d 546d6ffa19
fix vis_heap_chunk test on CI? (#1086)
* fix vis_heap_chunk test on CI?

* add libc6-dev for tests/CI for vis_heap_chunk test

* fix heap_vis.out build
2022-08-23 02:48:27 +02:00
disconnect3d 902d732816 add vis_heap_chunk testcase 2022-08-23 01:55:50 +02:00
Disconnect3d b51b07de77
Revert "Refactor heap code (#1063)" (#1084)
This reverts commit a0f3744743.
2022-08-22 22:38:05 +02:00
Gulshan Singh a0f3744743
Refactor heap code (#1063)
* Add Bins classes and refactor allocator methods to return them

* Refactor bins() and related commands

* Refactor malloc_chunk

* Use chunk_size_nomask in top_chunk()

* Refactor vis_heap_chunks

* Rename read_chunk to read_chunk_from_gdb and move to ptmalloc.py

* Add get_first_chunk_in_heap and use it in heap and vis_heap_chunks commands

* Move some methods from DebugSymsHeap to Heap base class

* Strip type hints from heap.py and ptmalloc.py

* Set heap_region before using it

* Fix test_heap_bins test

* Fix try_free
2022-08-22 14:39:55 +02:00
Gulshan Singh 8cb3d807c5
Fix test runner script for parallel make builds (#1083) 2022-08-22 14:37:46 +02:00
disconnect3d e7b4515e46 fix vmmap for qemu user targets 2022-08-20 23:38:02 +02:00
Arusekk 023a1c19b7
Avoid bare catch-all except blocks (#1080)
This was done with:

    grep -rl 'except:' | xargs sed -i 's/except:/except Exception:/'

Not tested, but I believe this could be useful.
2022-08-20 23:22:43 +02:00
Disconnect3d c10c8f840b
Fix coredump debugging (#1079)
* Fix coredump debugging

This commit fixes our headaches with core files debugging.

The TL;DR is that we will now try to parse `info proc mappings` and
`maintenance info sections` to give users best possible UX/vmmaps
information.

Related:
* https://sourceware.org/bugzilla/show_bug.cgi?id=29508
* https://github.com/pwndbg/pwndbg/issues/985
* https://github.com/pwndbg/pwndbg/issues/954

* cleanup

* cleanup

* Fix core dbg when EHDR map is not mapped
2022-08-20 22:35:45 +02:00