<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alien Chao on Medium]]></title>
        <description><![CDATA[Stories by Alien Chao on Medium]]></description>
        <link>https://medium.com/@oalieno.chao?source=rss-876fb29f130d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hXK0lcVlZ_vTeA-U</url>
            <title>Stories by Alien Chao on Medium</title>
            <link>https://medium.com/@oalieno.chao?source=rss-876fb29f130d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:40:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oalieno.chao/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[信用卡大盜：IIS 後門事件分析]]></title>
            <link>https://research.cycraft.ai/%E4%BF%A1%E7%94%A8%E5%8D%A1%E5%A4%A7%E7%9B%9C-iis-%E5%BE%8C%E9%96%80%E4%BA%8B%E4%BB%B6%E5%88%86%E6%9E%90-4a3a8fb238c3?source=rss-876fb29f130d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a3a8fb238c3</guid>
            <category><![CDATA[apt]]></category>
            <category><![CDATA[incident-response]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[Alien Chao]]></dc:creator>
            <pubDate>Wed, 23 Apr 2025 17:39:04 GMT</pubDate>
            <atom:updated>2025-04-24T06:56:31.155Z</atom:updated>
            <content:encoded><![CDATA[<p>近年來，資料外洩事件頻傳，從資料庫遭駭客入侵、大規模脫庫，到消費者個資在暗網上流竄，企業與用戶無不人心惶惶。</p><p>傳統上，金融機構多著重於保護資料庫安全，以防堵大規模資料洩露。然而，近期我們應對的這起事件卻顛覆了這種認知。攻擊者並非大費周章入侵資料庫，而是利用潛伏於 IIS 伺服器中的後門模組，直接在交易過程中攔截信用卡資訊。這種「即時竊取」(on-the-fly) 的手法，更隱蔽、更精準，也對現有防禦體系提出了嚴峻挑戰。</p><p>本文將深入剖析我們團隊近期應對的一起針對雲地混合基礎架構的信用卡資料外洩事件，還原攻擊路徑，並解析攻擊者所使用的惡意程式以及攻擊手法。</p><h3>事件背景</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Lefc0RGdESagqW4F2f3pA.png" /><figcaption>入侵流程</figcaption></figure><p>受害者環境為雲地混合架構，地端環境為傳統的 Windows AD 網域，雲端環境則基於 AWS 平台。位於雲端的 IIS 伺服器負責處理信用卡刷卡交易，正常流量經由 AWS Load Balancer 導向該伺服器。地端環境透過 VPN 伺服器與雲端 IIS 伺服器建立連線，以利應用程式部署與管理。值得注意的是，儘管環境中導入了 AWS 雲端服務，核心業務流程依舊運行於 EC2 虛擬機上的 Windows Server IIS 伺服器。因此，本次事件的調查分析，在實務操作上與傳統 Windows 環境下的事件相去不遠。</p><p>在事件調查過程中，我們於受害者的 IIS 伺服器上偵測到兩種類型的惡意程式：</p><ul><li><strong>IIS Backdoor Module:</strong> 專門用於竊取信用卡號碼的惡意 IIS 模組。</li><li><strong>後門程式:</strong> 具備 C2 連線能力的後門程式，用於維持持久化存取並接收遠端指令。</li></ul><p>在我們的調查中發現，攻擊者並非直接自外部入侵雲端環境，而是先滲透地端環境，再透過橫向移動逐步擴散，最終摸到雲端環境中負責敏感資料處理的 IIS 伺服器。</p><h3>橫向移動</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*r0dygIlkZgcMyFuWtvUedA.png" /><figcaption>RDP Logon</figcaption></figure><p>儘管事件的初始入侵點已難以精確追溯，但證據顯示攻擊者利用 RDP 作為主要的橫向移動手段。我們觀察到攻擊者在環境內多個系統上成功進行 RDP 登入，並藉此部署後門程式。推測攻擊者可能利用了弱密碼、憑證竊取或其他 方法進行初始滲透，但確切方法仍待進一步釐清。</p><p>攻擊者最終透過雲端上的 VPN 伺服器作為跳板連線至雲端 IIS 伺服器，並再次利用 RDP 在雲端環境中部署後門程式，顯示攻擊者對受害者環境十分熟悉。</p><h3>IIS Backdoor Module</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9058YJWyGMFffj9CtCIPqw.png" /><figcaption>IIS Backdoor Module</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*36cn0Y8PkWGG-sk0IbJ_rQ.png" /></figure><p>攻擊者巧妙地在 IIS 伺服器中植入一個惡意的 IIS Module。該模組 Hook 了 IIS 流程中的 OnPostBeginRequest 函式，使其能夠在每個新的 HTTP 請求進入伺服器時，即時攔截並檢視請求內容。該模組的核心功能是針對夾帶信用卡的資訊請求進行側錄。具體而言，模組會將包含信用卡號碼的請求內容，連同 User-Agent 字串及時間戳記，寫入至 C:\Users\Public\Libraries\crash.dmp 檔案。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lLhSLnvZ_qW3dQv3dwsR1Q.png" /></figure><p>為了規避基於關鍵字特徵的偵測機制，攻擊者對寫入檔案的內容進行了簡單的 XOR 0xa1 運算，藉此達到混淆效果。此外，將檔案命名為 crash.dmp 亦是一種障眼法，意圖偽裝成系統崩潰產生的記憶體傾印檔案，降低安全分析人員的警覺性。</p><p>另外，除了寫入檔案，惡意模組還會將竊取的資料回傳至 analysis.ap-northeast-1.rds.amazonregion[.]com。此網域使用了與受害者環境相同的 AWS Region (ap-northeast-1)，顯示攻擊者在發動攻擊前已進行充分的偵查，並針對受害者環境特性進行了客製化調整。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZfXE-UXYKb-4hXFuZra2GQ.png" /></figure><p>在 IIS 的組態檔 web.config 中，我們發現攻擊者在 &lt;globalModules&gt; 區段的末尾插入了一行，載入叫做 warmup.dll 的模組。此設定確保了惡意模組會在 IIS 啟動時被自動載入，實現持久化運作。</p><h3>後門程式</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4LR6psabiX8ytJnXRK9Uzw.png" /></figure><p>除了 IIS Backdoor Module，攻擊者也在環境中部署了後門程式 VsGraphicsProxyStub.dll，它是由有簽章的 MpDefenderPushService.exe 透過 DLL Sideloading 帶起來的。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*3Z7RtpvChxoglRQ8rVq6Gw.png" /></figure><p>VsGraphicsProxyStub.dll 和 MpDefenderPushService.exe 皆被放置在 C:\Program Files\Windows Defender Advanced Threat Protection\Classification 目錄下。儘管 MpDefenderPushService.exe 的名稱與 Windows Defender 相關，但實際上該程式是 Visual Studio 的 VsGraphicsDesktopEngine.exe，被攻擊者惡意更名以混淆視聽。 此外，C:\Program Files\Windows Defender Advanced Threat Protection\Classification 目錄只要 Administrators 群組的成員即可寫入，與受 Defender 保護的 C:\Program Files\Windows Defender 目錄不同，這也是攻擊者選擇此路徑的原因之一。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*Oyrl59X-soK5GKdjXD0HBQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D-gnkie7MHMyQeNRPve_pA.png" /></figure><p>VsGraphicsProxyStub.dll 啟動後，首先會載入名為 Pbsyfffinltsufq 的檔案。該檔案是被編碼過的 Shellcode，載入後該 Shellcode 會使用 RtlDecompressBuffer 函式將 sxqwgmyu 的檔案解壓縮並執行，這是第二階段的 PE 執行檔 (真正的後門)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*OuyU7mndTRcDc83xg5t8CQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*DnXMj6cB73YSesOgEgIfvA.png" /></figure><p>後門程式透過 SSL 加密連線至 C2 伺服器 hotfix.update.windowshotfix[.]com，並具備下載額外 Shellcode 模組並執行的能力，顯示其具備功能擴展性和遠程控制的功能。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VR9Ugpa4KcsNCDny3_XPrQ.png" /></figure><p>為實現持久化，後門程式還會將自身註冊為名為 &quot;Microsoft Defender Push Service&quot; 的 Windows 服務。</p><h3>結論</h3><p>由於近期各類個資外洩事件頻傳，而金融機構由於其經濟價值更是駭客的首要目標。因此在本文，我們以 IIS 後門的案例，讓大家認識針對金融單位的攻擊，如何竊取信用卡資訊以及攻擊者的 TTP。透過本篇文章我們也強調三個攻擊：</p><ul><li>隨著金融產業在雲端的使用漸增，雲地混合基礎架構的安全也成為重要的風險，從本次事件也可以看到攻擊者如何攻擊雲地混合基礎架構。</li><li>「即時竊取」(on-the-fly) 的手法 — 利用潛伏於 IIS 伺服器中的後門模組，直接在交易過程中攔截信用卡資訊，而不需實際存取資料庫。</li><li>近期我們也在其他攻擊中，監控到 IIS 伺服器後門的攻擊手法，也在本文提醒這類攻擊趨勢。</li></ul><p>可參考 CyCraft 官網的部落格文章，獲取更多相關資訊：<a href="https://www.cycraft.com/blog">https://www.cycraft.com/blog</a></p><h3>IOC</h3><ul><li>hotfix.update.windowshotfix[.]com</li><li>analysis.ap-northeast-1.rds.amazonregion[.]com</li><li>ee0a7b69a82bf84abb7d77dc907b6e69 (MpDefenderPushService.exe)</li><li>6a9881877e6bed705a42f3293263acc8 (VsGraphicsProxyStub.dll)</li><li>81b13fee07bd38dee08d615e54978be3 (warmup.dll)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a3a8fb238c3" width="1" height="1" alt=""><hr><p><a href="https://research.cycraft.ai/%E4%BF%A1%E7%94%A8%E5%8D%A1%E5%A4%A7%E7%9B%9C-iis-%E5%BE%8C%E9%96%80%E4%BA%8B%E4%BB%B6%E5%88%86%E6%9E%90-4a3a8fb238c3">信用卡大盜：IIS 後門事件分析</a> was originally published in <a href="https://research.cycraft.ai/">CyCraft Research Lab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[透過 IDA 腳本自動破解 ShadowPad 變種的 ScatterBee 混淆手法]]></title>
            <link>https://research.cycraft.ai/ida-shadowpad-scatterbee-226c637ae937?source=rss-876fb29f130d------2</link>
            <guid isPermaLink="false">https://medium.com/p/226c637ae937</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[shadowpad]]></category>
            <dc:creator><![CDATA[Alien Chao]]></dc:creator>
            <pubDate>Tue, 18 Jun 2024 05:34:03 GMT</pubDate>
            <atom:updated>2024-06-27T15:50:47.769Z</atom:updated>
            <content:encoded><![CDATA[<p>中國駭客組織 APT41（又名 Winnti Group、Amoeba、Wicked Spider 等）自 2010 年起便活躍於全球，攻擊目標遍及歐洲、亞洲、美洲等地，<a href="https://www.cycarrier.com/post/shadowpad20201209">主要使用的攻擊工具除了有特別針對攻擊對象系統的特製惡意程式</a>，也包含了本篇文章主題：ShadowPad 與其 ScatterBee 變種。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t_8WT6JGNYu6suerbENwCA.jpeg" /></figure><p><a href="https://www.secureworks.com/research/shadowpad-malware-analysis">APT41 至少於 2017 年開始使用 ShadowPad 進階模組化遠端存取木馬惡意程式</a>，此惡意軟體在 2019 年後，逐漸被許多與中國有關的駭客組織採用，針對航空、能源、金融、電信與教育等多種不同的產業。<a href="https://www.welivesecurity.com/2017/09/21/cconsiderations-on-ccleaner-incident/">2017 年 CCleaner 清理軟體遭駭事件</a>、<a href="https://www.welivesecurity.com/2020/01/31/winnti-group-targeting-universities-hong-kong/">2019 年香港反送中運動期間數所大學遭到攻擊</a>等案例，皆彰顯了 ShadowPad 持續迭代、涉及多重領域的威脅性。</p><p>奧義智慧科技資安研究員趙偉捷（oalieno）在此篇文章中針對 ShadowPad Loader 深入分析，並拆解了在野外發現、利用 ScatterBee 混淆手法的變種。<a href="https://medium.com/insomniacs/its-a-bee-it-s-a-no-it-s-shadowpad-aff6a970a1c2">ScatterBee 混淆手法的分析散見於多篇文章</a>中，<a href="https://github.com/PwCUK-CTO/ScatterBee_Analysis">開源協作平台上雖然也有 IDA plugin 模組</a>、但使用在此樣本上卻相對複雜且不順暢，因此我們提供了完整的 IDA 腳本，有助於還原未混淆的 assembly 程式碼。</p><h4><strong>閱讀本文，你可以知道：</strong></h4><ol><li>掌握 ShadowPad 情資與 ShadowPad Loader 技術分析。</li><li>參考 IDA 腳本，自動反混淆 ShadowPad ScatterBee 變種的攻擊手法。</li></ol><h3>ShadowPad Loader 樣本分析</h3><p>在 2023 年 8 月，攻擊者從網頁漏洞打進受害機器，並在端點中放置了三個檔案: log.dll, log.dll.dat, DRM.exe。是本篇文章主要分析的樣本。</p><p>DRM.exe 的原始檔名是 BDReinit.exe，是由 Bitdefender 簽章的合法執行檔。攻擊者利用這隻合法且有簽章的執行檔進行 DLL Sideloading，來載入惡意的 log.dll。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*WpOM4v3ahZaE7dpfPGE9JQ.png" /></figure><h4>DLL Sideloading</h4><p>這支 log.dll 是一個 Loader，它會利用有簽章的合法程式 DRM.exe 來載入自己，讀取並執行同資料夾底下的第二階段的 Shellcode log.dll.dat。</p><h4>Self modified code</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*BZ270VMscke7RZuA7w_7jQ.png" /><figcaption>圖1 sub_10001010 函式</figcaption></figure><p>首先，從 DllMain 進到 sub_10001010 函式（圖1），sub_10001010 函式會檢查 Sleep 和 CreateMutexW 的函式開頭是不是 0xE8 或 0xE9，以確認是否有 API Hooking 的行為。API Hooking 常被使用在 Sandbox 或 EDR 產品上，透過修改 Windows API 的前幾個 bytes 來劫持 API ，就能監控程式中使用 Windows API 的行為。</p><p>接著，sub_10001010函式會用 GetModuleHandleW 找出載入 log.dll 的 exe 主程式在記憶體中的位址，並檢查偏移 0x2777 的位址是不是等於 0x840FC33B，這代表 log.dll 要綁定使用 DRM.exe (md5: 8a8db1e20dc508af5a81fc00b1929468) 載入才能跑起來。</p><p>檢查完後，它會用 VirutalProtect 把該段 code 位址改為可寫（該段位址是 .text 的程式碼區段，原本的權限是 RX），直接把 LoadLibraryW(&quot;log.dll&quot;) 下的 assembly 改成 call sub_10001000（圖2–2 的 log.dll 是被載入到 0x74330000）。最後再利用 VirtualProtect 修改權限，所以當sub_10001010函式回溯到 DRM.exe 程式時，就會呼叫 call sub_10001000 ，並跳到 log.dll 的 sub_10001000 函式。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*--y0m_D3cqLX0DEygqmW6g.png" /><figcaption>圖2–1 LoadLibraryW(&quot;log.dll&quot;) 修改前</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*DAMQjZNMyAgCY8NgkhqFeQ.png" /><figcaption>圖2–2 LoadLibraryW(&quot;log.dll&quot;) 修改後</figcaption></figure><h4>ScatterBee 混淆手法</h4><p>呼叫 sub_10001000 函式後，後續的程式碼都被 ScatterBee（<a href="https://www.pwc.co.uk/issues/cyber-security-services/research/chasing-shadows.html">由英國 PwC 資安威脅研究團隊命名</a>）此手法進一步混淆。ScatterBee 先打散每一個 assembly 指令，再用一個特殊的 jmp function 串起來，類似於以下的程式碼。</p><pre>push ebp<br>jmp B<br><br>A:<br>mov ebp, esp<br>jmp C<br><br>B:<br>sub esp, 0x10<br>jmp A<br><br>C:<br>...</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*8lnJP8NEWgv2frnTVEW22g.png" /><figcaption>圖3 特殊的 jmp function (sub_10006374)</figcaption></figure><p>如圖3所示，這個特殊的 jmp function 就是 sub_10006374，此函式真正要跳轉的位址則是 0x1000A181 + 0xFFFFFDAA = 0x10009F2B，sub_10006374函式會執行以下的 assembly（已隱去原本包含很多 mov eax, eax, xchg ax, ax, jp + jnp, …等等的冗餘代碼）。</p><pre>xchg ecx, [esp]<br>pushf<br>add ecx, [ecx]<br>popf<br>xchg ecx, [esp]<br>ret</pre><h4>Custom decode function</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*CMa9umWmfIIPf7jADHgkzg.png" /><figcaption>圖4 ShadowPad Loader 自定義解碼函式</figcaption></figure><p>ShadowPad Loader 有自定義的解碼函式，Input 的前四個 bytes 是 key，其他是被加密的字串。key 每次會進行 17 * key - 0x443246ba 的運算（在其他樣本中也有不同的計算方式，像是 8 * key + 0x107E666D），產生的 xor key 則是把 key 的四個 bytes 相加的結果，整個過程會像是以下的 python 腳本：</p><pre>def decode(key: bytes, enc: bytes):<br>    key = int.from_bytes(key, &#39;little&#39;)<br>    dec = b&#39;&#39;<br><br>    i = 0<br>    for i in range(len(enc)):<br>        key = (17 * key - 0x443246ba) &amp; 0xffffffff<br>        dec += bytes([enc[i] ^ (sum(key.to_bytes(4, &#39;big&#39;)) &amp; 0xff)])<br><br>    return dec</pre><h4>Load payload</h4><p>除此之外，ShadowPad Loader 也會讀取 log.dll.dat 檔案，內含被加密的 shellcode，讀取後會立刻將檔案刪除，並將加密的 shellcode 儲存至 HKCU:\SOFTWARE\Classes\WOW6432Node\CLSID\{a44eee15-f652-fccc-801fdd3405aef4f8} 此位置的 D1EBF8C1 鍵值。儲存位置是寫死的，但我們發現這與 <a href="https://www.elastic.co/security-labs/update-to-the-REF2924-intrusion-set-and-related-campaigns">Elastic Security Labs 資安研究團隊於 2023 年 2 月發布的報告</a>不同，猜測是每次行動都會替換的值。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Syqt0hoRwdfCENLK67Xo9g.png" /><figcaption>圖5 加密的 shellcode 被儲存位置</figcaption></figure><p>調查時如果無法還原 log.dll.dat 檔案，建議嘗試以下的 powershell 指令，從 registry 讀取 shellcode 進行分析：</p><pre>-join ((Get-ItemProperty -Path &quot;HKCU:\SOFTWARE\Classes\WOW6432Node\CLSID\{a44eee15-f652-fccc-801fdd3405aef4f8}&quot;).D1EBF8C1 | ForEach-Object { $_.ToString(&quot;X2&quot;) }) &gt; payload.txt</pre><h3>使用 IDA 腳本破解 ScatterBee 混淆手法</h3><p>拆解 ScatterBee 混淆邏輯後，我們試圖寫出一個 IDA 腳本以重組並重新修補 assembly。</p><p>重組被分散的 assembly 所需步驟如下：</p><ol><li>從 0x1000A17C 以 DFS 取出原始的指令，儲存成一張有向圖<br>- 遇到 call 和 jxx (jb, jl, …) 指令的時候要處理<br>- 遇到 ret 結束</li><li>分配新的位址<br>- 遇到連續的指令要一起分配</li><li>針對 call 和 jxx 重新分配位址</li><li>重新進行修補</li></ol><p>原始的 assembly 中包含了很多 cmp esp xxxx + jb 組合的冗餘代碼，如何判斷哪些指令是冗餘代碼呢？例如在 Windows 與 Linux 系統中 Stack 是倒著長的，而且通常 Stack Allocate 會 Align 0x10000，所以 esp 的後兩個 bytes 會從 0xFFFF 開始往回長，在沒有用到太多 Stack 的情況下通常都是 0xF???。在 DFS 遍歷指令時，我們發現以下這兩行指令把 esp compare 一個小於 0xF000 的隨機值，導致 jb 的觸發條件永遠不會成立，由此確認這就是可以直接忽略的冗餘代碼。</p><pre>cmp esp 0x1234<br>jb 0x1000abcd ; never jump</pre><p>最後我們實作出完整的程式碼為：</p><pre>import idc<br>import ida_bytes<br><br>def X(x):<br>    return f&quot;0x{x:08x}&quot;<br><br>class DeObfus:<br>    def __init__(self, magic_function_addr, first_avaliable_addr):<br>        self.insts = {}<br>        self.magic_function_addr = magic_function_addr<br>        self.obf_flag = False<br>        # There are DllMain and a initialize function in front of FIRST_ADDR<br>        self.cursor = first_avaliable_addr<br><br>    @staticmethod<br>    def create_insn_force(addr):<br>        idc.del_items(idc.get_item_head(addr))<br>        if idc.create_insn(addr) &gt; 0:<br>            return True<br>        for i in range(1, 6):<br>            idc.del_items(addr + i, DELIT_SIMPLE)<br>            if idc.create_insn(addr) &gt; 0:<br>                return True<br>        return False<br><br>    def handle_inst(self, addr, prev):<br>        if prev:<br>            self.insts[prev][&quot;next_direct&quot;] = addr<br>        if self.insts.get(addr) is not None:<br>            return None<br>        inst = {<br>            &quot;addr&quot;: addr,<br>            &quot;size&quot;: get_item_size(addr),<br>            &quot;bytes&quot;: idc.get_bytes(addr, get_item_size(addr)),<br>            &quot;op0&quot;: idc.get_operand_value(addr, 0),<br>            &quot;mnem&quot;: idc.print_insn_mnem(addr),<br>            &quot;disasm&quot;: idc.generate_disasm_line(addr, 0),<br>            &quot;is_function_head&quot;: False,<br>            &quot;next_direct&quot;: None,<br>            &quot;next_branch&quot;: None<br>        }<br>        self.insts[addr] = inst<br>        if inst[&quot;mnem&quot;] == &#39;call&#39;:<br>            # call eax with operand value not an addr<br>            # call to .data section might be shellcode<br>            if 0x1001000 &lt;= inst[&quot;op0&quot;] &lt; 0x10016000:<br>                self.trace(inst[&quot;op0&quot;], prev_branch=addr, is_function_head=True)<br>        elif inst[&quot;mnem&quot;][0] == &#39;j&#39;:<br>            if 0x1001000 &lt;= inst[&quot;op0&quot;] &lt; 0x10016000:<br>                self.trace(inst[&quot;op0&quot;], prev_branch=addr, is_function_head=False)<br>        if &#39;ret&#39; in inst[&quot;mnem&quot;] or inst[&quot;mnem&quot;] == &#39;jmp&#39;:<br>            return None<br>        return addr + inst[&quot;size&quot;]<br><br>    def trace(self, start, prev_branch=None, is_function_head=True):<br>        addr, prev = start, None<br>        while addr:<br>            # convert target area to code in IDA<br>            if not self.create_insn_force(addr):<br>                raise ValueError(f&quot;[!] Create instruction fail at {X(addr)} (start: {X(start)})&quot;)<br>            size = get_item_size(addr)<br>            bytes_ = idc.get_bytes(addr, size)<br>            op0 = idc.get_operand_value(addr, 0)<br>            mnem = idc.print_insn_mnem(addr)<br>            # magic jump<br>            if mnem == &#39;call&#39; and op0 == self.magic_function_addr:<br>                offset = int.from_bytes(idc.get_bytes(addr + 5, 4), &#39;little&#39;)<br>                addr = (addr + 5 + offset) &amp; 0xffffffff<br>                continue<br>            # skip cmp esp, xxx + jb obfuscation combination<br>            # cmp esp, 0x???????? (\x81\xfc\x??\x??\x??\x??)<br>            # cmp esp, 0x?? (\x83\xfc\x??)<br>            if bytes_[:2] == b&#39;\x81\xfc&#39; or bytes_[:2] == b&#39;\x83\xfc&#39;:<br>                self.obf_flag = True<br>                addr = addr + size<br>                continue<br>            if self.obf_flag and mnem == &#39;jb&#39;:<br>                self.obf_flag = False<br>                addr = addr + size<br>                continue<br>            # can&#39;t skip jmp<br>            # there will be two insts have the same next_direct<br>            #if mnem == &#39;jmp&#39;:<br>            #    addr = op0<br>            #    continue<br>            addr_next = self.handle_inst(addr, prev)<br>            # first inst<br>            if prev is None:<br>                self.insts[addr][&quot;is_function_head&quot;] = is_function_head<br>                if prev_branch:<br>                    self.insts[prev_branch][&quot;next_branch&quot;] = addr<br>            addr, prev = addr_next, addr<br><br>    def get_addr(self, size):<br>        addr = self.cursor<br>        self.cursor += size<br>        return addr<br><br>    def allocate(self, addr):<br>        branches = []<br>        # this stream has been allocated<br>        if self.insts[addr].get(&quot;new_addr&quot;) is not None:<br>            return<br>        while addr:<br>            inst = self.insts[addr]<br>            if inst.get(&quot;new_addr&quot;) is not None:<br>                raise ValueError(f&quot;{X(addr)} ({inst[&#39;disasm&#39;]}) from two next_direct !??&quot;)<br>            inst[&quot;new_addr&quot;] = self.get_addr(inst[&quot;size&quot;])<br>            if inst[&quot;next_branch&quot;]:<br>                branches.append(inst[&quot;next_branch&quot;])<br>            addr = inst[&quot;next_direct&quot;]<br>        # allocate local branches together<br>        for addr in branches:<br>            inst = self.insts[addr]<br>            if not self.insts[inst[&quot;head&quot;]][&quot;is_function_head&quot;]:<br>                self.allocate(inst[&quot;head&quot;])<br><br>    def patch(self):<br>        patch_bytes = {}<br>        for addr, inst in self.insts.items():<br>            inst[&quot;is_child&quot;] = False<br>        for addr, inst in self.insts.items():<br>            if inst[&quot;next_direct&quot;]:<br>                self.insts[inst[&quot;next_direct&quot;]][&quot;is_child&quot;] = True<br>        # chain the stream<br>        for addr, inst in self.insts.items():<br>            if inst[&quot;is_child&quot;]:<br>                continue<br>            head = addr<br>            while addr:<br>                self.insts[addr][&quot;head&quot;] = head<br>                addr = self.insts[addr][&quot;next_direct&quot;]<br>        # all have head<br>        for addr, inst in self.insts.items():<br>            if inst.get(&quot;head&quot;) is None:<br>                raise ValueError(f&quot;{X(addr)} no head&quot;)<br>        # allocate<br>        for addr, inst in self.insts.items():<br>            if inst[&quot;is_function_head&quot;]:<br>                self.allocate(addr)<br>                print(f&quot;[+] Create function at {X(inst[&#39;new_addr&#39;])}&quot;)<br>                # align 0x10<br>                align = 0x10 - self.cursor % 0x10<br>                patch_bytes[self.cursor] = b&#39;\xcc&#39; * align<br>                self.cursor += align<br>        # check all instructions have been allocated<br>        for addr, inst in self.insts.items():<br>            if inst.get(&quot;new_addr&quot;) is None:<br>                raise ValueError(f&quot;[!] {X(addr)} is not allocated&quot;)<br>        # relocation<br>        for addr, inst in self.insts.items():<br>            if not inst[&quot;next_branch&quot;]:<br>                continue<br>            target = self.insts[inst[&quot;next_branch&quot;]]<br>            inst[&quot;bytes&quot;] = inst[&quot;bytes&quot;][:-4] + (<br>                (0x100000000 +<br>                    target[&quot;new_addr&quot;] - (inst[&quot;new_addr&quot;] + inst[&quot;size&quot;])<br>                ) &amp; 0xFFFFFFFF<br>            ).to_bytes(4, &#39;little&#39;)<br>        # wipe old code<br>        for addr, inst in self.insts.items():<br>            ida_bytes.patch_bytes(addr, b&#39;\x90&#39; * inst[&quot;size&quot;])<br>        # actual patch<br>        for addr, inst in self.insts.items():<br>            patch_bytes[inst[&quot;new_addr&quot;]] = inst[&quot;bytes&quot;]<br>        for addr in sorted(patch_bytes.keys()):<br>            ida_bytes.patch_bytes(addr, patch_bytes[addr])<br>            self.create_insn_force(addr)<br><br>    def run(self, address):<br>        self.trace(address)<br>        self.patch()</pre><p>使用此 IDA 腳本時，使用者需根據樣本不同，自行指定以下三個參數的位址：</p><ul><li>magic_function_addr：這是圖 3 提及的特殊 jmp function，在程式碼中不斷出現。</li><li>first_avaliable_addr：這是指定 patch 的位址，建議接在 DllMain 後面，因為原本被混淆的 assembly 已經被還原，可以直接覆蓋。</li><li>執行第一個特殊 jmp function 的位址。</li></ul><pre>de = DeObfus(magic_function_addr=0x10006374, first_avaliable_addr=0x10001180)<br>de.run(0x1000A17C)</pre><h3>Yara Rules</h3><p>我們提供的 Yara Rules 為：</p><pre>rule ShadowPad_Loader_Decode: CyCraft ShadowPad APT {<br>meta:<br>    author = &quot;oalieno&quot;<br>    description = &quot;Custom decode function of ShadowPad Loader&quot;<br>    severity = 9<br>    confidence = 9<br>    sample_hash = &quot;af6d2e58163999e00d57809efe765274&quot;<br>    malware_family = &quot;ShadowPad&quot;<br><br>strings:<br>    $c1 = {<br>      8D 8C D1 46 B9 CD BB    // lea     ecx, [ecx+edx*8-443246BAh]<br>      E8 ?? ?? ?? ??          // call xxx<br>    }<br>condition:<br>    all of them<br>}</pre><p>另外，<a href="https://www.elastic.co/security-labs/update-to-the-REF2924-intrusion-set-and-related-campaigns">Elastic Seucirty Labs 亦在前述報告</a>中提供過 Yara Rules：</p><pre>rule Windows_Trojan_ShadowPad_1 {<br>    meta:<br>        author = &quot;Elastic Security&quot;<br>        creation_date = &quot;2023-01-23&quot;<br>        last_modified = &quot;2023-01-31&quot;<br>        description = &quot;Target SHADOWPAD obfuscation loader+payload&quot;<br>        os = &quot;Windows&quot;<br>        arch = &quot;x86&quot;<br>        category_type = &quot;Trojan&quot;<br>        family = &quot;ShadowPad&quot;<br>        threat_name = &quot;Windows.Trojan.ShadowPad&quot;<br>        license = &quot;Elastic License v2&quot;<br>    strings:<br>        $a1 = { 87 0? 24 0F 8? }<br>        $a2 = { 9C 0F 8? }<br>        $a3 = { 03 0? 0F 8? }<br>        $a4 = { 9D 0F 8? }<br>        $a5 = { 87 0? 24 0F 8? }<br>    condition:<br>        all of them<br>}<br><br>rule Windows_Trojan_Shadowpad_2 {<br>    meta:<br>        author = &quot;Elastic Security&quot;<br>        creation_date = &quot;2023-01-31&quot;<br>        last_modified = &quot;2023-01-31&quot;<br>        description = &quot;Target SHADOWPAD loader&quot;<br>        os = &quot;Windows&quot;<br>        arch = &quot;x86&quot;<br>        category_type = &quot;Trojan&quot;<br>        family = &quot;Shadowpad&quot;<br>        threat_name = &quot;Windows.Trojan.Shadowpad&quot;<br>        license = &quot;Elastic License v2&quot;<br>    strings:<br>        $a1 = &quot;{%8.8x-%4.4x-%4.4x-%8.8x%8.8x}&quot;<br>    condition:<br>        all of them<br>}<br><br>rule Windows_Trojan_Shadowpad_3 {<br>    meta:<br>        author = &quot;Elastic Security&quot;<br>        creation_date = &quot;2023-01-31&quot;<br>        last_modified = &quot;2023-01-31&quot;<br>        description = &quot;Target SHADOWPAD payload&quot;<br>        os = &quot;Windows&quot;<br>        arch = &quot;x86&quot;<br>        category_type = &quot;Trojan&quot;<br>        family = &quot;Shadowpad&quot;<br>        threat_name = &quot;Windows.Trojan.Shadowpad&quot;<br>        license = &quot;Elastic License v2&quot;<br>    strings:<br>        $a1 = &quot;hH#whH#w&quot; fullword<br>        $a2 = &quot;Yuv~YuvsYuvhYuv]YuvRYuvGYuv1:tv&lt;Yuvb#tv1Yuv-8tv&amp;Yuv&quot; fullword<br>        $a3 = &quot;pH#wpH#w&quot; fullword<br>        $a4 = &quot;HH#wHH#wA&quot; fullword<br>        $a5 = &quot;xH#wxH#w:$&quot; fullword<br>        $re1 = /(HTTPS|TCP|UDP):\/\/[^:]+:443/<br>    condition:<br>        4 of them<br>}</pre><h4>總結</h4><p>ShadowPad 的反鑑識與反分析特性，在初始入侵與長期潛伏階段易於躲避偵測，使其成為供應鏈攻擊事件中的一大利器。<a href="https://www.kelacyber.com/i-soon-leak-kelas-insights/">今（2024）年初中國安洵信息公司外洩的內部文件中，KELA 威脅情資研究團隊發現 ShadowPad 也赫然在列，甚且包含了 ShadowPad C2 伺服器位址</a>。由此可見，ShadowPad 與其變種惡意軟體不僅為 APT41 所愛用，更是其他中國駭客組織用以肆掠世界各國的攻擊工具。奧義智慧資安研究員撰寫的 IDA 腳本與 ShadowPad Loader 技術分析，在協助緩解此類威脅之餘，也提供了資安社群延伸研究的著力點。</p><h3>IOC：</h3><p>log.dll (md5: f4693d792c0edbcc3ed62bf8222a3aca)</p><p>log.dll.dat (md5: 60940d341c313eee08dcd7b18154ce0a)</p><h4>延伸閱讀</h4><ul><li><a href="https://www.cycarrier.com/post/shadowpad20201209">【精選威脅情資 #1】ShadowPad：Winnti Group 展開的新一波行動</a></li><li>PT ESC. (2021). “Higaisa or Winnti? APT41 backdoors, old and new.” <em>positive technologies.</em> Retrieved from <a href="https://www.ptsecurity.com/ww-en/analytics/pt-esc-threat-intelligence/higaisa-or-winnti-apt-41-backdoors-old-and-new/#id6">https://www.ptsecurity.com/ww-en/analytics/pt-esc-threat-intelligence/higaisa-or-winnti-apt-41-backdoors-old-and-new/#id6</a> (Jun 12, 2024).</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=226c637ae937" width="1" height="1" alt=""><hr><p><a href="https://research.cycraft.ai/ida-shadowpad-scatterbee-226c637ae937">透過 IDA 腳本自動破解 ShadowPad 變種的 ScatterBee 混淆手法</a> was originally published in <a href="https://research.cycraft.ai/">CyCraft Research Lab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>