Rapid7 Vulnerability & Exploit Database

Junos OS PHPRC Environment Variable Manipulation RCE

Back to Search

Junos OS PHPRC Environment Variable Manipulation RCE

Disclosed
08/17/2023
Created
09/29/2023

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 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.

Author(s)

  • Jacob Baines
  • Ron Bowes
  • jheysel-r7

Platform

PHP,Unix

Architectures

php, cmd

Development

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

Time is precious, so I don’t want to do something manually that I can automate. Leveraging the Metasploit Framework when automating any task keeps us from having to re-create the wheel as we can use the existing libraries and focus our efforts where it matters.

– Jim O’Gorman | President, Offensive Security

;