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 / docker (push) Has been cancelled
Per the triage decisions: - DeletedExecutable when a new file exists at the executable's path (an update or reinstall) is stored as evidence only. A binary with nothing left at its path still raises a low finding. - scripts/install.sh writes /var/lib/strawberry/installed-files.sha256 (hashes of the units it installs, root-owned, written first). A PersistenceWrite whose file matches its listed hash is evidence only; other content at those paths, or a suspicious writer, is reported as before. The daemon ignores a manifest that is not root-owned or is group/world-writable. Evidence-only indicators make no finding, alert or containment on their own; correlation counts them when the same process has another signal. Status reports pipeline.evidence_only. Tests cover the manifest, the behavior hook, correlation and the pipeline (replaced vs deleted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
2.2 KiB
C++
56 lines
2.2 KiB
C++
// Installed-files manifest: installer-written persistence files whose content
|
|
// still matches are recognized; anything else is not.
|
|
|
|
#include "strawberry/hash_utils.hpp"
|
|
#include "strawberry/installed_files.hpp"
|
|
|
|
#include <cassert>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
namespace fs = std::filesystem;
|
|
using strawberry::InstalledFiles;
|
|
|
|
int main() {
|
|
const fs::path root = fs::temp_directory_path() / ("sb-installed-" + std::to_string(::getpid()));
|
|
fs::remove_all(root);
|
|
fs::create_directories(root / "units");
|
|
const std::string unit = (root / "units" / "strawberry.service").string();
|
|
std::ofstream(unit) << "[Unit]\nDescription=Strawberry\n";
|
|
const std::string hash = strawberry::HashUtils::sha256_file(unit);
|
|
const std::string manifest = (root / "installed-files.sha256").string();
|
|
{
|
|
std::ofstream m(manifest);
|
|
m << hash << " " << unit << "\n";
|
|
m << "not-a-hash /etc/x\n"; // ignored
|
|
m << std::string(64, 'a') << " relative/path\n"; // ignored: not absolute
|
|
m << std::string(64, 'b') << " *" << (root / "units" / "other.timer").string() << "\n"; // binary-mode form
|
|
}
|
|
|
|
InstalledFiles files(manifest, /*require_root_owned=*/false);
|
|
assert(files.size() == 2);
|
|
assert(files.matches(unit));
|
|
assert(!files.matches((root / "units" / "unlisted.service").string()));
|
|
assert(!files.matches((root / "units" / "other.timer").string())); // listed, file missing
|
|
|
|
// Content changed after install: no longer the shipped file.
|
|
std::ofstream(unit, std::ios::app) << "ExecStart=/tmp/implant\n";
|
|
assert(!files.matches(unit));
|
|
|
|
// A manifest that is not root-owned is ignored when root ownership is
|
|
// required (the daemon runs as root); tests run unprivileged.
|
|
if (::geteuid() != 0) {
|
|
InstalledFiles strict(manifest, /*require_root_owned=*/true);
|
|
assert(strict.size() == 0);
|
|
}
|
|
InstalledFiles missing((root / "nope").string(), false);
|
|
assert(missing.size() == 0 && !missing.matches(unit));
|
|
|
|
fs::remove_all(root);
|
|
std::cout << "installed files: PASSED" << std::endl;
|
|
return 0;
|
|
}
|