WSL
2026/5/29工具通用工具工具通用工具WSLWindows大约 3 分钟
WSL
是什么
WSL 是 Windows Subsystem for Linux,让 Windows 用户可以直接运行 Linux 环境。
CTF 学习中,WSL 适合:
- 运行 Linux 命令和脚本
- 安装 Python、pwntools、binwalk、foremost 等工具
- 编译和调试 Linux 题目
- 管理题解和知识库
安装与配置
Windows 10/11 推荐使用:
wsl --install安装 Ubuntu:
wsl --install -d Ubuntu查看发行版:
wsl -l -v进入 WSL 后更新:
sudo apt update
sudo apt upgrade基本用法
打开当前目录
PowerShell 中:
wslWSL 中访问 Windows 磁盘:
cd /mnt/c/Users安装基础工具
sudo apt install git curl wget python3 python3-pip build-essential gdb file和 VS Code 配合
安装 VS Code 的 WSL 扩展后,在 WSL 目录运行:
code .更多配置
安装多个发行版
# 查看可用发行版
wsl --list --online
# 安装特定发行版
wsl --install -d Ubuntu-22.04
wsl --install -d Kali-linux
wsl --install -d Debian设置默认发行版
wsl --set-default Ubuntu-22.04切换 WSL 版本
# WSL 1 到 WSL 2
wsl --set-version Ubuntu 2
# 查看版本
wsl -l -v配置 WSL 内存
创建 C:\Users\<user>\.wslconfig:
[wsl2]
memory=8GB
processors=4
swap=2GB重启 WSL:
wsl --shutdown配置 DNS
编辑 /etc/resolv.conf:
sudo rm /etc/resolv.conf
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
sudo chattr +i /etc/resolv.conf配置镜像源
编辑 /etc/apt/sources.list:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sudo apt update网络配置
WSL 访问 Windows 服务
# Windows 主机 IP
cat /etc/resolv.conf | grep nameserver
# 访问 Windows 上的服务
curl http://<windows-ip>:<port>Windows 访问 WSL 服务
# WSL 中启动服务
python3 -m http.server 8000
# Windows 浏览器访问
# http://localhost:8000端口转发
# 查看端口转发
netsh interface portproxy show v4tov4
# 添加端口转发
netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=<wsl-ip>WSL IP 地址
# 查看 WSL IP
ip addr show eth0
# 查看 Windows 主机 IP
cat /etc/resolv.conf文件共享
Windows 访问 WSL 文件
文件资源管理器地址栏输入:
\\wsl$\Ubuntu\home\<username>WSL 访问 Windows 文件
# Windows 磁盘挂载在 /mnt
cd /mnt/c/Users/<username>
cd /mnt/d/文件权限问题
# 在 /etc/wsl.conf 中配置
[automount]
enabled = true
options = "metadata,umask=22,fmask=11"复制文件
# WSL 到 Windows
cp /path/to/file /mnt/c/Users/<username>/Desktop/
# Windows 到 WSL
cp /mnt/c/Users/<username>/Desktop/file /home/<username>/CTF常用技巧
建议把题目放在 Linux 文件系统
性能更好:
mkdir -p ~/ctf
cd ~/ctf不要长期在 /mnt/c/... 里跑大量 Linux 编译和扫描。
Windows 工具和 WSL 分工
Windows: Burp、IDA、x64dbg、浏览器
WSL: Python、pwntools、GDB、binwalk、file、foremost端口互通
WSL 起的 Web 服务通常可以在 Windows 浏览器访问 localhost:端口。
安装 CTF 工具集
# Python 环境
sudo apt install python3 python3-pip python3-venv
# 编译工具
sudo apt install build-essential gcc g++ nasm
# 调试工具
sudo apt install gdb gdbserver
# 二进制分析
sudo apt install binutils file strings
# 网络工具
sudo apt install nmap netcat-openbsd curl wget
# Pwn 工具
pip3 install pwntools
# Web 工具
pip3 install requests beautifulsoup4使用 systemd(WSL 2)
编辑 /etc/wsl.conf:
[boot]
systemd=true重启 WSL:
wsl --shutdownDocker Desktop 集成
# 在 Docker Desktop 设置中启用 WSL 2 集成
# Settings -> Resources -> WSL Integration常见问题
wsl 命令不存在
检查 Windows 版本和系统组件,或从 Microsoft Store 安装 WSL。
apt 下载慢
可以换软件源,但公开文档中建议先使用默认源,减少环境差异。
pwntools 安装失败
先装编译依赖:
sudo apt install python3-dev libssl-dev libffi-dev build-essential内存不足
1. 编辑 .wslconfig 限制内存
2. 关闭不用的 WSL 发行版
3. wsl --shutdown 释放资源网络不通
1. 检查 DNS 配置
2. 重启 WSL: wsl --shutdown
3. 检查 Windows 防火墙
4. 重置网络: wsl --shutdown && netsh winsock reset文件权限问题
1. 编辑 /etc/wsl.conf 配置 metadata
2. wsl --shutdown 重启
3. 使用 chmod 设置权限关联
- Python环境
- Docker
- Git
- GDB+pwndbg
- pwntools