forked from cibecs/Olicyber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infiniteServer.py
80 lines (71 loc) · 1.73 KB
/
infiniteServer.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
67
68
69
70
71
72
73
74
75
76
77
78
import requests
import bs4
import re
from pwn import *
url = "http://infinite.challs.olicyber.it/"
def makeRequest():
r = requests.get(url)
soup = bs4.BeautifulSoup(r.text, 'html.parser')
return soup
def getType(soup):
question = soup.find('h2').text
split = question.split(" ")
return split[0]
def getQuestion (soup):
question = soup.find('p').text
return question
def solveGrammar (question):
split = question.split('"')
letter = split[1]
word = split[3]
#number of letters in word
res = len(re.findall(letter, word))
data = {
'letter': res
}
return data
def solveMath (question):
split = question.split(" ")
num1 = int(split[2])
split[4] = split[4].replace("?", "")
num2 = int(split[4])
res = num1 + num2
data = {
'sum': str(res)
}
return data
def solveArt (question):
split = question.split(" ")
color = split[5].replace("?", "")
return color+"="
r = requests.session()
soup = makeRequest()
q = log.progress("Question")
a = log.progress("Answer")
t = log.progress("Type")
c = log.progress("Count")
i = 0
while(True):
i+=1
c.status(i)
type = getType(soup)
question = getQuestion(soup)
q.status(question)
t.status(type)
if type == "GRAMMAR":
data = solveGrammar(question)
elif type == "MATH":
data = solveMath(question)
elif type == "ART":
data = solveArt(question)
else:
print("Error")
answ = r.post(url, data=data)
a.status(str(data))
if ("WRONG" in answ.text):
print("WRONG")
break
elif ("flag" in answ.text):
print("FLAG: "+answ.text)
break
soup = bs4.BeautifulSoup(answ.text, 'html.parser')