Sandbox Evasion Using NTP

Published: 2020-09-03
Last Updated: 2020-09-03 08:54:18 UTC
by Xavier Mertens (Version: 1)
2 comment(s)

I'm still hunting for interesting (read: "malicious") Python samples. By reading my previous diaries, you know that I like to find how attackers implement obfuscation and evasion techniques. Like yesterday, I found a Python sample that creates a thread to run a malicious shellcode[1]. But before processing the shellcode, it performs suspicious network traffic:

client = socket.socket(AF_INET, SOCK_DGRAM)
client.sendto((bytes.fromhex("1b") + 47 * bytes.fromhex("01")), ("us.pool.ntp.org",123))

Contacting an NTP server is common and does not look malicious at all. The code above will query the NTP server and extract the current time:

$ python3
Python 3.5.2 (default, Jul 17 2020, 14:04:10)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from socket import AF_INET, SOCK_DGRAM
>>> import socket
>>> client = socket.socket(AF_INET, SOCK_DGRAM)
>>> client.sendto((bytes.fromhex("1b") + 47 * bytes.fromhex("01")), ("us.pool.ntp.org",123))
48
>>> msg, address = client.recvfrom( 1024 )
>>> msg
b'\x1c\x02\x03\xe8\x00\x00\x03%\x00\x00\x0b`\xcel\x00\x83\xe2\xfb! \xf9]\xab\x0c\x01\x01\x01\x01\x01\x01\x01\x01\xe2\xfb(\x99\xaf\xf7(\xa3\xe2\xfb(\x99\xaf\xf9\x18\x82'

Then, the current time is extracted and converted by unpacking the relevant bytes:

>>> import struct
>>> import datetime
>>> datetime.datetime.fromtimestamp(struct.unpack("!12I",msg)[10] - 2208988800)
datetime.datetime(2020, 9, 3, 10, 32, 25)

The number 2208988800 corresponds to 00:00  1 Jan 1970 GMT.

Then, the script performs a "sleep(5)" instruction and, again, contacts the NTP server. Then it compares the two received timestamps:

if ((datetime.datetime.fromtimestamp((struct.unpack("!12I",msg)[10] - 2208988800)) - uWMTJmeXanwCx).seconds >= 5):

If the sleep() timeout is respected, the malicious activity will be performed otherwise, it will silently exit. Why? Because many sandboxes increase their clock to speed up the analyzis of malware that, at the opposite, implement a long pause, expecting to reach the sandbox timeout. This is a cool technique!

Another test implemented in the script is a check of the amount of CPU available:

import multiprocessing
YiSUTyJ = multiprocessing.cpu_count()
if YiSUTyJ >= 1:

The test isn't very relevant in this case because it will always succeed. All systems have at least 1 CPU ;-)

I suspect the script to be a beta version or a red-team exercise because the IP address used to grab the shellcode, is a RFC-1918 IP.

The script has a VT score of 7/58 and I uploaded it on MalwareBazaar[3].

[1] https://isc.sans.edu/forums/diary/Python+and+Risky+Windows+API+Calls/26530/
[2] https://tools.ietf.org/rfc/rfc868.txt
[3] https://bazaar.abuse.ch/sample/a8f6a74bd11b294d3b6805da9c4157f6c042acfbef4a63c54fd3b2ec7f557170/

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

2 comment(s)
ISC Stormcast For Thursday, September 3rd 2020 https://isc.sans.edu/podcastdetail.html?id=7152

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