Remove the browser UI, its Python server and the web API contract test. Add the Qt6 tray app (status, findings, process search, policy controls, notifications) and EvidenceStore, the read-only view of the daemon's evidence that the app and MCP server share. The GUI demo config becomes strawberry.demo.conf. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
714 lines
35 KiB
C++
714 lines
35 KiB
C++
#include "main_window.hpp"
|
|
|
|
#include <QCheckBox>
|
|
#include <QComboBox>
|
|
#include <QDateTime>
|
|
#include <QFont>
|
|
#include <QHBoxLayout>
|
|
#include <QHeaderView>
|
|
#include <QJsonArray>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QListWidget>
|
|
#include <QMessageBox>
|
|
#include <QPushButton>
|
|
#include <QSplitter>
|
|
#include <QTabWidget>
|
|
#include <QTableWidget>
|
|
#include <QTextBrowser>
|
|
#include <QUrl>
|
|
#include <QVBoxLayout>
|
|
|
|
#include <algorithm>
|
|
|
|
namespace strawberry::app {
|
|
|
|
namespace {
|
|
|
|
const QString kProcessScheme = QStringLiteral("sbprocess");
|
|
const QString kFindingScheme = QStringLiteral("sbfinding");
|
|
const QString kAllowHashScheme = QStringLiteral("sballowhash");
|
|
const QString kAllowPathRuleScheme = QStringLiteral("sballowpathrule");
|
|
const QString kContainScheme = QStringLiteral("sbcontain");
|
|
const QString kActionScheme = QStringLiteral("sbaction"); // sbaction:<verb>|<node id>
|
|
const QString kQuarantineScheme = QStringLiteral("sbquarantine");
|
|
|
|
QString esc(const std::string& value) {
|
|
return QString::fromStdString(value).toHtmlEscaped();
|
|
}
|
|
|
|
QString link(const QString& scheme, const std::string& id, const QString& text) {
|
|
return QStringLiteral("<a href=\"%1:%2\">%3</a>")
|
|
.arg(scheme, QString::fromLatin1(QUrl::toPercentEncoding(QString::fromStdString(id))), text);
|
|
}
|
|
|
|
// Evidence timestamps are wall-clock nanoseconds; demo data may use small values.
|
|
QString format_ns(int64_t ns) {
|
|
if (ns <= 0) {
|
|
return QStringLiteral("—");
|
|
}
|
|
if (ns < 1'000'000'000'000'000LL) {
|
|
return QString::number(ns);
|
|
}
|
|
return QDateTime::fromMSecsSinceEpoch(ns / 1'000'000).toString(QStringLiteral("yyyy-MM-dd HH:mm:ss"));
|
|
}
|
|
|
|
QString severity_color(const std::string& severity) {
|
|
switch (severity_rank(severity)) {
|
|
case 4: return QStringLiteral("#8b0012");
|
|
case 3: return QStringLiteral("#d72638");
|
|
case 2: return QStringLiteral("#c07a00");
|
|
case 1: return QStringLiteral("#5a6b7b");
|
|
default: return QStringLiteral("#666");
|
|
}
|
|
}
|
|
|
|
QString prop(const GraphNode& node, const char* key) {
|
|
const auto it = node.properties.find(key);
|
|
return it == node.properties.end() ? QString() : QString::fromStdString(it->second);
|
|
}
|
|
|
|
QString check(bool ok) {
|
|
return ok ? QStringLiteral("<span style=\"color:#2ea043\">✔</span>")
|
|
: QStringLiteral("<span style=\"color:#d72638\">✘</span>");
|
|
}
|
|
|
|
QString duration_text(qint64 seconds) {
|
|
if (seconds < 120) return QStringLiteral("%1 s").arg(seconds);
|
|
if (seconds < 7200) return QStringLiteral("%1 min").arg(seconds / 60);
|
|
if (seconds < 172800) return QStringLiteral("%1 h").arg(seconds / 3600);
|
|
return QStringLiteral("%1 days").arg(seconds / 86400);
|
|
}
|
|
|
|
int64_t json_ns(const QJsonObject& object, const char* key) {
|
|
return static_cast<int64_t>(object.value(QLatin1String(key)).toDouble());
|
|
}
|
|
|
|
} // namespace
|
|
|
|
MainWindow::MainWindow(const EvidenceStore& store, QWidget* parent)
|
|
: QMainWindow(parent), store_(store) {
|
|
setWindowTitle(QStringLiteral("Strawberry"));
|
|
resize(1100, 700);
|
|
|
|
tabs_ = new QTabWidget(this);
|
|
tabs_->addTab(build_findings_tab(), QStringLiteral("Findings"));
|
|
tabs_->addTab(build_processes_tab(), QStringLiteral("Processes"));
|
|
tabs_->addTab(build_rules_tab(), QStringLiteral("Rules"));
|
|
tabs_->addTab(build_allowlist_tab(), QStringLiteral("Allowlist"));
|
|
tabs_->addTab(build_response_tab(), QStringLiteral("Response"));
|
|
tabs_->addTab(build_diagnostics_tab(), QStringLiteral("Diagnostics"));
|
|
setCentralWidget(tabs_);
|
|
}
|
|
|
|
QWidget* MainWindow::build_findings_tab() {
|
|
auto* page = new QWidget(this);
|
|
auto* layout = new QVBoxLayout(page);
|
|
|
|
auto* bar = new QHBoxLayout();
|
|
severity_filter_ = new QComboBox(page);
|
|
severity_filter_->addItem(QStringLiteral("All severities"), 0);
|
|
severity_filter_->addItem(QStringLiteral("Low and above"), 1);
|
|
severity_filter_->addItem(QStringLiteral("Medium and above"), 2);
|
|
severity_filter_->addItem(QStringLiteral("High and above"), 3);
|
|
unseen_only_ = new QCheckBox(QStringLiteral("Unseen only"), page);
|
|
auto* mark_all = new QPushButton(QStringLiteral("Mark all seen"), page);
|
|
findings_banner_ = new QLabel(page);
|
|
findings_banner_->setWordWrap(true);
|
|
bar->addWidget(severity_filter_);
|
|
bar->addWidget(unseen_only_);
|
|
bar->addStretch();
|
|
bar->addWidget(mark_all);
|
|
layout->addLayout(bar);
|
|
layout->addWidget(findings_banner_);
|
|
|
|
auto* splitter = new QSplitter(Qt::Vertical, page);
|
|
findings_table_ = new QTableWidget(0, 4, splitter);
|
|
findings_table_->setHorizontalHeaderLabels(
|
|
{QStringLiteral("Severity"), QStringLiteral("Score"), QStringLiteral("Finding"), QStringLiteral("Last seen")});
|
|
findings_table_->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
findings_table_->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
findings_table_->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
|
|
findings_table_->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
|
findings_table_->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
findings_table_->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
findings_table_->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
findings_table_->verticalHeader()->setVisible(false);
|
|
finding_detail_ = new QTextBrowser(splitter);
|
|
finding_detail_->setOpenLinks(false);
|
|
splitter->addWidget(findings_table_);
|
|
splitter->addWidget(finding_detail_);
|
|
splitter->setStretchFactor(0, 3);
|
|
splitter->setStretchFactor(1, 2);
|
|
layout->addWidget(splitter);
|
|
|
|
connect(severity_filter_, &QComboBox::currentIndexChanged, this, [this]() { refresh_findings(seen_); });
|
|
connect(unseen_only_, &QCheckBox::toggled, this, [this]() { refresh_findings(seen_); });
|
|
connect(mark_all, &QPushButton::clicked, this, &MainWindow::mark_all_seen_requested);
|
|
connect(finding_detail_, &QTextBrowser::anchorClicked, this, &MainWindow::on_link);
|
|
connect(findings_table_, &QTableWidget::itemSelectionChanged, this, [this]() {
|
|
const auto rows = findings_table_->selectionModel()->selectedRows();
|
|
if (rows.isEmpty()) {
|
|
return;
|
|
}
|
|
const auto id = findings_table_->item(rows.first().row(), 0)->data(Qt::UserRole).toString().toStdString();
|
|
const auto it = std::find_if(findings_.begin(), findings_.end(), [&](const auto& f) { return f.id == id; });
|
|
if (it != findings_.end()) {
|
|
render_finding_detail(*it);
|
|
emit finding_viewed(QString::fromStdString(it->id), it->last_seen);
|
|
}
|
|
});
|
|
return page;
|
|
}
|
|
|
|
QWidget* MainWindow::build_processes_tab() {
|
|
auto* page = new QWidget(this);
|
|
auto* layout = new QVBoxLayout(page);
|
|
|
|
auto* bar = new QHBoxLayout();
|
|
process_query_ = new QLineEdit(page);
|
|
process_query_->setPlaceholderText(QStringLiteral("PID, path, hash, command line, rule or finding…"));
|
|
process_query_->setClearButtonEnabled(true);
|
|
auto* search = new QPushButton(QStringLiteral("Search"), page);
|
|
bar->addWidget(process_query_);
|
|
bar->addWidget(search);
|
|
layout->addLayout(bar);
|
|
|
|
auto* splitter = new QSplitter(Qt::Horizontal, page);
|
|
process_results_ = new QListWidget(splitter);
|
|
process_detail_ = new QTextBrowser(splitter);
|
|
process_detail_->setOpenLinks(false);
|
|
splitter->addWidget(process_results_);
|
|
splitter->addWidget(process_detail_);
|
|
splitter->setStretchFactor(0, 1);
|
|
splitter->setStretchFactor(1, 2);
|
|
layout->addWidget(splitter);
|
|
process_result_ = new QLabel(page);
|
|
process_result_->setWordWrap(true);
|
|
layout->addWidget(process_result_);
|
|
|
|
connect(search, &QPushButton::clicked, this, &MainWindow::run_process_search);
|
|
connect(process_query_, &QLineEdit::returnPressed, this, &MainWindow::run_process_search);
|
|
connect(process_detail_, &QTextBrowser::anchorClicked, this, &MainWindow::on_link);
|
|
connect(process_results_, &QListWidget::currentRowChanged, this, [this](int row) {
|
|
if (row >= 0 && static_cast<std::size_t>(row) < process_hits_.size()) {
|
|
render_process_detail(process_hits_[static_cast<std::size_t>(row)]);
|
|
}
|
|
});
|
|
return page;
|
|
}
|
|
|
|
QWidget* MainWindow::build_diagnostics_tab() {
|
|
auto* page = new QWidget(this);
|
|
auto* layout = new QVBoxLayout(page);
|
|
|
|
auto* bar = new QHBoxLayout();
|
|
reload_button_ = new QPushButton(QStringLiteral("Reload rules"), page);
|
|
rescan_button_ = new QPushButton(QStringLiteral("Rescan running processes"), page);
|
|
command_result_ = new QLabel(page);
|
|
command_result_->setWordWrap(true);
|
|
bar->addWidget(reload_button_);
|
|
bar->addWidget(rescan_button_);
|
|
bar->addWidget(command_result_, 1);
|
|
layout->addLayout(bar);
|
|
|
|
diagnostics_ = new QTextBrowser(page);
|
|
layout->addWidget(diagnostics_);
|
|
|
|
connect(reload_button_, &QPushButton::clicked, this, [this]() {
|
|
command_result_->setText(QStringLiteral("Reloading rules…"));
|
|
emit command_requested(QStringLiteral("reload-rules"));
|
|
});
|
|
connect(rescan_button_, &QPushButton::clicked, this, [this]() {
|
|
command_result_->setText(QStringLiteral("Requesting rescan…"));
|
|
emit command_requested(QStringLiteral("rescan"));
|
|
});
|
|
render_diagnostics();
|
|
return page;
|
|
}
|
|
|
|
void MainWindow::refresh_findings(const AckMap& seen) {
|
|
seen_ = seen;
|
|
findings_ = store_.findings();
|
|
std::sort(findings_.begin(), findings_.end(), [](const auto& a, const auto& b) {
|
|
if (a.score != b.score) return a.score > b.score;
|
|
return a.last_seen > b.last_seen;
|
|
});
|
|
|
|
const QString selected = [&]() {
|
|
const auto rows = findings_table_->selectionModel()->selectedRows();
|
|
return rows.isEmpty() ? QString() : findings_table_->item(rows.first().row(), 0)->data(Qt::UserRole).toString();
|
|
}();
|
|
|
|
const int min_rank = severity_filter_->currentData().toInt();
|
|
findings_table_->blockSignals(true);
|
|
findings_table_->setRowCount(0);
|
|
for (const auto& finding : findings_) {
|
|
const bool unseen = is_unseen({finding.id, finding.title, finding.severity, finding.last_seen}, seen_);
|
|
if (severity_rank(finding.severity) < min_rank || (unseen_only_->isChecked() && !unseen)) {
|
|
continue;
|
|
}
|
|
const int row = findings_table_->rowCount();
|
|
findings_table_->insertRow(row);
|
|
|
|
auto* severity = new QTableWidgetItem(QString::fromStdString(finding.severity));
|
|
severity->setData(Qt::UserRole, QString::fromStdString(finding.id));
|
|
severity->setForeground(QColor(severity_color(finding.severity)));
|
|
auto* score = new QTableWidgetItem(QString::number(finding.score));
|
|
auto* title = new QTableWidgetItem((unseen ? QStringLiteral("● ") : QString()) + QString::fromStdString(finding.title));
|
|
title->setToolTip(QString::fromStdString(finding.summary));
|
|
auto* last = new QTableWidgetItem(format_ns(finding.last_seen));
|
|
for (auto* item : {severity, score, title, last}) {
|
|
QFont font = item->font();
|
|
font.setBold(unseen);
|
|
item->setFont(font);
|
|
}
|
|
findings_table_->setItem(row, 0, severity);
|
|
findings_table_->setItem(row, 1, score);
|
|
findings_table_->setItem(row, 2, title);
|
|
findings_table_->setItem(row, 3, last);
|
|
if (!selected.isEmpty() && severity->data(Qt::UserRole).toString() == selected) {
|
|
findings_table_->selectRow(row);
|
|
}
|
|
}
|
|
findings_table_->blockSignals(false);
|
|
|
|
if (!store_.available()) {
|
|
findings_banner_->setText(QStringLiteral("<b>Evidence unavailable:</b> %1").arg(esc(store_.error())));
|
|
} else if (findings_.empty()) {
|
|
findings_banner_->setText(QStringLiteral("No findings stored yet."));
|
|
} else {
|
|
findings_banner_->setText(QStringLiteral("%1 finding(s); ● marks unseen.").arg(findings_.size()));
|
|
}
|
|
}
|
|
|
|
void MainWindow::render_finding_detail(const FindingRecord& finding) {
|
|
QString html;
|
|
html += QStringLiteral("<h3 style=\"color:%1\">%2</h3>").arg(severity_color(finding.severity), esc(finding.title));
|
|
html += QStringLiteral("<p><b>%1</b> · score %2 · first seen %3 · last seen %4</p>")
|
|
.arg(esc(finding.severity)).arg(finding.score).arg(format_ns(finding.first_seen), format_ns(finding.last_seen));
|
|
html += QStringLiteral("<p>%1</p>").arg(esc(finding.summary));
|
|
|
|
html += QStringLiteral("<h4>Related processes</h4><ul>");
|
|
bool any_process = false;
|
|
for (const auto& node_id : finding.related_node_ids) {
|
|
if (node_id.rfind("process_", 0) == 0) {
|
|
any_process = true;
|
|
html += QStringLiteral("<li>%1</li>").arg(link(kProcessScheme, node_id, esc(node_id)));
|
|
}
|
|
}
|
|
if (!any_process) {
|
|
html += QStringLiteral("<li>none recorded</li>");
|
|
}
|
|
html += QStringLiteral("</ul>");
|
|
|
|
// One-click allowlisting for false positives.
|
|
const auto meta = [&](const char* key) {
|
|
const auto it = finding.metadata.find(key);
|
|
return it == finding.metadata.end() ? std::string{} : it->second;
|
|
};
|
|
const auto hash = meta("hash");
|
|
const auto path = meta("process_path");
|
|
QStringList actions;
|
|
if (hash.size() == 64) {
|
|
actions << link(kAllowHashScheme, hash, QStringLiteral("Allowlist this binary (all rules, by hash)"));
|
|
}
|
|
QString response;
|
|
if (hash.size() == 64) {
|
|
response = QStringLiteral("<h4>Respond</h4><p>%1</p>")
|
|
.arg(link(kContainScheme, hash, QStringLiteral("Block this binary's network access (OpenSnitch)")));
|
|
}
|
|
if (!path.empty() && path.front() == '/') {
|
|
QString rules = QString::fromStdString(meta("rules"));
|
|
for (const auto& rule : rules.split(QLatin1Char(','), Qt::SkipEmptyParts)) {
|
|
actions << link(kAllowPathRuleScheme, rule.trimmed().toStdString() + "|" + path,
|
|
QStringLiteral("Allowlist rule %1 at this path").arg(rule.trimmed().toHtmlEscaped()));
|
|
}
|
|
}
|
|
html += response;
|
|
if (!actions.isEmpty()) {
|
|
html += QStringLiteral("<h4>False positive?</h4><p>%1</p>").arg(actions.join(QStringLiteral(" · ")));
|
|
}
|
|
|
|
html += QStringLiteral("<h4>Details</h4><table cellspacing=4>");
|
|
for (const auto& [key, value] : finding.metadata) {
|
|
html += QStringLiteral("<tr><td><b>%1</b></td><td><code>%2</code></td></tr>").arg(esc(key), esc(value));
|
|
}
|
|
html += QStringLiteral("</table><p style=\"color:#888\">%1</p>").arg(esc(finding.id));
|
|
finding_detail_->setHtml(html);
|
|
}
|
|
|
|
void MainWindow::run_process_search() {
|
|
const auto query = process_query_->text().trimmed().toStdString();
|
|
process_hits_ = store_.search_processes(query);
|
|
process_results_->clear();
|
|
for (const auto& hit : process_hits_) {
|
|
const auto& node = hit.process;
|
|
auto label = QStringLiteral("PID %1 %2").arg(prop(node, "pid"), prop(node, "path"));
|
|
if (!hit.findings.empty()) {
|
|
label = QStringLiteral("⚠ ") + label;
|
|
}
|
|
process_results_->addItem(label);
|
|
}
|
|
if (process_hits_.empty()) {
|
|
process_detail_->setHtml(store_.available()
|
|
? QStringLiteral("<p>No matching processes.</p>")
|
|
: QStringLiteral("<p><b>Evidence unavailable:</b> %1</p>").arg(esc(store_.error())));
|
|
} else {
|
|
process_results_->setCurrentRow(0);
|
|
}
|
|
}
|
|
|
|
void MainWindow::render_process_detail(const ProcessSearchResult& result) {
|
|
const auto& node = result.process;
|
|
QString html;
|
|
html += QStringLiteral("<h3>PID %1 — %2</h3>").arg(prop(node, "pid").toHtmlEscaped(), prop(node, "path").toHtmlEscaped());
|
|
|
|
QStringList flags;
|
|
if (prop(node, "exe_memfd") == QStringLiteral("true")) flags << QStringLiteral("<b style=\"color:#d72638\">running from memfd (fileless)</b>");
|
|
if (prop(node, "exe_deleted") == QStringLiteral("true")) flags << QStringLiteral("<b style=\"color:#c07a00\">executable deleted from disk</b>");
|
|
if (!flags.isEmpty()) {
|
|
html += QStringLiteral("<p>%1</p>").arg(flags.join(QStringLiteral(" · ")));
|
|
}
|
|
|
|
html += QStringLiteral("<table cellspacing=4>");
|
|
const auto row = [&](const QString& label, const QString& value) {
|
|
if (!value.isEmpty()) {
|
|
html += QStringLiteral("<tr><td><b>%1</b></td><td><code>%2</code></td></tr>").arg(label, value.toHtmlEscaped());
|
|
}
|
|
};
|
|
row(QStringLiteral("Command line"), prop(node, "cmdline"));
|
|
row(QStringLiteral("SHA-256"), prop(node, "hash"));
|
|
row(QStringLiteral("Node id"), QString::fromStdString(node.id));
|
|
if (result.first_seen) row(QStringLiteral("First seen"), format_ns(static_cast<int64_t>(*result.first_seen)));
|
|
if (result.last_seen) row(QStringLiteral("Last seen"), format_ns(static_cast<int64_t>(*result.last_seen)));
|
|
html += QStringLiteral("</table>");
|
|
|
|
html += QStringLiteral("<h4>Lineage</h4><ul>");
|
|
if (result.parent_process) {
|
|
html += QStringLiteral("<li>Parent: %1</li>").arg(link(kProcessScheme, result.parent_process->id,
|
|
QStringLiteral("PID %1 %2").arg(prop(*result.parent_process, "pid"), prop(*result.parent_process, "path")).toHtmlEscaped()));
|
|
} else {
|
|
html += QStringLiteral("<li>Parent: not recorded</li>");
|
|
}
|
|
for (const auto& child : result.child_processes) {
|
|
html += QStringLiteral("<li>Child: %1</li>").arg(link(kProcessScheme, child.id,
|
|
QStringLiteral("PID %1 %2").arg(prop(child, "pid"), prop(child, "path")).toHtmlEscaped()));
|
|
}
|
|
html += QStringLiteral("</ul>");
|
|
|
|
if (!result.findings.empty()) {
|
|
html += QStringLiteral("<h4>Findings</h4><ul>");
|
|
for (const auto& finding : result.findings) {
|
|
html += QStringLiteral("<li><span style=\"color:%1\">[%2]</span> %3</li>")
|
|
.arg(severity_color(finding.severity), esc(finding.severity),
|
|
link(kFindingScheme, finding.id, esc(finding.title)));
|
|
}
|
|
html += QStringLiteral("</ul>");
|
|
}
|
|
|
|
html += QStringLiteral("<h4>Related evidence</h4><ul>");
|
|
for (const auto& related : result.related_nodes) {
|
|
QString text = QString::fromStdString(related.type) + QStringLiteral(": ");
|
|
if (related.type == "indicator") {
|
|
text += prop(related, "rule_name") + QStringLiteral(" [") + prop(related, "severity") + QStringLiteral("]");
|
|
} else if (related.type == "file") {
|
|
text += prop(related, "path");
|
|
} else {
|
|
text += QString::fromStdString(related.id);
|
|
}
|
|
html += QStringLiteral("<li>%1</li>").arg(text.toHtmlEscaped());
|
|
}
|
|
html += QStringLiteral("</ul>");
|
|
|
|
if (const auto hash = prop(node, "hash"); hash.size() == 64) {
|
|
html += QStringLiteral("<p><b>Binary:</b> %1 · %2 · %3</p>")
|
|
.arg(link(kContainScheme, hash.toStdString(), QStringLiteral("Block network (OpenSnitch)")),
|
|
link(kQuarantineScheme, hash.toStdString(), QStringLiteral("Quarantine (block execution)")),
|
|
link(kAllowHashScheme, hash.toStdString(), QStringLiteral("Allowlist this binary (by hash)")));
|
|
}
|
|
// Live actions need a stable id (pid + boot + start time) so the daemon can
|
|
// verify it is still the same process.
|
|
if (std::count(node.id.begin(), node.id.end(), '_') == 3) {
|
|
const auto action = [&](const char* verb, const QString& text) {
|
|
return link(kActionScheme, std::string(verb) + "|" + node.id, text);
|
|
};
|
|
html += QStringLiteral("<p><b>Process (if still running):</b> %1 · %2 · %3 · %4</p>")
|
|
.arg(action("scan-memory", QStringLiteral("Scan memory")),
|
|
action("process-suspend", QStringLiteral("Suspend")),
|
|
action("process-resume", QStringLiteral("Resume")),
|
|
action("process-kill", QStringLiteral("<span style=\"color:#d72638\">Kill</span>")));
|
|
}
|
|
if (process_result_ != nullptr) {
|
|
process_result_->clear();
|
|
}
|
|
|
|
const auto trace = store_.trace(node.id, 2);
|
|
if (!trace.empty()) {
|
|
html += QStringLiteral("<h4>Incident trace</h4><pre>%1</pre>").arg(esc(trace));
|
|
}
|
|
process_detail_->setHtml(html);
|
|
}
|
|
|
|
void MainWindow::on_link(const QUrl& url) {
|
|
const auto id = QUrl::fromPercentEncoding(url.path().toLatin1());
|
|
if (url.scheme() == kProcessScheme) {
|
|
show_process(id);
|
|
} else if (url.scheme() == kFindingScheme) {
|
|
show_finding(id);
|
|
} else if (url.scheme() == kContainScheme) {
|
|
if (QMessageBox::question(this, QStringLiteral("Block network"),
|
|
QStringLiteral("Deny all network access for this binary via OpenSnitch?\n\nsha256 %1\n\n"
|
|
"You can undo this in the Response tab.").arg(id))
|
|
== QMessageBox::Yes) {
|
|
tabs_->setCurrentWidget(contain_table_->parentWidget());
|
|
response_result_->setText(QStringLiteral("Blocking network…"));
|
|
emit policy_change_requested(QStringLiteral("contain-add"), QJsonObject{{QStringLiteral("sha256"), id}});
|
|
}
|
|
} else if (url.scheme() == kQuarantineScheme) {
|
|
if (QMessageBox::question(this, QStringLiteral("Quarantine binary"),
|
|
QStringLiteral("Block every execution of this exact binary (and its network access)?\n\n"
|
|
"sha256 %1\n\nThe file is not moved or deleted. Undo in the Response tab.").arg(id))
|
|
== QMessageBox::Yes) {
|
|
process_result_->setText(QStringLiteral("Quarantining…"));
|
|
emit policy_change_requested(QStringLiteral("quarantine"), QJsonObject{{QStringLiteral("sha256"), id}});
|
|
}
|
|
} else if (url.scheme() == kActionScheme) {
|
|
const auto sep = id.indexOf(QLatin1Char('|'));
|
|
if (sep <= 0) {
|
|
return;
|
|
}
|
|
const auto verb = id.left(sep);
|
|
const auto node_id = id.mid(sep + 1);
|
|
QString question;
|
|
if (verb == QStringLiteral("process-kill")) {
|
|
question = QStringLiteral("Kill this process immediately (SIGKILL)? Unsaved work in it is lost.");
|
|
} else if (verb == QStringLiteral("process-suspend")) {
|
|
question = QStringLiteral("Suspend this process (SIGSTOP)? It stays frozen until you resume it.");
|
|
}
|
|
if (!question.isEmpty()
|
|
&& QMessageBox::question(this, QStringLiteral("Confirm"), question + QStringLiteral("\n\n") + node_id) != QMessageBox::Yes) {
|
|
return;
|
|
}
|
|
process_result_->setText(QStringLiteral("Sending…"));
|
|
emit policy_change_requested(verb, QJsonObject{{QStringLiteral("node_id"), node_id}});
|
|
} else if (url.scheme() == kAllowHashScheme) {
|
|
propose_allowlist(QStringLiteral("sha256"), id, {}, QStringLiteral("every rule match on this exact binary"));
|
|
} else if (url.scheme() == kAllowPathRuleScheme) {
|
|
const auto sep = id.indexOf(QLatin1Char('|'));
|
|
if (sep > 0) {
|
|
propose_allowlist(QStringLiteral("path"), id.mid(sep + 1), id.left(sep),
|
|
QStringLiteral("rule %1 for this path only").arg(id.left(sep)));
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::show_finding(const QString& finding_id) {
|
|
tabs_->setCurrentIndex(0);
|
|
severity_filter_->setCurrentIndex(0);
|
|
unseen_only_->setChecked(false);
|
|
refresh_findings(seen_);
|
|
for (int row = 0; row < findings_table_->rowCount(); ++row) {
|
|
if (findings_table_->item(row, 0)->data(Qt::UserRole).toString() == finding_id) {
|
|
findings_table_->selectRow(row);
|
|
findings_table_->scrollToItem(findings_table_->item(row, 0));
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::select_tab(const QString& name) {
|
|
for (int i = 0; i < tabs_->count(); ++i) {
|
|
if (tabs_->tabText(i).compare(name, Qt::CaseInsensitive) == 0) {
|
|
tabs_->setCurrentIndex(i);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::show_process(const QString& node_id) {
|
|
tabs_->setCurrentIndex(1);
|
|
process_query_->setText(node_id);
|
|
process_hits_.clear();
|
|
process_results_->clear();
|
|
if (auto result = store_.process(node_id.toStdString())) {
|
|
process_hits_.push_back(*result);
|
|
process_results_->addItem(QStringLiteral("PID %1 %2").arg(prop(result->process, "pid"), prop(result->process, "path")));
|
|
process_results_->setCurrentRow(0);
|
|
} else {
|
|
process_detail_->setHtml(QStringLiteral("<p>Process %1 is not in the evidence store.</p>").arg(node_id.toHtmlEscaped()));
|
|
}
|
|
}
|
|
|
|
void MainWindow::update_status(const QJsonObject& status, const QString& error, const TrayState& tray) {
|
|
status_ = status;
|
|
status_error_ = error;
|
|
tray_ = tray;
|
|
reload_button_->setEnabled(error.isEmpty());
|
|
rescan_button_->setEnabled(error.isEmpty());
|
|
render_diagnostics();
|
|
render_rules();
|
|
render_response();
|
|
}
|
|
|
|
void MainWindow::show_command_result(const QString& verb, bool ok, const QString& message) {
|
|
QString name = QStringLiteral("Rule reload");
|
|
if (verb == QStringLiteral("rescan")) {
|
|
name = QStringLiteral("Rescan");
|
|
} else if (verb == QStringLiteral("update-rules")) {
|
|
name = QStringLiteral("Rule update");
|
|
}
|
|
if (rules_result_ != nullptr && verb != QStringLiteral("rescan")) {
|
|
rules_result_->setText(QStringLiteral("<span style=\"color:%1\">%2: %3</span>")
|
|
.arg(ok ? QStringLiteral("#2ea043") : QStringLiteral("#d72638"), name, message.toHtmlEscaped()));
|
|
}
|
|
command_result_->setText(QStringLiteral("<span style=\"color:%1\">%2: %3</span>")
|
|
.arg(ok ? QStringLiteral("#2ea043") : QStringLiteral("#d72638"), name, message.toHtmlEscaped()));
|
|
}
|
|
|
|
void MainWindow::render_diagnostics() {
|
|
if (diagnostics_ == nullptr) {
|
|
return;
|
|
}
|
|
QString html;
|
|
if (!status_error_.isEmpty() || status_.isEmpty()) {
|
|
html += QStringLiteral("<h3>%1 Scanner not reachable</h3><p>%2</p>")
|
|
.arg(check(false), (status_error_.isEmpty() ? QStringLiteral("waiting for first status…") : status_error_).toHtmlEscaped());
|
|
html += QStringLiteral("<p>Check the service: <code>systemctl status strawberry</code></p>");
|
|
} else {
|
|
const auto monitor = status_.value(QStringLiteral("monitor")).toObject();
|
|
const auto rules = status_.value(QStringLiteral("rules")).toObject();
|
|
const auto pipeline = status_.value(QStringLiteral("pipeline")).toObject();
|
|
const auto backend = monitor.value(QStringLiteral("backend")).toString();
|
|
const qint64 now = json_ns(status_, "now_ns");
|
|
const qint64 started = json_ns(status_, "started_at_ns");
|
|
|
|
html += QStringLiteral("<h3>%1 Scanner %2</h3>").arg(check(tray_.problems.empty()),
|
|
tray_.problems.empty() ? QStringLiteral("healthy") : QStringLiteral("degraded"));
|
|
if (!tray_.problems.empty()) {
|
|
html += QStringLiteral("<ul>");
|
|
for (const auto& problem : tray_.problems) {
|
|
html += QStringLiteral("<li>%1</li>").arg(esc(problem));
|
|
}
|
|
html += QStringLiteral("</ul>");
|
|
}
|
|
|
|
html += QStringLiteral("<h4>Monitoring</h4><table cellspacing=4>");
|
|
html += QStringLiteral("<tr><td>%1</td><td>Backend: <b>%2</b>%3</td></tr>").arg(check(backend == QStringLiteral("bpf")), backend.toHtmlEscaped(),
|
|
backend == QStringLiteral("bpf") ? QString() : QStringLiteral(" (eBPF unavailable; polling /proc)"));
|
|
html += QStringLiteral("<tr><td>%1</td><td>execveat hooked (fexecve / memfd executions)</td></tr>").arg(check(monitor.value(QStringLiteral("execveat")).toBool()));
|
|
html += QStringLiteral("<tr><td>%1</td><td>Fork tracepoint (parent PID enrichment, optional)</td></tr>").arg(check(monitor.value(QStringLiteral("fork_tracepoint")).toBool()));
|
|
html += QStringLiteral("<tr><td></td><td>Process events seen: %1</td></tr>").arg(monitor.value(QStringLiteral("events")).toDouble(), 0, 'f', 0);
|
|
html += QStringLiteral("</table>");
|
|
|
|
const qint64 loaded_at = json_ns(rules, "loaded_at_ns");
|
|
html += QStringLiteral("<h4>Rules</h4><table cellspacing=4>");
|
|
html += QStringLiteral("<tr><td>%1</td><td>%2 rule file(s) from <code>%3</code></td></tr>")
|
|
.arg(check(rules.value(QStringLiteral("loaded")).toBool()))
|
|
.arg(rules.value(QStringLiteral("files")).toInt())
|
|
.arg(rules.value(QStringLiteral("path")).toString().toHtmlEscaped());
|
|
if (loaded_at > 0) {
|
|
html += QStringLiteral("<tr><td></td><td>Loaded %1 (%2 ago), generation %3</td></tr>")
|
|
.arg(format_ns(loaded_at), duration_text((now - loaded_at) / 1'000'000'000))
|
|
.arg(rules.value(QStringLiteral("generation")).toInt());
|
|
}
|
|
const auto rules_error = rules.value(QStringLiteral("last_error")).toString();
|
|
if (!rules_error.isEmpty()) {
|
|
html += QStringLiteral("<tr><td>%1</td><td>Last reload failed: <code>%2</code> (previous rules still active)</td></tr>")
|
|
.arg(check(false), rules_error.toHtmlEscaped());
|
|
}
|
|
html += QStringLiteral("</table>");
|
|
|
|
const auto count = [&](const char* key) { return QString::number(pipeline.value(QLatin1String(key)).toDouble(), 'f', 0); };
|
|
html += QStringLiteral("<h4>Detection pipeline</h4><table cellspacing=4>");
|
|
html += QStringLiteral("<tr><td>Events handled</td><td>%1</td></tr>").arg(count("events"));
|
|
html += QStringLiteral("<tr><td>Images scanned</td><td>%1 (+%2 from cache)</td></tr>").arg(count("scanned"), count("cache_hits"));
|
|
html += QStringLiteral("<tr><td>Detections stored</td><td>%1 (last: %2)</td></tr>").arg(count("detections"), format_ns(json_ns(pipeline, "last_detection_ns")));
|
|
html += QStringLiteral("<tr><td>Images gone before scan</td><td>%1</td></tr>").arg(count("images_unavailable"));
|
|
html += QStringLiteral("<tr><td>Scan errors</td><td>%1</td></tr>").arg(count("scan_errors"));
|
|
html += QStringLiteral("</table>");
|
|
|
|
const auto resources = status_.value(QStringLiteral("resources")).toObject();
|
|
if (!resources.isEmpty()) {
|
|
const auto host = resources.value(QStringLiteral("host")).toObject();
|
|
const auto level = resources.value(QStringLiteral("level")).toString();
|
|
const auto num = [](const QJsonObject& o, const char* key, int decimals = 0) {
|
|
return QString::number(o.value(QLatin1String(key)).toDouble(), 'f', decimals);
|
|
};
|
|
html += QStringLiteral("<h4>Resources</h4><table cellspacing=4>");
|
|
html += QStringLiteral("<tr><td>%1</td><td>Profile <b>%2</b>, pressure <b>%3</b>%4</td></tr>")
|
|
.arg(check(level == QStringLiteral("normal") || level == QStringLiteral("warning")),
|
|
resources.value(QStringLiteral("profile")).toString().toHtmlEscaped(), level.toHtmlEscaped(),
|
|
resources.value(QStringLiteral("host_busy")).toBool() ? QStringLiteral(" · host busy: background work waits")
|
|
: QString());
|
|
html += QStringLiteral("<tr><td></td><td>Scanner CPU %1% of %2 CPU(s) · memory %3 / %4 MiB</td></tr>")
|
|
.arg(num(resources, "own_cpu_pct", 1), num(resources, "cpu_capacity", 1), num(resources, "rss_mb"),
|
|
num(resources, "memory_budget_mb"));
|
|
html += QStringLiteral("<tr><td></td><td>Host pressure (%1): cpu %2% · io %3% · memory %4% · %5 MiB available</td></tr>")
|
|
.arg(host.value(QStringLiteral("source")).toString().toHtmlEscaped(), num(host, "cpu_some_pct", 1),
|
|
num(host, "io_some_pct", 1), num(host, "memory_some_pct", 1), num(host, "mem_available_mb"));
|
|
QStringList deferring;
|
|
for (const auto& name : resources.value(QStringLiteral("deferring")).toArray()) {
|
|
deferring << name.toString().toHtmlEscaped();
|
|
}
|
|
if (!deferring.isEmpty()) {
|
|
html += QStringLiteral("<tr><td></td><td>Waiting for a calmer system: %1 (%2 s)</td></tr>")
|
|
.arg(deferring.join(QStringLiteral(", ")), num(resources, "longest_deferral_s"));
|
|
}
|
|
html += QStringLiteral("<tr><td></td><td>Inventory pending %1 · memory scans skipped %2 · exec checks reduced to hash-only %3 · read pacing %4 s</td></tr>")
|
|
.arg(num(resources, "inventory_pending"), num(resources, "memory_scans_skipped"),
|
|
num(resources, "guard_degraded"),
|
|
QString::number(resources.value(QStringLiteral("read_paced_ms")).toDouble() / 1000.0, 'f', 1));
|
|
html += QStringLiteral("</table>");
|
|
}
|
|
|
|
const auto timings = status_.value(QStringLiteral("timings")).toObject();
|
|
if (!timings.isEmpty()) {
|
|
const std::pair<const char*, const char*> rows[] = {
|
|
{"exec_decision", "Program launch check"}, {"exec_assess", "Exec guard scan"},
|
|
{"queue_wait", "Queue wait"}, {"image_scan", "Image read + scan"},
|
|
{"yara_scan", "YARA scan"}, {"db_commit", "Database commit"},
|
|
{"correlation", "Correlation pass"}, {"rule_compile", "Rule compile"},
|
|
{"memory_scan", "Memory scan"},
|
|
};
|
|
html += QStringLiteral("<h4>Timings</h4><table cellspacing=4><tr><td></td><td><b>count</b></td>"
|
|
"<td><b>p50 ms</b></td><td><b>p95 ms</b></td><td><b>max ms</b></td></tr>");
|
|
for (const auto& [key, label] : rows) {
|
|
const auto t = timings.value(QLatin1String(key)).toObject();
|
|
const auto n = t.value(QStringLiteral("count")).toDouble();
|
|
if (n <= 0) {
|
|
continue;
|
|
}
|
|
html += QStringLiteral("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td></tr>")
|
|
.arg(QLatin1String(label), QString::number(n, 'f', 0),
|
|
QString::number(t.value(QStringLiteral("p50_ms")).toDouble(), 'f', 1),
|
|
QString::number(t.value(QStringLiteral("p95_ms")).toDouble(), 'f', 1),
|
|
QString::number(t.value(QStringLiteral("max_ms")).toDouble(), 'f', 1));
|
|
}
|
|
html += QStringLiteral("</table>");
|
|
}
|
|
|
|
html += QStringLiteral("<h4>Daemon</h4><table cellspacing=4>");
|
|
html += QStringLiteral("<tr><td>Version / PID</td><td>%1 / %2</td></tr>")
|
|
.arg(status_.value(QStringLiteral("version")).toString().toHtmlEscaped())
|
|
.arg(status_.value(QStringLiteral("pid")).toInt());
|
|
if (started > 0) {
|
|
html += QStringLiteral("<tr><td>Uptime</td><td>%1</td></tr>").arg(duration_text((now - started) / 1'000'000'000));
|
|
}
|
|
html += QStringLiteral("<tr><td>Config</td><td><code>%1</code></td></tr>").arg(status_.value(QStringLiteral("config_path")).toString().toHtmlEscaped());
|
|
html += QStringLiteral("</table>");
|
|
}
|
|
|
|
html += QStringLiteral("<h4>Evidence database</h4><table cellspacing=4>");
|
|
html += QStringLiteral("<tr><td>%1</td><td><code>%2</code>%3</td></tr>")
|
|
.arg(check(store_.available()), QString::fromStdString(store_.path()).toHtmlEscaped(),
|
|
store_.available() ? QStringLiteral(" (%1 KiB, read-only)").arg(store_.size_bytes() / 1024) : QString());
|
|
if (!store_.available()) {
|
|
html += QStringLiteral("<tr><td></td><td>%1</td></tr>").arg(esc(store_.error()));
|
|
}
|
|
html += QStringLiteral("</table>");
|
|
html += QStringLiteral("<p style=\"color:#888\">Logs: <code>journalctl -u strawberry -f</code></p>");
|
|
diagnostics_->setHtml(html);
|
|
}
|
|
|
|
} // namespace strawberry::app
|