# 0x0E. Powershell Deobfuscation [TOC] ## Sample Preview VT Link: https://www.virustotal.com/gui/file/261ee2ff1e9188342b6de16f1d8621e3baef4e76dbf09e9e760a5c448c0f35e6/details Download Link: https://bazaar.abuse.ch/sample/261ee2ff1e9188342b6de16f1d8621e3baef4e76dbf09e9e760a5c448c0f35e6/ SHA1: `6a863e455781a007b13fe612438156638c486a00` <br> 將樣本存成`.txt`,打開檔案看到一坨奇怪的東西, 只有一堆無法辨別的文字 ![](https://i.imgur.com/GcwBb3P.png) <br> 根據 [MalwareAnalysisForHedgehogs](https://twitter.com/struppigel/status/1438081523077500928) 的解釋 > 1. `${ }` --> these are variables, different whitespace means different variable > 2. at the end is a `|&` --> the & executes a string as command > 3. `@{ }` --> declares a hash table > 4. `$( )` --> sub-expression operator for double-quoted strings, the stuff inside is evaluated before the string is constructed <br> 看起來有點困難,但最重要的,是第二點 **executes a string as command** 代表可以在執行前,print出真正會執行的東西,就不用手動一一拆解 <br> ## First Deobfuscation 將樣本拿去Powershell ISE, 刪掉最後面執行部分 (其實是 `iex`) ![](https://i.imgur.com/nWQoTsZ.png =50%x) <br> 執行後得到以下output,注意最後面的 `iex` > iex 為 Invoke-Expression的簡寫,會執行code ![](https://i.imgur.com/g35erv3.jpg) <br> - 可以看到有許多 `[CHAR]`的code,只是單純的ASCII,範例如下 ![](https://i.imgur.com/eCTNijj.png =60%x) <br> 總之,第一層decode完畢,雖然看起來稍微好一點,但還不夠清楚,繼續下一步decode <br> ## Second Deobfuscation 直接貼上output,**並且移除最後面的 `|iex` ![](https://i.imgur.com/hMwT227.png) <br> 執行後得到結果 ![](https://i.imgur.com/bj2uvKS.png) <br> 可以看到清楚的本體還帶有少量的obfuscation像是URL,此樣本的功能也是單純的downloader ``` $url2 = 'htt'+'p://'+'35.163.'+'204.167/esfsdgh'+'frzeqsdffgfrt'+'sfd.z'+'i'+'p' $dir3 = $Mps + '\xx'+'rr'+'fff'+'ttt'+'bbb.z'+'ip' ``` <br> IOC ```35.163.204[.]167``` <br> ## Tools 樣本所使用的obfuscation tool為Invoke-Obfuscation,連結為 https://github.com/danielbohannon/Invoke-Obfuscation/blob/master/Out-EncodedSpecialCharOnlyCommand.ps1#L26 <br> [-0xbc](https://hackmd.io/@0xbc000) ###### tags: `Malware Analysis` `Reverse Engineering` `tutorials`