SQL Injection
SQL Injection
is a cyberattack that injects malicious SQL code into an application, allowing the attacker to view or
modify a database.
Exposes Sensitive Company Data: Using SQL injection, attackers can retrieve and alter data, which risks
exposing sensitive company data stored on the SQL server.
Compromise Users’ Privacy: Depending on the data stored on the SQL server, an attack can expose
private user data, such as credit card numbers.
Give an attacker administrative access to your system: If a database user has administrative privileges,
an attacker can gain access to the system using malicious code. To protect against this kind of
vulnerability, create a database user with the least possible privileges.
Give an Attacker General Access to Your System: If you use weak SQL commands to check user names
and passwords, an attacker could gain access to your system without knowing a user’s credentials. With
general access to your system, an attacker can cause additional damage accessing and manipulating
sensitive information.
Compromise the Integrity of Your Data: Using SQL injection, attackers can make changes to or delete
information from your system.
Error-based SQL injection: With this technique, attackers gain information about the database
structure when they use a SQL command to generate an error message from the database server. Error
messages are useful when developing a web application or web page, but they can be a vulnerability
later because they expose information about the database. To prevent this vulnerability, you can disable
error messages after a website or application is live.
Boolean injection: With this technique, attackers send a SQL query to the database and observe the
result. Attackers can infer if a result is true or false based on whether the information in the HTTP
response was modified.
Time-based injection: With this technique, attackers send a SQL query to the database, making the
database wait a specific number of seconds before responding. Attackers can determine if the result is
true or false based on the number of seconds that elapses before a response. For example, a hacker
could use a SQL query that commands a delay if the first letter of the first database’s name is A. Then, if
the response is delayed, the attacker knows the query is true.
3.Input Validation
Validating input plays a significant role in preventing SQL injection. Suspicious inputs are filtered
prior to submission or processing by the server when validated. An example of input validation
is an email validator. There are two types of validation: server side and client side.
''
``
"
""
//
\\
' or "
-- or #
' OR '1
' OR 1 -- -
" OR 1 = 1 -- -
'='
'LIKE'
'=0--+
OR 1=1
' OR 'x'='x
%00
/*…*/
AND 1
AND 0
AND true
AND false
1-false
1-true
1*56
-2
' and 1 in (select min(name) from sysobjects where xtype = 'U' and name > '.') --
Time-Based:
%2c(select%20*%20from%20(select(sleep(10)))a)
Comments:
# Hash comment
/* C-style comment
-- - SQL comment
;%00 Nullbyte
` Backtick