Suspicious APT Package Manager Network Connection
Detects suspicious network events executed by the APT package manager, potentially indicating persistence through an APT backdoor. In Linux, APT (Advanced Package Tool) is a command-line utility used for handling packages on Debian-based systems, providing functions for installing, updating, upgrading, and removing software along with managing package repositories. Attackers can backdoor APT to gain persistence by injecting malicious code into scripts that APT runs, thereby ensuring continued unauthorized access or control each time APT is used for package management.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2024/02/01"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2025/01/15"
6
7[rule]
8author = ["Elastic"]
9description = """
10Detects suspicious network events executed by the APT package manager, potentially indicating persistence through an APT
11backdoor. In Linux, APT (Advanced Package Tool) is a command-line utility used for handling packages on Debian-based
12systems, providing functions for installing, updating, upgrading, and removing software along with managing package
13repositories. Attackers can backdoor APT to gain persistence by injecting malicious code into scripts that APT runs,
14thereby ensuring continued unauthorized access or control each time APT is used for package management.
15"""
16from = "now-9m"
17index = ["logs-endpoint.events.*"]
18language = "eql"
19license = "Elastic License v2"
20name = "Suspicious APT Package Manager Network Connection"
21references = ["https://www.elastic.co/security-labs/sequel-on-persistence-mechanisms"]
22risk_score = 47
23rule_id = "eaef8a35-12e0-4ac0-bc14-81c72b6bd27c"
24setup = """## Setup
25
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: Command and Control",
57 "Tactic: Defense Evasion",
58 "Data Source: Elastic Defend",
59 "Resources: Investigation Guide",
60]
61type = "eql"
62
63query = '''
64sequence by host.id with maxspan=5s
65 [process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
66 process.parent.name == "apt" and process.args == "-c" and process.name in (
67 "bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish"
68 )
69 ] by process.entity_id
70 [network where host.os.type == "linux" and event.action == "connection_attempted" and event.type == "start" and not (
71 destination.ip == null or destination.ip == "0.0.0.0" or cidrmatch(
72 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",
73 "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",
74 "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",
75 "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",
76 "FF00::/8", "172.31.0.0/16"
77 )
78 ) and not process.executable == "/usr/bin/apt-listbugs"
79 ] by process.parent.entity_id
80'''
81note = """## Triage and analysis
82
83> **Disclaimer**:
84> 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.
85
86### Investigating Suspicious APT Package Manager Network Connection
87
88The APT package manager is crucial for managing software on Debian-based Linux systems. Adversaries may exploit APT by injecting malicious scripts, gaining persistence and control. The detection rule identifies suspicious APT-triggered shell executions followed by unusual network connections, flagging potential backdoor activities and unauthorized access attempts.
89
90### Possible investigation steps
91
92- Review the process details to confirm the parent process is indeed 'apt' and check the command-line arguments for any unusual or unauthorized scripts being executed.
93- Investigate the network connection details, focusing on the destination IP address to determine if it is known to be malicious or associated with suspicious activity. Cross-reference with threat intelligence sources.
94- Examine the process tree to identify any child processes spawned by the suspicious shell execution, which may provide further insight into the attacker's actions or intentions.
95- Check the system logs for any other recent unusual activities or alerts that might correlate with the suspicious APT activity, such as unauthorized user logins or file modifications.
96- Assess the system for any signs of persistence mechanisms that may have been established, such as cron jobs or modified startup scripts, which could indicate a backdoor installation.
97- If possible, capture and analyze network traffic to and from the destination IP to understand the nature of the communication and identify any data exfiltration or command and control activities.
98
99### False positive analysis
100
101- Legitimate administrative scripts executed by APT may trigger the rule if they involve shell commands followed by network connections. Users can create exceptions for known scripts by specifying their paths or hashes.
102- Automated system updates or package installations that involve network connections might be flagged. Users should monitor and whitelist these routine operations by identifying the specific processes and network destinations involved.
103- Network connections to internal or trusted IP addresses not covered by the existing CIDR exclusions could be mistakenly flagged. Users can expand the CIDR list to include additional trusted IP ranges specific to their environment.
104- Use of alternative shell environments or custom scripts that invoke APT with network operations may cause false positives. Users should document and exclude these specific use cases by process name or command-line arguments.
105- Non-standard APT configurations or third-party tools that interact with APT and initiate network connections might be misidentified. Users should review and whitelist these tools by their executable paths or process names.
106
107### Response and remediation
108
109- Isolate the affected host immediately to prevent further unauthorized network connections and potential lateral movement within the network.
110- Terminate any suspicious processes identified as being executed by the APT package manager, especially those involving shell executions.
111- Conduct a thorough review of the APT configuration files and scripts to identify and remove any injected malicious code or unauthorized modifications.
112- Revert any unauthorized changes to the system or software packages by restoring from a known good backup, ensuring the integrity of the system.
113- Update all system packages and apply security patches to close any vulnerabilities that may have been exploited by the attacker.
114- Monitor network traffic for any further suspicious connections or activities originating from the affected host, using enhanced logging and alerting mechanisms.
115- Escalate the incident to the security operations team for further investigation and to determine if additional systems have been compromised, ensuring a comprehensive response."""
116
117
118[[rule.threat]]
119framework = "MITRE ATT&CK"
120[[rule.threat.technique]]
121id = "T1543"
122name = "Create or Modify System Process"
123reference = "https://attack.mitre.org/techniques/T1543/"
124
125[[rule.threat.technique]]
126id = "T1546"
127name = "Event Triggered Execution"
128reference = "https://attack.mitre.org/techniques/T1546/"
129[[rule.threat.technique.subtechnique]]
130id = "T1546.016"
131name = "Installer Packages"
132reference = "https://attack.mitre.org/techniques/T1546/016/"
133
134
135[[rule.threat.technique]]
136id = "T1574"
137name = "Hijack Execution Flow"
138reference = "https://attack.mitre.org/techniques/T1574/"
139
140
141[rule.threat.tactic]
142id = "TA0003"
143name = "Persistence"
144reference = "https://attack.mitre.org/tactics/TA0003/"
145[[rule.threat]]
146framework = "MITRE ATT&CK"
147
148[rule.threat.tactic]
149id = "TA0011"
150name = "Command and Control"
151reference = "https://attack.mitre.org/tactics/TA0011/"
152[[rule.threat]]
153framework = "MITRE ATT&CK"
154
155[rule.threat.tactic]
156id = "TA0005"
157name = "Defense Evasion"
158reference = "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 Suspicious APT Package Manager Network Connection
The APT package manager is crucial for managing software on Debian-based Linux systems. Adversaries may exploit APT by injecting malicious scripts, gaining persistence and control. The detection rule identifies suspicious APT-triggered shell executions followed by unusual network connections, flagging potential backdoor activities and unauthorized access attempts.
Possible investigation steps
- Review the process details to confirm the parent process is indeed 'apt' and check the command-line arguments for any unusual or unauthorized scripts being executed.
- Investigate the network connection details, focusing on the destination IP address to determine if it is known to be malicious or associated with suspicious activity. Cross-reference with threat intelligence sources.
- Examine the process tree to identify any child processes spawned by the suspicious shell execution, which may provide further insight into the attacker's actions or intentions.
- Check the system logs for any other recent unusual activities or alerts that might correlate with the suspicious APT activity, such as unauthorized user logins or file modifications.
- Assess the system for any signs of persistence mechanisms that may have been established, such as cron jobs or modified startup scripts, which could indicate a backdoor installation.
- If possible, capture and analyze network traffic to and from the destination IP to understand the nature of the communication and identify any data exfiltration or command and control activities.
False positive analysis
- Legitimate administrative scripts executed by APT may trigger the rule if they involve shell commands followed by network connections. Users can create exceptions for known scripts by specifying their paths or hashes.
- Automated system updates or package installations that involve network connections might be flagged. Users should monitor and whitelist these routine operations by identifying the specific processes and network destinations involved.
- Network connections to internal or trusted IP addresses not covered by the existing CIDR exclusions could be mistakenly flagged. Users can expand the CIDR list to include additional trusted IP ranges specific to their environment.
- Use of alternative shell environments or custom scripts that invoke APT with network operations may cause false positives. Users should document and exclude these specific use cases by process name or command-line arguments.
- Non-standard APT configurations or third-party tools that interact with APT and initiate network connections might be misidentified. Users should review and whitelist these tools by their executable paths or process names.
Response and remediation
- Isolate the affected host immediately to prevent further unauthorized network connections and potential lateral movement within the network.
- Terminate any suspicious processes identified as being executed by the APT package manager, especially those involving shell executions.
- Conduct a thorough review of the APT configuration files and scripts to identify and remove any injected malicious code or unauthorized modifications.
- Revert any unauthorized changes to the system or software packages by restoring from a known good backup, ensuring the integrity of the system.
- Update all system packages and apply security patches to close any vulnerabilities that may have been exploited by the attacker.
- Monitor network traffic for any further suspicious connections or activities originating from the affected host, using enhanced logging and alerting mechanisms.
- Escalate the incident to the security operations team for further investigation and to determine if additional systems have been compromised, ensuring a comprehensive response.
References
Related rules
- Suspicious Network Connection via systemd
- APT Package Manager Configuration File Creation
- DNF Package Manager Plugin File Creation
- Directory Creation in /bin directory
- Dynamic Linker (ld.so) Creation