This commit is contained in:
Ilyastarcek
2025-11-07 15:57:27 +03:00
parent 1aff196155
commit e9cf63c1fb
14 changed files with 10232 additions and 10232 deletions

View File

@@ -1,83 +1,83 @@
import socket
from __init__ import app
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.QUEUED: ['timeout', 'game not started', 'try again later', 'game over', 'is not up',
'no such flag'],
FlagStatus.ACCEPTED: ['accepted', 'congrat'],
FlagStatus.REJECTED: ['bad', 'wrong', 'expired', 'unknown', 'your own',
'too old', 'not in database', 'already submitted', 'invalid flag',
'self', 'invalid', 'already_submitted', 'team_not_found', 'too_old', 'stolen'],
}
READ_TIMEOUT = 5
APPEND_TIMEOUT = 0.05
BUFSIZE = 4096
def recvall(sock):
sock.settimeout(READ_TIMEOUT)
chunks = [sock.recv(BUFSIZE)]
sock.settimeout(APPEND_TIMEOUT)
while True:
try:
chunk = sock.recv(BUFSIZE)
if not chunk:
break
chunks.append(chunk)
except socket.timeout:
break
sock.settimeout(READ_TIMEOUT)
return b''.join(chunks)
def submit_flags(flags, config):
try:
sock = socket.create_connection((config['SYSTEM_HOST'], config['SYSTEM_PORT']),
READ_TIMEOUT)
except (socket.error, ConnectionRefusedError) as e:
app.logger.error(f"Failed to connect to checksystem: {e}")
# Return all flags as QUEUED since we couldn't submit them
for item in flags:
yield SubmitResult(item.flag, FlagStatus.QUEUED, "Connection failed")
return
try:
greeting = recvall(sock)
if b'Welcome' not in greeting:
raise Exception('Checksystem does not greet us: {}'.format(greeting))
sock.sendall(config['TEAM_TOKEN'].encode() + b'\n')
invite = recvall(sock)
if b'enter your flags' not in invite:
raise Exception('Team token seems to be invalid: {}'.format(invite))
unknown_responses = set()
for item in flags:
sock.sendall(item.flag.encode() + b'\n')
response = recvall(sock).decode().strip()
if response:
response = response.splitlines()[0]
response = response.replace('[{}] '.format(item.flag), '')
response_lower = response.lower()
for status, substrings in RESPONSES.items():
if any(s in response_lower for s in substrings):
found_status = status
break
else:
found_status = FlagStatus.QUEUED
if response not in unknown_responses:
unknown_responses.add(response)
app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)
yield SubmitResult(item.flag, found_status, response)
finally:
sock.close()
import socket
from __init__ import app
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.QUEUED: ['timeout', 'game not started', 'try again later', 'game over', 'is not up',
'no such flag'],
FlagStatus.ACCEPTED: ['accepted', 'congrat'],
FlagStatus.REJECTED: ['bad', 'wrong', 'expired', 'unknown', 'your own',
'too old', 'not in database', 'already submitted', 'invalid flag',
'self', 'invalid', 'already_submitted', 'team_not_found', 'too_old', 'stolen'],
}
READ_TIMEOUT = 5
APPEND_TIMEOUT = 0.05
BUFSIZE = 4096
def recvall(sock):
sock.settimeout(READ_TIMEOUT)
chunks = [sock.recv(BUFSIZE)]
sock.settimeout(APPEND_TIMEOUT)
while True:
try:
chunk = sock.recv(BUFSIZE)
if not chunk:
break
chunks.append(chunk)
except socket.timeout:
break
sock.settimeout(READ_TIMEOUT)
return b''.join(chunks)
def submit_flags(flags, config):
try:
sock = socket.create_connection((config['SYSTEM_HOST'], config['SYSTEM_PORT']),
READ_TIMEOUT)
except (socket.error, ConnectionRefusedError) as e:
app.logger.error(f"Failed to connect to checksystem: {e}")
# Return all flags as QUEUED since we couldn't submit them
for item in flags:
yield SubmitResult(item.flag, FlagStatus.QUEUED, "Connection failed")
return
try:
greeting = recvall(sock)
if b'Welcome' not in greeting:
raise Exception('Checksystem does not greet us: {}'.format(greeting))
sock.sendall(config['TEAM_TOKEN'].encode() + b'\n')
invite = recvall(sock)
if b'enter your flags' not in invite:
raise Exception('Team token seems to be invalid: {}'.format(invite))
unknown_responses = set()
for item in flags:
sock.sendall(item.flag.encode() + b'\n')
response = recvall(sock).decode().strip()
if response:
response = response.splitlines()[0]
response = response.replace('[{}] '.format(item.flag), '')
response_lower = response.lower()
for status, substrings in RESPONSES.items():
if any(s in response_lower for s in substrings):
found_status = status
break
else:
found_status = FlagStatus.QUEUED
if response not in unknown_responses:
unknown_responses.add(response)
app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)
yield SubmitResult(item.flag, found_status, response)
finally:
sock.close()

View File

@@ -1,76 +1,76 @@
# Based on https://gist.github.com/xmikasax/90a0ce5736a4274e46b9958f836951e7
import socket
from __init__ import app
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.QUEUED: ['timeout', 'game not started', 'try again later', 'game over', 'is not up',
'no such flag'],
FlagStatus.ACCEPTED: ['accepted', 'congrat'],
FlagStatus.REJECTED: ['bad', 'wrong', 'expired', 'unknown', 'your own',
'too old', 'not in database', 'already submitted', 'invalid flag',
'self', 'invalid', 'already_submitted', 'team_not_found', 'too_old', 'stolen'],
}
READ_TIMEOUT = 5
APPEND_TIMEOUT = 0.05
BUFSIZE = 4096
def recvall(sock):
sock.settimeout(READ_TIMEOUT)
chunks = [sock.recv(BUFSIZE)]
sock.settimeout(APPEND_TIMEOUT)
while True:
try:
chunk = sock.recv(BUFSIZE)
if not chunk:
break
chunks.append(chunk)
except socket.timeout:
break
sock.settimeout(READ_TIMEOUT)
return b''.join(chunks)
def submit_flags(flags, config):
sock = socket.create_connection((config['SYSTEM_HOST'], config['SYSTEM_PORT']),
READ_TIMEOUT)
greeting = recvall(sock)
if b'Welcome' not in greeting:
raise Exception('Checksystem does not greet us: {}'.format(greeting))
sock.sendall(config['TEAM_TOKEN'].encode() + b'\n')
invite = recvall(sock)
if b'enter your flags' not in invite:
raise Exception('Team token seems to be invalid: {}'.format(invite))
unknown_responses = set()
for item in flags:
sock.sendall(item.flag.encode() + b'\n')
response = recvall(sock).decode().strip()
if response:
response = response.splitlines()[0]
response = response.replace('[{}] '.format(item.flag), '')
response_lower = response.lower()
for status, substrings in RESPONSES.items():
if any(s in response_lower for s in substrings):
found_status = status
break
else:
found_status = FlagStatus.QUEUED
if response not in unknown_responses:
unknown_responses.add(response)
app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)
yield SubmitResult(item.flag, found_status, response)
sock.close()
# Based on https://gist.github.com/xmikasax/90a0ce5736a4274e46b9958f836951e7
import socket
from __init__ import app
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.QUEUED: ['timeout', 'game not started', 'try again later', 'game over', 'is not up',
'no such flag'],
FlagStatus.ACCEPTED: ['accepted', 'congrat'],
FlagStatus.REJECTED: ['bad', 'wrong', 'expired', 'unknown', 'your own',
'too old', 'not in database', 'already submitted', 'invalid flag',
'self', 'invalid', 'already_submitted', 'team_not_found', 'too_old', 'stolen'],
}
READ_TIMEOUT = 5
APPEND_TIMEOUT = 0.05
BUFSIZE = 4096
def recvall(sock):
sock.settimeout(READ_TIMEOUT)
chunks = [sock.recv(BUFSIZE)]
sock.settimeout(APPEND_TIMEOUT)
while True:
try:
chunk = sock.recv(BUFSIZE)
if not chunk:
break
chunks.append(chunk)
except socket.timeout:
break
sock.settimeout(READ_TIMEOUT)
return b''.join(chunks)
def submit_flags(flags, config):
sock = socket.create_connection((config['SYSTEM_HOST'], config['SYSTEM_PORT']),
READ_TIMEOUT)
greeting = recvall(sock)
if b'Welcome' not in greeting:
raise Exception('Checksystem does not greet us: {}'.format(greeting))
sock.sendall(config['TEAM_TOKEN'].encode() + b'\n')
invite = recvall(sock)
if b'enter your flags' not in invite:
raise Exception('Team token seems to be invalid: {}'.format(invite))
unknown_responses = set()
for item in flags:
sock.sendall(item.flag.encode() + b'\n')
response = recvall(sock).decode().strip()
if response:
response = response.splitlines()[0]
response = response.replace('[{}] '.format(item.flag), '')
response_lower = response.lower()
for status, substrings in RESPONSES.items():
if any(s in response_lower for s in substrings):
found_status = status
break
else:
found_status = FlagStatus.QUEUED
if response not in unknown_responses:
unknown_responses.add(response)
app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)
yield SubmitResult(item.flag, found_status, response)
sock.close()

View File

@@ -1,46 +1,46 @@
import requests
from __init__ import app
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.QUEUED: ['timeout', 'game not started', 'try again later', 'game over', 'is not up',
'no such flag'],
FlagStatus.ACCEPTED: ['accepted', 'congrat'],
FlagStatus.REJECTED: ['bad', 'wrong', 'expired', 'unknown', 'your own',
'too old', 'not in database', 'already submitted', 'invalid flag'],
}
# The RuCTF checksystem adds a signature to all correct flags. It returns
# "invalid flag" verdict if the signature is invalid and "no such flag" verdict if
# the signature is correct but the flag was not found in the checksystem database.
#
# The latter situation happens if a checker puts the flag to the service before putting it
# to the checksystem database. We should resent the flag later in this case.
TIMEOUT = 5
def submit_flags(flags, config):
r = requests.put(config['SYSTEM_URL'],
headers={'X-Team-Token': config['SYSTEM_TOKEN']},
json=[item.flag for item in flags], timeout=TIMEOUT)
unknown_responses = set()
for item in r.json():
response = item['msg'].strip()
response = response.replace('[{}] '.format(item['flag']), '')
response_lower = response.lower()
for status, substrings in RESPONSES.items():
if any(s in response_lower for s in substrings):
found_status = status
break
else:
found_status = FlagStatus.QUEUED
if response not in unknown_responses:
unknown_responses.add(response)
app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)
yield SubmitResult(item['flag'], found_status, response)
import requests
from __init__ import app
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.QUEUED: ['timeout', 'game not started', 'try again later', 'game over', 'is not up',
'no such flag'],
FlagStatus.ACCEPTED: ['accepted', 'congrat'],
FlagStatus.REJECTED: ['bad', 'wrong', 'expired', 'unknown', 'your own',
'too old', 'not in database', 'already submitted', 'invalid flag'],
}
# The RuCTF checksystem adds a signature to all correct flags. It returns
# "invalid flag" verdict if the signature is invalid and "no such flag" verdict if
# the signature is correct but the flag was not found in the checksystem database.
#
# The latter situation happens if a checker puts the flag to the service before putting it
# to the checksystem database. We should resent the flag later in this case.
TIMEOUT = 5
def submit_flags(flags, config):
r = requests.put(config['SYSTEM_URL'],
headers={'X-Team-Token': config['SYSTEM_TOKEN']},
json=[item.flag for item in flags], timeout=TIMEOUT)
unknown_responses = set()
for item in r.json():
response = item['msg'].strip()
response = response.replace('[{}] '.format(item['flag']), '')
response_lower = response.lower()
for status, substrings in RESPONSES.items():
if any(s in response_lower for s in substrings):
found_status = status
break
else:
found_status = FlagStatus.QUEUED
if response not in unknown_responses:
unknown_responses.add(response)
app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)
yield SubmitResult(item['flag'], found_status, response)

View File

@@ -1,74 +1,74 @@
import socket
from __init__ import app
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.QUEUED: ['timeout', 'game not started', 'try again later', 'game over', 'is not up',
'no such flag'],
FlagStatus.ACCEPTED: ['accepted', 'congrat'],
FlagStatus.REJECTED: ['bad', 'wrong', 'expired', 'unknown', 'your own',
'too old', 'not in database', 'already submitted', 'invalid flag'],
}
# The RuCTF checksystem adds a signature to all correct flags. It returns
# "invalid flag" verdict if the signature is invalid and "no such flag" verdict if
# the signature is correct but the flag was not found in the checksystem database.
#
# The latter situation happens if a checker puts the flag to the service before putting it
# to the checksystem database. We should resent the flag later in this case.
READ_TIMEOUT = 5
APPEND_TIMEOUT = 0.05
BUFSIZE = 4096
def recvall(sock):
sock.settimeout(READ_TIMEOUT)
chunks = [sock.recv(BUFSIZE)]
sock.settimeout(APPEND_TIMEOUT)
while True:
try:
chunk = sock.recv(BUFSIZE)
if not chunk:
break
chunks.append(chunk)
except socket.timeout:
break
sock.settimeout(READ_TIMEOUT)
return b''.join(chunks)
def submit_flags(flags, config):
sock = socket.create_connection((config['SYSTEM_HOST'], config['SYSTEM_PORT']),
READ_TIMEOUT)
greeting = recvall(sock)
if b'Enter your flags' not in greeting:
raise Exception('Checksystem does not greet us: {}'.format(greeting))
unknown_responses = set()
for item in flags:
sock.sendall(item.flag.encode() + b'\n')
response = recvall(sock).decode().strip()
if response:
response = response.splitlines()[0]
response = response.replace('[{}] '.format(item.flag), '')
response_lower = response.lower()
for status, substrings in RESPONSES.items():
if any(s in response_lower for s in substrings):
found_status = status
break
else:
found_status = FlagStatus.QUEUED
if response not in unknown_responses:
unknown_responses.add(response)
app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)
yield SubmitResult(item.flag, found_status, response)
sock.close()
import socket
from __init__ import app
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.QUEUED: ['timeout', 'game not started', 'try again later', 'game over', 'is not up',
'no such flag'],
FlagStatus.ACCEPTED: ['accepted', 'congrat'],
FlagStatus.REJECTED: ['bad', 'wrong', 'expired', 'unknown', 'your own',
'too old', 'not in database', 'already submitted', 'invalid flag'],
}
# The RuCTF checksystem adds a signature to all correct flags. It returns
# "invalid flag" verdict if the signature is invalid and "no such flag" verdict if
# the signature is correct but the flag was not found in the checksystem database.
#
# The latter situation happens if a checker puts the flag to the service before putting it
# to the checksystem database. We should resent the flag later in this case.
READ_TIMEOUT = 5
APPEND_TIMEOUT = 0.05
BUFSIZE = 4096
def recvall(sock):
sock.settimeout(READ_TIMEOUT)
chunks = [sock.recv(BUFSIZE)]
sock.settimeout(APPEND_TIMEOUT)
while True:
try:
chunk = sock.recv(BUFSIZE)
if not chunk:
break
chunks.append(chunk)
except socket.timeout:
break
sock.settimeout(READ_TIMEOUT)
return b''.join(chunks)
def submit_flags(flags, config):
sock = socket.create_connection((config['SYSTEM_HOST'], config['SYSTEM_PORT']),
READ_TIMEOUT)
greeting = recvall(sock)
if b'Enter your flags' not in greeting:
raise Exception('Checksystem does not greet us: {}'.format(greeting))
unknown_responses = set()
for item in flags:
sock.sendall(item.flag.encode() + b'\n')
response = recvall(sock).decode().strip()
if response:
response = response.splitlines()[0]
response = response.replace('[{}] '.format(item.flag), '')
response_lower = response.lower()
for status, substrings in RESPONSES.items():
if any(s in response_lower for s in substrings):
found_status = status
break
else:
found_status = FlagStatus.QUEUED
if response not in unknown_responses:
unknown_responses.add(response)
app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)
yield SubmitResult(item.flag, found_status, response)
sock.close()

View File

@@ -1,26 +1,26 @@
from themis.finals.attack.helper import Helper
from themis.finals.attack.result import Result
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.ACCEPTED: [Result.SUCCESS_FLAG_ACCEPTED],
FlagStatus.REJECTED: [Result.ERROR_FLAG_EXPIRED, Result.ERROR_FLAG_YOURS,
Result.ERROR_FLAG_SUBMITTED, Result.ERROR_FLAG_NOT_FOUND],
}
def submit_flags(flags, config):
h = Helper(config['SYSTEM_HOST'])
codes = h.attack(*[item.flag for item in flags])
for item, code in zip(flags, codes):
for status, possible_codes in RESPONSES.items():
if code in possible_codes:
found_status = status
break
else:
found_status = FlagStatus.QUEUED
yield SubmitResult(item.flag, found_status, code.name)
from themis.finals.attack.helper import Helper
from themis.finals.attack.result import Result
from models import FlagStatus, SubmitResult
RESPONSES = {
FlagStatus.ACCEPTED: [Result.SUCCESS_FLAG_ACCEPTED],
FlagStatus.REJECTED: [Result.ERROR_FLAG_EXPIRED, Result.ERROR_FLAG_YOURS,
Result.ERROR_FLAG_SUBMITTED, Result.ERROR_FLAG_NOT_FOUND],
}
def submit_flags(flags, config):
h = Helper(config['SYSTEM_HOST'])
codes = h.attack(*[item.flag for item in flags])
for item, code in zip(flags, codes):
for status, possible_codes in RESPONSES.items():
if code in possible_codes:
found_status = status
break
else:
found_status = FlagStatus.QUEUED
yield SubmitResult(item.flag, found_status, code.name)