Skip to content

Gin-vue-admin subject to Remote Code Execution via file upload vulnerability

Critical severity GitHub Reviewed Published Oct 23, 2022 in flipped-aurora/gin-vue-admin • Updated Jan 30, 2023

Package

gomod github.com/flipped-aurora/gin-vue-admin/server (Go)

Affected versions

< 2.5.4

Patched versions

2.5.4

Description

Impact

Gin-vue-admin < 2.5.4 has File upload vulnerabilities。
File upload vulnerabilities are when a web server allows users to upload files to its filesystem without sufficiently validating things like their name, type, contents, or size. Failing to properly enforce restrictions on these could mean that even a basic image upload function can be used to upload arbitrary and potentially dangerous files instead. This could even include server-side script files that enable remote code execution.

Patches

flipped-aurora/gin-vue-admin#1264

Workarounds

flipped-aurora/gin-vue-admin#1264

References

#1263

For more information

The plugin installation function of Gin-Vue-Admin allows users to download zip packages from the plugin market and upload them for installation. This function has an arbitrary file upload vulnerability. A malicious attacker can upload a constructed zip package to traverse the directory and upload or overwrite arbitrary files on the server side.

The affected code https://github.com/flipped-aurora/gin-vue-admin/blob/main/server/service/system/sys_auto_code.go line 880 called the utils.Unzip method

paths, err := utils.Unzip(GVAPLUGPINATH+file.Filename, GVAPLUGPINATH)
	paths = filterFile(paths)
	var webIndex = -1
	var serverIndex = -1
	for i := range paths {
		paths[i] = filepath.ToSlash(paths[i])
		pathArr := strings.Split(paths[i], "/")
		ln := len(pathArr)
		if ln < 2 {
			continue
		}
		if pathArr[ln-2] == "server" && pathArr[ln-1] == "plugin" {
			serverIndex = i
		}
		if pathArr[ln-2] == "web" && pathArr[ln-1] == "plugin" {
			webIndex = i
		}
	}
	if webIndex == -1 && serverIndex == -1 {
		zap.L().Error("非标准插件,请按照文档自动迁移使用")
		return webIndex, serverIndex, errors.New("非标准插件,请按照文档自动迁移使用")
	}
...

The https://github.com/flipped-aurora/gin-vue-admin/blob/main/server/utils/zip.go code defines the utils.Unzip method

//解压
func Unzip(zipFile string, destDir string) ([]string, error) {
	zipReader, err := zip.OpenReader(zipFile)
	var paths []string
	if err != nil {
		return []string{}, err
	}
	defer zipReader.Close()

	for _, f := range zipReader.File {
		fpath := filepath.Join(destDir, f.Name)
		paths = append(paths, fpath)
		if f.FileInfo().IsDir() {
			os.MkdirAll(fpath, os.ModePerm)
...

It can be analyzed that after uploading a zip compressed file, the Unzip method will be called to decompress the compressed file, and then judge whether the compressed file contains the fixed directory structure of server, web, and plugin.

Whether the zip file is correct or not, it will be decompressed first. If the directory does not exist, it will be created automatically. Therefore, malicious zip packages can be constructed, and directory traversal can be performed during automatic decompression to upload or overwrite any file.

Use the Zip Slip vulnerability to construct a malicious zip package with ../../../../ filenames, and upload the malicious zip package to trigger the vulnerability.

1
2

References

@piexlmax piexlmax published to flipped-aurora/gin-vue-admin Oct 23, 2022
Published by the National Vulnerability Database Oct 25, 2022
Published to the GitHub Advisory Database Oct 25, 2022
Reviewed Oct 25, 2022
Last updated Jan 30, 2023

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

EPSS score

0.121%
(47th percentile)

Weaknesses

CVE ID

CVE-2022-39345

GHSA ID

GHSA-7gc4-r5jr-9hxv

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.