feature: log.txt with all stdout/stderr

This commit is contained in:
Dobin
2024-02-12 18:12:54 +00:00
parent 9639f1c405
commit 3b8ba16b3f
3 changed files with 31 additions and 17 deletions
+23 -9
View File
@@ -98,18 +98,32 @@ def clean_files():
pathlib.Path(file).unlink(missing_ok=True) pathlib.Path(file).unlink(missing_ok=True)
def run_process_checkret(args): def run_process_checkret(args, check=True):
ret = None ret = subprocess.run(args,
ret = subprocess.run(args, capture_output=True, text=True) capture_output=True)
if ret.returncode != 0:
with open("logs/log.txt", "ab") as f:
cmd = "------------------------------------\n"
cmd += "--- " + " ".join(args)
f.write(cmd.encode('utf-8'))
if ret.stdout != None:
f.write(ret.stdout)
if ret.stderr != None:
f.write(ret.stderr)
if ret.returncode != 0 and check:
print("----! FAILED Command: {}".format(" ".join(args))) print("----! FAILED Command: {}".format(" ".join(args)))
print(ret.stdout) if ret.stdout != None:
print(ret.stderr) print(ret.stdout.decode('utf-8'))
raise Exception("Command failed") if ret.stderr != None:
print(ret.stderr.decode('utf-8'))
raise Exception("Command failed: " + " ".join(args))
if project.show_command_output: if project.show_command_output:
print("> " + " ".join(args)) print("> " + " ".join(args))
print(ret.stdout) if ret.stdout != None:
print(ret.stderr) print(ret.stdout.decode('utf-8'))
if ret.stderr != None:
print(ret.stderr.decode('utf-8'))
def try_start_shellcode(shc_file): def try_start_shellcode(shc_file):
print("--[ Blindly execute shellcode: {} ]".format(shc_file)) print("--[ Blindly execute shellcode: {} ]".format(shc_file))
+2 -2
View File
@@ -57,9 +57,9 @@ def verify_injected_exe(exefile):
# remove indicator file # remove indicator file
pathlib.Path(verify_filename).unlink(missing_ok=True) pathlib.Path(verify_filename).unlink(missing_ok=True)
subprocess.run([ run_process_checkret([
exefile, exefile,
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # , check=True ], check=False)
time.sleep(SHC_VERIFY_SLEEP) time.sleep(SHC_VERIFY_SLEEP)
if os.path.isfile(verify_filename): if os.path.isfile(verify_filename):
print("---> Verify OK. Infected exe works (file was created)") print("---> Verify OK. Infected exe works (file was created)")
+6 -6
View File
@@ -178,9 +178,9 @@ def start():
if project.try_start_final_infected_exe: if project.try_start_final_infected_exe:
print("--[ Start infected exe ]") print("--[ Start infected exe ]")
subprocess.run([ run_process_checkret([
project.inject_exe_out, project.inject_exe_out,
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) ], check=False)
# dump the info i gathered # dump the info i gathered
#file = open('latest.pickle', 'wb') #file = open('latest.pickle', 'wb')
@@ -196,7 +196,7 @@ def obfuscate_shc_loader(file_shc_in, file_shc_out):
print("--[ Convert with SGN ]") print("--[ Convert with SGN ]")
if True: if True:
path_sgn = r'C:\tools\sgn2.0\sgn.exe' path_sgn = r'C:\tools\sgn2.0\sgn.exe'
subprocess.run([ run_process_checkret([
path_sgn, path_sgn,
"-a", "64", "-a", "64",
"{}".format(file_shc_in), "{}".format(file_shc_in),
@@ -204,7 +204,7 @@ def obfuscate_shc_loader(file_shc_in, file_shc_out):
#shutil.copy(file_shc_in + ".sgn", file_shc_out) #shutil.copy(file_shc_in + ".sgn", file_shc_out)
else: else:
path_sgn = r'C:\training\tools\sgn\sgn.exe' path_sgn = r'C:\training\tools\sgn\sgn.exe'
subprocess.run([ run_process_checkret([
path_sgn, path_sgn,
"--arch=64", "--arch=64",
"-i", "{}".format(file_shc_in), "-i", "{}".format(file_shc_in),
@@ -229,10 +229,10 @@ def verify_shellcode(shc_name):
# remove indicator file # remove indicator file
pathlib.Path(verify_filename).unlink(missing_ok=True) pathlib.Path(verify_filename).unlink(missing_ok=True)
subprocess.run([ run_process_checkret([
config.get("path_runshc"), config.get("path_runshc"),
"{}".format(shc_name), "{}".format(shc_name),
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # , check=True ], check=False)
time.sleep(SHC_VERIFY_SLEEP) time.sleep(SHC_VERIFY_SLEEP)
if os.path.isfile(verify_filename): if os.path.isfile(verify_filename):
print("---> Verify OK. Shellcode works (file was created)") print("---> Verify OK. Shellcode works (file was created)")