Fuzzing101 Exercise 1 - Xpdf

实验流程

编译xpdf

./configure --prefix="/home/lemon/Documents/AFL/fuzzing_xpdf/xpdf-3.02/install/"
make && make install

下载三个样本:

wget https://github.com/mozilla/pdf.js-sample-files/raw/master/helloworld.pdf
wget http://www.africau.edu/images/default/sample.pdf
wget https://www.melbpc.org.au/wp-content/uploads/2017/10/small-example-pdf-file.pdf

xpdf功能测试:

下面正式开始用AFL进行fuzz,首先进行插桩编译
修改CC和CXX,配置编译选项和安装目录:
image.png
之后使用make && make install进行编译安装

运行afl-fuzz

afl-fuzz -i $HOME/fuzzing_xpdf/pdf_examples/ -o $HOME/fuzzing_xpdf/out/ -s 123 -- $HOME/fuzzing_xpdf/install/bin/pdftotext @@ $HOME/fuzzing_xpdf/output

参数解释:
-i:输入路径
-o:输出路径
-s:fuzzing时随机数使用的种子
—:目标程序
@@:被fuzz的程序从文件读取输入

image.png

运行了一会发现有三个崩溃点
image.png

crash文件
image.png

根据实验要求解决如下问题:

In order to complete this exercise, you need to:

  1. Reproduce the crash with the indicated file
  2. Debug the crash to find the problem
  3. Fix the issue

重现崩溃

以id:000000,sig:11,src:000742,time:643742,execs:237215,op:havoc,rep:3文件为例
将crash文件作为文件输入给pdftotext:
image.png
显示报错,经过后文的调试分析应该是无限递归导致了栈溢出

动态调试

gdb加载程序:
image.png
使用run指令,运行程序
使用bt查看调用回溯,发现在Parser.cc中存在一个无限递归
image.png

定位到源码出,似乎是在这个地方有个递归调用
image.png

漏洞修复

查看4.02版的源码,这个漏洞得到了修复:[xpdf-4.02.tar.gz][https://dl.xpdfreader.com/old/xpdf-4.02.tar.gz]

diff一下:
image.png
发现加了一个recursion变量,并且加了一个recursionLimit宏定义,限制了递归的最大次数
image.png

总结思考

通过lab1,我学到了使用AFL fuzz程序的基本流程,以及简单的AFL工具的基本使用方法。通过AFL提供的crash信息配合gdb可以比较准确的定位到报错点,再定位到源码进行分析。

文章作者: Alex
文章链接: http://example.com/2023/07/07/fuzzing-lab1/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Alex's blog~