From 05ae288e8b806e9ffeafcf210cfbaf26cfd224fa Mon Sep 17 00:00:00 2001 From: Michael Haag <5632822+MHaggis@users.noreply.github.com> Date: Tue, 29 Aug 2023 08:20:41 -0600 Subject: [PATCH 1/4] Juniper JunOS Remote Code Execution --- .gitignore | 1 + ...emote_code_execution_exploit_detection.yml | 65 +++++++++++++++++++ .../juniper_junos_remote_code_execution.yml | 28 ++++++++ 3 files changed, 94 insertions(+) create mode 100644 detections/web/juniper_networks_remote_code_execution_exploit_detection.yml create mode 100644 stories/juniper_junos_remote_code_execution.yml diff --git a/.gitignore b/.gitignore index 8a3262dc05..af77c8950d 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,4 @@ bin/docker_detection_tester/test_results/ lookups/APP_ENRICHMENT_CACHE.db.db lookups/CVE_CACHE.db.db lookups/REFERENCE_CACHE.db.db +*.code-workspace diff --git a/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml b/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml new file mode 100644 index 0000000000..a993735052 --- /dev/null +++ b/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml @@ -0,0 +1,65 @@ +name: Juniper Networks Remote Code Execution Exploit Detection +id: 6cc4cc3d-b10a-4fac-be1e-55d384fc690e +version: 1 +date: '2023-08-29' +author: Michael Haag, Splunk +status: production +type: TTP +data_source: [] +description: The following analytic detects the exploitation of a remote code execution vulnerability in Juniper Networks devices. The vulnerability involves multiple steps, including uploading a malicious PHP file and an INI file to the target server, and then executing the PHP code by manipulating the PHP configuration via the uploaded INI file. The analytic specifically looks for requests to /webauth_operation.php?PHPRC=*, which are used to upload the files and execute the code, respectively. This behavior is worth identifying for a SOC because it indicates that an attacker is attempting to exploit the vulnerability to gain unauthorized access to the device and execute arbitrary code. If a true positive is found, it suggests that an attacker has successfully exploited the vulnerability and may have gained control over the device, leading to data theft, network compromise, or other damaging outcomes. Upon triage, review the request parameters and the response to determine if the exploitation was successful. Capture and inspect any relevant network traffic and server logs to identify the attack source. This approach helps analysts detect potential threats earlier and mitigate the risks. +search: '| tstats count min(_time) as firstTime max(_time) + as lastTime from datamodel=Web where Web.url IN ("/webauth_operation.php?PHPRC=*") Web.status=200 + by Web.http_user_agent, Web.status Web.http_method, Web.url, Web.url_length, Web.src, Web.dest, sourcetype + | `drop_dm_object_name("Web")` + | `security_content_ctime(firstTime)` + | `security_content_ctime(lastTime)` | `juniper_networks_remote_code_execution_exploit_detection_filter`' +how_to_implement: To implement this search, ensure that the Web data model is populated. The search is activated when the Web data model is accelerated. Network products, such as Suricata or Palo Alto, need to be mapped to the Web data model. Adjust the mapping as necessary to suit your specific products. +known_false_positives: Be aware of potential false positives - legitimate uses of the /webauth_operation.php endpoint may cause benign activities to be flagged.The URL in the analytic is specific to a successful attempt to exploit the vulnerability. Review contents of the HTTP body to determine if the request is malicious. If the request is benign, add the URL to the whitelist or continue to monitor. +references: +- https://supportportal.juniper.net/s/article/2023-08-Out-of-Cycle-Security-Bulletin-Junos-OS-SRX-Series-and-EX-Series-Multiple-vulnerabilities-in-J-Web-can-be-combined-to-allow-a-preAuth-Remote-Code-Execution?language=en_US +- https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2023/CVE-2023-36844.yaml +- https://thehackernews.com/2023/08/new-juniper-junos-os-flaws-expose.html +- https://github.com/watchtowrlabs/juniper-rce_cve-2023-36844 +- https://labs.watchtowr.com/cve-2023-36844-and-friends-rce-in-juniper-firewalls/ +tags: + analytic_story: + - Juniper JunOS Remote Code Execution + asset_type: Web server + atomic_guid: [] + confidence: 80 + impact: 90 + message: 'This analytic has identified a potential exploitation of a remote code execution vulnerability in Juniper Networks devices on $dest$ on the URL $url$ used for the exploit.' + observable: + - name: dest + type: Hostname + role: + - Victim + - name: url + type: URL String + role: + - Attacker + mitre_attack_id: + - T1190 + - T1105 + - T1059 + product: + - Splunk Enterprise + - Splunk Enterprise Security + - Splunk Cloud + risk_score: 72 + required_fields: + - Web.http_user_agent + - Web.status + - Web.http_method + - Web.url + - Web.url_length + - Web.src + - Web.dest + - sourcetype + security_domain: network +tests: +- name: True Positive Test + attack_data: + - data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/attack_techniques/T1190/juniper/suricata_junos_cvemegazord.log + source: suricata + sourcetype: suricata diff --git a/stories/juniper_junos_remote_code_execution.yml b/stories/juniper_junos_remote_code_execution.yml new file mode 100644 index 0000000000..52cf7b16db --- /dev/null +++ b/stories/juniper_junos_remote_code_execution.yml @@ -0,0 +1,28 @@ +name: Juniper JunOS Remote Code Execution +id: 3fcef843-c97e-4cf3-a72f-749be480cee3 +version: 1 +date: '2023-08-29' +author: Michael Haag, Splunk +description: uniper Networks has resolved multiple critical vulnerabilities in the J-Web component of Junos OS on SRX and EX Series devices. These vulnerabilities, when chained together, could allow an unauthenticated, network-based attacker to remotely execute code on the devices. The vulnerabilities affect all versions of Junos OS on SRX and EX Series, but specific fixes have been released to address each vulnerability. Juniper Networks recommends applying the necessary fixes to mitigate potential remote code execution threats. As a workaround, users can disable J-Web or limit access to only trusted hosts. Proof-of-concept (PoC) exploit code has been released, demonstrating the severity of these flaws and the urgency to apply the fixes. +narrative: Juniper Networks, a networking hardware company, has released an "out-of-cycle" security update to address multiple flaws in the J-Web component of Junos OS that could be combined to achieve remote code execution on susceptible installations. The flaws have a cumulative CVSS rating of 9.8, making them critical in severity. They affect all versions of Junos OS on SRX and EX Series. The J-Web interface allows users to configure, manage, and monitor Junos OS devices. The vulnerabilities include two PHP external variable modification vulnerabilities (CVE-2023-36844 and CVE-2023-36845) and two missing authentications for critical function vulnerabilities (CVE-2023-36846 and CVE-2023-36847). These vulnerabilities could allow an unauthenticated, network-based attacker to control certain important environment variables, cause limited impact to the file system integrity, or upload arbitrary files via J-Web without any authentication. \ + + The vulnerabilities have been addressed in specific Junos OS versions for EX Series and SRX Series devices. Users are recommended to apply the necessary fixes to mitigate potential remote code execution threats. As a workaround, Juniper Networks suggests disabling J-Web or limiting access to only trusted hosts. \ + + Additionally, a PoC exploit has been released by watchTowr, combining CVE-2023-36846 and CVE-2023-36845 to upload a PHP file containing malicious shellcode and achieve code execution by injecting the PHPRC environment variable to point to a configuration file to load the booby-trapped PHP script. WatchTowr noted that this is an interesting bug chain, utilizing two bugs that would be near-useless in isolation and combining them for a "world-ending" unauthenticated remote code execution. \ + + In conclusion, these vulnerabilities pose a significant threat to Juniper SRX and EX Series devices, and it is imperative for users to apply the necessary fixes or implement the recommended workaround to mitigate the potential impact. +references: +- https://supportportal.juniper.net/s/article/2023-08-Out-of-Cycle-Security-Bulletin-Junos-OS-SRX-Series-and-EX-Series-Multiple-vulnerabilities-in-J-Web-can-be-combined-to-allow-a-preAuth-Remote-Code-Execution?language=en_US +- https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2023/CVE-2023-36844.yaml +- https://thehackernews.com/2023/08/new-juniper-junos-os-flaws-expose.html +- https://github.com/watchtowrlabs/juniper-rce_cve-2023-36844 +- https://labs.watchtowr.com/cve-2023-36844-and-friends-rce-in-juniper-firewalls/ +tags: + analytic_story: Juniper JunOS Remote Code Execution + category: + - Adversary Tactics + product: + - Splunk Enterprise + - Splunk Enterprise Security + - Splunk Cloud + usecase: Advanced Threat Detection From db5982f33d626c8ba192b9a267631029946dc113 Mon Sep 17 00:00:00 2001 From: Michael Haag <5632822+MHaggis@users.noreply.github.com> Date: Tue, 29 Aug 2023 08:25:58 -0600 Subject: [PATCH 2/4] typo --- stories/juniper_junos_remote_code_execution.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stories/juniper_junos_remote_code_execution.yml b/stories/juniper_junos_remote_code_execution.yml index 52cf7b16db..7e5c217358 100644 --- a/stories/juniper_junos_remote_code_execution.yml +++ b/stories/juniper_junos_remote_code_execution.yml @@ -3,7 +3,7 @@ id: 3fcef843-c97e-4cf3-a72f-749be480cee3 version: 1 date: '2023-08-29' author: Michael Haag, Splunk -description: uniper Networks has resolved multiple critical vulnerabilities in the J-Web component of Junos OS on SRX and EX Series devices. These vulnerabilities, when chained together, could allow an unauthenticated, network-based attacker to remotely execute code on the devices. The vulnerabilities affect all versions of Junos OS on SRX and EX Series, but specific fixes have been released to address each vulnerability. Juniper Networks recommends applying the necessary fixes to mitigate potential remote code execution threats. As a workaround, users can disable J-Web or limit access to only trusted hosts. Proof-of-concept (PoC) exploit code has been released, demonstrating the severity of these flaws and the urgency to apply the fixes. +description: Juniper Networks has resolved multiple critical vulnerabilities in the J-Web component of Junos OS on SRX and EX Series devices. These vulnerabilities, when chained together, could allow an unauthenticated, network-based attacker to remotely execute code on the devices. The vulnerabilities affect all versions of Junos OS on SRX and EX Series, but specific fixes have been released to address each vulnerability. Juniper Networks recommends applying the necessary fixes to mitigate potential remote code execution threats. As a workaround, users can disable J-Web or limit access to only trusted hosts. Proof-of-concept (PoC) exploit code has been released, demonstrating the severity of these flaws and the urgency to apply the fixes. narrative: Juniper Networks, a networking hardware company, has released an "out-of-cycle" security update to address multiple flaws in the J-Web component of Junos OS that could be combined to achieve remote code execution on susceptible installations. The flaws have a cumulative CVSS rating of 9.8, making them critical in severity. They affect all versions of Junos OS on SRX and EX Series. The J-Web interface allows users to configure, manage, and monitor Junos OS devices. The vulnerabilities include two PHP external variable modification vulnerabilities (CVE-2023-36844 and CVE-2023-36845) and two missing authentications for critical function vulnerabilities (CVE-2023-36846 and CVE-2023-36847). These vulnerabilities could allow an unauthenticated, network-based attacker to control certain important environment variables, cause limited impact to the file system integrity, or upload arbitrary files via J-Web without any authentication. \ The vulnerabilities have been addressed in specific Junos OS versions for EX Series and SRX Series devices. Users are recommended to apply the necessary fixes to mitigate potential remote code execution threats. As a workaround, Juniper Networks suggests disabling J-Web or limiting access to only trusted hosts. \ From 172c316a3449ec48e1fac399b4eb89ce92d08e21 Mon Sep 17 00:00:00 2001 From: Michael Haag <5632822+MHaggis@users.noreply.github.com> Date: Tue, 29 Aug 2023 10:00:52 -0600 Subject: [PATCH 3/4] cve tag --- ...iper_networks_remote_code_execution_exploit_detection.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml b/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml index a993735052..0e5cc2eeca 100644 --- a/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml +++ b/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml @@ -24,6 +24,11 @@ references: tags: analytic_story: - Juniper JunOS Remote Code Execution + cve: + - CVE-2023-36844 + - CVE-2023-36845 + - CVE-2023-36846 + - CVE-2023-36847 asset_type: Web server atomic_guid: [] confidence: 80 From 8a853086c055e232cacde348276fdc4b401bb613 Mon Sep 17 00:00:00 2001 From: Bhavin Patel Date: Tue, 29 Aug 2023 12:37:07 -0700 Subject: [PATCH 4/4] Update juniper_networks_remote_code_execution_exploit_detection.yml --- ...juniper_networks_remote_code_execution_exploit_detection.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml b/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml index 0e5cc2eeca..36fded196d 100644 --- a/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml +++ b/detections/web/juniper_networks_remote_code_execution_exploit_detection.yml @@ -8,7 +8,7 @@ type: TTP data_source: [] description: The following analytic detects the exploitation of a remote code execution vulnerability in Juniper Networks devices. The vulnerability involves multiple steps, including uploading a malicious PHP file and an INI file to the target server, and then executing the PHP code by manipulating the PHP configuration via the uploaded INI file. The analytic specifically looks for requests to /webauth_operation.php?PHPRC=*, which are used to upload the files and execute the code, respectively. This behavior is worth identifying for a SOC because it indicates that an attacker is attempting to exploit the vulnerability to gain unauthorized access to the device and execute arbitrary code. If a true positive is found, it suggests that an attacker has successfully exploited the vulnerability and may have gained control over the device, leading to data theft, network compromise, or other damaging outcomes. Upon triage, review the request parameters and the response to determine if the exploitation was successful. Capture and inspect any relevant network traffic and server logs to identify the attack source. This approach helps analysts detect potential threats earlier and mitigate the risks. search: '| tstats count min(_time) as firstTime max(_time) - as lastTime from datamodel=Web where Web.url IN ("/webauth_operation.php?PHPRC=*") Web.status=200 + as lastTime from datamodel=Web where Web.url IN ("*/webauth_operation.php?PHPRC=*") Web.status=200 by Web.http_user_agent, Web.status Web.http_method, Web.url, Web.url_length, Web.src, Web.dest, sourcetype | `drop_dm_object_name("Web")` | `security_content_ctime(firstTime)`