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.
21 dbconnstring = "host=127.0.0.1 port=5432 dbname=flagbot user=flagbot password=flagbotpw"
23 def login(force = False):
25 if force == True or team is None:
26 team = ictf.iCTF().login('ctf@w0y.at','ZmtphWHFUDwRWk6m')
27 print("login(): logged in.")
30 print("getTargets() starting...")
35 service_list = team.get_service_list()
36 #dbconn = psycopg2.connect(dbconnstring)
37 #cur = dbconn.cursor()
38 #cur.execute("DELETE FROM flag_ids")
41 for service in service_list:
43 print("getTargets() getting for:"+str(service['service_name']))
44 targets = team.get_targets(service['service_id'])
45 print("getTargets() got "+str(len(targets['targets']))+" targets.")
46 for target in targets['targets']:
48 dbconn = psycopg2.connect(dbconnstring)
50 cur.execute("INSERT INTO flag_ids (service, team, host, port, flag_id) VALUES (%s, %s, %s, %s, %s)",
51 (service['service_name'], target['team_name'], target['hostname'], target['port'], target['flag_id']))
53 except psycopg2.IntegrityError as e:
56 except psycopg2.DatabaseError as e:
57 print('getTargets() Error %s' % e)
58 traceback.print_exc(file=sys.stdout)
60 except Exception as e:
61 print('getTargets() Error %s' % e)
62 traceback.print_exc(file=sys.stdout)
64 except Exception as e:
65 print('getTargets() Error %s' % e)
66 traceback.print_exc(file=sys.stdout)
70 gettargetth = threading.Timer(0.5, getTargets)
72 print("getTargets(): ended")
75 print("*** starting ...")
78 if __name__ == "__main__":
79 def signal_handler(signal, frame):
80 print('SIG received. exitting!')
82 signal.signal(signal.SIGINT, signal_handler)