Rating:


**PLEASE READ THE OTHER WRITEUPS, THEY ARE MUTCH BETTER.
**

This was posted out of frustration I finished the task 30 minutes after the ctf was closed. (I though I had 30 more minuts to go.)
I had some problems with cookies. I realize now I forgot to make a session for requests.

the code below is a mess made by a verry tired madman trying to win a race against the clock
and get his session cookie updated, copying and pasting code..

```
from PIL import Image, ImageDraw
import requests
import logging

import cookielib
# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 0

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
shit = ""

'''--==------------------=================-----------========================'''
#target = "http://ee.sunshinectf.org/practice"
target = "http://ee.sunshinectf.org/exam"
filename = 'test.png'
ses =""
size = 55 #size of the dot

######################
#x axis
a = 335
b = 404
c = 472
d = 541
e = 607
offset = 487 # offset for second colmn

########################
# built an list with y axis
y = [435]
for i in range (0,9):
y.append(y[i]+90)
y= [0]+y+y # dubble up and sync up wiht anwser number :P
'''--==------------------=================-----------========================'''

jar = cookielib.CookieJar()
#function to draw a dot on the disired place.
def awnser(qnr, awn,dr):
if qnr > 10:
awn = awn+offset
dr.ellipse((awn, y[qnr], awn+size, y[qnr]+size), fill = 'black', outline ='black')

'''--==------------------=================-----------========================'''

########################################
# Open up the awnser sheet
def make_file(winrar,num):
im = Image.open('scantron.png')
im.load()
dr = ImageDraw.Draw(im)
for i in range(1,21):
awnser(i,winrar[i-1],dr)
im.save(str(num)+filename)

while 1:
r = requests.get(target,cookies=jar)
cookies = r.cookies.get_dict()
shit = cookies['session']
test = r.text
count =0
while 1:
quests = []
aS=[]
bS=[]
cS=[]
dS=[]
eS=[]
ret=[]
print aS
print quests
for i in range(0,20):
question = test[test.index("

  • ")+4:test.index("
  • ")]
    quests.append(question)
    test = test[test.index("")+5:]
    aS.append(test[test.index("
  • ")+4:test.index("
  • ")])
    test = test[test.index("")+5:]
    bS.append(test[test.index("
  • ")+4:test.index("
  • ")])
    test = test[test.index("")+5:]
    cS.append(test[test.index("
  • ")+4:test.index("
  • ")])
    test = test[test.index("")+5:]
    dS.append(test[test.index("
  • ")+4:test.index("
  • ")])
    test = test[test.index("")+5:]

    i = 0
    for x in quests:
    print x
    tmp = str(eval(x)) #braking all the rules of commencense
    if tmp == aS[i]:
    ret.append(a)
    if tmp == bS[i]:
    ret.append(b)
    if tmp == cS[i]:
    ret.append(c)
    if tmp == dS[i]:
    ret.append(d)
    i=i+1
    print ret

    make_file(ret,count)

    files = {'file': open(str(count)+filename,'rb')}
    fuck = dict(session=shit)
    r = requests.post(target, files=files, cookies=fuck)
    test = r.text
    print test
    cookies = r.cookies.get_dict()
    shit = cookies['session']
    count += 1
    if "Wrong" in test:
    print "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUUUUUUUUUUUUCCCCCCCCCCCCCCCCCCCCCCCCCCCCKKKKKKKKKKK"
    break

    '''--==------------------=================-----------========================
    better late than never
    sun{7h3_b357_7h3r3_15_7h3_b357_7h3r3_w45_7h3_b357_7h3r3_3v3r_w1ll_b3}
    '''
    ```