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-kubernetes.audit_logs-* metadata _id, _index, _version | WHERE kubernetes.audit.objectRef.subresource == "exec" AND kubernetes.audit.requestURI LIKE "*command=*" | EVAL Esql.decoded_uri = URL_DECODE(kubernetes.audit.requestURI) | GROK Esql.decoded_uri "%{DATA}/exec\\?%{DATA:raw_commands}&(?:container|stdin|stdout|stderr)=%{GREEDYDATA}" | EVAL command = REPLACE(raw_commands, "command=", "") | EVAL command = REPLACE(command, "&", " ") | EVAL Esql.executed_command = REPLACE(command, "\\+", " ") | WHERE Esql.executed_command IS NOT NULL AND Esql.executed_command RLIKE """.*(curl.*https|wget.*https).*""" AND NOT Esql.executed_command RLIKE """.*(/api/v1/health|/healthz|/readyz|/livez|127\.0\.0\.1|localhost|/openid/v1/jwks|/openid-connect/certs|/.well-known/openid-configuration|/.well-known/jwks\.json|kubernetes\.default\.svc).*""" | KEEP Esql.*, user.name, user_agent.original, event.*, source.ip, kubernetes.audit.*, _id, _version, _index, data_stream.namespace
Install detection rules in Elastic Security
Detect Kubernetes Pod Exec with Curl or Wget to HTTPS 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).