Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DEFCON 29 Badge Signer
#!/usr/bin/env python3
import argparse
import random
import sys
def gen_key():
random.seed()
key = ""
for idx in range(32):
key += hex(random.randrange(0, 16)).upper()[-1]
return key
def sign_key(request, signer, signer_type, with_signal):
random_buf = gen_key()
response = random_buf[0:2]
response += request[2:4]
response += signer[2:4]
response += signer[8:10]
response += request[8:10]
response += signer[16:18]
response += random_buf[12:14]
response += signer[18:20]
response += request[16:20]
response += "13"
response += random_buf[22:24]
response += f'{signer_type:#04X}'[2:]
response += random_buf[26:28]
if not with_signal:
response += "01"
else:
response += "7F"
response += random_buf[30:32]
return response
def parse():
parser = argparse.ArgumentParser()
parser.add_argument("request_code")
parser.add_argument("signer_type", help="Type of badge being used to sign the request. "
"Valid values are: HUMAN, GOON, CREATOR, SPEAKER, ARTIST, VENDOR, PRESS")
parser.add_argument("-s", "--with-signal", action="store_true", help="Sets that the signer has the signal")
return parser.parse_args()
def main():
args = parse()
stype = 0x1
if args.signer_type.lower() == "human":
stype = 0x1 << 0
elif args.signer_type.lower() == "goon":
stype = 0x1 << 1
elif args.signer_type.lower() == "creator":
stype = 0x1 << 2
elif args.signer_type.lower() == "speaker":
stype = 0x1 << 3
elif args.signer_type.lower() == "artist":
stype = 0x1 << 4
elif args.signer_type.lower() == "vendor":
stype = 0x1 << 5
elif args.signer_type.lower() == "press":
stype = 0x1 << 6
else:
print(f"Invalid signer type {args.signer_type}")
return 1
signer_key = gen_key()
print(f"Signing request {args.request_code} with the "
f"{args.signer_type.lower()} badge {signer_key}")
result = sign_key(args.request_code, signer_key, stype, args.with_signal)
print(result)
return 0
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment