apex-twin 1.89.0: fapolicyd, systemd timer and yara audits, OpenBMC probe
Three blue config audits and one red probe: - fapolicyd_audit: permissive=1, integrity=none/0, an allow-all rule before any deny, world-writable fapolicyd.conf. - systemd_timer_audit: OnCalendar every minute or OnUnitActiveSec<=60s, Persistent=true, .service without User= (runs as root), writable unit file. - yara_audit: scanning disabled in yara.conf, writable or empty rule file, no rule set at all. - openbmc_probe: xyz.openbmc_project control tree on 443 answering without a session; power restore policy saved as evidence. Checks: make test 1459/1459, test-asan 1459/1459, analyze 0 warnings, 240 fuzz cases clean, coverage 85.0%, release-check incl. distcheck exit 0.
This commit is contained in:
1 parent
c5ba9d537b
commit
ea40473dc3
9 files changed
+886
-12
No files matched your search
@@ -1,5 +1,23 @@
|
||||
# Changelog
|
||||
|
||||
## 1.89.0 - 2026-11-24 - this change
|
||||
|
||||
- **fapolicyd** (`fapolicyd_audit`): `permissive = 1` (a denial is only
|
||||
logged), `integrity = none` or `0` (a replaced binary still matches its
|
||||
allow rule), an `allow all : all : all` rule before any `deny`, and a
|
||||
world-writable `fapolicyd.conf`.
|
||||
- **systemd timers** (`systemd_timer_audit`): an `OnCalendar=*:*:00` or
|
||||
`OnUnitActiveSec` of 60s or less (beacon interval), `Persistent=true`
|
||||
(missed runs fire after boot), a `.service` without `User=` (runs as root),
|
||||
and a world-writable unit file.
|
||||
- **YARA** (`yara_audit`): scanning switched off in `yara.conf`, a rule file
|
||||
any local user can write, an empty rule file, and no rule set at all.
|
||||
- **OpenBMC** (`openbmc_probe`): the `xyz.openbmc_project` control tree on
|
||||
443 answering without a session; the power restore policy is saved as
|
||||
evidence. A reachable `/redfish/v1/` alone is reported as `redfish` only.
|
||||
|
||||
389 tools, 1459 checks, 240 fuzz cases, 85.0% line coverage.
|
||||
|
||||
## 1.88.0 - 2026-11-24 - this change
|
||||
|
||||
- **freshclam** (`freshclam_audit`): `UpdateChecks no` (the signatures never
|
||||
|
||||
@@ -5,11 +5,11 @@ no Python in the serving path. It gives an agent real reconnaissance and real we
|
||||
testing behind a scope gate that refuses everything until a rules-of-engagement
|
||||
file says otherwise.
|
||||
|
||||
**385 tools · 1451 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
|
||||
**389 tools · 1459 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.88.0","tools":385,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.89.0","tools":389,...,"scope":{"loaded":true,...}}
|
||||
```
|
||||
|
||||
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
|
||||
@@ -238,6 +238,7 @@ uploads and secret-file reads. It does not execute anything.
|
||||
| `vault_probe` | `/v1/sys/mounts` on 8200 without a token; mount list as evidence |
|
||||
| `nomad_probe` | `/v1/jobs` on 4646 without a token; job inventory as evidence |
|
||||
| `coredns_probe` | plugin API `/config/` on 2019 without a token; server blocks as evidence |
|
||||
| `openbmc_probe` | xyz.openbmc_project control tree on 443 without a session; power policy as evidence |
|
||||
| `airflow_probe` | `/api/v1/dags` without auth; DAG inventory as evidence |
|
||||
| `jupyter_probe` | `/api/kernels` on 8888 without a token; sessions as evidence |
|
||||
| `jira_probe` | `/rest/api/2/project` on 8080 without auth; project list as evidence |
|
||||
@@ -581,6 +582,9 @@ does.
|
||||
| `tlog_audit` | tlog: scope without `session`, notice without `wall`, missing log target |
|
||||
| `abrt_audit` | abrt.conf: autoreporting, public collector URL, no TLS verify |
|
||||
| `freshclam_audit` | freshclam.conf: UpdateChecks off, http mirror, Checks below 2 |
|
||||
| `fapolicyd_audit` | fapolicyd: permissive = 1, integrity = none, allow-all before deny |
|
||||
| `systemd_timer_audit` | timers: every-minute interval, Persistent, service without User= |
|
||||
| `yara_audit` | YARA: scanning disabled, writable or empty rule file |
|
||||
| `tripwire_audit` | twcfg.txt: no site key, loose site key, no MAILTO |
|
||||
| `networkd_audit` | systemd-networkd: [Match] without Name/MAC/Type, DHCP DNS without UseDNS=no, public resolver |
|
||||
| `namespace_audit` | namespace.conf: no /tmp entry, empty/unknown method, `~` user list |
|
||||
@@ -1067,7 +1071,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
|
||||
ollama_probe, cadvisor_probe, teamcity_probe,
|
||||
superset_probe, argocd_probe, kafka_connect_probe,
|
||||
zabbix_probe, datasette_probe, vault_probe,
|
||||
nomad_probe, coredns_probe
|
||||
nomad_probe, coredns_probe, openbmc_probe
|
||||
src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
|
||||
detect_rules, integrity_baseline, mitre_map,
|
||||
process_snapshot, persistence_audit, net_baseline,
|
||||
@@ -1092,7 +1096,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
|
||||
jetty_audit, dhclient_audit,
|
||||
journal_upload_audit, fwupd_audit,
|
||||
smartd_audit, tlog_audit, abrt_audit,
|
||||
freshclam_audit, tripwire_audit)
|
||||
freshclam_audit, tripwire_audit, fapolicyd_audit,
|
||||
systemd_timer_audit, yara_audit)
|
||||
src/tools_esp.c esp_info, esp_monitor, esp_read_flash, esp_flash,
|
||||
esp_partition_table, esp_nvs_parse, firmware_scan,
|
||||
esp_app_info, esp_image_verify
|
||||
@@ -1131,7 +1136,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.88.0. Built and run: 385 tools, 1451 checks, 240 fuzz cases and 85.0% line
|
||||
1.89.0. Built and run: 389 tools, 1459 checks, 240 fuzz cases and 85.0% line
|
||||
coverage. The loop closes: a probe captures the exchange as a pair, a finding
|
||||
points at it, `finding_update` gives it a state, an asset records the host it
|
||||
came from, `cors_check`/`cookie_audit`/`http_options` turn a web answer into a
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ problem.
|
||||
|
||||
The supported line is the one printed by `apex-twin --version` for the tree you
|
||||
built; this document ships with that same tree. At the time of writing the line
|
||||
is **1.88.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.89.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
line. The 1.0 line promises that the on-disk JSON formats for findings, assets
|
||||
and traffic only gain fields, so state stays readable; older builds are still
|
||||
rebuilt rather than patched in place.
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.88.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.89.0" "User Commands"
|
||||
.SH NAME
|
||||
apex-twin \- scope\-gated offensive\-security MCP server
|
||||
.SH SYNOPSIS
|
||||
@@ -45,7 +45,7 @@ graphql_probe, docker_api_probe, elasticsearch_probe, imap_probe, pop3_probe,
|
||||
sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk,
|
||||
ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, dns_caa_check, sni_vhost_check, tls_client_auth_probe, kubernetes_api_probe,
|
||||
dns_ns_consistency, dns_dangling_cname, http_redirect_audit,
|
||||
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe, tls_chain_probe, smtp_auth_probe, jenkins_api_probe, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, zabbix_probe, datasette_probe, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe, vault_probe, nomad_probe, coredns_probe,
|
||||
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe, tls_chain_probe, smtp_auth_probe, jenkins_api_probe, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, zabbix_probe, datasette_probe, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe, vault_probe, nomad_probe, coredns_probe, openbmc_probe,
|
||||
nuclei_scan, nikto_scan, ffuf_scan, gobuster_scan, sqlmap_scan),
|
||||
defensive
|
||||
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
|
||||
@@ -96,6 +96,7 @@ nfs_conf_audit, idmapd_audit, netplan_audit,
|
||||
apt_auth_audit, aliases_audit, netgroup_audit, jetty_audit,
|
||||
dhclient_audit, journal_upload_audit, fwupd_audit,
|
||||
smartd_audit, tlog_audit, abrt_audit, freshclam_audit, tripwire_audit,
|
||||
fapolicyd_audit, systemd_timer_audit, yara_audit,
|
||||
php_fpm_audit, uwsgi_audit, lighttpd_audit)
|
||||
and ESP32 board tools (esp_info, esp_monitor,
|
||||
esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan,
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "1.88.0"
|
||||
#define APEX_VERSION "1.89.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -29011,6 +29011,512 @@ static void t_tripwire_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------- fapolicyd_audit */
|
||||
|
||||
/* fapolicyd decides which binaries may execute. Two settings take the teeth
|
||||
* out of it: "permissive = 1" only logs a would-be denial, and
|
||||
* "integrity = none" drops the hash check, so a replaced binary still runs.
|
||||
* In fapolicyd.rules the first match wins, so an allow-everything rule above
|
||||
* any deny rule is an open door for everything below it. */
|
||||
struct fap_state {
|
||||
int files;
|
||||
int permissive;
|
||||
int integrity_off;
|
||||
int allow_all;
|
||||
int seen_deny;
|
||||
int world_writable;
|
||||
};
|
||||
|
||||
static void fap_scan_rules(struct fap_state *st, const char *path,
|
||||
mcp_buf *findings, int *first, int *count)
|
||||
{
|
||||
static char text[65536];
|
||||
const char *p;
|
||||
|
||||
if (read_text(path, text, sizeof(text)) <= 0)
|
||||
return;
|
||||
st->files++;
|
||||
p = text;
|
||||
while (p != NULL && *p != '\0') {
|
||||
const char *eol = strchr(p, '\n');
|
||||
size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p);
|
||||
char line[1024];
|
||||
const char *s;
|
||||
char decision[16];
|
||||
size_t dl = 0;
|
||||
|
||||
if (len >= sizeof(line))
|
||||
len = sizeof(line) - 1;
|
||||
memcpy(line, p, len);
|
||||
line[len] = '\0';
|
||||
s = line;
|
||||
while (*s == ' ' || *s == '\t')
|
||||
s++;
|
||||
if (*s != '\0' && *s != '#') {
|
||||
while (s[dl] != '\0' && s[dl] != ' ' &&
|
||||
s[dl] != '\t' && s[dl] != '=' &&
|
||||
dl < sizeof(decision) - 1) {
|
||||
decision[dl] = s[dl];
|
||||
dl++;
|
||||
}
|
||||
decision[dl] = '\0';
|
||||
/* A deny before the allow-everything keeps a later one
|
||||
* harmless for that path, so only an allow-all seen be-
|
||||
* fore any deny is reported. */
|
||||
if (strcmp(decision, "deny") == 0)
|
||||
st->seen_deny = 1;
|
||||
else if (strcmp(decision, "allow") == 0 &&
|
||||
!st->seen_deny && !st->allow_all &&
|
||||
strstr(line, "all : all : all") != NULL) {
|
||||
st->allow_all = 1;
|
||||
add_finding(findings, first, "allow-everything",
|
||||
"high",
|
||||
"%s allows every program before any deny "
|
||||
"rule; nothing below it is ever reached",
|
||||
path);
|
||||
(*count)++;
|
||||
}
|
||||
}
|
||||
p = eol != NULL ? eol + 1 : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void t_fapolicyd_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char path[1024];
|
||||
char value[256];
|
||||
static char text[65536];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
struct fap_state st;
|
||||
struct stat sb;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 400) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
memset(&st, 0, sizeof(st));
|
||||
mcp_buf_init(&findings);
|
||||
snprintf(path, sizeof(path), "%.400s/etc/fapolicyd/fapolicyd.conf", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "cannot read fapolicyd.conf");
|
||||
return;
|
||||
}
|
||||
st.files++;
|
||||
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
|
||||
st.world_writable++;
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"%s is writable by any local user; it decides whether "
|
||||
"fapolicyd enforces or only logs", path);
|
||||
count++;
|
||||
}
|
||||
if (ini_value(text, "", "permissive", value, sizeof(value)) == 1 &&
|
||||
strcmp(value, "1") == 0) {
|
||||
st.permissive = 1;
|
||||
add_finding(&findings, &first, "permissive-mode", "high",
|
||||
"%s sets permissive = 1; a denied execution is only "
|
||||
"logged, never stopped", path);
|
||||
count++;
|
||||
}
|
||||
if (ini_value(text, "", "integrity", value, sizeof(value)) == 1 &&
|
||||
(strcmp(value, "none") == 0 || strcmp(value, "0") == 0)) {
|
||||
st.integrity_off = 1;
|
||||
add_finding(&findings, &first, "no-integrity", "medium",
|
||||
"%s sets integrity = %s; a replaced binary still "
|
||||
"matches its allow rule", path, value);
|
||||
count++;
|
||||
}
|
||||
snprintf(path, sizeof(path), "%.400s/etc/fapolicyd/fapolicyd.rules",
|
||||
root);
|
||||
fap_scan_rules(&st, path, &findings, &first, &count);
|
||||
if (st.files == 1 && st.allow_all == 0 && count == 0) {
|
||||
add_finding(&findings, &first, "no-rules", "medium",
|
||||
"%.400s/etc/fapolicyd/fapolicyd.rules cannot be read; "
|
||||
"the policy has no allow or deny rules", root);
|
||||
count++;
|
||||
}
|
||||
if (count == 0)
|
||||
add_finding(&findings, &first, "no-findings", "info",
|
||||
"fapolicyd enforces, checks integrity and its rules "
|
||||
"start with a deny");
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"files\":%d,\"permissive\":%s,"
|
||||
"\"integrity_off\":%s,\"allow_everything\":%s,"
|
||||
"\"world_writable\":%d,\"findings_count\":%d,\"findings\":[",
|
||||
st.files, st.permissive ? "true" : "false",
|
||||
st.integrity_off ? "true" : "false",
|
||||
st.allow_all ? "true" : "false",
|
||||
st.world_writable, count);
|
||||
if (findings.p != NULL)
|
||||
mcp_buf_add(&b, findings.p, findings.len);
|
||||
mcp_buf_puts(&b, "]}");
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------- systemd_timer_audit */
|
||||
|
||||
/* A .timer unit says when, the matching .service says what. Two patterns let a
|
||||
* compromised account keep a foothold: OnCalendar with a very short interval
|
||||
* (a beacon every minute) and Persistent=true, which fires a missed run right
|
||||
* after boot. A timer whose service has no User= runs as root. A unit file
|
||||
* writable by anyone is a direct edit of the schedule. */
|
||||
struct timer_state {
|
||||
int units;
|
||||
int timers;
|
||||
int short_interval;
|
||||
int persistent;
|
||||
int no_user;
|
||||
int world_writable;
|
||||
};
|
||||
|
||||
/* systemd unit files put each key under a section header, so a plain
|
||||
* "section-less" lookup would never see User= or Persistent=. Unit keys are
|
||||
* unique across sections in practice, so searching every line is enough. */
|
||||
static int unit_value(const char *text, const char *key, char *out, size_t n)
|
||||
{
|
||||
const char *p = text;
|
||||
size_t kl = strlen(key);
|
||||
|
||||
out[0] = '\0';
|
||||
while (p != NULL && *p != '\0') {
|
||||
const char *eol = strchr(p, '\n');
|
||||
size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p);
|
||||
char line[1024];
|
||||
const char *s;
|
||||
|
||||
if (len >= sizeof(line))
|
||||
len = sizeof(line) - 1;
|
||||
memcpy(line, p, len);
|
||||
line[len] = '\0';
|
||||
s = line;
|
||||
while (*s == ' ' || *s == '\t')
|
||||
s++;
|
||||
if (*s != '#' && *s != ';' && *s != '[' &&
|
||||
strncasecmp(s, key, kl) == 0 && s[kl] == '=') {
|
||||
const char *v = s + kl + 1;
|
||||
size_t vl;
|
||||
|
||||
while (*v == ' ' || *v == '\t')
|
||||
v++;
|
||||
vl = strlen(v);
|
||||
while (vl > 0 && (v[vl - 1] == ' ' || v[vl - 1] == '\t' ||
|
||||
v[vl - 1] == '\r'))
|
||||
vl--;
|
||||
if (vl >= n)
|
||||
vl = n - 1;
|
||||
memcpy(out, v, vl);
|
||||
out[vl] = '\0';
|
||||
return 1;
|
||||
}
|
||||
p = eol != NULL ? eol + 1 : NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int timer_path_is_unit(const char *name)
|
||||
{
|
||||
size_t n = strlen(name);
|
||||
|
||||
if (n > 6 && strcmp(name + n - 6, ".timer") == 0)
|
||||
return 1;
|
||||
if (n > 8 && strcmp(name + n - 8, ".service") == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void timer_scan_dir(struct timer_state *st, const char *dir,
|
||||
mcp_buf *findings, int *first, int *count)
|
||||
{
|
||||
DIR *d = opendir(dir);
|
||||
struct dirent *ent;
|
||||
|
||||
if (d == NULL)
|
||||
return;
|
||||
while ((ent = readdir(d)) != NULL) {
|
||||
char path[1400];
|
||||
static char text[65536];
|
||||
struct stat sb;
|
||||
char value[256];
|
||||
char line[1024];
|
||||
const char *p;
|
||||
|
||||
if (ent->d_name[0] == '.')
|
||||
continue;
|
||||
if (!timer_path_is_unit(ent->d_name))
|
||||
continue;
|
||||
snprintf(path, sizeof(path), "%.1000s/%.200s", dir, ent->d_name);
|
||||
if (read_text(path, text, sizeof(text)) <= 0)
|
||||
continue;
|
||||
st->units++;
|
||||
if (strstr(ent->d_name, ".timer") != NULL)
|
||||
st->timers++;
|
||||
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
|
||||
st->world_writable++;
|
||||
add_finding(findings, first, "world-writable", "high",
|
||||
"%s is writable by any local user; anyone can "
|
||||
"add a job to the schedule", path);
|
||||
(*count)++;
|
||||
}
|
||||
if (strstr(ent->d_name, ".service") != NULL) {
|
||||
if (unit_value(text, "User", value, sizeof(value)) != 1) {
|
||||
st->no_user++;
|
||||
add_finding(findings, first, "service-as-root",
|
||||
"medium",
|
||||
"%s sets no User=; the timer's job runs as "
|
||||
"root", path);
|
||||
(*count)++;
|
||||
}
|
||||
}
|
||||
if (strstr(ent->d_name, ".timer") == NULL)
|
||||
continue;
|
||||
if (unit_value(text, "Persistent", value, sizeof(value)) == 1 &&
|
||||
strcasecmp(value, "true") == 0) {
|
||||
st->persistent++;
|
||||
add_finding(findings, first, "persistent-timer", "low",
|
||||
"%s sets Persistent=true; a missed run fires "
|
||||
"immediately after boot", path);
|
||||
(*count)++;
|
||||
}
|
||||
p = text;
|
||||
while (p != NULL && *p != '\0') {
|
||||
const char *eol = strchr(p, '\n');
|
||||
size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p);
|
||||
const char *s;
|
||||
|
||||
if (len >= sizeof(line))
|
||||
len = sizeof(line) - 1;
|
||||
memcpy(line, p, len);
|
||||
line[len] = '\0';
|
||||
s = line;
|
||||
while (*s == ' ' || *s == '\t')
|
||||
s++;
|
||||
/* OnCalendar=*:*:00 is systemd's every-minute form;
|
||||
* OnUnitActiveSec=60s is the same through a monotonic
|
||||
* timer. Both keep a host busy and are easy to spot. */
|
||||
if (strncasecmp(s, "OnCalendar=", 11) == 0 &&
|
||||
strstr(s + 11, "*:*:00") != NULL) {
|
||||
st->short_interval++;
|
||||
add_finding(findings, first, "every-minute",
|
||||
"medium",
|
||||
"%s fires every minute; a beacon needs "
|
||||
"no cron entry to stay alive", path);
|
||||
(*count)++;
|
||||
}
|
||||
if (strncasecmp(s, "OnUnitActiveSec=", 16) == 0 &&
|
||||
strtoul(s + 16, NULL, 10) <= 60 &&
|
||||
strchr(s + 16, 's') != NULL) {
|
||||
st->short_interval++;
|
||||
add_finding(findings, first, "short-interval",
|
||||
"medium",
|
||||
"%s reactivates after %s; that is a "
|
||||
"beacon interval, not a maintenance run",
|
||||
path, s + 16);
|
||||
(*count)++;
|
||||
}
|
||||
p = eol != NULL ? eol + 1 : NULL;
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static void t_systemd_timer_audit(mcp_conn *c, const mcp_json *args,
|
||||
void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char dir[1200];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
struct timer_state st;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int i;
|
||||
static const char *dirs[] = { "/etc/systemd/system",
|
||||
"/etc/systemd/system/timers.target.wants",
|
||||
"/run/systemd/system", NULL };
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 300) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
memset(&st, 0, sizeof(st));
|
||||
mcp_buf_init(&findings);
|
||||
for (i = 0; dirs[i] != NULL; i++) {
|
||||
snprintf(dir, sizeof(dir), "%.300s%s", root, dirs[i]);
|
||||
timer_scan_dir(&st, dir, &findings, &first, &count);
|
||||
}
|
||||
if (st.units == 0) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "cannot read any systemd timer or service unit");
|
||||
return;
|
||||
}
|
||||
if (count == 0)
|
||||
add_finding(&findings, &first, "no-findings", "info",
|
||||
"every timer runs as a named user on a maintenance "
|
||||
"schedule and none of the unit files is writable");
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"units\":%d,\"timers\":%d,"
|
||||
"\"short_interval\":%d,\"persistent\":%d,"
|
||||
"\"no_user\":%d,\"world_writable\":%d,"
|
||||
"\"findings_count\":%d,\"findings\":[",
|
||||
st.units, st.timers, st.short_interval, st.persistent,
|
||||
st.no_user, st.world_writable, count);
|
||||
if (findings.p != NULL)
|
||||
mcp_buf_add(&b, findings.p, findings.len);
|
||||
mcp_buf_puts(&b, "]}");
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- yara_audit */
|
||||
|
||||
/* A YARA scanner is only as strict as its rule set. A rule file in a directory
|
||||
* any local user can write lets that user add an "exclude everything" rule, and
|
||||
* a rule set that is never reloaded checks yesterday's signatures. The audit
|
||||
* reads yara.conf when present, otherwise scans the usual rule directories for
|
||||
* writable .yar/.yara files and checks that scanning is not switched off. */
|
||||
struct yara_state {
|
||||
int rule_files;
|
||||
int writable_rules;
|
||||
int disabled;
|
||||
int empty_rules;
|
||||
};
|
||||
|
||||
static void yara_scan_dir(struct yara_state *st, const char *dir,
|
||||
mcp_buf *findings, int *first, int *count, int depth)
|
||||
{
|
||||
DIR *d;
|
||||
struct dirent *ent;
|
||||
|
||||
if (depth > 3)
|
||||
return;
|
||||
d = opendir(dir);
|
||||
if (d == NULL)
|
||||
return;
|
||||
while ((ent = readdir(d)) != NULL) {
|
||||
char path[1400];
|
||||
struct stat sb;
|
||||
size_t n;
|
||||
|
||||
if (ent->d_name[0] == '.')
|
||||
continue;
|
||||
snprintf(path, sizeof(path), "%.1000s/%.200s", dir, ent->d_name);
|
||||
if (stat(path, &sb) != 0)
|
||||
continue;
|
||||
if (S_ISDIR(sb.st_mode)) {
|
||||
yara_scan_dir(st, path, findings, first, count, depth + 1);
|
||||
continue;
|
||||
}
|
||||
n = strlen(ent->d_name);
|
||||
if (!(n > 4 && strcmp(ent->d_name + n - 4, ".yar") == 0) &&
|
||||
!(n > 5 && strcmp(ent->d_name + n - 5, ".yara") == 0))
|
||||
continue;
|
||||
st->rule_files++;
|
||||
if (sb.st_size == 0) {
|
||||
st->empty_rules++;
|
||||
add_finding(findings, first, "empty-rule-file", "low",
|
||||
"%s is an empty rule file; it matches nothing",
|
||||
path);
|
||||
(*count)++;
|
||||
}
|
||||
if ((sb.st_mode & 0002) != 0) {
|
||||
st->writable_rules++;
|
||||
add_finding(findings, first, "writable-rule", "high",
|
||||
"%s is writable by any local user; a rule that "
|
||||
"excludes a path can be added", path);
|
||||
(*count)++;
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static void t_yara_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char path[1200];
|
||||
static char text[65536];
|
||||
char value[256];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
struct yara_state st;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int i;
|
||||
static const char *files[] = { "/etc/yara/yara.conf",
|
||||
"/etc/yara.conf", NULL };
|
||||
static const char *dirs[] = { "/etc/yara/rules",
|
||||
"/usr/share/yara/rules",
|
||||
"/var/lib/yara/rules", NULL };
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 300) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
memset(&st, 0, sizeof(st));
|
||||
mcp_buf_init(&findings);
|
||||
for (i = 0; files[i] != NULL; i++) {
|
||||
snprintf(path, sizeof(path), "%.300s%s", root, files[i]);
|
||||
if (read_text(path, text, sizeof(text)) <= 0)
|
||||
continue;
|
||||
if (ini_value(text, "", "enabled", value, sizeof(value)) == 1 &&
|
||||
(strcmp(value, "no") == 0 || strcmp(value, "0") == 0 ||
|
||||
strcasecmp(value, "false") == 0)) {
|
||||
st.disabled++;
|
||||
add_finding(&findings, &first, "scanning-disabled", "high",
|
||||
"%s disables scanning; nothing is checked at "
|
||||
"all", path);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
for (i = 0; dirs[i] != NULL; i++) {
|
||||
snprintf(path, sizeof(path), "%.300s%s", root, dirs[i]);
|
||||
yara_scan_dir(&st, path, &findings, &first, &count, 0);
|
||||
}
|
||||
if (count == 0 && st.rule_files == 0) {
|
||||
add_finding(&findings, &first, "no-rules", "medium",
|
||||
"no YARA rule file is readable under %.300s; the "
|
||||
"scanner has nothing to match", root);
|
||||
count++;
|
||||
}
|
||||
if (count == 0)
|
||||
add_finding(&findings, &first, "no-findings", "info",
|
||||
"every YARA rule file is readable by its owner only "
|
||||
"and non-empty");
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"rule_files\":%d,\"writable_rules\":%d,"
|
||||
"\"disabled\":%d,\"empty_rules\":%d,"
|
||||
"\"findings_count\":%d,\"findings\":[",
|
||||
st.rule_files, st.writable_rules, st.disabled,
|
||||
st.empty_rules, count);
|
||||
if (findings.p != NULL)
|
||||
mcp_buf_add(&b, findings.p, findings.len);
|
||||
mcp_buf_puts(&b, "]}");
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
const mcp_tool TOOLS_BLUE[] = {
|
||||
{ "hardening_audit",
|
||||
"Read-only posture audit of the local host: sshd_config (root login, "
|
||||
@@ -30626,6 +31132,27 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_tripwire_audit },
|
||||
{ "fapolicyd_audit",
|
||||
"Read fapolicyd.conf and fapolicyd.rules (root prefix): permissive = 1, "
|
||||
"integrity = none, an allow-everything rule before any deny rule and a "
|
||||
"world-writable config. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_fapolicyd_audit },
|
||||
{ "systemd_timer_audit",
|
||||
"Scan systemd unit directories (root prefix) for .timer and .service "
|
||||
"files: an every-minute or sub-minute interval, Persistent=true, a "
|
||||
"service without User= and a world-writable unit file. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_systemd_timer_audit },
|
||||
{ "yara_audit",
|
||||
"Scan YARA configuration and rule directories (root prefix): scanning "
|
||||
"disabled, a world-writable or empty rule file and a rule set that does "
|
||||
"not exist. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_yara_audit },
|
||||
};
|
||||
|
||||
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
|
||||
+109
@@ -9212,6 +9212,105 @@ static void t_vault_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ openbmc_probe */
|
||||
|
||||
/* OpenBMC exposes Redfish and the legacy xyz.openbmc_project REST tree over
|
||||
* HTTPS. /redfish/v1/ answers without a session on every build, so it only
|
||||
* proves the service exists; the xyz tree, /xyz/openbmc_project/state/host0 and
|
||||
* the manager list are the parts that need a session. A 2xx on one of those
|
||||
* without credentials means power control and firmware update over the network
|
||||
* for whoever reaches the port. */
|
||||
static void t_openbmc_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
static const char *paths[] = {
|
||||
"/redfish/v1/",
|
||||
"/redfish/v1/Systems",
|
||||
"/xyz/openbmc_project/",
|
||||
"/xyz/openbmc_project/state/host0",
|
||||
"/xyz/openbmc_project/control/host0/power_restore_policy",
|
||||
NULL
|
||||
};
|
||||
const char *target = mcp_arg_string(args, "target");
|
||||
int port = mcp_arg_int(args, "port", 443);
|
||||
int tls = mcp_arg_bool(args, "tls", 1);
|
||||
mcp_buf b;
|
||||
int first = 1;
|
||||
int tested = 0;
|
||||
int open_count = 0;
|
||||
int redfish = 0;
|
||||
int control_open = 0;
|
||||
char *evidence = NULL;
|
||||
int i;
|
||||
|
||||
(void)user;
|
||||
if (target == NULL || *target == '\0') {
|
||||
mcp_reply_error(c, "target is required");
|
||||
return;
|
||||
}
|
||||
if (port <= 0 || port > 65535) {
|
||||
mcp_reply_error(c, "port out of range");
|
||||
return;
|
||||
}
|
||||
if (!gated(c, "openbmc_probe", target, port))
|
||||
return;
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"target\":");
|
||||
apex_json_str(&b, target);
|
||||
mcp_buf_printf(&b, ",\"port\":%d,\"tls\":%s,\"endpoints\":[", port,
|
||||
tls ? "true" : "false");
|
||||
for (i = 0; paths[i] != NULL; i++) {
|
||||
char status[256];
|
||||
char *resp = NULL;
|
||||
size_t len = 0;
|
||||
int code;
|
||||
int open;
|
||||
int is_control = strstr(paths[i], "/control/") != NULL;
|
||||
|
||||
status[0] = '\0';
|
||||
if (apex_http_once(target, port, tls, "GET", paths[i], NULL, NULL,
|
||||
8000, &resp, &len, status,
|
||||
sizeof(status)) != 0)
|
||||
continue;
|
||||
tested++;
|
||||
code = apex_status_code(status);
|
||||
open = code >= 200 && code < 300;
|
||||
if (open)
|
||||
open_count++;
|
||||
if (open && strstr(paths[i], "/redfish/v1/") != NULL)
|
||||
redfish = 1;
|
||||
if (open && is_control) {
|
||||
control_open = 1;
|
||||
if (evidence == NULL)
|
||||
evidence = apex_evidence_save("openbmc-control", resp,
|
||||
len);
|
||||
}
|
||||
if (!first)
|
||||
mcp_buf_puts(&b, ",");
|
||||
first = 0;
|
||||
mcp_buf_puts(&b, "{\"path\":");
|
||||
apex_json_str(&b, paths[i]);
|
||||
mcp_buf_printf(&b, ",\"status\":%d,\"bytes\":%lu,\"open\":%s}",
|
||||
code, (unsigned long)len, open ? "true" : "false");
|
||||
free(resp);
|
||||
}
|
||||
mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d,"
|
||||
"\"redfish\":%s,\"control_open\":%s,\"evidence\":",
|
||||
tested, open_count, redfish ? "true" : "false",
|
||||
control_open ? "true" : "false");
|
||||
if (evidence != NULL)
|
||||
apex_json_str(&b, evidence);
|
||||
else
|
||||
mcp_buf_puts(&b, "null");
|
||||
mcp_buf_puts(&b, "}");
|
||||
apex_audit("openbmc_probe", target, port, !control_open,
|
||||
control_open
|
||||
? "the OpenBMC host control tree answers without a session"
|
||||
: "the OpenBMC control tree requires a session", "list");
|
||||
mcp_reply_json(c, b.p);
|
||||
free(evidence);
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- coredns_probe */
|
||||
|
||||
/* CoreDNS serves its health and metrics on plain HTTP (:8080 health, :9153
|
||||
@@ -10756,6 +10855,16 @@ const mcp_tool TOOLS_RED[] = {
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_vault_probe },
|
||||
{ "openbmc_probe",
|
||||
"Get the Redfish root and the xyz.openbmc_project tree on 443 without a "
|
||||
"session. A 2xx on the host control tree means power control and "
|
||||
"firmware update are open; the answer is saved as evidence.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"target\":{\"type\":\"string\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"},"
|
||||
"\"tls\":{\"type\":\"boolean\",\"description\":\"default true\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_openbmc_probe },
|
||||
{ "coredns_probe",
|
||||
"Get /health, /metrics and the caddy plugin API /config/ on 2019 "
|
||||
"without a token. A 2xx on /config/ means the DNS server blocks can be "
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import re
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
EXPECTED_TOOLS = 385
|
||||
EXPECTED_TOOLS = 389
|
||||
GATE = ("gated(", "gated_cmd(", "gated_run(", "apex_scope_check(")
|
||||
# Handlers may hand argv to a shared runner instead of calling the gate
|
||||
# themselves. That runner has to call the gate; both halves are checked
|
||||
|
||||
+216
-2
@@ -134,7 +134,7 @@ res, _ = run([
|
||||
], home=empty)
|
||||
check("tools/list answers", any(r.get("id") == 1 for r in res))
|
||||
tools = [r for r in res if r.get("id") == 1][0]["result"]["tools"]
|
||||
check("385 tools registered", len(tools) == 385, len(tools))
|
||||
check("389 tools registered", len(tools) == 389, len(tools))
|
||||
names = {t["name"] for t in tools}
|
||||
for need in ("portscan", "nmap", "http_request", "marauder_scan",
|
||||
"method_playbook", "finding_add", "finding_update", "scope_check",
|
||||
@@ -1560,7 +1560,7 @@ try:
|
||||
check("http initialize", init["result"]["serverInfo"]["name"] == "apex-twin",
|
||||
init)
|
||||
listing = post({"jsonrpc": "2.0", "id": 2, "method": "tools/list"})
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 385)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 389)
|
||||
shown = post(call(3, "scope_show"))
|
||||
check("http scope_show", '"loaded":true' in shown["result"]["content"][0]["text"])
|
||||
# the id must be the request's id, not one found inside the arguments
|
||||
@@ -17343,6 +17343,220 @@ cd_open_srv.shutdown()
|
||||
for d in (fc_root, fc_good_root, tw_root, tw_good_root, cfg59_home):
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
|
||||
# --- 1.89.0: fapolicyd, systemd timer and yara audits plus the OpenBMC probe ---
|
||||
print("\n== fapolicyd, systemd timers, yara and OpenBMC ==")
|
||||
|
||||
fap_root = tempfile.mkdtemp(prefix="apex-fap-")
|
||||
os.makedirs(os.path.join(fap_root, "etc", "fapolicyd"))
|
||||
fap_bad = os.path.join(fap_root, "etc", "fapolicyd", "fapolicyd.conf")
|
||||
with open(fap_bad, "w") as f:
|
||||
f.write("# fapolicyd\n")
|
||||
f.write("permissive = 1\n")
|
||||
f.write("integrity = none\n")
|
||||
os.chmod(fap_bad, 0o666)
|
||||
fap_rules = os.path.join(fap_root, "etc", "fapolicyd", "fapolicyd.rules")
|
||||
with open(fap_rules, "w") as f:
|
||||
f.write("allow all : all : all\n")
|
||||
f.write("deny all : all : all\n")
|
||||
os.chmod(fap_rules, 0o644)
|
||||
|
||||
fap_good_root = tempfile.mkdtemp(prefix="apex-fapg-")
|
||||
os.makedirs(os.path.join(fap_good_root, "etc", "fapolicyd"))
|
||||
fap_good = os.path.join(fap_good_root, "etc", "fapolicyd", "fapolicyd.conf")
|
||||
with open(fap_good, "w") as f:
|
||||
f.write("permissive = 0\n")
|
||||
f.write("integrity = sha256\n")
|
||||
os.chmod(fap_good, 0o640)
|
||||
fap_good_rules = os.path.join(fap_good_root, "etc", "fapolicyd",
|
||||
"fapolicyd.rules")
|
||||
with open(fap_good_rules, "w") as f:
|
||||
f.write("deny all : all : all\n")
|
||||
f.write("allow exe=/usr/bin/bash : all : all\n")
|
||||
os.chmod(fap_good_rules, 0o640)
|
||||
|
||||
tm_root = tempfile.mkdtemp(prefix="apex-tmr-")
|
||||
tm_units = os.path.join(tm_root, "etc", "systemd", "system")
|
||||
os.makedirs(tm_units)
|
||||
tm_timer = os.path.join(tm_units, "beacon.timer")
|
||||
with open(tm_timer, "w") as f:
|
||||
f.write("[Unit]\n")
|
||||
f.write("Description=Beacon\n")
|
||||
f.write("[Timer]\n")
|
||||
f.write("OnCalendar=*:*:00\n")
|
||||
f.write("Persistent=true\n")
|
||||
os.chmod(tm_timer, 0o666)
|
||||
tm_service = os.path.join(tm_units, "beacon.service")
|
||||
with open(tm_service, "w") as f:
|
||||
f.write("[Service]\n")
|
||||
f.write("ExecStart=/usr/local/bin/beacon\n")
|
||||
os.chmod(tm_service, 0o644)
|
||||
tm_sub = os.path.join(tm_units, "poll.timer")
|
||||
with open(tm_sub, "w") as f:
|
||||
f.write("[Timer]\n")
|
||||
f.write("OnUnitActiveSec=30s\n")
|
||||
os.chmod(tm_sub, 0o644)
|
||||
|
||||
tm_good_root = tempfile.mkdtemp(prefix="apex-tmg-")
|
||||
tm_good_units = os.path.join(tm_good_root, "etc", "systemd", "system")
|
||||
os.makedirs(tm_good_units)
|
||||
tm_good_timer = os.path.join(tm_good_units, "backup.timer")
|
||||
with open(tm_good_timer, "w") as f:
|
||||
f.write("[Timer]\n")
|
||||
f.write("OnCalendar=daily\n")
|
||||
os.chmod(tm_good_timer, 0o644)
|
||||
tm_good_service = os.path.join(tm_good_units, "backup.service")
|
||||
with open(tm_good_service, "w") as f:
|
||||
f.write("[Service]\n")
|
||||
f.write("User=backup\n")
|
||||
f.write("ExecStart=/usr/local/bin/backup\n")
|
||||
os.chmod(tm_good_service, 0o644)
|
||||
|
||||
yr_root = tempfile.mkdtemp(prefix="apex-yr-")
|
||||
yr_rules = os.path.join(yr_root, "etc", "yara", "rules")
|
||||
os.makedirs(yr_rules)
|
||||
yr_bad = os.path.join(yr_rules, "evil.yar")
|
||||
with open(yr_bad, "w") as f:
|
||||
f.write("rule anything { condition: true }\n")
|
||||
os.chmod(yr_bad, 0o666)
|
||||
yr_empty = os.path.join(yr_rules, "empty.yara")
|
||||
with open(yr_empty, "w") as f:
|
||||
f.write("")
|
||||
os.chmod(yr_empty, 0o644)
|
||||
|
||||
yr_good_root = tempfile.mkdtemp(prefix="apex-yrg-")
|
||||
yr_good_rules = os.path.join(yr_good_root, "etc", "yara", "rules")
|
||||
os.makedirs(yr_good_rules)
|
||||
yr_good_rule = os.path.join(yr_good_rules, "malware.yar")
|
||||
with open(yr_good_rule, "w") as f:
|
||||
f.write("rule malware { strings: $a = \"evil\" condition: $a }\n")
|
||||
os.chmod(yr_good_rule, 0o644)
|
||||
|
||||
|
||||
class _OpenBMCHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
if path == "/redfish/v1/":
|
||||
body = b'{"RedfishVersion":"1.15.0"}'
|
||||
self.send_response(200)
|
||||
elif path in ("/redfish/v1/Systems",):
|
||||
body = b'{"Members":[]}'
|
||||
self.send_response(401)
|
||||
elif path == "/xyz/openbmc_project/":
|
||||
body = b'{"data":["state","control"]}'
|
||||
self.send_response(401)
|
||||
elif path == "/xyz/openbmc_project/control/host0/power_restore_policy":
|
||||
body = b'{"data":"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn"}'
|
||||
self.send_response(401)
|
||||
else:
|
||||
body = b'{"error":"not found"}'
|
||||
self.send_response(404)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
class _OpenBMCControlHandler(_OpenBMCHandler):
|
||||
def do_GET(self):
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
if path == "/xyz/openbmc_project/control/host0/power_restore_policy":
|
||||
body = b'{"data":"RestorePolicy.AlwaysOn","status":"ok"}'
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
return
|
||||
_OpenBMCHandler.do_GET(self)
|
||||
|
||||
|
||||
ob_srv = http.server.HTTPServer(("127.0.0.1", 0), _OpenBMCHandler)
|
||||
ob_port = ob_srv.server_address[1]
|
||||
ob_open_srv = http.server.HTTPServer(("127.0.0.1", 0),
|
||||
_OpenBMCControlHandler)
|
||||
ob_open_port = ob_open_srv.server_address[1]
|
||||
for _s in (ob_srv, ob_open_srv):
|
||||
threading.Thread(target=_s.serve_forever, daemon=True).start()
|
||||
|
||||
cfg60_home = tempfile.mkdtemp(prefix="apex-cfg60-home-")
|
||||
write_scope(cfg60_home,
|
||||
{"label": "cfg60", "expires": "2099-01-01T00:00:00Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"allow_port": ["1-65535"]})
|
||||
|
||||
res, _ = run([
|
||||
call(1, "fapolicyd_audit", root=fap_root),
|
||||
call(2, "fapolicyd_audit", root=fap_good_root),
|
||||
call(3, "systemd_timer_audit", root=tm_root),
|
||||
call(4, "systemd_timer_audit", root=tm_good_root),
|
||||
call(5, "yara_audit", root=yr_root),
|
||||
call(6, "yara_audit", root=yr_good_root),
|
||||
call(7, "openbmc_probe", target="127.0.0.1", port=ob_port, tls=False),
|
||||
call(8, "openbmc_probe", target="127.0.0.1", port=ob_open_port, tls=False),
|
||||
], home=cfg60_home)
|
||||
by_id = {r["id"]: r for r in res if "id" in r}
|
||||
fapa = json.loads(text(by_id[1]))
|
||||
fapa_kinds = {f["id"] for f in fapa["findings"]}
|
||||
check("fapolicyd_audit flags permissive mode, no integrity, allow-everything "
|
||||
"and a writable config",
|
||||
{"permissive-mode", "no-integrity", "allow-everything",
|
||||
"world-writable"} <= fapa_kinds and fapa["permissive"] is True and
|
||||
fapa["integrity_off"] is True and
|
||||
fapa["allow_everything"] is True, fapa)
|
||||
fapa_good = json.loads(text(by_id[2]))
|
||||
check("fapolicyd_audit accepts enforcing mode with a deny-first ruleset",
|
||||
fapa_good["findings_count"] == 0 and
|
||||
fapa_good["findings"][0]["id"] == "no-findings" and
|
||||
fapa_good["permissive"] is False and
|
||||
fapa_good["allow_everything"] is False, fapa_good)
|
||||
|
||||
tma = json.loads(text(by_id[3]))
|
||||
tma_kinds = {f["id"] for f in tma["findings"]}
|
||||
check("systemd_timer_audit flags an every-minute timer, Persistent, a "
|
||||
"root service and a writable unit",
|
||||
{"every-minute", "persistent-timer", "service-as-root",
|
||||
"world-writable", "short-interval"} <= tma_kinds and
|
||||
tma["timers"] == 2 and tma["units"] == 3 and
|
||||
tma["short_interval"] == 2, tma)
|
||||
tma_good = json.loads(text(by_id[4]))
|
||||
check("systemd_timer_audit accepts a daily timer with a named user",
|
||||
tma_good["findings_count"] == 0 and
|
||||
tma_good["findings"][0]["id"] == "no-findings" and
|
||||
tma_good["short_interval"] == 0 and tma_good["no_user"] == 0,
|
||||
tma_good)
|
||||
|
||||
yra = json.loads(text(by_id[5]))
|
||||
yra_kinds = {f["id"] for f in yra["findings"]}
|
||||
check("yara_audit flags a writable rule file and an empty one",
|
||||
{"writable-rule", "empty-rule-file"} <= yra_kinds and
|
||||
yra["rule_files"] == 2 and yra["writable_rules"] == 1 and
|
||||
yra["empty_rules"] == 1, yra)
|
||||
yra_good = json.loads(text(by_id[6]))
|
||||
check("yara_audit accepts a readable non-empty rule set",
|
||||
yra_good["findings_count"] == 0 and
|
||||
yra_good["findings"][0]["id"] == "no-findings" and
|
||||
yra_good["rule_files"] == 1 and yra_good["writable_rules"] == 0,
|
||||
yra_good)
|
||||
|
||||
ob = json.loads(text(by_id[7]))
|
||||
check("openbmc_probe reports a session-protected control tree as closed",
|
||||
ob["control_open"] is False and ob["redfish"] is True and
|
||||
ob["evidence"] is None and ob["open_count"] == 1, ob)
|
||||
ob_open = json.loads(text(by_id[8]))
|
||||
check("openbmc_probe finds the open control tree and saves evidence",
|
||||
ob_open["control_open"] is True and ob_open["evidence"] is not None and
|
||||
os.path.isfile(ob_open["evidence"]) and
|
||||
"RestorePolicy" in open(ob_open["evidence"]).read(), ob_open)
|
||||
|
||||
ob_srv.shutdown()
|
||||
ob_open_srv.shutdown()
|
||||
for d in (fap_root, fap_good_root, tm_root, tm_good_root, yr_root,
|
||||
yr_good_root, cfg60_home):
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
|
||||
# --- 1.84.0: gated wrappers for external scanners (mock binaries) ---
|
||||
print("\n== external scanner wrappers ==\n")
|
||||
|
||||
|
||||
Reference in new issue
Block a user