Credential Discovery via PowerShell Scripting
Adversaries use PowerShell to search local file systems and network shares for files containing embedded or insecurely stored credentials.
Adversaries often attempt to locate credentials stored within configuration files, source code, scripts, or binary files to facilitate lateral movement and privilege escalation. This technique involves using native PowerShell capabilities to recursively traverse directories and identify sensitive content using keyword pattern matching. By leveraging built-in cmdlets such as 'Select-String' combined with recursive listing commands like 'ls -R', attackers can efficiently scan large file systems for strings associated with passwords, API keys, or service account configurations. This approach is highly effective because it utilizes legitimate administrative tools, often blending in with normal system maintenance activity, and does not require the deployment of additional malicious binaries. Detection relies on monitoring PowerShell Script Block logs for combinations of specific commands indicative of recursive file content searching.
Impact
Successful execution of this technique enables attackers to harvest credentials for further compromise of the environment. If credentials for administrative accounts or service accounts are identified, the impact can include unauthorized access to sensitive systems, increased persistence, and potential data exfiltration.
Recommendation
- Enable and centralize PowerShell Script Block Logging (Event ID 4104) across all Windows endpoints.
- Deploy the Sigma rule provided in this brief to identify suspicious recursive search patterns.
- Monitor for the execution of PowerShell commands that use 'Select-String' in conjunction with recursive listing flags against sensitive file paths.
- Implement access controls on configuration files and source code repositories to prevent unauthorized reading of credential stores.
Immediate actions
Enable PowerShell Script Block Logging (Event ID 4104) across all endpoints
Threat Hunt
Search for high-frequency use of Select-String by non-admin users
Data: Powershell Script Block logs
Mitigations
Remove plain-text credentials from configuration files and scripts
T1552.001
Detection coverage 1
Detect Credential Discovery via PowerShell Select-String
mediumDetects the use of PowerShell commands that recursively search file contents for sensitive patterns often used to discover stored credentials
Detection queries are available on the platform. Get full rules →