Detection rules › Elastic

Suspicious PowerShell Console History Deletion

Time window
5m
Sequence by
process.entity_id
Source
github.com/elastic/protections-artifacts

Identifies when a process attempts to delete PowerShell Console History. An adversary may clear the command history of a compromised account to conceal the actions undertaken during an intrusion.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
Identifies when a process attempts to delete PowerShell Console History. An adversary may clear the command history of a
compromised account to conceal the actions undertaken during an intrusion.
"""
id = "feb6d562-7c15-412a-8be1-48d93f382028"
license = "Elastic License v2"
name = "Suspicious PowerShell Console History Deletion"
os_list = ["windows"]
reference = ["https://attack.mitre.org/techniques/T1070/004/"]
version = "1.0.10"

query = '''
sequence by process.entity_id with maxspan=5m
[process where event.action == "start" and
 (
  process.name in~ ("powershell.exe", "rundll32.exe", "regsvr32.exe", "cmd.exe", "wscript.exe", "cscript.exe", "mshta.exe",
                  "winword.exe", "excel.exe") or
  process.executable : ("?:\\Users\\*", "?:\\Windows\\Temp\\*", "?:\\ProgramData\\*", "?:\\Windows\\Microsoft.NEt\\*") or
  (process.code_signature.trusted == false or process.code_signature.exists == false)
 ) and
 not user.id in ("S-1-5-18", "S-1-5-19")
 ]
[file where event.action == "deletion" and file.name : "ConsoleHost_history.txt"]
'''

min_endpoint_version = "7.16.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1070"
name = "Indicator Removal"
reference = "https://attack.mitre.org/techniques/T1070/"
[[threat.technique.subtechnique]]
id = "T1070.003"
name = "Clear Command History"
reference = "https://attack.mitre.org/techniques/T1070/003/"

[[threat.technique.subtechnique]]
id = "T1070.004"
name = "File Deletion"
reference = "https://attack.mitre.org/techniques/T1070/004/"



[threat.tactic]
id = "TA0005"
name = "Defense Evasion"
reference = "https://attack.mitre.org/tactics/TA0005/"

[internal]
min_endpoint_version = "7.16.0"

Stages and Predicates

Ordered sequence: each step below must occur in order within 5m, correlated by process.entity_id.

Stage 1: process

[process where event.action == "start" and
 (
  process.name in~ ("powershell.exe", "rundll32.exe", "regsvr32.exe", "cmd.exe", "wscript.exe", "cscript.exe", "mshta.exe",
                  "winword.exe", "excel.exe") or
  process.executable : ("?:\\Users\\*", "?:\\Windows\\Temp\\*", "?:\\ProgramData\\*", "?:\\Windows\\Microsoft.NEt\\*") or
  (process.code_signature.trusted == false or process.code_signature.exists == false)
 ) and
 not user.id in ("S-1-5-18", "S-1-5-19")
 ]

Stage 2: file

[file where event.action == "deletion" and file.name : "ConsoleHost_history.txt"]

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
user.idinS-1-5-18, S-1-5-19excludes:user.id field:"user.id" value:"S-1-5-18" field:"user.id" value:"S-1-5-19"

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • deletion corpus 12 (elastic 12)
  • start corpus 391 (elastic 391)
field:"EventType" kind:eq
file.namewildcard
  • ConsoleHost_history.txt
field:"file.name" kind:wildcard value:"ConsoleHost_history.txt"
process.code_signature.existseq
  • false transforms: boolean corpus 119 (elastic 119)
field:"process.code_signature.exists" kind:eq value:"false"
process.code_signature.trustedeq
  • false transforms: boolean corpus 115 (elastic 115)
field:"process.code_signature.trusted" kind:eq value:"false"
process.executablewildcard
  • ?:\ProgramData\* corpus 17 (elastic 17)
  • ?:\Users\* corpus 18 (elastic 18)
  • ?:\Windows\Microsoft.NEt\* corpus 5 (elastic 5)
  • ?:\Windows\Temp\* corpus 9 (elastic 9)
field:"Image" kind:wildcard
process.namein
  • cmd.exe corpus 121 (elastic 92, splunk 29)
  • cscript.exe corpus 67 (elastic 65, splunk 2)
  • excel.exe corpus 34 (elastic 34)
  • mshta.exe corpus 84 (elastic 79, splunk 5)
  • powershell.exe corpus 184 (elastic 140, splunk 44)
  • regsvr32.exe corpus 73 (elastic 68, splunk 5)
  • rundll32.exe corpus 126 (elastic 100, splunk 26)
  • winword.exe corpus 35 (elastic 35)
  • wscript.exe corpus 83 (elastic 82, splunk 1)
field:"process_name" kind:in