Compiling/Debugging Apache

 Date: November 1, 2021

This blogpost covers compiling & debugging Apache. It is not suggesting to replace the existing documentation, but rather give a practical examples and other useful tips if you’re interested in starting a small lab for analysis/research purposes.

Download

You can use git, svn, or just use one of the Apache httpd mirror sites: http://archive.apache.org/dist/httpd/

APR Utils

Before starting the building process, you’ll need APR (Apache Portable Runtime)

https://publib.boulder.ibm.com/httpserv/manual24/install.html

Make sure you have APR and APR-Util already installed on your system. If you don’t, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into /httpd_source_tree_root/srclib/apr and /httpd_source_tree_root/srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under /httpd_source_tree_root/srclib/apr/) and use ./configure’s –with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util

You can get APR and APR-Utils from here: https://apr.apache.org/download.cgi

Compiling

If you want to start a build with debug symbols / common modules, use the following options when running ./configure:

./configure --enable-maintainer-mode \
--enable-debugger-mode \
--with-mpm=prefork

We’re use the prefork MPM since this MPM uses multiple child processes with one thread each and each process handles one connection at a time. This will be useful for debugging as we’ll see soon.

After the configure command is done, just compile it with make & go grab a coffee because that’s gonna take awhile.

Debugging

By its nature, Apache spawns new processes when incoming requests arrives. This can be very painful to do analysis/debug stuff because every time a new process starts, the debugger will switch contexts & your breakpoints might not hit. To overcome that, run the httpd binary with an -X argument:

  -X     : debug mode (only one worker, do not detach)

You can also add to the httpd.conf the following line, to ensure Apache will proccess just one request at a time:

MaxClients 1

Other Useful Reading

 Tags:  apache debug dev-env

Previous
⏪ Hacking Apache servers like it's 2004 (CVE-2021-41773)

Next
Fuzzing with AFL | Part 1: Trying Harder(Redis) ⏩