3 # 2014 by Jan "Someone" Vales <someone@somenet.org>
14 submission_success = False
15 print "submitting flag: "+flag
16 browser = mechanize.Browser()
17 browser.open('http://10.10.40.200/SubmitFlagServlet')
19 browser.select_form(nr=1)
20 browser.form["teamInput"] = "16"
21 browser.form["flagInput"] = flag
23 response = browser.submit()
24 resp = response.read()
26 if 'Status:scored' in resp:
27 return (1, 'Status:scored')
29 if 'Status:resubmission' in resp:
30 return (2, 'Status:resubmission')
32 if 'Status:denied' in resp:
33 return (3, 'Status:denied')
35 if 'Status:expired' in resp:
36 return (2, 'Status:expired')
38 if 'Status:error' in resp:
41 for line in resp.splitlines():
45 if 'Status:error' in line:
47 return (2, 'Status:error::'+servresponse)
49 # RETURN (success?, srvresponse)
58 print "*** sleeping "+str(sleeptime)+" sec..."
60 dbconn = psycopg2.connect("host=127.0.0.1 dbname=postgres user=postgres password=dba")
62 cur.execute("CREATE TABLE IF NOT EXISTS flags ("
63 "fid serial NOT NULL PRIMARY KEY,"
64 "flag character varying(32) NOT NULL UNIQUE,"
65 "service character varying(32),"
66 "received timestamp without time zone NOT NULL DEFAULT date_trunc('second', NOW()),"
67 "submitted timestamp without time zone,"
68 "status integer NOT NULL DEFAULT 0,"
69 "srvresponse character varying(128)"
73 print "Connected to DB + table created"
77 print "*** sleeping another "+str(sleeptime)+" sec..."
80 cur = dbconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
81 cur.execute("SELECT * from flags where status = 0 or status = 3")
82 print "Fetched " + str(cur.rowcount) + " rows"
83 # rows = cur.fetchall()
84 for row in cur.fetchall():
85 (success, resp) = submit(row['flag'])
87 cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), "
88 "status = %s, srvresponse = %s WHERE fid = %s",
89 (success, resp, row['fid']))
91 except psycopg2.DatabaseError as e:
96 except psycopg2.DatabaseError as e:
101 except psycopg2.DatabaseError as e:
105 except psycopg2.DatabaseError as e:
108 print "should never be reached"
110 if __name__ == "__main__":
111 def signal_handler(signal, frame):
112 print 'SIG received. exitting!'
114 signal.signal(signal.SIGINT, signal_handler)