WSL2 PWN 환경 설정 가이드

1. 초기 설정

WSL2 및 Ubuntu 설치

# Microsoft Store에서 Ubuntu 22.04 설치 또는
wsl --install Ubuntu-22.04

홈 디렉터리로 이동

cd ~

2. 기본 도구 설치

set.sh 파일 생성

# Kakao 미러 서버로 변경 (빠른 다운로드)
sed -i 's@archive.ubuntu.com@mirror.kakao.com@g' /etc/apt/sources.list
 
# 32bit 아키텍처 추가
dpkg --add-architecture i386
 
# 시스템 업데이트 및 필수 패키지 설치
apt-get update
apt-get install -y netcat sudo git curl wget vim zsh gdb gcc python3 python3-pip \
    python3-dev libssl-dev libffi-dev build-essential tmux binwalk autoconf openssl \
    pkg-config liblzma-dev libgmp3-dev libmpc-dev libcapstone-dev libc6:i386 \
    ruby-full patchelf
apt-get upgrade -y
rm -rf /var/lib/apt/lists/*
 
# Python 패키지 설치
python3 -m pip install --upgrade pip
pip3 install unicorn keystone-engine capstone angr ropgadget
python3 -m pip install --upgrade pwntools
 
# Ruby 도구 설치
gem install one_gadget seccomp-tools

실행

chmod +x ./set.sh
sudo ./set.sh

3. oh-my-zsh 설치

oh-my-zsh 설치

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

4. pwndbg 설치

git clone https://github.com/pwndbg/pwndbg
cd pwndbg
./setup.sh

5. pwntools 설정

~/.pwn.conf 파일 생성

[context]
bits=64
arch="amd64"
log_level="debug"
terminal=['wt.exe', '-w', '0', 'split-pane', '-p', 'Ubuntu 22.04', 'wsl.exe', '-d', 'Ubuntu-22.04']

주의사항:

  • -p: Windows Terminal의 드롭다운에 표시되는 우분투 이름
  • -d: wsl -l 명령에서 확인되는 우분투 이름

6 pwninit 설치

Rust 및 pwninit 설치

# Rust 설치
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
 
# Rust 업데이트
rustup update stable
rustup default stable
 
# pwninit 설치
cargo install pwninit

PATH 환경 변수 설정

vi ~/.zshrc

파일 맨 아래에 추가

export PATH="$PATH:$HOME/.cargo/bin/"
export PATH="$HOME/.local/bin/:$PATH"

변경사항 적용

source ~/.zshrc

템플릿 커스터마이징: https://github.com/io12/pwninit 참조


7. Docker 설치

# 필수 패키지 설치
sudo apt update -y
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
 
# Docker GPG 키 추가
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
 
# Docker 저장소 추가
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" -y
 
# Docker 설치
sudo apt update -y
sudo apt install docker-ce -y
 
# 설치 확인
sudo systemctl status docker

Docker 명령어

sudo systemctl start docker    # 시작
sudo systemctl stop docker     # 종료
sudo systemctl status docker   # 상태 확인

sudo 없이 사용 (선택)

sudo usermod -aG docker [유저명]
# 재부팅 후 적용됨

8. 라이브러리 매칭 문제 해결

pwninit로 생성한 exploit이 라이브러리를 찾지 못할 경우, solve.py에 추가:

import os
 
gdb_script = f"""
set solib-search-path {os.getcwd()}
"""
 
# GDB 연결 시
gdb.attach(p, gdb_script)

9. WSL과 Windows 간 호환성 설정

/etc/wsl.conf 파일 생성 또는 수정

sudo vi /etc/wsl.conf

다음 내용 추가

[interop]
enabled=true
appendWindowsPath=true

CMD에서 wsl 재시작

wsl --shutdown

wsl 실행 후 테스트

wsl
explorer.exe .