Skip to content

Commit e8f2c9f

Browse files
authored
Update handleConfig.py
1 parent 0bec12b commit e8f2c9f

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

beacon/beacon/handleConfig.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys, getopt
2-
from Crypto.Cipher import AES
32
import os
43
from os import urandom
54
import hashlib
@@ -8,30 +7,12 @@
87
import subprocess
98
from pathlib import Path
109

11-
1210
characters = string.ascii_letters + string.digits
1311
password = ''.join(random.choice(characters) for i in range(16))
1412

15-
1613
KEY_XOR = password.replace('"','-').replace('\'','-')
17-
KEY_AES = urandom(16)
18-
19-
20-
def pad(s):
21-
return s + (AES.block_size - len(s) % AES.block_size) * chr(AES.block_size - len(s) % AES.block_size).encode('ISO-8859-1')
22-
23-
24-
def aesenc(plaintext, key):
25-
k = hashlib.sha256(key).digest()
26-
iv = 16 * b'\x00'
27-
plaintext = pad(plaintext)
28-
cipher = AES.new(k , AES.MODE_CBC, iv)
29-
output = cipher.encrypt(plaintext)
30-
return output
31-
3214

3315
def xor(data, key):
34-
3516
key = str(key)
3617
l = len(key)
3718
output_str = ""
@@ -40,7 +21,7 @@ def xor(data, key):
4021
current = data[i]
4122
current_key = key[i % len(key)]
4223
output_str += chr(ord(current) ^ ord(current_key))
43-
24+
4425
return output_str
4526

4627

@@ -49,7 +30,6 @@ def printCiphertext(ciphertext):
4930

5031

5132
def generateConfig(outputFilePath):
52-
5333
fileConfigJsonPath = os.path.join(Path(__file__).parent, 'BeaconConfig.json')
5434
fileConfig = open(fileConfigJsonPath, 'r')
5535
config = fileConfig.read()
@@ -69,18 +49,13 @@ def generateConfig(outputFilePath):
6949
test = printCiphertext(KEY_XOR)
7050
fileClearContent = fileClearContent.replace("KEY_XOR", test)
7151

72-
7352
fileEncrypt.write(fileClearContent)
74-
7553
fileEncrypt.close()
76-
7754
return
7855

7956

8057
def main(argv):
81-
8258
outputFilePath = "./cryptDef.hpp"
83-
8459
opts, args = getopt.getopt(argv,"hb:o:",["output="])
8560
for opt, arg in opts:
8661
if opt == '-h':
@@ -90,11 +65,8 @@ def main(argv):
9065
outputFilePath = arg
9166

9267
print('[+] Generate config:')
93-
9468
generateConfig(outputFilePath)
9569

9670

97-
9871
if __name__ == "__main__":
9972
main(sys.argv[1:])
100-

0 commit comments

Comments
 (0)