# Path: lib/redisopt.py
# def get_hash(host, uri, postdata):
# def content_deal(headers, host, method, postdata, uri, packet):
# 
# Path: lib/out.py
# def error(msg):
#     if "Windows" not in platform.platform():
#         color = '\033[01;31m'
#         endc = '\033[0m'
#         print "[*] " + color + msg + endc
#     else:
#         windows_out(0x0c, "[+] %s" % msg)
# 
# 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):


import re
import logging
from scapy.all import *
from lib.redisopt import conn, content_deal
from lib.out import error
from lib import config
    except Exception, e:
        if 'url' in dir() and "method" in dir():
            print "%s   %s" % (method, uri)
        print "Http Error: " + str(e)


def print_request(method, host, url):
    print "%s   %s%s" % (method, host, url)


def capture(x):
    out = config.load()['scapy_out'].lower()
    if config.load()['scapy_stat'].lower() == 'false':
        raise Exception('scapy', 'out')
    if 'HTTP/' in x.lastlayer().original and x.lastlayer().original[0:4] != 'HTTP':
        body = x.lastlayer().original
        http = extract(body, out)


def main():
    NIC = config.load()["scapy_network_card"]  # network adapter name
    try:
        if NIC == 'all':
            sniff(filter="tcp", prn=lambda x: capture(x))
        else:
            sniff(iface=NIC, filter="tcp", prn=lambda x: capture(x))
    except Exception as e:
        error("scapy out!")
        conf = config.load()
        conf['scapy_stat'] = "false"

# Path: lib/redisopt.py
# def get_hash(host, uri, postdata):
# def content_deal(headers, host, method, postdata, uri, packet):
# 
# Path: lib/out.py
# def error(msg):
#     if "Windows" not in platform.platform():
#         color = '\033[01;31m'
#         endc = '\033[0m'
#         print "[*] " + color + msg + endc
#     else:
#         windows_out(0x0c, "[+] %s" % msg)
# 
# 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: proxy/pyscapy.py
import re
import logging
from scapy.all import *
from lib.redisopt import conn, content_deal
from lib.out import error
from lib import config

    except Exception, e:
        if 'url' in dir() and "method" in dir():
            print "%s   %s" % (method, uri)
        print "Http Error: " + str(e)


def print_request(method, host, url):
    print "%s   %s%s" % (method, host, url)


def capture(x):
    out = config.load()['scapy_out'].lower()
    if config.load()['scapy_stat'].lower() == 'false':
        raise Exception('scapy', 'out')
    if 'HTTP/' in x.lastlayer().original and x.lastlayer().original[0:4] != 'HTTP':
        body = x.lastlayer().original
        http = extract(body, out)


def main():
    NIC = config.load()["scapy_network_card"]  # network adapter name
    try:
        if NIC == 'all':
            sniff(filter="tcp", prn=lambda x: capture(x))
        else:
            sniff(iface=NIC, filter="tcp", prn=lambda x: capture(x))
    except Exception as e:
        error("scapy out!")
        conf = config.load()
        conf['scapy_stat'] = "false"

        config.update(conf)