import base64, os
path = ""
path2 = ""
flag = False
while not os.path.isfile(path):
if flag:
print("File path does not exist!\n")
path = input("Enter path to python file to base64 encode: ")
flag = True
path2 = input("Enter path to save base64 encoded python file: ")
if os.path.isfile(path):
contentb64 = ""
with open(path, "r") as file:
content = file.read()
contentb64 = base64.b64encode(content.encode()).decode()
contentb64 = 'import base64; exec(base64.b64decode(b"%s").decode())' % contentb64
with open(path2, "w") as file:
file.write(contentb64)
print("dOnE!")
input(); exit()Base 64 encodes python code, can be useful if you don't want people to see your code, just modify this one to do it multiple times as you wish.
I apologize for not really knowing what I'm asking for. I know what I want to get to, but not really how to even ask how to get there.
I'm trying to create a python function to calculate base64(sha256(utf16le(username))) as implemented by Microsoft in some RDP logs. The sha256(utf16le(username)) part is easy, it's basically the python NTLM function, but using sha256 instead of MD5.
The part I can't get past is where the base64 calculation comes in. Microsoft calculates the base64 value of the hash (in my example, hash= b3cbfbc12d543247349b2cad1885de5f631687da23a62e1a2b04706cec054b95) as s8v7wS1UMkc0myytGIXeX2MWh9ojpi4aKwRwbOwFS5U=. A Go implementation that calculates it correctly is here: https://play.golang.org/p/6EH64HJBVzr
Bash base64 and Python however calculate the hash as YjNjYmZiYzEyZDU0MzI0NzM0OWIyY2FkMTg4NWRlNWY2MzE2ODdkYTIzYTYyZTFhMmIwNDcwNmNlYzA1NGI5NQ==, I can also get Go to calculate the same hash, though I don't know why: https://play.golang.org/p/-yZPjBBFGy1
I'd like to understand why I'm getting two different hash values and what the difference between those two is. I'd also love to know how to get the correct (correct for my case anyway) hash out of Python.