feat: build wahrwelt A/D toolkit
This commit is contained in:
1 parent
303438d206
commit
653924d8c6
564 files changed
+36310
-49998
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import copy
|
||||
|
||||
import jwt
|
||||
import requests
|
||||
|
||||
API_PREFIX = 'api/capsule/v1'
|
||||
PUBLIC_KEY_ENDPOINT = 'public_key'
|
||||
|
||||
|
||||
def get_public_key(host):
|
||||
r = requests.get(f"{host}/{API_PREFIX}/{PUBLIC_KEY_ENDPOINT}", timeout=5)
|
||||
|
||||
if r is not None and r.status_code == requests.codes.ok:
|
||||
return r.text
|
||||
|
||||
raise ConnectionError("Не удалось получить открытый ключ для проверки флагов: %s" % host)
|
||||
|
||||
|
||||
def decode(key, capsule):
|
||||
payload = jwt.decode(
|
||||
capsule,
|
||||
algorithms=['ES256', 'RS256'],
|
||||
key=key
|
||||
)
|
||||
return payload
|
||||
|
||||
|
||||
def validate_flags(flags, config):
|
||||
key = config.get('SYSTEM_SERVER_KEY')
|
||||
if not key:
|
||||
key = get_public_key(config['SYSTEM_HOST'])
|
||||
|
||||
for item in flags:
|
||||
item = copy.deepcopy(item)
|
||||
flag = item['flag']
|
||||
if flag.startswith('VolgaCTF{'):
|
||||
flag = flag[len('VolgaCTF{'): -len('}')]
|
||||
|
||||
try:
|
||||
item['flag'] = decode(key, flag)['flag']
|
||||
yield item
|
||||
except: # noqa
|
||||
continue
|
||||
Reference in new issue
Block a user