-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrc4.py
56 lines (44 loc) · 1.39 KB
/
rc4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
import argparse
import sys
import uuid
from Crypto.Cipher import ARC4
from Crypto.Random import get_random_bytes
def encrypt(data):
key = get_random_bytes(16)
rc4 = ARC4.new(key)
ct = rc4.encrypt(data)
print("KEY: ", fmt_output(key))
print("PAYLOAD SIZE: ", len(ct))
return ct
def fmt_output(ct):
p = '02x'
fmt_data = '0x' + ',0x'.join(format(x, p) for x in ct)
return fmt_data
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='aes.py')
parser.add_argument(
'-f', help='bin file to encrypt'
)
parser.add_argument(
'--raw', dest='raw', help='Data will be saved as raw binary file.', action=argparse.BooleanOptionalAction, default='--no-raw'
)
args = parser.parse_args()
if args.f == None:
parser.print_help()
sys.exit()
with open(args.f, mode='rb') as file:
buf = file.read()
file.close()
ciphertext = encrypt(buf)
f_name = uuid.uuid4()
if args.raw == True:
with open(f"{f_name}.txt", mode='wb') as file:
file.write(ciphertext)
file.close()
print(f"[+] Encrypted binary payload saved as {f_name}.txt!")
else:
file = open(f"{f_name}.txt", "w")
file.write(fmt_output(ciphertext))
file.close()
print(f"[+] Encrypted payload saved as {f_name}.txt!")