예제 #1
0
def request(flow):
    # pretty_host takes the "Host" header of the request into account,
    # which is useful in transparent mode where we usually only have the IP
    # otherwise.

    # Method 1: Answer with a locally generated response
    if flow.request.pretty_host.endswith("example.com"):
        resp = HTTPResponse.make(200, b"Hello World", {"Content-Type": "text/html"})
        flow.reply.send(resp)

    # Method 2: Redirect the request to a different server
    if flow.request.pretty_host.endswith("example.org"):
        flow.request.host = "mitmproxy.org"
예제 #2
0
def request(flow):
    # pretty_host takes the "Host" header of the request into account,
    # which is useful in transparent mode where we usually only have the IP
    # otherwise.

    # Method 1: Answer with a locally generated response
    if flow.request.pretty_host.endswith("example.com"):
        flow.response = HTTPResponse.make(200, b"Hello World",
                                          {"Content-Type": "text/html"})

    # Method 2: Redirect the request to a different server
    if flow.request.pretty_host.endswith("example.org"):
        flow.request.host = "mitmproxy.org"
예제 #3
0
def requests2mitmproxy(resp):
    # We first remove some troublesome headers

    # Content is automatically decoded
    if "Content-Encoding" in resp.headers: del resp.headers["Content-Encoding"]

    # Remove clickjacking protections
    if "X-Frame-Options" in resp.headers: del resp.headers["X-Frame-Options"]

    # Ensure that cookies can be sent over HTTP
    if "Set-Cookie" in resp.headers:
        resp.headers["Set-Cookie"] = resp.headers["Set-Cookie"].replace(
            " Secure;", " ")
        resp.headers["Set-Cookie"] = resp.headers["Set-Cookie"].replace(
            " Secure", " ")

    h = list(resp.headers.items())
    headers = []
    for i in h:
        headers.append((i[0].encode(), i[1].encode()))

    r = HTTPResponse.make(200, stripHttpsLinks(resp.content), headers)
    return r
예제 #4
0
    def request(self, flow):
        # This will often cause problems later, so we just remove it
        if "Accept-Encoding" in flow.request.headers:
            del flow.request.headers["Accept-Encoding"]

        ll = common.bcpConfig.foundMatch(flow.request.headers["host"],
                                         flow.request.path, "inject", True)
        ll2 = common.bcpConfig.foundMatch(flow.request.headers["host"],
                                          flow.request.path, "serve", False)

        # Can only be one response, if multiple we take the first
        res = None
        if len(ll) > 0:
            res = ll[0]
        if len(ll2) > 0:
            res = ll2[0]

        if res != None:
            r = HTTPResponse.make(200, "",
                                  common.list2headers(res.get("headers", [])))
            r.raw_content = res.get("data").encode()
            flow.response = r
        return