forked from shiltemann/CTF-writeups-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
16.py
40 lines (31 loc) · 1.03 KB
/
16.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
import requests
import json
import pprint
count = 0
def findpath(current_url, mypaths):
global count
for p in mypaths:
count += 1
if count %100 == 0:
print "currently trying: " + current_url
new_url = current_url+str(p)
r = s.get(new_url, headers=headers)
response = json.loads(r.text)
if response['Answer'] == "You've left the path!":
print "error"
exit()
# recurse
elif response['Answer'] == "Go on! Follow one of the possible paths":
findpath(new_url, response['paths'])
# if other response, we found it maybe?
elif response['Answer'] != "This leads to nowhere, so turn around!":
pprint.pprint(response)
exit()
# backtrack
url = 'http://hackyeaster.hacking-lab.com:9999/'
headers = {'User-Agent': 'PathFinder'}
s = requests.Session()
# recursively follow path until we get to an ending
r = s.get(url, headers=headers)
response = json.loads(r.text)
findpath(url, response['paths'])