I'm trying an SQLi attack.
The compiler executes the following query despite warnings:
select * from users where username='A' or 'B' and password='C';
Because the query executes, the attack is successful. Why does this query works and what is it doing? Can I assume that the value 'B' is taken as 'True' in the boolean sense? How do the logical operators work with each other? Is there any specific order like BODMAS for mathematics? Note that 'B' is standalone and not a boolean condition.
A query of the above format works fine in mysql database and returns the same result as the query:
select * from users where username='A';
No syantax errors are returned.
mysql> select * from authentication where user='A' or 'B' and password='C';
+------+----------+
| user | password |
+------+----------+
| A | B |
+------+----------+
1 row in set, 1 warning (0.00 sec)
The warning is as follows:
mysql> show warnings;
+---------+------+----------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: 'B' |
+---------+------+----------------------------------------+
1 row in set (0.00 sec)