strawberry/fuzz/fuzz_ioc_list.cpp
trvon 2e94ae1485
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / macos (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
Privacy: tracker list feeds (advisory only, never block)
First piece of tracker attribution (docs/tracker-attribution.md): which
programs reach advertising and tracking domains, built with the
measurement rules of the CarolinaCon 2026 privacy talk (bridgescope):
a listed domain is a circumstantial label, never proof.

- Feed kind "trackers": hosts lines, plain domains and adblock
  whole-domain rules (||host^, ||host^$third-party). Cosmetic rules,
  exceptions, paths and other options are skipped; the comment cut used
  to turn "site.example##.ad" into a domain.
- TrackerSet: suffix matching (a.b.t.example matches t.example, never
  nott.example, an IP literal or a bare TLD); first feed reported.
- List parsing moves from rule_updater.cpp to ioc_list.cpp (no network
  code) so the query-side core can use it.
- Source invariant R11: tracker lists never meet exec-guard or OpenSnitch
  code. They are not in the OpenSnitch blocklist sync.

Tests: T1-T3 (test_tracker_set), trackers in the list-parsing property
and the list fuzzer (60 s clean), R11 self-test fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 05:25:53 -06:00

33 lines
1.2 KiB
C++

// Threat-intel list parsing (downloaded feed bodies) + IOC set loading.
#include "strawberry/ioc_set.hpp"
#include "strawberry/rule_updater.hpp"
#include <cstdint>
#include <cstdio>
#include <string>
#include <unistd.h>
#include <vector>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size == 0) return 0;
static const char* kinds[] = {"hashes", "domains", "ips", "nets", "trackers"};
const std::string kind = kinds[data[0] % 5];
const std::string text(reinterpret_cast<const char*>(data) + 1, size - 1);
std::vector<std::string> out;
strawberry::parse_ioc_list(kind, text, 10000, out);
// The daemon loads normalized lists from disk: feed the raw text too.
static const std::string path = "/tmp/strawberry-fuzz-ioc-" + std::to_string(::getpid()) + ".txt";
if (FILE* f = std::fopen(path.c_str(), "wb")) {
std::fwrite(text.data(), 1, text.size(), f);
std::fclose(f);
strawberry::IocNetSet nets;
nets.load({{"ips", path}}, {{"nets", path}});
(void) nets.find("1.2.3.4");
(void) nets.find("2001:db8::1");
strawberry::IocHashSet hashes;
hashes.load({{"hashes", path}});
(void) hashes.find(std::string(64, 'a'));
}
return 0;
}