-
Notifications
You must be signed in to change notification settings - Fork 2
/
http_client.py
executable file
·66 lines (54 loc) · 2.68 KB
/
http_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from os import linesep
from argparse import ArgumentParser, FileType
from sys import stdin
from oracle import HttpOracle
def parse_arguments():
parser = ArgumentParser(description="A simple HTTP client used to test server responses to padding errors")
parser.add_argument("ciphertext", help="The ciphertext to record the response for. If not provided, stdin is assumed", type=str, default='-', nargs='?')
parser.add_argument("-u", "--url", help="The url to test the padding faults against", required=True)
parser.add_argument("-n", "--noproxy", help="Do not use a proxy. The http(s)_proxy environment variable will be ignored in this case. Default is to consider the environment variable", action="store_false")
parser.add_argument("-i", "--iterations", help="Number of times to run the test for a single entry. Helps get more consistent time results", type=int, default=5)
parser.add_argument("-x", "--headers", help="The headers to set in the request. Format is a list of comma separated key=value pairs. A valueless key entry is also accepted", default="")
parser.add_argument("-p", "--post", help="The post parameters to set in the request. Format is a list of comma separated key=value pairs. A valueless key entry is also accepted. All values provided are then URL encoded", default="")
parser.add_argument("-g", "--get", help="The get parameters to set in the URL. Format is a list of comma separated key=value pairs. A valueless key entry is also accepted. All values provided are then URL encoded", default="")
return parser
def kv_pairs_to_dict(free_form_str):
kv = {}
pairs = free_form_str.split(',')
for pair in pairs:
items = pair.split('=', 1)
try:
kv[items[0]] = items[1]
except IndexError:
kv[items[0]] = ""
return kv
def http_response_parser(response, query_duration):
print("\tCode: % 8d\tDuration: % 8f" % (response.code, query_duration))
#print(response.read())
if __name__ == "__main__":
parser = parse_arguments()
args = parser.parse_args()
if args.ciphertext != '-':
ciphertext = [args.ciphertext]
else:
ciphertext = [ciphertext.strip(linesep) for ciphertext in stdin.readlines()]
get_free_form = args.get
if get_free_form != "":
get = kv_pairs_to_dict(get_free_form)
else:
get = {}
http_client = HttpOracle(args.url, get)
if not args.noproxy:
http_client.set_proxy()
headers = args.headers
if headers != "":
http_client.headers = kv_pairs_to_dict(headers)
post = args.post
if post != "":
http_client.post = kv_pairs_to_dict(post)
for c in ciphertext:
print(c)
for _ in xrange(args.iterations):
http_client.query(c, http_response_parser)