People often ask me "How did you learn how to hack?" The answer: by reading. This page is a collection of the blog posts and other articles that I have accumulated over the years of my journey. Enjoy!
connection.query( "SELECT * FROM accounts WHERE username = ? AND password = ?", [username, password], func...)Normally, we would expect a string (like 'admin') as the input for the
username and password fields. If the query is setup insecurely, we may be able to put arbitrary objects into these fields. I would call this an unintended use case. 1 will evaluate to true within MySQL. With the query above, sending object like below will bypass the logic:
data = {
username: "admin",
password: {
password: 1,
},
};
format can be found. The logic of this is as follows:
objectToValues works by getting the value of each key in the object then running the escape code on each KEY and VALUE. Once done, it sets the SQL to be `<key>` = <value> in the SQL. The backticks are used for literal SQL statements, such as the username column. Interesting and this is NOT how this should work. ...`password = password` = 1. For whatever reason, ...`password = password` = 1 will evaluate to true (tested locally in MySQL repl), allowing any user to authenticate as that user. Wow, what a crazy chain of events that makes this work!