VX Reversing II, Sasser B-Virus
VX Reversing II, Sasser B-Virus
VX Reversing II, Sasser B-Virus
Abstract
The well known worm Sasser has been one of the viruses which has received more attention in the press in the
latest months. It’s author, an 18 years old student from Germany, after causing lots of troubles to many home users
and small enterprises faces up to several years of prison. Sasser is not a well programmed virus, it’s success is
entirely due to the exploit it implements, which was announced by Microsoft in one of their security bulletins. In
this paper, we will reverse Sasser.B - the second of its variants - showing how it works and also how to clean your
computer after infection.
Warning: disconnect your computer from the network while working with Sasser, you are left as the only responsible
of your mistakes.
I. Introduction
If you have read the previous paper on Virus Reversing at CodeBreakers then you have all necessary background
to beat Sasser. It’s not only surprising, but worrying too, how such a simple virus can spread through all over the
internet devastating whole networks and provoking millionaire losses to many enterprises. This stresses, yet again,
two evident facts:
This time, using an (theoretically) outdated exploit was enough to bypass all firewalls and anti-virus products.
Sasser will not be the last i-Worm making trouble, unfortunately there is another ”worm of the year” every two
or three months, nor this will be the last paper in which you will read this remarks. There is an only way of
successfully beating computer viruses, understanding them.
In this paper, we will take a close inspection at Sasser’s behaviour, showing how it infects, spreads and how to
clean it up from your computer. The article is divided in three parts: first, we unpack the virus, second, we have a
look at its imports and strings references, finally, we debug into the virus to examine how it works.
Usually, papers on malware reversing request the use of several very expansive tools. However, following this paper
just requires a debugger, anyone one will do (download Olly, which is freeware, from [1]).
As you see, this is a small self-modifying code, done to hide the offset of the seh-handler it is going to install in
the next instructions:
When installed, the packer provokes an exception writing to a non allowed offset:
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
This calls our handler, so we set a bpx there and pass the exception to Sasser:
The handler modifies a dword outside it, this is done to ensure the handler has been called. After it you can see
that it overwrites the instruction which provoked the exception with a jump, then we continue execution:
0040981D mov edx,dword ptr [esp+4] ; take pointer to the exception record
00409821 mov edx,dword ptr [edx+C] ; address where the exception took place
00409824 mov byte ptr [edx],0E9 ; write a jump
...
0040982F xor eax,eax ; continue exception
00409831 retn
Now, set a breakpoint on the address where the exception took place (which has been overwritten with a jump, as
we mentioned) and let’s continue debugging.
Note for Olly users: the seh handler hasn’t set the trap flag, having it set to TRUE when reaching the
jump it’s possibly a bug in Olly, set it to FALSE.
The packer removes the current seh and restores the registers. After it, it takes the address of kernel32.VirtualAlloc
from its imports table and reserves memory for unpacking Sasser:
Now, we are going to take profit to see the APIs the packer has imported. Just go to its Imports Table, at RVA
9024 as given in the PE-header, and you will find the following ones:
kernel32.LoadLibraryA
kernel32.GetProcAddress
kernel32.VirtualAlloc
kernel32.VirtualFree
Of course, the first two are used for importing APIs from any DLL it might need. By other hand, VirtualAlloc and
VirtualFree are simply to allocate a buffer, two of them actually, where the packed program will be decrypted.
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
00409881 push 0 ;
00409883 push eax ; 4098CD <= end of code to decrypt
00409884 push edi ; 370000 <= buffer
00409885 push esi ; 4090C5 <= start of block to decrypt
00409886 call ecx ; decrypt
Note that is evident by far what this routine does (debug into it too, it’s easy to see how it works). The next call
is this one:
What does 901C mean?. If you recall, the imports table was at RVA 9024, so chances are that this is an RVA and,
indeed, is so (the value of eax is at this point 8C, which is a common size of small imports table - multiple of the
decimal number 20, which is the size of an IMAGE IMPORT DESCRIPTOR).
901C is the RVA of kernel32.VirtualFree into the IAT of the packed virus. The virus, will examine its import table
to retrieve the address of each of its imported APIs (see above). Then, it will decrypt the string ”kernel32.dll” and
will call LoadLibraryA to get the image base of this DLL. The imports reconstruction has started:
As usual, once we have the image base of kernel32 we can start to get the addresses of each one of the APIs (from
kernel32) we are interested in. The first we retrieve is ExitProcess:
Next what?. Edx, as you can see yourself, is the pointer to the IAT. As you know, each imported DLL has a piece
of the IAT for itself, there you have a zeroe terminated array of RVAs to the names of the imported APIs.
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
If there is still another IMAGE IMPORT DESCRIPTOR to examine then we take its DLL name and call LoadLi-
braryA (this closes a cycle, we are above at the call to LoadLibraryA). To work, this algorithm needs to have a
correct OriginalFirstThunk - not a must-have in the PE-format. This can only be ensured for the packer, meaning the
reconstruction of the imports table for the virus will be done later. As you can see, in this the very first pass through
the imports reconstruction we have only got kernel32.ExitProcess, user32.MessageBoxA and user32.wsprintfA.
Again, the packer now allocates more memory calling kernel32.VirtualAlloc and starts again to decrypt there. To
know what is doing you only have to pay attention on where it writes to, check the value of edi when it does
”repne movsb” (points to the allocated buffer).
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
At this point we are going to have a look at the values pointed by ecx and esi. Esi points inside the buffer, not too
relevant, however ecx points to the imports table:
00405488 CC 55 00 00 00 00 00 00 00 00 00 00 1C 56 00 00
00405498 E0 50 00 00 00 55 00 00
00405608 77 73 70 72 69 6E wsprin
00405618 74 66 41 00 55 53 45 52 33 32 2E 64 6C 6C 00 00 tfA.USER32.dll..
00405628 00 00 47 65 74 50 72 6F 63 41 64 64 72 65 73 73 ..GetProcAddress
00405638 00 00 00 00 4C 6F 61 64 4C 69 62 72 61 72 79 41 ....LoadLibraryA
00405648 00 00 00 00 6C 73 74 72 63 70 79 41 00 00 00 ....lstrcpyA...
As you can see, the imports table is totally correct, therefore you only have to save it for later. This is quite a lame
imports protection. We will not enter into details about the imports reconstruction, the algorithm is pretty similar
to the one above but taking in account imports by ordinal and other minor stuff.
After reconstructing the imports both buffers are freed (by means of kernel32.VirtualFree) and, finally, the packer
jumps to the entry point of the virus, once all registers have been restored:
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
That’s all, unpack it yourself so you can see a clean copy of the virus.
For sure, you have heard about different modifications of the original virus. Being able to unpack it also
means being able to produce your own variant by injecting some code. When done, you have to take the
packer and protect the virus again.
In this section, we are going to have a look at the internals of Sasser, let’s start by extracting some of the the string
references:
The next, is the standard registry key where you have to add yourself for running on startup:
Software\Microsoft\Current Version\Run
FTP commands:
avserve.exe
220 OK,...
Apart from this strings one has also those ones corresponding to the imported APIs, this is what we examine next.
Let’s make a summary of the most relevant imported APIs and their (common) use in virus writing:
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
From kernel32:
From user32:
From advapi32:
1) AbortSystemShutdown the user will surely notice that the virus is running (this virus is not stealth at all),
if he tries to shutdown the computer this will stop it.
2) RegOpenKeyA, RegSetValueExA, RegCloseKey write a new entry on the registry to achieve per-session
residency. There are several possible keys to alter, the one used by this virus is too obvious.
From Winsock (actually from ws2 32, but is enough to link with Winsock ). Wsock32.dll is the DLL used for
network communication, you will need some background on the field to understand this article:
1) WSAStartup initialises winsock (gets the Winsock version installed in the current machine).
2) socket create a socket
3) connect connects your socket to a server on a given port.
4) gethostname get the name of the current machine.
5) gethostbyname get the IP of a machine given its name.
6) bind bind to a port and accept connections there.
7) accept accepts connection on a socket
8) inet addr converts a string having an IP, for example 127.0.0.1, into an in addr structure.
9) listen makes a socket to await for connections.
10) send, recv send and receive bytes from a connected socket.
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
This completes our preliminary description of the worm. Now, we are ready to study it in detail.
This part of the article is divided into three. The first, examines how Sasser infects the local machine, this is simply
achieved by coping itself to the WINDOWS directory and modifying the registry to ensure to be run on each OS
startup. The second, shows how the virus looks for new possible hosts and how it connects to them and tries to
exploit a vulnerability in one of the Windows Services, LSASS.exe. The third and last examines the serve-like
behaviour of the virus, which is able to respond to a very basic FTP-like session.
Since the virus has been coded in Visual C++ it has the standard useless calls automatically inserted by compilers
to easy up the non-programmer’s work.
Of course, we don’t need at all to debug step by step into a Visual C++ application, instead we will simply hook all
those APIs we consider dangerous (the ones we listed above). In case you prefer the lengthy, and useless, way you
will see calls to retrieve the command line, the stdin/stdout/stderr consoles,... and other meaningless calls before
you reach the relevant ones. You will see the following calls:
Next, there are several calls to play with some strings retrieved above. Finally, this ones:
In summary, the virus (apart from getting the information automatically given by Visual C++) has retrieved the
path to the current file. Now we, finally, start the viric activity:
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
The virus has created a named mutex called ’jobaka3’, this is done to prevent several instances of the virus running
on the same machine (a widely used technique). The virus initialises now its random number generator calling
GetTickCount and, next, it starts Winsock calling WSAStartup. WSAStartup retrieves the current version of Winsock
installed in the OS and fills an important structure you need to start interneting with your virus, therefore is always
the first network-oriented call. The initialisation required by the virus is now complete, note this has consisted of
the following three steps:
All worms, this is not an exception, try to ensure they will be run when the system reboots. There are many ways
of achieving per-session residence, once of the most widely used (and so less interesting) is the one chosen by
Sasser:
; First, we get the path to the current file
004020EE push 0
004020F0 call dword ptr [KERNEL32.GetModuleFileNameA]
; Next, we get the path to the windows directory (usually C:\WINNT or C:\WINDOWS)
At this point, you will see how it constructs the string ”C:\ WINDOWS\ avserve2.exe” and, as you can well
imagine, it copies itself there:
Once the virus has copied itself to a safe place (note: the Windows directory is probably one of the worst, every
sysadmin checks for changes there) it proceeds to add itself to the following registry key: Software\Microsoft\Current
Version\Run. All programs included in this key are run on startup by Windows. Needless to say, there are many
other ways to hide your virus to ensure it shall be run on startup, the one chosen by the author of Sasser is probably
the most evident. To add a value to the registry you have to first open the key, advapi32.RegOpenKey, and then
set it with advapi32.RegSetValueExA:
10
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
After this, the virus closes the key. Now, you can go to regedit and check that the new entry has been added,
remove it (and remove the copy of the virus at your Windows Directory, as well). Once the virus makes sure that
it shall be run on every re-booting of your machine it creates a new mutex, called ”JumpallsNlsTillt”. If the call
returns ERROR ALREADY EXISTS, 0B7h, the virus exits. Otherwise, the network infection starts.
At this point, Sasser has ensured it shall be run on every session. Let’s see how it spreads through the internet.
After checking that the mutex ”JumpallsNlsTillt” is not present in the system the virus will create lots of copies
of the same thread in charge of searching for new hosts and infecting them. Each thread will generate a random
IP and will try to connect there on an specific port, if the port is available the target might be exploitable. You can
see that there are two consecutive calls to CreateThread. The first thread is the server part of the virus, which shall
be examined later in the article, the second is the one that looks for new hosts. For now, we will concentrate on
the later. It’s also interesting to see that the second thread is created 128 times, this means that the virus searches
128 possible IPs in parallel. However, this considerably slows down the connection and makes the presence of the
virus pretty evident:
Before to examine these two threads let’s follow a bit more the code we have below, there is an interesting loop:
Possibly, the author of the virus saw that so many threads dealing with network connections were going to
be noticed by the user (it slows down the machine too much). Then, the user would probably try to re-boot
his machine and this would stop the virus activity. The loop above is in charge of fixing up this situation,
Advapi32.AbortSystemShutdownA will cancel every trial of re-booting. As you see, this call is done every 3
seconds. Of course, one can simply go to the TaskManager and kill the worm... this is supposed to be too difficult
for the average user, who doesn’t know which processes are running on his machine.
Hands on, let’s examine the thread which is created 128 times (we will denote it by 128-thread):
Nop out the creation of the previous thread, we will be back to it later, and let’s create the 128-thread. The entry
point of the thread is at 401EF0, see the parameters passed to kernel32.CreateThread, where we are going to set
our bpx. Apart from this breakpoint we will overwrite the instruction next to the call to kernel32.CreateThread with
an infinite loop, this way we ensure that only our thread will be run (in more complicated multi-thread applications
this is impossible).
11
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
Now, we debug to see what it does. First of all, the virus get the name of the current host., the name will be used
later to get its IP.
In my case, this name is ”myPC”, which is returned at the buffer. Now, as we mentioned above, the virus can get
the IP of the current machine:
This API returns a pointer to the IP of the host, which has to be converted to the usual format (for example,
”155.21.21.128”), Windows provides APIs for conversions to the different formats:
Now, you will see that the API returns into eax a pointer to the string ”127.0.0.1”, which is the IP i have now
(because i am NOT connected to the internet, never be connected when debugging a worm!).
The virus is going to randomly generate IPs and to try to connect them, note that this is a complete loss of time
and, indeed, makes this worm much less dangerous than it could be. However, IP enumeration has been a standard
mistake in many i-Worms.
Below this, you will see 12 calls to the same procedure. Them all,are in charge of randomising each part of the
current IP. Normally, given a valid IP, say XXX.YYY.ZZZ.TTT one would try to take nodes in the same sub-net,
this has more probability of success.
12
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
Once the new IP has been got the virus transforms it into the standard format with the help of user32.wsprintfA:
Apart from the IP you want to connect to you also need the port. Normally, when an exploit is found this requires
connecting to a given port where a service is listening (for example, this could be the FTP service, at port 21 or
the TELNET service, at port 23). The next call converts an hexadecimal value to the standard format for ports, we
will try to connect to port 445:
When you have the IP, port included, in a valid format you have to create a socket and to connect it to that IP at
the chosen port:
...
004011A3 call dword ptr [<&WS2_32.#23>] ; WS2_32.socket,
; create a socket
; (receives a handle to it)
The virus creates a standard SOCK STREAM socket for TCP/IP connection through the internet. Different protocols
need different kinds of sockets, SOCK STREAM is the most commonly used. Let’s connect the virus to the host:
Of course, since we are not connected, the call is going to fail and will return a -1. Change it to 0, which is the
success code and let’s continue with the analysis:
So, the socket is closed (which is a loss of time) and we continue looking for more hosts. First we get the path to
the current file:
13
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
Next, after working a bit with this path and with the IP we found above, we start another instance of this application
(calling kernel32.WinExec) passing as command line the path to the virus concatenated to the IP. The current instance
continues looking for more hosts.
As we have seen above, when a possible new host is found the virus calls WinExec to run itself with command
line a given IP, let’s do it ourselves passing an easy to distinguish IP, for example, ”111.11.11.111” to see what
this new instance does. Of course, we’re going to start this new instance with our debugger.
Set a bpx on all APIs and run the virus. Everything goes on as we saw above until we reach the call to
kernel32.GetLastError. If you recall, we commented above that the mutex was created to mark that another instance
of this same process is running, kernel32.GetLastError returns ERROR ALREADY EXISTS in this case and, then,
the virus exits. This, of course, means that this has to be done after the other instance of the virus has been
terminated, there we go. After creating the named mutex the virus stores the input IP address in another buffer
(you will see a call to kernel32.lstrcpyA and another one to user32.wsprintfA). This is followed by the decryption
of some of the buffers containing the data for exploiting the vulnerability into LSASS.exe, a service you will see
running in your computer at the TASK MANAGER. As we saw in the previous section of this article we have
passed as the IP address of the target the string ”111.11.11.111”. The virus needs this IP to connect to it, the IP
of a host given its name is returned by WS2 32.gethostbyname:
Since we are not connected to the Internet, change the string ”111.11.11.111” by your not-connected IP ”127.0.0.1”
and do the call (after the call, restore the string just in case the virus makes use of it later). This way, the call
retrieves a valid information. Next, you will see that it creates a socket and connects it to port 445 at the given IP
(have a look at the structure pointed by pSockAddr on the call to WS2 32.connect). As above, the call fails because
we are not connected, not a big deal, change the return to 0 (we could open this port ourselves and connect to it
then, however there is no need of complicating this any longer). Once the virus is connected it starts sending and
receiving information, this is always done with the APIs WS2 32.send and WS2 32.recv (which will always fail,
change the return to the number of sent/received bytes respectively):
Let’s see what it sends. You only have to see the parameteres at the calls, in case of calling WS2 32.send one of
them is a buffer with the sent data and another one its length (WS2 32.recv is also pretty easy, check win32.hlp
for a detailed description of the APIs).
14
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
sent (change the return to 89h after the call, you would have this value if the call would succeed):
004061CC 00 00 00 85 FF 53 4D 42 72 00 00 00 00 18 53 C8 ...ÿSMBr....XSÈ
004061DC 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FE ..............ÿ
004061EC 00 00 00 00 00 62 00 02 50 43 20 4E 45 54 57 4F .....b.BPC NETWO
004061FC 52 4B 20 50 52 4F 47 52 41 4D 20 31 2E 30 00 02 RK PROGRAM 1.0.B
...
Now, the virus calls WS2 32.recv with a buffer size of 640h bytes. The virus does not process the received bytes - you
always have to receive the bytes from the server before to send more because all protocols send acknowledgments
and stuff - and calls again WS2 32.send. This time we sent 0A8h bytes:
00406258 00 00 00 A4 FF 53 4D 42 73 00 00 00 00 18 07 C8 ...ÿSMBs....XGÈ
00406268 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FE ..............ÿ
00406278 00 00 10 00 0C FF 00 A4 00 04 11 0A 00 00 00 00 ..P..ÿ..DQ.....
...
Again, the virus receives more data, with a call to WS2 32.recv, but does nothing to them... More bytes sent (size
0DEh)...
00406304 00 00 00 DA FF 53 4D 42 73 00 00 00 00 18 07 C8 ...ÚÿSMBs....XGÈ
00406314 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FE ..............ÿ
00406324 00 08 20 00 0C FF 00 DA 00 04 11 0A 00 00 00 00 .H ..ÿ.Ú.DQ.....
00406334 00 00 00 57 00 00 00 00 00 D4 00 00 80 9F 00 4E ...W.....Ô...N
...
Immediately after this, it starts some heavy string manipulation. Among other things, it includes the IP we have
passed to it at the command line inside some buffers. For example, see the following extract, got just before running
the call at 4015FB:
0012FE2C 4C 4D 4E 4F 1E 28 F4 77 5C 5C 31 31 31 2E 31 31 LMNO.(ôw\\111.11
0012FE3C 2E 31 31 2E 31 31 31 5C 69 70 63 24 00 2E 31 31 .11.111\ipc$..11
0012FE4C 2E 31 31 2E 31 31 31 5C 69 70 63 24 00 .11.111\ipc$.
The virus, has in the buffer an IP (possibly from a previously infected target) which it substitutes by the new target
IP, ”111.11.11.111”. Note that, if this is true, one can trace back the virus to the author very easily (the telecom
companies will give immediately the phone number connected with that IP at a given time, the creation timestamp
of the avserve2.exe file will give the requested connection time).
15
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
Once this string manipulation has concluded the virus prepares to connect to port 9996. Presumably, the vulnerability
has opened this port and so the virus is able to connect there. We will not enter in details at this point, at the end,
this is a exploit and could still be profitable for some systems. Therefore, we simply assume that the virus has
prepared the code to be run in the remote host. When done, the virus creates a socket:
004017F2 push 2
004017F4 call dword ptr [<&WS2_32.#23>] ; WS2_32.socket
And connects again to port 445. Again, all the buffers we have seen above are sent but (meaning the previous time
the virus was only checking if this host was exploitable), this time, there is an additional one (which has been
created in the omitted calls) which contains the following:
0012FDBC 00 00 00 5C FF 53 4D 42 75 00 00 00 00 18 07 C8 ...\ÿSMBu....XGÈ
...
0012FDEC 5C 00 5C 00 31 00 31 00 31 00 2E 00 31 00 31 00 \.\.1.1.1...1.1.
0012FDFC 2E 00 31 00 31 00 2E 00 31 00 31 00 31 00 5C 00 ..1.1...1.1.1.\.
0012FE0C 69 00 70 00 63 00 24 00 00 00 3F 3F 3F 3F 3F 00 i.p.c.$...?????.
Note that the target IP is present there, there are also some script-like characters like ”ipc$”. More data to be sent...
we don’t cut and paste the next here due to lack of interest. After more string manipulation the virus sends a big
10FC bytes length string to the target host. Finally, another call to send more data and the virus closes this socket.
This completes this part of this article, which - as we mentioned - you yourself can extend by examining how the
exploit works (connect to your own port).
The server
Our virus, is also able to act as a elementary FTP server, it receives commands on port 5554 (ports open by trojans
and viruses frequently have numbers more or less as big as this one, the lower ones are reserved by the system)
and responds accordingly. The server part is done at the thread we omitted above, let’s see how it works.
After creating the mutex we are again at the thread creation, the first thread will start a server in the local host
(the second has already been studied).
We set an infinite loop after the call to kernel32.CreateThread, a bpx at the entry point of the thread and create it:
16
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
This thread starts by creating a new socket, with the same parameteres we used above in the other thread, then it
converts to the right format the pre-stored port number, which results into 5554.
00401E72 push 2
00401E74 call dword ptr [<&WS2_32.#23>] ; WS2_32.socket
...
00401E8E mov word ptr [ebp-14],2
00401E94 call dword ptr [<&WS2_32.#9>] ; WS2_32.ntohs
When you want to install a server in your machine you need to open one of your ports and to allow incoming
connections. This, essencially, consists of the following steps:
• Create a socket.
• Bind your socket to a local port.
• Prepare your socket to receive messages (for example, FTP commands).
At this point, since we don’t know what the virus does and we don’t want to connect to the Internet due to the
risk it involves, we have the following options:
Yes, we choose the third one (in other articles we will choose the first, the second is only good for very simple
viruses). So, you have to go to the command line and type ”telnet 127.0.0.1 5554”. This will establish connection
and you will see that the debugger is called again, WS2 2.accept has returned.
Btw: do ”netstat -na” on the command line and you will see all our open ports, in particular the one the virus has
opened. Note that, since you are not connected to the internet, the local IP will be displayed as ”0.0.0.0”. However,
you must connect to 127.0.0.1 (which is the so called loopback).
17
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
When WS2 32.accept returns the virus creates a new thread, this thread will respond to our commands. Let’s create
it and see what happens:
First, the virus sends us a typical ”ok” reply, to be exact it sends ”220 OK” (ending in a line feed, all data you
send in internet protocols ends with it):
Run it, and you will see the message on your telnet session. Now, the virus expects to receive some data. Type
”USER yourname” and press intro, this will send this data to the virus (normally, you have to send the user and
then the password, in this order). Go to the virus and run the call to WS2 32.recv, you will see that it has received
your username, check the buffer. Then, the virus sends us its acknowledgment, ”331 OK” (again, go to the telnet
session to see it). Of course, we now have to send the password, something like ”PASS yourname” (you will
see the string ”PASS” after the call to WS2 32.recv). Again, the procedure to look inside the returned data for a
given string is called, it locates ”PASS” and proceeds to send us another success code, ”230 OK”. After having
received the username and password you also have this other possible commands: PORT, RETR, QUIT (see the
string references, all possible commands are nicely grouped so everybody can easily read them). The command
”QUIT” is a bit confusing, the virus will simply reply with a ”226 OK”. Let’s go with the other commands.
The command RETR requests a copy to the virus to a given IP, this IP has to be specified through a PORT directive,
for example let’s send a ”PORT 123”. For now, the virus will return - after some string manipulation - a ”220 OK”.
Next, it shall move to await for more input. Let’s tell the virus we want to receive a copy of it at the given port,
”RETR” will do this job, send it. The virus takes the previously passed IP once formatted and will try to connect
there. Note that the routine to generate the IP from the passed one is buggy, it shall always generate - as far as we
have seen - an IP of the form XXX.XX.65538.X, which is an invalid one. Changing the destination port doesn’t
work at all, let’s try the command RETR.
First, we send an ”PORT 111” and next a RETR, the virus will try to convert the ”111.1.65538.0” to the standard
format:
Since the passed IP was invalid, 65538 ¿ 255, the call will return a -1, change this to any other value than 0,1 and
continue debugging. The virus checks the return code, it testes that this is neither INADDR NONE nor 0. Next, it
creates a socket to connect to the given IP:
18
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.
The CodeBreakers-Journal, Vol. 1, No. 1 (2004)
The call to WS2 32.connect will obviously fail, change the return to 0. As we mentioned above, the virus is going
to send itself through this connection. For this, it needs to have access to its own executable file:
00401D50 push 0
00401D52 call dword ptr [<&KERNEL32.GetModuleFileNameA>]
Finally, it reads a single byte from itself and sends it to the host we have provided. This operation repeats again
and again, until the whole virus has been transferred to the remote host. When this cycle terminates the virus awaits
for new instructions.
V. How to clean it
If you have read so far you don’t need to be said that to clean Sasser from your machine you have to:
VI. Conclusions
Sasser is quite a simple virus, programmed in Visual C++ with some elementary features that can be simply ripped
from many other viruses. However, it has the virtue of incorporating an exploit which makes it to spread quite
quickly. Well patched Operative Systems are essentially safe against this kind of i-Worms but the truth is that most
users do not want to loose their time into downloading heavy updates, this makes all Anti-Virus efforts useless.
• Creating 128 threads slows so much the machine that is evident that something strange is going on.
• Sending the virus byte by byte requires lots of unnecessary calls. Again, this slows down the connection.
• Sockets are opened and closed when no need.
• The registry key used by the virus is totally outdated.
It’s hard to believe that somebody able to find by himself one of the latest exploits, which are published in a way
that are totally impossible to reproduce for the novice, ends up coding such a poor program.
Unfortunately, Sasser is only one more of many viruses which simply incorporate an outdated exploit, they all
survive a few days but the economical damage is big enough to gain headlines in the international press. At the
time of this writing, another variant of the almost dead worm myDoom has been found in the wild.
References
[1] OllyDebugger, Available at ollydbg.cbj.net
19
Copyright c 2004 and published by the CodeBreakers-Journal. Single print or electronic copies for personal use only are permitted.
Reproduction and distribution without permission is prohibited.