Skip to content
RCE Write-up Advanced

Securing Developer Tools: Unpatched Code Vulnerabilities in Gogs (1/2)

Gogs, a self-hosted Git service, contains four unpatched vulnerabilities, including argument injection in its built-in SSH server that lets an authenticated attacker run arbitrary commands on the server. The other flaws allow file reads and deletion of internal files, so an attacker could steal source code, plant backdoors or wipe code.

Thomas Chauchefoin Follow

Published on sonarsource.com

Most companies today value their source code as an important asset and rely on cloud services like GitHub or operate their own source code hosting platform to manage this asset. One option for this is Gogs, an open-source solution for self-hosting source code.

Thomas Chauchefoin (@swapgs), Paul Gerste, on sonarsource.com

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

Likely the SSH env handler passes a user-controlled variable name straight to the env command as an argument, so a name beginning with a dash is treated as an option such as --split-string, which then runs an arbitrary command.

Impact

An authenticated attacker could execute arbitrary commands as the Gogs user, reading, modifying or deleting all source code and reaching internal hosts; exploitation depends on the server's env binary, so Alpine/BusyBox and Windows instances are not affected.

What the attacker needed

Built-in SSH server enabled; a valid SSH private key for the instance; GNU coreutils env with --split-string

The fix

The maintainers did not fix it; the researchers' patch removes the SSH env handler, and users should disable the built-in SSH server or migrate to Gitea.

How it was found

  1. Enable the built-in SSH server in Gogs and obtain a valid SSH private key registered to an account.
  2. Connect to the server over SSH and open a session channel.
  3. Send an env request whose variable name is the split-string option and whose value is the desired command.
  4. The env binary splits the value and executes the command under the Gogs user.

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 software a company can run on its own server to host source code, like a private GitHub. A helper program it calls to set environment variables can be tricked by a specially named variable into running a command of the attacker's choosing. Because the attacker must already have an account and an SSH key, this is not open to just anyone on the internet.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Thomas Chauchefoin

View all

3 more disclosed reports, best first.

More from Gogs

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.