Git Hook Command Execution

This rule detects the execution of a potentially malicious process from a Git hook. Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. An attacker can abuse Git hooks to execute arbitrary commands on the system and establish persistence.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2024/07/15"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2024/09/23"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10This rule detects the execution of a potentially malicious process from a Git hook. Git hooks are scripts that Git
 11executes before or after events such as: commit, push, and receive. An attacker can abuse Git hooks to execute arbitrary
 12commands on the system and establish persistence.
 13"""
 14from = "now-9m"
 15index = ["logs-endpoint.events.process*"]
 16language = "eql"
 17license = "Elastic License v2"
 18name = "Git Hook Command Execution"
 19references = [
 20    "https://swisskyrepo.github.io/InternalAllTheThings/redteam/persistence/linux-persistence/#backdooring-git",
 21    "https://www.elastic.co/security-labs/sequel-on-persistence-mechanisms",
 22]
 23risk_score = 47
 24rule_id = "dc61f382-dc0c-4cc0-a845-069f2a071704"
 25setup = """## Setup
 26
 27This rule requires data coming in from Elastic Defend.
 28
 29### Elastic Defend Integration Setup
 30Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
 31
 32#### Prerequisite Requirements:
 33- Fleet is required for Elastic Defend.
 34- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 35
 36#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 37- Go to the Kibana home page and click "Add integrations".
 38- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 39- Click "Add Elastic Defend".
 40- Configure the integration name and optionally add a description.
 41- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 42- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
 43- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 44- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
 45For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 46- Click "Save and Continue".
 47- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
 48For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 49"""
 50severity = "medium"
 51tags = [
 52    "Domain: Endpoint",
 53    "OS: Linux",
 54    "Use Case: Threat Detection",
 55    "Tactic: Persistence",
 56    "Tactic: Execution",
 57    "Tactic: Defense Evasion",
 58    "Data Source: Elastic Defend",
 59]
 60type = "eql"
 61
 62query = '''
 63sequence by host.id with maxspan=3s
 64  [process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
 65   process.parent.name == "git" and process.args : ".git/hooks/*" and
 66   process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish")
 67  ] by process.entity_id
 68  [process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
 69   process.parent.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish")] by process.parent.entity_id
 70'''
 71
 72
 73[[rule.threat]]
 74framework = "MITRE ATT&CK"
 75[[rule.threat.technique]]
 76id = "T1543"
 77name = "Create or Modify System Process"
 78reference = "https://attack.mitre.org/techniques/T1543/"
 79
 80[[rule.threat.technique]]
 81id = "T1574"
 82name = "Hijack Execution Flow"
 83reference = "https://attack.mitre.org/techniques/T1574/"
 84
 85
 86[rule.threat.tactic]
 87id = "TA0003"
 88name = "Persistence"
 89reference = "https://attack.mitre.org/tactics/TA0003/"
 90[[rule.threat]]
 91framework = "MITRE ATT&CK"
 92[[rule.threat.technique]]
 93id = "T1059"
 94name = "Command and Scripting Interpreter"
 95reference = "https://attack.mitre.org/techniques/T1059/"
 96[[rule.threat.technique.subtechnique]]
 97id = "T1059.004"
 98name = "Unix Shell"
 99reference = "https://attack.mitre.org/techniques/T1059/004/"
100
101
102
103[rule.threat.tactic]
104id = "TA0002"
105name = "Execution"
106reference = "https://attack.mitre.org/tactics/TA0002/"
107[[rule.threat]]
108framework = "MITRE ATT&CK"
109
110[rule.threat.tactic]
111id = "TA0005"
112name = "Defense Evasion"
113reference = "https://attack.mitre.org/tactics/TA0005/"

References

Related rules

to-top