Research/fuzzing101

[Fuzzing101] AFL++로 libexif 퍼징하기 (1) (타겟 다운로드, 퍼징)

jir4vvit 2022. 2. 27. 21:26
출처 : https://github.com/antonio-morales/Fuzzing101

한 3주전에 노션으로 정리해놨었는데,, 기술과제하고 등 할 게 좀 많았어서 업로드를 못하고 있었다. 8ㅅ8

이거 하면서 굉장히 삽질을 했었는데,,,, 그 삽질을 글로 최대한 녹여내보는 것이 목표

 

AFL++로 libexif 퍼징하기

  • 타겟 : libexif 0.6.14 EXIF 파싱 라이브러리
  • 목표 : CVE-2009-3895 and CVE-2012-2836
  • 환경 : ubuntu-20.04.3 x86-64
  1. Find an interface application that makes use of the libexif library
  2. Create a seed corpus of exif samples
  3. Compile libexif and the chosen application to be fuzzed using afl-clang-lto
  4. Fuzz libexif until you have a few unique crashes
  5. Triage the crashes to find a PoC for each vulnerability
  6. Fix the issues

libexif를 사용하는 인터페이스 앱 찾기

타겟 다운로드 https://github.com/libexif/libexif/releases/tag/libexif-0_6_14-release

libexif-libexif-0_6_14-release.tar.gz

tar -xzvf libexif-libexif-0_6_14-release.tar.gz

libexif를 사용하는 오픈소스 찾기

https://github.com/libexif

glibxif는 gui app이라 퍼징하기에 적절하지 않음

exif으로 결정

git clone <https://github.com/libexif/exif.git>

exif 빌드 방법

BUILDING
--------

Assuming libexif and popt are installed, building exif from the source
tar ball should be a simple matter of:

  ./configure
  make
  sudo make install

If your libexif is installed in a non-standard location, you must point
configure at the location of its libexif.pc file using the pkg-config
path, like this:

  ./configure PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

When building from git, run this before configuring:

  autoreconf -i

libexif 설치 후 exif 빌드를 하자.

libexif 빌드 방법

BUILDING
--------

It really depends on your environment what to do in order to get libexif
to build. Building from the source tar ball usually involves the commands:

  ./configure
  make
  sudo make install

When building from source out of git, something like the following will be
necessary:

  autoreconf -i
  ./configure
  make

autoreconf 명령을 실행하다가 에러 뜸...

참고

sudo apt install autopoint
sudo apt install gettext

또 다른 에러 뜸

참고

sudo apt install libtool

libexif 빌드

autoreconf -i
./configure --prefix="$HOME/fuzzing_libexif/install/"
make
sudo make install

exif 빌드

PKG_CONFIG_PATH 를 설정을 해줘야한다.. 이게 뭐징 ㅇㅅㅇ.....

help 쳐서 확인해봄

아 빌드 방법에 명시되어 있구나

If your libexif is installed in a non-standard location, you must point
configure at the location of its libexif.pc file using the pkg-config
path, like this:

  ./configure PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

popt이란 것도 필요하다고 해서 급하게 설치,,

역시 호락호락하지 않다..(?)

sudo apt install libpopt-dev

 

다시 exif 빌드

autoreconf -i
./configure --prefix="$HOME/fuzzing_libexif/install/" PKG_CONFIG_PATH=$HOME/fuzzing_libexif/install/lib/pkgconfig
make
sudo make install

ㅠㅠ

libexif 라이브러리를 인식을 하지 못한다. 분명 configuration에는 yes로 되어있는데 ㅠㅠ

그래서 이게 아닌가 싶어서 스포 봤는데 버전을 더 내려야 한다. (이 버전은 어캐아는거지..)

 

찐 exif 빌드 ...

버전 0.6.15로 진행 ㅎㅎ;

실행이 잘 되는 것을 확인!

 

exif 샘플의 seed corpus 생성

corpus = fuzzing에 이용되는 sample

 

구글링해서 샘플파일 찾아서 wget으로 다운받았다.

위 : 스포보고 다운로드 / 아래 : 내가 다운로드

킹받는다.

계속 안되서 삽질하다가 스포봤는데 똑같은 파일인거같은데 ㅋ......

저때 내가 wget 명령어를 뭐라고 쳤을까? ,,,  ,왜 안됐던 것일까... 

cd $HOME/fuzzing_libexif
wget https://github.com/ianare/exif-samples/archive/refs/heads/master.zip
unzip master.zip

$HOME/fuzzing_libexif/install/bin/exif $HOME/fuzzing_libexif/exif-samples-master/jpg/Canon_40D_photoshop_import.jpg

일단 스포 투척하고 그 다음으로 넘어갑시다..

 

afl-clang-lto를 사용하여 libexif와 퍼징할 앱을 컴파일

afl-clang-lto를 쓰는 이유 : instrumentation을 측정?할 때 충돌이 덜하다고 한다..

https://github.com/AFLplusplus/AFLplusplus/blob/stable/instrumentation/README.lto.md#afl-clang-lto---collision-free-instrumentation-at-link-time

 

GitHub - AFLplusplus/AFLplusplus: The fuzzer afl++ is afl with community patches, qemu 5.1 upgrade, collision-free coverage, enh

The fuzzer afl++ is afl with community patches, qemu 5.1 upgrade, collision-free coverage, enhanced laf-intel & redqueen, AFLfast++ power schedules, MOpt mutators, unicorn_mode, and a lot more!...

github.com

 

아무튼 여기서 삽질(?)을 굉장히 많이 했었는데...........

결론만 말하면 내가 ALF++을 뭔가 덜 설치(?)해서 afl-clang-lto가 없었다 ㅇㅅㅇ.

그래서 alf++를 다시 설치했다.

참고 

 

afl-clang-lto로 재컴파일

rm -r $HOME/fuzzing_libexif/install
cd $HOME/fuzzing_libexif/libexif-libexif-0_6_14-release/
make clean
export LLVM_CONFIG="llvm-config-11"
CC=afl-clang-lto 
CFLAGS="-fsanitize=address"
./configure --enable-shared=no --prefix="$HOME/fuzzing_libexif/install/"
make
make install

cd $HOME/fuzzing_libexif/exif-exif-0_6_15-release
make clean
export LLVM_CONFIG="llvm-config-11"
CC=afl-clang-lto 
CFLAGS="-fsanitize=address"
./configure --enable-shared=no --prefix="$HOME/fuzzing_libexif/install/" PKG_CONFIG_PATH=$HOME/fuzzing_libexif/install/lib/pkgconfig
make
make install

Let's libexif 퍼징~

afl-fuzz -i $HOME/fuzzing_libexif/exif-samples-master/jpg/ -o $HOME/fuzzing_libexif/out/ -s 123 -- $HOME/fuzzing_libexif/install/bin/exif @@

크래시 분석한 내용은 다음 게시글에서 소개 8ㅅ8

 

'Research > fuzzing101' 카테고리의 다른 글

[Fuzzing101] AFL++로 Xpdf 퍼징하기  (0) 2022.02.05