{"description":"Trending threats, MITRE ATT\u0026CK coverage, and detection metadata — refreshed continuously.","feed_url":"https://feed.craftedsignal.io/tags/git-hooks/","home_page_url":"https://feed.craftedsignal.io/","items":[{"_cs_actors":[],"_cs_cves":[{"cvss":9.8,"id":"CVE-2023-40267"}],"_cs_exploited":false,"_cs_products":["GitPython"],"_cs_severities":["high"],"_cs_tags":["gitpython","code-execution","git-hooks","command-injection"],"_cs_type":"advisory","_cs_vendors":["pip"],"content_html":"\u003cp\u003eGitPython before version 3.1.47 is susceptible to a command execution vulnerability. The issue stems from how the \u003ccode\u003e_clone()\u003c/code\u003e function validates the \u003ccode\u003emulti_options\u003c/code\u003e parameter used in the \u003ccode\u003eclone_from()\u003c/code\u003e, \u003ccode\u003eclone()\u003c/code\u003e, or \u003ccode\u003eSubmodule.update()\u003c/code\u003e methods. Specifically, the validation occurs on the original list of options before the \u003ccode\u003eshlex.split\u003c/code\u003e transformation. This allows an attacker to craft a string like \u003ccode\u003e\u0026quot;--branch main --config core.hooksPath=/x\u0026quot;\u003c/code\u003e which passes the initial validation because it starts with a safe option (\u003ccode\u003e--branch\u003c/code\u003e). However, after the string is split into tokens, the \u003ccode\u003e--config\u003c/code\u003e option becomes active, allowing the attacker to inject a malicious \u003ccode\u003ecore.hooksPath\u003c/code\u003e configuration. This configuration points Git to a directory containing attacker-controlled Git hooks, which are then executed during the clone operation. This vulnerability is similar in nature to CVE-2023-40267.\u003c/p\u003e\n\u003ch2 id=\"attack-chain\"\u003eAttack Chain\u003c/h2\u003e\n\u003col\u003e\n\u003cli\u003eAn attacker identifies a vulnerable application using GitPython to clone repositories.\u003c/li\u003e\n\u003cli\u003eThe attacker crafts a malicious string containing a Git configuration option, such as \u003ccode\u003e--config core.hooksPath=/path/to/malicious/hooks\u003c/code\u003e, embedded within a seemingly benign option string like \u003ccode\u003e--branch main --config core.hooksPath=/path/to/malicious/hooks\u003c/code\u003e.\u003c/li\u003e\n\u003cli\u003eThe attacker injects this malicious string into the \u003ccode\u003emulti_options\u003c/code\u003e parameter of the \u003ccode\u003eclone_from()\u003c/code\u003e, \u003ccode\u003eclone()\u003c/code\u003e, or \u003ccode\u003eSubmodule.update()\u003c/code\u003e methods.\u003c/li\u003e\n\u003cli\u003eGitPython\u0026rsquo;s \u003ccode\u003e_clone()\u003c/code\u003e function validates the \u003ccode\u003emulti_options\u003c/code\u003e parameter using \u003ccode\u003eGit.check_unsafe_options()\u003c/code\u003e \u003cem\u003ebefore\u003c/em\u003e it is processed by \u003ccode\u003eshlex.split()\u003c/code\u003e.\u003c/li\u003e\n\u003cli\u003eBecause the malicious string starts with a safe option (\u003ccode\u003e--branch\u003c/code\u003e), it bypasses the validation check.\u003c/li\u003e\n\u003cli\u003eThe \u003ccode\u003eshlex.split()\u003c/code\u003e function then transforms the string into a list of individual options, making the \u003ccode\u003e--config\u003c/code\u003e option active.\u003c/li\u003e\n\u003cli\u003eThe \u003ccode\u003egit clone\u003c/code\u003e command is executed with the injected \u003ccode\u003e--config core.hooksPath=/path/to/malicious/hooks\u003c/code\u003e option, causing Git to use the attacker-controlled directory for Git hooks.\u003c/li\u003e\n\u003cli\u003eGit executes the malicious hooks (e.g., \u003ccode\u003epost-checkout\u003c/code\u003e), resulting in arbitrary code execution on the victim\u0026rsquo;s machine.\u003c/li\u003e\n\u003c/ol\u003e\n\u003ch2 id=\"impact\"\u003eImpact\u003c/h2\u003e\n\u003cp\u003eSuccessful exploitation of this vulnerability allows an attacker to execute arbitrary code on the system where the GitPython library is used. Any application that passes user-supplied input to the \u003ccode\u003emulti_options\u003c/code\u003e parameter of the affected functions is vulnerable. This can lead to complete system compromise, data exfiltration, or denial of service. The vulnerability affects GitPython versions prior to 3.1.47.\u003c/p\u003e\n\u003ch2 id=\"recommendation\"\u003eRecommendation\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003eUpgrade GitPython to version 3.1.47 or later to patch the vulnerability (Affected Packages).\u003c/li\u003e\n\u003cli\u003eImplement input validation and sanitization for any user-supplied input used to construct the \u003ccode\u003emulti_options\u003c/code\u003e parameter to prevent injection of malicious Git configurations (Code).\u003c/li\u003e\n\u003cli\u003eMonitor process creation events for the execution of unexpected processes from directories specified as \u003ccode\u003ecore.hooksPath\u003c/code\u003e (see Sigma rule \u003ccode\u003eDetect Suspicious Git Hook Execution\u003c/code\u003e).\u003c/li\u003e\n\u003cli\u003eDeploy the Sigma rules in this brief to your SIEM and tune for your environment.\u003c/li\u003e\n\u003c/ul\u003e\n","date_modified":"2024-01-23T12:00:00Z","date_published":"2024-01-23T12:00:00Z","id":"/briefs/2024-01-23-gitpython-hook-execution/","summary":"A vulnerability in GitPython versions prior to 3.1.47 allows for command execution during repository cloning by manipulating the `multi_options` parameter to inject malicious Git configurations, such as `core.hooksPath`, leading to the execution of attacker-controlled hooks.","title":"GitPython Vulnerability Allows Arbitrary Code Execution via Git Hooks","url":"https://feed.craftedsignal.io/briefs/2024-01-23-gitpython-hook-execution/"}],"language":"en","title":"CraftedSignal Threat Feed — Git-Hooks","version":"https://jsonfeed.org/version/1.1"}