-
Notifications
You must be signed in to change notification settings - Fork 0
/
b64_windows.py
58 lines (51 loc) · 1.91 KB
/
b64_windows.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
57
58
#!/usr/bin/env python3
#Convertir archivos a base64 con el formato de windows
import readline
import base64
import argparse
import sys
def get_args():
parser = argparse.ArgumentParser(description='Convert file to base64 as Windows likes')
parser.add_argument('-o', '--output', dest='output', type=str, required=False, help='Output File')
parser.add_argument('-f', '--file', dest='file', type=str, required=False, help='File to convert')
return parser.parse_args()
def load_file(filePath):
try:
with open(filePath, 'r') as file:
file = file.read()
file = file.strip()
#print ("Fichero ",file)
return file
except:
print((" [!] WARNING: path not found"))
exit()
if len(file) == 0:
print(" [!] WARNING: File is empty", )
exit()
if __name__ == '__main__':
if len(sys.argv) == 2:
if (sys.argv[1] != '-h' and sys.argv[1] != '-o' and sys.argv[1] != '--ouput' and sys.argv[1] != '--file' and sys.argv[1] != '--help'):
output = "powershell -enc " + base64.b64encode(sys.argv[1].encode('utf16')[2:]).decode()
print (output)
exit()
else:
args = get_args()
else:
args = get_args()
if (args.file == None):
readline.set_completer_delims(' \t\n=')
readline.parse_and_bind("tab: complete")
filePath = input("Tab complete a file: ")
payload = load_file(filePath)
else:
payload = load_file(args.file)
if (args.output == None):
output = "powershell -enc " + base64.b64encode(payload.encode('utf16')[2:]).decode()
print (output)
else:
output = "powershell -enc " + base64.b64encode(payload.encode('utf16')[2:]).decode()
try:
with open(args.output, 'w') as file:
file.write(output)
except:
print((" [!] WARNING: Error with the outpout file"))