Elastic Defend high stable eql

Python Network Connection Followed by Command Execution

Detects network connections originating from Python, followed by a suspicious command execution. This behavior is consistent with Python-based agents such as Medusa connecting to a C2 framework such as Mythic. The agent polls the C2 for commands through a web request, after which the command gets executed.

View Source

Detection Logic

sequence with maxspan=3s
  [network where event.type == "start" and event.action == "connection_attempted" and
   process.name like "python*" and 
   process.executable like ("/bin/python*", "/usr/bin/python*", "/usr/local/bin/python*") and
   not (
     destination.ip == null or destination.ip == "0.0.0.0" or cidrmatch(
       destination.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"
     )
   )
  ] by process.entity_id
  [process where event.type == "start" and event.action == "exec" and
   process.parent.executable like ("/bin/python*", "/usr/bin/python*", "/usr/local/bin/python*") and
   process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and process.args == "-c" and
   process.parent.args_count < 3 and process.command_line like (
     "*whoami*", "* wget *", "* chmod *", "* busybox *", "* chattr *", "* php*", "* perl*", "* ruby*", "* lua*",
     "*netcat *", "*ncat *", "*/dev/shm/*", "* base64 *", "*base32*"
   ) and not (
     process.parent.executable like (
       "/opt/code/localstack/.venv/bin/python", "/opt/imunify360*", "/var/www/kyb/*/env/bin/python3",
       "/opt/saltstack/salt/bin/python*", "/usr/lib/venv-salt-minion/bin/python.original"
     ) or
     process.parent.args in ("/sbin/mount.efs", "/usr/local/bin/cloud_updater.py") or
     process.command_line in (
       "/bin/sh -c echo $(ls /home/) root 2>/dev/null",
       "/bin/sh -c (dir 2>&1 *`
| echo CMD);&<# rem #>echo powershell",
       "/bin/sh -c chmod 744 /tmp/import_gpgkey.sh"
     ) or
     process.parent.command_line in (
       "/opt/imunify360/venv/bin/python3 -m im360.run", "python3 /app_v2/user_monitor_v2.2.py"
    ) or
     process.args like ("*openssl*", "/home/*/connect.sh*", "*scraper*", "*crawler*", "*X-aws-ec2-metadata-token:*") or
     process.parent.command_line like ("*scraper*", "*crawler*", "*ansible*")
   )
  ] by process.parent.entity_id

Field Validations

Loading…

Comments (0)

Loading comments...