KYE - Conficker.pdf
(
789 KB
)
Pobierz
T H E H O N E Y N E T P R O J E C T ® | KYE Paper
Know Your Enemy: Containing Conficker
To Tame A Malware
The Honeynet Project
http://honeynet.org
Felix Leder, Tillmann Werner
Last Modified: 7
th
April 2009 (rev2)
The Conficker worm has infected several million computers since it first started spreading in
late 2008 but attempts to mitigate Conficker have not yet proved very successful. In this paper
we present several potential methods to repel Conficker. The approaches presented take
advantage of the way Conficker patches infected systems, which can be used to remotely
detect a compromised system. Furthermore, we demonstrate various methods to detect and
remove Conficker locally and a potential vaccination tool is presented. Finally, the domain
name generation mechanism for all three Conficker variants is discussed in detail and an
overview of the potential for upcoming domain collisions in version .C is provided. Tools for
all the ideas presented here are freely available for download from [9], including source code.
1. INTRODUCTION
The big years of widearea network spreading worms were 2003 and 2004, the years of Blaster [1] and Sasser
[2]. About four years later, in late 2008, we witnessed a similar worm that exploits the MS08067 server
service vulnerability in Windows [3]: Conficker. Like its forerunners, Conficker exploits a stack corruption
vulnerability to introduce and execute shellcode on affected Windows systems, download a copy of itself,
infect the host and continue spreading. SRI has published an excellent and detailed analysis of the malware
[4]. The scope of this paper is different: we propose ideas on how to identify, mitigate and remove Conficker
bots.
This paper contains information about detecting and removing Conficker – either remotely, by the way it
patches the Windows server service vulnerability by which is spreads, or by identifying the malware locally
and wiping it from memory and hard drive. In addition to just describing how this can be achieved, we have
also developed software for all the mitigation methods described in this paper. All these tools are licensed
under the GPL and therefore released including source. Downloads are available from http://iv.cs.uni
bonn.de/conficker [9].
This paper is structured as follows: The rest of section 1 gives a very brief introduction about how Conficker
infects a system and how it's exploits for the Windows MS08067 vulnerability are designed to operate.
Section 2 explains the way Conficker dynamically patches the Windows server service vulnerability
following successful infection. Section 3 explains how the decentralized update procedure of Conficker.B
works, how the signatures in Conficker.A, .B, and .C are verified and why it is difficult to attack this
procedure. Section 4 describes the hooking mechanism Conficker uses to prevent infections using this attack
vector. Section 5 explains how the investigation helped to create a network scanner for infected machines.
Besides actively scanning for infected machines, infections can be enumerated passively. The generation and
usage of specific IDS patterns from Conficker's shellcode to detect infections is presented in section 6. Section
Page 1 of 23
T H E H O N E Y N E T P R O J E C T ® | KYE Paper
7 describes the domain name generation mechanism that Confickerinfected hosts are using to check for
updates on a regular basis and discusses a potential solution to the aforementioned problem based on this
knowledge. Further, it illustrates related issues in the pseudo random number generator based on a re
implementation in C. In section 8 we provide some details about the mechanisms Conficker implements to
complicate enumeration. Conficker variants .B and .C contain blacklists of some IP addresses used by
various antivirus and security companies and prevents connections to these networks. We provide some
details about the network ranges contained in those blacklists and discuss how these blacklists were created.
On infected systems it is important to disable Conficker as quickly as possible, to prevent any attempted
countermeasures against disinfection tools. Section 9 explains our disinfection tool and demonstrates the
method it uses to terminate and wipe Conficker from memory on infected hosts, while keeping the infected
system's services running. Various organizations have reported reinfection after rebooting cleansed
Conficker systems, so we have created a vaccination tool that prevents infection by Conficker variants .A, .B,
and .C. In Section 10 we explain in detail how mutexes are used in Conficker and how we exploit the use of
mutexes to create our Nonficker Vaxination tool. Besides attacking Conficker in memory and using mutexes
for vaccination, it is also possible to remove the binary file Conficker installs. Although there have been
reports that Conficker files have random names, this is not completely accurate. In section 11 we explain the
name generation mechanism and installation path of the Conficker.B and .C DLLs. As the name generation
mechanism is deterministic, this information can be used to find and remove the malicious files. In section
12, we show the impact of Conficker.C's modified domain name generation mechanism and provide
information about the potential for collisions with existing domain names that Conficker.C will attempt to
contact in April 2009. In section 13, we attempt to derive information about the designers and developers of
Conficker, based on our findings and observations to date. We conclude our work in section 14.
The original paper included a detailed explanation about issues in Conficker, which allow exploitation. The
Conficker Working Group (CWG) has requested to not include this section in this public version for various
reasons. The full paper will be published in the near future.
The tools discussed in all of this paper are all licensed under the GPL and everything presented here is freely
available for download from [9], including the source code.
1.1 CONFICKER INFECTION PROCESS
Conficker is delivered as a Dynamic Link Library (DLL), so it cannot run as a standalone program and must
be loaded by another application. A vulnerable Windows system is generally infected with the Conficker
worm via the MS08067 vulnerability, using exploit shellcode that injects the DLL into the running Windows
server service. Other possible infection vectors are accessing network shares or USB drives where the
malicious DLL is started via the rundll32.exe application. Once infected, Conficker installs itself as a
Windows service to survive reboots. It then computes domain names using a timeseeded random domain
name generator and attempts to resolve these addresses. Each resolved address is contacted and a HTTP
download is attempted. No successful HTTP download was witnessed until the middle of March 2009, at
which point security experts observed nodes that downloaded encrypted binaries from some of the
randomly generated domains.
Thinking about ways to attack Conficker's infrastructure, this DNS based update feature is obviously a
potential target. However, Conficker uses RSA signatures to validate the downloads and rejects them if the
check fails, and attacking RSA is not feasible.
1.2 CONFICKER'S SERVER SERVICE EXPLOIT
The Windows server service vulnerability allows Conficker to act as autonomously spreading malware,
which is probably the main reason for it's success. This section describes how the vulnerable function is
exploited to execute commands on the victim host. The exploit vector is a remote procedure call to the
Windows API function NetpwPathCanonicalize(), exported by netapi32.dll
over an established
server message block (SMB) session on TCP port 445. This function takes a single argument, a path string,
and canonicalizes it, e.g., aaa\bbb\..\ccc becomes aaa\ccc. However, the routine that shrinks the string
Page 2 of 23
T H E H O N E Y N E T P R O J E C T ® | KYE Paper
contains a security bug: by invoking a specially crafted path string, it is possible to move beyond the start of a
stack buffer and control the value of a function's return address (note that this is not a classical buffer
overflow where you write beyond the buffer's end). With this knowledge standard exploitation actions can
be performed. Alexander Sotirov has decompiled the relevant function and published some C code with
comments that greatly explain the problem [5].
Figure 1: Conficker's shellcode and it's structure in a path string
Conficker uses some standard PEB shellcode to load libraries and resolve function names. It is encoded using
a one byte XOR key to prevent 0bytes, which would be interpreted as string terminators. As displayed in
figure 1, the first few shellcode instructions form a decryptor stub that, upon execution, reconstructs the
original shellcode in memory. The shellcode itself loads urlmon.dll and locates URLDownloadToFile()
in it, which is a function designed to download a file from a webserver and store it on the local hard drive.
Both the DLL and function name are appended to the shellcode instructions and also covered by the XOR
encoding. The last two encoded MS bytes are used as a stop pattern to the decryptor.
Figure 2 shows a shellcode example that was caught in a honeypot in its encoded and decoded form. As the
XOR key is always 0xC4, collecting Conficker samples is fairly straight forward: it is sufficient to XOR the
whole exploit string (even with the SMB protocol information), extract the URL and download the file. These
steps are easy to automate on a honeypot itself. Nevertheless, there are some additional factors to consider.
We observed that downloading samples using wget or similar command line tools would not work for
variants later than Conficker.A, even when using a spoofed user agent string. This is because the server
would not submit the binary but instead returns a stream of lowercase characters. We haven't looked into the
corresponding code parts yet, but there appears to be some kind of browser identification functionality
within Conficker that goes beyond simple user agent string comparison. The solution is to behave exactly
like an exploited system, so we wrote our own small downloader that uses URLDownloadTofile(), cross
compiled it on Linux and ran it in wine to retrieve the samples.
e8 ff ff ff ff c2 5f 8d 4f 10 80 31 c4 41 66 81 |......_.O..1.Af.| 2c 3b 3b 3b 3b 06 9b 49 8b d4 44 f5 00 85 a2 45 |,;;;;..I..D....E|
39 4d 53 75 f5 38 ae c6 9d a0 4f 85 ea 4f 84 c8 |9MSu.8....O..O..| fd 89 97 b1 31 fc 6a 02 59 64 8b 41 2e 8b 40 0c |....1.j.Yd.A..@.|
4f 84 d8 4f c4 4f 9c cc 49 73 65 c4 c4 c4 2c ed |O..O.O..Ise...,.| 8b 40 1c 8b 00 8b 58 08 8d b7 a1 00 00 00 e8 29 |.@....X........)|
c4 c4 c4 94 26 3c 4f 38 92 3b d3 57 47 02 c3 2c |....&<O8.;.WG..,| 00 00 00 50 e2 f8 8b fc 56 ff 17 93 83 c6 07 e8 |...P....V.......|
dc c4 c4 c4 f7 16 96 96 4f 08 a2 03 c5 bc ea 95 |........O.......| 18 00 00 00 33 d2 52 52 8b cc 66 c7 01 78 2e 51 |....3.RR..f..x.Q|
3b b3 c0 96 96 95 92 96 3b f3 3b 24 69 95 92 51 |;.......;.;$i..Q| ff 77 04 52 52 51 56 52 ff 37 ff e0 ad 51 56 95 |.w.RRQVR.7...QV.|
4f 8f f8 4f 88 cf bc c7 0f f7 32 49 d0 77 c7 95 |O..O......2I.w..| 8b 4b 3c 8b 4c 0b 78 03 cb 33 f6 8d 14 b3 03 51 |.K<.L.x..3.....Q|
e4 4f d6 c7 17 cb c4 04 cb 7b 04 05 04 c3 f6 c6 |.O.......{......| 20 8b 12 03 d3 0f 00 c0 0f bf c0 c1 c0 07 32 02 | .............2.|
86 44 fe c4 b1 31 ff 01 b0 c2 82 ff b5 dc b6 1f |.D...1..........| 42 80 3a 00 75 f5 3b c5 74 06 46 3b 71 18 72 db |B.:.u.;.t.F;q.r.|
4f 95 e0 c7 17 cb 73 d0 b6 4f 85 d8 c7 07 4f c0 |O.....s..O....O.| 8b 51 24 03 d3 0f b7 14 72 8b 41 1c 03 c3 8b 04 |.Q$.....r.A.....|
54 c7 07 9a 9d 07 a4 66 4e b2 e2 44 68 0c b1 b6 |T......fN..Dh...| 90 03 c3 5e 59 c3 60 a2 8a 76 26 80 ac c8 75 72 |...^Y.`..v&...ur|
a8 a9 ab aa c4 5d e7 99 1d ac b0 b0 b4 fe eb eb |.....]..........| 6c 6d 6f 6e 00 99 23 5d d9 68 74 74 70 3a 2f 2f |lmon..#].http://|
fd f5 ea f5 ea f6 f0 f7 ea f6 f4 f0 fe fc f4 eb |................| 39 31 2e 31 2e 32 34 33 2e 32 30 34 3a 38 30 2f |91.1.243.204:80/|
a9 a5 b1 a8 c4 4d 53 |.....MS| 6d 61 75 6c 00 89 97 |maul...|
Figure 2: Encoded and decoded shellcode sample
One interesting aspect is a slight change in the shellcode that was observed in recorded exploits. It was
probably introduced by Conficker version .B (see the next section for a discussion on versions and names):
One of the first decoded assembly instructions is the SLDT instruction (Store Local Descriptor Table) which is
widely used in malware for virtual machine detection. Because the result is not used, we assume that the
only purpose of this additional instruction is to evade analysis. When this was first observed, the SLDT
instruction was not implemented in the libemubased sctest utility [16], and analyzing the shellcode with
libemu
was therefore not possible. However, adding the SLDT instruction to libemu
was fairly easy, which
means that this evasion mechanism no longer evades sctest. The SRI technical report contains an example of
sctest's
output for Conficker's shellcode [4] that was generated after the SLDT instruction was added to
libemu.
Page 3 of 23
T H E H O N E Y N E T P R O J E C T ® | KYE Paper
1.3 NAMING
The different sample naming schemes used by different antivirus companies often leads to malware naming
confusion. For Conficker, the most prominent naming scheme is appending a letter so that .A indicates the
first version, .B the second and so on. In this paper, we distinguish between different Conficker versions
based on the mutexes they create. Each Conficker version installs a couple of named mutexes during startup,
to make sure that older version of the code are not run. This is achieved by registering all previous mutex
names plus an additional mutex with a different name in each version. If mutex creation fails, this indicates
that another Conficker version is already running which is at least as recent as the one currently being
executed. We observed three different mutex installation routines, corresponding to three Conficker variants
that we call .A, .B, and .C. Although some researchers refer to versions .D or .B++, our naming convention
matches the most common agreement. However, while Conficker is definitely a sophisticated piece of
malware, there seems to be a flaw in it's mutex generation mechanism mechanism. We assume that the
Conficker authors made a mistake that effectively renders the concept of using mutual exclusion useless. We
will discuss the mutexes in more detail in section 10.1.
2.
THE
NetpwPathCanonicalize()
HOOK
It is quite common in modern malware to patch a vulnerability after successful exploitation, to prevent other
malware from also infecting the compromised system. Conficker attempts the same approach by hooking
itself into the vulnerable function NetpwPathCanonicalize() and intercepting corresponding incoming
remote procedure calls. This hook replaces the first couple of bytes of the function's instructions with a JMP
instruction to redirect execution to Conficker's own code . The purpose of the hook will be explained later.
The following figure compares the first instructions of the original function to the hooked one (taken from an
English Windows XP SP2 without any updates installed and infected with Conficker.C):
5B86A259 8BFF MOV EDI,EDI 5B86A259 E9 A0B028A6 JMP 01AF52FE
5B86A25B 55 PUSH EBP
5B86A25C 8BEC MOV EBP,ESP
5B86A25E 53 PUSH EBX 5B86A25E 53 PUSH EBX
5B86A25F 8B5D 14 MOV EBX,DWORD PTR SS:[EBP+14] 5B86A25F 8B5D 14 MOV EBX,DWORD PTR SS:[EBP+14]
5B86A262 56 PUSH ESI 5B86A262 56 PUSH ESI
5B86A263 57 PUSH EDI 5B86A263 57 PUSH EDI
5B86A264 33FF XOR EDI,EDI 5B86A264 33FF XOR EDI,EDI
5B86A266 3BDF CMP EBX,EDI 5B86A266 3BDF CMP EBX,EDI
5B86A268 0F85 8EDE0000 JNZ NETAPI32.5B8780FC 5B86A268 0F85 8EDE0000 JNZ NETAPI32.5B8780FC
Figure 3: Unpatched and patched version of NetpwPathCanonicalize()
As we can see, the JMP instruction takes 5 bytes (1 byte for the opcode plus a 4 bytes address), so only the
first 5 bytes of the original function are modified. Conficker needs to know where the next unmodified
instruction starts in order to save all (partially) overwritten instructions in a different location, otherwise
execution could land in the middle of an instruction and cause errors. It has to ensure that all overwritten
instructions are completely copied and that execution is resumed at the next unmodified original instruction.
This is achieved by parsing the instructions with mlde32, a Micro LengthDisassembler Engine 32 [6], that is
included in the code. This disassembler is called in a loop, and the length values are added up until the
identified instructions provide enough room for the patch (e.g., the JMP as in figure 3). In fact, the hook
installer routine is implemented generically to work with arbitrary target functions and hooking instructions.
Conficker.C hooks a couple of other functions in different DLLs using the same method. Table 1 contains a
list that we extracted from one of the samples. Which of these functions are hooked depends on the way the
library was loaded. For instance, if the DLL was injected into svchost.exe by the server service
vulnerability shellcode, it only hooks NetpwPathCanonicalize(). If an infected system is rebooted, the
svchost process that provides a DNS caching service to other applications is also hooked too. The purpose of
these hooks is to filter out name resolution attempts for a list of antivirus and security vendor sites whose
names are embedded in the malware. You can easily verify this effect by attempting to load a web page for
one such domain in a web browser. If the name resolution fails in the browser but a command line nslookup
works for the target domain, the Conficker hook is probably active. For now, a more detailed analysis of the
hooking routines is beyond the scope of this paper, but may be added in later versions.
Page 4 of 23
T H E H O N E Y N E T P R O J E C T ® | KYE Paper
DLL
dnsapi.dll
Function
DnsQuery_A
DnsQuery_UTF8
DnsQuery_W
Query_Main
netapi32.dll
ntdll.dll
wininet.dll
ws2_32.dll
NetpwPathCanonicalize
NtQueryInformationProcess
InetnetGetConnectedState
sendto
Table 1: Functions hooked by Conficker.C
3. HOOKING INTO THE DECENTRALIZED UPDATE PROCESS
Conficker.B contains a routine to update itself by scanning incoming exploitation attempts from other
infected machines and downloading the new malware binaries from the attacker. If the \..\ pattern was
found in the path argument to a NetpwPathCanonicalize() request, it is not only blocked. Instead, the
path is compared against the shellcode template to check whether the request belongs to an exploit sent by
another Conficker infected computer. This is possible because of the static shellcode design. Figure 4 shows
the decryption loop, a simple bytewise XOR with the constant key 0xC4 (the first box). After that, the routine
tries to locate an occurrence of the substring http://, which, in case of a valid exploit, would point to a
sample download URL. If found, the download is performed and the running Conficker code is updated on
the fly to the newer version.
Figure 4: Shellcode decryptor and URL finder
Page 5 of 23
Plik z chomika:
WMatrixie
Inne pliki z tego folderu:
The Art of Computer Virus Research & Defense.chm
(6868 KB)
Computer Viruses - From Theory to Applications.pdf
(2727 KB)
Black Book of Viruses and Hacking.pdf
(1420 KB)
The Giant Black Book of Computer Viruses.pdf
(5906 KB)
Bavarian Trojan for non-Germans.html
(26 KB)
Inne foldery tego chomika:
Advanced
Attack
Basics
BlackHat
Clickjacking
Zgłoś jeśli
naruszono regulamin