Operator On The Wire
Join
← Back to Knowledge Base
BLUE TEAM / THREAT HUNT / LINUX / EVASION

Log Tampering and Cleanup

This note documents detection patterns related to Log Tampering and Cleanup on Linux systems.


Direct Indicators

SourceGrep Pattern / ArtifactMeaningForensic ValueNotes
Shell historyhistory -cInteractive history clearCriticalClassic immediate cleanup action.
Shell historyunset HISTFILEDisable history loggingCriticalStrong anti-forensic intent.
Shell historyrm ~/.bash_historyDelete shell historyCriticalDirect anti-forensic action.
Shell historyecho > ~/.bash_historyTruncate historyCriticalCommon cleanup shortcut.
Shell historytruncate -s 0File zeroingCriticalBroader anti-forensic pattern.
Shell historysed -i on logsSelective line removalCriticalPrecise cleanup attempt.
Shell historyrm /var/log/...Log deletionCriticalHigh-confidence anti-forensics.
Shell historyjournalctl --vacuumJournal cleanupCriticalDirect journal tampering.
Shell history> /var/log/auth.logAuth log truncationCriticalStrong malicious cleanup.
File size anomalylog suddenly tiny / emptyCleanup artifactCriticalStrong timeline clue.
File timestamprecent log touchCleanup timing anchorCriticalCorrelates with intrusion.
Missing rotated logsabnormal rotation gapHighSuggests deletion.
auditdwrite/delete logsProcess attributionCriticalBest truth source if enabled.
Journald gapmissing expected entriesHighStrong anti-forensic clue.

Indirect Indicators

IndicatorWhat To Look ForForensic ValueNotes
History missing after active shellSelective cleanupCriticalStrong operator signal.
Auth log gap during compromiseLog tamperingCriticalImportant timeline clue.
Only specific lines removedTargeted anti-forensicsCriticalMature operator behavior.
Logs cleared after sudo or persistenceCover-up sequenceCriticalStrong hostile chain.
History disabled before actionsIntentional stealthCriticalHigh-value intent evidence.
Journald vacuum after intrusionJournal anti-forensicsCriticalStrong cleanup signal.
Temp payload deleted plus logs alteredFull cleanup disciplineCriticalMature operator pattern.
Shell history recreated emptyManual resetHighCommon cleanup artifact.
File inode persists but size zeroTruncationHighUseful forensic clue.
Logs missing but other artifacts remainPartial cleanupHighCommon real-world outcome.

Common Tools

ToolUsage
history -cClear shell history.
unset HISTFILEDisable history writes.
rmDelete logs/history.
truncateZero files.
sed -iSelective line deletion.
journalctl --vacuum-*Journal cleanup.

Relevant Artifacts

ArtifactPath / CommandForensic ValueNotes
Shell history.bash_history, .zsh_historyCriticalPrimary anti-forensic target.
Auth logs/var/log/auth.log, /var/log/secureCriticalCommon cleanup target.
Syslog/var/log/syslog, /var/log/messagesCriticalSecondary target.
Journal/var/log/journal/CriticalJournald persistence.
Rotated logs/var/log/*.1, .gzCriticalCompare for gaps.
Audit logs/var/log/audit/audit.logCriticalOften survives if enabled.
File metadatastatCriticalTimestamp truth.

MITRE ATT&CK References

  • T1070 Indicator Removal on Host
  • T1070.003 Clear Command History
  • T1070.002 Clear Linux or Mac System Logs

Decision Tree

  1. Are logs/history altered?

    • Inspect size, timestamps, missing content.
  2. Which logs were targeted?

    • History, auth, syslog, journal.
  3. Was cleanup broad or selective?

    • Full deletion vs line edits.
  4. What survives elsewhere?

    • Rotated logs, auditd, target logs.
  5. Did cleanup follow compromise actions?

    • Sequence matters strongly.
  6. Pivot

    • Timestamp → intrusion chain.
    • Missing logs → alternate sources.
    • File metadata → tamper timing.
  7. Confirm anti-forensics

    • Cleanup commands + altered logs + intrusion context = strong anti-forensic finding.

Example Detection Templates

Grep

grep -R "history -c\|unset HISTFILE\|rm ~/.bash_history\|truncate -s 0\|journalctl --vacuum" /home/*/.bash_history /root/.bash_history 2>/dev/null
grep -R "rm /var/log\|> /var/log\|sed -i" /home/*/.bash_history /root/.bash_history 2>/dev/null
ls -lh /var/log/auth.log /var/log/syslog /var/log/secure 2>/dev/null

Journalctl

journalctl --list-boots
journalctl | tail

File Inspection

stat ~/.bash_history /root/.bash_history 2>/dev/null
find /var/log -type f -printf '%TY-%Tm-%Td %TT %s %p\n' 2>/dev/null | sort

Sigma

title: Linux Log Tampering and Cleanup
id: linux-log-tampering-cleanup
status: experimental
description: Detects suspicious commands and artifacts associated with Linux anti-forensic cleanup
logsource:
  product: linux
detection:
  selection_keywords:
    message|contains:
      - 'history -c'
      - 'unset HISTFILE'
      - 'truncate -s 0'
      - 'journalctl --vacuum'
  condition: selection_keywords
fields:
  - message
  - hostname
falsepositives:
  - Rare legitimate cleanup activity
level: high
tags:
  - attack.defense_evasion
  - attack.t1070

Mitigation & Hardening

Control AreaMitigationEffectivenessNotes
Central loggingForward logs remotelyCriticalPrevents local-only cleanup success.
AuditdPreserve command and file actionsCriticalStrong anti-forensic resilience.
Log immutabilityProtect critical logsHighLimits tampering.
Shell loggingCentral shell command captureHighSurvives local history deletion.
Rotation monitoringDetect abnormal gapsHighStrong invariant clue.

Fast Triage Checks

QuestionCommand / ArtifactWhy It Matters
Is history empty unexpectedly?inspect history filesImmediate anti-forensic clue.
Were logs truncated?size + timestampsStrong tamper signal.
Are rotated logs missing?inspect older logsGap detection.
Did journal shrink recently?journal metadataCleanup clue.
Does auditd preserve truth?inspect audit logsAlternate truth source.
What action preceded cleanup?surviving timelineAttack reconstruction.

High Value Grep Strings

PatternWhy It Matters
history -cDirect shell cleanup.
unset HISTFILEDisable future history.
rm ~/.bash_historyDelete shell history.
truncate -s 0Zero file content.
journalctl --vacuumJournal cleanup.
sed -iSelective deletion.
> /var/log/Direct truncation.

Analyst Notes

ScenarioInterpretation
Empty history after active compromiseStrong cleanup signal.
Auth log suddenly tinyLikely truncation.
Journald gap after intrusionAnti-forensic attempt likely.
Specific lines removedMature operator cleanup.
Logs cleaned but known_hosts remainsPartial cleanup common.
History deleted but audit survivesAuditd becomes decisive.