Suspicious APT Package Manager Execution

Detects suspicious process 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", "sentinel_one_cloud_funnel"]
  4maturity = "production"
  5min_stack_version = "8.13.0"
  6min_stack_comments = "Breaking change at 8.13.0 for SentinelOne Integration."
  7updated_date = "2025/01/15"
  8
  9[rule]
 10author = ["Elastic"]
 11description = """
 12Detects suspicious process events executed by the APT package manager, potentially indicating persistence through an APT
 13backdoor. In Linux, APT (Advanced Package Tool) is a command-line utility used for handling packages on Debian-based
 14systems, providing functions for installing, updating, upgrading, and removing software along with managing package
 15repositories. Attackers can backdoor APT to gain persistence by injecting malicious code into scripts that APT runs,
 16thereby ensuring continued unauthorized access or control each time APT is used for package management.
 17"""
 18from = "now-9m"
 19index = ["logs-endpoint.events.*", "logs-sentinel_one_cloud_funnel.*"]
 20language = "eql"
 21license = "Elastic License v2"
 22name = "Suspicious APT Package Manager Execution"
 23references = ["https://www.elastic.co/security-labs/sequel-on-persistence-mechanisms"]
 24risk_score = 47
 25rule_id = "ad959eeb-2b7b-4722-ba08-a45f6622f005"
 26setup = """## Setup
 27
 28
 29This rule requires data coming in from Elastic Defend.
 30
 31### Elastic Defend Integration Setup
 32Elastic 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.
 33
 34#### Prerequisite Requirements:
 35- Fleet is required for Elastic Defend.
 36- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 37
 38#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 39- Go to the Kibana home page and click "Add integrations".
 40- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 41- Click "Add Elastic Defend".
 42- Configure the integration name and optionally add a description.
 43- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 44- 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).
 45- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 46- 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.
 47For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 48- Click "Save and Continue".
 49- 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.
 50For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 51"""
 52severity = "medium"
 53tags = [
 54    "Domain: Endpoint",
 55    "OS: Linux",
 56    "Use Case: Threat Detection",
 57    "Tactic: Persistence",
 58    "Tactic: Execution",
 59    "Tactic: Defense Evasion",
 60    "Data Source: Elastic Defend",
 61    "Data Source: SentinelOne",
 62    "Resources: Investigation Guide",
 63]
 64type = "eql"
 65
 66query = '''
 67sequence by host.id with maxspan=5s
 68  [process where host.os.type == "linux" and event.type == "start" and event.action in ("exec", "start") and
 69   process.parent.name == "apt" and process.args == "-c" and process.name in (
 70     "bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish"
 71   )
 72  ] by process.entity_id
 73  [process where host.os.type == "linux" and event.type == "start" and event.action in ("exec", "start") and process.name : (
 74     "bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish", "python*", "php*",
 75     "perl", "ruby", "lua*", "openssl", "nc", "netcat", "ncat", "telnet", "awk"
 76   )
 77  ] by process.parent.entity_id
 78'''
 79note = """## Triage and analysis
 80
 81> **Disclaimer**:
 82> 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.
 83
 84### Investigating Suspicious APT Package Manager Execution
 85
 86The APT package manager is a vital tool for managing software on Debian-based Linux systems, handling tasks like installation and updates. Adversaries may exploit APT by embedding malicious scripts to maintain persistence and control. The detection rule identifies unusual shell or script executions initiated by APT, signaling potential backdoor activities, thus aiding in early threat detection and response.
 87
 88### Possible investigation steps
 89
 90- Review the process execution details to identify the specific shell or script that was executed with APT as the parent process. Pay attention to the process names and arguments, such as "bash", "dash", "sh", etc., and the presence of the "-c" argument.
 91- Examine the command-line arguments and scripts executed by the suspicious process to determine if they contain any malicious or unexpected commands.
 92- Check the parent process details, specifically the APT process, to understand the context in which the shell or script was executed. This includes reviewing any recent package installations or updates that might have triggered the execution.
 93- Investigate the user account under which the suspicious process was executed to assess if it has been compromised or if it has elevated privileges that could be exploited.
 94- Correlate the event with other security logs or alerts from the same host to identify any additional indicators of compromise or related suspicious activities.
 95- Review the system's package management logs to identify any recent changes or anomalies in package installations or updates that could be linked to the suspicious execution.
 96
 97### False positive analysis
 98
 99- Legitimate administrative scripts executed by system administrators using APT may trigger the rule. To handle this, identify and document routine administrative tasks and create exceptions for these specific scripts or commands.
100- Automated system maintenance scripts that use APT for updates or installations can be mistaken for suspicious activity. Review and whitelist these scripts by their specific command patterns or script names.
101- Custom software deployment processes that involve APT and shell scripts might be flagged. Analyze these processes and exclude them by defining clear criteria for legitimate deployment activities.
102- Security tools or monitoring solutions that interact with APT for scanning or auditing purposes may cause false positives. Verify these tools' operations and exclude their known benign processes from triggering the rule.
103- Development environments where developers frequently use APT and shell scripts for testing and building software can lead to alerts. Establish a baseline of normal development activities and exclude these from the detection rule.
104
105### Response and remediation
106
107- Isolate the affected host immediately to prevent further unauthorized access or lateral movement within the network.
108- Terminate any suspicious processes identified in the alert, particularly those initiated by the APT package manager that match the query criteria.
109- Conduct a thorough review of the APT configuration files and scripts to identify and remove any injected malicious code or unauthorized modifications.
110- Restore the affected system from a known good backup if malicious modifications are extensive or if the integrity of the system cannot be assured.
111- Update all system packages and apply security patches to mitigate vulnerabilities that may have been exploited by the adversary.
112- Monitor the affected host and network for any signs of re-infection or further suspicious activity, focusing on the execution of shell scripts and unauthorized network connections.
113- Escalate the incident to the security operations team for further investigation and to determine if additional systems have been compromised."""
114
115
116[[rule.threat]]
117framework = "MITRE ATT&CK"
118[[rule.threat.technique]]
119id = "T1543"
120name = "Create or Modify System Process"
121reference = "https://attack.mitre.org/techniques/T1543/"
122
123[[rule.threat.technique]]
124id = "T1546"
125name = "Event Triggered Execution"
126reference = "https://attack.mitre.org/techniques/T1546/"
127[[rule.threat.technique.subtechnique]]
128id = "T1546.016"
129name = "Installer Packages"
130reference = "https://attack.mitre.org/techniques/T1546/016/"
131
132
133[[rule.threat.technique]]
134id = "T1574"
135name = "Hijack Execution Flow"
136reference = "https://attack.mitre.org/techniques/T1574/"
137
138
139[rule.threat.tactic]
140id = "TA0003"
141name = "Persistence"
142reference = "https://attack.mitre.org/tactics/TA0003/"
143[[rule.threat]]
144framework = "MITRE ATT&CK"
145[[rule.threat.technique]]
146id = "T1059"
147name = "Command and Scripting Interpreter"
148reference = "https://attack.mitre.org/techniques/T1059/"
149[[rule.threat.technique.subtechnique]]
150id = "T1059.004"
151name = "Unix Shell"
152reference = "https://attack.mitre.org/techniques/T1059/004/"
153
154
155
156[rule.threat.tactic]
157id = "TA0002"
158name = "Execution"
159reference = "https://attack.mitre.org/tactics/TA0002/"
160[[rule.threat]]
161framework = "MITRE ATT&CK"
162
163[rule.threat.tactic]
164id = "TA0005"
165name = "Defense Evasion"
166reference = "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 Execution

The APT package manager is a vital tool for managing software on Debian-based Linux systems, handling tasks like installation and updates. Adversaries may exploit APT by embedding malicious scripts to maintain persistence and control. The detection rule identifies unusual shell or script executions initiated by APT, signaling potential backdoor activities, thus aiding in early threat detection and response.

Possible investigation steps

  • Review the process execution details to identify the specific shell or script that was executed with APT as the parent process. Pay attention to the process names and arguments, such as "bash", "dash", "sh", etc., and the presence of the "-c" argument.
  • Examine the command-line arguments and scripts executed by the suspicious process to determine if they contain any malicious or unexpected commands.
  • Check the parent process details, specifically the APT process, to understand the context in which the shell or script was executed. This includes reviewing any recent package installations or updates that might have triggered the execution.
  • Investigate the user account under which the suspicious process was executed to assess if it has been compromised or if it has elevated privileges that could be exploited.
  • Correlate the event with other security logs or alerts from the same host to identify any additional indicators of compromise or related suspicious activities.
  • Review the system's package management logs to identify any recent changes or anomalies in package installations or updates that could be linked to the suspicious execution.

False positive analysis

  • Legitimate administrative scripts executed by system administrators using APT may trigger the rule. To handle this, identify and document routine administrative tasks and create exceptions for these specific scripts or commands.
  • Automated system maintenance scripts that use APT for updates or installations can be mistaken for suspicious activity. Review and whitelist these scripts by their specific command patterns or script names.
  • Custom software deployment processes that involve APT and shell scripts might be flagged. Analyze these processes and exclude them by defining clear criteria for legitimate deployment activities.
  • Security tools or monitoring solutions that interact with APT for scanning or auditing purposes may cause false positives. Verify these tools' operations and exclude their known benign processes from triggering the rule.
  • Development environments where developers frequently use APT and shell scripts for testing and building software can lead to alerts. Establish a baseline of normal development activities and exclude these from the detection rule.

Response and remediation

  • Isolate the affected host immediately to prevent further unauthorized access or lateral movement within the network.
  • Terminate any suspicious processes identified in the alert, particularly those initiated by the APT package manager that match the query criteria.
  • Conduct a thorough review of the APT configuration files and scripts to identify and remove any injected malicious code or unauthorized modifications.
  • Restore the affected system from a known good backup if malicious modifications are extensive or if the integrity of the system cannot be assured.
  • Update all system packages and apply security patches to mitigate vulnerabilities that may have been exploited by the adversary.
  • Monitor the affected host and network for any signs of re-infection or further suspicious activity, focusing on the execution of shell scripts and unauthorized network connections.
  • Escalate the incident to the security operations team for further investigation and to determine if additional systems have been compromised.

References

Related rules

to-top