Overview
ThePowerShellHistory command searches PowerShell console history files (ConsoleHost_history.txt) for sensitive information using regex pattern matching. PowerShell history often contains credentials, API keys, commands with sensitive parameters, and other valuable intelligence from user command-line activities.
Important: User commands run for the current user if not elevated and for ALL users if elevated.
Syntax
Output
The command returns:- PowerShell history file locations
- Commands matching sensitive patterns (passwords, credentials, API keys, etc.)
- Timestamps of command execution (when available)
- User context for each history file
- Matched sensitive strings and patterns
Use Cases
Red Team
- Credential Harvesting: Find passwords and API keys in command history
- Command Intelligence: Discover administrative commands and scripts used
- Network Mapping: Identify remote systems accessed via PowerShell
- Infrastructure Discovery: Find database connections, API endpoints, and services
- Attack Path Discovery: Understand administrative workflows and tools used
Blue Team
- Security Audit: Identify users typing credentials in plaintext
- Incident Response: Review command history during security investigations
- Insider Threat Detection: Identify suspicious PowerShell commands
- Compliance Monitoring: Ensure command-line usage aligns with policies
- User Training: Identify users who need security awareness training
Example Output
Privilege Context
- Non-Elevated: Searches PowerShell history for the current user only
- Elevated: Searches PowerShell history for ALL users on the system, providing comprehensive command history analysis
Remote Execution
This command supports remote execution (marked with + in the command list). Remote syntax:Detection Considerations
Indicators
- File system access to PowerShell history files
- Reading ConsoleHost_history.txt in user AppData directories
- Pattern-based regex searching of command history
- Enumeration across multiple user profiles
Defensive Monitoring
- Monitor access to PowerShell history files by unexpected processes
- Alert on automated enumeration of command history
- Track processes reading PSReadline history files
- Log bulk access to history files across multiple users
- Detect credential dumping tools accessing PowerShell data
- Monitor for exfiltration of history files
Sensitive Patterns Detected
- Passwords and credentials in commands
- API keys and authentication tokens
- Database connection strings
- Secret keys and encryption passphrases
- Remote access commands with credentials
- Administrative commands with sensitive parameters
- File paths to sensitive resources
Security Recommendations
- Educate users never to type credentials in plaintext
- Use secure credential prompts (Get-Credential)
- Implement PowerShell logging and monitoring
- Regularly audit PowerShell history for sensitive data
- Consider clearing history files containing credentials
- Use secret management solutions instead of plaintext credentials
- Enable Constrained Language Mode where appropriate
Related Commands
- ExplorerRunCommands: Shows recent Run dialog commands
- ProcessCreationEvents: Shows process creation event logs
- PowerShellEvents: Searches PowerShell script block logs
- EnvironmentVariables: May reveal PowerShell configuration