-
Notifications
You must be signed in to change notification settings - Fork 1
/
level20.py
61 lines (51 loc) · 1.76 KB
/
level20.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
#!/usr/bin/env python
import urllib2
import sre
import zipfile
url = "http://www.pythonchallenge.com/pc/hex/unreal.jpg"
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password('pluses and minuses', 'www.pythonchallenge.com', 'butter', 'fly')
opener = urllib2.build_opener(auth_handler)
regex = sre.compile("bytes (\d)+-(\d+)/\d+")
# your new nickname is "invader"
def getnickname():
nextrange = 0
while True:
req = urllib2.Request(url)
req.headers['Range'] = "bytes=%d-"%nextrange
print req.headers['Range']
c = opener.open(req)
nextrange = int(sre.match(regex, c.headers['content-range']).groups()[1]) + 1
print c.headers['content-range']
f = open("level20.out","w")
for data in c.read():
f.write(data)
# tells you the password is your new nickname in reverse
# and that "it" is hidden at 1152983631
def getpassword():
nextrange = 2123456789
while True:
req = urllib2.Request(url)
req.headers['Range'] = "bytes=%d-"%nextrange
print req.headers['Range']
c = opener.open(req)
nextrange = int(sre.match(regex, c.headers['content-range']).groups()[0]) - 1
print c.headers['content-range']
f = open("level20.out","w")
for data in c.read():
f.write(data)
# gets "it", which turns out to be a zip file
def getzip():
nextrange = 1152983631
req = urllib2.Request(url)
req.headers['Range'] = "bytes=%d-"%nextrange
print req.headers['Range']
c = opener.open(req)
print c.headers['content-range']
f = open("level20.out","w")
for data in c.read():
f.write(data)
f.close()
return "level20.out"
# so you get level20.out, which is a zip file, with a password ("redavni")
getzip()