CVE-2024-3400: PAN-OS Command Injection Vulnerability in GlobalProtect Gateway. Learn More

CVE-2024-3400: PAN-OS Command Injection Vulnerability in GlobalProtect Gateway. Learn More

Services
Capture
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

twi-managed-portal-color
Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

twi-briefcase-color-svg
Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

tw-laptop-data
Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

twi-database-color-svg
Database Security

Prevent unauthorized access and exceed compliance requirements.

twi-email-color-svg
Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

tw-officer
Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

tw-network
Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Offensive Security
Solutions to maximize your security ROI
Microsoft Exchange Server Attacks
Stay protected against emerging threats
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
SpiderLabs Blog

Morto: More than Meets the Eye

There's been a lot of talk the past week or so about Morto. For those unfamiliar or unaware, Morto is a tricky little worm which looks for instances of Remote Desktop exposed online with weak Administrator passwords. How weak you ask? Pretty weak. I won't lie to you, if I got infected with this worm, I'd be pretty embarrassed. Which is probably why there's only about 3,000 or so infected machines last time I heard. Based on some preliminary analysis done by others, and knowing how it propagated, I figured reversing this thing would be a walk in the park. Oddly enough, there were anti-debugging tactics and other little nuances in place that, honestly, really surprised me. Two tactics in particular, while not terribly sophisticated, had enough merit that I felt it would be an interesting look for our readers at what some malware authors are doing. Before I get into the specifics, I should point out that this write-up won't be going into the details of what Morto does, or how it works. There's been plenty of great write-ups on this very topic done by both Microsoft and F-Secure (to name a couple), and I suggest taking a look at them if you're looking for this kind of information.

http://www.f-secure.com/v-descs/worm_w32_morto_a.shtml

http://www.microsoft.com/security/portal/Threat/Encyclopedia/Entry.aspx?name=Worm%3AWin32%2FMorto.A

Both of the tricks the malware authors performed were both done in the DLL, which is dropped on the infected system after the initial infection takes place. When initially opening the DLL in IDA, you can see right away that something is off. If this were a scene in the movie Inception, this would be the equivalent of jumping into a guy's dream and (spoiler alert?) having a freight train start plowing down main street.

11861_cd034c8e-4123-4116-854d-6b60876b2bae

So what's going on you ask? Well, to put it simply, a large chunk of code in DLLMain is being obfuscated somehow. Further digging shows just what's happening.

9749_6a537bd9-ae6a-42aa-9a56-c839ab121643

Breaking this code down, essentially the authors are performing a simple rotation cipher of -7 against that large chunk of code we saw earlier. So if you have a value of 0x08, that becomes 0x01, 0x15 becomes 0x0E, and so forth.

What's the really interesting part is how this -7 value is being calculated. This value is calculated based on the name of the process this DLL is being injected into. By adding the sum of every letter in the process name, ignoring the value '2', and dividing this result by 0x64, or 100 in decimal, the authors are able to determine if the DLL is being injected into the correct process or not. A quick little code snippet in ruby shows how this is done-

 

  k = 0  "regedit".each_byte {|x| k+=x }  -1 * (k / "64".hex)    => -7

If any other process tries to load this DLL, the chunk of obfuscated code will not be de-obfuscated, and none of the malicious code will execute.

The next trick was discovered by essentially staring at the code until I started to get a headache. That was, until I realized it was more likely to be allergies, and I proceeded to take what I thought was non-drowsy medication... but that's a story for another posting. While looking at the code of this DLL, I kept looking for the LoadLibrary function to get called, but it alluded me. It was right about this time that I started looking at these strange blobs of data further down in the code. There was obviously some sort of obfuscation going on, but at first glance it's hard to see exactly what's happening. The key to solving this, (and when I say key, I mean the actual key) is in this larger blob of data that shows up before everything else.

10800_9a5141c5-432f-4dec-8248-4160798a6a40
We can see that these small obfuscated strings are all being referenced from the same function. Now, if we look at the size of these obfuscated strings, it looks to me that these might be function names.

BSL_12177_dd993091-8a5b-42f8-aa28-e5b1794de679
Using this hypothesis, lets start looking for patterns. One of the big things that hits me is that every hex value in every one of these obfuscated strings shows up in that large blob of data we saw at the top. What's the significance of this you ask? Well, since everything seems to be showing up in that large blob of data, it seems to me that this might be using a substitution table. In actuality, the rotation cipher we saw earlier is also a substitution table as well. It's just a different kind. Now hopefully I'm not completely confusing you. Remember, I did say it was drowsy medication. Let's just start working through this in order to show you what process I took to figure this out.

Now first, let's take a look at this large blob of data that we think is the key-

11020_a46dc026-e99b-46d1-9658-d469170f59ea

Nothing really pops out at us, but that's OK. Let's start taking a look at this small obfuscated strings and see if any patterns show up. Now remember earlier we guessed that these might be obfuscated function names, so let's think of that in the back of our heads going forward.

8365_25813066-df8c-4917-8885-560d13f88446

Something jumps out on the top obfuscated string. Five characters, where 3+4 are the same.

11350_b4d3fcf9-bdfe-473d-bdd4-cc6e39010255
In a way it's a lot like that show Wheel of Fortune if you think about it. Well, talking about Wheel of Fortune... the word 'wheel' actually fits the bill. I'm not sure of any function name called 'wheel', but let's use it to take a shot anyways. Specifically, let's use what we think the letter 'e' is and map it up to that large blob of data.

9776_6bde159f-8af9-4037-ada2-f3eaa5f4b127

9471_5b4d85a8-93c6-4e51-8d3f-dfeda31f7092

OK, now that we've got that mapped up, we can see if the letter 'l' lines up.

9425_596f3ba1-1e32-45ef-81b2-6163fcd49e22

9416_58fa7d30-4f37-4ffa-a216-48277fb6e996
No luck there, as we were looking for 0x0D, but got 0x29 instead. However, 0x29 does line up to where the 'l' is supposed to be. So going from this, we now theoretically have _lee_. Let's see if we can use what we have to guess the other values.

11278_b14ab08a-b419-414e-a9af-94d33261051f

10833_9c059dee-23bb-4764-8358-1dcb407c01e6
Looks like the letter 'p' fits. If I were a betting man, I'd take a stab and say this is the function 'sleep', but it doesn't look like the letter 's' lines up. Well, knowing that the ASCII value of 'S' is different from 's', perhaps the first letter is simply capitalized. Let's take a stab at that and see if things line up.

8014_12ff1948-4c91-4944-b6c4-4494a006ae57

9622_63df40d2-b160-4530-bbe0-a7e778a5ecca
Nice! It looks like this might work out. Let's try some of the other small obfuscated strings, and see if we have similar luck.

11677_c52310f0-cb26-4c4f-867b-328c926a640c

And just to put our minds at ease, here's the code in the DLL which actually converts these strings via the substitution cipher (Not in it's entirety, as it's quite long).

12718_f58ec41d-07a8-4fdc-82eb-133a0effed7d
As you can see, our initial guess about these being function names appears to be correct. Using this method we can decrypt the 10-15 other methods which appear in this DLL as obfuscated garbage (at least at first glance).

This pretty much wraps up the two little tricks we saw in use while performing a static analysis on the Morto DLL. While the method of infection is relatively simplistic in nature, the authors show they still have a couple tricks, albeit not terribly sophisticated, up their sleeves.


Update 9/7/2011: Josh was trying to go to for the world record for screen shots in a blog post and forgot to include one of them. His quest is now complete. -c7five

Latest SpiderLabs Blogs

EDR – The Multi-Tool of Security Defenses

This is Part 8 in my ongoing project to cover 30 cybersecurity topics in 30 weekly blog posts. The full series can be found here.

Read More

The Invisible Battleground: Essentials of EASM

Know your enemy – inside and out. External Attack Surface Management tools are an effective way to understand externally facing threats and help plan cyber defenses accordingly. Let’s discuss what...

Read More

Fake Dialog Boxes to Make Malware More Convincing

Let’s explore how SpiderLabs created and incorporated user prompts, specifically Windows dialog boxes into its malware loader to make it more convincing to phishing targets during a Red Team...

Read More