Persistence (TA0003)(external, opens in a new tab or window)
Execution (TA0002)(external, opens in a new tab or window)
Command and Control (TA0011)(external, opens in a new tab or window)
text code block:from logs-endpoint.events.process-* | keep @timestamp, host.os.type, event.type, event.action, process.parent.name, user.name, user.id, process.working_directory, process.name, process.command_line, process.parent.executable, agent.id, host.name | where @timestamp > now() - 1 hours and host.os.type == "linux" and event.type == "start" and event.action == "exec" and ( ( process.parent.name in ( "apache", "nginx", "apache2", "httpd", "lighttpd", "caddy", "node", "mongrel_rails", "java", "gunicorn", "uwsgi", "openresty", "cherokee", "h2o", "resin", "puma", "unicorn", "traefik", "tornado", "hypercorn", "daphne", "twistd", "yaws", "webfsd", "httpd.worker", "flask", "rails", "mongrel" ) or user.name in ( "apache", "www-data", "httpd", "nginx", "lighttpd", "tomcat", "tomcat8", "tomcat9", "ftp", "ftpuser", "ftpd" ) or user.id in ("99", "33", "498", "48") or process.working_directory like "/var/www/*" ) or ( ( process.parent.name like "php-*" or process.parent.name like "python*" or process.parent.name like "ruby*" or process.parent.name like "perl*" ) and ( process.working_directory like "/var/www/*" or process.working_directory like "/srv/www/*" or process.working_directory like "/usr/share/nginx/*" ) ) ) and process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and process.command_line like "* -c *" and not ( process.working_directory like "/home/*" or process.working_directory == "/" or process.working_directory like "/vscode/vscode-server/*" or process.parent.executable like "/vscode/vscode-server/*" or process.parent.executable == "/usr/bin/xfce4-terminal" ) | stats Esql.event_count = count(), Esql.agent_id_count_distinct = count_distinct(agent.id), Esql.host_name_values = values(host.name), Esql.agent_id_values = values(agent.id) by process.command_line, process.working_directory, process.parent.executable | where Esql.agent_id_count_distinct == 1 and Esql.event_count < 5 | sort Esql.event_count asc | limit 100
Install detection rules in Elastic Security
Detect Unusual Command Execution from Web Server Parent in the Elastic Security detection engine by installing this rule into your Elastic Stack.
To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).