Introduction
Imagine someone sneaking harmful commands into a conversation between your computer and a database. This problem happens when attackers send tricky messages over a network to make a database do things it shouldn't.
Imagine sending a letter to a bank asking for your account balance. If someone sneaks extra instructions into your letter, the bank might accidentally give away your money or personal info. The mail system is like the network carrying your message.
┌───────────────┐ Network ┌───────────────┐
│ User Input │────────────────────▶│ Database Server│
│ (Potentially │ │ (Executes │
│ Malicious) │ │ Queries) │
└───────────────┘ └───────────────┘
▲ │
│ │
└───────────── Malicious SQL Injection ──────────────▶SELECT * FROM users WHERE username = '' OR '1'='1';. What is the likely result?username = '' OR '1'='1' means either username is empty or '1' equals '1'. Since '1'='1' is always true, the whole condition is true for all rows."SELECT * FROM users WHERE id = " + user_input; sent over network. What is the main problem?SELECT * FROM accounts WHERE user = 'admin'--' AND password = 'anything'; What does the -- do in this SQL injection attempt?-- in SQL-- sequence starts a comment in SQL, ignoring everything after it on the same line.-- = comment to skip code [OK]Pass the test and this pattern moves unknown