Gogs 0-Day Exploited in the Wild
A symlink bypass in Gogs' PutContents API allowed authenticated users to overwrite files outside the repository, leading to remote code execution. Attackers exploited this to compromise over 700 public instances.
Published on wiz.io
On July 10th, the Wiz Threat Research team observed malware findings on public-facing instances of Gogs, a popular self-hosted Git service. What began as a routine investigation into an infected machine turned into the accidental discovery of a live zero-day vulnerability.
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 fix for a previous path traversal vulnerability validated the path but did not check if the destination was a symbolic link pointing outside the repository.
Impact
Attackers could execute arbitrary code on vulnerable Gogs instances, and over 700 public-facing servers were confirmed compromised.
What the attacker needed
Gogs version <= 0.13.3; Open registration enabled (default); Internet-exposed instance
The fix
The vulnerability was fixed in Gogs version v0.13.4.
How it was found
- Create a standard git repository.
- Commit a symbolic link pointing to a sensitive target file.
- Use the PutContents API to write data to the symlink, overwriting the target file outside the repository.
- Overwrite .git/config to set sshCommand and execute arbitrary commands.
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.
Gogs is a tool for hosting Git repositories. A feature meant to let users edit files in their repository could be tricked into writing to any file on the server by using a special shortcut called a symbolic link. This let attackers run their own commands on the server.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.