Ctf
25 Oct 2019

关于wsl中gdb无法attach以及无法运行32位程序的解决方案

How to install

i386 support

sudo apt install qemu-user-static
sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic '\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install cpp:i386
sudo apt install cpp-7:i386
sudo apt install gcc-7:i386
sudo apt install binutils:i38
sudo apt install gcc:i386
sudo apt install lib32ncurses5
sudo apt autoremove

gdb attach settings

sudo vi /etc/sysctl.d/10-ptrace.conf
//set kernel.yama.ptrace_scope to 0
sysctl -p /etc/sysctl.d/10-ptrace.conf

How to set it to auto-start

first in your wsl

sudo vi /etc/init.wsl

//add "
#!/bin/sh
sudo /etc/init.d/binfmt-support start
sudo sysctl -p /etc/sysctl.d/10-ptrace.conf
"

sudo chmod +x /etc/init.wsl
sudo nano /etc/sudoers
//add "%sudo ALL=NOPASSWD: /etc/init.wsl" to the end of file

second in your windows

Win+R, Run "shell:startup"
Create file "startservics.vbs"
add "
Set ws = WScript.CreateObject("WScript.Shell")
ws.run "wsl -d Ubuntu-18.04 -u root '/etc/init.wsl'",0
ws.run "wsl -d Ubuntu-16.04 -u root '/etc/init.wsl'",0
"

Tags:
0 comments