Persistence (TA0003)(external, opens in a new tab or window)
text code block:FROM logs-aws.cloudtrail-* METADATA _id, _version, _index | WHERE event.provider == "sagemaker.amazonaws.com" AND event.action IN ("CreateNotebookInstanceLifecycleConfig", "UpdateNotebookInstanceLifecycleConfig") AND event.outcome == "success" AND aws.cloudtrail.user_identity.type != "AWSService" | GROK aws.cloudtrail.request_parameters "[Cc]ontent=(?<script_b64>[A-Za-z0-9+/=]+)" | EVAL Esql_priv.aws_cloudtrail_lifecycle_script = FROM_BASE64(script_b64) | WHERE TO_LOWER(Esql_priv.aws_cloudtrail_lifecycle_script) RLIKE """.*(/dev/tcp/|/dev/udp/|bash -i|sh -i|nc -e|ncat |socat |mkfifo|169\.254\.169\.254|/latest/meta-data/|/latest/api/token|\| ?sh|\| ?bash|base64 -d|import socket|pty\.spawn|perl -e|ruby -rsocket|php -r|xmrig|minerd|stratum\+|authorized_keys|/etc/cron|crontab ).*""" | KEEP _id, _version, _index, @timestamp, aws.*, cloud.*, event.*, source.*, user.*, user_agent.*, Esql_priv.aws_cloudtrail_lifecycle_script
Install detection rules in Elastic Security
Detect AWS SageMaker Notebook Lifecycle Configuration With Suspicious Script Content 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).