예제 #1
0
def response(flow: http.HTTPFlow) -> None:
    """Mock response

    If URL corresponds to router.yaml, use matched json file as response
    Link url and json file in router.yaml

    Arg:
        flow: http flow, from mitm
    """

    routers = utils.readFile(ROUTER_FILE)
    url = flow.request.url

    if routers is not None:
        for patternURL, jsonfilename in routers.items():
            if re.match(patternURL, url) is not None:
                jsonfile = DATA_DIR + str(jsonfilename) + '.json'
                ctx.log.info(url + ' found. Send data from "' + jsonfile + '"')

                data = utils.readFile(jsonfile)

                if data is not None:
                    status = int(data['status'])
                    try:
                        content = json.dumps(data['content'])
                    except:
                        content = ''
                    header = data['header']

                    flow.response = http.HTTPResponse.make(status, content, header)
예제 #2
0
def response(flow: http.HTTPFlow) -> None:
    """Mock response

    If URL corresponds to router.yaml, use matched yaml file with replacement strings
    Link url and yaml file in router.yaml

    Arg:
        flow: http flow, from mitm
    """

    routers = utils.readFile(ROUTER_FILE)
    url = flow.request.url

    if routers is not None:
        for patternURL, yamlfilename in routers.items():
            if re.match(patternURL, url) is not None:
                yamlfile = DATA_DIR + str(yamlfilename) + '.yaml'
                ctx.log.info(url + ' found. Replace strings from "' +
                             yamlfile + '"')

                data = utils.readFile(yamlfile)
                ctx.log.info(data)

                if data is not None:
                    for old, new in data.items():
                        flow.response.content = flow.response.content.replace(
                            bytes(old.encode('utf8')),
                            bytes(new.encode('utf8')))
예제 #3
0
def response(flow: http.HTTPFlow) -> None:
    routers = utils.readFile(ROUTER_FILE)
    url = flow.request.url

    if routers is not None:
        for patternURL, yamlfilename in routers.items():
            if re.match(patternURL, url) is not None:
                yamlfile = DATA_DIR + str(yamlfilename) + '.yaml'
                ctx.log.info('>>> FOUND "' + url + '" to replace strings from "' + yamlfile + '"')

                data = utils.readFile(yamlfile)
                ctx.log.info(data)

                if data is not None:
                    for old, new in data.items():
                        flow.response.content = flow.response.content.replace(bytes(old.encode('utf8')), bytes(new.encode('utf8')))
예제 #4
0
def request(flow: http.HTTPFlow) -> None:
    """Show matched analytics keyword and value

    Arg:
        flow: http flow, from mitm
    """

    check_data(flow.request.url, utils.readFile(DATA_FILE), flow)
def request(flow: http.HTTPFlow) -> None:
    routers = utils.readFile(ROUTER_FILE)
    url = flow.request.url

    if routers is not None:
        for patternURL, redirectURL in routers.items():
            if re.match(patternURL, url) is not None:
                ctx.log.alert(url + '>>> FOUND url "' + url + '" to redircet: ' + redirectURL)
                flow.request.url = redirectURL
예제 #6
0
def request(flow: http.HTTPFlow) -> None:
    routers = utils.readFile(ROUTER_FILE)
    url = flow.request.url
    ctx.log.info(url)

    if routers is not None:
        for patternURL, jsonfilename in routers.items():
            if re.match(patternURL, url) is not None:
                jsonfile = DATA_DIR + str(jsonfilename) + '.json'
                data = utils.readFile(jsonfile)
                if data is not None:
                    status = int(data['status'])
                    try:
                        content = json.dumps(data['content'])
                    except:
                        content = ''
                    header = data['header']
                    flow.response = http.HTTPResponse.make(
                        status, content, header)
예제 #7
0
def request(flow: http.HTTPFlow) -> None:
    config = utils.readFile(CONFIG_FILE)
    method = flow.request.method
    url = flow.request.url

    if config is not None:
        for matchMethod in config:
            if matchMethod == method:
                for patternURL in config[matchMethod]:
                    if re.match(patternURL, url) is not None:
                        ctx.log.warn('>>> FOUND request to kill: ' + method +
                                     ' ' + url)
                        flow.kill()
예제 #8
0
def request(flow: http.HTTPFlow) -> None:
    matches = utils.readFile(CONFIG_FILE)
    url = flow.request.url

    if matches is not None:
        for patternURL, dumpFolder in matches.items():
            if not os.path.exists(dumpFolder):
                os.makedirs(dumpFolder)

            if re.match(patternURL, url) is not None:
                dumpFile = dumpFolder + '/' + str(int(round(time.time() * 1000)))
                ctx.log.info('Dump ' + url + ' to ' + dumpFile)
                ctx.master.commands.call("export.file", 'curl', flow, dumpFile)
def searchHeaders(flow, config, state):
    config = utils.readFile(config)
    url = flow.request.url

    if config is not None:
        for patternURL, headers in config.items():
            if re.match(patternURL, url) is not None:

                if state == 'request':
                    items = flow.request.headers.items()
                else:
                    items = flow.response.headers.items()

                ctx.log.warn('>> FOUND ' + state + ' header in: ' + url)
                for k, v in items:
                    if k.lower() in [x.lower() for x in headers]:
                        ctx.log.warn('-> ' + str(k) + ': ' + str(v))
예제 #10
0
def request(flow: http.HTTPFlow) -> None:
    """Mock request

    If URL corresponds to redirect-router.yaml, it will be redirected to other URL defined in redirect-router.yaml

    Arg:
        flow: http flow, from mitm
    """

    routers = utils.readFile(ROUTER_FILE)
    url = flow.request.url

    if routers is not None:
        for patternURL, redirectURL in routers.items():
            if re.match(patternURL, url) is not None:
                ctx.log.alert(url + ' found. Redirect whole url to "' + redirectURL + '"')
                flow.request.url = redirectURL
예제 #11
0
def response(flow: http.HTTPFlow) -> None:
    matches = utils.readFile(CONFIG_FILE)
    url = flow.request.url

    if matches is not None:
        for patternURL, dumpFolder in matches.items():
            if not os.path.exists(dumpFolder):
                os.makedirs(dumpFolder)

            if re.match(patternURL, url) is not None:
                dumpFile = dumpFolder + '/' + str(int(round(time.time() * 1000)))

                ctx.log.info('Save ' + url + ' request details to ' + dumpFile)
                with open(dumpFile, 'a') as f:
                    f.write(str(flow.request.method) + ' ' + str(flow.request.url) + '\n')
                    for k, v in flow.request.headers.items():
                        f.write(str(k) + ': ' + str(v) + '\n')
                    f.write('\n' + str(flow.request.content.decode('utf-8')) + '\n')
                    f.write('---\n')
                    for k, v in flow.response.headers.items():
                        f.write(str(k) + ': ' + str(v) + '\n')
                    f.write('\n' + str(flow.response.content.decode('utf-8')) + '\n')
def request(flow: http.HTTPFlow) -> None:
    check_data(flow.request.url, utils.readFile(DATA_FILE), flow)