module

Junos OS PHPRC Environment Variable Manipulation RCE

Disclosed
2023-08-17
Created
2023-09-29

Description

This module exploits a PHP environment variable manipulation vulnerability affecting Juniper SRX firewalls
and EX switches. The affected Juniper devices run FreeBSD and every FreeBSD process can access their stdin
by opening /dev/fd/0. The exploit also makes use of two useful PHP features. The first being
'auto_prepend_file' which causes the provided file to be added using the 'require' function. The second PHP
function is 'allow_url_include' which allows the use of URL-aware fopen wrappers. By enabling
allow_url_include, the exploit can use any protocol wrapper with auto_prepend_file. The module then uses
data:// to provide a file inline which includes the base64 encoded PHP payload.

By default this exploit returns a session confined to a FreeBSD jail with limited functionality. There is a
datastore option 'JAIL_BREAK', that when set to true, will steal the necessary tokens from a user authenticated
to the J-Web application, in order to overwrite the root password hash. If there is no user authenticated
to the J-Web application this exploit will try to create one. If unsuccesfull this method will not work.
The module then authenticates with the new root password over SSH and then rewrites the original root password
hash to /etc/master.passwd. There is an option to set allow ssh root login, if disabled.

Authors

Jacob Baines
Ron Bowes
jheysel-r7
Fabian Hafner

Platform

PHP,Unix

Architectures

php, cmd

Module Options

To display the available options, load the module within the Metasploit console and run the commands ‘show options’ or ‘show advanced’:


msf > use exploit/freebsd/http/junos_phprc_auto_prepend_file
msf exploit(junos_phprc_auto_prepend_file) > show targets
...targets...
msf exploit(junos_phprc_auto_prepend_file) > set TARGET < target-id >
msf exploit(junos_phprc_auto_prepend_file) > show options
...show and set options...
msf exploit(junos_phprc_auto_prepend_file) > exploit

Title
NEW

Explore Exposure Command

Confidently identify and prioritize exposures from endpoint to cloud with full attack surface visibility and threat-aware risk context.