.NET 7 的 AOT 到底能不能杠反編譯?

一:背景

1.講故事

在B站,公眾號上發了一篇 AOT 的文章后,沒想到反響還是挺大的,都稱贊這個東西能抗反編譯,可以讓破解難度極大提高,可能有很多朋友對逆向不了解,以為用 ILSpy,Reflector,DnSpy 這些工具打不開就覺得很安全,其實不然,在 OllyDbg,IDA,WinDBG 這些逆向工具面前一樣是裸奔。

既然大家都很感興趣,那這篇就和大家聊一聊。

二:幾個例子

1. 動態修改程序數據

修改程序數據在逆向中再正常不過了,由于目前的 AOT 只能發布成 x64 ,這里就用 WinDbg 做下演示,首先看下例子。

internal?class?Program{static?void?Main(string[]?args){while?(true){Console.WriteLine("hello?world!");Thread.Sleep(1000);}}}
6965caf284287d1046835b183011858f.png

程序在不斷的輸出,接下來我們將 hello world 中的 world 給去掉,操作手法非常簡單,先內存搜索找到 hello world,然后修改 length=5 即可。

0:005>?lm
start?????????????end?????????????????module?name
00007ff7`95b70000?00007ff7`95e5d000???ConsoleApp1?C?(private?pdb?symbols)??0:005>?s-u?00007ff7`95b70000?L?0x00007ff7`95e5d000?hello
00007ff7`95e1c41c??0068?0065?006c?006c?006f?0020?0077?006f??h.e.l.l.o.?.w.o.0:000>?dp?00007ff795e1c41c-0x4?L1
00007ff7`95e1c418??00650068`0000000c0:000>?eq?00007ff7`95e1c418?00650068`00000005
0:000>?g
d5dcc3fa56d01075d340523285745223.png

2. 獲取程序托管堆

AOT 再怎么牛,它終還是個托管程序,既然是托管程序自然就有托管堆,托管堆中就有所有的托管數據,玩過 SOS.dll 朋友應該知道,用 !eeheap -gc 就能把托管堆給顯示出來,比如下面這樣。

0:022>?!eeheap?-gc
Number?of?GC?Heaps:?1
generation?0?starts?at?0x000002414D891030
generation?1?starts?at?0x000002414D891018
generation?2?starts?at?0x000002414D891000
ephemeral?segment?allocation?context:?nonesegment?????????????begin?????????allocated?????????committed????allocated?size????committed?size
000002414D890000??000002414D891000??000002414D8D1FE8??000002414D8D2000??0x40fe8(266216)??0x41000(266240)
Large?object?heap?starts?at?0x000002415D891000segment?????????????begin?????????allocated?????????committed????allocated?size????committed?size
000002415D890000??000002415D891000??000002415D891018??000002415D892000??0x18(24)??0x1000(4096)
Pinned?object?heap?starts?at?0x0000024165891000
0000024165890000??0000024165891000??0000024165899C10??00000241658A2000??0x8c10(35856)??0x11000(69632)
Total?Allocated?Size:??????????????Size:?0x49c10?(302096)?bytes.
Total?Committed?Size:??????????????Size:?0x42000?(270336)?bytes.
------------------------------
GC?Allocated?Heap?Size:????Size:?0x49c10?(302096)?bytes.
GC?Committed?Heap?Size:????Size:?0x42000?(270336)?bytes.

雖然目前的 AOT 不支持 SOS 擴展,無法顯示出托管堆,但一點關系都沒有,SOS 是通過 DataAccess 去挖的,大不來我手工挖一下就好了哈,接下來就是怎么挖的問題了,熟悉 CLR 的朋友應該知道所謂的托管堆在內部用的是 generation_table[] 一維數據來維護的,以 的方式來劃分,代的落地是用 heap_segment 來表示的, 參考代碼如下:

generation?gc_heap::generation_table?[total_generation_count];enum?gc_generation_num
{//?small?object?heap?includes?generations?[0-2],?which?are?"generations"?in?the?general?sense.soh_gen0?=?0,soh_gen1?=?1,soh_gen2?=?2,max_generation?=?soh_gen2,//?large?object?heap,?technically?not?a?generation,?but?it?is?convenient?to?represent?it?as?suchloh_generation?=?3,//?pinned?heap,?a?separate?generation?for?the?same?reasons?as?lohpoh_generation?=?4,uoh_start_generation?=?loh_generation,//?number?of?ephemeral?generationsephemeral_generation_count?=?max_generation,//?number?of?all?generationstotal_generation_count?=?poh_generation?+?1
};

接下來用 x 命令看下數組內容,代碼如下:

0:000>?x?ConsoleApp1!WKS::gc_heap::generation_table
00007ff7`95e25010?ConsoleApp1!WKS::gc_heap::generation_table?=?class?WKS::generation?[5]0:000>?dx?-r1?(*((ConsoleApp1!WKS::generation?(*)[5])0x7ff795e25010))
(*((ConsoleApp1!WKS::generation?(*)[5])0x7ff795e25010))?????????????????[Type:?WKS::generation?[5]][0]??????????????[Type:?WKS::generation]...[4]??????????????[Type:?WKS::generation]0:000>?dx?-r1?(*((ConsoleApp1!WKS::generation?*)0x7ff795e25010))
(*((ConsoleApp1!WKS::generation?*)0x7ff795e25010))?????????????????[Type:?WKS::generation][+0x038]?start_segment????:?0x25100000000?[Type:?WKS::heap_segment?*][+0x040]?allocation_start?:?0x25100001030?:?0x38?[Type:?unsigned?char?*][+0x048]?allocation_segment?:?0x25100000000?[Type:?WKS::heap_segment?*][+0x0d0]?allocation_size??:?0x0?[Type:?unsigned?__int64][+0x100]?gen_num??????????:?0?[Type:?int]...0:000>?dx?-r1?((ConsoleApp1!WKS::heap_segment?*)0x25100000000)
((ConsoleApp1!WKS::heap_segment?*)0x25100000000)?????????????????:?0x25100000000?[Type:?WKS::heap_segment?*][+0x000]?allocated????????:?0x25100001048?:?0x90?[Type:?unsigned?char?*][+0x008]?committed????????:?0x25100012000?:?Unable?to?read?memory?at?Address?0x25100012000?[Type:?unsigned?char?*][+0x010]?reserved?????????:?0x25110000000?:?0x18?[Type:?unsigned?char?*][+0x018]?used?????????????:?0x25100009fe0?:?0x0?[Type:?unsigned?char?*][+0x020]?mem??????????????:?0x25100001000?:?0x38?[Type:?unsigned?char?*][+0x028]?flags????????????:?0x0?[Type:?unsigned?__int64][+0x030]?next?????????????:?0x0?[Type:?WKS::heap_segment?*]...

上面的這些字段就描述出了 !eeheap -gc 的結果,接下來想挖什么,提取什么我就不過多介紹了。

3. 提取托管線程列表

提取 托管線程 列表也是非常重要的, 它能指示出很多信息,一般用 !t 命令就能顯示,輸出如下:

0:022>?!t
ThreadCount:??????17
UnstartedThread:??0
BackgroundThread:?6
PendingThread:????0
DeadThread:???????0
Hosted?Runtime:???noLock??DBG???ID?????OSID?ThreadOBJ???????????State?GC?Mode?????GC?Alloc?Context??????????????????Domain???????????Count?Apt?Exception0????1?????4128?000002414BDB8C70????2a020?Preemptive??000002414D8C6108:000002414D8C8000?000002414bdaf8f0?-00001?MTA?6????2?????4458?000002414BDE5EB0????2b220?Preemptive??0000000000000000:0000000000000000?000002414bdaf8f0?-00001?MTA?(Finalizer)?7????4?????23e8?000002416DDB15C0??102b220?Preemptive??000002414D8C9250:000002414D8CA000?000002414bdaf8f0?-00001?MTA?(Threadpool?Worker)?...20???17?????50a8?000002416DE43DD0??102b220?Preemptive??000002414D8BC2D0:000002414D8BDFD0?000002414bdaf8f0?-00001?MTA?(Threadpool?Worker)?21???18?????57d4?000002416DE628E0??8029220?Preemptive??000002414D8CC2A8:000002414D8CE000?000002414bdaf8f0?-00001?MTA?(Threadpool?Completion?Port)

既然目前的 SOS 不支持,同樣可以手工到 CLR 中去挖,熟悉的朋友應該知道 !t 的數據源來自于 ThreadStore::s_pThreadStore 下的 m_ThreadList 集合,它以鏈表的形式串聯了每個線程的 LinkPtr 字段,但可惜的是,在 AOT 中,這一塊已經重寫了,由 g_pTheRuntimeInstance 全局變量下的 m_ThreadList 來維護了。

為了方便觀察,多生成幾個 Thread。

static?void?Main(string[]?args){Debugger.Break();var?tasks?=?Enumerable.Range(0,?10).Select(m?=>?new?Thread(()?=>{Console.WriteLine($"tid={Thread.CurrentThread.ManagedThreadId}?已執行!");Console.ReadLine();}));foreach?(var?item?in?tasks){item.Start();}Console.ReadLine();}

程序跑起來后,深挖 g_pTheRuntimeInstance 全局變量即可。

0:015>?x?ConsoleApp1!g_pTheRuntimeInstance
00007ff7`0155ee20?ConsoleApp1!g_pTheRuntimeInstance?=?0x00000291`cb5b9300
0:015>?dx?-r1?((ConsoleApp1!RuntimeInstance?*)0x291cb5b9300)
((ConsoleApp1!RuntimeInstance?*)0x291cb5b9300)?????????????????:?0x291cb5b9300?[Type:?RuntimeInstance?*][+0x000]?m_pThreadStore???:?0x291cb5b9390?[Type:?ThreadStore?*]...
0:015>?dx?-r1?((ConsoleApp1!ThreadStore?*)0x291cb5b9390)
((ConsoleApp1!ThreadStore?*)0x291cb5b9390)?????????????????:?0x291cb5b9390?[Type:?ThreadStore?*][+0x000]?m_ThreadList?????[Type:?SList<Thread,DefaultSListTraits<Thread,DoNothingFailFastPolicy>?>][+0x008]?m_pRuntimeInstance?:?0x291cb5b9300?[Type:?RuntimeInstance?*][+0x010]?m_Lock???????????[Type:?ReaderWriterLock]
0:015>?dx?-r1?(*((ConsoleApp1!SList<Thread,DefaultSListTraits<Thread,DoNothingFailFastPolicy>?>?*)0x291cb5b9390))
(*((ConsoleApp1!SList<Thread,DefaultSListTraits<Thread,DoNothingFailFastPolicy>?>?*)0x291cb5b9390))?????????????????[Type:?SList<Thread,DefaultSListTraits<Thread,DoNothingFailFastPolicy>?>][+0x000]?m_pHead??????????:?0x291ed366240?[Type:?Thread?*]
0:015>?dx?-r1?((ConsoleApp1!Thread?*)0x291ed366240)
((ConsoleApp1!Thread?*)0x291ed366240)?????????????????:?0x291ed366240?[Type:?Thread?*]...[+0x058]?m_pNext??????????:?0x291cb6aeb60?[Type:?Thread?*][+0x060]?m_hPalThread?????:?0x204?[Type:?void?*][+0x068]?m_ppvHijackedReturnAddressLocation?:?0x0?[Type:?void?*?*][+0x070]?m_pvHijackedReturnAddress?:?0x0?[Type:?void?*][+0x078]?m_uHijackedReturnValueFlags?:?0x0?[Type:?unsigned?__int64][+0x080]?m_pExInfoStackHead?:?0x0?[Type:?ExInfo?*][+0x088]?m_threadAbortException?:?0x0?[Type:?Object?*][+0x090]?m_pThreadLocalModuleStatics?:?0x291cb6aee90?[Type:?void?*?*][+0x098]?m_numThreadLocalModuleStatics?:?0x1?[Type:?unsigned?int][+0x0a0]?m_pGCFrameRegistrations?:?0x0?[Type:?GCFrameRegistration?*][+0x0a8]?m_pStackLow??????:?0xf754100000?[Type:?void?*][+0x0b0]?m_pStackHigh?????:?0xf754200000?[Type:?void?*][+0x0b8]?m_pTEB???????????:?0xf7533ba000?:?0x0?[Type:?unsigned?char?*][+0x0c0]?m_uPalThreadIdForLogging?:?0x2044?[Type:?unsigned?__int64][+0x0c8]?m_threadId???????[Type:?EEThreadId][+0x0d0]?m_pThreadStressLog?:?0x0?[Type:?void?*][+0x0d8]?m_interruptedContext?:?0x0?[Type:?_CONTEXT?*][+0x0e0]?m_redirectionContextBuffer?:?0x0?[Type:?unsigned?char?*]
0:015>?dx?-r1?(*((ConsoleApp1!EEThreadId?*)0x291ed366308))
(*((ConsoleApp1!EEThreadId?*)0x291ed366308))?????????????????[Type:?EEThreadId][+0x000]?m_uiId???????????:?0x2044?[Type:?unsigned?__int64]

從CLR 的 Thread 維護的信息來看,這個結構體已經很小了,也說明 AOT 在Thread信息維護上做了很多的精簡。

三:總結

總的來說,AOT 確實能加速程序的初始啟動,一體化的打包機制也非常方便部署,但怎么變終究還是一個托管程序,需要底層的 C++ 托著它,扛 反編譯 無從談起,所以防小人的話,該加殼的加殼,該混淆的混淆。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/281015.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/281015.shtml
英文地址,請注明出處:http://en.pswp.cn/news/281015.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

google hdr+_更好的隱私權控制使Google+死了

google hdrEarlier this year, Google started a project to review third-party developer access to Google accounts through the use of APIs. It found a security breach surrounding Google, and is now shutting the service down, at least for consumers. 今年年初&a…

新0-Day漏洞或將給Linux桌面發行版帶來浩劫

Linux 的各個發行版都一直強調安全及其相關元素&#xff0c;比如防火墻、滲透測試、沙盒、無痕上網和隱私等等&#xff0c;但事實上可能并沒有想象中的那么安全。安全研究員 Chris Evans 公開了其發現的針對 Linux 桌面發行版的 0day 漏洞&#xff0c;利用特制的音頻文件入侵 L…

php中把美國時間轉為北京時間的自定義

我的服務器北京時間&#xff0c;php調用的時間&#xff1a; date.timezone "America/Chicago" 這是美國這邊的一個時間&#xff0c;有的時候跟北京相差13個小時&#xff0c;有的時候跟北京時間相差14個小時&#xff0c;所以很不好處理&#xff0c;現在php函數就能處…

C# DataTable筆記

文章轉載自http://www.cnblogs.com/Sandon/p/5175829.html 感謝博主Sandon。 為了方便以后編程查看&#xff0c;特把文章復制過來。 創建表 //創建一個空表 DataTable dt new DataTable(); //創建一個名為"Table_New"的空表 DataTable dt new DataTable("Tabl…

一份詳盡的利用 Kubeadm部署 Kubernetes 1.13.1 集群指北

2019獨角獸企業重金招聘Python工程師標準>>> 概 述 Kubernetes集群的搭建方法其實有多種&#xff0c;比如我在之前的文章《利用K8S技術棧打造個人私有云&#xff08;連載之&#xff1a;K8S集群搭建&#xff09;》中使用的就是二進制的安裝方法。雖然這種方法有利于我…

.NET性能優化-使用內存+磁盤混合緩存

我們回顧一下上一篇文章中的內容&#xff0c;有一個朋友問我這樣一個問題&#xff1a;我的業務依賴一些數據&#xff0c;因為數據庫訪問慢&#xff0c;我把它放在 Redis 里面&#xff0c;不過還是太慢了&#xff0c;有什么其它的方案嗎&#xff1f;其實這個問題比較簡單的是吧&…

最小生成樹詳解

注&#xff1a;本文算法使用鏈式前向星數據結構實現。學習鏈接&#xff1a;鏈式前向星-學習筆記 一、Prim算法 普通prim算法模板&#xff1a; //用前向星錄數據的時候記得把head初始化為-1 fill(dist,distLEN,MAX); memset(vis,0,sizeof vis); int ans0; dist[1]0; //如…

dropbox文件_Dropbox即將發布的擴展程序更新將添加更多文件編輯支持,包括Pixlr照片...

dropbox文件Dropbox is perhaps the best-known cloud storage platform for consumers, but it’s hoping to become something more. With an upcoming overhaul to its user tools, Dropbox will add more complex editing tools, in addition to what it already provides …

黑客竊取思科、IBM與甲骨文認證管理系統內的敏感數據

目前一套被思科、F5、IBM以及甲骨文等企業所廣泛使用的認證管理系統(即Credential Manager System)正面臨著數據泄露風險&#xff0c;其中的敏感數據也許已經被黑客們所獲取。 根據Pearson VUE(主營計算機測試方案開發與交付)發布的一項公告&#xff0c;某惡意軟件已經藏身于該…

Spring下載地址

下載地址&#xff1a;https://repo.spring.io/libs-release-local/org/springframework/spring/ 進入后可選擇下載版本&#xff0c;選擇版本后&#xff0c;進入目錄結構。其中dist是最終發布版本&#xff0c;包含開發所需lib和源碼。docs是開發文檔。schema是一些約束文件。 Do…

C#字符串:轉數組、數字

1.List<string> 轉數組&#xff0c;字符串 string[] strs list.ToArray();string s string.Join(",", list.ToArray());//數組轉list string[] strArr new string[3] { "1", "2", "3" }; List<string> strList strArr…

.NET7發布,一大批優秀.NET6項目沒人看了嗎...(都是好項目)

恍惚間都已經.NET7.0了&#xff0c;不能再呆在舊版本了&#xff01;這里分享一套Vue3 Axios TS Vite Element Plus .NET 6 WebAPI JWT SqlSugar的通用管理后臺&#xff0c;各種最新框架組件&#xff0c;學習必備&#xff01;這里把源碼、腳本以及專門錄制的視頻教程都打…

Python的日志記錄-logging模塊的使用

一、日志 1.1什么是日志 日志是跟蹤軟件運行時所發生的事件的一種方法&#xff0c;軟件開發者在代碼中調用日志函數&#xff0c;表明發生了特定的事件&#xff0c;事件由描述性消息描述&#xff0c;同時還包含事件的重要性&#xff0c;重要性也稱為級別或嚴重性。 1.2何時使用日…

詢問HTG:白噪聲屏幕保護程序,有效的文件命名以及從密碼泄露中恢復

Once a week we share three of the questions we’ve answered from the Ask HTG inbox with the greater readership; this week we’re looking at white noise screen savers, efficient file naming systems, and recovering from a password compromise. 每周一次&#…

專家預測第二波WannaCry勒索病毒攻擊即將到來!

WannaCry的傳播腳步今晨戛然而止 今天一大早&#xff0c;全網的WannaCry蠕蟲病毒攻擊突然減弱消退了!所有這一切功勞來自于英國研究人員malwaretech&#xff0c;他通過逆向發現WannaCry代碼中有一個特殊域名地址&#xff1a; www.iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.co…

01.HTML基礎命令筆記

目錄 HTML結構 body內常用標簽 常用 div與span img a標簽 超鏈接標簽 其他格式標簽 列表 表格 表單 select標簽 label標簽 textarea多行文本 HTML結構 <!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"&…

ios numlock_從“提示”框:默認情況下啟用NumLock,無廣告的iOS應用和立體聲供電的派對燈...

ios numlockOnce a week we round up some of the great tips readers have sent into the tip box. This week we’re looking at how to enable the NumLock by default, stripping ads from iOS apps, and turning Christmas lights into audio-responsive party lights. 每…

Windows 7 自動更新失敗導致無法進系統解決方案

故障現象&#xff1a;自動更新后&#xff0c;重啟電腦&#xff0c;提示&#xff1a;&#xff08;配置Windows update 失敗 還原更改 請勿關閉計算機&#xff09;&#xff0c; 而計算機一直停留該界面&#xff0c;如果半個小時以上都無反應。此時&#xff0c;就不要再繼續等待了…

Net程序員為什么要學點其他語言副業

最近看了很多同行的文章、或者是現實中身邊的例子也好&#xff0c;真的覺得大家太不容易了。感覺說的就是自己。入門上學的時候接觸了.NET&#xff0c;它的簡單以及宇宙無敵的Visual Studio&#xff0c;讓我深深地迷戀上它。畢業之后&#xff0c;就成功的做來一名.Neter&#x…

PaperWeekly 第28期 | 圖像語義分割之特征整合和結構預測

“ 余昌黔 華中科技大學碩士 研究方向為圖像語義分割 知乎專欄 https://zhuanlan.zhihu.com/semantic-segmentation 前言 近來閱讀了 PASCAL VOC 2012 排行榜上前幾的文章&#xff0c;包括 PSPNet 和林國省老師的幾篇論文&#xff0c;覺得現在在 semantic segmentation 領域對于…