eqqn Security blog

CTF write-ups

Home

Insomnihack CTF 2018

vba01-baby

The challenge:

“Help, I’ve accidentally opened an email attachment, help me find out what happened”

We are given a XLS sheet with macro enabled. worskheet_content

Nothing suspicious in the Worksheet.

At this point it is wise to proceed in a Windows VM, because macros will run as soon as the document is opened, once they are enabled. Let’s edit the macro:

Macro

Sub Workbook_Open()
    a ("Sheet1")
End Sub

Private Function a(ByVal aaaaaaaa As String) As String
    Dim aa As Integer
    Dim aaaa As String
    Dim aaaaaa As Worksheet
    Dim aaaaaaa() As String
    
    On Error GoTo e
    Set aaaaaa = Worksheets(aaaaaaaa)
    aa = 874104 / 220128
    aaa = 1
    strHex = ""
    Do While aaaaaa.Columns(aaa).Cells(aa, Int(221892 / 139112)).Value <> ""
        Do While aaaaaa.Columns(aaa).Cells(aa, Int(291792 / 189112)).Value <> ""
            aaaa = aaaa + Chr(aaaaaa.Columns(aaa).Cells(aa, 1).Value Xor ((37 Xor 12) + 1))
            aaa = aaa + Int(218526 / 213912)
        Loop
        aa = aa + Int(18526 / 13912)
        aaa = Int(199526 / 139112)
    Loop
    aaaaaaa = Split(aaaa, Chr(54 Xor 12))
    Set aaaaa = CreateObject(aaaaaaa(0))
    aaaaa.RegWrite aaaaaaa(1), aaaaaaa(2), "REG_SZ"
    Exit Function
e:
    Exit Function
End Function

Interestingly enough, the payload is generated from cells contents. VBA language is used for macros and printing the output of the function is not as straightforward, but we can direct the payload content into a cell, to see what’s happening. Looking online, you can find samples how it is done, if you are not familiar with VBA. Adding Cells(1, 1) = aaaaaaa(0) + aaaaaaa(1) + aaaaaaa(2) after regwrite, we dump the string into the first cell. Now run it!

WScript.ShellHKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
flagINS{Do_n0t_Ena8le_M4cro}

Extra