<?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>Pyp2spec (&lt; 0.14.1) — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/products/pyp2spec--0.14.1/</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>Wed, 03 Jan 2024 12:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/products/pyp2spec--0.14.1/feed.xml" rel="self" type="application/rss+xml"/><item><title>pyp2spec Code Injection Vulnerability</title><link>https://feed.craftedsignal.io/briefs/2024-01-pyp2spec-code-injection/</link><pubDate>Wed, 03 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-pyp2spec-code-injection/</guid><description>pyp2spec before 0.14.1 is vulnerable to code injection by writing PyPI package metadata into generated spec files without escaping RPM macro directives, allowing malicious packages to execute arbitrary commands on the build machine.</description><content:encoded><![CDATA[<p>pyp2spec, a tool for generating RPM spec files from PyPI packages, contains a code injection vulnerability affecting versions prior to 0.14.1. The vulnerability stems from the tool&rsquo;s failure to properly escape RPM macro directives when writing PyPI package metadata (such as the summary field) into the generated spec file. This allows a malicious PyPI package to inject arbitrary commands into the spec file, which are then executed when an RPM tool processes the file. This poses a significant risk to package maintainers and build systems, particularly within the Fedora ecosystem where compromised credentials can lead to widespread supply chain attacks. The realistic attack vector involves typosquatting or targeting packages known to be under review.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker crafts a malicious PyPI package containing specially formatted metadata, including an RPM macro directive (e.g., within the package summary).</li>
<li>A Fedora packager, intending to package a legitimate Python package, uses <code>pyp2spec</code> to generate an RPM spec file from the malicious PyPI package.</li>
<li><code>pyp2spec</code> writes the attacker-controlled metadata, including the unescaped RPM macro directive, into the generated spec file.</li>
<li>The packager, or an automated system, uses an RPM tool like <code>rpmbuild -bs</code>, <code>rpmbuild --nobuild</code>, or <code>rpm -q --specfile</code> to inspect or build the package from the spec file.</li>
<li>The RPM tool parses the spec file and, upon encountering the RPM macro directive, executes the embedded command.</li>
<li>The attacker&rsquo;s command executes on the build machine, potentially granting the attacker access to the packager&rsquo;s credentials (dist-git SSH keys, Koji build credentials, Bodhi update credentials).</li>
<li>The attacker uses the compromised credentials to commit malicious source code to the distribution&rsquo;s Git repository (dist-git).</li>
<li>The malicious code is built and distributed to end users through the normal package update pipeline, resulting in a supply chain attack.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation allows attackers to execute arbitrary commands on the build machine. This can lead to the compromise of sensitive credentials, such as SSH keys and build system credentials. In the Fedora ecosystem, this could enable an attacker to inject malicious code into packages that are distributed to end users, potentially affecting millions of systems. The vulnerability poses a high risk to package maintainers and build systems.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Upgrade to <code>pyp2spec</code> version 0.14.1 or later to remediate the code injection vulnerability as described in the advisory (<a href="https://github.com/advisories/GHSA-r35x-v8p8-xvhw)">https://github.com/advisories/GHSA-r35x-v8p8-xvhw)</a>.</li>
<li>Implement file integrity monitoring on RPM spec files, alerting on unexpected modifications, to detect potentially malicious injected code. Use file_event logs with a rule like the one below.</li>
<li>Monitor process executions originating from RPM tools (<code>rpmbuild</code>, <code>rpm</code>), focusing on unusual or unexpected commands that could indicate exploitation, using process_creation logs and the Sigma rule provided.</li>
</ul>
]]></content:encoded><category domain="severity">high</category><category domain="type">advisory</category><category>code-injection</category><category>supply-chain</category><category>rpm</category><category>linux</category></item></channel></rss>