Skip to content
Path traversal Write-up Advanced

CVE-2018-14364: How did I find a bug in Gitlab project import and got shell access

A regular expression in GitLab's project import used `$` instead of `\z`, so a filename containing a newline after a dot could bypass the symlink removal check. An attacker could import a crafted tarball to create a symlink, delete the project, then import another tarball to write an SSH authorised_keys file and gain shell access.

Li Rongxi Follow

Published on blog.nyangawa.me

We use Gitlab-CE as our version control tool and part of the auto dev-ops pipeline. As one of the several sys admins in this company, I think that I might also be the one who knows Gitlab the most.

Li Rongxi, on blog.nyangawa.me

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The regular expression used `$` (end of line) instead of `\z` (end of string), so a filename containing a newline after a dot was not recognised as a symlink and was not removed.

Impact

An attacker could gain shell access to the GitLab instance as the GitLab user, potentially leading to full compromise.

What the attacker needed

Ability to import projects; ability to delete projects; SSH access to the GitLab server

The fix

The issue was fixed in GitLab 11.0.4 by correcting the regular expression to use `\z` instead of `$`.

How it was found

  1. Import a crafted tarball that creates a symbolic link named with a dot, newline, and 'evil' pointing to /var/opt/gitlab.
  2. Delete the project, but the uploaded symlink remains on disk.
  3. Import another crafted tarball where the same name is now a real directory containing an authorized_keys file with the attacker's public key.
  4. Connect to the GitLab instance via SSH using the attacker's private key.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

GitLab lets you import projects from a compressed file (a tarball). The code tried to remove symbolic links (shortcuts to other files) from the imported files, but a mistake in a pattern match let a specially named file slip through. By importing two such files in sequence, the attacker could place their own SSH key on the server and log in as the GitLab user.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More by Li Rongxi

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.