The log says nothing happened here. Three lines say otherwise, from a copy the attacker never touched. This file deletes the evidence, then reads the copy.
MITRE ATT&CK T1070.004: adversaries delete or edit the records of what they did. This file removes two lines from a log with the standard editor, then reads the copy the demonstrated edit could not reach.
Why this technique. The log is the story of what happened on the box. Delete the lines about the break-in and the story reads clean: one innocent SSH login, nothing else, case closed. Every "nothing happened here" you have ever read in a log was either true or edited, and from the log alone you cannot tell which. That indistinguishability is the technique.
Why not just lock the file. Permissions stop other users, not the account that was compromised: the service account that writes the log can rewrite the log, and root can do anything. Anyone who must be able to write can also delete, unless the write path is separated from the attacker's reach. There is no permission bit that means "writable by the service but not by an attacker holding the service's credentials."
Why the quiet edit beats the loud delete. Deleting the whole log is a confession: the gap screams. The professional version removes only the attacker's lines and leaves the benign ones, so the log keeps its rhythm and its timestamps stay plausible. Phase Red does the quiet version.
The concrete case, before the abstraction. Three lines go into access.log: one innocent login, one attacker login, one attacker sudo. sed -i '/attacker/d' access.log removes the attacker's two lines. cat access.log shows one innocent login. cat ship.log, the copy that was forwarded as each line was written, shows all three.
Terms, earned. sed -i edits a file in place by rewriting it, the standard tool for the quiet edit. /dev/udp is bash's built-in UDP client: writing to /dev/udp/host/port sends a datagram, no binary needed. Log forwarding is copying each entry to a second destination the moment it is written, before anyone can edit the original. File deletion is T1070.004: removing the records of the intrusion, wholesale or line by line.
Scope. T1070.004 covers wiping whole files, clearing event logs, and selective edits. This file works the selective edit: the quieter cousin, the one that leaves a plausible log behind.
Ubuntu 24.04.5 LTS, x86-64, in a disposable VM used only for this lab. The attack is one sed command and needs no privilege beyond write access to the log. The lab directory is ~/gh006.
Two pieces. A tiny UDP receiver in Python plays the role of the remote log collector: it listens on localhost and appends every datagram to ship.log. A shell function plays the service: it writes each log line to access.log and forwards a copy over UDP in the same breath.
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("127.0.0.1", 1514))
f = open("ship.log", "ab", buffering=0)
while True:
d, _ = s.recvfrom(65535)
f.write(d)
$ log(){ printf '%s\n' "$1" | tee -a access.log > /dev/udp/127.0.0.1/1514; sleep 0.3; }
Every line exists in two places from the moment it is written: the local log the attacker will find, and the shipped copy the demonstrated attack does not touch. That separation is the entire defense, and it is built before the attack, not after.
Three log lines go in, one of them innocent. The attacker removes their own two and leaves the innocent one standing. Read the log after, and believe it the way a tired responder would.
The service logs three events. The attacker keeps the innocent one and deletes their own.
$ log 'Sep 16 15:40:11 lab sshd[411]: Accepted publickey for ops from 10.0.0.8' $ log 'Sep 16 15:40:44 lab sshd[601]: Accepted password for attacker from 45.9.8.7' $ log 'Sep 16 15:41:19 lab sudo[602]: attacker : COMMAND=/bin/bash' $ sed -i '/attacker/d; /45.9.8.7/d' access.log $ cat access.log Sep 16 15:40:11 lab sshd[411]: Accepted publickey for ops from 10.0.0.8
One innocent SSH login. That is the whole story now, according to the log. The timestamps still flow, the format is intact, nothing looks redacted, because nothing was redacted: the file was rewritten with the inconvenient lines simply absent. A responder reading this log finds nothing, and "nothing" is exactly what the attacker wrote.
One sed command removed the intrusion from the record and left a plausible log behind. The edit needed no exploit and no privilege beyond write access, which the compromised account already had. The log is now a story the attacker co-authored.
The local log is now a suspect, not a source. Read the copy the demonstrated edit could not reach, line by line, as each event happened.
Here is the trap: opening the log, seeing one innocent login, and closing the case. The local log is the attacker's co-authored story. The defense was built before the attack: every line was forwarded to a second destination the moment it was written, and the attacker only cleaned the copy they knew about.
Same three events. The shipped copy never heard about the sed command.
$ cat ship.log Sep 16 15:40:11 lab sshd[411]: Accepted publickey for ops from 10.0.0.8 Sep 16 15:40:44 lab sshd[601]: Accepted password for attacker from 45.9.8.7 Sep 16 15:41:19 lab sudo[602]: attacker : COMMAND=/bin/bash $ grep -c attacker ship.log 2
All three lines, including the two the local log no longer contains. The attacker cleaned the only copy they could see; the forwarded copy was written to a different process, through a different path, at the moment of the event. The divergence between the two copies is itself the detection: when the local log and the shipped log disagree, the local log has been edited.
The shipped copy preserved every deleted line. No forensics, no undelete tools, no luck: the record survived because the demonstrated edit never touched the second write path.
Three moves, in order: distrust the local copy, watch for the edit pattern, forward everything off-host. Each is one way, not the way.
The moment a box is suspect, its local logs are evidence of what the attacker wants you to believe, not what happened. Pull the forwarded copy first and diff the two: the lines present in the shipped copy but missing locally are the edit, mapped precisely.
$ diff /var/log/auth.log /var/log/ship/auth.log 1a2,3 > Sep 16 15:40:44 lab sshd[601]: Accepted password for attacker from 45.9.8.7 > Sep 16 15:41:19 lab sudo[602]: attacker : COMMAND=/bin/bash
Do not "fix" the local log by restoring it; preserve both, because the divergence is the proof of tampering. Then contain: isolate the host from the network, snapshot both copies before the attacker returns to finish the job, and scope the incident from the shipped copy, which the demonstrated edit could not reach.
First principle: independent observation paths. The local log and the shipped copy are two witnesses; when they disagree, the disagreement itself is the detection.
Logs grow; they do not shrink, except on rotation. Keep yesterday's line count in a state file, compare on a timer, and alert on any decrease. The check is copy-pasteable (run it from cron every few minutes):
$ prev=$(cat /var/lib/logwatch/auth.prev 2>/dev/null || echo 0) $ now=$(wc -l < /var/log/auth.log) $ [ "$now" -lt "$prev" ] && logger -p auth.alert "auth.log shrank: $prev -> $now lines" $ echo "$now" > /var/lib/logwatch/auth.prev
What a catch looks like (real output, the demo's deletion):
prev=3 now=1 ALERT: log shrank 3 -> 1 lines
Good vs bad: on a healthy box the count only climbs between rotations; any decrease outside the rotation window is either the attacker or logrotate, and the monitor must know the rotation schedule to tell them apart. Check /etc/logrotate.d/ and the last rotation timestamp before paging anyone.
Honest limit. Size monitoring catches wholesale deletion, not the quiet edit that keeps the file growing: an in-place rewrite (sed -i 's/attacker/operator/g') held the count at 2 and fired no alert, while the shipped copy still held all three original lines. The shipped copy is what catches that; the counter is only the tripwire.
First principle: monitor the property the attacker must disturb. Deleting lines must shrink the file; a check on that property cannot be evaded without leaving the lines in place.
The production version of the demo's UDP receiver is rsyslog forwarding security logs in real time to a hardened collector: a separate host, with credentials the endpoint does not hold, over TCP with TLS. The attacker can rewrite every log on the box and the collector still has the originals. Where the filesystem allows it, chattr +a makes the local log append-only, which stops the quiet edit from non-root attackers.
Honest limit. The demo's receiver ran on the same box, as the same user the attacker holds. Verified: a same-user kill stops it, no privilege needed, no root required. The demo receiver is a teaching stand-in with no protection at all; do not mistake it for a control. That is why production puts the collector on separate hardware, with credentials the endpoint does not hold. UDP can drop datagrams under load; production uses TCP with TLS. Where the filesystem allows it, chattr +a makes the local log append-only, which stops the quiet edit from non-root attackers (setting or clearing the flag needs root, and it needs a filesystem that supports it, ext4/xfs class). Append-only slows a non-root attacker and does nothing against root. Against root on the endpoint, only the off-host copy counts.
The shipped copy is the whole defense: written before the attack through a second write path, it makes the demonstrated edit pointless. Size monitoring catches the loud deletion; real-time off-host forwarding catches everything else. The local log is a convenience; the collector is the record.
A log the attacker can rewrite is a rumor. The copy they could not reach is the record.
IOC checklist: signs this technique was used
Reproducibility checklist
Sources
MITRE ATT&CK T1070.004: File Deletion
rsyslog omfwd (real-time log forwarding, the production form of the demo)
sed(1) (the quiet edit)
MITRE D3FEND: D3-FIM
You type ls and the shell searches for it. Tonight the search answers from the wrong directory first, and the output looks perfect.