T1546.013 Google Chronicle · YARA-L

Detect PowerShell Profile in Google Chronicle

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/

YARA-L Detection Query

Google Chronicle (YARA-L)
yaral
rule powershell_profile_persistence_t1546_013 {
  meta:
    author = "Argus Detection Engineering"
    description = "Detects creation or modification of PowerShell profile scripts by unexpected processes (T1546.013 — Event Triggered Execution: PowerShell Profile)"
    severity = "HIGH"
    priority = "HIGH"
    mitre_attack_tactic = "Persistence"
    mitre_attack_technique = "T1546.013"
    reference = "https://attack.mitre.org/techniques/T1546/013/"
    version = "1.0"

  events:
    $e.metadata.event_type = "FILE_CREATION"
    $e.principal.hostname != ""
    (
      re.regex($e.target.file.full_path, `(?i)(Microsoft\.PowerShell_profile\.ps1|Microsoft\.VSCode_profile\.ps1|Microsoft\.PowerShellISE_profile\.ps1)`) or
      re.regex($e.target.file.full_path, `(?i)(^|\\)profile\.ps1$`) or
      (
        re.regex($e.target.file.full_path, `(?i)(WindowsPowerShell|\\PowerShell\\)`) and
        re.regex($e.target.file.full_path, `(?i)\.ps1$`)
      )
    )
    not re.regex($e.principal.process.file.full_path, `(?i)(powershell\.exe|pwsh\.exe|notepad\.exe|code\.exe|devenv\.exe|vim\.exe|nano\.exe|notepad\+\+\.exe|sublime_text\.exe)$`)

  condition:
    $e
}
high severity high confidence

YARA-L 2.0 rule detecting PowerShell profile file creation events initiated by processes outside the expected set of editors and PowerShell itself. Covers all four profile scopes including system-wide AllUsersAllHosts profiles which provide the broadest persistence footprint.

Data Sources

Google Chronicle via Windows Sysmon or Defender for Endpoint UDM ingestion

Required Tables

UDM FILE_CREATION events

False Positives & Tuning

  • Enterprise configuration management systems (Desired State Configuration, Group Policy scripts) that write standardised profiles to system PowerShell directories
  • PowerShell-based deployment frameworks that bootstrap module paths by modifying profile.ps1 during software rollout
  • Developers using unconventional editors (Emacs, Helix, JetBrains IDEs) not in the process exclusion list that legitimately edit their own profiles
Download portable Sigma rule (.yml)

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.

  1. 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.

  2. 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.

  3. 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.

Unlock Pro Content

Get the full detection package for T1546.013 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections