• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# american fuzzy lop++ - fuzzer synchronization tool
4# --------------------------------------------------
5#
6# Originally written by Michal Zalewski
7#
8# Copyright 2014 Google Inc. All rights reserved.
9# Copyright 2019-2022 AFLplusplus Project. All rights reserved.
10#
11# Licensed under the Apache License, Version 2.0 (the "License");
12# you may not use this file except in compliance with the License.
13# You may obtain a copy of the License at:
14#
15#   http://www.apache.org/licenses/LICENSE-2.0
16#
17# To make this script work:
18#
19# - Edit FUZZ_HOSTS, FUZZ_DOMAIN, FUZZ_USER, and SYNC_DIR to reflect your
20#   environment.
21#
22# - Make sure that the system you are running this on can log into FUZZ_HOSTS
23#   without a password (authorized_keys or otherwise).
24#
25# - Make sure that every fuzzer is running with -o pointing to SYNC_DIR and -S
26#   that consists of its local host name, followed by an underscore, and then
27#   by some host-local fuzzer ID.
28#
29
30# Hosts to synchronize the data across.
31FUZZ_HOSTS='host1 host2 host3 host4'
32
33# Domain for all hosts
34FUZZ_DOMAIN='example.com'
35
36# Remote user for SSH
37FUZZ_USER=bob
38
39# Directory to synchronize
40SYNC_DIR='/home/bob/sync_dir'
41
42# We only capture -M main nodes, set the name to your chosen naming scheme
43MAIN_NAME='main'
44
45# Interval (seconds) between sync attempts (eg one hour)
46SYNC_INTERVAL=$((60 * 60))
47
48if [ "$AFL_ALLOW_TMP" = "" ]; then
49
50  if [ "$PWD" = "/tmp" -o "$PWD" = "/var/tmp" ]; then
51    echo "[-] Error: do not use shared /tmp or /var/tmp directories with this script." 1>&2
52    exit 1
53  fi
54
55fi
56
57rm -rf .sync_tmp 2>/dev/null
58mkdir .sync_tmp || exit 1
59
60while :; do
61
62  # Pull data in...
63
64  for host in $FUZZ_HOSTS; do
65
66    echo "[*] Retrieving data from ${host}.${FUZZ_DOMAIN}..."
67
68    ssh -o 'passwordauthentication no' ${FUZZ_USER}@${host}.$FUZZ_DOMAIN \
69      "cd '$SYNC_DIR' && tar -czf - ${host}_${MAIN_NAME}*/" > ".sync_tmp/${host}.tgz"
70
71  done
72
73  # Distribute data. For large fleets, see tips in the docs/ directory.
74
75  for dst_host in $FUZZ_HOSTS; do
76
77    echo "[*] Distributing data to ${dst_host}.${FUZZ_DOMAIN}..."
78
79    for src_host in $FUZZ_HOSTS; do
80
81      test "$src_host" = "$dst_host" && continue
82
83      echo "    Sending fuzzer data from ${src_host}.${FUZZ_DOMAIN}..."
84
85      ssh -o 'passwordauthentication no' ${FUZZ_USER}@$dst_host \
86        "cd '$SYNC_DIR' && tar -xkzf - " < ".sync_tmp/${src_host}.tgz"
87
88    done
89
90  done
91
92  echo "[+] Done. Sleeping for $SYNC_INTERVAL seconds (Ctrl-C to quit)."
93
94  sleep $SYNC_INTERVAL
95
96done
97
98