mirror of https://github.com/dirtbags/moth.git
Merge cfl:/var/projects/gctf
Conflicts: pollster/pollster.py
This commit is contained in:
commit
811141e4d9
|
@ -52,6 +52,9 @@ for cat in os.listdir(opts.puzzles):
|
||||||
dirname = os.path.join(opts.puzzles, cat)
|
dirname = os.path.join(opts.puzzles, cat)
|
||||||
for points in os.listdir(dirname):
|
for points in os.listdir(dirname):
|
||||||
pointsdir = os.path.join(dirname, points)
|
pointsdir = os.path.join(dirname, points)
|
||||||
|
if not os.path.isdir(pointsdir):
|
||||||
|
continue
|
||||||
|
|
||||||
outdir = os.path.join(opts.htmldir, cat, points)
|
outdir = os.path.join(opts.htmldir, cat, points)
|
||||||
try:
|
try:
|
||||||
os.makedirs(outdir)
|
os.makedirs(outdir)
|
||||||
|
|
|
@ -70,19 +70,16 @@ def socket_poll(ip, port, msg, prot, max_recv=1):
|
||||||
sock.send(msg)
|
sock.send(msg)
|
||||||
|
|
||||||
# get a response
|
# get a response
|
||||||
resp = ''
|
resp = []
|
||||||
try:
|
try:
|
||||||
# first read
|
# read from the socket until <max_recv> responses or read,
|
||||||
data = sock.recv(1024)
|
# a timeout occurs, the socket closes, or some other exception
|
||||||
resp += data.decode('utf-8')
|
# is raised
|
||||||
max_recv -= 1
|
for i in range(max_recv):
|
||||||
|
|
||||||
# remaining reads as necessary until timeout or socket closes
|
|
||||||
while(len(data) > 0 and max_recv > 0):
|
|
||||||
data = sock.recv(1024)
|
data = sock.recv(1024)
|
||||||
resp += data.decode('utf-8')
|
if len(data) == 0:
|
||||||
max_recv -= 1
|
break
|
||||||
sock.close()
|
resp.append(data)
|
||||||
|
|
||||||
except socket.timeout as e:
|
except socket.timeout as e:
|
||||||
print('pollster: timed out waiting for a response from %s:%d (%s)' % (ip, port, e))
|
print('pollster: timed out waiting for a response from %s:%d (%s)' % (ip, port, e))
|
||||||
|
@ -91,10 +88,12 @@ def socket_poll(ip, port, msg, prot, max_recv=1):
|
||||||
print('pollster: receive from %s:%d failed (%s)' % (ip, port, e))
|
print('pollster: receive from %s:%d failed (%s)' % (ip, port, e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
sock.close()
|
||||||
|
|
||||||
if len(resp) == 0:
|
if len(resp) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return resp
|
return b''.join(resp)
|
||||||
|
|
||||||
# PUT POLLS FUNCTIONS HERE
|
# PUT POLLS FUNCTIONS HERE
|
||||||
# Each function should take an IP address and return a team name or None
|
# Each function should take an IP address and return a team name or None
|
||||||
|
@ -105,14 +104,14 @@ def poll_fingerd(ip):
|
||||||
resp = socket_poll(ip, 79, b'flag\n', socket.SOCK_STREAM)
|
resp = socket_poll(ip, 79, b'flag\n', socket.SOCK_STREAM)
|
||||||
if resp is None:
|
if resp is None:
|
||||||
return None
|
return None
|
||||||
return resp.strip('\r\n')
|
return resp.strip(b'\r\n')
|
||||||
|
|
||||||
def poll_noted(ip):
|
def poll_noted(ip):
|
||||||
''' Poll the noted service. Returns None or a team name. '''
|
''' Poll the noted service. Returns None or a team name. '''
|
||||||
resp = socket_poll(ip, 4000, b'rflag\n', socket.SOCK_STREAM)
|
resp = socket_poll(ip, 4000, b'rflag\n', socket.SOCK_STREAM)
|
||||||
if resp is None:
|
if resp is None:
|
||||||
return None
|
return None
|
||||||
return resp.strip('\r\n')
|
return resp.strip(b'\r\n')
|
||||||
|
|
||||||
def poll_catcgi(ip):
|
def poll_catcgi(ip):
|
||||||
''' Poll the cat.cgi web service. Returns None or a team name. '''
|
''' Poll the cat.cgi web service. Returns None or a team name. '''
|
||||||
|
@ -121,11 +120,11 @@ def poll_catcgi(ip):
|
||||||
if resp is None:
|
if resp is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
content = resp.split('\r\n\r\n')
|
content = resp.split(b'\r\n\r\n')
|
||||||
if len(content) < 3:
|
if len(content) < 3:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
content = content[1].split('\r\n')
|
content = content[1].split(b'\r\n')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
content_len = int(content[0])
|
content_len = int(content[0])
|
||||||
|
@ -134,7 +133,7 @@ def poll_catcgi(ip):
|
||||||
|
|
||||||
if content_len <= 0:
|
if content_len <= 0:
|
||||||
return None
|
return None
|
||||||
return content[1].strip('\r\n')
|
return content[1].strip(b'\r\n')
|
||||||
|
|
||||||
def poll_tftpd(ip):
|
def poll_tftpd(ip):
|
||||||
''' Poll the tftp service. Returns None or a team name. '''
|
''' Poll the tftp service. Returns None or a team name. '''
|
||||||
|
@ -145,8 +144,12 @@ def poll_tftpd(ip):
|
||||||
if len(resp) <= 5:
|
if len(resp) <= 5:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
resp = resp.split('\n')[0]
|
resp = resp.split(b'\n')[0]
|
||||||
return resp[4:].strip('\r\n')
|
|
||||||
|
# ack
|
||||||
|
resp = socket_poll(ip, 69, b'\x00\x04' + resp[2:4], socket.SOCK_DGRAM, 0)
|
||||||
|
|
||||||
|
return resp[4:].strip(b'\r\n')
|
||||||
|
|
||||||
# PUT POLL FUNCTIONS IN HERE OR THEY WONT BE POLLED
|
# PUT POLL FUNCTIONS IN HERE OR THEY WONT BE POLLED
|
||||||
POLLS = {
|
POLLS = {
|
||||||
|
@ -210,7 +213,7 @@ while True:
|
||||||
|
|
||||||
# perform polls
|
# perform polls
|
||||||
for service,func in POLLS.items():
|
for service,func in POLLS.items():
|
||||||
team = func(ip)
|
team = str(func(ip))
|
||||||
if team is None:
|
if team is None:
|
||||||
team = 'dirtbags'
|
team = 'dirtbags'
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
10: the key is in the generated source.
|
||||||
|
20: enter a non-integer into form field and submit. the key is in the resulting
|
||||||
|
traceback.
|
||||||
|
30: change the value in the GET request to a non-integer. the key is in the
|
||||||
|
resulting traceback.
|
||||||
|
40: change the value in the POST request to a non-integer. the key is in the
|
||||||
|
resulting traceback.
|
||||||
|
|
Loading…
Reference in New Issue