fix(ssh-capture): hide watcher bash argv and sanitize script header
Two leaks remained after the inotifywait argv fix:
1. The bash running journal-relay showed its argv[1] (the script path)
in /proc/PID/cmdline, producing a line like
'journal-relay /usr/libexec/udev/journal-relay'
Apply argv_zap.so to that bash too.
2. argv_zap previously hardcoded PR_SET_NAME to 'kmsg-watch', which was
wrong for any caller other than inotifywait. The comm name now comes
from ARGV_ZAP_COMM so each caller can pick its own (kmsg-watch for
inotifywait, journal-relay for the watcher bash).
3. The capture.sh header started with 'SSH honeypot file-catcher' —
fatal if an attacker runs 'cat' on it. Rewritten as a plausible
systemd-journal relay helper; stray 'attacker' / 'honeypot' words
in mid-script comments stripped too.
This commit is contained in:
@@ -356,6 +356,35 @@ def test_capture_script_preloads_argv_zap():
|
||||
assert "LD_PRELOAD=/usr/lib/argv_zap.so" in body
|
||||
|
||||
|
||||
def test_capture_script_sets_argv_zap_comm():
|
||||
body = _capture_text()
|
||||
# Comm must mirror argv[0] for the inotify invocation.
|
||||
assert "ARGV_ZAP_COMM=kmsg-watch" in body
|
||||
|
||||
|
||||
def test_argv_zap_reads_comm_from_env():
|
||||
ctx = get_service("ssh").dockerfile_context()
|
||||
src = (ctx / "argv_zap.c").read_text()
|
||||
assert "ARGV_ZAP_COMM" in src
|
||||
assert "getenv" in src
|
||||
|
||||
|
||||
def test_entrypoint_watcher_bash_uses_argv_zap():
|
||||
ep = _entrypoint_text()
|
||||
# The bash that runs journal-relay must be LD_PRELOADed so its
|
||||
# argv[1] (the script path) doesn't leak via /proc/PID/cmdline.
|
||||
assert "LD_PRELOAD=/usr/lib/argv_zap.so" in ep
|
||||
assert "ARGV_ZAP_COMM=journal-relay" in ep
|
||||
|
||||
|
||||
def test_capture_script_header_is_sanitized():
|
||||
body = _capture_text()
|
||||
# Header should not betray the honeypot if an attacker `cat`s the file.
|
||||
first_lines = "\n".join(body.splitlines()[:20])
|
||||
assert "honeypot" not in first_lines.lower()
|
||||
assert "attacker" not in first_lines.lower()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# File-catcher: compose_fragment volume
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user