Interactive Terminal Spawned via Perl
Identifies when a terminal (tty) is spawned via Perl. Attackers may upgrade a simple reverse shell to a fully interactive tty after obtaining initial access to a host.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2020/04/16"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2025/01/15"
6
7[rule]
8author = ["Elastic"]
9description = """
10Identifies when a terminal (tty) is spawned via Perl. Attackers may upgrade a simple reverse shell to a fully
11interactive tty after obtaining initial access to a host.
12"""
13from = "now-9m"
14index = ["auditbeat-*", "logs-endpoint.events.*", "endgame-*"]
15language = "kuery"
16license = "Elastic License v2"
17name = "Interactive Terminal Spawned via Perl"
18risk_score = 73
19rule_id = "05e5a668-7b51-4a67-93ab-e9af405c9ef3"
20setup = """## Setup
21
22This rule requires data coming in from one of the following integrations:
23- Elastic Defend
24- Auditbeat
25
26### Elastic Defend Integration Setup
27Elastic 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.
28
29#### Prerequisite Requirements:
30- Fleet is required for Elastic Defend.
31- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
32
33#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
34- Go to the Kibana home page and click "Add integrations".
35- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
36- Click "Add Elastic Defend".
37- Configure the integration name and optionally add a description.
38- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
39- 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).
40- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
41- 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.
42For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
43- Click "Save and Continue".
44- 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.
45For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
46
47### Auditbeat Setup
48Auditbeat is a lightweight shipper that you can install on your servers to audit the activities of users and processes on your systems. For example, you can use Auditbeat to collect and centralize audit events from the Linux Audit Framework. You can also use Auditbeat to detect changes to critical files, like binaries and configuration files, and identify potential security policy violations.
49
50#### The following steps should be executed in order to add the Auditbeat on a Linux System:
51- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
52- To install the APT and YUM repositories follow the setup instructions in this [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setup-repositories.html).
53- To run Auditbeat on Docker follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-docker.html).
54- To run Auditbeat on Kubernetes follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-kubernetes.html).
55- For complete “Setup and Run Auditbeat” information refer to the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setting-up-and-running.html).
56"""
57severity = "high"
58tags = [
59 "Domain: Endpoint",
60 "OS: Linux",
61 "Use Case: Threat Detection",
62 "Tactic: Execution",
63 "Data Source: Elastic Endgame",
64 "Data Source: Elastic Defend",
65 "Resources: Investigation Guide",
66]
67timestamp_override = "event.ingested"
68type = "query"
69
70query = '''
71event.category:process and host.os.type:linux and event.type:(start or process_started) and process.name:perl and
72 process.args:("exec \"/bin/sh\";" or "exec \"/bin/dash\";" or "exec \"/bin/bash\";")
73'''
74note = """## Triage and analysis
75
76> **Disclaimer**:
77> 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.
78
79### Investigating Interactive Terminal Spawned via Perl
80
81Perl, a versatile scripting language, can execute system commands, making it a target for adversaries seeking to escalate privileges or maintain persistence. Attackers may exploit Perl to spawn interactive terminals, transforming basic shells into robust command interfaces. The detection rule identifies such activity by monitoring process events on Linux systems, specifically when Perl executes shell commands, signaling potential misuse.
82
83### Possible investigation steps
84
85- Review the process event logs to confirm the presence of a Perl process with arguments indicating the execution of a shell, such as "exec \\"/bin/sh\\";", "exec \\"/bin/dash\\";", or "exec \\"/bin/bash\\";".
86- Identify the user account associated with the Perl process to determine if it aligns with expected activity or if it suggests unauthorized access.
87- Examine the parent process of the Perl execution to understand how the Perl script was initiated and assess if it correlates with legitimate user activity or a potential compromise.
88- Check for any network connections or data transfers initiated by the Perl process to identify possible exfiltration or communication with external command and control servers.
89- Investigate any recent changes to user accounts, permissions, or scheduled tasks that might indicate privilege escalation or persistence mechanisms associated with the Perl activity.
90- Correlate the event with other security alerts or logs from the same host to identify patterns or additional indicators of compromise that could suggest a broader attack campaign.
91
92### False positive analysis
93
94- System maintenance scripts that use Perl to execute shell commands may trigger this rule. Review and whitelist known maintenance scripts by adding exceptions for specific script paths or process arguments.
95- Automated deployment tools that utilize Perl for executing shell commands can cause false positives. Identify these tools and exclude their specific process arguments or execution paths from the detection rule.
96- Development environments where Perl is used for testing or debugging purposes might inadvertently spawn interactive terminals. Consider excluding processes initiated by known development user accounts or within specific development directories.
97- Backup or monitoring scripts that rely on Perl to perform system checks or data collection could be flagged. Analyze these scripts and create exceptions based on their unique process arguments or execution context.
98
99### Response and remediation
100
101- Immediately isolate the affected host from the network to prevent further unauthorized access or lateral movement.
102- Terminate any suspicious Perl processes identified by the detection rule to halt any ongoing malicious activity.
103- Conduct a thorough review of the affected system's logs and process history to identify any additional indicators of compromise or related malicious activity.
104- Reset credentials and review access permissions for any accounts that may have been compromised or used in the attack.
105- Restore the affected system from a known good backup to ensure any malicious changes are removed.
106- Implement additional monitoring on the affected host and network to detect any further attempts to exploit Perl for spawning interactive terminals.
107- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if broader organizational impacts exist."""
108
109
110[[rule.threat]]
111framework = "MITRE ATT&CK"
112[[rule.threat.technique]]
113id = "T1059"
114name = "Command and Scripting Interpreter"
115reference = "https://attack.mitre.org/techniques/T1059/"
116
117
118[rule.threat.tactic]
119id = "TA0002"
120name = "Execution"
121reference = "https://attack.mitre.org/tactics/TA0002/"
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 Interactive Terminal Spawned via Perl
Perl, a versatile scripting language, can execute system commands, making it a target for adversaries seeking to escalate privileges or maintain persistence. Attackers may exploit Perl to spawn interactive terminals, transforming basic shells into robust command interfaces. The detection rule identifies such activity by monitoring process events on Linux systems, specifically when Perl executes shell commands, signaling potential misuse.
Possible investigation steps
- Review the process event logs to confirm the presence of a Perl process with arguments indicating the execution of a shell, such as "exec "/bin/sh";", "exec "/bin/dash";", or "exec "/bin/bash";".
- Identify the user account associated with the Perl process to determine if it aligns with expected activity or if it suggests unauthorized access.
- Examine the parent process of the Perl execution to understand how the Perl script was initiated and assess if it correlates with legitimate user activity or a potential compromise.
- Check for any network connections or data transfers initiated by the Perl process to identify possible exfiltration or communication with external command and control servers.
- Investigate any recent changes to user accounts, permissions, or scheduled tasks that might indicate privilege escalation or persistence mechanisms associated with the Perl activity.
- Correlate the event with other security alerts or logs from the same host to identify patterns or additional indicators of compromise that could suggest a broader attack campaign.
False positive analysis
- System maintenance scripts that use Perl to execute shell commands may trigger this rule. Review and whitelist known maintenance scripts by adding exceptions for specific script paths or process arguments.
- Automated deployment tools that utilize Perl for executing shell commands can cause false positives. Identify these tools and exclude their specific process arguments or execution paths from the detection rule.
- Development environments where Perl is used for testing or debugging purposes might inadvertently spawn interactive terminals. Consider excluding processes initiated by known development user accounts or within specific development directories.
- Backup or monitoring scripts that rely on Perl to perform system checks or data collection could be flagged. Analyze these scripts and create exceptions based on their unique process arguments or execution context.
Response and remediation
- Immediately isolate the affected host from the network to prevent further unauthorized access or lateral movement.
- Terminate any suspicious Perl processes identified by the detection rule to halt any ongoing malicious activity.
- Conduct a thorough review of the affected system's logs and process history to identify any additional indicators of compromise or related malicious activity.
- Reset credentials and review access permissions for any accounts that may have been compromised or used in the attack.
- Restore the affected system from a known good backup to ensure any malicious changes are removed.
- Implement additional monitoring on the affected host and network to detect any further attempts to exploit Perl for spawning interactive terminals.
- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if broader organizational impacts exist.
Related rules
- AWS SSM `SendCommand` with Run Shell Command Parameters
- BPF filter applied using TC
- Binary Executed from Shared Memory Directory
- Cupsd or Foomatic-rip Shell Execution
- Dynamic Linker (ld.so) Creation