[Osquery_manager] Shell history artifact saved query #16204
+85
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Shell History Artifact
The Shell History artifact provides critical forensic visibility into command-line execution history across Linux and macOS systems. This query uniquely implements anti-forensics detection using LEFT JOIN to identify users with missing or cleared shell history—a key indicator of compromise or malicious activity.
Core Forensic Artifacts Coverage
MITRE ATT&CK Coverage
Queries by Platform
🐧 Linux / 🍎 macOS - Shell Command History with Anti-Forensics Detection
Description
Retrieves shell command history for all users with anti-forensics detection. Uses LEFT JOIN to identify users with no shell history (potential evidence of history clearing). Review results for: (1) suspicious command patterns including reverse shells, encoded commands, credential access, (2) users with
no_history_suspicious='yes'indicating missing history files.Detection Focus:
bash -i >& /dev/tcp/,nc -e /bin/sh)echo ... | base64 -d | sh)cat /etc/passwd,cat ~/.ssh/*)curl,wget,scp,rsync)unset HISTFILE,HISTSIZE=0,history -c)Key Features
Result
Query results include:
username,uid,gid- User identificationuser_home- User's home directory pathcommand- The executed command (NULL if no history)history_file- Path to the history fileshell_type- Detected shell (bash/zsh/fish/ash/unknown)command_time- Human-readable timestamp or 'unknown'command_timestamp- Raw Unix epoch timestampno_history_suspicious- 'yes' if user has no history (investigate!)Platform
linux,darwinInterval
3600seconds (1 hour)Query ID
shell_history_linux_macos_elasticECS Field Mappings
user.nameusernameuser.iduiduser.group.idgiduser.homeuser_homeprocess.command_linecommandfile.pathhistory_fileevent.category["process"]event.type["info"]tags["shell_history", "forensics", "anti_forensics_detection", ...]SQL Query
Investigation Guidance
Suspicious Command Patterns to Search For
Limitations
no_history_suspiciousHISTCONTROL=ignorespaceHISTTIMEFORMATprocess_eventsfor real-timeThis PR was AI assisted with Claude Code