Detect PowerShell Profile in Sumo Logic CSE
Adversaries may establish persistence by placing malicious commands into a PowerShell profile. A PowerShell profile script is a script that runs when PowerShell starts and can be used as a logon script to customize user environments. PowerShell supports several profile locations including: $PROFILE (current user, current host), $PROFILE.AllUsersCurrentHost (all users, current host), $PROFILE.CurrentUserAllHosts (current user, all hosts), and $PROFILE.AllUsersAllHosts (all users, all hosts — the most powerful). Malicious profile content executes whenever an interactive PowerShell session is started, providing persistent code execution in the user's context.
MITRE ATT&CK
- Tactic
- Privilege Escalation Persistence
- Technique
- T1546 Event Triggered Execution
- Sub-technique
- T1546.013 PowerShell Profile
- Canonical reference
- https://attack.mitre.org/techniques/T1546/013/
Sumo Detection Query
_sourceCategory=windows/sysmon OR _sourceCategory=os/windows/sysmon
| parse xml "*" as sysmon_xml nodrop
| json auto
| where EventID = "11"
| where (
matches(TargetFilename, "(?i)Microsoft\.PowerShell_profile\.ps1") or
matches(TargetFilename, "(?i)Microsoft\.VSCode_profile\.ps1") or
matches(TargetFilename, "(?i)Microsoft\.PowerShellISE_profile\.ps1") or
matches(TargetFilename, "(?i)(?:^|\\\\)profile\.ps1$") or
(
matches(TargetFilename, "(?i)(WindowsPowerShell|\\\\PowerShell\\\\)") and
matches(TargetFilename, "(?i)\.ps1$")
)
)
| eval IsSystemProfile = if(matches(TargetFilename, "(?i)(System32|SysWOW64)\\\\WindowsPowerShell"), "true", "false")
| eval IsUserProfile = if(matches(TargetFilename, "(?i)(Documents|Users)"), "true", "false")
| eval SuspiciousWriter = if(
!matches(toLowerCase(Image), "(powershell\.exe|pwsh\.exe|notepad\.exe|code\.exe|devenv\.exe|vim\.exe|nano\.exe)"),
"true", "false"
)
| where SuspiciousWriter = "true"
| fields _messagetime, Computer, User, TargetFilename, Image, CommandLine, IsSystemProfile, IsUserProfile, SuspiciousWriter
| sort by _messagetime desc Detects writes to PowerShell profile files by unexpected processes using Sysmon EventID 11 (FileCreate) on Windows endpoints. Enriches events with flags indicating whether the profile is a system-wide or user-specific profile and whether the writing process is outside the expected whitelist.
Data Sources
Required Tables
False Positives & Tuning
- Automated workstation setup scripts run by IT during onboarding that configure PowerShell environments for new users
- Third-party PowerShell module managers (PSDepend, Stucco) that append module loading commands to profile files during installation
- Legitimate red team tooling on authorized penetration testing systems where testers use non-standard editors
Other platforms for T1546.013
Testing Methodology
Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1Add Malicious Command to PowerShell Profile
Expected signal: File modification event (Sysmon 11) for the PowerShell profile file. Process creation for powershell.exe executing Add-Content. PowerShell ScriptBlock Log Event ID 4104 shows the appended content. On next PowerShell launch, Event ID 4104 will show Invoke-Expression and DownloadString.
- Test 2Create AllUsers PowerShell Profile with Persistence
Expected signal: File creation or modification event (Sysmon 11) for C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1. IsSystemProfile=true in detection. Process creation for powershell.exe with Add-Content. This is a high-severity detection — AllUsers profile modification.
- Test 3Verify Profile Persistence Execution
Expected signal: File modification event for PowerShell profile. Process creation for powershell.exe (child session). File creation event for profile_executed.txt in Temp — confirms execution. The spawned PowerShell process loads the profile and executes the New-Item command.
References (4)
- https://attack.mitre.org/techniques/T1546/013/
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1546.013/T1546.013.md
- https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles
- https://learn.microsoft.com/en-us/powershell/scripting/learn/shell/creating-profiles
Unlock Pro Content
Get the full detection package for T1546.013 including response playbook, investigation guide, and atomic red team tests.