Suspicious File Creation via Web Server
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.
Query · eql
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*"
)
]