A very interesting piece of malware that targets Point of Sale systems has recently surfaced in the malware community. As a guy who frequently reverses malware that targets card data (aka. Track data), this caused me to take notice. Before I jump into the really interesting bits of the malware, I’d like to offer a few links to those that have already taken a look at this stuff. Seculert specifically were the ones that originally discovered, and named, the Dexter malware.
- Injects itself into iexplore.exe
- Ensures the iexplore.exe process restarts in the event that it is manually stopped
- Ensures persistence via writes to the ‘Run’ registry key
- Scrapes track data through a very common method
- Has a command and control structure with a remote host
That last bullet in particular really caught my eye. I can’t remember the last time I saw a piece of malware that targeted Point of Sale systems that had a nice C&C structure to it. And that is where our story really begins…
So in looking at the underlying assembly of the malware, it becomes apparent that this sample is planning on talking to as many as seven different domains. It’s also apparent that it’s going to communicate over HTTP, via a POST request. Looking at the traffic that gets generated, we see something similar to the following:
Now you might be thinking to yourself, “Geez, that’s a lot of …stuff”. And you’d be right. So lets break down that nice blob of data that’s being sent over the wire. In total, we see the following ten different variables:
I’m going to focus on the last variable (‘val’) first, mainly because it’s the easies to decode, and because it’s one of the most important. We see that ‘val’ has a value of ‘ZnJ0a2o=’, which I’m sure you’ve all guessed by now is Base64 encoded. Once decoded, we see this value change to ‘frtkj’. You might be thinking that this is also garbage, but it is, in fact, a key that is used to encode the remaining text in the POST request. Specifically, we see the following occur when each variable’s data is decoded:
- The data is Base64 decoded
- Each character in the decoded string is xored sequentially against each character of the key we previously identified. In Ruby, it looks something like this:
This results in the original content.
Know how this works, we can whip up a quick script to decode the entire string.
We can now easily determine when a number of the variable discovered actually contain.
- page: Mutex string
- ump: Track data
- unm: Username
- cnm: Hostname
- query: Victim OS
- spec: Processor type
- opt: Unknown
- view: List of all running processes on the victim
- var: Some unique string. Appears to be constant for this sample
- val: Random key that changes every time the malware restarts
So at this point we can see how the malware is communicating outbound to its master. However, that’s only half of the puzzle. How is the malware receiving commands?
Well, the answer to that question comes in the form of the response Cookie. Specifically, the malware will set the ‘response’ cookie using the same technique (only in reverse) that we just witnessed. So basically, the server takes the key from before, XORs each byte of the string against each character in the key, and Base64 encodes it. Dexter will then parse this data, and look for one of the following variables:
- update- (Updates the malware with the specified argument)
- checkin: (alters the delay between times the malware attempts to make POST requests to the master host)
- scanin: (alters the delay between times the malware scrapes memory for track data)
- uninstall (completely removes the malware)
- download- (downloads and execute the specified argument)
I should point out that each variable has to start with the character ‘$’ in order for the malware to look at it. We can see how these variables are checked in the following decompiled code:
So at this point we can get a pretty clear picture of how this malware operates over the wire. The details of how this malware has gotten on these victim machines is still unclear, but please ensure that you are taking the necessary precautions to protect your system, with a special emphasis on Point of Sale boxes. Because really, nobody wants to become Dexter’s next victim.