Linux - Evasion
An Unicode zero-width space can be inserted into filenames which makes the names visually indistinguishable:
Most shells save their command history so a user can recall them again later. The command history can be viewed with the
history command or by manually inspecting the contents of the file pointed to by
This can be prevented in a number of ways.
Individual commands that match a pattern in
HISTIGNORE will be excluded from the command history, regardless of
HISTIGNORE will ignore all commands that begin with whitespace:
If commands are accidentally added to the command history, individual command entries can be removed with
The entire command history can be purged as well, although this approach is much less subtle and very likely to be noticed:
ANSI escape sequences can be abused to hide text under certain circumstances.
If the file's contents are printed to the terminal (e.g.
tail) then the text will be hidden.
If the file is viewed with an editor (e.g.
emacs), then the escape sequences will be visible.
Timestomping refers to the alteration of a file or directory's modification/access timestamps in order to conceal the fact that it was modified.
The simplest way to accomplish this is with the
# Changes the access (-a) and modification (-m) times using YYYYMMDDhhmm format. touch -a -m -t 202210312359 "example" # Changes time using a Unix epoch timestamp. touch -a -m -d @1667275140 "example" # Copies timestamp from one file to another. touch -a -m -r "other_file" "example" # Get the file's modification timestamp, modify the file, then restore the timestamp. MODIFIED_TS=$(stat --format="%Y" "example") echo "backdoor" >> "example" touch -a -m -d @$MODIFIED_TS "example"
It should be noted that
touch can only modify the access and modification timestamps. It can't be used to update a file's "change" or "birth" timestamps. The birth timestamp, if supported by the filesystem, tracks when the file was created. The change timestamp tracks whenever the file's metadata changes, including updates to the access and modification timestamps.
If an attacker has root privileges, they can work around this limitation by modifying the system clock, creating or modifying a file, then reverting the system clock:
Don't forget that creating a file also updates the parent directory's modification timestamp as well!
- ATT&CK - Impair Defenses: Impair Command History Logging
- ATT&CK - Indicator Removal: Timestomp
- ATT&CK - Indicator Removal on Host: Clear Command History
- ATT&CK - Masquerading: Match Legitimate Name or Location
- Wikipedia - ANSI escape codes
- InverseCos - Detecting Linux Anti-Forensics: Timestomping