Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created October 29, 2021 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndyNovo/615e64d30d2a48b49497b8a19f93fd21 to your computer and use it in GitHub Desktop.
Save AndyNovo/615e64d30d2a48b49497b8a19f93fd21 to your computer and use it in GitHub Desktop.
#This AWS lambda is setup at:
#https://o5lyi532hb.execute-api.us-east-1.amazonaws.com/default/ecboracle?prefixhex=00112233
import json
import os
import sys
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
def lambda_handler(event, context):
prefix=bytes.fromhex(event["queryStringParameters"]["prefixhex"])
flag = os.environ["flag"]
padded = pad(prefix + flag.encode(), 16)
cipher = AES.new(os.environ["secretkey"].encode(), AES.MODE_ECB)
try:
encrypted = cipher.encrypt(padded)
except ValueError as e:
return {'statusCode': 500, "error": str(e)}
return {
'statusCode': 200,
'body': json.dumps({"ciphertext": encrypted.hex()})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment