Potential Reverse Shell via Java
This detection rule identifies the execution of a Linux shell process from a Java JAR application post an incoming network connection. This behavior may indicate reverse shell activity via a Java application.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/07/04"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2025/12/19"
6
7[rule]
8author = ["Elastic"]
9description = """
10This detection rule identifies the execution of a Linux shell process from a Java JAR application post an incoming
11network connection. This behavior may indicate reverse shell activity via a Java application.
12"""
13from = "now-9m"
14index = ["logs-endpoint.events.network*", "logs-endpoint.events.process*"]
15language = "eql"
16license = "Elastic License v2"
17name = "Potential Reverse Shell via Java"
18note = """## Triage and analysis
19
20> **Disclaimer**:
21> 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.
22
23### Investigating Potential Reverse Shell via Java
24
25Java applications, often run on Linux systems, can be exploited by adversaries to establish reverse shells, allowing remote control over a compromised system. Attackers may execute shell commands via Java processes post-network connection. The detection rule identifies suspicious Java activity by monitoring for shell executions following network connections, excluding benign processes, to flag potential reverse shell attempts.
26
27### Possible investigation steps
28
29- Review the network connection details, focusing on the destination IP address to determine if it is external or potentially malicious, as the rule excludes common internal and reserved IP ranges.
30- Examine the Java process that initiated the network connection, including its executable path and arguments, to identify any unusual or unauthorized JAR files being executed.
31- Investigate the child shell process spawned by the Java application, checking its command-line arguments and execution context to assess if it aligns with known reverse shell patterns.
32- Cross-reference the parent Java process and the child shell process with known benign applications or services, such as Jenkins or NetExtender, to rule out false positives.
33- Analyze historical data for the host to identify any previous similar activities or patterns that might indicate a persistent threat or repeated exploitation attempts.
34
35### False positive analysis
36
37- Java-based administrative tools like Jenkins may trigger false positives when executing shell commands. Exclude known benign Java applications such as Jenkins by adding their specific JAR paths to the exception list.
38- Automated scripts or maintenance tasks that use Java to execute shell commands can be mistaken for reverse shell activity. Identify and exclude these scripts by specifying their unique process arguments or executable paths.
39- Development environments where Java applications frequently execute shell commands for testing purposes can generate false alerts. Consider excluding these environments by filtering based on specific host identifiers or network segments.
40- Security tools that utilize Java for network operations and shell executions might be flagged. Verify and exclude these tools by adding their process names or executable paths to the exception list.
41
42### Response and remediation
43
44- Immediately isolate the affected host from the network to prevent further unauthorized access or data exfiltration.
45- Terminate any suspicious Java processes identified in the alert to stop potential reverse shell activity.
46- Conduct a thorough review of the affected system's logs to identify any additional indicators of compromise or lateral movement attempts.
47- Remove any unauthorized or malicious Java JAR files and associated scripts from the system.
48- Apply security patches and updates to the Java environment and any other vulnerable software on the affected host.
49- Restore the system from a known good backup if any unauthorized changes or persistent threats are detected.
50- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to assess the potential impact on other systems within the network."""
51references = [
52 "https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md",
53]
54risk_score = 47
55rule_id = "5a3d5447-31c9-409a-aed1-72f9921594fd"
56setup = """## Setup
57
58This rule requires data coming in from Elastic Defend.
59
60### Elastic Defend Integration Setup
61Elastic 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.
62
63#### Prerequisite Requirements:
64- Fleet is required for Elastic Defend.
65- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
66
67#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
68- Go to the Kibana home page and click "Add integrations".
69- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
70- Click "Add Elastic Defend".
71- Configure the integration name and optionally add a description.
72- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
73- 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).
74- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
75- 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.
76For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
77- Click "Save and Continue".
78- 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.
79For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
80"""
81severity = "medium"
82tags = [
83 "Domain: Endpoint",
84 "OS: Linux",
85 "Use Case: Threat Detection",
86 "Tactic: Execution",
87 "Data Source: Elastic Defend",
88 "Resources: Investigation Guide",
89]
90type = "eql"
91query = '''
92sequence by host.id with maxspan=5s
93 [network where host.os.type == "linux" and event.action in ("connection_accepted", "connection_attempted") and
94 process.executable : ("/usr/bin/java", "/bin/java", "/usr/lib/jvm/*", "/usr/java/*") and
95 not (destination.ip == null or destination.ip == "0.0.0.0" or cidrmatch(
96 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",
97 "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",
98 "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",
99 "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",
100 "FF00::/8"
101 )
102 )] by process.entity_id
103 [process where host.os.type == "linux" and event.action == "exec" and
104 process.parent.executable : ("/usr/bin/java", "/bin/java", "/usr/lib/jvm/*", "/usr/java/*") and
105 process.parent.args : "-jar" and process.name in ("bash", "dash", "ash", "sh", "tcsh", "csh", "zsh", "ksh", "fish")
106 and not (
107 process.parent.args in (
108 "/usr/lib/jenkins/jenkins.war", "/etc/remote-iot/services/remoteiot.jar", "/opt/pentaho/data-integration/launcher/launcher.jar",
109 "/usr/share/java/jenkins.war", "/opt//tomcat/statistics/statistics.jar", "/usr/lib64/NetExtender.jar",
110 "/var/lib/jenkins/workspace/MP-QA/tc_certified_copy*/tc_certified_copy_web_ui_test/target/surefire/surefirebooter*.jar",
111 "-javaagent:/opt/opentelemetry/opentelemetry-javaagent-all.jar", "./lib/pipeline-job-executor*SNAPSHOT.jar",
112 "./lib/worker-launcher-agent*SNAPSHOT.jar", "/opt/Seqrite_EndPoint_Security/wildfly/jboss-modules.jar",
113 "/home/data/jenkins.war", "/pro/service-modules/deployment.jar", "/application/HES/READER/*.jar", "*-SNAPSHOT.jar",
114 "READER/G1A/READER_G1A.jar", "READER_G1.jar"
115 ) or
116 process.command_line like~ (
117 "bash -c ps -eo pid,lstart,comm*",
118 "bash -c df -i /application | tail -n 1",
119 "/bin/sh -xe /tmp/hudson*.sh",
120 "bash -c cat /application/HES/*"
121 )
122 )] by process.parent.entity_id
123'''
124
125[[rule.threat]]
126framework = "MITRE ATT&CK"
127
128[[rule.threat.technique]]
129id = "T1059"
130name = "Command and Scripting Interpreter"
131reference = "https://attack.mitre.org/techniques/T1059/"
132
133[[rule.threat.technique.subtechnique]]
134id = "T1059.004"
135name = "Unix Shell"
136reference = "https://attack.mitre.org/techniques/T1059/004/"
137
138[rule.threat.tactic]
139id = "TA0002"
140name = "Execution"
141reference = "https://attack.mitre.org/tactics/TA0002/"
142
143[[rule.threat]]
144framework = "MITRE ATT&CK"
145
146[[rule.threat.technique]]
147id = "T1071"
148name = "Application Layer Protocol"
149reference = "https://attack.mitre.org/techniques/T1071/"
150
151[rule.threat.tactic]
152id = "TA0011"
153name = "Command and Control"
154reference = "https://attack.mitre.org/tactics/TA0011/"
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 Potential Reverse Shell via Java
Java applications, often run on Linux systems, can be exploited by adversaries to establish reverse shells, allowing remote control over a compromised system. Attackers may execute shell commands via Java processes post-network connection. The detection rule identifies suspicious Java activity by monitoring for shell executions following network connections, excluding benign processes, to flag potential reverse shell attempts.
Possible investigation steps
- Review the network connection details, focusing on the destination IP address to determine if it is external or potentially malicious, as the rule excludes common internal and reserved IP ranges.
- Examine the Java process that initiated the network connection, including its executable path and arguments, to identify any unusual or unauthorized JAR files being executed.
- Investigate the child shell process spawned by the Java application, checking its command-line arguments and execution context to assess if it aligns with known reverse shell patterns.
- Cross-reference the parent Java process and the child shell process with known benign applications or services, such as Jenkins or NetExtender, to rule out false positives.
- Analyze historical data for the host to identify any previous similar activities or patterns that might indicate a persistent threat or repeated exploitation attempts.
False positive analysis
- Java-based administrative tools like Jenkins may trigger false positives when executing shell commands. Exclude known benign Java applications such as Jenkins by adding their specific JAR paths to the exception list.
- Automated scripts or maintenance tasks that use Java to execute shell commands can be mistaken for reverse shell activity. Identify and exclude these scripts by specifying their unique process arguments or executable paths.
- Development environments where Java applications frequently execute shell commands for testing purposes can generate false alerts. Consider excluding these environments by filtering based on specific host identifiers or network segments.
- Security tools that utilize Java for network operations and shell executions might be flagged. Verify and exclude these tools by adding their process names or executable paths to the exception list.
Response and remediation
- Immediately isolate the affected host from the network to prevent further unauthorized access or data exfiltration.
- Terminate any suspicious Java processes identified in the alert to stop potential reverse shell activity.
- Conduct a thorough review of the affected system's logs to identify any additional indicators of compromise or lateral movement attempts.
- Remove any unauthorized or malicious Java JAR files and associated scripts from the system.
- Apply security patches and updates to the Java environment and any other vulnerable software on the affected host.
- Restore the system from a known good backup if any unauthorized changes or persistent threats are detected.
- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to assess the potential impact on other systems within the network.
References
Related rules
- Abnormal Process ID or Lock File Created
- BPF filter applied using TC
- Binary Executed from Shared Memory Directory
- Deprecated - Potential curl CVE-2023-38545 Exploitation
- Egress Connection from Entrypoint in Container