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

Can't attach to gdb on ArchWSL(WSL2). #2464

Closed
Xunflash opened this issue Sep 25, 2024 · 3 comments · Fixed by #2470
Closed

Can't attach to gdb on ArchWSL(WSL2). #2464

Xunflash opened this issue Sep 25, 2024 · 3 comments · Fixed by #2470
Labels

Comments

@Xunflash
Copy link

I can't attach to gdb, details on the outputs below:

from pwn import *
context.log_level='debug'
# context.terminal=['cmd.exe', '/c', 'start', 'wsl.exe', '--', 'sudo', 'su', '-c'] #use this line can attach to su gdb
sh = process("./challenge")
gdb.attach(sh)

and I get the following output

image

I searched the error (ptrace: Operation not permitted.) on google and I found the following wiki:
https://github.com/Microsoft/MIEngine/wiki/Troubleshoot-attaching-to-processes-using-GDB

so I exeuted the second option's command because my wsl don't support yama (it shows "no such file or directory.")

sudo setcap cap_sys_ptrace=eip /usr/bin/gdb

But still not working.

@peace-maker
Copy link
Member

I can't attach to gdb, details on the outputs below:

from pwn import *
context.log_level='debug'
# context.terminal=['cmd.exe', '/c', 'start', 'wsl.exe', '--', 'sudo', 'su', '-c'] #use this line can attach to su gdb
sh = process("./challenge")
gdb.attach(sh)

If this is your whole script, the problem is that your exploit script terminates and takes the target process with it before gdb has a chance to attach. Usually adding a p.interactive() call at the end helps. Try adding a pause() call after your gdb.attach or use gdb.debug instead to avoid race conditions.

A different issue appears to be the wait_for_debugger helper failing for you.

[-] Waiting for debugger: debugger exited!

That should block execution in your exploit script until the debugger is actually attached. If you manage to fix it, please open a pull request!

def wait_for_debugger(pid, debugger_pid=None):

@peace-maker peace-maker linked a pull request Sep 26, 2024 that will close this issue
@Xunflash
Copy link
Author

Xunflash commented Sep 27, 2024

If this is your whole script

Actually it's not the whole script. I omitted some code.

A different issue appears to be the wait_for_debugger helper failing for you.

[-] Waiting for debugger: debugger exited!

That should block execution in your exploit script

I think here is the key point.(This may be caused by the ptrace error) Actually I need to add a "-- sudo" to the context.terminal so that I can temporarily attach to the gdb. But this means I need to prefix each script with context.terminal.
I think it maybe a issue that associated with WSL.

@RocketMaDev
Copy link

@Xunflash Dude, I does not recommend using Arch Linux in WSL2 as neither Microsoft nor Arch has official support for Arch/WSL2. I have a friend who used Arch/WSL2 first, and praised how convenient yay is. But some infrustructure like systemd couldn't behave like real Arch Linux. So he ended up using back Ubuntu/WSL2.

In my opinion, Ubuntu is suitable for WSL2 and Arch Linux is suitable for physical system. If you would like to try Arch Linux, I only suggest Dual boot with Windows, and separate them in different disks to avoid efi corrupt if you have two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants