Update handleConfig.py

This commit is contained in:
maxdcb
2026-04-21 13:48:25 +02:00
parent 2354348e23
commit d850a22102
+1 -29
View File
@@ -1,5 +1,4 @@
import sys, getopt
from Crypto.Cipher import AES
import os
from os import urandom
import hashlib
@@ -8,30 +7,12 @@ import string
import subprocess
from pathlib import Path
characters = string.ascii_letters + string.digits
password = ''.join(random.choice(characters) for i in range(16))
KEY_XOR = password.replace('"','-').replace('\'','-')
KEY_AES = urandom(16)
def pad(s):
return s + (AES.block_size - len(s) % AES.block_size) * chr(AES.block_size - len(s) % AES.block_size).encode('ISO-8859-1')
def aesenc(plaintext, key):
k = hashlib.sha256(key).digest()
iv = 16 * b'\x00'
plaintext = pad(plaintext)
cipher = AES.new(k , AES.MODE_CBC, iv)
output = cipher.encrypt(plaintext)
return output
def xor(data, key):
key = str(key)
l = len(key)
output_str = ""
@@ -40,7 +21,7 @@ def xor(data, key):
current = data[i]
current_key = key[i % len(key)]
output_str += chr(ord(current) ^ ord(current_key))
return output_str
@@ -49,7 +30,6 @@ def printCiphertext(ciphertext):
def generateConfig(outputFilePath):
fileConfigJsonPath = os.path.join(Path(__file__).parent, 'BeaconConfig.json')
fileConfig = open(fileConfigJsonPath, 'r')
config = fileConfig.read()
@@ -69,18 +49,13 @@ def generateConfig(outputFilePath):
test = printCiphertext(KEY_XOR)
fileClearContent = fileClearContent.replace("KEY_XOR", test)
fileEncrypt.write(fileClearContent)
fileEncrypt.close()
return
def main(argv):
outputFilePath = "./cryptDef.hpp"
opts, args = getopt.getopt(argv,"hb:o:",["output="])
for opt, arg in opts:
if opt == '-h':
@@ -90,11 +65,8 @@ def main(argv):
outputFilePath = arg
print('[+] Generate config:')
generateConfig(outputFilePath)
if __name__ == "__main__":
main(sys.argv[1:])