Only sync main nodes across servers

This commit is contained in:
2021-05-17 15:20:37 +02:00
parent a95b6ce3fe
commit 7807b45ed5
4 changed files with 38 additions and 106 deletions

View File

@@ -13,21 +13,26 @@ import (
var (
rescan int
isMainNode bool
)
// RegisterWatchdogFlags registers required flags for the watchdog
func RegisterWatchdogFlags() {
flag.IntVar(&rescan, "rescan", 30, "Minutes to wait before rescanning local fuzzer directories")
flag.BoolVar(&isMainNode, "main", false, "Set this option if this afl-transmit instance is running on the node running the main afl-fuzz instance")
flag.IntVar(&rescan, "rescan", 30, "Minutes to wait before rescanning local fuzzer directory")
}
// Watch over the specified directory, send updates to peers and re-scan after the specified amount of seconds
// WatchFuzzers watches over the specified directory, sends updates to peers and re-scans after the specified amount of seconds
func WatchFuzzers(outputDirectory string) {
// Loop forever
for {
// Pack important parts of the fuzzers into an archive
packedFuzzers, packerErr := logistic.PackFuzzers(getTargetFuzzer(outputDirectory), outputDirectory)
// Search for main fuzzer
targetFuzzer, targetErr := getTargetFuzzer(outputDirectory)
if targetErr != nil {
log.Printf("Failed to detect main fuzzer: %s", targetErr)
continue
}
// Pack important parts of the fuzzer into an archive
packedFuzzers, packerErr := logistic.PackFuzzer(targetFuzzer, outputDirectory)
if packerErr != nil {
log.Printf("Failed to pack fuzzer: %s", packerErr)
continue
@@ -41,24 +46,24 @@ func WatchFuzzers(outputDirectory string) {
}
}
// Searches in the specified output directory for fuzzers which we want to pack.
// Identifying the main fuzzer is done by searching for the file "is_main_node"
// This relies on the "election process" done by secondary fuzzers if they don't find a local main node.
// If that is detected, a secondary fuzzer becomes the main node in terms of syncing. That means we need to focus on
// the main node even if there is no real main node running locally.
// Searches in the specified output directory for the main fuzzer.
// Identifying the main fuzzer is done by searching for the file "is_main_node". On secondary-only servers, this relies
// on the "election process" done by secondary fuzzers if they don't find a local main node. In that election process, a
// secondary fuzzer becomes the main node in terms of syncing. That means we need to focus on the main node even if
// there is no real main node running locally. Good thing is that the elected node will create a "is_main_node" file, so
// we really just need to search for that.
// However it is important to avoid transmitting the is_main_node file - else, the secondaries will think that there is
// a main node running locally. Skipping the is_main_node file means the other fuzzers (and especially the elected main
// fuzzer) detect the transmitted fuzzer as a normal (and dead) secondary. ... blabla
// fuzzer) detect the transmitted fuzzer as a normal (and dead) secondary.
//
// (see AFLplusplus/src/afl-fuzz.run.c:542)
func getTargetFuzzer(outputDirectory string) []string {
func getTargetFuzzer(outputDirectory string) (string, error) {
// find main fuzzer directory - its the only one required by the secondaries
// List files (read: fuzzers) in output directory
filesInDir, readErr := ioutil.ReadDir(outputDirectory)
if readErr != nil {
log.Printf("Failed to list directory content of %s: %s", outputDirectory, readErr)
return nil
return "", fmt.Errorf("Failed to list directory content of %s: %s", outputDirectory, readErr)
}
for _, f := range filesInDir {
@@ -75,13 +80,9 @@ func getTargetFuzzer(outputDirectory string) []string {
}
// is_main_node file exists, so we found the correct fuzzer directory - return it
fullPath := fmt.Sprintf("%s%c%s", outputDirectory, os.PathSeparator, f.Name())
return []string{
fullPath,
}
return fmt.Sprintf("%s%c%s", outputDirectory, os.PathSeparator, f.Name()), nil
}
// Failed to find the main node - probably we are in --main mode by accident
log.Printf("Unable to find main node in %s - sure afl-transmit should run in --main mode?", outputDirectory)
return nil
return "", fmt.Errorf("Unable to find main node in %s", outputDirectory)
}