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 = "2024/09/23"
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"
20references = [
21 "https://swisskyrepo.github.io/InternalAllTheThings/redteam/persistence/linux-persistence/#backdooring-git",
22 "https://www.elastic.co/security-labs/sequel-on-persistence-mechanisms",
23]
24risk_score = 47
25rule_id = "9822c5a1-1494-42de-b197-487197bb540c"
26setup = """## Setup
27
28This rule requires data coming in from Elastic Defend.
29
30### Elastic Defend Integration Setup
31Elastic 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.
32
33#### Prerequisite Requirements:
34- Fleet is required for Elastic Defend.
35- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
36
37#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
38- Go to the Kibana home page and click "Add integrations".
39- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
40- Click "Add Elastic Defend".
41- Configure the integration name and optionally add a description.
42- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
43- 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).
44- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
45- 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.
46For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
47- Click "Save and Continue".
48- 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.
49For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
50"""
51severity = "medium"
52tags = [
53 "Domain: Endpoint",
54 "OS: Linux",
55 "Use Case: Threat Detection",
56 "Tactic: Persistence",
57 "Tactic: Execution",
58 "Tactic: Defense Evasion",
59 "Data Source: Elastic Defend",
60]
61type = "eql"
62
63query = '''
64sequence by host.id with maxspan=3s
65 [process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
66 process.parent.name == "git" and process.args : ".git/hooks/*" and
67 process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish")] by process.entity_id
68 [network where host.os.type == "linux" and event.type == "start" and event.action == "connection_attempted" and not (
69 destination.ip == null or destination.ip == "0.0.0.0" or cidrmatch(
70 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",
71 "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",
72 "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",
73 "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",
74 "FF00::/8", "172.31.0.0/16"
75 )
76 )
77 ] by process.parent.entity_id
78'''
79
80
81[[rule.threat]]
82framework = "MITRE ATT&CK"
83[[rule.threat.technique]]
84id = "T1543"
85name = "Create or Modify System Process"
86reference = "https://attack.mitre.org/techniques/T1543/"
87
88[[rule.threat.technique]]
89id = "T1574"
90name = "Hijack Execution Flow"
91reference = "https://attack.mitre.org/techniques/T1574/"
92
93
94[rule.threat.tactic]
95id = "TA0003"
96name = "Persistence"
97reference = "https://attack.mitre.org/tactics/TA0003/"
98[[rule.threat]]
99framework = "MITRE ATT&CK"
100[[rule.threat.technique]]
101id = "T1059"
102name = "Command and Scripting Interpreter"
103reference = "https://attack.mitre.org/techniques/T1059/"
104[[rule.threat.technique.subtechnique]]
105id = "T1059.004"
106name = "Unix Shell"
107reference = "https://attack.mitre.org/techniques/T1059/004/"
108
109
110
111[rule.threat.tactic]
112id = "TA0002"
113name = "Execution"
114reference = "https://attack.mitre.org/tactics/TA0002/"
115[[rule.threat]]
116framework = "MITRE ATT&CK"
117
118[rule.threat.tactic]
119id = "TA0005"
120name = "Defense Evasion"
121reference = "https://attack.mitre.org/tactics/TA0005/"
References
Related rules
- Git Hook Child Process
- Git Hook Command Execution
- Suspicious APT Package Manager Execution
- At Job Created or Modified
- DNF Package Manager Plugin File Creation