Exemplo n.º 1
0
def filter_prune(line):
    """
    Delete all out of context requests from the data file. 
    CANNOT BE UNDONE!! Be careful!
    Usage: filter_prune
    """
    # Delete filtered items from datafile
    print ""
    print "Currently active filters:"
    for f in pappyproxy.pappy.main_context.active_filters:
        print "> %s" % f.filter_string

    # We copy so that we're not removing items from a set we're iterating over
    act_reqs = yield pappyproxy.pappy.main_context.get_reqs()
    inact_reqs = Request.cache.all_ids.difference(set(act_reqs))
    inact_reqs = inact_reqs.difference(set(Request.cache.unmangled_ids))
    message = "This will delete %d/%d requests. You can NOT undo this!! Continue?" % (
        len(inact_reqs),
        (len(inact_reqs) + len(act_reqs)),
    )
    if not confirm(message, "n"):
        defer.returnValue(None)

    for reqid in inact_reqs:
        try:
            req = yield pappyproxy.http.Request.load_request(reqid)
            yield req.deep_delete()
        except PappyException as e:
            print e
    print "Deleted %d requests" % len(inact_reqs)
    defer.returnValue(None)
Exemplo n.º 2
0
def submit(line):
    """
    Resubmit some requests, optionally with modified headers and cookies.

    Usage: submit reqids [-h] [-m] [-u] [-p] [-o REQID] [-c [COOKIES [COOKIES ...]]] [-d [HEADERS [HEADERS ...]]]
    """
    
    parser = argparse.ArgumentParser(prog="submit", usage=submit.__doc__)
    parser.add_argument('reqids')
    parser.add_argument('-m', '--inmem', action='store_true', help='Store resubmitted requests in memory without storing them in the data file')
    parser.add_argument('-u', '--unique', action='store_true', help='Only resubmit one request per endpoint (different URL parameters are different endpoints)')
    parser.add_argument('-p', '--uniquepath', action='store_true', help='Only resubmit one request per endpoint (ignoring URL parameters)')
    parser.add_argument('-c', '--cookies', nargs='*', help='Apply a cookie to requests before submitting')
    parser.add_argument('-d', '--headers', nargs='*', help='Apply a header to requests before submitting')
    parser.add_argument('-o', '--copycookies', help='Copy the cookies used in another request')
    args = parser.parse_args(shlex.split(line))

    headers = {}
    cookies = {}
    clear_cookies = False

    if args.headers:
        for h in args.headers:
            k, v = h.split('=', 1)
            headers[k] = v

    if args.copycookies:
        reqid = args.copycookies
        req = yield Request.load_request(reqid)
        clear_cookies = True
        for k, v in req.cookies.all_pairs():
            cookies[k] = v

    if args.cookies:
        for c in args.cookies:
            k, v = c.split('=', 1)
            cookies[k] = v

    if args.unique and args.uniquepath:
        raise PappyException('Both -u and -p cannot be given as arguments')

    newsession = Session(cookie_vals=cookies, header_vals=headers)
    
    reqs = yield load_reqlist(args.reqids)

    for req in reqs:
        if clear_cookies:
            req.cookies.clear()
        newsession.apply_req(req)

    conf_message = "You're about to submit %d requests, continue?" % len(reqs)
    if not confirm(conf_message):
        defer.returnValue(None)

    for r in reqs:
        r.tags.add('resubmitted')

    save = not args.inmem
    yield async_submit_requests(reqs, save=save, save_in_mem=args.inmem,
        unique_paths=args.uniquepath, unique_path_and_args=args.unique)
Exemplo n.º 3
0
def filter_prune(line):
    """
    Delete all out of context requests from the data file. 
    CANNOT BE UNDONE!! Be careful!
    Usage: filter_prune
    """
    # Delete filtered items from datafile
    print ''
    print 'Currently active filters:'
    for f in pappyproxy.pappy.main_context.active_filters:
        print '> %s' % f.filter_string

    # We copy so that we're not removing items from a set we're iterating over
    act_reqs = yield pappyproxy.pappy.main_context.get_reqs()
    inact_reqs = set(Request.cache.req_ids()).difference(set(act_reqs))
    message = 'This will delete %d/%d requests. You can NOT undo this!! Continue?' % (
        len(inact_reqs), (len(inact_reqs) + len(act_reqs)))
    #print message
    if not confirm(message, 'n'):
        defer.returnValue(None)

    for reqid in inact_reqs:
        try:
            req = yield pappyproxy.http.Request.load_request(reqid)
            yield req.deep_delete()
        except PappyException as e:
            print e
    print 'Deleted %d requests' % len(inact_reqs)
    defer.returnValue(None)
Exemplo n.º 4
0
def gencerts(line):
    """
    Generate CA cert and private CA file
    Usage: gencerts [/path/to/put/certs/in]
    """
    dest_dir = line or pappyproxy.pappy.session.config.cert_dir
    message = "This will overwrite any existing certs in %s. Are you sure?" % dest_dir
    if not confirm(message, 'n'):
        return False
    print "Generating certs to %s" % dest_dir
    pappyproxy.proxy.generate_ca_certs(dest_dir)
Exemplo n.º 5
0
def gencerts(line):
    """
    Generate CA cert and private CA file
    Usage: gencerts [/path/to/put/certs/in]
    """
    dest_dir = line or pappyproxy.pappy.session.config.cert_dir
    message = "This will overwrite any existing certs in %s. Are you sure?" % dest_dir
    if not confirm(message, 'n'):
        return False
    print "Generating certs to %s" % dest_dir
    pappyproxy.proxy.generate_ca_certs(dest_dir)
Exemplo n.º 6
0
def submit(line):
    """
    Resubmit some requests, optionally with modified headers and cookies.

    Usage: submit reqids [-h] [-m] [-u] [-p] [-c [COOKIES [COOKIES ...]]] [-d [HEADERS [HEADERS ...]]]
    """
    
    parser = argparse.ArgumentParser(prog="submit", usage=submit.__doc__)
    parser.add_argument('reqids')
    parser.add_argument('-m', '--inmem', action='store_true', help='Store resubmitted requests in memory without storing them in the data file')
    parser.add_argument('-u', '--unique', action='store_true', help='Only resubmit one request per endpoint (different URL parameters are different endpoints)')
    parser.add_argument('-p', '--uniquepath', action='store_true', help='Only resubmit one request per endpoint (ignoring URL parameters)')
    parser.add_argument('-c', '--cookies', nargs='*', help='Apply a cookie to requests before submitting')
    parser.add_argument('-d', '--headers', nargs='*', help='Apply a header to requests before submitting')
    args = parser.parse_args(shlex.split(line))

    headers = {}
    cookies = {}

    if args.headers:
        for h in args.headers:
            k, v = h.split('=', 1)
            headers[k] = v

    if args.cookies:
        for c in args.cookies:
            k, v = c.split('=', 1)
            cookies[k] = v

    if args.unique and args.uniquepath:
        raise PappyException('Both -u and -p cannot be given as arguments')

    newsession = Session(cookie_vals=cookies, header_vals=headers)
    
    reqs = yield load_reqlist(args.reqids)

    if args.unique or args.uniquepath:
        endpoints = set()
        new_reqs = []
        for r in reqs:
            if args.unique:
                s = r.url
            else:
                s = r.path

            if not s in endpoints:
                new_reqs.append(r.copy())
                endpoints.add(s)
        reqs = new_reqs
    else:
        reqs = [r.copy() for r in reqs]

    for req in reqs:
        newsession.apply_req(req)

    conf_message = "You're about to submit %d requests, continue?" % len(reqs)
    if not confirm(conf_message):
        defer.returnValue(None)

    for r in reqs:
        r.tags.add('resubmitted')

    if args.inmem:
        yield async_submit_requests(reqs)
        for req in reqs:
            add_to_history(req)
    else:
        yield async_submit_requests(reqs, save=True)
Exemplo n.º 7
0
def submit(line):
    """
    Resubmit some requests, optionally with modified headers and cookies.

    Usage: submit reqids [-h] [-m] [-u] [-p] [-c [COOKIES [COOKIES ...]]] [-d [HEADERS [HEADERS ...]]]
    """

    parser = argparse.ArgumentParser(prog="submit", usage=submit.__doc__)
    parser.add_argument('reqids')
    parser.add_argument(
        '-m',
        '--inmem',
        action='store_true',
        help=
        'Store resubmitted requests in memory without storing them in the data file'
    )
    parser.add_argument(
        '-u',
        '--unique',
        action='store_true',
        help=
        'Only resubmit one request per endpoint (different URL parameters are different endpoints)'
    )
    parser.add_argument(
        '-p',
        '--uniquepath',
        action='store_true',
        help='Only resubmit one request per endpoint (ignoring URL parameters)'
    )
    parser.add_argument('-c',
                        '--cookies',
                        nargs='*',
                        help='Apply a cookie to requests before submitting')
    parser.add_argument('-d',
                        '--headers',
                        nargs='*',
                        help='Apply a header to requests before submitting')
    args = parser.parse_args(shlex.split(line))

    headers = {}
    cookies = {}

    if args.headers:
        for h in args.headers:
            k, v = h.split('=', 1)
            headers[k] = v

    if args.cookies:
        for c in args.cookies:
            k, v = c.split('=', 1)
            cookies[k] = v

    if args.unique and args.uniquepath:
        raise PappyException('Both -u and -p cannot be given as arguments')

    newsession = Session(cookie_vals=cookies, header_vals=headers)

    reqs = yield load_reqlist(args.reqids)

    if args.unique or args.uniquepath:
        endpoints = set()
        new_reqs = []
        for r in reqs:
            if args.unique:
                s = r.url
            else:
                s = r.path

            if not s in endpoints:
                new_reqs.append(r.copy())
                endpoints.add(s)
        reqs = new_reqs
    else:
        reqs = [r.copy() for r in reqs]

    for req in reqs:
        newsession.apply_req(req)

    conf_message = "You're about to submit %d requests, continue?" % len(reqs)
    if not confirm(conf_message):
        defer.returnValue(None)

    for r in reqs:
        r.tags.add('resubmitted')

    if args.inmem:
        yield async_submit_requests(reqs)
        for req in reqs:
            add_to_history(req)
    else:
        yield async_submit_requests(reqs, save=True)
Exemplo n.º 8
0
def submit(line):
    """
    Resubmit some requests, optionally with modified headers and cookies.

    Usage: submit reqids [-h] [-m] [-u] [-p] [-o REQID] [-c [COOKIES [COOKIES ...]]] [-d [HEADERS [HEADERS ...]]]
    """

    parser = argparse.ArgumentParser(prog="submit", usage=submit.__doc__)
    parser.add_argument('reqids')
    parser.add_argument(
        '-m',
        '--inmem',
        action='store_true',
        help=
        'Store resubmitted requests in memory without storing them in the data file'
    )
    parser.add_argument(
        '-u',
        '--unique',
        action='store_true',
        help=
        'Only resubmit one request per endpoint (different URL parameters are different endpoints)'
    )
    parser.add_argument(
        '-p',
        '--uniquepath',
        action='store_true',
        help='Only resubmit one request per endpoint (ignoring URL parameters)'
    )
    parser.add_argument('-c',
                        '--cookies',
                        nargs='*',
                        help='Apply a cookie to requests before submitting')
    parser.add_argument('-d',
                        '--headers',
                        nargs='*',
                        help='Apply a header to requests before submitting')
    parser.add_argument('-o',
                        '--copycookies',
                        help='Copy the cookies used in another request')
    args = parser.parse_args(shlex.split(line))

    headers = {}
    cookies = {}
    clear_cookies = False

    if args.headers:
        for h in args.headers:
            k, v = h.split('=', 1)
            headers[k] = v

    if args.copycookies:
        reqid = args.copycookies
        req = yield Request.load_request(reqid)
        clear_cookies = True
        for k, v in req.cookies.all_pairs():
            cookies[k] = v

    if args.cookies:
        for c in args.cookies:
            k, v = c.split('=', 1)
            cookies[k] = v

    if args.unique and args.uniquepath:
        raise PappyException('Both -u and -p cannot be given as arguments')

    newsession = Session(cookie_vals=cookies, header_vals=headers)

    reqs = yield load_reqlist(args.reqids)

    for req in reqs:
        if clear_cookies:
            req.cookies.clear()
        newsession.apply_req(req)

    conf_message = "You're about to submit %d requests, continue?" % len(reqs)
    if not confirm(conf_message):
        defer.returnValue(None)

    for r in reqs:
        r.tags.add('resubmitted')

    save = not args.inmem
    yield async_submit_requests(reqs,
                                save=save,
                                save_in_mem=args.inmem,
                                unique_paths=args.uniquepath,
                                unique_path_and_args=args.unique)