LoFP LoFP / legitimate powershell scripts

Techniques

Sample rules

Tamper Windows Defender Remove-MpPreference

Description

Detects attempts to remove Windows Defender configurations using the ‘MpPreference’ cmdlet

Detection logic

condition: all of selection_*
selection_remove:
  CommandLine|contains: Remove-MpPreference
selection_tamper:
  CommandLine|contains:
  - '-ControlledFolderAccessProtectedFolders '
  - '-AttackSurfaceReductionRules_Ids '
  - '-AttackSurfaceReductionRules_Actions '
  - '-CheckForSignaturesBeforeRunningScan '

Clear PowerShell History - PowerShell Module

Description

Detects keywords that could indicate clearing PowerShell history

Detection logic

condition: 1 of selection_payload_* or all of selection_1*
selection_1a_payload:
  Payload|contains:
  - del
  - Remove-Item
  - rm
selection_1b_payload:
  Payload|contains: (Get-PSReadlineOption).HistorySavePath
selection_payload_2:
  Payload|contains|all:
  - Set-PSReadlineOption
  - "\u2013HistorySaveStyle"
  - SaveNothing
selection_payload_3:
  Payload|contains|all:
  - Set-PSReadlineOption
  - -HistorySaveStyle
  - SaveNothing

Suspicious Get-ADReplAccount

Description

The DSInternals PowerShell Module exposes several internal features of Active Directory and Azure Active Directory. These include FIDO2 and NGC key auditing, offline ntds.dit file manipulation, password auditing, DC recovery from IFM backups and password hash calculation.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - Get-ADReplAccount
  - '-All '
  - '-Server '

Suspicious IO.FileStream

Description

Open a handle on the drive volume via the \.\ DOS device path specifier and perform direct access read of the first few bytes of the volume.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - New-Object
  - IO.FileStream
  - \\\\.\\

Password Policy Discovery With Get-AdDefaultDomainPasswordPolicy

Description

Detetcts PowerShell activity in which Get-Addefaultdomainpasswordpolicy is used to get the default password policy for an Active Directory domain.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains: Get-AdDefaultDomainPasswordPolicy

Create Volume Shadow Copy with Powershell

Description

Adversaries may attempt to access or create a copy of the Active Directory domain database in order to steal credential information

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - win32_shadowcopy
  - ).Create(
  - ClientAccessible

Suspicious Invoke-Item From Mount-DiskImage

Description

Adversaries may abuse container files such as disk image (.iso, .vhd) file formats to deliver malicious payloads that may not be tagged with MOTW.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - 'Mount-DiskImage '
  - '-ImagePath '
  - Get-Volume
  - .DriveLetter
  - 'invoke-item '
  - ):\

Powershell Directory Enumeration

Description

Detects technique used by MAZE ransomware to enumerate directories using Powershell

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - foreach
  - Get-ChildItem
  - '-Path '
  - '-ErrorAction '
  - SilentlyContinue
  - 'Out-File '
  - -append

Suspicious Start-Process PassThru

Description

Powershell use PassThru option to start in background

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - Start-Process
  - '-PassThru '
  - '-FilePath '

Clear PowerShell History - PowerShell

Description

Detects keywords that could indicate clearing PowerShell history

Detection logic

condition: 1 of selection_* or all of selection1*
selection1a:
  ScriptBlockText|contains:
  - del
  - Remove-Item
  - rm
selection1b:
  ScriptBlockText|contains: (Get-PSReadlineOption).HistorySavePath
selection_2:
  ScriptBlockText|contains|all:
  - Set-PSReadlineOption
  - "\u2013HistorySaveStyle"
  - SaveNothing
selection_3:
  ScriptBlockText|contains|all:
  - Set-PSReadlineOption
  - -HistorySaveStyle
  - SaveNothing

Suspicious Unblock-File

Description

Remove the Zone.Identifier alternate data stream which identifies the file as downloaded from the internet.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - 'Unblock-File '
  - '-Path '

Tamper Windows Defender Remove-MpPreference - ScriptBlockLogging

Description

Detects attempts to remove Windows Defender configuration using the ‘MpPreference’ cmdlet

Detection logic

condition: all of selection_*
selection_remove:
  ScriptBlockText|contains: Remove-MpPreference
selection_tamper:
  ScriptBlockText|contains:
  - '-ControlledFolderAccessProtectedFolders '
  - '-AttackSurfaceReductionRules_Ids '
  - '-AttackSurfaceReductionRules_Actions '
  - '-CheckForSignaturesBeforeRunningScan '

Suspicious GetTypeFromCLSID ShellExecute

Description

Detects suspicious Powershell code that execute COM Objects

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - ::GetTypeFromCLSID(
  - .ShellExecute(

Suspicious Process Discovery With Get-Process

Description

Get the processes that are running on the local computer.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains: Get-Process

Suspicious GPO Discovery With Get-GPO

Description

Detect use of Get-GPO to get one GPO or all the GPOs in a domain.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains: Get-GPO

Suspicious Hyper-V Cmdlets

Description

Adversaries may carry out malicious operations using a virtual instance to avoid detection

Detection logic

condition: selection
selection:
  ScriptBlockText|contains:
  - New-VM
  - Set-VMFirmware
  - Start-VM

Get-ADUser Enumeration Using UserAccountControl Flags

Description

Detects AS-REP roasting is an attack that is often-overlooked. It is not very common as you have to explicitly set accounts that do not require pre-authentication.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - Get-ADUser
  - -Filter
  - useraccountcontrol
  - -band
  - '4194304'

Suspicious PowerShell Get Current User

Description

Detects the use of PowerShell to identify the current logged user.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains:
  - '[System.Environment]::UserName'
  - $env:UserName
  - '[System.Security.Principal.WindowsIdentity]::GetCurrent()'

Suspicious Mount-DiskImage

Description

Adversaries may abuse container files such as disk image (.iso, .vhd) file formats to deliver malicious payloads that may not be tagged with MOTW.

Detection logic

condition: selection
selection:
  ScriptBlockText|contains|all:
  - 'Mount-DiskImage '
  - '-ImagePath '