1*08b48e0bSAndroid Build Coastguard Worker# Remote monitoring and metrics visualization 2*08b48e0bSAndroid Build Coastguard Worker 3*08b48e0bSAndroid Build Coastguard WorkerAFL++ can send out metrics as StatsD messages. For remote monitoring and 4*08b48e0bSAndroid Build Coastguard Workervisualization of the metrics, you can set up a tool chain. For example, with 5*08b48e0bSAndroid Build Coastguard WorkerPrometheus and Grafana. All tools are free and open source. 6*08b48e0bSAndroid Build Coastguard Worker 7*08b48e0bSAndroid Build Coastguard WorkerThis enables you to create nice and readable dashboards containing all the 8*08b48e0bSAndroid Build Coastguard Workerinformation you need on your fuzzer instances. There is no need to write your 9*08b48e0bSAndroid Build Coastguard Workerown statistics parsing system, deploy and maintain it to all your instances, and 10*08b48e0bSAndroid Build Coastguard Workersync with your graph rendering system. 11*08b48e0bSAndroid Build Coastguard Worker 12*08b48e0bSAndroid Build Coastguard WorkerCompared to the default integrated UI of AFL++, this can help you to visualize 13*08b48e0bSAndroid Build Coastguard Workertrends and the fuzzing state over time. You might be able to see when the 14*08b48e0bSAndroid Build Coastguard Workerfuzzing process has reached a state of no progress and visualize what are the 15*08b48e0bSAndroid Build Coastguard Worker"best strategies" for your targets (according to your own criteria). You can do 16*08b48e0bSAndroid Build Coastguard Workerso without logging into each instance individually. 17*08b48e0bSAndroid Build Coastguard Worker 18*08b48e0bSAndroid Build Coastguard Worker 19*08b48e0bSAndroid Build Coastguard Worker 20*08b48e0bSAndroid Build Coastguard WorkerThis is an example visualization with Grafana. The dashboard can be imported 21*08b48e0bSAndroid Build Coastguard Workerwith [this JSON template](resources/grafana-afl++.json). 22*08b48e0bSAndroid Build Coastguard Worker 23*08b48e0bSAndroid Build Coastguard Worker## AFL++ metrics and StatsD 24*08b48e0bSAndroid Build Coastguard Worker 25*08b48e0bSAndroid Build Coastguard WorkerStatsD allows you to receive and aggregate metrics from a wide range of 26*08b48e0bSAndroid Build Coastguard Workerapplications and retransmit them to a backend of your choice. 27*08b48e0bSAndroid Build Coastguard Worker 28*08b48e0bSAndroid Build Coastguard WorkerFrom AFL++, StatsD can receive the following metrics: 29*08b48e0bSAndroid Build Coastguard Worker- cur_item 30*08b48e0bSAndroid Build Coastguard Worker- cycle_done 31*08b48e0bSAndroid Build Coastguard Worker- cycles_wo_finds 32*08b48e0bSAndroid Build Coastguard Worker- edges_found 33*08b48e0bSAndroid Build Coastguard Worker- execs_done 34*08b48e0bSAndroid Build Coastguard Worker- execs_per_sec 35*08b48e0bSAndroid Build Coastguard Worker- havoc_expansion 36*08b48e0bSAndroid Build Coastguard Worker- max_depth 37*08b48e0bSAndroid Build Coastguard Worker- corpus_favored 38*08b48e0bSAndroid Build Coastguard Worker- corpus_found 39*08b48e0bSAndroid Build Coastguard Worker- corpus_imported 40*08b48e0bSAndroid Build Coastguard Worker- corpus_count 41*08b48e0bSAndroid Build Coastguard Worker- pending_favs 42*08b48e0bSAndroid Build Coastguard Worker- pending_total 43*08b48e0bSAndroid Build Coastguard Worker- slowest_exec_ms 44*08b48e0bSAndroid Build Coastguard Worker- total_crashes 45*08b48e0bSAndroid Build Coastguard Worker- saved_crashes 46*08b48e0bSAndroid Build Coastguard Worker- saved_hangs 47*08b48e0bSAndroid Build Coastguard Worker- var_byte_count 48*08b48e0bSAndroid Build Coastguard Worker- corpus_variable 49*08b48e0bSAndroid Build Coastguard Worker 50*08b48e0bSAndroid Build Coastguard WorkerDepending on your StatsD server, you will be able to monitor, trigger alerts, or 51*08b48e0bSAndroid Build Coastguard Workerperform actions based on these metrics (for example: alert on slow exec/s for a 52*08b48e0bSAndroid Build Coastguard Workernew build, threshold of crashes, time since last crash > X, and so on). 53*08b48e0bSAndroid Build Coastguard Worker 54*08b48e0bSAndroid Build Coastguard Worker## Setting environment variables in AFL++ 55*08b48e0bSAndroid Build Coastguard Worker 56*08b48e0bSAndroid Build Coastguard Worker1. To enable the StatsD metrics collection on your fuzzer instances, set the 57*08b48e0bSAndroid Build Coastguard Worker environment variable `AFL_STATSD=1`. By default, AFL++ will send the metrics 58*08b48e0bSAndroid Build Coastguard Worker over UDP to 127.0.0.1:8125. 59*08b48e0bSAndroid Build Coastguard Worker 60*08b48e0bSAndroid Build Coastguard Worker2. To enable tags for each metric based on their format (banner and 61*08b48e0bSAndroid Build Coastguard Worker afl_version), set the environment variable `AFL_STATSD_TAGS_FLAVOR`. By 62*08b48e0bSAndroid Build Coastguard Worker default, no tags will be added to the metrics. 63*08b48e0bSAndroid Build Coastguard Worker 64*08b48e0bSAndroid Build Coastguard Worker The available values are the following: 65*08b48e0bSAndroid Build Coastguard Worker - `dogstatsd` 66*08b48e0bSAndroid Build Coastguard Worker - `influxdb` 67*08b48e0bSAndroid Build Coastguard Worker - `librato` 68*08b48e0bSAndroid Build Coastguard Worker - `signalfx` 69*08b48e0bSAndroid Build Coastguard Worker 70*08b48e0bSAndroid Build Coastguard Worker For more information on environment variables, see 71*08b48e0bSAndroid Build Coastguard Worker [env_variables.md](env_variables.md). 72*08b48e0bSAndroid Build Coastguard Worker 73*08b48e0bSAndroid Build Coastguard Worker Note: When using multiple fuzzer instances with StatsD it is *strongly* 74*08b48e0bSAndroid Build Coastguard Worker recommended to set up `AFL_STATSD_TAGS_FLAVOR` to match your StatsD server. 75*08b48e0bSAndroid Build Coastguard Worker This will allow you to see individual fuzzer performance, detect bad ones, 76*08b48e0bSAndroid Build Coastguard Worker and see the progress of each strategy. 77*08b48e0bSAndroid Build Coastguard Worker 78*08b48e0bSAndroid Build Coastguard Worker3. Optional: To set the host and port of your StatsD daemon, set 79*08b48e0bSAndroid Build Coastguard Worker `AFL_STATSD_HOST` and `AFL_STATSD_PORT`. The default values are `localhost` 80*08b48e0bSAndroid Build Coastguard Worker and `8125`. 81*08b48e0bSAndroid Build Coastguard Worker 82*08b48e0bSAndroid Build Coastguard Worker## Installing and setting up StatsD, Prometheus, and Grafana 83*08b48e0bSAndroid Build Coastguard Worker 84*08b48e0bSAndroid Build Coastguard WorkerThe easiest way to install and set up the infrastructure is with Docker and 85*08b48e0bSAndroid Build Coastguard WorkerDocker Compose. 86*08b48e0bSAndroid Build Coastguard Worker 87*08b48e0bSAndroid Build Coastguard WorkerDepending on your fuzzing setup and infrastructure, you may not want to run 88*08b48e0bSAndroid Build Coastguard Workerthese applications on your fuzzer instances. This setup may be modified before 89*08b48e0bSAndroid Build Coastguard Workeruse in a production environment; for example, adding passwords, creating volumes 90*08b48e0bSAndroid Build Coastguard Workerfor storage, tweaking the metrics gathering to get host metrics (CPU, RAM, and 91*08b48e0bSAndroid Build Coastguard Workerso on). 92*08b48e0bSAndroid Build Coastguard Worker 93*08b48e0bSAndroid Build Coastguard WorkerFor all your fuzzing instances, only one instance of Prometheus and Grafana is 94*08b48e0bSAndroid Build Coastguard Workerrequired. The 95*08b48e0bSAndroid Build Coastguard Worker[statsd exporter](https://registry.hub.docker.com/r/prom/statsd-exporter) 96*08b48e0bSAndroid Build Coastguard Workerconverts the StatsD metrics to Prometheus. If you are using a provider that 97*08b48e0bSAndroid Build Coastguard Workersupports StatsD directly, you can skip this part of the setup." 98*08b48e0bSAndroid Build Coastguard Worker 99*08b48e0bSAndroid Build Coastguard WorkerYou can create and move the infrastructure files into a directory of your 100*08b48e0bSAndroid Build Coastguard Workerchoice. The directory will store all the required configuration files. 101*08b48e0bSAndroid Build Coastguard Worker 102*08b48e0bSAndroid Build Coastguard WorkerTo install and set up Prometheus and Grafana: 103*08b48e0bSAndroid Build Coastguard Worker 104*08b48e0bSAndroid Build Coastguard Worker1. Install Docker and Docker Compose: 105*08b48e0bSAndroid Build Coastguard Worker 106*08b48e0bSAndroid Build Coastguard Worker ```sh 107*08b48e0bSAndroid Build Coastguard Worker curl -fsSL https://get.docker.com -o get-docker.sh 108*08b48e0bSAndroid Build Coastguard Worker sh get-docker.sh 109*08b48e0bSAndroid Build Coastguard Worker ``` 110*08b48e0bSAndroid Build Coastguard Worker 111*08b48e0bSAndroid Build Coastguard Worker2. Create a `docker-compose.yml` containing the following: 112*08b48e0bSAndroid Build Coastguard Worker 113*08b48e0bSAndroid Build Coastguard Worker ```yml 114*08b48e0bSAndroid Build Coastguard Worker version: '3' 115*08b48e0bSAndroid Build Coastguard Worker 116*08b48e0bSAndroid Build Coastguard Worker networks: 117*08b48e0bSAndroid Build Coastguard Worker statsd-net: 118*08b48e0bSAndroid Build Coastguard Worker driver: bridge 119*08b48e0bSAndroid Build Coastguard Worker 120*08b48e0bSAndroid Build Coastguard Worker services: 121*08b48e0bSAndroid Build Coastguard Worker prometheus: 122*08b48e0bSAndroid Build Coastguard Worker image: prom/prometheus 123*08b48e0bSAndroid Build Coastguard Worker container_name: prometheus 124*08b48e0bSAndroid Build Coastguard Worker volumes: 125*08b48e0bSAndroid Build Coastguard Worker - ./prometheus.yml:/prometheus.yml 126*08b48e0bSAndroid Build Coastguard Worker command: 127*08b48e0bSAndroid Build Coastguard Worker - '--config.file=/prometheus.yml' 128*08b48e0bSAndroid Build Coastguard Worker restart: unless-stopped 129*08b48e0bSAndroid Build Coastguard Worker ports: 130*08b48e0bSAndroid Build Coastguard Worker - "9090:9090" 131*08b48e0bSAndroid Build Coastguard Worker networks: 132*08b48e0bSAndroid Build Coastguard Worker - statsd-net 133*08b48e0bSAndroid Build Coastguard Worker 134*08b48e0bSAndroid Build Coastguard Worker statsd_exporter: 135*08b48e0bSAndroid Build Coastguard Worker image: prom/statsd-exporter 136*08b48e0bSAndroid Build Coastguard Worker container_name: statsd_exporter 137*08b48e0bSAndroid Build Coastguard Worker volumes: 138*08b48e0bSAndroid Build Coastguard Worker - ./statsd_mapping.yml:/statsd_mapping.yml 139*08b48e0bSAndroid Build Coastguard Worker command: 140*08b48e0bSAndroid Build Coastguard Worker - "--statsd.mapping-config=/statsd_mapping.yml" 141*08b48e0bSAndroid Build Coastguard Worker ports: 142*08b48e0bSAndroid Build Coastguard Worker - "9102:9102/tcp" 143*08b48e0bSAndroid Build Coastguard Worker - "8125:9125/udp" 144*08b48e0bSAndroid Build Coastguard Worker networks: 145*08b48e0bSAndroid Build Coastguard Worker - statsd-net 146*08b48e0bSAndroid Build Coastguard Worker 147*08b48e0bSAndroid Build Coastguard Worker grafana: 148*08b48e0bSAndroid Build Coastguard Worker image: grafana/grafana 149*08b48e0bSAndroid Build Coastguard Worker container_name: grafana 150*08b48e0bSAndroid Build Coastguard Worker restart: unless-stopped 151*08b48e0bSAndroid Build Coastguard Worker ports: 152*08b48e0bSAndroid Build Coastguard Worker - "3000:3000" 153*08b48e0bSAndroid Build Coastguard Worker networks: 154*08b48e0bSAndroid Build Coastguard Worker - statsd-net 155*08b48e0bSAndroid Build Coastguard Worker ``` 156*08b48e0bSAndroid Build Coastguard Worker 157*08b48e0bSAndroid Build Coastguard Worker3. Create a `prometheus.yml` containing the following: 158*08b48e0bSAndroid Build Coastguard Worker 159*08b48e0bSAndroid Build Coastguard Worker ```yml 160*08b48e0bSAndroid Build Coastguard Worker global: 161*08b48e0bSAndroid Build Coastguard Worker scrape_interval: 15s 162*08b48e0bSAndroid Build Coastguard Worker evaluation_interval: 15s 163*08b48e0bSAndroid Build Coastguard Worker 164*08b48e0bSAndroid Build Coastguard Worker scrape_configs: 165*08b48e0bSAndroid Build Coastguard Worker - job_name: 'fuzzing_metrics' 166*08b48e0bSAndroid Build Coastguard Worker static_configs: 167*08b48e0bSAndroid Build Coastguard Worker - targets: ['statsd_exporter:9102'] 168*08b48e0bSAndroid Build Coastguard Worker ``` 169*08b48e0bSAndroid Build Coastguard Worker 170*08b48e0bSAndroid Build Coastguard Worker4. Create a `statsd_mapping.yml` containing the following: 171*08b48e0bSAndroid Build Coastguard Worker 172*08b48e0bSAndroid Build Coastguard Worker ```yml 173*08b48e0bSAndroid Build Coastguard Worker mappings: 174*08b48e0bSAndroid Build Coastguard Worker - match: "fuzzing.*" 175*08b48e0bSAndroid Build Coastguard Worker name: "fuzzing" 176*08b48e0bSAndroid Build Coastguard Worker labels: 177*08b48e0bSAndroid Build Coastguard Worker type: "$1" 178*08b48e0bSAndroid Build Coastguard Worker ``` 179*08b48e0bSAndroid Build Coastguard Worker 180*08b48e0bSAndroid Build Coastguard Worker5. Run `docker-compose up -d`. 181*08b48e0bSAndroid Build Coastguard Worker 182*08b48e0bSAndroid Build Coastguard Worker## Running AFL++ with StatsD 183*08b48e0bSAndroid Build Coastguard Worker 184*08b48e0bSAndroid Build Coastguard WorkerTo run your fuzzing instances: 185*08b48e0bSAndroid Build Coastguard Worker 186*08b48e0bSAndroid Build Coastguard Worker``` 187*08b48e0bSAndroid Build Coastguard WorkerAFL_STATSD_TAGS_FLAVOR=dogstatsd AFL_STATSD=1 afl-fuzz -M test-fuzzer-1 -i i -o o [./bin/my-application] @@ 188*08b48e0bSAndroid Build Coastguard WorkerAFL_STATSD_TAGS_FLAVOR=dogstatsd AFL_STATSD=1 afl-fuzz -S test-fuzzer-2 -i i -o o [./bin/my-application] @@ 189*08b48e0bSAndroid Build Coastguard Worker... 190*08b48e0bSAndroid Build Coastguard Worker```