3 # Copyright 2015-2017 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
4 # send me your changes. credit author(s). do not publish. share alike.
5 # to be done: find a suitable licence text.
20 dbconnstring = "host=127.0.0.1 port=5432 dbname=flagbot user=flagbot password=flagbotpw"
22 def login(force = False):
24 if force == True or team is None:
25 team = ictf.iCTF().login('ctf@w0y.at','ZmtphWHFUDwRWk6m')
26 print("login(): logged in.")
33 result = team.submit_flag([flag])
36 if "notactive" in result:
38 elif "incorrect" in result:
40 elif "correct" in result:
45 except Exception as e:
47 traceback.print_exc(file=sys.stdout)
55 print("*** sleeping "+str(sleeptime)+" sec...")
57 dbconn = psycopg2.connect("host=s.i port=5432 dbname=flagbot user=flagbot password=flagbotpw")
58 print("Connected to DB")
66 cur = dbconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
67 cur.execute("SELECT * from flags where status = 0 or status = 4 order by random() limit 1")
69 print("*** sleeping another "+str(sleeptime)+" sec...")
72 for row in cur.fetchall():
73 if row['flag'] is None or row['flag'].strip() == '':
75 (status, resp) = submit(row['flag'])
76 print("submitted: "+row['flag']+" - response: ("+str(status)+") "+resp)
78 cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), status = %s, srvresponse = %s WHERE fid = %s and status = 0 or status = 4",
79 (status, resp, row['fid']))
81 except psycopg2.DatabaseError as e:
86 except psycopg2.DatabaseError as e:
90 sock.shutdown(socket.SHUT_WR)
93 except psycopg2.DatabaseError as e:
97 except psycopg2.DatabaseError as e:
101 print("should never be reached")
104 if __name__ == "__main__":
105 def signal_handler(signal, frame):
106 print('SIG received. exitting!')
108 signal.signal(signal.SIGINT, signal_handler)