Detection rules › Elastic

Potential Gsocket Activity

Source
github.com/elastic/protections-artifacts

This rule detects the execution of gsocket binaries or scripts that may be used to establish a reverse shell or exfiltrate data from a compromised system. Gsocket is a tool that can be used to create a reverse shell, transfer files, or mount remote directories over a network connection. This activity may indicate an attacker is attempting to establish persistence or move laterally within a network.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
This rule detects the execution of gsocket binaries or scripts that may be used to establish a reverse shell or
exfiltrate data from a compromised system. Gsocket is a tool that can be used to create a reverse shell, transfer files,
or mount remote directories over a network connection. This activity may indicate an attacker is attempting to establish
persistence or move laterally within a network.
"""
id = "9015e5ec-a68d-4539-923d-a96d2c6227d3"
license = "Elastic License v2"
name = "Potential Gsocket Activity"
os_list = ["linux"]
reference = ["https://github.com/hackerschoice/gsocket", "https://www.gsocket.io/", "https://www.thc.org/ssh-it/"]
version = "1.0.8"

query = '''
process where event.type == "start" and event.action == "exec" and
process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and
process.command_line like~ (
  "*GS_ARGS=*", "*gs-netcat*", "*gs-sftp*", "*gs-mount*", "*gs-full-pipe*", "*GS_NOINST=*", "*GSOCKET_ARGS=*",
  "*GS_DSTDIR=*", "*GS_URL_BASE=*", "*GS_OSARCH=*", "*GS_HIDDEN_NAME=*", "*GS_HOST=*",
  "* GS_PORT=*", "*GS_TG_TOKEN=*", "*GS_TG_CHATID=*", "*GS_DISCORD_KEY=*", "*GS_WEBHOOK_KEY=*"
) and not (
  process.parent.name in ("make", "ninja", "qmake", "gmake") or
  process.parent.executable like ("/tmp/newroot/nix/store/*/generator/generator", "/usr/share/cursor/cursor") or
  process.command_line like "*/bin/qmake*"
)
'''

min_endpoint_version = "7.15.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0

[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[threat.technique.subtechnique]]
id = "T1059.004"
name = "Unix Shell"
reference = "https://attack.mitre.org/techniques/T1059/004/"



[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1071"
name = "Application Layer Protocol"
reference = "https://attack.mitre.org/techniques/T1071/"


[threat.tactic]
id = "TA0011"
name = "Command and Control"
reference = "https://attack.mitre.org/tactics/TA0011/"

[internal]
min_endpoint_version = "7.15.0"

Stages and Predicates

Stage 1: process

process where event.type == "start" and event.action == "exec" and
process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and
process.command_line like~ (
  "*GS_ARGS=*", "*gs-netcat*", "*gs-sftp*", "*gs-mount*", "*gs-full-pipe*", "*GS_NOINST=*", "*GSOCKET_ARGS=*",
  "*GS_DSTDIR=*", "*GS_URL_BASE=*", "*GS_OSARCH=*", "*GS_HIDDEN_NAME=*", "*GS_HOST=*",
  "* GS_PORT=*", "*GS_TG_TOKEN=*", "*GS_TG_CHATID=*", "*GS_DISCORD_KEY=*", "*GS_WEBHOOK_KEY=*"
) and not (
  process.parent.name in ("make", "ninja", "qmake", "gmake") or
  process.parent.executable like ("/tmp/newroot/nix/store/*/generator/generator", "/usr/share/cursor/cursor") or
  process.command_line like "*/bin/qmake*"
)

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.command_linematch/bin/qmakeexcludes:process.command_line field:"process.command_line" value:"/bin/qmake"
process.parent.executablewildcard/tmp/newroot/nix/store/*/generator/generator, /usr/share/cursor/cursorexcludes:process.parent.executable field:"process.parent.executable" value:"/tmp/newroot/nix/store/*/generator/generator" field:"process.parent.executable" value:"/usr/share/cursor/cursor"
process.parent.nameingmake, make, ninja, qmakeexcludes:process.parent.name

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • exec
field:"EventType" kind:eq value:"exec"
event.typeeq
  • start
field:"event.type" kind:eq value:"start"
process.command_linewildcard
  • * GS_PORT=*
  • *GSOCKET_ARGS=*
  • *GS_ARGS=*
  • *GS_DISCORD_KEY=*
  • *GS_DSTDIR=*
  • *GS_HIDDEN_NAME=*
  • *GS_HOST=*
  • *GS_NOINST=*
  • *GS_OSARCH=*
  • *GS_TG_CHATID=*
  • *GS_TG_TOKEN=*
  • *GS_URL_BASE=*
  • *GS_WEBHOOK_KEY=*
  • *gs-full-pipe*
  • *gs-mount*
  • *gs-netcat*
  • *gs-sftp*
field:"CommandLine" kind:wildcard
process.namein
  • bash
  • csh
  • dash
  • fish
  • ksh
  • sh
  • tcsh
  • zsh
field:"process_name" kind:in