将C#EXE或DLL程序集注入其他进程的每个CLR运行时和AppDomain

网友投稿 1029 2022-10-23

将C#EXE或DLL程序集注入其他进程的每个CLR运行时和AppDomain

将C#EXE或DLL程序集注入其他进程的每个CLR运行时和AppDomain

clrinject

Injects C# EXE or DLL Assembly into any CLR runtime and AppDomain of another process. The injected assembly can then access static instances of the injectee process's classes and therefore affect it's internal state.

Usage

clrinject-cli.exe -p -a

Opens process with id or name , inject EXE and execute Main method.

Additional options

-e Enumerates all loaded CLR Runtimes and created AppDomains.-d <#> Inject only into <#>-th AppDomain. If no number or zero is specified, assembly is injected into every AppDomain.-i . Create an instance of class from namespace .

Examples

Usage examples

clrinject-cli.exe -p victim.exe -e (Enumerate Runtimes and AppDomains from victim.exe)clrinject-cli.exe -p 1234 -a "C:\Path\To\invader.exe" -d 2 (Inject invader.exe into second AppDomain from process with id 1234)clrinject-cli.exe -p victim.exe -a "C:\Path\To\invader.dll" -i "Invader.Invader" (Create instance of Invader inside every AppDomain in victim.exe)clrinject-cli64.exe -p victim64.exe -a "C:\Path\To\invader64.exe" (Inject x64 assembly into x64 process)

Injectable assembly example

Following code can be compiled as C# executable and then injected into a PowerShell process. This code accessees static instances of internal PowerShell classes to change console text color to green.

using System;using System.Reflection;using Microsoft.PowerShell;using System.Management.Automation.Host;namespace Invader{ class Invader { static void Main(string[] args) { try { var powerShellAssembly = typeof(ConsoleShell).Assembly; var consoleHostType = powerShellAssembly.GetType("Microsoft.PowerShell.ConsoleHost"); var consoleHost = consoleHostType.GetProperty("SingletonInstance", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); var ui = (PSHostUserInterface)consoleHostType.GetProperty("UI").GetValue(consoleHost); ui.RawUI.ForegroundColor = ConsoleColor.Green; } catch (Exception e) { Console.WriteLine(e.ToString()); } } }}

Injection command:

clrinject-cli64.exe -p powershell.exe -a "C:\Path\To\invader64.exe"

Result:

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:面试官:volatile关键字用过吧?说一下作用和实现吧
下一篇:全网最全RabbitMQ总结,别再说你不会RabbitMQ
相关文章

 发表评论

暂时没有评论,来抢沙发吧~