Detection rules › Elastic

Less Pipe Backdoor Execution

Source
github.com/elastic/protections-artifacts

This rule detects the execution of a backdoor script or command via the less pipe. Less is a utility that is used to view text files. By creating a malicious less configuration file, threat actors can execute a backdoor script or command on the target system upon file viewing.

MITRE ATT&CK coverage

TacticTechniques
Persistence

Rule body

[rule]
description = """
This rule detects the execution of a backdoor script or command via the less pipe. Less is a utility that is used to
view text files. By creating a malicious less configuration file, threat actors can execute a backdoor script or command
on the target system upon file viewing.
"""
id = "9cbbcea4-7a2c-49f9-8537-20a495fd03c5"
license = "Elastic License v2"
name = "Less Pipe Backdoor Execution"
os_list = ["linux"]
version = "1.0.1"

query = '''
process where event.type == "start" and event.action == "exec" and (
  process.name in ("setsid", "nohup", "disown") or
  (process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish", "mksh", "busybox") and process.args == "-c") or
  process.name like (".*", "python*", "perl*", "php*", "ruby*", "lua*", "node") or
  process.executable like (
    "./*", "/tmp/*", "/var/tmp/*", "/dev/shm/*", "/run/*", "/var/run/*", "/boot/*", "/sys/*",
    "/lost+found/*", "/proc/*", "/var/mail/*", "/var/www/*", "/root/*"
  )
) and
process.parent.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish", "mksh", "busybox") and
process.parent.command_line like "*lesspipe*" and not process.parent.args == "-c" and
not process.executable like "/nix/store/*"
'''

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

[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1546"
name = "Event Triggered Execution"
reference = "https://attack.mitre.org/techniques/T1546/"


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

[internal]
min_endpoint_version = "7.15.0"

Stages and Predicates

Stage 1: process

process where event.type == "start" and event.action == "exec" and (
  process.name in ("setsid", "nohup", "disown") or
  (process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish", "mksh", "busybox") and process.args == "-c") or
  process.name like (".*", "python*", "perl*", "php*", "ruby*", "lua*", "node") or
  process.executable like (
    "./*", "/tmp/*", "/var/tmp/*", "/dev/shm/*", "/run/*", "/var/run/*", "/boot/*", "/sys/*",
    "/lost+found/*", "/proc/*", "/var/mail/*", "/var/www/*", "/root/*"
  )
) and
process.parent.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish", "mksh", "busybox") and
process.parent.command_line like "*lesspipe*" and not process.parent.args == "-c" and
not process.executable like "/nix/store/*"

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.executablestarts_with/nix/store/excludes:process.executable field:"process.executable" value:"/nix/store/"
process.parent.argseq-cexcludes:process.parent.args field:"process.parent.args" value:"-c"

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • exec
field:"EventType" kind:eq value:"exec"
event.typeeq
  • start
field:"event.type" kind:eq value:"start"
process.argseq
  • -c
field:"process.args" kind:eq value:"-c"
process.executablewildcard
  • ./*
  • /boot/*
  • /dev/shm/*
  • /lost+found/*
  • /proc/*
  • /root/*
  • /run/*
  • /sys/*
  • /tmp/*
  • /var/mail/*
  • /var/run/*
  • /var/tmp/*
  • /var/www/*
field:"Image" kind:wildcard
process.namein
  • bash
  • busybox
  • csh
  • dash
  • disown
  • fish
  • ksh
  • mksh
  • nohup
  • setsid
  • sh
  • tcsh
  • zsh
field:"process_name" kind:in
process.namewildcard
  • .*
  • lua*
  • node
  • perl*
  • php*
  • python*
  • ruby*
field:"process_name" kind:wildcard
process.parent.command_linewildcard
  • *lesspipe*
field:"ParentCommandLine" kind:wildcard value:"*lesspipe*"
process.parent.namein
  • bash
  • busybox
  • csh
  • dash
  • fish
  • ksh
  • mksh
  • sh
  • tcsh
  • zsh
field:"parent_process_name" kind:in