Networked HTB
IP
initial nmap scan
we have the following ports open on the machine
Lets run a more in-depth scan of these ports
results
looks like
the target machine is centos
both http and https
Lets navigate to port 80
we are greeted with
if we look at the page source we can see this website is planning on linking a upload and gallary
we could seem to find these directories through the url bar so lets perform some feroxbusting and see if we can find anything
we find the following
/uploads
: no content is served
/uploads.php
: which does give us the ability to upload a file
Since we know the webserver runs php and lets see if we can upload a php reverse shell
after trying to upload a php reverse shell we find that it only accepts image files
Lets catch the request with burp and see if we can play around with the request and get it to pass through the restrictions
Once we are in burp and sent the request to repeater we can find a way to bypass restrictions
we can see
we change the file extention from
php
to.php.png
we modified the Content-type: image/png
we also added a magic byte to try and pass of our php scripts as a png file
We can send this off
Lets start a listener
Now when we check our listener we should have a hit
Priv Esc via apache
Lets stabilise our shell
when we look within the /home
directory we can see a user account guly
when looking at guly's home directory we can see the following
Looking through the crontab.guly
we can see there is a cronjob in place to run the the check_attack.php
script
we can see the crontab runs every 3 minutes
the check_attack.php
script
What we can see is that this script checks for files that aren;t suppose to be in the uploads directory and deletes them, what is interesting is how this script deletes these files, it appends the filename to the rm command without filtering which in theory should make it vulnerable to command injection exec("nohup /bin/rm -f $path$value > /dev/null 2>&1 &");
the $path
is the path of the uploads directory and $value
is the sus file name
Plan of attack
we can simple place a file within the /var/www/html/uploads
, within the filename holds the payload we want to execute, the file name will start with a semi colon ;
(to inject a new command) then the command to establish a reverse-shell
start our listner
Now we just wait for the cronjob to execute
after a couple of minutes we gain our shell
Lets upgrade our shell
checking our sudo privs
we can see the following
Lets have a look at this script
#!/bin/bash -p
the
-p
option specifies to run the script in pivileged mode
This part of the script uses a here document (
<< EoF ... EoF
) to create or overwrite the contents of the/etc/sysconfig/network-scripts/ifcfg-guly
file.It sets some initial parameters for the network interface (
DEVICE
,ONBOOT
,NM_CONTROLLED
).
Defines a regular expression (
regexp
) that allows alphanumeric characters, underscores, spaces, and hyphens.
Iterates through a list of network interface configuration variables (
NAME
,PROXY_METHOD
,BROWSER_ONLY
,BOOTPROTO
).
Prompts the user to input a value for the current configuration variable.
Uses a loop to validate user input against the defined regular expression. If the input doesn't match, the user is prompted to try again.
Appends the validated input to the network interface configuration file
Attempts to bring up the network interface
guly0
using the/sbin/ifup
command.
Now how does this help us
we are only really interested in the NAME
option because according to this page
we can inject commands in the interface name Lets try
just like that we are root
Last updated