<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Git-Hooks — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/tags/git-hooks/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata — refreshed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Tue, 23 Jan 2024 12:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/tags/git-hooks/feed.xml" rel="self" type="application/rss+xml"/><item><title>GitPython Vulnerability Allows Arbitrary Code Execution via Git Hooks</title><link>https://feed.craftedsignal.io/briefs/2024-01-23-gitpython-hook-execution/</link><pubDate>Tue, 23 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-23-gitpython-hook-execution/</guid><description>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.</description><content:encoded><![CDATA[<p>GitPython before version 3.1.47 is susceptible to a command execution vulnerability. The issue stems from how the <code>_clone()</code> function validates the <code>multi_options</code> parameter used in the <code>clone_from()</code>, <code>clone()</code>, or <code>Submodule.update()</code> methods. Specifically, the validation occurs on the original list of options before the <code>shlex.split</code> transformation. This allows an attacker to craft a string like <code>&quot;--branch main --config core.hooksPath=/x&quot;</code> which passes the initial validation because it starts with a safe option (<code>--branch</code>). However, after the string is split into tokens, the <code>--config</code> option becomes active, allowing the attacker to inject a malicious <code>core.hooksPath</code> 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.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker identifies a vulnerable application using GitPython to clone repositories.</li>
<li>The attacker crafts a malicious string containing a Git configuration option, such as <code>--config core.hooksPath=/path/to/malicious/hooks</code>, embedded within a seemingly benign option string like <code>--branch main --config core.hooksPath=/path/to/malicious/hooks</code>.</li>
<li>The attacker injects this malicious string into the <code>multi_options</code> parameter of the <code>clone_from()</code>, <code>clone()</code>, or <code>Submodule.update()</code> methods.</li>
<li>GitPython&rsquo;s <code>_clone()</code> function validates the <code>multi_options</code> parameter using <code>Git.check_unsafe_options()</code> <em>before</em> it is processed by <code>shlex.split()</code>.</li>
<li>Because the malicious string starts with a safe option (<code>--branch</code>), it bypasses the validation check.</li>
<li>The <code>shlex.split()</code> function then transforms the string into a list of individual options, making the <code>--config</code> option active.</li>
<li>The <code>git clone</code> command is executed with the injected <code>--config core.hooksPath=/path/to/malicious/hooks</code> option, causing Git to use the attacker-controlled directory for Git hooks.</li>
<li>Git executes the malicious hooks (e.g., <code>post-checkout</code>), resulting in arbitrary code execution on the victim&rsquo;s machine.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful 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 <code>multi_options</code> 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.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Upgrade GitPython to version 3.1.47 or later to patch the vulnerability (Affected Packages).</li>
<li>Implement input validation and sanitization for any user-supplied input used to construct the <code>multi_options</code> parameter to prevent injection of malicious Git configurations (Code).</li>
<li>Monitor process creation events for the execution of unexpected processes from directories specified as <code>core.hooksPath</code> (see Sigma rule <code>Detect Suspicious Git Hook Execution</code>).</li>
<li>Deploy the Sigma rules in this brief to your SIEM and tune for your environment.</li>
</ul>
]]></content:encoded><category domain="severity">high</category><category domain="type">advisory</category><category>gitpython</category><category>code-execution</category><category>git-hooks</category><category>command-injection</category></item></channel></rss>