윈도우 퍼징 공부를 하면서 정리했던 WinAFL 사용법이랑 타겟 잡는 법을 설명 해볼까 한다.
주요 타겟
- Viewer 프로그램
- Zip 압축 관련 프로그램
파일 파싱을 하는 소프트웨어가 버그가 많음. Logical Bug나 Memory Corruption 등등..
1. WinAFL 설치
- Hyper -v Windows 10 x64 에서 진행
- python3
- visual studio 2022
- DynamoRIO
적절 한 경로에 DynamoRIO 압축 해제
C:\ 경로에 다음과 같이 설치
git clone https://github.com/googleprojectzero/winafl
cd winafl
git submodule update --init --recursive
32bit build
- 32bit는 2022로 하니까 에러가 떠서 2019로 대체함
- Developer Command Prompt for VS 2019 열기
mkdir build32
cd build32
cmake -G"Visual Studio 16 2019" -A x86 .. -DDynamoRIO_DIR=[DynamoRIO 경로]\cmake
cmake --build . --config Release
64bit build
- x64 Native Tools Command Prompt for VS 2022 열기
mkdir build64
cd build64
cmake -G"Visual Studio 17 2022" -A x64 .. -DDynamoRIO_DIR=[DynamoRIO 경로]\cmake
cmake --build . --config Release
이렇게 하면 빌드가 잘 된것!
2. 타겟 선정
- user input을 집어넣을 수 있는 뷰어, 압축 프로그램, 미디어 플레이어 등
- procmon을 통해 user input 입력 했을 때의 동작을 분석하면 좋다
- operation : Load Library, ReadFile 등
- 여러 쓰레드에서 동작 가능
- 플러그인 dll에서 file open, parsing, file close 작업 전부 이루어질 경우
→ DLL 하네스 작성 후 퍼징- 한 함수에서 open, parse, close 전부 이루어지면 그 함수만 GetProcAddress
- 별개의 함수에서 이루어지면 전부 GetProcAddress로 가져온 후 fp만 전달
- exe에서 file open, parsing, file close 작업 전부 이루어질 경우
→ exe 파싱 루틴 부분만 하네스 작성 후 퍼징- 난이도 더 높음, 하네스 작성 힘듬
- target offset fuzzing 방법
이렇게 WinAFL은 다 설정이 되어 있는 걸 전제로 Fuzzing Exercise 101에 나오는 CVE-2016-2334 7zip을 퍼징 해보자.
이건 7zip 15.05 버전 을 IDA로 열어 본 것이다. x86 버전으로, 샘플 데이터도 github에서 다운 받아주었다.
https://github.com/antonio-morales/Fuzzing101/tree/main/Exercise%209
Fuzzing101/Exercise 9 at main · antonio-morales/Fuzzing101
An step by step fuzzing tutorial. A GitHub Security Lab initiative - antonio-morales/Fuzzing101
github.com
3. WinAFL 명령어
WinAFL은 그냥 AFL과는 다르게 추가 옵션이 존재
- coverage_module : 커버리지를 기록할 모듈을 명시 → 여러개 가능
- target_module : 퍼징할 함수 지정
- target_offset : 퍼징할 메소드의 시작 주소로부터의 오프셋 주소
함수의 베이스 주소가 0x400000 이므로 0x42F3B3 - 0x400000 = 0x02F3B3이 target_offset 인자가 된다.
이 주소가 맞는지 DynamoRIO에서 확인 해보자.
C:\DynamoRIO-Windows-11.90.20168\bin32\drrun.exe -c winafl.dll -debug -target_module 7z.exe -target_offset 0x02F3B3 -fuzz_iterations 10 -nargs 2 -- "C:\Program Files (x86)\7-Zip\7z.exe" l C:\Users\lee\Downloads\example.img
이런식으로 목적한 함수가 10회 실행되고 종료된다. 이제 직접 퍼징을 돌려보자.
관리자로 cmd를 연 뒤 afl-fuzz.exe가 있는 winafl/build32/bin/Release로 가서 다음 명령어를 입력하면 된다.
afl-fuzz.exe -i C:\afl_in -o C:\afl_out -t 2000 -D C:\DynamoRIO-Windows-11.90.20168\bin32 -- -coverage_module 7z.exe -coverage_module 72.dll -target_module 7z.exe -target_offset 0x02F3B3 -nargs 2 -- "C:\Program Files (x86)\7-Zip\7z.exe" e -y @@
이렇게 퍼징이 돌아간다. 크래시를 찾으려면 더 확실한 타겟 함수나 조건에 맞는 부분을 찾아서 타겟으로 잡아주는 것이 중요하다.
'<Windows> > Windows Exploit' 카테고리의 다른 글
[Windows Exploit] Stack BOF (corelen tutorial) (0) | 2025.04.06 |
---|