GH-001 T1070.003 PHASE RED INSIDE

The Vanishing Shell

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.

TechniqueClear Command History
Target OSUbuntu 24.04.5 LTS
Shellbash 5.2.21
LevelBeginner
Time25 min

OBJECTIVES

  1. Understand why shell history is erasable by design
  2. Build the exact lab: Ubuntu 24.04, test account, seeded history
  3. Run the wipe and confirm the trail is gone
  4. Detect the wipe four ways, no prior setup required
  5. Contain the incident, then raise the cost of the next wipe
  6. Take the IOC checklist and the one-sentence lesson
01

Intel Brief

CONTEXT

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.

02

Target Environment

LOADOUT

Any full virtual machine running Ubuntu 24.04. Use a dedicated test account, never a production box.

1

Confirm the OS and shell

Every output below is what these commands actually returned on the verification box.

bash
$ 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)
2

Create the test account

bash
$ 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.

03

Phase Red: the Wipe

ATTACK

Three commands. That is the entire attack. Watch it work, then verify the trail is gone.

1

Seed normal activity

First, give the account a history worth stealing. Log in as ghostdemo and work normally.

bash
$ 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
2

Run the wipe

The intruder does their reconnaissance, then erases it. Press RUN REPLAY: this is the literal verified session.

Real screen recording 00:41
What you are watching: The intruder's reconnaissance, then the three-command wipe. Recorded live on Ubuntu 24.04, bash 5.2.21. Every command below is copy-pasteable.
bash, commands in this recording
$ whoami
$ id
$ ls /home
$ unset HISTFILE
$ history -c
$ rm -f ~/.bash_history
$ echo "checking the damage:"
$ history
$ ls -la ~/.bash_history
Stealth confirmed

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.

3

The companion move

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.

bash
$ echo 'history -c' >> ~/.bash_logout
04

Phase Blue: Detection

DEFENSE

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.

1

The absence is the evidence

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.

bash
$ 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.

2

Correlate sessions with commands

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.

bash
$ 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.

3

Hunt for tampering

One grep across the shell's startup and shutdown files. The stock Ubuntu comments are noise; anything else is a finding.

Real screen recording 00:21
What you are watching: The analyst hunts for tampering: one grep across the shell's startup and shutdown files. Every command below is copy-pasteable.
bash, commands in this recording
$ grep -rn "HISTFILE\|history -c" ~/.bashrc ~/.profile ~/.bash_logout /etc/profile.d/ 2>/dev/null
Detected

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.

4

Watch the file die

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.

Real screen recording 00:25
What you are watching: An inotify watch on the history file sees the deletion happen live, even though the file is gone. Every command below is copy-pasteable.
bash, commands in this recording
$ 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.

05

Countermeasures

DEFENSE

First stop the bleeding, then raise the cost of the next attempt. Each layer names its bypass.

1

Mitigate: preserve and sweep

Do not reboot yet; memory and logs are evidence. Copy what remains somewhere safe, then sweep for the companions this technique travels with.

bash
$ 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.

2

Prevent, layer one: tamper-evident shell logging

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.

bash: /etc/profile.d/shell-audit.sh
# 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:

Real screen recording 00:38
What you are watching: The attack re-run against the hardened shell. The wipe fails to hide. Every command below is copy-pasteable.
bash, commands in this recording
$ 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:

bash
$ 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"
Prevention verified

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.

3

Prevent, layer two: kernel audit watches (full VM only)

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:

bash
$ 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:

bash
$ 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.

4

Prevent, layer three: ship it off the box

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:

rsyslog: /etc/rsyslog.d/99-remote.conf
# 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.

06

Debrief

TAKEAWAY

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

  • ~/.bash_history missing, truncated, or starting after the incident window
  • history -c or HISTFILE tampering in ~/.bash_logout, ~/.bashrc, ~/.profile, or /etc/profile.d/
  • Logins (last, lastlog, sshd journal) with no corresponding commands
  • File-watch events: DELETE_SELF or unlink on the history file

Reproducibility checklist

  • Verified on Ubuntu 24.04.5 LTS, bash 5.2.21, test account ghostdemo, on 2026-09-15
  • Transcripts are the literal commands and outputs; prompts normalized to ghostdemo@lab
  • Journal timestamps are system time (UTC on the verification box)
  • Known environment limits documented inline: containers disable kernel audit; btrfs lacks append-only flags

Sources

MITRE ATT&CK T1070.003, Clear Command History
Bash manual, history facilities (HISTFILE, history -c semantics)
inotifywait(1) (DELETE_SELF semantics)

Next file

GH-002: The Lying Library

T1014 Rootkit: a 70-line library makes ps lie. Cross-view detection with a raw syscall.