<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Kernel of Truth]]></title><description><![CDATA[I write about latest CVE's and hack arround technology!]]></description><link>https://blogs.hiteshpatra.in</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1734966193392/d030ddd8-79f6-4776-bba8-4f51249181c5.png</url><title>Kernel of Truth</title><link>https://blogs.hiteshpatra.in</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 15:47:28 GMT</lastBuildDate><atom:link href="https://blogs.hiteshpatra.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[CVE-2024-53677 - Apache Struts File Upload Vulnerability leading to RCE]]></title><description><![CDATA[Apache has announced a critical vulnerability affecting Apache Struts, a widely used Java-based web application framework by various organizations, including government agencies, e-commerce platforms, financial institutions, and airlines.
Apache publ...]]></description><link>https://blogs.hiteshpatra.in/cve-2024-53677-apache-struts-file-upload-vulnerability-leading-to-rce</link><guid isPermaLink="true">https://blogs.hiteshpatra.in/cve-2024-53677-apache-struts-file-upload-vulnerability-leading-to-rce</guid><category><![CDATA[struts2]]></category><category><![CDATA[CVE-2024-53677]]></category><category><![CDATA[apache]]></category><category><![CDATA[RCE]]></category><category><![CDATA[vulnerability]]></category><category><![CDATA[CVE]]></category><category><![CDATA[apache struts]]></category><dc:creator><![CDATA[Hitesh Patra]]></dc:creator><pubDate>Tue, 17 Dec 2024 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1734964851108/6add7eac-27f1-4aa7-8f50-741dab2b52d6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Apache has announced a critical vulnerability affecting Apache Struts, a widely used Java-based web application framework by various organizations, including government agencies, e-commerce platforms, financial institutions, and airlines.</p>
<p>Apache publicly released an <a target="_blank" href="https://cwiki.apache.org/confluence/display/WW/S2-067">advisory</a> recently stating,</p>
<blockquote>
<p>File upload logic is flawed, and allows an attacker to enable paths with traversals - similar problem as reported in <a target="_blank" href="https://cwiki.apache.org/confluence/display/WW/S2-066">S2-066</a></p>
<p>An attacker can manipulate file upload params to enable paths traversal and under some circumstances this can lead to uploading a malicious file which can be used to perform Remote Code Execution.</p>
<p><strong>Note: applications not using</strong> <a target="_blank" href="https://struts.apache.org/core-developers/file-upload-interceptor"><strong>FileUploadInterceptor</strong></a> <strong>are safe.</strong></p>
</blockquote>
<p>Affected versions,</p>
<ul>
<li><p><em>Struts 2.0.0 through Struts 2.3.37 (</em><a target="_blank" href="https://struts.apache.org/struts23-eol-announcement"><em>EOL</em></a><em>)</em></p>
</li>
<li><p><em>Struts 2.5.0 through Struts 2.5.33 (</em><a target="_blank" href="https://struts.apache.org/struts25-eol-announcement"><em>EOL</em></a><em>)</em></p>
</li>
<li><p><em>Struts 6.0.0 through Struts 6.3.0.2</em></p>
</li>
</ul>
<p>It has been assigned as <a target="_blank" href="https://nvd.nist.gov/vuln/detail/CVE-2024-53677">CVE-2024-53677 with a CVSS 4.0</a> scored as 9.5 - <strong>Critical</strong></p>
<p><strong>Vector:</strong> CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H/S:N/AU:Y/R:A/V:C/RE:L/U:Red</p>
<h2 id="heading-what-is-the-vulnerability">What is the Vulnerability?</h2>
<p><a target="_blank" href="https://nvd.nist.gov/vuln/detail/CVE-2024-54134"><strong>CVE-2024-53677</strong></a> is a file upload vulnerability in Apache Struts 2, stemming from path traversal flaws in the deprecated <code>File Upload Interceptor</code> component. By exploiting this vulnerability, attackers can manipulate file upload parameters to navigate directories and upload malicious files. In certain conditions, these files may lead to remote code execution, enabling attackers to gain control over affected systems.</p>
<p>Applications not utilizing the <code>File Upload Interceptor</code> component remain unaffected by <strong>CVE-2024-53677</strong>. Starting with version <code>6.4.0</code>, Apache deprecated the File Upload Interceptor and introduced the Action File Upload Interceptor, offering enhanced security, improved configuration, and better integration capabilities. Users are strongly encouraged to migrate to this new mechanism to mitigate potential risks.</p>
<h2 id="heading-root-cause-analysis">Root Cause Analysis</h2>
<p>The vulnerability allows an attacker to override internal file upload variables in applications that use the <a target="_blank" href="https://struts.apache.org/core-developers/file-upload-interceptor">File Upload Interceptor</a>.</p>
<p>What is <strong>File Upload Interceptor?</strong></p>
<blockquote>
<p>The <strong>File Upload Interceptor</strong> in Struts 2 is a framework component that facilitates file uploads in web applications. It is a part of the Struts 2 interceptor stack and is typically used to handle multipart form submissions where file uploads are involved. This interceptor processes file upload requests, saving uploaded files to a specified location and making them accessible to the application for further processing.</p>
<p><strong>Note: The File Upload Interceptor has been deprecated</strong> since Struts 2 version 6.4.0 due to security concerns <strong>and has been replaced with the File Upload Interceptor for enhanced security and provide better integration to modern application needs.</strong></p>
</blockquote>
<p>As per Struts version 6.4.0 release <strong>File Upload Interceptor</strong> has been marked deprecated and should no longer be used.</p>
<p>However, it has not been removed or patched from 6.4.0 release. It still exists and appers to operate in a vulnerable way on all 6.x versions of Struts.</p>
<p>This issue is quite similar to <a target="_blank" href="https://cwiki.apache.org/confluence/display/WW/S2-066"><strong>CVE-2023-50164</strong></a> where the file upload logic is flawed, and allows an attacker to enable paths with traversals.</p>
<blockquote>
<p>An attacker can manipulate file upload params to enable paths traversal and under some circumstances this can lead to uploading a malicious file which can be used to perform Remote Code Execution.</p>
</blockquote>
<h3 id="heading-environment-setup">Environment Setup</h3>
<p>To demonstrate the vulnerability, first let’s setup our vulnerable environment and understand the issue in detail.</p>
<p>Setting up the target is really easy, you can build your own war app by immitating the FileUploadInterceptor Integration and defining the logic for an upload functionality</p>
<p>Let’s understand the file structure and the files needed,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1734958910835/a7146fd4-e3d4-4bfc-87c6-ee26b97a0ff1.png" alt class="image--center mx-auto" /></p>
<p>The above screenshot shows the file structure of the vulnerable app, where the <code>struts.xml</code> is the Struts definition file, <code>UploadAction.java</code> being the primary upload logic where we’ll use a typical File Upload Interceptor-based file upload pattern, <code>web.xml</code> is the Web Application Deployment Descriptor (WADD) for the application and <code>index.jsp</code> , <code>upload.jsp</code> being the front end files.</p>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>
<span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">struts</span> <span class="hljs-meta-keyword">PUBLIC</span> <span class="hljs-meta-string">"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"</span>
    <span class="hljs-meta-string">"http://struts.apache.org/dtds/struts-2.5.dtd"</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">struts</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">package</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"default"</span> <span class="hljs-attr">extends</span>=<span class="hljs-string">"struts-default"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">action</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"upload"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"com.example.UploadAction"</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- File Upload Interceptor configuration --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">interceptor-ref</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"fileUpload"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">param</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"allowedTypes"</span>&gt;</span>text/plain,image/jpeg,image/png,application/octet-stream<span class="hljs-tag">&lt;/<span class="hljs-name">param</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">param</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"maximumSize"</span>&gt;</span>5242880<span class="hljs-tag">&lt;/<span class="hljs-name">param</span>&gt;</span> <span class="hljs-comment">&lt;!-- Max file size is 5MB --&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">interceptor-ref</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">interceptor-ref</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"defaultStack"</span> /&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">result</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"success"</span>&gt;</span>upload.jsp<span class="hljs-tag">&lt;/<span class="hljs-name">result</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">result</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"error"</span>&gt;</span>upload.jsp<span class="hljs-tag">&lt;/<span class="hljs-name">result</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">action</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">package</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">struts</span>&gt;</span>
</code></pre>
<p>The above XML is part of the <code>struts.xml</code> file, where the File Upload Interceptor is specified at <code>&lt;interceptor-ref name="fileUpload"&gt;</code></p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> java.io.File;
<span class="hljs-keyword">import</span> java.io.IOException;
<span class="hljs-keyword">import</span> org.apache.commons.io.FileUtils;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UploadAction</span> </span>{
    <span class="hljs-keyword">private</span> File upload;                
    <span class="hljs-keyword">private</span> String uploadFileName;    
    <span class="hljs-keyword">private</span> String uploadContentType;  

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String UPLOAD_DIRECTORY = <span class="hljs-string">"/webapps/ROOT/uploads/"</span>;

    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">execute</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">try</span> {
         System.out.println(<span class="hljs-string">"Src File name: "</span> + upload);
         System.out.println(<span class="hljs-string">"Dst File name: "</span> + uploadFileName);

         File destFile  = <span class="hljs-keyword">new</span> File(UPLOAD_DIRECTORY, uploadFileName);
         FileUtils.copyFile(upload, destFile);

      } <span class="hljs-keyword">catch</span>(IOException e) {
         e.printStackTrace();
         <span class="hljs-keyword">return</span> <span class="hljs-string">"error"</span>;
      }

      <span class="hljs-keyword">return</span> <span class="hljs-string">"success"</span>;
    }

   <span class="hljs-function"><span class="hljs-keyword">public</span> File <span class="hljs-title">getUpload</span><span class="hljs-params">()</span> </span>{
      <span class="hljs-keyword">return</span> upload;
   }

   <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setUpload</span><span class="hljs-params">(File upload)</span> </span>{
      <span class="hljs-keyword">this</span>.upload = upload;
   }

   <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getUploadContentType</span><span class="hljs-params">()</span> </span>{
      <span class="hljs-keyword">return</span> uploadContentType;
   }

   <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setUploadContentType</span><span class="hljs-params">(String uploadContentType)</span> </span>{
      <span class="hljs-keyword">this</span>.uploadContentType = uploadContentType;
   }

   <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getUploadFileName</span><span class="hljs-params">()</span> </span>{
      <span class="hljs-keyword">return</span> uploadFileName;
   }

   <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setUploadFileName</span><span class="hljs-params">(String uploadFileName)</span> </span>{
      <span class="hljs-keyword">this</span>.uploadFileName = uploadFileName;
   }
}
</code></pre>
<p>The primary upload logic is in <code>UploadAction.java</code>, where we have used a typical File Upload Interceptor-based upload pattern. We specify an <strong>uploads</strong> directory (<code>/webapps/ROOT/uploads/</code>), generate a new file path by appending the <code>uploadFileName</code> (assumed to be safe) to the directory path, and then transfer the temporary file from the Tomcat temp directory to this new location. No sanitization is performed, as we rely on Struts to handle it for us.</p>
<p>The remaining files can be customized as per your needs, however we are focused on only these two important files.</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- web.xml --&gt;</span>

<span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">web-app</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://xmlns.jcp.org/xml/ns/javaee"</span>
         <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">"http://www.w3.org/2001/XMLSchema-instance"</span>
         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">"http://xmlns.jcp.org/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"</span>
         <span class="hljs-attr">version</span>=<span class="hljs-string">"3.1"</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>struts2<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">filter-class</span>&gt;</span>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter<span class="hljs-tag">&lt;/<span class="hljs-name">filter-class</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">filter-mapping</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>struts2<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/*<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter-mapping</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">welcome-file-list</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">welcome-file</span>&gt;</span>index.jsp<span class="hljs-tag">&lt;/<span class="hljs-name">welcome-file</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">welcome-file-list</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">web-app</span>&gt;</span>
</code></pre>
<pre><code class="lang-java"><span class="hljs-comment">// index.jsp</span>

&lt;%@ page contentType=<span class="hljs-string">"text/html; charset=UTF-8"</span> %&gt;
&lt;html&gt;
&lt;body&gt;
    &lt;h1&gt;Upload&lt;/h1&gt;
    &lt;form action=<span class="hljs-string">"upload"</span> method=<span class="hljs-string">"post"</span> enctype=<span class="hljs-string">"multipart/form-data"</span>&gt;
        &lt;label <span class="hljs-keyword">for</span>=<span class="hljs-string">"file"</span>&gt;Select a file:&lt;/label&gt;
        &lt;input type=<span class="hljs-string">"file"</span> name=<span class="hljs-string">"upload"</span> id=<span class="hljs-string">"file"</span> /&gt;
        &lt;br&gt;&lt;br&gt;
        &lt;input type=<span class="hljs-string">"submit"</span> value=<span class="hljs-string">"Upload File"</span> /&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<pre><code class="lang-java"><span class="hljs-comment">// upload.jsp</span>

&lt;%@ page contentType=<span class="hljs-string">"text/html; charset=UTF-8"</span> %&gt;
&lt;%@ taglib prefix=<span class="hljs-string">"s"</span> uri=<span class="hljs-string">"/struts-tags"</span> %&gt;
&lt;html&gt;
&lt;body&gt;
    &lt;h1&gt;Upload Result&lt;/h1&gt;
    &lt;s:property value=<span class="hljs-string">"message"</span> /&gt;
    &lt;br&gt;
    &lt;a href=<span class="hljs-string">"index.jsp"</span>&gt;Back&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>You can find the docker setup and instructions to build and run this at - <a target="_blank" href="https://github.com/0xdeviner/CVE-2024-53677">https://github.com/0xdeviner/CVE-2024-53677</a></p>
<h2 id="heading-exploit">Exploit</h2>
<p>We are all set to exploit this vulnerability as we are ready with our target and have understood the cause.</p>
<p>Let’s try and see if the upload works and we will possibly try to exploit the issue.</p>
<p>We will start with uploading a simple text file trying to obtain a path traversal,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1734959894452/919dacb0-f1b5-48df-8364-02088c0d3b86.png" alt class="image--center mx-auto" /></p>
<p>The file is uploaded, now if we check the logs, we see <code>Dst File name: test.txt</code> which means, our attempt to simple path traversal is stripped and the file is written properly to the upload directory.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Logs</span>
Src File name: /usr/<span class="hljs-built_in">local</span>/tomcat/work/Catalina/localhost/ROOT/upload_9ef5f866_c251_49fb_b593_c63fc63f3b49_00000009.tmp
Dst File name: test.txt

<span class="hljs-comment"># Upload Directory contents</span>
root@c6abf85581ec:/webapps/ROOT/uploads<span class="hljs-comment"># ls</span>
test.txt
</code></pre>
<p>Next, we’ll attempt to clobber <code>top.uploadFileName</code>, the internal OGNL value used by Struts 2 for single-file uploads, as discussed in the <a target="_blank" href="https://y4tacker.github.io/2024/12/16/year/2024/12/Apache-Struts2-%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E9%80%BB%E8%BE%91%E7%BB%95%E8%BF%87-CVE-2024-53677-S2-067/">Y4tacker analysis</a>. Our input aligns with the file upload parameter (referred to as <code>upload</code>) and targets the topmost value in the OGNL value stack. However, we intentionally avoid capitalizing <strong>"upload"</strong> in <strong>"uploadFileName"</strong> to disrupt the upload data handling logic. Due to this inconsistency, this attempt is also expected to fail.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1734960543096/2b4029bb-5b29-4de9-a4c2-507d1f75d4ad.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-bash"><span class="hljs-comment"># Logs</span>
Src File name: /usr/<span class="hljs-built_in">local</span>/tomcat/work/Catalina/localhost/ROOT/upload_9ef5f866_c251_49fb_b593_c63fc63f3b49_00000010.tmp
Dst File name: test1.txt

<span class="hljs-comment"># Upload Directory contents</span>
root@c6abf85581ec:/webapps/ROOT/uploads<span class="hljs-comment"># ls</span>
test1.txt  test.txt
</code></pre>
<p>This attempt failed, the traversal is stripped again.</p>
<p>Now, we will send a Uppercase payload to confuse the parameter binding process and gain control of the <code>top</code> OGNL stack value, as described in the <a target="_blank" href="https://y4tacker.github.io/2024/12/16/year/2024/12/Apache-Struts2-%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E9%80%BB%E8%BE%91%E7%BB%95%E8%BF%87-CVE-2024-53677-S2-067/">Y4tacker analysis</a>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1734960780044/d700b6be-1c38-4d34-9874-facd44cb4923.png" alt class="image--center mx-auto" /></p>
<p>This time, the console logs <code>Dst File name: ../test2.txt</code> and the file traversal results in the file being written in the parent <code>/webapps/ROOT</code> directory.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Logs</span>
Src File name: /usr/<span class="hljs-built_in">local</span>/tomcat/work/Catalina/localhost/ROOT/upload_9ef5f866_c251_49fb_b593_c63fc63f3b49_00000012.tmp
Dst File name: ../test2.txt

<span class="hljs-comment"># Upload Directory contents</span>
root@c6abf85581ec:/webapps/ROOT/uploads<span class="hljs-comment"># ls ../</span>
test2.txt  uploads
</code></pre>
<p>This can be further escalated to RCE further, I am working on the PoC for the time being.</p>
<h2 id="heading-mitigation"><strong>Mitigation</strong></h2>
<p>Updating Struts 2 to &gt;=6.4.0 is not enough to prevent this exploitation as there is no patch issued for the vulnerability (as of December 18, 2024). Apache recommends to use <a target="_blank" href="https://struts.apache.org/core-developers/action-file-upload-interceptor"><strong>Action File Upload Interceptor</strong></a> instead of <strong>File Upload Interceptor.</strong></p>
<h2 id="heading-references">References</h2>
<ul>
<li><p>Security researcher Y4tacker’s <a target="_blank" href="https://y4tacker.github.io/2024/12/16/year/2024/12/Apache-Struts2-%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E9%80%BB%E8%BE%91%E7%BB%95%E8%BF%87-CVE-2024-53677-S2-067/">excellent analysis</a></p>
</li>
<li><p><a target="_blank" href="https://attackerkb.com/topics/YfjepZ70DS/cve-2024-53677">Attackerkb</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/apache/struts/commit/162e29fee9136f4bfd9b2376da2cbf590f9ea163">Commit to CVE-2023-50164</a></p>
</li>
<li><p><a target="_blank" href="https://cwiki.apache.org/confluence/display/WW/S2-067">S2-067</a></p>
</li>
<li><p><a target="_blank" href="https://cwiki.apache.org/confluence/display/WW/S2-066">S2-066</a></p>
</li>
</ul>
<hr />
<p>Thanks for reading, do like and follow for more such content :)</p>
<div class="hn-embed-widget" id="buymeacoffee"></div>]]></content:encoded></item><item><title><![CDATA[CVE-2024-54134 - Solana Web3.js Supply Chain Attack]]></title><description><![CDATA[A supply chain attack was detected in version 1.95.6 and 1.95.7 of the @solana/web3.js npm library. This compromised version contain injected malicious code that can steal keys from developers and users, potentially enabling attackers to drain crypto...]]></description><link>https://blogs.hiteshpatra.in/cve-2024-54134-solana-web3js-supply-chain-attack</link><guid isPermaLink="true">https://blogs.hiteshpatra.in/cve-2024-54134-solana-web3js-supply-chain-attack</guid><category><![CDATA[supplychainattack]]></category><category><![CDATA[Solana]]></category><category><![CDATA[supplychainsecurity]]></category><category><![CDATA[CVE]]></category><category><![CDATA[Security]]></category><category><![CDATA[information security]]></category><category><![CDATA[Web3]]></category><category><![CDATA[Web3 Security]]></category><category><![CDATA[infosec]]></category><category><![CDATA[research]]></category><dc:creator><![CDATA[Hitesh Patra]]></dc:creator><pubDate>Wed, 04 Dec 2024 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1733420407752/d43edc7f-9ff7-46d4-9cac-3db25482f8e4.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A supply chain attack was detected in version <code>1.95.6</code> and <code>1.95.7</code> of the <a target="_blank" href="http://github.com/solana-labs/solana-web3.js">@solana/web3.js</a> npm library. This compromised version contain injected malicious code that can steal keys from developers and users, potentially enabling attackers to drain cryptocurrency wallets.</p>
<p>Solana offers an SDK called "<a target="_blank" href="http://github.com/solana-labs/solana-web3.js">@solana/web3.js</a>" used by decentralized applications (dApps) to connect and interact with the Solana blockchain.</p>
<p>Solana has confirmed the breach with a <a target="_blank" href="https://github.com/solana-labs/solana-web3.js/releases/tag/v1.95.8">fix release</a> and stated,</p>
<blockquote>
<p>Earlier today, a publish-access account was compromised for <code>@solana/web3.js</code>, a JavaScript library that is commonly used by Solana dapps. This allowed an attacker to publish unauthorized and malicious packages that were modified, allowing them to steal private key material and drain funds from dapps, like bots, that handle private keys directly. This issue should not affect non-custodial wallets, as they generally do not expose private keys during transactions. This is not an issue with the Solana protocol itself, but with a specific JavaScript client library and only appears to affect projects that directly handle private keys and that updated within the window of 3:20pm UTC and 8:25pm UTC on Tuesday, December 3, 2024.</p>
<p>These two unauthorized versions (1.95.6 and 1.95.7) were caught within hours and have since been unpublished.</p>
<p>We are asking all Solana app developers to upgrade to version 1.95.8. Developers pinned to <code>latest</code> should also upgrade to 1.95.8.</p>
<p>Developers that suspect they might be compromised should rotate any suspect authority keys, including multisigs, program authorities, server keypairs, and so on.</p>
</blockquote>
<p>The attack was initially identified by <a target="_blank" href="http://socket.dev">socket.dev</a></p>
<p>It has been assigned as <a target="_blank" href="https://nvd.nist.gov/vuln/detail/CVE-2024-54134">CVE-2024-54134</a> with a CVSS 4.0 scored as 8.3 - <strong>High</strong></p>
<p><strong>Vector:</strong> CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N</p>
<h2 id="heading-root-cause-analysis">Root Cause Analysis</h2>
<p>As per <a target="_blank" href="https://bsky.app/profile/did:plc:zwlpsxw2udovqf4mbfi4ibqf/post/3lcgt6l7s4c2a">Christophe Tafani-Dereeper</a>, a researcher @ DataDog on 12/4/2024 - 6:50PM EST mentioned that a function <code>addToQueue</code> is responsible to exfiltrates the private key and transmits them to a hardcoded address <a target="_blank" href="https://sol-rpc.xyz/api/rpc/queue"><code>https://sol-rpc.xyz/api/rpc/queue</code></a>.</p>
<p>npm has currently removed the affected versions, thanks to Christophe Tafani-Dereeper for sharing the sample affected version <a target="_blank" href="https://github.com/DataDog/malicious-software-packages-dataset/blob/main/samples/npm/%40solana%40web3.js/1.95.7/2024-12-03-%40solana_web3.js-v1.95.7.zip">solana_</a><a target="_blank" href="http://web3.js-v1.95.7.zip">web3.js-v1.95.7.zip</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1733393794558/f398479a-2d64-4496-8231-f26a163a7143.png" alt="Malicious addTo-Queue function" class="image--center mx-auto" /></p>
<p>The above code adds a process, represented as a <code>Uint8Array</code>, to a queue after encoding it using Base58 and ensuring it is not already present. It then sends the encoded value to an external hardcoded API endpoint <a target="_blank" href="https://sol-rpc.xyz/api/rpc/queue"><code>https://sol-rpc.xyz/api/rpc/queue</code></a> via a <code>POST</code> request, including custom headers derived from the encoded data.</p>
<p>The headers resemble AWS CloudFront identifiers, potentially raising concerns about misuse or impersonation. Errors during the request are suppressed with an empty <code>.catch()</code> block, making debugging and monitoring difficult.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1733393835689/d55db8e3-1d3d-43d9-8b79-1259179aac67.png" alt class="image--center mx-auto" /></p>
<p>In the above code, calls are made to the function <code>addToQueue</code> in various places to access the private keys.</p>
<p>After further analysis, the malicious function was added to the following locations,</p>
<p><code>fromSecretKey()</code> - Create a keypair from a raw secret key byte array.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1733393869216/b78dacf1-a50f-4514-a167-d5fde5929916.png" alt class="image--center mx-auto" /></p>
<p><code>fromSeed()</code> - Generate a keypair from a 32 byte seed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1733393882079/18aa32a9-d30b-4704-b94a-aea767d08755.png" alt class="image--center mx-auto" /></p>
<p><code>createInstructionWithPrivateKey()</code> &amp; <code>createInstructionWithPublicKey()</code> - Create an ed25519 instruction with a private key and create an ed25519 instruction with a public key and signature, respectively.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1733393914840/57336b66-5c1b-4f00-aa52-0755cfb387a9.png" alt class="image--center mx-auto" /></p>
<p><code>account constructor</code> - Create a new Account object and if the secretKey parameter is not provided a new key pair is randomly created for the account.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1733393923569/aa47bc07-0843-4e6e-ac3f-762cd8dadf52.png" alt class="image--center mx-auto" /></p>
<p>Christophe Tafani-Dereeper also noted that, the hardcoded domain <a target="_blank" href="http://sol-rpc.xyz"><code>sol-rpc.xyz</code></a> was registered on Nov 22, 2024 on <a target="_blank" href="https://www.namesilo.com/">NameSilo</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1733393974473/f6fe9dfa-947b-4936-ba29-e7925943e078.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-potential-impact">Potential Impact</h2>
<p>Developer using the impacted versions of the library might expose their private keys and users of the applications relying on the compromised versions of the library may have their wallets drained if their private keys are compromised.</p>
<p>According to a <a target="_blank" href="https://github.com/advisories/GHSA-2mhj-xmf4-pr8m?trk=public_post_comment-text">GitHub advisory</a>, developers who have installed one of the malicious versions should consider their systems fully compromised and reset all secrets and keys, from a different computer. They have also mentioned that, <strong>there is no guarantee that removing the package will remove all malicious software resulting from installing it.</strong></p>
<p><a target="_blank" href="https://socket.dev/blog/supply-chain-attack-solana-web3-js-library#Impact-of-the-Supply-Chain-Attack">Socket</a> also mentioned, "At 6:12PM on December 3, Anza, a Solana focused research and development firm, disclosed that a publish-access account was compromised, allowing the threat actor to steal private key material and drain funds from dapps, like bots, that handle private keys directly.</p>
<p>Anza clarified that the attack should not affect non-custodial wallets, because they don't expose private keys during transactions."</p>
<p><a target="_blank" href="https://x.com/0xMert_">Mert Mumtaz</a>, CEO of <a target="_blank" href="https://www.helius.dev/">Helius Labs</a> later in a tweet mentioned, "<strong><em>this is a javascript client library, meaning it has nothing to do with the security of the blockchain itself</em></strong>"</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/0xMert_/status/1864069157257613719">https://twitter.com/0xMert_/status/1864069157257613719</a></div>
<p> </p>
<h2 id="heading-mitigation">Mitigation</h2>
<p>To address the compromise in the <code>@solana/web3.js</code> library, developers should audit their projects to identify if versions 1.95.6 or 1.95.7 are in use. If affected, they should either downgrade to a safe version prior to 1.95.6 or update to version 1.95.8, which removes the malicious code. It's essential to manually inspect the <code>node_modules</code> directory and dependency trees for suspicious modifications. Additionally, compromised keys should be regenerated, and permissions revoked as necessary to secure affected systems.</p>
<hr />
<p>Thanks for reading, do like and follow for more such content :)</p>
<div class="hn-embed-widget" id="buymeacoffee"></div>]]></content:encoded></item></channel></rss>