An intruder wipes their bash history in three commands and walks away clean. This file runs the wipe, proves nothing is left, then catches it four independent ways and installs prevention layers that make the next attempt harder to hide, each with its bypass named.
MITRE ATT&CK T1070.003: adversaries clear command history to hide what they ran. Shell history feels like a record, but it is a convenience feature owned by the user it records, which means anyone holding that user's shell can erase it in three commands.
The scenario. An intruder lands a shell as ghostdemo on an Ubuntu 24.04 box, does their reconnaissance, then wipes the history before leaving. You are the analyst who logs in afterward and finds nothing. This file runs that wipe, proves the trail is gone, then shows you how to prove it happened and how to make the next attempt harder to hide.
Why this technique matters to victims. On many breached boxes, shell history is the only record of what the intruder typed. When it is gone, most analysts stop looking. The four detection methods in Phase Blue assume you set up nothing in advance.
Scope. History wiping has many implementations, from truncating the file to disabling logging per session to tampering at the filesystem layer. This file works one of them end to end, the classic in-shell wipe, and resolves that instance four ways. Treat it as one case in your collection, not the whole technique.
Any full virtual machine running Ubuntu 24.04. Use a dedicated test account, never a production box.
Every output below is what these commands actually returned on the verification box.
$ cat /etc/os-release | head -2 PRETTY_NAME="Ubuntu 24.04.5 LTS" NAME="Ubuntu" $ bash --version | head -1 GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
$ sudo useradd -m -s /bin/bash ghostdemo
Container note. Everything in this file runs in containers except the kernel auditd countermeasure in Phase 05, which is marked full VM only. Most containers disable the kernel audit subsystem.
Three commands. That is the entire attack. Watch it work, then verify the trail is gone.
First, give the account a history worth stealing. Log in as ghostdemo and work normally.
$ su - ghostdemo ghostdemo@lab:~$ echo "analyst morning check: uptime" ghostdemo@lab:~$ uptime ghostdemo@lab:~$ echo "analyst morning check: disk usage" ghostdemo@lab:~$ df -h / | tail -1 ghostdemo@lab:~$ wc -l ~/.bash_history 4 /home/ghostdemo/.bash_history
The intruder does their reconnaissance, then erases it. Press RUN REPLAY: this is the literal verified session.
$ whoami $ id $ ls /home $ unset HISTFILE $ history -c $ rm -f ~/.bash_history $ echo "checking the damage:" $ history $ ls -la ~/.bash_history
whoami, id, and ls /home ran and left no trace. The history file is gone and the shell remembers nothing. If history were your only record, the intruder was never here.
Attackers rarely stop at one wipe. A classic companion is planting the wipe in ~/.bash_logout, so every logout clears the session automatically. Plant it now; Phase Blue will find it.
$ echo 'history -c' >> ~/.bash_logout
Four independent ways to prove the wipe happened. Three of them need nothing set up in advance. The fourth, the live watch, must be running before the deletion: a watch started after the file is gone fails outright (inotify_add_watch: No such file or directory), because there is nothing left to watch. The watch is for catching the wipe live, or proving the mechanism to a skeptic. It is never a post-incident tool.
First principle: the absence of evidence is not the evidence of absence, but a missing history on a known-active account is itself a measurement, and a detection that needs no prior setup is worth more than a perfect one that needed last month's foresight.
A healthy account accumulates history. An account with known activity and an empty history file is already telling you something. Check what the file looks like now, and when it starts.
$ ls -la ~/.bash_history ls: cannot access '/home/ghostdemo/.bash_history': No such file or directory $ history | wc -l 1
Subtlety: a fresh shell recreates the file on exit, so a wiped box often shows a history file that starts after the incident window. Compare the oldest entries against when you know the account was active.
Logins that produced no commands are the tell. These three commands answer: who logged in, when was the last login, and what did sshd see.
$ last ghostdemo | head $ lastlog -u ghostdemo Username Port From Latest ghostdemo **Never logged in** $ journalctl _COMM=sshd --since "2 hours ago" | grep "session opened"
Reading this output. This verification box used local shells, so last legitimately shows nothing for ghostdemo. On any box with SSH logins, these commands show the sessions, and sessions with no corresponding history entries are your evidence of a wipe.
One grep across the shell's startup and shutdown files. The stock Ubuntu comments are noise; anything else is a finding.
$ grep -rn "HISTFILE\|history -c" ~/.bashrc ~/.profile ~/.bash_logout /etc/profile.d/ 2>/dev/null
The .bashrc hits are stock Ubuntu comments. The .bash_logout hit is the planted wipe. One grep, one finding, and you now know the wipe re-arms on every logout.
If you catch it live, or want to prove the mechanism to a skeptic: watch the history file in one terminal while the attack runs in another. The watcher sees the deletion even though the file is gone.
$ inotifywait -m -e delete_self,delete,attrib,move_self --format '%T %e %f' --timefmt '%H:%M:%S' /home/ghostdemo/.bash_history
DELETE_SELF in the watch output is the rm -f ~/.bash_history landing. Install the watcher with sudo apt-get install -y inotify-tools on Ubuntu.
First stop the bleeding, then raise the cost of the next attempt. Each layer names its bypass.
Do not reboot yet; memory and logs are evidence. Copy what remains somewhere safe, then sweep for the companions this technique travels with.
$ sudo mkdir -p /root/case-gh001 $ sudo cp -a /home/ghostdemo/.bash_history /root/case-gh001/ 2>/dev/null $ sudo journalctl --since "24 hours ago" > /root/case-gh001/journal.txt $ grep -rn "HISTFILE\|history -c" /home/*/.bash_logout /home/*/.bashrc 2>/dev/null
Then sweep every account with the Phase Blue hunt, check cron tables, authorized_keys, and user systemd units, and rotate the compromised account's credentials plus any secrets it could read. Isolate the host from the network before the sweep: a history wipe is evidence of an intrusion, not the intrusion itself, and the box stays considered compromised until it is rebuilt. The wipe tells you someone was here; assume they are still here until the rebuild says otherwise.
A root-owned login snippet that ships every command to the system journal the moment it finishes, and locks the history variables read-only. The attacker can still delete the file. They cannot reach back in time.
# GHOSTLIGHT-001 prevention layer 1: tamper-evident shell logging. # Root-owned. Every interactive login shell ships each command to the # system journal the moment it finishes, before an attacker can wipe history. export HISTTIMEFORMAT='%F %T ' export HISTSIZE=100000 export HISTFILESIZE=100000 shopt -s histappend PROMPT_COMMAND='history -a; logger -t shell-audit -p authpriv.info "$(id -un) [$$] $(history 1 | sed "s/^ *[0-9]* *//")"' readonly PROMPT_COMMAND readonly HISTFILE
Install it root-owned and read-only, then re-run the attack and watch it fail to hide. This is the verified session:
$ echo "morning check: services up" $ whoami $ echo "intruder: staging data for exfil" $ ls /etc/*.conf | head -3 $ unset HISTFILE $ history -c $ rm -f ~/.bash_history $ echo "intruder: trail is clean"
The wipe still deleted the file. But every keystroke, including the wipe itself, was already in the journal with a timestamp. Check it:
$ sudo journalctl -t shell-audit -o cat --since "5 minutes ago" ghostdemo [10446] ghostdemo [10446] 2026-09-15 08:44:01 echo "morning check: services up" ghostdemo [10446] 2026-09-15 08:44:01 whoami ghostdemo [10446] 2026-09-15 08:44:01 echo "intruder: staging data for exfil" ghostdemo [10446] 2026-09-15 08:44:01 ls /etc/*.conf | head -3 ghostdemo [10446] 2026-09-15 08:44:01 unset HISTFILE ghostdemo [10446] ghostdemo [10446] 2026-09-15 08:44:01 rm -f ~/.bash_history ghostdemo [10446] 2026-09-15 08:44:01 echo "intruder: trail is clean"
The attacker believed the trail was clean. The journal disagrees, timestamp by timestamp, including the rm itself. Timestamps are system time (UTC on the verification box).
Bypass, stated honestly. A shell started with bash --noprofile --norc skips /etc/profile.d entirely, so this layer does not cover an attacker who knows it is there. It raises the cost and catches the careless. The kernel layer below covers everyone.
Kernel-level file watches cannot be removed from user space: a non-root attacker cannot unset them, and with auditctl -e 2 even root cannot change the rules until reboot. That is the whole of the guarantee, and it has edges. Root can still reboot with audit=0 or rewrite the rules for the next boot. The watches cover only the paths someone configured. And many containers ship without audit userspace at all: if auditctl -w answers "The audit system is disabled," you are in one, and this layer does not exist there. What survives a compromised box is the off-host copy (layer three), not the local rules. First, check your environment can run them:
$ sudo auditctl -w /tmp -p wa -k test The audit system is disabled
If you see The audit system is disabled, you are in a container: run this section in a full VM. We verified this exact failure on a containerized Ubuntu 24.04 box. Where audit runs, the rules are:
$ sudo auditctl -w /home/ghostdemo/.bash_history -p wa -k bash_history $ sudo auditctl -e 2 # immutable: rules stand until reboot
Re-run the Phase Red wipe, then read the kernel's own account with sudo ausearch -k bash_history -i. The unlink event names the process that deleted the file. Make the rules permanent in /etc/audit/rules.d/ so they survive reboot. MITRE D3FEND names this class of defense Operational Process Monitoring (D3-OPM): the lab built it first, the framework gives it a name.
The only record that survives a full compromise of the machine is the one that is not on the machine. Forward the audit stream to a log host:
# needs rsyslog installed and a reachable log host authpriv.* @@loghost.internal:514
On append-only flags. On ext4 and xfs, chattr +a ~/.bash_history makes the history append-only (even root must clear the flag first). On btrfs the flag does not exist: we verified chattr +a fails there with Operation not permitted. Portable answer: the journal and audit layers above.
Shell history is a convenience, not a control. Treat its absence as evidence, and keep the real record somewhere the shell cannot reach: the journal, the kernel audit log, or another machine.
IOC checklist: signs this technique was used
Reproducibility checklist
Sources
MITRE ATT&CK T1070.003, Clear Command History
Bash manual, history facilities (HISTFILE, history -c semantics)
inotifywait(1) (DELETE_SELF semantics)
T1014 Rootkit: a 70-line library makes ps lie. Cross-view detection with a raw syscall.