Detection rules › Elastic

Suspicious File Creation via Web Server

Time window
3s
Sequence by
process.entity_id
Source
github.com/elastic/protections-artifacts

This rule detects suspicious file uploads to web servers. Attackers may exploit RCE or file upload vulnerabilities to upload malicious files to web servers to gain/maintain access and to establish a command and control channel.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
This rule detects suspicious file uploads to web servers. Attackers may exploit RCE or file upload vulnerabilities to
upload malicious files to web servers to gain/maintain access and to establish a command and control channel.
"""
id = "a67ef648-f04e-475c-8f53-a2db038ee834"
license = "Elastic License v2"
name = "Suspicious File Creation via Web Server"
os_list = ["linux"]
version = "1.0.7"

query = '''
sequence by process.entity_id with maxspan=3s
  [network where event.type == "start" and event.action == "connection_accepted" and not (
     source.ip == null or source.ip == "0.0.0.0" or cidrmatch(
       source.ip, "10.0.0.0/8", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24", "192.0.0.0/29",
       "192.0.0.8/32", "192.0.0.9/32", "192.0.0.10/32", "192.0.0.170/32", "192.0.0.171/32", "192.0.2.0/24",
       "192.31.196.0/24", "192.52.193.0/24", "192.168.0.0/16", "192.88.99.0/24", "224.0.0.0/4", "100.64.0.0/10",
       "192.175.48.0/24","198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "240.0.0.0/4", "::1", "FE80::/10",
       "FF00::/8"
     )
   )
  ]
  [file where event.type == "change" and event.action in ("rename", "creation") and 
   file.extension in ("py", "pl", "rb", "elf", "so", "rs", "lua", "jpeg", "md", "sh", "jsp") and (
     user.name in (
      "apache", "www-data", "httpd", "nginx", "lighttpd", "tomcat", "tomcat8", "tomcat9", "ftp", "ftpuser", "ftpd"
     ) or
     user.id in (99, 33, 498, 48)
   ) and (
     file.path : ("/var/www/*", "/tmp/*", "/var/tmp/*", "/dev/shm/*", "/root/*", "/home/*") and
     process.name : (
       "apache", "nginx", "apache2", "httpd", "lighttpd", "caddy", "php-*", "node", "mongrel_rails", "gunicorn",
       "uwsgi", "openresty", "cherokee", "h2o", "resin", "puma", "unicorn", "traefik", "tornado", "hypercorn",
       "daphne", "twistd", "yaws", "webfsd", "httpd.worker", "flask", "rails", "mongrel"
     )
   ) or
   (process.name : ("ruby*", "perl*", "python*", "java") and file.path : "/var/www/*") and
   not (
     file.name in (
       "config-livewaf.php", "pageviews-busy.php", "attack-data.php", "config-synced.php", "packages.php", "README.txt"
     ) or
     file.name like~ "cookie*.txt" or
     file.path like ("/tmp/requestdir/*", "/var/www/html/storage*", "/var/www/*/Cache/*", "/var/www/*/cache/*") or
     file.extension like ("log", "*-*-*", "webm") or
     process.executable like~ "/root/miniconda3/bin/python*"
   )
  ]
'''

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

[[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.004"
name = "Unix Shell"
reference = "https://attack.mitre.org/techniques/T1059/004/"



[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1505"
name = "Server Software Component"
reference = "https://attack.mitre.org/techniques/T1505/"
[[threat.technique.subtechnique]]
id = "T1505.003"
name = "Web Shell"
reference = "https://attack.mitre.org/techniques/T1505/003/"



[threat.tactic]
id = "TA0003"
name = "Persistence"
reference = "https://attack.mitre.org/tactics/TA0003/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1071"
name = "Application Layer Protocol"
reference = "https://attack.mitre.org/techniques/T1071/"


[threat.tactic]
id = "TA0011"
name = "Command and Control"
reference = "https://attack.mitre.org/tactics/TA0011/"

[internal]
min_endpoint_version = "7.15.0"

Stages and Predicates

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

Stage 1: network

[network where event.type == "start" and event.action == "connection_accepted" and not (
     source.ip == null or source.ip == "0.0.0.0" or cidrmatch(
       source.ip, "10.0.0.0/8", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24", "192.0.0.0/29",
       "192.0.0.8/32", "192.0.0.9/32", "192.0.0.10/32", "192.0.0.170/32", "192.0.0.171/32", "192.0.2.0/24",
       "192.31.196.0/24", "192.52.193.0/24", "192.168.0.0/16", "192.88.99.0/24", "224.0.0.0/4", "100.64.0.0/10",
       "192.175.48.0/24","198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "240.0.0.0/4", "::1", "FE80::/10",
       "FF00::/8"
     )
   )
  ]

Stage 2: file

[file where event.type == "change" and event.action in ("rename", "creation") and 
   file.extension in ("py", "pl", "rb", "elf", "so", "rs", "lua", "jpeg", "md", "sh", "jsp") and (
     user.name in (
      "apache", "www-data", "httpd", "nginx", "lighttpd", "tomcat", "tomcat8", "tomcat9", "ftp", "ftpuser", "ftpd"
     ) or
     user.id in (99, 33, 498, 48)
   ) and (
     file.path : ("/var/www/*", "/tmp/*", "/var/tmp/*", "/dev/shm/*", "/root/*", "/home/*") and
     process.name : (
       "apache", "nginx", "apache2", "httpd", "lighttpd", "caddy", "php-*", "node", "mongrel_rails", "gunicorn",
       "uwsgi", "openresty", "cherokee", "h2o", "resin", "puma", "unicorn", "traefik", "tornado", "hypercorn",
       "daphne", "twistd", "yaws", "webfsd", "httpd.worker", "flask", "rails", "mongrel"
     )
   ) or
   (process.name : ("ruby*", "perl*", "python*", "java") and file.path : "/var/www/*") and
   not (
     file.name in (
       "config-livewaf.php", "pageviews-busy.php", "attack-data.php", "config-synced.php", "packages.php", "README.txt"
     ) or
     file.name like~ "cookie*.txt" or
     file.path like ("/tmp/requestdir/*", "/var/www/html/storage*", "/var/www/*/Cache/*", "/var/www/*/cache/*") or
     file.extension like ("log", "*-*-*", "webm") or
     process.executable like~ "/root/miniconda3/bin/python*"
   )
  ]

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
source.ipcidr_match10.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.0.0.0/24, 192.0.0.0/29, 192.0.0.8/32, 192.0.0.9/32, 192.0.0.10/32, 192.0.0.170/32, 192.0.0.171/32, 192.0.2.0/24, 192.31.196.0/24, 192.52.193.0/24, 192.168.0.0/16, 192.88.99.0/24, 224.0.0.0/4, 100.64.0.0/10, 192.175.48.0/24, 198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24, 240.0.0.0/4, ::1, FE80::/10, FF00::/8excludes:source.ip
source.ipeq0.0.0.0excludes:source.ip field:"source.ip" value:"0.0.0.0"
source.ipis_null(no value, null check)excludes:source.ip

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • connection_accepted
field:"EventType" kind:eq value:"connection_accepted"
event.actionin
  • creation
  • rename
field:"EventType" kind:in
event.typeeq
  • change
  • start
field:"event.type" kind:eq
file.extensionin
  • elf
  • jpeg
  • jsp
  • lua
  • md
  • pl
  • py
  • rb
  • rs
  • sh
  • so
field:"file.extension" kind:in
file.pathwildcard
  • /dev/shm/*
  • /home/*
  • /root/*
  • /tmp/*
  • /var/tmp/*
  • /var/www/*
field:"TargetFilename" kind:wildcard
process.namewildcard
  • apache
  • apache2
  • caddy
  • cherokee
  • daphne
  • flask
  • gunicorn
  • h2o
  • httpd
  • httpd.worker
  • hypercorn
  • java
  • lighttpd
  • mongrel
  • mongrel_rails
  • nginx
  • node
  • openresty
  • perl*
  • php-*
  • puma
  • python*
  • rails
  • resin
  • ruby*
  • tornado
  • traefik
  • twistd
  • unicorn
  • uwsgi
  • webfsd
  • yaws
field:"process_name" kind:wildcard
user.idin
  • 33 transforms: number
  • 48 transforms: number
  • 498 transforms: number
  • 99 transforms: number
field:"user.id" kind:in
user.namein
  • apache
  • ftp
  • ftpd
  • ftpuser
  • httpd
  • lighttpd
  • nginx
  • tomcat
  • tomcat8
  • tomcat9
  • www-data
field:"user" kind:in