-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix issues related with debugging #1323
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this seems to be a nice change.
There are two minor drawbacks I addressed, but generally it is fine. Also it would be perfect if you added doctests for the new changes.
Co-Authored-By: Arusekk <arek_koz@o2.pl>
@Arusekk It seems that there are no doctests in |
There is never anything wrong with adding tests to an untested piece of code 😉 The reason was so far that it was hard to automatically test debugging without having a display on the testing machine. (gdb.debug() results in starting another terminal by default) |
How can we test remote debugging? The vps provided in the comment ( pwnable.kr ) can't be used, I think they may add some restrictions. |
Fortunately, the CI setup creates a virtual host |
I'm trying to add doctests to I have some questions about it:
|
Yes, this looks perfectly fine, although a separate script for each file seems not very great. As for the path, you can use a path stored on the module (e.g. Also, it could be useful to generate the fake terminal files on-the-fly, maybe using some utility function and tempfiles (the best option in my opinion). You mentioned before something of deduplicating the code for validating argv and env. This is also a great idea, and the validation takes place (AFAICT) in @zachriggle what do you think of that? |
Hey @bet4it, I pulled your debug branch and noticed that this issue still crops up when gdb.attach() is invoked to attach to a local process.
in GDB
After hacking together a solution to remove the offending |
I have added doctests for most functions in Now I only need one fake terminal file for all the situations. To solve the bug mentioned by @skywardgaze, I remove all the 'file' statement in gdb script. I think we should always load the symbols of executable in the argument of gdb command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not responding, I have been quite busy lately. I have some questions about the code you added.
@@ -45,6 +48,7 @@ before_script: | |||
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print(pwnlib.term.term_mode)' | |||
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print(pwnlib.term.term_mode)' | |||
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print(pwnlib.term.term_mode)' | |||
- sudo sh -c "echo 0 > /proc/sys/kernel/yama/ptrace_scope" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary, as we do some prctl() in pwntools to mitigate this already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's necessary. prctl()
only affects direct child process.
You can try this by yourself:
Lines 587 to 597 in 0491972
# Start a forking server | |
server = process(['socat', 'tcp-listen:1234,fork,reuseaddr', 'exec:/bin/sh']) | |
# Connect to the server | |
io = remote('localhost', 1234) | |
# Connect the debugger to the server-spawned process | |
gdb.attach(io, ''' | |
break exit | |
continue | |
''') |
The
attach
should fail if ptrace_scope
is not set to 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, the process is created by socat
, not us. This is bad, because pwntools users won't be able to do this either without disabling Yama.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most users won't use pwntools in this way, so it's okey to leave this problem here😃
Conflicts: pwnlib/gdb.py
@@ -209,6 +209,7 @@ def cyclic_find(subseq, alphabet = None, n = None): | |||
|
|||
if isinstance(subseq, six.integer_types): | |||
subseq = packing.pack(subseq, bytes=n) | |||
subseq = context._encode(subseq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks python 3 build. What is your usecase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope cyclic_find
can also accept a str likes cyclic_find('baaacaaa')
besides of cyclic_find(b'baaacaaa')
in Python 3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be done somehow differently. _encode
enforces bytes, while we need the type that is used in the alphabet. The internal library usage does not use str
with binary alphabets, nor does it use bytes
with text alphabets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can unify subseq
and alphabet
to bytes
. Add a commit to fix the build.
os.environ
whenenv
is not set, and when remote debugging this will lead to a confusion.file
the local executable when remote debugging,gdb
will download it automatically byexec-file
related commands.After this pulll request, some tests like
pwntools/pwnlib/gdb.py
Lines 387 to 402 in 544ae93
pwntools/pwnlib/gdb.py
Lines 596 to 608 in 544ae93
pwntools/pwnlib/gdb.py
Lines 858 to 864 in 544ae93
can work (on my vps).
I think this pull request also solves #1314.