Git Hook Egress Network Connection

This rule detects a suspicious egress network connection attempt from a Git hook script. Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. An attacker can abuse these features to execute arbitrary commands on the system, establish persistence or to initialize a network connection to a remote server and exfiltrate data or download additional payloads.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2024/07/15"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2025/12/22"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10This rule detects a suspicious egress network connection attempt from a Git hook script. Git hooks are scripts that Git
 11executes before or after events such as: commit, push, and receive. An attacker can abuse these features to execute
 12arbitrary commands on the system, establish persistence or to initialize a network connection to a remote server and
 13exfiltrate data or download additional payloads.
 14"""
 15from = "now-9m"
 16index = ["logs-endpoint.events.process*", "logs-endpoint.events.network*"]
 17language = "eql"
 18license = "Elastic License v2"
 19name = "Git Hook Egress Network Connection"
 20note = """## Triage and analysis
 21
 22> **Disclaimer**:
 23> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
 24
 25### Investigating Git Hook Egress Network Connection
 26
 27Git hooks are scripts that automate tasks during Git operations like commits or pushes. Adversaries can exploit these hooks to execute unauthorized commands, maintain persistence, or initiate network connections for data exfiltration. The detection rule identifies suspicious network activities by monitoring script executions from Git hooks and subsequent egress connections to non-local IPs, flagging potential misuse.
 28
 29### Possible investigation steps
 30
 31- Review the process execution details to identify the specific Git hook script that triggered the alert. Check the process.args field for the exact script path within the .git/hooks directory.
 32- Investigate the parent process details to confirm the legitimacy of the Git operation. Verify the process.parent.name is "git" and assess whether the Git activity aligns with expected user or system behavior.
 33- Analyze the destination IP address involved in the network connection attempt. Use the destination.ip field to determine if the IP is known, trusted, or associated with any malicious activity.
 34- Check for any additional network connections from the same host around the time of the alert to identify potential patterns or additional suspicious activity.
 35- Correlate the alert with any recent changes in the repository or system that might explain the execution of the Git hook, such as recent commits or updates.
 36- Review user activity logs to determine if the Git operation was performed by an authorized user and if their actions align with their typical behavior.
 37- If suspicious activity is confirmed, isolate the affected system to prevent further unauthorized access or data exfiltration and initiate a deeper forensic analysis.
 38
 39### False positive analysis
 40
 41- Legitimate automated scripts or CI/CD pipelines may trigger Git hooks to perform network operations. Review the source and purpose of these scripts and consider excluding them if they are verified as non-threatening.
 42- Development environments often use Git hooks for tasks like fetching dependencies or updating remote services. Identify these common operations and create exceptions for known safe IP addresses or domains.
 43- Internal tools or services that rely on Git hooks for communication with other internal systems might be flagged. Ensure these tools are documented and whitelist their network activities if they are deemed secure.
 44- Frequent updates or deployments that involve Git hooks could lead to repeated alerts. Monitor the frequency and context of these alerts to determine if they are part of regular operations and adjust the rule to reduce noise.
 45- Consider the context of the network connection, such as the destination IP or domain. If the destination is a known and trusted entity, it may be appropriate to exclude it from triggering alerts.
 46
 47### Response and remediation
 48
 49- Immediately isolate the affected host from the network to prevent further unauthorized egress connections and potential data exfiltration.
 50- Terminate any suspicious processes identified as originating from Git hooks, particularly those executing shell scripts like bash, dash, or zsh.
 51- Conduct a thorough review of the .git/hooks directory on the affected system to identify and remove any unauthorized or malicious scripts.
 52- Reset credentials and access tokens associated with the affected Git repository to prevent further unauthorized access.
 53- Restore any modified or deleted files from a known good backup to ensure system integrity.
 54- Implement network monitoring to detect and block any future unauthorized egress connections from Git hooks or similar scripts.
 55- Escalate the incident to the security operations team for further investigation and to assess the potential impact on other systems or repositories."""
 56references = [
 57    "https://swisskyrepo.github.io/InternalAllTheThings/redteam/persistence/linux-persistence/#backdooring-git",
 58    "https://www.elastic.co/security-labs/sequel-on-persistence-mechanisms",
 59]
 60risk_score = 47
 61rule_id = "9822c5a1-1494-42de-b197-487197bb540c"
 62setup = """## Setup
 63
 64This rule requires data coming in from Elastic Defend.
 65
 66### Elastic Defend Integration Setup
 67Elastic 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.
 68
 69#### Prerequisite Requirements:
 70- Fleet is required for Elastic Defend.
 71- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 72
 73#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 74- Go to the Kibana home page and click "Add integrations".
 75- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 76- Click "Add Elastic Defend".
 77- Configure the integration name and optionally add a description.
 78- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 79- 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).
 80- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 81- 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.
 82For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 83- Click "Save and Continue".
 84- 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.
 85For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 86"""
 87severity = "medium"
 88tags = [
 89    "Domain: Endpoint",
 90    "OS: Linux",
 91    "Use Case: Threat Detection",
 92    "Tactic: Persistence",
 93    "Tactic: Execution",
 94    "Tactic: Defense Evasion",
 95    "Data Source: Elastic Defend",
 96    "Resources: Investigation Guide",
 97]
 98type = "eql"
 99query = '''
100sequence by host.id with maxspan=3s
101  [process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
102   process.parent.name == "git" and process.args like ".git/hooks/*" and
103   process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and
104   not (process.name like "python*" and process.command_line like "*pip*")
105  ] by process.entity_id
106  [network where host.os.type == "linux" and event.type == "start" and event.action == "connection_attempted" and not (
107     destination.ip == null or destination.ip == "0.0.0.0" or cidrmatch(
108       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",
109       "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",
110       "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",
111       "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",
112       "FF00::/8", "172.31.0.0/16"
113     )
114   )
115  ] by process.parent.entity_id
116'''
117
118[[rule.threat]]
119framework = "MITRE ATT&CK"
120
121[[rule.threat.technique]]
122id = "T1543"
123name = "Create or Modify System Process"
124reference = "https://attack.mitre.org/techniques/T1543/"
125
126[[rule.threat.technique]]
127id = "T1574"
128name = "Hijack Execution Flow"
129reference = "https://attack.mitre.org/techniques/T1574/"
130
131[rule.threat.tactic]
132id = "TA0003"
133name = "Persistence"
134reference = "https://attack.mitre.org/tactics/TA0003/"
135
136[[rule.threat]]
137framework = "MITRE ATT&CK"
138
139[[rule.threat.technique]]
140id = "T1059"
141name = "Command and Scripting Interpreter"
142reference = "https://attack.mitre.org/techniques/T1059/"
143
144[[rule.threat.technique.subtechnique]]
145id = "T1059.004"
146name = "Unix Shell"
147reference = "https://attack.mitre.org/techniques/T1059/004/"
148
149[rule.threat.tactic]
150id = "TA0002"
151name = "Execution"
152reference = "https://attack.mitre.org/tactics/TA0002/"
153
154[[rule.threat]]
155framework = "MITRE ATT&CK"
156
157[rule.threat.tactic]
158id = "TA0005"
159name = "Defense Evasion"
160reference = "https://attack.mitre.org/tactics/TA0005/"

Triage and analysis

Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.

Investigating Git Hook Egress Network Connection

Git hooks are scripts that automate tasks during Git operations like commits or pushes. Adversaries can exploit these hooks to execute unauthorized commands, maintain persistence, or initiate network connections for data exfiltration. The detection rule identifies suspicious network activities by monitoring script executions from Git hooks and subsequent egress connections to non-local IPs, flagging potential misuse.

Possible investigation steps

  • Review the process execution details to identify the specific Git hook script that triggered the alert. Check the process.args field for the exact script path within the .git/hooks directory.
  • Investigate the parent process details to confirm the legitimacy of the Git operation. Verify the process.parent.name is "git" and assess whether the Git activity aligns with expected user or system behavior.
  • Analyze the destination IP address involved in the network connection attempt. Use the destination.ip field to determine if the IP is known, trusted, or associated with any malicious activity.
  • Check for any additional network connections from the same host around the time of the alert to identify potential patterns or additional suspicious activity.
  • Correlate the alert with any recent changes in the repository or system that might explain the execution of the Git hook, such as recent commits or updates.
  • Review user activity logs to determine if the Git operation was performed by an authorized user and if their actions align with their typical behavior.
  • If suspicious activity is confirmed, isolate the affected system to prevent further unauthorized access or data exfiltration and initiate a deeper forensic analysis.

False positive analysis

  • Legitimate automated scripts or CI/CD pipelines may trigger Git hooks to perform network operations. Review the source and purpose of these scripts and consider excluding them if they are verified as non-threatening.
  • Development environments often use Git hooks for tasks like fetching dependencies or updating remote services. Identify these common operations and create exceptions for known safe IP addresses or domains.
  • Internal tools or services that rely on Git hooks for communication with other internal systems might be flagged. Ensure these tools are documented and whitelist their network activities if they are deemed secure.
  • Frequent updates or deployments that involve Git hooks could lead to repeated alerts. Monitor the frequency and context of these alerts to determine if they are part of regular operations and adjust the rule to reduce noise.
  • Consider the context of the network connection, such as the destination IP or domain. If the destination is a known and trusted entity, it may be appropriate to exclude it from triggering alerts.

Response and remediation

  • Immediately isolate the affected host from the network to prevent further unauthorized egress connections and potential data exfiltration.
  • Terminate any suspicious processes identified as originating from Git hooks, particularly those executing shell scripts like bash, dash, or zsh.
  • Conduct a thorough review of the .git/hooks directory on the affected system to identify and remove any unauthorized or malicious scripts.
  • Reset credentials and access tokens associated with the affected Git repository to prevent further unauthorized access.
  • Restore any modified or deleted files from a known good backup to ensure system integrity.
  • Implement network monitoring to detect and block any future unauthorized egress connections from Git hooks or similar scripts.
  • Escalate the incident to the security operations team for further investigation and to assess the potential impact on other systems or repositories.

References

Related rules

to-top