1036
In versions of Go prior to v1.19, the LookPath function would follow the conventions of the runtime
OS and look for a program in the directiories listed in the current path [REF-1325].
Therefore, Go would prioritize searching the current directory when the provided command name
does not contain a directory separator and continued to search for programs even when the
specified program name is empty.
Consider the following where an application executes a git command to run on the system.
Example Language: Go (Bad)
func ExecuteGitCommand(name string, arg []string) error {
c := exec.Command(name, arg...)
var err error
c.Path, err = exec.LookPath(name)
if err != nil {
return err
}
}
An attacker could create a malicious repository with a file named ..exe and another file named
git.exe. If git.exe is not found in the system PATH, then ..exe would execute [REF-1326].
Example 3:
In February 2021 [REF-1169], a researcher was able to demonstrate the ability to breach major
technology companies by using "dependency confusion" where the companies would download
and execute untrusted packages.
The researcher discovered the names of some internal, private packages by looking at dependency
lists in public source code, such as package.json. The researcher then created new, untrusted
packages with the same name as the internal packages, then uploaded them to package hosting
services. These services included the npm registry for Node, PyPi for Python, and RubyGems.
In affected companies, their dependency resolution would search the public hosting services
first before consulting their internal service, causing the untrusted packages to be automatically
downloaded and executed.
Observed Examples
Reference Description
CVE-2023-25815 chain: a change in an underlying package causes the gettext function to use
implicit initialization with a hard-coded path (CWE-1419) under the userwritable
C:\ drive, introducing an untrusted search path element (CWE-427)
that enables spoofing of messages.
https://www.cve.org/CVERecord?id=CVE-2023-25815
CVE-2022-4826 Go-based git extension on Windows can search for and execute a malicious
"..exe" in a repository because Go searches the current working directory if
git.exe is not found in the PATH
https://www.cve.org/CVERecord?id=CVE-2022-4826
CVE-2020-26284 A Static Site Generator built in Go, when running on Windows, searches the
current working directory for a command, possibly allowing code execution
using a malicious .exe or .bat file with the name being searched
https://www.cve.org/CVERecord?id=CVE-2020-26284
CVE-2022-24765 Windows-based fork of git creates a ".git" folder in the C: drive, allowing local
attackers to create a .git folder with a malicious config file
https://www.cve.org/CVERecord?id=CVE-2022-24765
CVE-2019-1552 SSL package searches under "C:/usr/local" for configuration files and other
critical data, but C:/usr/local might be world-writable.
https://www.cve.org/CVERecord?id=CVE-2019-1552
CVE-2010-3402 "DLL hijacking" issue in document editor.
https://www.cve.org/CVERecord?id=CVE-2010-3402
CWE Version 4.14
CWE-427: Uncontrolled Search Path Element
CWE-427: Uncontrolled Search Path Element