Detection rules › Elastic

Potential Shell Execution via NetCat

Source
github.com/elastic/protections-artifacts

Detects execution of a Windows command shell spawned as a result of connecting to or from a Netcat listener. Attackers often use Netcat to run commands on remote systems.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
Detects execution of a Windows command shell spawned as a result of connecting to or from a Netcat listener. Attackers
often use Netcat to run commands on remote systems.
"""
id = "2e80dd26-3966-4a16-9fad-ac643b5dd66e"
license = "Elastic License v2"
name = "Potential Shell Execution via NetCat"
os_list = ["windows"]
reference = ["https://github.coventry.ac.uk/pages/aa9863/5063CEM/3_LinuxAndShells/Netcat/"]
version = "1.0.2"

query = '''
process where event.action == "start" and
process.name : ("cmd.exe", "powershell.exe") and process.parent.args : "-e" and process.args_count == 1 and
 (
  (process.parent.args_count == 5 and process.parent.command_line regex~ """.*[0-9]{1,3}(\.[0-9]{1,3}){3}.*""") or
  (process.parent.args : "-*l*" and process.parent.args : "-*p*" and process.parent.args : ("cmd.exe", "powershell.exe") and
   not process.parent.name : ("cmd.exe", "powershell.exe") and process.parent.args_count <= 5)
  )
'''

min_endpoint_version = "8.10.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0
tree = true

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[threat.technique.subtechnique]]
id = "T1059.001"
name = "PowerShell"
reference = "https://attack.mitre.org/techniques/T1059/001/"

[[threat.technique.subtechnique]]
id = "T1059.003"
name = "Windows Command Shell"
reference = "https://attack.mitre.org/techniques/T1059/003/"



[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"

[internal]
min_endpoint_version = "8.10.0"

Stages and Predicates

Stage 1: process

process where event.action == "start" and
process.name : ("cmd.exe", "powershell.exe") and process.parent.args : "-e" and process.args_count == 1 and
 (
  (process.parent.args_count == 5 and process.parent.command_line regex~ """.*[0-9]{1,3}(\.[0-9]{1,3}){3}.*""") or
  (process.parent.args : "-*l*" and process.parent.args : "-*p*" and process.parent.args : ("cmd.exe", "powershell.exe") and
   not process.parent.name : ("cmd.exe", "powershell.exe") and process.parent.args_count <= 5)
  )

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • start corpus 391 (elastic 391)
field:"EventType" kind:eq value:"start"
process.args_counteq
  • 1 transforms: number corpus 49 (elastic 49)
field:"process.args_count" kind:eq value:"1"
process.namewildcard
  • cmd.exe corpus 121 (elastic 92, splunk 29)
  • powershell.exe corpus 184 (elastic 140, splunk 44)
field:"process_name" kind:wildcard
process.parent.argswildcard
  • -*l* corpus 2 (elastic 2)
  • -*p* corpus 2 (elastic 2)
  • -e corpus 3 (elastic 3)
  • cmd.exe corpus 2 (elastic 2)
  • powershell.exe corpus 2 (elastic 2)
field:"process.parent.args" kind:wildcard
process.parent.args_counteq
  • 5 transforms: number corpus 2 (elastic 2)
field:"process.parent.args_count" kind:eq value:"5"
process.parent.args_countle
  • 5 transforms: number
field:"process.parent.args_count" kind:le value:"5"
process.parent.command_lineregex_match
  • .*[0-9]{1,3}(.[0-9]{1,3}){3}.* corpus 2 (elastic 2)
field:"ParentCommandLine" kind:regex_match value:".*[0-9]{1,3}(.[0-9]{1,3}){3}.*"