usr bin python import random import sys import urllib2 import base64 v

 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
import random
import sys
import urllib2
import base64
verbose = 0
charset = "0123456789"
method = 'GET'
content_type = 'text/html'
def randomKey(charset, len):
randKey = []
for i in xrange(0, len):
sampl = random.choice(charset)
randKey.append(sampl)
return ''.join(randKey)
def checkResponse(resp_content, failure_keyword):
print resp_content + "{OK}"
if not failure_keyword in resp_content:
return 1
return 0
def sendKey(url, param, key):
if verbose:
print key
clen = 0
data = ""
if (method == "GET"):
url = url + "?" + param + "=" + key
else:
data = key
clen = len(data)
print "url : " + url
request = urllib2.Request(url, data, {'Content-Type': content_type, 'Content-Length': clen})
request.get_method = lambda: method
try:
resp = urllib2.urlopen(request)
rcode = resp.getcode()
resp_content = resp.read()
if (checkResponse(resp_content,"better") == 1) :
print "GOT IT:" + resp_content
exit
else :
print "FAIL"
resp.close()
except urllib2.HTTPError, e:
print str(e)
rcode = e.getcode()
return rcode
def main():
ARG_NUM = 3
argc = sys.argv.__len__()
rcode = 200
if (argc < ARG_NUM):
print "Expected args: <url> <key_len>"
exit (2)
v_url = sys.argv[1]
len = int(sys.argv[2])
key = randomKey(charset, len)
rcode = sendKey(v_url, "param", key)
print "DONE: " + str(rcode)
return(0)
if __name__ == "__main__":
sys.exit(main())