> For the complete documentation index, see [llms.txt](https://ajaykumar-kanthi.gitbook.io/write-ups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ajaykumar-kanthi.gitbook.io/write-ups/hack-the-box-oscp-machines/htb-updown.md).

# HTB - UpDown

## Enumeration and Foothold

### NMAP

```bash
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

### HTTP

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FfkjHooCp3UDXKTeEavGY%2Fimage.png?alt=media&amp;token=58b28dc7-6f80-42bf-925e-cc3ab928d032" alt=""><figcaption></figcaption></figure>

if we give a url it will check if the given url is up or down that means i can test for SSRF.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FscXA1GVaPo4evJbdC0AX%2Fimage.png?alt=media&amp;token=e0583e32-f0a5-4901-ab50-c402623263ac" alt=""><figcaption></figcaption></figure>

i can ping the localhost also the domain name is found in the response.

Scanning fro internal ports reveal only port 80 is able to give successful response and remaining says site is down so SSRF is not the case here.

that said i will add the domain name to the hosts and scan for subdomains.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FUMIOo88RBGroysdv3QH0%2Fimage.png?alt=media&amp;token=c4d68b55-0e1b-4a7d-9ddd-0612d613cc08" alt=""><figcaption></figcaption></figure>

and it reveals a new subdomain called dev, add it to the hosts file.

but accessing it says forbidden error.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FtEKsxFKrm1TosYdDIpFE%2Fimage.png?alt=media&amp;token=53db301f-357c-48e7-906b-eb7f6f58d715" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FZNc857hyH9JRSAX6It35%2Fimage.png?alt=media&amp;token=a5f0750d-b92d-498c-95e5-2014660f93ea" alt=""><figcaption></figcaption></figure>

running feroxbuster reveals a dev directory on the main site.

Accessing dev results in an empty page&#x20;

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FNcnM193ldetN8s75Eiln%2Fimage.png?alt=media&amp;token=1a3b4084-4e26-4b0e-ba13-6e24cb1f0197" alt=""><figcaption></figcaption></figure>

dev should be there for a reason so i will again fuzz for hidden directories.

using a different wordlist reveals a hidden git directory.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fcl595GLQDsDGd92C933Q%2Fimage.png?alt=media&amp;token=55963933-e3e5-42b1-a82d-11d1e012025a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fj4jdrM8meSsJvNcgVjiF%2Fimage.png?alt=media&amp;token=4c02e505-9d93-4ebd-8078-26274fc86f93" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FFOtPupcG5AnHnqSCNXA1%2Fimage.png?alt=media&amp;token=ca39552d-075d-4a36-97d4-cdc9168b220a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FdetPsTVFZaxu1W4QysZk%2Fimage.png?alt=media&amp;token=52ced2df-6e10-46aa-951b-2aa8facaf42d" alt=""><figcaption></figcaption></figure>

it holds some interesting files

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FZsEmz9kHNZmvOnnJ41oN%2Fimage.png?alt=media&amp;token=c108c4bf-4118-4f37-8461-f9ff0763ae38" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FLS3RxphKcS3iisUi2aqE%2Fimage.png?alt=media&amp;token=3fec87cf-bd64-46d3-9aa0-67def3a4f43d" alt=""><figcaption></figcaption></figure>

the checker.php checks for any file uploaded and if any wrappers are used results in a hacking attempt detected. The uploaded files are stored in uploads directory as md5 sum of the time uploaded.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fv6R73xS899Llv2Lyk2nT%2Fimage.png?alt=media&amp;token=abbf14d0-fe7a-484c-828a-bb9270c62479" alt=""><figcaption></figcaption></figure>

direct access is blocked could be a possible reason why the `dev.siteisup.htb` is blocked.

Also the upload option takes a list of ips and checks if they are down or up.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FilOjycCKzF7ErXEIbmoN%2Fimage.png?alt=media&amp;token=ed63e2d6-ca28-4471-a151-0a37f060860f" alt=""><figcaption></figcaption></figure>

* `SetEnvIfNoCase Special-Dev "only4dev" Required-Header` this checks incoming requests for a header named `Special-Dev`. If its value matches the string `only4dev` (case-insensitive), Apache sets an internal environment variable called `Required-Header`
* `Deny from All` / `Allow from env=Required-Header`  access is denied by default, **unless** that environment variable got set i.e., unless the request included the correct header/value pair

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FqphGKrH6tZknhnvjRoPd%2Fimage.png?alt=media&amp;token=8bbe969e-3763-4c01-a3f7-f21e6bb9658b" alt=""><figcaption></figcaption></figure>

using the header gives access to the site.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FV9s4KSrKv9C1R6WmO6gM%2Fimage.png?alt=media&amp;token=bd3aa4f9-7043-4dde-9435-8ae248e1e151" alt=""><figcaption></figcaption></figure>

i will create a list of ips and upload to see how it reacts.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FYhK3iwKJi4yi816qi68a%2Fimage.png?alt=media&amp;token=52dcab6e-1689-4eaf-b1aa-159f270cc607" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FAyVeHApM0YVnA49LGL9s%2Fimage.png?alt=media&amp;token=80d5c6fc-8581-47b2-a2b9-081c5fb4d4a9" alt=""><figcaption></figcaption></figure>

the files are saved in uploads directory.

since i know how the website filters i will use a polyglot technique to upload a php file and execute it.

for this purpose i will use phar.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F65C0w7FbFTHH3Gq5vSOn%2Fimage.png?alt=media&amp;token=8710adad-bc2e-4c3e-93ad-43d82e7d0baa" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FSBaSg8yvovDXV492QA1W%2Fimage.png?alt=media&amp;token=42560737-db77-4f4c-b90d-b146a8db94f7" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FHPSKCrz6PlINPVPhARDO%2Fimage.png?alt=media&amp;token=615d18d6-143e-4d49-a50d-ae4b135d2188" alt=""><figcaption></figcaption></figure>

the file is saved ion uploads directory

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FNXCvXvPk7m5Y0EoBJSv6%2Fimage.png?alt=media&amp;token=6fc42850-7ea9-434f-b180-88d22f652cb9" alt=""><figcaption></figcaption></figure>

and the execution works

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FAUwfbobbgagPMoVEX2wJ%2Fimage.png?alt=media&amp;token=e4272f36-10a9-4e2d-91da-a6f4e592e184" alt=""><figcaption></figcaption></figure>

that said i will build a payload that will give me reverse shell.

```
disable_functions: pcntl_*, error_log, system, exec, shell_exec, popen, 
passthru, link, symlink, syslog, ld, mail, stream_socket_sendto, dl, 
stream_socket_client, fsockopen
```

**`System`, `exec`, `shell_exec`, `passthru`, and `popen` are all explicitly disabled.** So the payload you were about to send (`system($_GET['cmd'])`) will fail  PHP will throw a fatal error/warning on that call (suppressed since `display_errors` is Off, so you'd just get blank output.

`proc_open` is NOT blocked.

i can use it to get reverse shell.

### php reverse shell using proc\_open

{% embed url="<https://gist.github.com/simran-sankhala/d94bc4e42fee5158395d189ec39ecac4>" %}

the payload can be used to get reverse shell.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F7mU954t11vxvKeZcnQKj%2Fimage.png?alt=media&amp;token=9aa61a74-36c7-43f6-ad6d-f7e77db40c84" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FmYnoKR9V9HctkAba9Iy1%2Fimage.png?alt=media&amp;token=8624728d-473f-47e9-af1c-afc8a64c7476" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F5rmvJanW3OBg4WsngxOe%2Fimage.png?alt=media&amp;token=3707cfe4-6b57-4854-b21f-fcdb2a7b019a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FTp3bHpiGFulYiwanCVoE%2Fimage.png?alt=media&amp;token=96f00603-6bbd-4454-90eb-e8831f09c333" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FqnNQ7b3NoiP1Stlh8Imm%2Fimage.png?alt=media&amp;token=67655847-9dd7-43ca-97ce-905d6ab8cd08" alt=""><figcaption></figcaption></figure>

## Shell as www-data

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fip9v1IeIdXYROiS5aw3g%2Fimage.png?alt=media&amp;token=78297836-8ce0-4178-ad39-b0c0fef7d750" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FLnCY9PA2Bs0iJukb8NYd%2Fimage.png?alt=media&amp;token=599ae9e8-ff7f-4a63-bd45-9241ab5d6bd3" alt=""><figcaption></figcaption></figure>

i need to get shell access as developer but first upgrade the shell

```bash
$ python -c 'import pty; pty.spawn("/bin/bash")'
www-data@updown:/home/developer$ export TERM=xterm
export TERM=xterm
www-data@updown:/home/developer$ 
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F0cbgQwbB8bQf5jMVfAD1%2Fimage.png?alt=media&amp;token=c8cde0ae-0d61-4410-ab77-859d660d2416" alt=""><figcaption></figcaption></figure>

takes a url and check up or down.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FemR6mIPmX5YPhQs5o9A4%2Fimage.png?alt=media&amp;token=47cb7b61-5142-492d-997b-b28b52d711f0" alt=""><figcaption></figcaption></figure>

also the siteisup file has suid bit set so  i can use it to spawn a shell as developer.

## Shell as developer

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FHaGysAKqSDUXgCCeKYqR%2Fimage.png?alt=media&amp;token=bfe78e95-b91c-46d1-a788-8f29177ba81b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F7x7qpDjyEXEg49UT3xCx%2Fimage.png?alt=media&amp;token=8bea0db9-48e8-4b2f-b853-eea8dc19cdaa" alt=""><figcaption></figcaption></figure>

developer can run easy\_install as root without password.

```
developer@updown:/home/developer$ cat /usr/local/bin/easy_install   cat /usr/local/bin/easy_install

#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from setuptools.command.easy_install import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
developer@updown:/home/developer$ 

```

gtfo bins has a page on how to abuse this&#x20;

{% embed url="<https://gtfobins.org/gtfobins/easy_install/#inherit>" %}

```bash
mkdir /tmp/priv && cd /tmp/priv
echo 'import os; os.system("exec /bin/sh </dev/tty >/dev/tty 2>/dev/tty")' > setup.py
sudo easy_install .
```

## Shell as Root

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FrNuoXdXEFcE20uZmQd94%2Fimage.png?alt=media&amp;token=6b2139ca-7742-4320-8857-e9bda2c5df59" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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 following URL with the `ask` and `goal` query parameters:

```
GET https://ajaykumar-kanthi.gitbook.io/write-ups/hack-the-box-oscp-machines/htb-updown.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

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.
