[VBA] 從 Excel xlsm 檔中取出 VBA 巨集程式

[VBA] 從 Excel xlsm 檔中取出 VBA 巨集程式

今天收到一個新的 case,說某個 Excel .xlsm 檔有問題,

看了一下,猜測裡面有巨集 (macro),

可是要怎麼確認這件事情,以及要如何取出巨集的內容呢?

 

後來找到 python-oletools 這套工具,可以很方便的解析 Office 檔案中 VBA 的資訊~

立刻來試試看它的效果吧~

 

1. 安裝 python-oletools

用 pip 就可以安裝 python-oletools:

sudo pip install -U oletools

 

裝好的 oletools 會在 python 的 site-packages 下面,

像是我的裝好是在 /Library/Python/2.7/site-packages/oletools~

 

2. 使用 oletools 擷取 VBA 資訊 

oletools 裡面包含了許多的工具,其中 olevba 可以用來取出 VBA 的內容,

像我想取出 test.xlsm 裡的 VBA 內容的話,

可以執行 python -m oletools.olevba <filename>,例如:

testuser@localhost ~ $ python -m oletools.olevba ~/test.xlsm
olevba 0.31 - http://decalage.info/python/oletools
Flags        Filename
-----------  -----------------------------------------------------------------
OpX:MASI---- /Users/testuser/test.xlsm
(Flags: OpX=OpenXML, XML=Word2003XML, MHT=MHTML, M=Macros, A=Auto-executable, S=Suspicious keywords, I=IOCs, H=Hex strings, B=Base64 strings, D=Dridex strings, V=VBA strings, ?=Unknown)
===============================================================================
FILE: /Users/testuser/test.xlsm
Type: OpenXML
-------------------------------------------------------------------------------
VBA MACRO Module1.bas
in file: xl/vbaProject.bin - OLE stream: u'VBA/Module1'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub auto_open()
' http://excel.tips.net/T002003_Opening_an_HTML_Page_in_a_Macro.html
  Dim ie As Object
  Set ie = CreateObject("Internetexplorer.Application")
  ie.Visible = True
  ie.Navigate "www.google.com"
End Sub
-------------------------------------------------------------------------------
VBA MACRO ThisWorkbook.cls 
in file: xl/vbaProject.bin - OLE stream: u'VBA/ThisWorkbook'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
(empty macro)
-------------------------------------------------------------------------------
VBA MACRO Sheet1.cls 
in file: xl/vbaProject.bin - OLE stream: u'VBA/Sheet1'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(empty macro)
+------------+----------------------+----------------------------------------+
| Type       | Keyword              | Description                            |
+------------+----------------------+----------------------------------------+
| AutoExec   | Auto_Open            | Runs when the Excel Workbook is opened |
| Suspicious | CreateObject         | May create an OLE object               |
| IOC        | http://excel.tips.ne | URL                                    |
|            | t/T002003_Opening_an |                                        |
|            | _HTML_Page_in_a_Macr |                                        |
|            | o.html               |                                        |

 

從輸出裡可以看到 VBA macro 的內容,可以發現裡面有一個 auto_open() 函式,

因此這個 .xlsm 只要一被開啟,就會自動執行 auto_open(),

因此就會用 IE 瀏覽至 Google 網站~

 

最下面的部分還會有個分析結果,把一些比較可疑的行為標示出來,

像是有 Auto_Open() 函式,以及使用了 CreateObject() 建立 OLE 物件等等,

對於判斷這個 VBA 巨集是否是惡意病毒蠻有幫助的~

不過覺得最方便的還是可以取出 VBA 巨集內容這一點,

這樣一方面可以檢查 VBA 巨集是否有問題,一方面也可以看看別人的寫法囉~

 

(本頁面已被瀏覽過 1,830 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料