Created
April 15, 2019 13:18
-
-
Save Ge0rg3/79dda3a98e001fb89521e68c380923fa to your computer and use it in GitHub Desktop.
Solution to Sunshine CTF 2019's Entry Exam challenge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw | |
from io import BytesIO | |
from math import floor | |
import requests as rq | |
import time | |
filepath = "/home/george/" | |
questionUrl = "http://archive.sunshinectf.org:19005/exam" | |
x1 = 337 | |
y1 = 435 | |
yOffset = 90.5 | |
xOffset = 68 | |
xJump = 490 | |
size = 50 | |
session = rq.Session() | |
def fillForm(question, answer): | |
answer = list("ABCDE").index(answer) | |
question = question - 1 | |
if question <= 9: | |
drawScantron.ellipse((x1+(answer*xOffset), y1+(question*yOffset), x1+size+(answer*xOffset), y1+size+(question*yOffset)), fill=0, outline=0) | |
else: | |
question -= 10 | |
drawScantron.ellipse((x1+(answer*xOffset)+xJump, y1+(question*yOffset), x1+size+(answer*xOffset)+xJump, y1+size+(question*yOffset)), fill=0, outline=0) | |
while True: | |
scantron = Image.open(filepath+"scantron.png") | |
drawScantron = ImageDraw.Draw(scantron) | |
start = time.time() #Start timer | |
questions = session.get(questionUrl).text.split("\n")[1:] #Get questions from page | |
for i in range(20): | |
question = questions[i*7][4:-5] #Get question from HTML | |
answerNumber = floor(eval(question)) #Eval question to get answer | |
answerChoices = [z[4:-5] for z in questions[i*7+2:i*7+2+4]] #Get possible answers | |
answerPosition = answerChoices.index(str(answerNumber)) #Get position of our answer in given answers | |
answerLetter = list("ABCDE")[answerPosition] #Translate position to number | |
fillForm(i+1, answerLetter) #Draw to scantron | |
imgByteArr = BytesIO() | |
scantron.save(imgByteArr, format='PNG') | |
imgByteArr = imgByteArr.getvalue() | |
files = {'file': imgByteArr} | |
resp = session.post(questionUrl, files=files) | |
end = time.time() | |
scantron.close() | |
print(resp.text) | |
if "sun" in resp.text.lower: | |
break | |
print(f"{len(resp.text)} : {end - start}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment