Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pwndbg.gdblib.arch.current is wrong if executed in a pwntools gdbscript command #1189

Closed
disconnect3d opened this issue Oct 2, 2022 · 0 comments
Labels
Milestone

Comments

@disconnect3d
Copy link
Member

disconnect3d commented Oct 2, 2022

TL;DR: This should not fail, but does so, because the patch command fetches pwndbg.gdblib.arch.current which for some reason is wrong/not updated.

from pwn import *

gdbscript = '''
tbreak main
patch $rip 'xor rax, rax'
continue
'''

p = gdb.debug('/bin/ls', gdbscript=gdbscript)

p.interactive()

Stacktrace:

Traceback (most recent call last):
  File "/home/dc/tools/pwndbg/pwndbg/commands/__init__.py", line 145, in __call__
    return self.function(*args, **kwargs)
  File "/home/dc/tools/pwndbg/pwndbg/commands/__init__.py", line 216, in _OnlyWhenRunning
    return function(*a, **kw)
  File "/home/dc/tools/pwndbg/pwndbg/commands/patch.py", line 25, in patch
    new_mem = asm(ins, arch=pwndbg.gdblib.arch.current)
  File "/home/dc/.virtualenvs/pwn/lib/python3.8/site-packages/pwnlib/context/__init__.py", line 1444, in setter
    raise AttributeError("Invalid arch/bits combination: %s/%s" % (arch, bits))
AttributeError: Invalid arch/bits combination: i386/64

If that is an issue, you can report it on https://github.com/pwndbg/pwndbg/issues
(Please don't forget to search if it hasn't been reported before)
To generate the report and open a browser, you may run `bugreport --run-browser`
PS: Pull requests are welcome
> /home/dc/.virtualenvs/pwn/lib/python3.8/site-packages/pwnlib/context/__init__.py(1444)setter()
-> raise AttributeError("Invalid arch/bits combination: %s/%s" % (arch, bits))
(Pdb) p arch, bits
('i386', 64)
(Pdb) 
@disconnect3d disconnect3d added this to the Sprint 1 milestone Oct 3, 2022
disconnect3d added a commit that referenced this issue Oct 11, 2022
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 9e84c18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant