# Path: lib/out.py
# def windows_out(color, msg):
# def good(msg):
# def warning(msg):
# def error(msg):
# def jump(url):
# def alert(content, url):
#     STD_OUTPUT_HANDLE = -11
# 
# Path: lib/config.py
# def load():
# def update(conf):
# def load_rule():
# def update_rule(rule):
# def rule_read(name, get_file_handle=None):
# def rule_write(name, rule):
# 
# Path: lib/redisopt.py
# def get_hash(host, uri, postdata):
# def content_deal(headers, host, method, postdata, uri, packet):


import re
import json
import time
import base64
import requests
import urlparse
import threading
from xml.dom import minidom
from base64 import decodestring as ds
from lib import out
from lib import config
from lib.redisopt import conn
    dom = minidom.parse(config.rule_read("sqlibool", get_file_handle=True)).documentElement
    for node in dom.getElementsByTagName('couple'):
        couple_id = int(node.getAttribute("id"))
        if couple_id <= config_level:
            for compare in node.getElementsByTagName("compare"):
                compare1 = compare.getElementsByTagName("compare1")[0].childNodes[0].nodeValue
                compare11 = compare.getElementsByTagName("compare11")[0].childNodes[0].nodeValue
                compare2 = compare.getElementsByTagName("compare2")[0].childNodes[0].nodeValue
                compare22 = compare.getElementsByTagName("compare22")[0].childNodes[0].nodeValue
                for param_name in urlparse.urlparse(request['url']).query.split("&"):
                    response1 = request_payload(request, compare1, param_name)
                    response2 = request_payload(request, compare2, param_name)
                    response22 = request_payload(request, compare22, param_name)
                    time.sleep(1)#prevent time stamp in response
                    response11 = request_payload(request, compare11, param_name)
                    if response1 == response11 and response2 == response22 and response1 != response2:
                        message['request_stat'] = 2
                        message['message'] += "payload1: %s|#|payload2: %s|#|param: %s|,|" % (compare1.encode('utf-8'), compare2.encode('utf-8'), param_name.split("=")[0])
                        if config.load()['only_one_match'].lower() == "true":
                            return message
                for param_name in request['postdata'].split("&"):
                    if request['postdata'] == "":
                        break
                    response1 = request_payload(request, compare1, param_name, postdata=True)
                    response11 = request_payload(request, compare11, param_name, postdata=True)
                    response2 = request_payload(request, compare2, param_name, postdata=True)
                    response22 = request_payload(request, compare22, param_name, postdata=True)
                    if response1 == response11 and response2 == response22 and response1 != response2:
                        message['request_stat'] = 2
                        message['message'] += "payload1: %s|#|payload2: %s|#|param: %s|,|" % (compare1.encode('utf-8'), compare2.encode('utf-8'), param_name.split("=")[0])

# Path: lib/out.py
# def windows_out(color, msg):
# def good(msg):
# def warning(msg):
# def error(msg):
# def jump(url):
# def alert(content, url):
#     STD_OUTPUT_HANDLE = -11
# 
# Path: lib/config.py
# def load():
# def update(conf):
# def load_rule():
# def update_rule(rule):
# def rule_read(name, get_file_handle=None):
# def rule_write(name, rule):
# 
# Path: lib/redisopt.py
# def get_hash(host, uri, postdata):
# def content_deal(headers, host, method, postdata, uri, packet):


# Path: lib/scan.py
import re
import json
import time
import base64
import requests
import urlparse
import threading
from xml.dom import minidom
from base64 import decodestring as ds
from lib import out
from lib import config
from lib.redisopt import conn

    dom = minidom.parse(config.rule_read("sqlibool", get_file_handle=True)).documentElement
    for node in dom.getElementsByTagName('couple'):
        couple_id = int(node.getAttribute("id"))
        if couple_id <= config_level:
            for compare in node.getElementsByTagName("compare"):
                compare1 = compare.getElementsByTagName("compare1")[0].childNodes[0].nodeValue
                compare11 = compare.getElementsByTagName("compare11")[0].childNodes[0].nodeValue
                compare2 = compare.getElementsByTagName("compare2")[0].childNodes[0].nodeValue
                compare22 = compare.getElementsByTagName("compare22")[0].childNodes[0].nodeValue
                for param_name in urlparse.urlparse(request['url']).query.split("&"):
                    response1 = request_payload(request, compare1, param_name)
                    response2 = request_payload(request, compare2, param_name)
                    response22 = request_payload(request, compare22, param_name)
                    time.sleep(1)#prevent time stamp in response
                    response11 = request_payload(request, compare11, param_name)
                    if response1 == response11 and response2 == response22 and response1 != response2:
                        message['request_stat'] = 2
                        message['message'] += "payload1: %s|#|payload2: %s|#|param: %s|,|" % (compare1.encode('utf-8'), compare2.encode('utf-8'), param_name.split("=")[0])
                        if config.load()['only_one_match'].lower() == "true":
                            return message
                for param_name in request['postdata'].split("&"):
                    if request['postdata'] == "":
                        break
                    response1 = request_payload(request, compare1, param_name, postdata=True)
                    response11 = request_payload(request, compare11, param_name, postdata=True)
                    response2 = request_payload(request, compare2, param_name, postdata=True)
                    response22 = request_payload(request, compare22, param_name, postdata=True)
                    if response1 == response11 and response2 == response22 and response1 != response2:
                        message['request_stat'] = 2
                        message['message'] += "payload1: %s|#|payload2: %s|#|param: %s|,|" % (compare1.encode('utf-8'), compare2.encode('utf-8'), param_name.split("=")[0])

                        if config.load()['only_one_match'].lower() == "true":