Skip to content

Commit cd19b5a

Browse files
20
1 parent 64a05a1 commit cd19b5a

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed

20.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import requests
2+
import zipfile
3+
4+
5+
def main():
6+
url = "http://www.pythonchallenge.com/pc/hex/unreal.jpg"
7+
auth = ("butter", "fly")
8+
# first_step(url, auth)
9+
# second_step(url, auth)
10+
# third_step(url, auth)
11+
# fourth_step(hint)
12+
# five_step(url, auth)
13+
# six_step(url, auth)
14+
seven_step("fence/1152983631.zip")
15+
16+
17+
def first_step(url, auth):
18+
res = requests.get(url, auth=auth)
19+
res_header = res.headers
20+
res_content = res.content
21+
print("res_header is {}, res_content is {}".format(res_header, res_content))
22+
# 'Content-Range': 'bytes 0-30202/2123456789
23+
24+
25+
def second_step(url, auth):
26+
start = 0
27+
while True:
28+
print("start is {}".format(start))
29+
if start >= 2123456789:
30+
break
31+
headers = {"RANGE": "bytes={}-".format(start)}
32+
res = requests.get(url, auth=auth, headers=headers)
33+
res_headers = res.headers
34+
res_content_range = res_headers.get("Content-Range")
35+
if res_content_range is not None:
36+
begin, end = get_start_end(res_content_range)
37+
print("===================== {} ========================".format(start))
38+
print("res_content is {}".format(res.content))
39+
print("res_heads is {}".format(res.headers))
40+
print("res_raw is {}".format(res.raw))
41+
print("res_text is {}".format(res.text))
42+
print("res_cookies is {}".format(res.cookies))
43+
print("=================================================")
44+
start = int(end)
45+
else:
46+
start += 1
47+
48+
49+
def get_start_end(st):
50+
bscount_sum = st[6:]
51+
start_to_end = bscount_sum.split("/")[0]
52+
start = start_to_end.split("-")[0]
53+
end = start_to_end.split("-")[1]
54+
print("start is {}, end is {}".format(start, end))
55+
return start, end
56+
57+
58+
def third_step(url, auth):
59+
request_url_with_range(url, auth, 2123456789)
60+
# esrever ni emankcin wen ruoy si drowssap eht
61+
62+
63+
def request_url_with_range(url, auth, num):
64+
headers = {"RANGE": "bytes={}-".format(num)}
65+
res = requests.get(url, auth=auth, headers=headers)
66+
print("=================================================")
67+
print("res_content is {}".format(res.content))
68+
print("res_heads is {}".format(res.headers))
69+
print("res_raw is {}".format(res.raw))
70+
print("res_text is {}".format(res.text))
71+
print("res_cookies is {}".format(res.cookies))
72+
print("=================================================")
73+
74+
75+
def fourth_step(hint):
76+
result = ""
77+
for i in range(len(hint) - 1, -1, -1):
78+
result += hint[i]
79+
print(result)
80+
return result
81+
# the password is your new nickname in reverse
82+
83+
84+
def five_step(url, auth):
85+
request_url_with_range(url, auth, 2123456743)
86+
# and it is hiding at 1152983631.
87+
88+
89+
def six_step(url, auth):
90+
headers = {"RANGE": "bytes={}-".format(1152983631)}
91+
res = requests.get(url, auth=auth, headers=headers)
92+
print(res.content)
93+
file = open("fence/1152983631.zip", "wb")
94+
file.write(res.content)
95+
print("finished")
96+
97+
98+
def seven_step(file_path):
99+
with zipfile.ZipFile(file_path) as myzip:
100+
pwd = fourth_step("invader")
101+
print(pwd)
102+
files = myzip.filelist
103+
for file in files:
104+
with myzip.open(file.filename, pwd=pwd.encode()) as tem_file:
105+
print(tem_file.read())
106+
107+
108+
if __name__ == "__main__":
109+
main()

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
# pythonchallenge
22
Solve Problems in http://www.pythonchallenge.com
33

4+
#### 20
5+
result: password is redavni
6+
```python
7+
import requests
8+
import zipfile
9+
```
10+
- requests is a good lib for http request
11+
- request an url with username and password
12+
- breakpoint resume
13+
- you shoule know a http header {"RANGE":"bytes 0-500"}
14+
- revers
15+
- ZIP file Magic number: none or "PK\x03\x04" or "PK\x05\x06"(empty) or "PK\x07\x08"(spanned), PK for Phil Katz
16+
- find points in 2123456789 points
17+
18+
419
#### 19
520
result: http://www.pythonchallenge.com/pc/hex/idiot2.html
621
```python

fence/1152983631.zip

234 KB
Binary file not shown.

fence/unreal.jpg

29.5 KB
Loading

game/package.pack

234 KB
Binary file not shown.

game/readme.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Yes! This is really level 21 in here.
2+
And yes, After you solve it, you'll be in level 22!
3+
4+
Now for the level:
5+
6+
* We used to play this game when we were kids
7+
* When I had no idea what to do, I looked backwards.

0 commit comments

Comments
 (0)