Potentially Suspicious Powershell Script Execution From Temp Folder
A Sigma rule for process creation on Windows, by Florian Roth (Nextron Systems), Max Altgelt (Nextron Systems), Tim Shelton.
medium 1 ATT&CK technique 2 programs it names 2 everyday examples trip it
What it looks for
detection:
filter_optional_amazon_ec2:
CommandLine|contains: '\Windows\system32\config\systemprofile\AppData\Local\Temp\Amazon\EC2-Windows\'
filter_optional_chocolatey_installer:
CommandLine|contains|all:
- '-NoProfile -ExecutionPolicy Bypass -Command'
- 'AppData\Local\Temp\'
- 'Install-Chocolatey.ps1'
Image|endswith: '\powershell.exe'
ParentImage:
- 'C:\Windows\System32\Msiexec.exe'
- 'C:\Windows\SysWOW64\Msiexec.exe'
filter_optional_ec2launch:
CommandLine|contains|all:
- '\config\systemprofile\AppData\Local\Temp\EC2Launch'
- '\UserScript.ps1'
ParentImage|endswith: '\Amazon\EC2Launch\EC2Launch.exe'
filter_optional_generic:
CommandLine|contains:
- ' >'
- 'Out-File'
- 'ConvertTo-Json'
filter_optional_vscode:
CommandLine|contains: '-WindowStyle hidden -Verb runAs'
selection:
CommandLine|contains:
- '\Windows\Temp'
- '\Temporary Internet'
- '\AppData\Local\Temp'
- '\AppData\Roaming\Temp'
- '%TEMP%'
- '%TMP%'
- '%LocalAppData%\Temp'
Image|endswith:
- '\powershell.exe'
- '\pwsh.exe'
condition: selection and not 1 of filter_optional_*
The rule’s detection, its selections and fields in order of name. The whole rule, with its references and false positives, is on SigmaHQ, by Florian Roth (Nextron Systems), Max Altgelt (Nextron Systems), Tim Shelton, under the Detection Rule License 1.1. CmdID evaluates it on a command line alone: a test on what a command line cannot show, such as the parent process or the user, is not met.
Command lines that trip it
Get the link target for a junction point on the page for Get-ChildItem
PS D:> New-Item -ItemType Junction -Name tmp -Target $Env:TEMP
PS D:> Get-ChildItem | Select-Object Name, *Target
Name Target
---- ------
tmp {C:\Users\user1\AppData\Local\Temp}IdentifyCreate a module in a temporary file on the page for Import-PSSession
PS C:> Import-PSSession $S -CommandName Get-Date, SearchHelp -FormatTypeName * -AllowClobber
Name : tmp_79468106-4e1d-4d90-af97-1154f9317239_tcw1zunz.ttf
Path : C:\Users\User01\AppData\Local\Temp\tmp_79468106-4e1d-4d90-af97-1154f9317239_tcw1
zunz.ttf\tmp_79468106-4e1d-4d90-af97-1154f9317239_
tcw1zunz.ttf.psm1
Description : Implicit remoting for http://server01.corp.fabrikam.com/wsman
Guid : 79468106-4e1d-4d90-af97-1154f9317239
Version : 1.0
ModuleBase : C:\Users\User01\AppData\Local\Temp\tmp_79468106-4e1d-4d90-af97-1154f9317239_tcw1
zunz.ttf
ModuleType : Script
PrivateData : {ImplicitRemoting}
AccessMode : ReadWrite
ExportedAliases : {}
ExportedCmdlets : {}
ExportedFunctions : {[Get-Date, Get-Date], [SearchHelp, SearchHelp]}
ExportedVariables : {}
NestedModules : {}IdentifyPrograms and files it names
ATT&CK
T1059.001Command and Scripting Interpreter: PowerShell