To debug mod_mshield the following tools are a good collection to start the challenge. Make sure you have installed them on your system if you follow these instructions.
apt-get update
apt-get install -y gdb valgrind apache2-dbg libapr1-dbg libaprutil1-dbg binutils linux-toolsView the mod_mshield logs you could use tail -f. Change the log file path depending on your setup.
tail -f /opt/applic/httpd/logs/*error_logTo trace the performance of mod_mshield or apache in general, the tool perf does a quite good job.
Start the apache server with the -X option to run it in debugging mode where only a single worker is started.
/usr/sbin/apachectl -DFOREGROUND -k start -e debug -XIn another terminal start perf using the options shown or add/replace some options depending on your needs.
perf record -F 100 -p <PID>Another possibility is to run perf so it traces the function call graphs:
perf record -a --call-graph dwarf -p <PID-of-apache2-process>If perf failed because of kernel restrictions, allow is by issuing the following command:
echo 0 > /proc/sys/kernel/kptr_restrictNow you can access the website the manual way or run the load tests provided by MarkovShield. To run the load tests have a look at the markovshield_benchmark repository.
To view the perf results hit perf report to use the interactive reporting tool from perf.
To debug a segmentation fault follow the steps shown here to have a good chance to detect the faulty spot in the code:
# Source the apache environment variables
source /etc/apache2/envvars
# Run gdb with the command apache2
gdb apache2
# You should now be inside the gdb console.
# Set a break point to the function in which you think the segmentation fault could be triggered
b mshield_access_checker
# Now run the apache2 command with the -X option to run it with a single worker.
run -XListen on topic (e.g. MarkovClicks):
kafkacat -C -b 192.168.56.50 -t MarkovClicksecho $'xtTALCofbVIMEmuJzd95Me0prdFNKt%{"sessionUUID": "xtTALCofbVIMEmuJzd95Me0prdFNKt","clickUUID": "zugbwerz23g8gzbhb","timeStamp": 1493639064719,"url": "/private/request-header/","urlRiskLevel": 4,"validationRequired": true}' | kafka-console-producer.sh \
--broker-list localhost:9092 \
--topic MarkovClicks \
--property parse.key=true \
--property key.separator=%kafka-consumer-groups.sh --list --bootstrap-server localhost:9092redis-cli psubscribe W*Publish engine result (e.g. FRAUD) to channel zugbwerz23g8gzbhb :
redis-cli publish zugbwerz23g8gzbhb FRAUDHint: The clickUUID is used as channel ID.
If you want to debug mod_mshield inside a docker container have a look at the files in the dev-docker-image directory.
First you need the MarkovShield demo application running in the background. Please follow the steps from Getting started to achive this. In additon to that you need to stop the existing mshielddemo_mshield_reverse_proxy_1 container by hitting the command docker stop mshielddemo_mshield_reverse_proxy_1.
To create the mod_mshield docker container follow the steps shown down here:
- Backup the regular
Dockerfileinsideexamplesite/reverseproxybe renaming it to something likeDockerfile_orig. - Copy all files from
dev-docker-imagetoexamplesite/reverseproxy. - Build the docker debug container using the
build_it.shscript. - Finally run the
mod_mshielddebug container inside the existingmake demodocker-compose network by runningrun_it.sh.