Re-architect Sentinel as a zero-dependency Python package
Port the bash prototype to a structured, testable Python codebase while
preserving the same control loop and the seven detection signatures. The bash
implementation stays in src/ as the regression oracle.
Highlights:
- enodia_sentinel/ package (stdlib only — no runtime deps):
- detectors/ : one pure function per signature, detect(state, cfg)->Alerts
- system.py : SystemState — one cached /proc + ss snapshot per sweep,
fully injectable so detectors are unit-testable
- daemon.py : sweep loop, in-process cooldown dedup, threaded snapshot
capture, and a SUID filesystem scan moved OFF the loop
thread onto a slow background cadence
- snapshot.py: forensic text + JSON sidecar with per-signature IR guidance
- config.py : dataclass config via TOML + env overrides
- netutil.py : public-IP / CIDR logic via stdlib ipaddress
- tests/ : 25 stdlib-unittest cases (no root, no /proc, no ss needed)
- TOML config, launcher wrapper, Makefile (pip-free install), hardened
systemd unit (env-resolved ExecStart), updated PKGBUILD, rewritten README
Performance: per-sweep cost ~200 ms (shared cached state); the multi-second
SUID walk no longer blocks detection. scandir-based walk replaces os.walk.
Verified on Arch: all 7 detectors fire on red-team drills (reverse_shell,
ld_preload, deleted_exe, new_listener, new_suid confirmed live end-to-end),
no false positives on a clean sweep, 25/25 tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
45f8acb24a
commit
28d67a1360
28 changed files with 1783 additions and 133 deletions
|
|
@ -35,14 +35,25 @@ trap cleanup EXIT INT TERM
|
|||
|
||||
note() { echo -e "\n=== DRILL: $1 ===\n $2"; }
|
||||
|
||||
# A tiny TCP listener that accepts one connection and holds it open (no EOF, no
|
||||
# data) for $HOLD seconds. Python is always present and, unlike some nc/ncat
|
||||
# builds, won't half-close and tear the connection down before detection.
|
||||
drill_listener() { # $1 = port
|
||||
python3 -c 'import socket,sys,time
|
||||
s=socket.socket(); s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
|
||||
s.bind(("127.0.0.1",int(sys.argv[1]))); s.listen(1)
|
||||
try:
|
||||
c,_=s.accept(); time.sleep(int(sys.argv[2]))
|
||||
except Exception: pass' "$1" "$HOLD" >/dev/null 2>&1 &
|
||||
PIDS+=("$!")
|
||||
}
|
||||
|
||||
drill_reverse_shell() {
|
||||
note reverse_shell "a bash with a TCP socket wired to its stdin/stdout (classic reverse shell)"
|
||||
# Local listener stands in for the attacker's box. No remote traffic leaves.
|
||||
( exec -a enodia-drill-listener nc -l 127.0.0.1 "$LISTEN_PORT" >/dev/null 2>&1 ) &
|
||||
PIDS+=("$!")
|
||||
sleep 1 # let the listener bind (single-shot nc; don't probe-connect it)
|
||||
drill_listener "$LISTEN_PORT"
|
||||
sleep 1
|
||||
# bash whose fd 0/1/2 are the socket — exactly what `nc -e /bin/bash` produces.
|
||||
# The shell retries the connect itself so it wins the listener's accept slot.
|
||||
# It then BLOCKS reading the socket (like a real reverse shell awaiting
|
||||
# commands) so the process holding the socket stays a 'bash', not a sleep.
|
||||
( exec -a enodia-drill-rsh bash -c \
|
||||
|
|
@ -73,9 +84,8 @@ drill_deleted_exe() {
|
|||
|
||||
drill_new_listener() {
|
||||
note new_listener "a new TCP listening port that wasn't in the baseline"
|
||||
( exec -a enodia-drill-bind nc -l 127.0.0.1 $((LISTEN_PORT+1)) >/dev/null 2>&1 ) &
|
||||
PIDS+=("$!")
|
||||
echo " -> opened listener on 127.0.0.1:$((LISTEN_PORT+1)) (pid $!)"
|
||||
drill_listener $((LISTEN_PORT+1))
|
||||
echo " -> opened listener on 127.0.0.1:$((LISTEN_PORT+1)) (pid ${PIDS[-1]})"
|
||||
}
|
||||
|
||||
drill_new_suid() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue