Advanced Malware Analysis - Christopher Elisan
Advanced Malware Analysis - Christopher Elisan
the Author
Christopher C. Elisan is a veteran of the security industry, having started his career
straight out of college in the 1990s. He is a seasoned reverse engineer and malware
researcher. He has seen malware develop from the DOS days to the more complicated and
sophisticated malware we see today. He is currently the Principal Malware Scientist and
senior manager of the Malware Intelligence Team at RSA, The Security Division of EMC.
Elisan is a pioneer of Trend Micro’s TrendLabs, where he started his career as a
malware reverse engineer. There, he held multiple technical and managerial positions.
After leaving Trend Micro, he joined F-Secure. He built and established F-Secure’s Asia
R&D and spearheaded multiple projects that included vulnerability discovery, web
security, and mobile security. He then joined Damballa, Inc., as a senior threat analyst
specializing in malware research. Elisan graduated with a Bachelor of Science Degree in
Computer Engineering and holds the following industry certifications: Certified Ethical
Hacker, Microsoft Certified Systems Engineer, Microsoft Certified Systems
Administrator, Microsoft Certified Professional, and Certified Scrum Master.
Elisan is considered one of the world’s subject-matter experts when it comes to
malware, digital fraud, and cybercrime. He lends his expertise to different law
enforcement agencies, and he provides expert opinion about malware, botnets, and
advanced persistent threats to leading industry and mainstream publications, including
USA Today, San Francisco Chronicle, SC Magazine, InformationWeek, Fox Business, and
Dark Reading. He is a frequent speaker at various security conferences around the globe,
including RSA Conference, SecTor, HackerHalted, TakeDownCon, Toorcon, (ISC)2
Security Congress, Rootcon, and B-Sides. He also authored Malware, Rootkits & Botnets:
A Beginner’s Guide.
When he is not dissecting or talking about malware, Elisan spends time with his kids
playing basketball and video games. He also enjoys watching with his family the Atlanta
Hawks beat the hell out of their opponents. If time permits, he lives his rockstar dream as
a vocalist/guitarist with his local rock band in Atlanta.
You can follow him on Twitter: @Tophs.
Copyright © 2015 by McGraw-Hill Education. All rights reserved. Except as permitted
under the United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a data base or retrieval
system, without the prior written permission of the publisher, with the exception that the
program listings may be entered, stored, and executed in a computer system, but they may
not be reproduced for publication.
ISBN: 978-0-07-181975-6
MHID: 0-07-181975-4
The material in this eBook also appears in the print version of this title: ISBN: 978-0-
07181974-9, MHID: 0-07-181974-6.
eBook conversion by codeMantra
Version 1.0
All trademarks are trademarks of their respective owners. Rather than put a trademark
symbol after every occurrence of a trademarked name, we use names in an editorial
fashion only, and to the benefit of the trademark owner, with no intention of infringement
of the trademark. Where such designations appear in this book, they have been printed
with initial caps.
McGraw-Hill Education eBooks are available at special quantity discounts to use as
premiums and sales promotions or for use in corporate training programs. To contact a
representative, please visit the Contact Us page at www.mhprofessional.com.
Information contained in this work has been obtained by McGraw-Hill Education from
sources believed to be reliable. However, because of the possibility of human or
mechanical error by our sources, McGraw-Hill Education, or others, McGraw-Hill
Education does not guarantee the accuracy, adequacy, or completeness of any information
and is not responsible for any errors or omissions or the results obtained from the use of
such information.
TERMS OF USE
This is a copyrighted work and McGraw-Hill Education and its licensors reserve all rights
in and to the work. Use of this work is subject to these terms. Except as permitted under
the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you
may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative
works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or
any part of it without McGraw-Hill Education’s prior consent. You may use the work for
your own noncommercial and personal use; any other use of the work is strictly
prohibited. Your right to use the work may be terminated if you fail to comply with these
terms.
THE WORK IS PROVIDED “AS IS.” McGRAW-HILL EDUCATION AND ITS
LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE
ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE
OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT
CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE,
AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill
Education and its licensors do not warrant or guarantee that the functions contained in the
work will meet your requirements or that its operation will be uninterrupted or error free.
Neither McGraw-Hill Education nor its licensors shall be liable to you or anyone else for
any inaccuracy, error or omission, regardless of cause, in the work or for any damages
resulting therefrom. McGraw-Hill Education has no responsibility for the content of any
information accessed through the work. Under no circumstances shall McGraw-Hill
Education and/or its licensors be liable for any indirect, incidental, special, punitive,
consequential or similar damages that result from the use of or inability to use the work,
even if any of them has been advised of the possibility of such damages. This limitation of
liability shall apply to any claim or cause whatsoever whether such claim or cause arises
in contract, tort or otherwise.
To my family, Kara, Sebastian, and Noah, for their love, support, and understanding, and
to all security practitioners who always strive to be better than they currently are.
Contents at a Glance
Foreword
Acknowledgments
Introduction
Part I Malware Blueprint
F irst, I would like to thank God for this blessing. Second, I would like to thank all
the people who were involved in one way or another in the creation of this book:
Amanda Russell, Brandi Shailer, Melinda Lytle, Wendy Rinaldi, and Amy
Jollymore. Special thanks go out to Meghan Manfre for seeing the book through;
Meghan’s support, patience, and understanding were instrumental in finishing this book.
And thanks to Jong Purisima for sharing his views and expertise as technical editor of this
book.
Thank you to Amit Yoran, President of RSA, for writing the foreword of this book. I
really appreciate him taking time out of his busy schedule to share his thoughts about this
book. A big thank you goes out to my colleagues, Rotem Salinas and Ahmed Sonbol, for
their contribution in the laboratory part of this book.
Specifically, thanks to Rotem Salinas for sharing his knowledge in malware analysis
through the following labs:
Manually Unpacking a Packed Malware
Analyzing a User Mode Rootkit
Analyzing a Kernel Mode Rootkit
Also, thanks to Ahmed Sonbol for sharing his experience in Cuckoo through this lab:
Installing and Configuring Cuckoo
Rotem Salinas is a security researcher on RSA’s FirstWatch Team. His work focuses on
reverse engineering malware and research-oriented development of tools for this purpose.
You are most likely to find him coding in Python, C++, Assembly, and .NET. Rotem has
spoken at security conventions such as RSA Conference 2015 and RSA Global Summit
2014.
Ahmed Sonbol is a senior technologist at RSA, The Security Division of EMC. He
focuses on malware analysis and reverse engineering. Ahmed has years of experience in
writing log and network parsers for different RSA products. He holds a Master of Science
Degree in Computer Science from Northeastern University in Boston and a Bachelor of
Science Degree in Computer Science and Automatic Control from Alexandria University
in Egypt.
About the Technical Editor
Jong Purisima has been around threats and malware since he analyzed his first malware
in 1995. He started his affiliation with the computer security industry by being part of the
Virus Doctor Team at Trend Micro, where he analyzed malware to generate detection,
remediation, and customer-facing malware reports. Throughout his decade-long stint at
Trend Micro, he wore various hats, but the common theme was to deliver technologies,
services, and solutions from TrendLabs to Trend Micro customers. Jong then joined
Webroot Software as a core technology product manager, managing Webroot’s anti-
malware and URL filtering engines, as well as OEM relationships. He then later joined
GFI Software’s Security Business Unit as an anti-malware lab manager, leading a global
team of 100 in the sourcing, processing, and publishing of anti-malware signatures for the
VIPRE product line.
He currently works as a product manager in Cisco’s Security Business Group. During
his free time, Jong keeps himself busy as an amateur handyman, and loves woodworking
and taking road trips, during which he stops and takes photos at “Welcome to _____!”
state signs with his family.
Introduction
This book is a labor of love. I hope that it adds value to your endeavor of becoming the
best malware researcher that you can be.
S o you want to learn how to analyze malware? Well, you picked up the right book.
But before I go into the meat of analyzing malware, it is important to know and
understand several things that will be key in effectively analyzing malware.
This chapter will get you started on the right path to malware analysis by establishing
the needed foundational knowledge to effectively analyze malware.
The chapter will tackle the two types of malware analysis, as well as its purpose, its
limitations, and the malware analysis process itself. The chapter will then conclude by
discussing what is needed to become an effective malware analyst.
Malware Analysis
Malware analysis is the process of extracting information from malware through static
and dynamic inspection by using different tools, techniques, and processes. It is a
methodical approach to uncovering a malware’s main directive by extracting as much data
from malware as possible while it is at rest and in motion.
LINGO
A malware at rest is a malware that is not running in a target environment,
while a malware in motion is a malware that is running in a target environment.
Data is extracted from malware through the use of data extracting and monitoring tools.
The techniques and processes needed to successfully gather data from malware differ
depending on the malware’s capability; they adapt to the changing malware landscape.
This is why malware analysis is considered an art. The tools are your paintbrushes, the
techniques and processes are your drawing style, and the malware is your subject. How
effectively you use those tools and how well the techniques and processes are applied and
refined will reflect how well the malware subject is pictured. It’s a picture you create to
show the malware’s true identity stripped of all its protective mechanisms and revealing
only its darkest and deepest malicious directive. The artist becomes better at her craft
through practice and by gaining knowledge, skills, and experience as time goes by. The
same concepts apply to the malware analyst and researcher. With continuous practice and
exposure to different malware, the malware analyst becomes more knowledgeable,
skillful, and experienced.
Static Analysis
Static analysis is the process of extracting information from malware while it is not
running. Typically, malware is subjected to different static analysis tools, which will be
detailed in succeeding chapters of the book that are designed to extract as much
information as possible from the malware. The information that is collected can range
from the simplest, such as the malware’s file type, to the most complicated, such as
identifying maliciousness based on non-encrypted code or strings found in the malware.
Static analysis is the easiest and least risky malware analysis process. It is the easiest
because there are no special conditions needed for analysis. The malware is simply
subjected to different static analysis tools. It is as easy as clicking some buttons or using a
command line. It is less risky because the malware is not running during static analysis;
therefore, there is no risk of an infection occurring while analysis is taking place.
Another thing that makes static analysis less risky is the availability of tools in other
operating system, such as Linux, that can be used to statically extract information from
Windows files. Statically inspecting a malware in an operating system where the subject
malware is not intended to execute eliminates the malware’s ability to run and wreak
havoc in the system.
But not all static analysis tools that Windows offers have a counterpart or equivalent
tool in other operating systems. This leaves the researcher no choice but to use those
Windows-based tools. If this is the case and just an added precaution, Linux-based
systems can still be used to run Windows-based static analysis tools by using WINE in
Linux. WINE is short for Wine Is Not an Emulator. WINE makes it possible to run
Windows programs under Linux-based systems, such as Ubuntu and Debian. WINE acts
as a middleman and translator between the Windows-based program and the Linux-based
operating system.
TIP
Using WINE in Linux to run Windows static analysis tools also means that the
subject malware can run using WINE. Utmost care must still be practiced at all
times even if the malware’s capability is limited because of the absence of some
aspects of Windows that the malware needs to achieve its directive.
Static analysis is considered to be a low-risk, low-reward process. It is low risk, but it
yields less promising results because information gathering is based solely on what can be
seen while the malware is inactive. The information gathered is limited and does not
reveal that much about the malware’s directive. Most of the time, malware reveals its true
nature only while it is running.
Dynamic Analysis
Dynamic analysis is the process of extracting information from malware while it is
running. Unlike the limited view static analysis provides of the malware being analyzed,
dynamic analysis offers a more in-depth view into the malware’s functions because it is
collecting information while the malware is executing its functions and directives.
To conduct dynamic malware analysis, two things are needed:
Malware test environment
Dynamic analysis tools
A malware test environment is a system where malware is executed for the purpose of
analysis. It is designed to satisfy most, if not all, of the conditions for a malware to run. It
must consist of an operating system that the malware is written for and must have most, if
not all, of the dependencies the malware needs to execute properly.
Dynamic analysis tools, also known as system monitoring tools, are the ones
monitoring the malware test environment for any changes made by the malware to the
target system. Some of the changes that are monitored and recorded include changes in the
file system, modifications in configuration files, and any other relevant changes that are
triggered by the malware’s execution. The dynamic analysis tools also monitor inbound
and outbound network communications and any operating system resources used by the
malware. With these tools, the analyst is able to understand what the malware is trying to
do to the target system.
A fully implemented malware test environment with the appropriate dynamic analysis
tools is also known as a malware sandbox. A malware sandbox is where an analyst can run
and observe a malware’s behavior. A malware sandbox can be a single system or a
network of systems designed solely to analyze malware during runtime.
LINGO
Malware sandbox, malware test environment, and dynamic analysis lab are
different names given to a system where malware is executed for the purpose of
analysis.
Unlike static analysis, dynamic analysis is a high-risk, high-reward process. The risk of
infection or something wrong happening is high because the malware is running; the
reward is high because the malware reveals more of itself during execution. But do not let
the high-risk part of dynamic analysis scare you because this is manageable and just takes
common sense. There are precautions that can be taken to minimize if not completely
eliminate any risk of infection. One of them is to make sure that the system used for
dynamic analysis is fully isolated from any production systems and network. I’ll talk more
about dynamic analysis precautions in Chapter 8 once we start explaining how to build
your own dynamic analysis lab or malware test environment.
Figure 1-2 Number of malware discovered from 1984 to 2014. (Source: AV-Test.ORG.)
As of June 16, 2014, the number of malware that has been discovered is about 230
million. This equates to about 1.4 million unique malware samples per day, and that is
already about 50 million more than all malware discovered in 2013. Note that this is
discovered malware. It does not account for malware that has not been discovered yet.
There could be millions more out there that is still enjoying the luxury of not being found.
With this fact, manual malware analysis is not feasible anymore. It does not scale to
handle this amount of malware, and even if all the researchers in the world combined to
tackle this amount of malware on a daily basis, our efforts would still not be enough. This
is why the process of malware analysis became automated. Manual malware analysis is
now called upon only when a malware is considered noteworthy or if the automated
malware analysis systems are not able to produce any results.
An automated malware analysis system consists of multiple malware test environments
or malware sandboxes. Malware samples are thrown at these sandboxes, where the
malware is executed and monitored for a specific amount of time. As mentioned in the
previous section, this can range from 30 seconds to a few minutes. The more sandboxes
there are, the more malware the automated system can process. The processing is done in
parallel, so if an automated system has 10 sandboxes and each is configured to run
malware in 30 seconds, then it can process 10 malware in 30 seconds, which equates to
28,800 malware processed per day (assuming an ideal situation where each system is
utilized and there is no downtime).
LINGO
Automated malware analysis systems are also known as automated sandbox
systems or simply sandbox. The term sandbox is widely used to describe
automated systems because it is expected that a sandbox is always part of an
automated malware analysis system.
Static analysis complements dynamic analysis. I cannot stress this enough, but
unfortunately some automated malware analysis systems do not utilize static analysis and
proceed directly to dynamic analysis. In my humble opinion, this is a waste of sandbox
resources. Static analysis is still needed not only to gather static information from malware
but also to provide intelligence to the whole automated malware analysis system. One of
the ways it does this is by determining whether the malware needs a special sandbox
implementation. For example, if the analyst has different sandbox flavors and
implementations, it is important to know which of those flavors and implementations will
work well for the malware. This intelligence can be provided by static analysis. So instead
of subjecting the malware blindly to the next available sandbox, the automated system,
through the intelligence provided by the static analysis, can assign the malware to the
appropriate sandbox, thus increasing the chances of a successful dynamic analysis session.
Figure 1-3 shows an automated sandbox implementation taking advantage of static
analysis.
Patience
Malware analysis is not for those who get frustrated easily. As a malware analyst, you
have to understand that analyzing malware will not always go the way you want it to go.
There will be hiccups along the way. There will be unforeseen circumstances and
challenges that might slow you down. Your limits and patience will be tested. But the key
here is to recognize that this will happen, and you have to prepare yourself for it. There
will be instances wherein nothing is going right and no data is being extracted from the
malware. If this happens, you need to pause for a bit and give yourself some time to relax
and then start tinkering again. Do not be afraid to try different things, different tool
combinations, or different methods. Malware analysis is an art after all.
TIP
It is important to remember that malware analysis is not a set process, wherein
you just follow a series of steps and arrive at your destination. Nothing is set in
stone. Every malware analysis case can be different. The best thing to do is to
recognize patterns of analysis so you can apply them as a mental template when
faced with a malware analysis problem.
Recap
Malware analysis is a fun and exciting activity. The joy of discovering a new malware
technology and using it against the malware can be an overwhelmingly good feeling. This
chapter introduces malware analysis to the reader. It is aimed to warm you up before your
journey into malware analysis. It serves as a brief introduction into malware analysis.
In this chapter, I discussed the two types of malware analysis, which are the following:
Static analysis
Dynamic analysis
I then proceeded to discuss the purpose of malware analysis, which includes the
following:
Preventing the spread of malware
Detecting the presence of malware
Remediating the malware infection
Conducting advance malware research
Producing actionable intelligence
Understanding how the malware operates enables you to achieve all of these.
You also recognized the fact that malware analysis has its limitations, which I
described so you fully understand what malware analysis can and cannot do.
I also touched on the two types of malware analysis process, which are the following:
Manual malware analysis
Automated malware analysis
I gave an overview of each process and discussed how each of them can be used to
your advantage in solving the malware problem in general.
Then I concluded by discussing the characteristics or needed knowledge, skills, and
attitude of an effective malware analyst. I summarized them as follows:
Familiarization with malware
Familiarization with analysis tools
Patience
Now let’s begin.
1 Malware, Rootkits & Botnets by Christopher C. Elisan, published by McGraw-Hill.
CHAPTER
2
Malware Taxonomy
T he first part of your journey into malware analysis is to understand the nature of
malware, including why it exists and what its purpose, directive, and primary
function are. Understanding all of these topics will help you get to the core of the
malware’s behavior, which is the main goal of analyzing malware.
The first step in accomplishing this is to understand the different classes of malware.
This is where malware taxonomy comes into the picture. Malware taxonomy is the
process of classifying malware into different groups using a systematic approach based on
its characteristics or attributes. It results in well-organized groups of malware with
recognizable relationship patterns. Becoming familiar with these patterns enables you to
identify specific malware that belongs to a certain class. It also leads to the discovery of a
new and unknown class of malware, especially if the characteristics or attributes of the
newly discovered malware do not fit any of the known classes. Familiarization with
different classes of malware helps you predict malware behavior based on patterns of
characteristics or attributes that are revealed during the stages of analysis. If this gathered
data is similar to a certain class of malware, it will be easy for you to conclude what the
malware’s main directive is. In this instance, you save time and effort by not going
through the other steps of analysis because what you need to know was already revealed
by the patterns you found.
In this chapter, I will discuss the different classes of malware and how each class
differs from the others. I will highlight the main functionalities and directives so you can
better understand each malware class.
Malware Classes
Malware has been classified in different ways. Classifications include target operating
system (OS), such as Windows, OS X, or Unix; target device, such as mobile devices or
desktop devices; vector dependencies; spreading mechanisms; type of victims; and more.
Each of these taxonomy methods serves a purpose. It may be a specific purpose or
something that covers a wide range of needs. An analyst who wants to eliminate or
mitigate a malware’s infection vector might be interested in classifying malware based on
vector dependencies and spreading mechanisms, while someone who wants to build a
computing infrastructure might be more interested in classifying malware based on target
OS, target device, and type of victims the malware is after. In most cases, an
understanding of all these classes is needed to secure an organization.
In this book, I will classify malware based on its behavior. The categories are as
follows:
Infectors
Network worms
Trojan horses
Backdoors
Remote-access Trojans
Information stealers
Ransomware
Scareware
Fakeware
Greyware
It is important to note that malware does not neatly fall into just one category. The
attackers do not write malware to stick to one class alone or follow strictly the description
of a specific class. This is not their concern. Their main concern is for malware to execute
based on their directive. If achieving the attacker’s directive means creating a malware
that infects files to spread, which is classified as an infector, and with backdoor capability,
then so be it. In reality, therefore, most malware will exhibit two or more of the behaviors
in the previous list. This reality can pose a challenge in classifying malware. To solve this,
researchers and the industry at large moved to classify malware based on class priority.
The classes listed previously are based on priority, with infectors being the highest priority
and greyware being the lowest. This is the common practice in the industry.
To better illustrate this, let’s take two imaginary malware as an example: first a
malware that spreads via e-mail that also has the ability to infect files, and second a
malware that is destructive that also has a backdoor capability that provides access to a
compromised system. Based on class prioritization, the first example of the e-mail
malware is classified as an infector, while the second example is classified as a Trojan.
TIP
Malware classes can be considered as attributes or characteristics and tagged
as such. If one malware exhibits two or more class behaviors, it can be tagged
with those classes.
When it comes to classifying malware, it is always good to tag it with all the classes it
belongs to, especially in a malware database. Based on the e-mail malware example, the
malware can be classified, or tagged, as an infector and a network worm. This makes it
easy to query for malware based on class behavior. In this scenario, the prioritization is not
an issue. Instead, the main issue is to tag the malware with all the class behaviors it is
exhibiting. This is useful when it comes to profiling malware.
Infectors
A malware that spreads by attaching a copy of its malicious code to a target host is known
as an infector. Its main directive is to populate by infecting other computer files that are
usually of the same file type. The first infectors were called computer viruses. Named
after their real-world counterparts that spread from one human host to another causing an
epidemic within a small community, these computer viruses instead infect files causing a
system-wide infection within the compromised system. In the old days, computer viruses
were considered to have reached pandemic proportions if computer systems from different
geographical locations became infected because of removable media usage such as floppy
disks.
Before the term malware was coined, all malicious programs were collectively called
computer viruses. Computer viruses are self-replicating programs that spread from one
host to another. They were mainly file and boot sector infectors. But because of advances
in technology and the ability to spread to other systems through other means that are much
more efficient and faster than file and boot sector infection, infectors have vanished into
the annals of malware history.
Infectors are rare nowadays, but it is still important to know about them, especially if
you are going to deal with malware that has been armored by tools such as binders and
joiners, which I will discuss in detail in succeeding chapters.
LINGO
Binders and joiners are malware tools that enable a malware to attach itself to
a benign file.
Infectors are divided into the following types:
File infectors
Boot sector viruses
Multipartite viruses
File Infectors
File infectors defined the computer virus era. All widespread computer viruses during the
DOS era were file infectors. File infectors attach themselves to host programs, and then
these infected files serve as the virus carrier to other systems. When an infected file is
executed, the virus code in the infected file gets executed first, and after that is done, the
execution flow is then passed to the code of the host program. As far as the victim is
concerned, the program did what is supposed to do but unknown to him the virus code
was executed first.
LINGO
The changing of execution flow from virus code to the host code is also
referred to as passing control.
Before a host becomes an infected file or a virus carrier, file infection has to take place.
File infection can occur in two ways.
Through direct infection
Through memory infection
Direct infection occurs when a virus actively looks for files in the system to infect.
Depending on the search parameters of the virus, it might search for files in selected
folders such as the operating system folder, the programs folder, or the current folder
where the virus was executed; or it can search for files in the whole system.
Memory infection, on the other hand, occurs when a host file is executed and is loaded
in memory. In this form of infection, the virus does not actively look for files to infect;
rather, it sits in memory waiting for a host file to be executed. Once a host file is executed,
the virus attaches itself to the host file’s code in memory, and when the operation is
complete, the virus code is saved to the file on disk.
NOTE
Direct infection occurs when the host files are static, while memory infection
occurs when the host file is running. As a result, direct infection has the potential
of infecting all malware-supported file types in the system, even those files that
have not been executed for a long time.
There are different types of file infectors.
Executables
Macros
Scripts
Executables In the early years of malware, almost all infectors were executables. They
were either a COM file or an EXE file. Some of them infect exclusively their own file
type; i.e., COM infects COM only, and EXE infects EXE only. But there are those that
infect all file types regardless of what the original malware’s file type is; i.e., COM infects
both COM and EXE, and EXE infects both COM and EXE.
Regardless of what file type the computer virus is, it follows certain patterns when it
comes to infecting or attaching its code to the host file. These patterns of infection serve as
a way to classify viruses and file infectors.
They are the following:
Overwriting viruses
Companion viruses
Parasitic viruses
An overwriting virus is the most destructive of all file infectors because, as the name
suggests, the virus overwrites the host code with its own. This results in the total
destruction of the host file. There is no way to recover from this infection unless there is a
backup of the overwritten host file. Figure 2-1 shows the results of an overwriting virus
infection.
Figure 2-1 Overwriting virus infection.
Figure 2-1 shows two different scenarios. If the size of the host file is bigger than the
overwriting virus, the resulting file is the overwriting virus plus the remaining bytes at the
end of the host file. The virus simply overlays itself on the host file. If the size of the host
file is equal to or smaller than the overwriting virus, the resulting file is the overwriting
virus itself, an exact copy, because it has completely overwritten the host file.
In some cases where performance is a must, such as it was during the DOS era, the
overwriting virus, regardless of the size of the host file, simply replaces the host file with
its own copy and changes its name to that of the host file. Although this improves the
malware’s performance, it also has a drawback. Replacing the host file with a copy of the
virus can lead to easy detection via optical inspection by simply listing the files in the
directory. For example, say an overwriting virus with a file size of 470 bytes infects a
folder of several thousands of files that originally have different file sizes. Listing the files
in this folder will show all of them having 470 bytes each, which will arouse suspicion. In
addition, assuming the malware does not have a routine to retain the original date of the
infected host files, the infected files will have similar timestamps, which will definitely
scream infection. These telltale signs are so obvious that optical inspection makes it easy
to spot the virus.
Another telltale sign of an overwriting virus infection is that every time an infected host
file is executed, it will not function as expected because the virus code completely
destroyed the original program or host code so there is nothing to pass the control to after
the virus code has executed, which is often silent. As far as the user is concerned, nothing
happened. This will raise the level of suspicion that something might be wrong.
NOTE
The only way to recover from an overwriting virus infection is by restoring the
affected files from backup.
Companion viruses are the second type of executable file infectors. Companion viruses
are interesting because they are the only ones that do not really attach their malware code
to the host file. I often refer to them as an exception to the rule. But even without attaching
companion virus code to the host file, the virus code is still executed first, and control is
still passed to the host program code for it to execute its function and not raise suspicion.
The virus is able to do this, without the need to attach its code, by using the operating
system’s rules and capabilities, which are the following:
File type execution hierarchy
Ability to set a file’s attribute to HIDDEN
File type execution hierarchy, on the other hand, deals with deciding which files with
the same name but different executable extension get to be executed first. In DOS and
Windows, this hierarchy exists. The order of execution based on filename is COM, then
EXE, and then BAT. For example, if there are three files with the names HELLO.BAT,
HELLO.EXE, and HELLO.COM in the same folder, typing HELLO only without any
extension at the command line will execute HELLO.COM. Deleting HELLO.COM and
typing HELLO at the command line again executes HELLO.EXE. Deleting HELLO.EXE
leaves the user with HELLO .BAT, so typing HELLO executes HELLO.BAT. Evidently,
taking advantage of file type execution hierarchy works best in command lines, which is
why companion viruses were highly successful during the DOS era but not in modern
operating systems.
TIP
Make it a habit to type the entire filename when executing a file at the
command line.
Figure 2-2 (a) shows an example of a companion virus renaming a target host file’s
extension and setting its attribute to HIDDEN. For example, when VIRUS.COM infects
HOST.COM, the virus renames HOST.COM to HOST.CON (note the N) and sets its
attribute to HIDDEN. Then the virus renames itself to HOST.COM. So when the user
executes HOST.COM, he is actually executing the virus, and then after the virus executes,
it passes control to HOST.CON, which is the real HOST.COM. This scenario is applicable
to COM files because COM is highest when it comes to file execution hierarchy.
Figure 2-2 Companion virus infection.
Figure 2-2 (b) shows how VIRUS.COM or VIRUS.EXE deals with an EXE file.
Instead of renaming and setting the attribute of the target host file (HOST.EXE), the virus
renames itself and sets its attribute to HIDDEN. As a result, the virus becomes
HOST.COM with a HIDDEN attribute. So when the user types HOST at the command
prompt, he is actually executing the virus because of the COM’s highest hierarchy and not
HOST.EXE. Once the virus is finished executing, the virus passes control to HOST.EXE.
This scenario is the main reason why it is always suggested to type the whole filename
including the extension when executing a program at a command line.
The third type of computer virus, parasitic virus, is the most definitive executable virus
of all because, technically speaking, this virus attaches itself to the host file during
infection and still lets the host file function as intended. This is the classic form of file
infection. A parasitic virus takes control of a target host file’s first instruction by replacing
it with a jump or a pointer to the virus code. To pass control back to the host file after the
virus executes, the virus saves the location of the host file’s real first instruction.
There are two types of parasitic viruses, as shown in Figure 2-3.
Figure 2-3 Parasitic virus infection.
Prepending
Appending
A prepending parasitic virus attaches itself to the top of the host file. In this type of
infection, there is little need for file instruction manipulation because the virus code is on
top of the file, so the virus code gets executed first.
As for an appending virus, the virus code attaches itself at the end of the file. If
parasitic virus is the classic form of file infection, an appending parasitic virus is the
classic form of parasitic virus infection. It hijacks the host file’s first instruction to point to
the virus code. After virus execution, it passes control back to the host program code. As
mentioned, the virus is able to do this by saving the location of the host file’s first
instruction.
Macros What is a macro? A macro is a set of instructions that performs a specific task
automatically. The task can be a series of mouse movements, clicks, and keystrokes that
follow a specific pattern that can be repeated in an automated fashion. Macros can be
constructed using an application-specific macro language. A macro language is a form of
scripting that enables a user to program tasks to run automatically. This is utilized mostly
in word processors and spreadsheets to automate tasks such as formatting text and
crunching numbers.
An application-specific macro language is essentially a programming language. And if
there is an opportunity to program or write instructions, there is always the possibility to
write a virus. It didn’t take long for virus writers to use macro languages for their
creations. This resulted in a new form of file infectors called macro viruses, which are
viruses created from an application-specific macro language.
The most popular macro viruses have been written mostly using the Microsoft Office
macro language. It produced the following macro viruses:
Single-platform macro virus
Microsoft Word macro virus
Microsoft Excel macro virus
Microsoft Access macro virus
Microsoft PowerPoint macro virus
Cross-platform macro virus
Single-platform macro viruses infect only the same file type the macro is written in.
For example, a Word macro virus will infect only Word document files and nothing more.
Cross-platform macro viruses, on the other hand, have the ability to infect other Office file
types. This is possible because in Microsoft Office, Visual Basic for Applications (VBA)
is the macro language used across Office documents.
Cross-platform macro viruses infect not only other Office document file types but also
executables.
Scripts Since a macro is a scripting language, it is not far-fetched to use other scripts as
platforms for viruses. The only difference between a macro virus and a script virus is that
the script does not need to be embedded in a file. It can be embedded, or it can be a stand-
alone script.
The most utilized scripting languages to write script viruses are Visual Basic Script
(VBS) and JavaScript. VBS is supported by Windows, so there are no special
dependencies needed for it to run properly. As for JavaScript, it usually works as part of
an application such as a web browser and a Portable Document Format (PDF) file.
Therefore, for it to function as intended by the virus writer without revealing its true
nature, the virus takes advantage of vulnerabilities present in the application where
JavaScript is implemented.
NOTE
Any file format that uses or can interpret scripts has the potential to be
infected.
Multipartite Viruses
Multipartite viruses are viruses that infect both files and boot sectors. This type of virus
has a file infector and a boot sector infector component. It does not matter whether the
boot virus or the file virus counterpart is executed. Both parts usually follow the same
formula; that is, the virus looks for host files to infect and then looks for boot sectors to
infect. If the virus supports Master Boot Record (MBR) infections, it looks for a fixed
hard disk and attempts to infect it.
The Master Boot Record, as defined by Microsoft,1 is the most important data structure
on the disk. It is created when the disk is partitioned. The MBR contains the following:
A small amount of executable code called the master boot code
The disk signature
The disk partition table
At the end of the MBR is a 2-byte signature word or end-of-sector marker, which is
always set to 0x55AA.
NOTE
0x55AA marks the end of a master boot record, an extended boot record
(EBR), and the boot sector.
LINGO
Nowadays, multipartite refers to viruses that are capable of multiplatform
infection, not just boot and file infections.
Network Worms
A network worm is a type of malware that replicates or spreads via a network with little or
no user intervention using widely used network services such as Internet browsers, e-mail,
and chat, among others. Worms usually rely on social engineering to spread, while the
most advanced worms exploit software vulnerabilities to infect other systems. The reach
of the network worm when it comes to potential victims is massive. Everyone who is
online or connected to any network such as the Internet is a potential victim.
Network worms changed the game when it came to the speed and coverage of
infection. Before the advent of network worms, malware infections were limited to file
infections, which spread slowly. And if they did spread, the coverage was usually just a
small geographical area. But network worms spread widely and quickly across networks
with no geographical boundaries, giving meaning to the term malware outbreak. What
took days or even months for a typical malware to spread across different geographic
location takes only seconds for a network worm to accomplish.
LINGO
Malware outbreak describes a worldwide malware infection occurring in a
short time.
Network worms are further classified based on their network-propagating features.
Mass mailers
File-sharing worms
Instant messaging (IM) worms
Internet Relay Chat (IRC) worms
Local network worms
Internet worms
Mass Mailers
Worms that spread via e-mail are called mass mailers. Social engineering is usually this
worm’s most potent weapon. It fools the user into downloading and executing an e-mail
attachment, which is the worm itself. Or if the e-mail is not carrying any file to avoid anti-
spam solutions, it persuades the user into clicking a link, which oftentimes leads to a
download site that installs a malware onto the user’s machine.
File-Sharing Worms
A file-sharing worm spreads through publicly facing file-sharing folders by dropping a
copy of itself into a folder using an enticing filename that users will likely download to
their systems and execute. File-sharing worms usually take advantage of file-sharing peer-
to-peer programs to spread.
A few example of enticing file names are below.
MSOfficeCrack.EXE
FreeAntivirus.EXE
PopularGameUnlockedVersion.EXE
IM Worms
Instant messaging worms spread through IM. The worm utilizes the infected system’s
installed IM software by sending messages to the user’s contact list. The message usually
contains a malicious link pointing to a drive-by download site. In some cases, instead of
sending a malicious link, the IM worm initiates file transfers to the target victims in the
contact list. Since the file transfer is coming from a known contact and the file has an
enticing name, there is a big chance the target victim will accept the file transfer,
download it, and then execute it. IM worms are good at exploiting trust because the target
user thinks the link or file is coming from a friend.
LINGO
The server component is the one that is deployed by the attackers to
compromise a system, while the client component is the one that the attackers use
to control the server component in the compromised system.
IRC Worms
IRC worms spread through IRC channels by sending messages containing malicious links
or instructions that the receiver or target victim should type in return for something such
as “free software” or “ops channel privilege.” The links point to a website that serves the
worm, while the instruction that the target victim is being socially engineered to type
results in a series of commands that can infect not just the target victim’s system but also
the other users in the channel.
IRC worms also utilize direct client-to-client (DCC) file transfer requests. The worm
usually sends the requests to users joining the channel. These files, like any other socially
engineered malicious files, have enticing names to increase their chances of being
executed in the target system.
Internet Worms
Internet worms spread to other system by scanning the Internet for vulnerable machines.
Oftentimes, Internet worms use vulnerable browsers to infiltrate target systems. An
unpatched system that is connected to the Internet always runs the risk of being infected
by an Internet worm.
NOTE
An unpatched system is a good way to collect malware samples just by
connecting to the Internet.
Trojan Horse
A Trojan horse, also known simply as a Trojan, is a destructive malware in disguise. It
passes itself as a harmless, legitimate program that is enticing to the user. It can disguise
itself as a game, a tool, or even popular software. The main idea is to convince the user to
run it.
The main directive of a Trojan is destruction of files or the system. The end result is
usually loss of files and an inoperable system. The only way to recover from a Trojan is by
restoring from backup or reinstalling the whole system.
Backdoors
Backdoors enable an attacker to gain access to a compromised system, bypassing any
form of digital safeguards and authentication, usually through the use of vulnerable and
undocumented OS and network functions. The access can be an open shell with root
permission.
An important characteristic or attribute of a backdoor is stealth because its success lies
in it being hidden and undetected. Once it is discovered, it is “game over” for the attacker.
Remote-Access Trojan
A remote-access Trojan (RAT), also known as remote administration Trojan, is a
malicious system administration tool that has backdoor capabilities, enabling an attacker
to gain root access to the compromised machine through a stealthy malicious program
running in the system. Unlike a backdoor that typically uses a shell, a RAT uses a client-
server model. A RAT has a user interface (UI), also known as the client component, that
the attacker can use to issue commands to the server component residing in the
compromised machine.
Looking at the RAT’s user interface, you can immediately determine what the attacker
can do to the compromised machine. The UI is so revealing that it is easy to analyze the
malware. But the challenge here is obtaining a copy of the client component, which is
usually in the attacker’s possession. Most of the time, researchers and analysts are left
only with the server part, which is extracted from the compromised machine.
One of the most popular RATs was SubSeven by mobman, as shown in Figure 2-4.
Figure 2-4 SubSeven by mobman.
Information Stealers
An information stealer, as the name implies, is a malware that steals information. The
stolen information could be a password, financial credentials, proprietary data, intellectual
property, or anything that is reserved for somebody else’s eyes and not the attacker’s.
Information stealers are further classified into the following:
Keyloggers
Desktop recorders
Memory scrapers
Keyloggers
Keyloggers capture keystrokes in a compromised system. The captured keystrokes can be
stored locally for future retrieval, which was true for early keyloggers, or sent to a remote
server to which the attacker has access.
Desktop Recorders
Desktop recorders work by taking a screenshot of the desktop or the active window when
the conditions are met for the malware to capture such information. Usually, the
conditions are event driven, such as a mouse click or keyboard press, or is determined by
a certain time interval. Desktop recorders are oftentimes used to get around virtual
keyboards utilized by some online banks.
One disadvantage of desktop recorders is the amount of data they store. The file size of
each screenshot quickly adds up.
Memory Scrapers
Data and code when in memory are decrypted, which is the only way they can be
processed. Memory scrapers take advantage of this fact by stealing information in
memory while it is being processed. Memory is always the best place to grab data because
everything is decrypted.
Ransomware
Ransomware is a malicious program that holds data or access to systems or resources
containing that data hostage unless the victim pays a ransom. This type of malware is a
form of virtual extortion that can be any of the following:
Data encryption
Data destruction
User lockout
Data Encryption
In this type of extortion, the ransomware encrypts a victimized user’s data. The data can
be specific such as documents, pictures, or files with specific extensions, or it can be a
lockdown of the whole disk or a certain partition. The main idea here is that the data is
held hostage, preventing the user from accessing it. To restore access, the user needs to
pay a ransom, after which the data will be decrypted by the malware or the user will be
provided with a decryption tool and key. Or a more devious act can be purported by the
attacker, such as running away with the money and leaving the victimized user with
inaccessible data and a big hole in his pocket.
The most telling characteristic of this type of ransomware is that it has encryption
algorithms.
Data Destruction
This is like saying, “Pay up or I will blow up the town.” In this scenario, the user is given
a time frame to pay or the data or hard drive will be wiped clean. This typically happens
after data is encrypted to prevent the user from copying or backing up anything, and then
the attackers resort to this type of extortion so they get the money immediately.
The most telling characteristic of this type of ransomware is that it usually has a disk-
wipe or data-deleting feature.
User Lockout
Instead of encrypting data, how about just denying the user access to the system itself?
This is what user lockout is. The user is locked out and denied login access to the system.
This also renders the system unusable because the user is stuck at the login screen. If the
user does decide to pay the extortionist, he would need a different system to do it.
NOTE
Not all ransomware can do what it claims to do. Fake ransomware relies on
scare tactics to coerce a user into paying a ransom.
Scareware
Scareware is a form of digital fraud. These are malicious programs that are designed to
scare users into installing a program and even paying for it. Fake antivirus (AV) programs
are the most popular scareware. These are programs that fool the user into thinking that
his system is infected with multiple malware and the only way to solve the problem is to
install the full version of the program and pay a nominal fee such as $30.
Scareware can victimize the user in three ways. First, it convinces the user to install
something into the system, which is most likely malware. If there are User Account
Control (UAC) prompts or requests to grant administrative permission, the user is likely to
agree to them. Second, it asks for the user’s credit card to “unlock” the full features of the
program to make the bad things go away, giving the attackers access to the victim’s credit
card information that they can use to sell or use for their own purposes. Third, the user’s
credit card is charged an average of $30 for the software. The attackers just made money
on bogus software. In short, the victim installed the malware, gave his credit card number
away, and paid for everything.
NOTE
The difference between a ransomware and a scareware is that a ransomware
asks the user to pay money to gain access to the user’s system or data, while a
scareware scares the user into paying money to solve a problem that does not
exist.
Fakeware
If other malware such as Trojans use enticing names to get executed, fakeware passes
itself along as a legitimate program update. It disguises itself as an update of popular
software, including security software. Figure 2-5 shows an example of a fakeware
disguising itself as a Flash Player update.
Figure 2-5 Fakeware disguising itself as a Flash Player update.
It is always suggested that users update their software to avoid being exploited by
attackers. This is the sentiment that attackers are banking on when it comes to fakeware. If
users believe a fakeware is a legitimate update, it has a higher chance of being installed on
the system.
NOTE
The difference between a fakeware and a fake AV program is the part where
the user is charged money for installing the software. Even with this difference, it
is acceptable that a fake AV program be classified as both scareware and
fakeware.
TIP
Always update software using manufacturer-suggested methods such as
visiting a specific link manually or using the software’s own update features.
Treat updates popping up randomly with suspicion.
Greyware
There are files that are not malicious but can be malicious based on how they are used and
what effects they have on a user. This is why they are classified as gray-area software or
greyware.
The most common greyware types are the following:
Joke
Hacktools
Adware
Spyware
LINGO
Greyware is also known as a potentially unwanted program (PUP).
Joke
A joke greyware is a program designed to fool the user into believing that something is
wrong with the system when really there is nothing wrong. The classic joke programs
usually invert the display, make the mouse cursor move in the other direction, mess up the
keyboard, and even make disc drives open and close. These programs are harmless and do
nothing malicious to the system, but they are nuisances.
Joke programs are supposed to be fun, but they have the potential of producing
unwanted consequences depending on the victim’s reaction. Take, for example, the blue
screen of death (BSOD) joke program. This program makes the user believe that the
system is not functioning anymore. If the user is not aware that this is a joke, he might
resort to formatting the system immediately to fix the “problem.” If the user has backed up
of all his files, this is fine. He only lost time in formatting and restoring his system, but if
the user has no backup, he just lost all his files because of a simple joke program.
Hacktools
Hacktools is short for hacking tools. These are programs that give users access to a target
system. Hacktools are similar to network administrator tools. Most of them function the
same way. The only difference is the intent for which they are used. A network
administrator tool can be used to manage a network to make sure that everything is
running smoothly, but in the wrong hands, that same tool can be used to compromise a
network.
Some organizations want hacktools and administration tools absent from all systems
connected to their network except for those used by network and system administrators.
Think of these like guns. Guns in the hands of law enforcement are used for preserving the
peace and for upholding the law, but guns in the wrong hands can have deadly
consequences.
Adware
Adware is short for advertisement software or ad-supported software. These are programs
that display advertisement pop-ups. These pop-ups are definitely a nuisance because they
appear more frequently than they are supposed to, and most of the time, the pop-ups are
offensive to some users.
Adware became popular in free software. A developer posts or shares a product for
free, but to recover development costs and to generate income, the freeware is most of the
time bundled with adware. This gave rise to the term ad-supported software. The user can
continue using the software as long as the ads are displayed.
NOTE
There is nothing bad about ad-supported software. It becomes bad or
considered a nuisance only when pop-ups appear almost all the time even if the
freeware is not running.
Spyware
Spyware is pretty self-explanatory. Some people consider it really bad and would even
group it under the category of information stealers. When spyware was booming, almost
everybody was calling anything that stole information spyware. There is nothing wrong
with this because technically speaking a spyware is an information stealer, but there is a
difference between greyware spyware and the information stealers class of malware.
Spyware, in the strictest sense, is software that can be purchased for the purpose of
spying. This means it is available to anybody who can afford it. On the other hand, the
information stealers class of malware is available only to the attackers. Their
functionalities are added exclusively to the attacker’s malware creation.
The target consumer of spyware usually includes those who want to monitor their
family members’ activity online, but most of the time it can be used to spy on other people
as well. When Internet cafés were becoming popular, most unscrupulous owners would
plant spyware in the system that they used for renting out to patrons. This made it a major
security and privacy concern that gave rise to a lot of anti-spyware companies in the
nineties and early part of the 21st century.
NOTE
Almost all spyware comes with an end user license agreement (EULA) stating
that the user must own the computer where the spyware is being installed and
that the publishers have no liability whatsoever resulting from the use or misuse
of their software.
Recap
Malware taxonomy is the process of classifying malware. Depending on the need,
malware can be classified in different ways. But for our purposes, you can classify
malware based on its behavior or directive. The following are the different classes of
malware that were discussed in this chapter:
Infectors
Network worms
Trojan horses
Backdoors
Remote-access Trojans
Information stealers
Ransomware
Scareware
Fakeware
Greyware
Classifying malware enables analysts to come up with well-organized groups of
malware with recognizable patterns. Familiarity with these patterns is important to make
an educated guess about a malware’s main functionality, especially if the data gathered
during analysis is not enough to paint a complete picture of the malware. It also makes
analysis efficient by enabling analysts to predict malware behavior based on the patterns
that are revealed during the different stages of analysis, thus saving time and effort by not
having to go through the other steps of analysis.
1 Microsoft Technet: http://technet.microsoft.com/en-US/.
CHAPTER
3
Malware Deployment
B efore malware can do any real damage, it must reach the target system. To reach a
target system, the attackers use or abuse different technologies, some of which are
legitimate while others are designed purely to deploy malware.
Malware deployment is just as important as the actual capabilities of malware. Without
the deployment technology, malware, no matter how sophisticated, will be rendered
useless. Think of malware as soldiers. For them to reach their target site, they must be
deployed effectively and oftentimes under stealth. This is why capable countries invest in
air, land, and sea deployment vehicles for the purpose of successfully carrying soldiers to
their target destinations. This is the same concept when it comes to malware deployment
technologies. The attackers invest heavily in the most effective and stealthy deployment
technology to deliver their malware. One example of this is the exorbitant price of a newly
discovered, zero-day vulnerability.
Malware deployment does not concern itself with the execution of malware, although
some deployment technology has that capability. It is mostly concerned about malware
reaching its intended target. For instance, in the early days of computer viruses, the often-
used technology to deploy or spread malware was the floppy disk. The disk carried
infected host files, and an infected disk, once placed inside a disk drive, was considered a
successful deployment. The malware had reached its target. Infection of the target system
was possible because the infected files reached the target, and if a user executed these
infected files, the result was a compromised system.
As previously stated, some deployment technology has the capability of automatically
executing malware, resulting in deployment and infection. Going back to the disk
example, if a disk is infected with a boot sector virus, simply accessing the disk will
execute the boot sector virus, causing system compromise. There is no need for a user to
execute any infected files to infect the target system.
NOTE
Successful malware deployment does not equal successful malware infection.
The computer virus was successfully deployed using physical media, the disk, to reach
its target. The ability to execute the malware once it reaches a target is an added bonus,
especially if a deployment technology has this capability. The physical media, and other
techniques or technology used to deploy malware are called malware infection vectors.
In this chapter, I will discuss what a malware infection vector is and how it is used by
attackers to deploy malware to their targets. I will identify the different dimensions of a
malware infection vector that serve as a guide to attackers on which specific infection
vector to use in their attack campaigns. And most importantly, I will enumerate the most
common malware infection vectors that are being used by attackers regardless of whether
their campaign of attack is opportunistic or targeted. I will then conclude the chapter by
identifying the different characteristics that make a technology suitable for becoming a
malware infection vector.
Malware Infection Vectors
An infection vector (or a combination of several infection vectors) is what is behind the
spread of malware. It is responsible for the distribution and proliferation of malware. In a
threat ecosystem, having the right infection vector is what separates success from failure
of malware deployment.
LINGO
A threat ecosystem is a collection of different technologies that attackers use
to conduct attack campaigns. Each of these technologies supports the malware
and each other. If one fails, so does the attack campaign.
There are a lot of infection vectors at the disposal of attackers. I will enumerate these
different infection vectors later in the chapter. To help attackers choose which one is best
for their specific needs, they consider the different dimensions of each malware infection
vector.
Infection vectors are chosen based on the different dimensions they offer. The
following are the important dimensions of an infection vector:
Speed
Stealth
Coverage
Shelf life
Speed
The speed by which infection occurs is important to the attackers. Depending on the
attacker’s intent, she might choose the slow physical media infection vector that relies on
physical transport by humans or the faster e-mail infection vector that relies on the speed
of different network connections to reach a target. If time is of the essence, the faster
infection vector is always chosen. If there is no rush and the target system to be
compromised is not connected to any network systems, the physical media might be the
better alternative.
The speed by which a malware can reach a target is quite scary. Before everybody was
connected to the Internet and everyone had e-mail, malware infection was slow. Almost all
malware relied on physical media, and malware infection was not a big thing. A well-
known researcher and a personal idol of mine once said in an interview that computer
viruses are an urban legend, like the crocodiles in the New York sewers, and one U.K.
expert claimed that he had proof that computer viruses were a figment of the imagination.1
Systems still get infected, but the impact is not as big to garner any attention. There were
infections that are well known during those times but not as impactful as the infections
that occur when everybody got on the World Wide Web.
With the advent of e-mail and so many computers and devices connected to the
Internet, malware now has a faster infection vector in e-mail. This means malware has the
ability to reach targets in an instant. With this speed, a malware coming from the East
Coast can reach a target on the West Coast, or in any part of the world for that matter, in
mere seconds.
The speed and coverage of an e-mail infection vector make it possible to have a
worldwide malware outbreak.
Stealth
A successful infection vector is one that cannot be detected easily and can bypass most
security solutions. The stealthiest infection vector by far is vulnerable software. A well-
crafted exploit can easily bypass most security hurdles and take advantage of the
vulnerable software’s permissions and privileges. It is always a challenge to detect a zero-
day vulnerability. In most cases, it takes a long time to detect the vulnerability and even
more time to fix it. This is why zero-day vulnerabilities fetch a big chunk of change in the
underground market. Software publishers would rather pay researchers who discover
zero-day vulnerabilities rather than know about the zero-day after a massive infection has
hit.
LINGO
Zero-day vulnerabilities or zero-days are vulnerabilities that have been
discovered but are still unknown to the software publisher and to the information
security industry at large.
In some cases, physical media can prove to be the stealthiest infection vector of all. For
example, a target company that does not have any security policy in its endpoints to
prevent the use of unauthorized universal serial bus (USB) sticks or external hard drives
can easily fall victim to a malware delivered through infected physical media. No matter
how state-of-the-art or best-of-breed security solutions are used to guard the network from
infiltration and infection, the lowly physical media can easily infect an endpoint, which
can serve as the staging ground for further infections within the network.
Coverage
Coverage means the number of targets an infection vector can reach. Is it a single target?
Is it in the tens of thousands? Is it in the millions across geopolitical borders? All of these
are possible depending on the infection vector chosen.
In an opportunistic attack, the desired coverage is as many as possible. Therefore, an e-
mail spam carrying the malware or linking to the malware is often used as the infection
vector. Think of the worldwide malware outbreaks that the world saw in the nineties and
early part of the 21st century such as the Melissa worm, the ILOVEYOU worm, and
MYDOOM, among others. Most of the malware was delivered by e-mail. Anybody who
has an e-mail address is a potential target.
LINGO
An opportunistic attack is an attack targeting everybody. Whoever stumbles
upon the infection vector and becomes compromised becomes the attacker’s
victim.
In a targeted attack, the desired coverage can range from a single person to a handful of
targets. If the target is a specific person or position within a target entity, the malware
infection vector needs to deliver the malware to only one target. If the target is a group of
employees, the malware infection vector might be crafted to deliver malware to only this
small group. For example, an attacker who wants to compromise a small subsidiary that
has ten employees will target only those ten employees. In most targeted attacks, the
smaller the number of compromised systems, the higher the chance that the malware will
stay hidden and not raise any suspicion.
LINGO
A targeted attack is an attack focusing on a specific entity chosen specifically
by the attacker. Targets are usually executives or important people within an
organization.
Shelf Life
Some malware infection vectors have an expiration. Take, for instance, software
vulnerability. A patch that closes the software vulnerability can render all exploits that
take advantage of it useless. The software vulnerability will not be as successful in
deploying malware as it was before the patch was applied.
An e-mail that is captured that delivers malware loses its freshness immediately after a
solution to block it gets released.
This is why time is always of the essence when it comes to deploying malware. It is a
race between the attackers and the researchers. Once a vector is found out, it is only a
matter of time before that specific infection vector is rendered useless, and it is up to the
attackers to come up with a new one.
Physical Media
Physical media are the main infection vectors of computer viruses. Since computer viruses
are mostly file infectors, the only way they can reach another system is to be manually
carried to that system through the use of a disk.
A malware with no capabilities of spreading through any other means than file
infection usually uses this infection vector. It is already assumed that the infection vector
is physical media since there is no other way for this type of malware to get into another
system. But if a malware infects physical media such as the boot sector or sets itself up in
the physical media to take advantage of the autorun capabilities of the target OS, then that
is clear evidence the malware uses physical media as its infection vector. But what if the
malware does not exhibit these capabilities? Is it still possible to use physical media as an
infection vector? The answer is yes.
There have been cases where malware that has no routine to infect files or boot sectors
is deployed using physical media. For example, someone giving away USB sticks outside
of an office building, a school, or anywhere for that matter, can simply put a sophisticated
malware on the USB stick hoping that somebody will put it in a system and start the
infection process. In this case, the USB stick is a decoupled infection vector because the
malware did not put itself on the USB stick; therefore, no traces of this activity will be
found during analysis.
TIP
Be wary of free USB sticks even at security conferences; they might be
carrying more than what they’re supposed to be carrying.
E-mails
One of the fastest ways to reach someone is through e-mail. The same thing goes for
malware. Anyone with an e-mail address is a potential target. Lots of noteworthy malware
went on to produce worldwide outbreaks because of e-mail; among them are the
ILOVEYOU worm, as shown in Figure 3-1, and the Melissa worm.
Social Networking
Social networks are popular. They not only are used to connect with someone but also are
used to promote products. The more registered users a social network has, the more
valuable it is, and the number of users is directly proportional to its popularity. Some
social networks are so popular that the number of registered users actually exceeds the
population of some countries, as shown in Figure 3-3.
Figure 3-3 Population size of social networks relative to countries. (Source:
www.pingdom.com.)
Social networks offer features that are desirable to attackers. Among them is the ability
to send instant messages and post updates in the form of feeds. The feeds can be visible to
friends only or to the public. The feeds are desirable to the attackers because the links
remain posted until they are taken down; they are just there waiting for unsuspecting users
to click them.
Social networks also take advantage of trust. Attackers can post malicious links to the
compromised account’s wall, and posts can be made to a friend’s feed wall. That friend
will think it’s legitimate, and chances are he will click that link.
A malware that looks for social network accounts or requires a certain user to be logged
in to a social network for it to function as intended usually uses social networks to spread.
But not all malware that uses social networks to spread will show this feature, especially if
the social network is used as a decoupled infection vector. One example of this is when the
attackers create a social network page about a celebrity, a new movie, a new product, or
breaking news. These pages will often attract users to it. The more relevant the subject of
the page is, the more users will be drawn to it. Chances are, some of these potential
victims will click a link or download a file from that page. Figure 3-4 shows a social
network page created by attackers to lure visitors to do what the page says. The result of
course is infection.
Figure 3-4 Fake Osama Bin Laden video page on a social network site.
TIP
Be wary of clicking supposed videos in social network feeds. The malicious
ones are not videos but graphic files pretending to be videos with play icons in
the middle. They can lead to infection.
URL Links
Another way of delivering malware to a target system is through URL links. Attackers use
URLs to point to a webpage containing malware or even directly to the malware itself. In
the case of the latter, the malware is saved to the file system. In the worst-case scenario, it
gets executed immediately, a classic example of a drive-by download site.
A URL link is a special kind of infection vector. It is both an infection vector and a
payload of another infection vector. Infection vectors that have URL links as their payload
are called infection-vector-hosting (IVH) infection vectors and include e-mail, instant
messaging, social network feeds, and documents with links.
TIP
When investigating malware that uses IVH infection vectors, be on the lookout
for links. These links usually contains new version of the malware or some of its
components.
Sometimes static analysis can reveal some of these URL links, especially if the
malware is not encrypted. Otherwise, dynamic analysis with network monitoring tools is
the only way to reveal these malicious URL links.
File Shares
Peer-to-peer (P2P) file sharing is commonly taken advantage of by malware to get into the
system of other users. A malware will drop a copy of itself in the public-facing file share
folders. This makes the malware available to all peers that are downloading files. To make
sure that other users will download and execute the files, the malicious files use enticing
names such as MSOfficeCrack. EXE, DOTAFullVersionNoAccountNeeded.EXE, and
more. The idea is to social engineer its way into a target user system by making itself
desirable for download.
A malware that looks for common P2P file share folders and drops itself there during
execution uses this kind of infection vector.
Software Vulnerabilities
No software is perfect. All software has bugs, and some have flaws. Some are known,
while others are not. Some are critical, while others are minor. Depending on the severity
of the bug, it can have unpredictable and unintended results. The attackers, with some of
them being software developers themselves, recognize the value of an unknown or
undiscovered critical bug waiting to be exploited in certain software.
It is important to know the difference between a software bug and a software flaw. A
software bug is an issue with a feature that is not functioning as intended, while a software
flaw is an error in the design and architecture of the software. A bug can be fixed by a
patch, but a flaw can be fixed only by a complete redesign of the software.
The advantage of using software vulnerabilities as an infection vector over other
infection vectors is that it significantly lowers, if not totally eliminates, the need for
human interaction. Typically, it results in the automated execution of malware, which is
what is considered the most effective way of infecting a system. It also takes advantage of
software that is whitelisted in the system, thus evading any sort of application control
security products.
LINGO
Application control is also known as whitelisting. The concept of this security
product or feature is to let only known whitelisted applications to run in a system.
Lots of material covers software vulnerabilities already. With this in mind, I will focus
on those that are used to install malware on a system.
To take advantage of software vulnerabilities, the attackers use an exploit. An exploit
can be a piece of code or a chunk of malformed data that causes the target software to
behave in a way not intended by the software manufacturer. The most common exploit is
the one that takes advantage of buffer overflow.
NOTE
An exploit is not a vulnerability. An exploit is something that takes advantage
of a vulnerability.
Buffer Overflow
Software consists of two distinct components: code and data. Code is the set of
instructions that makes use of data. During data manipulation, software often makes use
of a temporary data storage called a buffer. A buffer is created to hold data and nothing
more. But sometimes, because of programmatic error, more data is written to the allocated
buffer. This results in data overflowing to adjacent buffers. This condition is called a
buffer overflow. Attackers take advantage of this by overflowing the buffer with code
instead of data. The buffer is overflowed in such a way to transfer the control to that code,
thus executing it. The often-used buffer overflows are
Stack overflow
Heap overflow
It is important to note that a buffer overflow can be triggered using a malformed file.
The malformed file is the one that is deployed by the attacker. Once this file is opened
using the vulnerable application, the data from the malformed file overflows the buffer.
Getting hold of a malformed file during malware hunting helps in understanding how the
vulnerable application is being exploited.
Stack Overflow The stack is a last-in first-out (LIFO) data structure. This means the
data that is pushed last onto the stack is what is popped out first. It is aptly called a stack
because it is stacking data on top of one another. Think of it like a stack of plates. The last
plate that is put on the top of the stack is the one that is used first. Because of its LIFO
nature, the stack is often used to store temporary variables, making it efficient to use with
program functions.
Stack overflow is the result of overflowing the buffers on the stack to get control of the
execution flow of the program. This is made possible by overflowing the buffer enough to
overwrite the value stored in the return address (RET). To understand this concept, let’s
look at how program functions use the stack.
A program function is like a small program within a program. It’s independent,
compartmentalized code that performs specific operations using data passed to it and then
returns the result to the main program. Since a function has to manipulate data, it utilizes
the stack as a temporary storage for this data. When a function is called within a program,
it pushes all the data into the stack, including the return address. To understand what the
stack looks like, see Figure 3-5.
Figure 3-5 What the stack looks like during a function call.
The return address is where the instruction pointer is currently pointing when the
function is called. This is important because after the function has finished processing, the
execution flow has to go back to that return address so the main program can continue its
execution flow. This value is stored in RET. When the function finishes, the value stored
in RET is passed to the instruction pointer so the main program can go back to its
execution flow before the function was called. So if the attacker is able to overflow the
buffer and as a result overwrite the value stored in RET with an address value that points
to malicious code, the instruction pointer will point directly to the malicious code,
resulting in the malicious code being executed.
Heap Overflow The heap is dynamically allocated memory space. The logic behind this
is that the amount of memory needed by a program is not known in advance; therefore,
memory has to be allocated as needed and freed up when not needed. The difference
between a heap and a stack is that a heap does not have a return address like a stack does.
This makes the technique used to control execution flow in stack overflow useless.
Overflowing a heap instead results in data and pointers to other data or program functions
being overwritten. As a result, the attacker can overwrite these pointers to point to
malicious code instead of the original location.
Privilege Escalation
The ability of a software vulnerability to deliver and install malware in a system depends
on its getting privilege escalation. Privilege escalation is the process of gaining access to
system resources that are accessible only to a superuser or system administrator. With this,
the attacker can do pretty much anything with the system, including installing malware.
Privilege escalation is achieved when the exploited, vulnerable software (or some of its
components) is already running on escalated privilege or it has access to system resources
or functions running on escalated privileges.
Zero-Day Vulnerabilities
The knowledge of a program’s vulnerabilities that can be exploited is often kept private
by the attacker. This is known as a zero-day vulnerability. A zero-day vulnerability is an
exploitable hole in an operating system, software, or even hardware that has no solution
and has been discovered by those other than the manufacturers or publishers of the
vulnerable object. If an independent researcher has discovered a zero-day vulnerability,
the next step is to report this to the manufacturer or publisher so a patch or a new minor
version can be released that fixes the vulnerability. Some software manufacturers even
pay for this kind of information, making vulnerability discovery a good independent
business for software hobbyists. But it’s a different story if an attacker discovers it. It is
usually kept secret to be used in future attacks or to be sold to other cybercrime groups.
Keeping it a secret creates immense value because this vector’s shelf life depends on how
long it is kept a secret and how long before a patch is released to fix it.
There have been cases where a vulnerability has been public already but the patch to
fix it was pending release; thus, any malware that utilized this vulnerability still enjoyed
some level of success. Unfortunately, the only way to prevent vulnerable software with no
available patch or fix from being exploited is to uninstall or not use it, but in cases where
the software is vital to an enterprise’s operation, this is usually out of the question.
TIP
A good way to stay abreast of the latest vulnerabilities is by visiting
http://cve.mitre.org.
Recap
Malware deployment is an important part of the threat ecosystem. As stated previously, it
is as important as the actual capabilities of malware. Without the deployment technology,
malware, no matter how sophisticated it is, would be rendered useless.
Having familiarity with the different malware infection vectors enables analysts to
determine how the malware spreads. This answers the important question of how the
victim got infected and also helps security professionals in securing networks.
In this chapter, I discussed what an infection vector is and how attackers use it to
deploy their malware. I enumerated the four dimensions of a malware infection vector,
which are the following:
Speed
Stealth
Coverage
Shelf life
Depending on the attacker’s needs, an infection vector is chosen based on these
dimensions. It serves as a guide for the attacker on which appropriate infection vector
should be chosen to deploy their malware.
I then enumerated the most common infection vectors that are used by the attackers to
deploy their malware.
Physical media
E-mails
Instant messaging and chat
Social networking
URL links
File shares
Software vulnerabilities
An infection vector can be coupled with or decoupled from the malware. A coupled
infection vector can easily be revealed during malware analysis because the malware
initiates the use of the vector. A decoupled vector is much more challenging to discover;
because it is not initiated by the malware, no evidence of it will appear during analysis.
The attackers usually initiate the use of a decoupled vector.
It is important to note that most infection vectors used by attackers are legitimate
services that are essential to the operation of any network system. These services cannot
be blocked simply for the purpose of stopping malware. The key here is to understand
how these technologies are being used by attackers to deliver their malware and then find
a solution.
Any technology can be used by attackers to deploy malware, which is why I concluded
this chapter by discussing the potential of any technology to be used as an infection vector.
It actually depends on the following characteristics:
The ability to process data from an external source
The ability to move data to a chosen destination
The ability to share data
Finding out which infection vector an attacker used to deploy malware completes the
story of system compromise. And most of the time, it is important to complete the story.
1 1988 The Game Begins by DaBoss: http://www.cknow.com/cms/vtutor/1988-the-game-begins.html.
CHAPTER
4
Protective Mechanisms
Static Malware
A malware that is being transported by a deployment technology such as a physical drive
or e-mail is a malware at rest. This is usually a good time to capture malware because it is
powerless in this state. It cannot do anything to prevent anyone from copying it from the
deployment technology and distributing it to other analysts and researchers for further
analysis. Whatever protective mechanisms it has that are activated by its malware code are
rendered useless. But this does not mean the malware is easy to crack. The attackers have
taken this into consideration, which is why static malware or malware at rest also has
protective mechanisms built in.
Dynamic Malware
Dynamic malware, or malware in motion, is malware that is currently active or running in
a system. Unlike static malware, dynamic malware has all the encoded protective
mechanisms available to it; therefore, it can actively defend itself from scanning by
security products, from the invasive system-monitoring tools that record the malware’s
every move, and from the prying eyes of researchers.
A running malware can actively protect itself. It has full access to its codes and features
that the attackers built into the malware. It has the ability to react to whatever changes
there are in the target system it is running on and to guard against any tools that are used
for the purpose of extracting and analyzing it.
Protective Mechanisms
The attackers understand the risk of malware being captured through interception of the
malware infection vector used or through extraction from the compromised system. This
is why highly funded attackers invest heavily in different evasion technologies to protect
their malware. A malware’s main goal is to impede detection and analysis. The more time
it takes for researchers and analysts to understand malware, the more time the attackers
have to achieve their directive. It is therefore essential that malware researchers and
analysts understand the different protective mechanisms employed by malware. The
ability to recognize and mitigate these protective mechanisms is important so malware
analysis can proceed.
LINGO
Malware protective mechanisms are also known as evasion technologies.
The attackers choose or create malware for their attack campaign with the goal and
expectation that it will be successful. They do everything that is technically possible
within their capability to protect their malware creation. A well-funded attacker group
might have access to more malware protective mechanisms and technologies, while those
that form a rag-tag group might have limited options. Regardless of the funding, the main
idea is that the attackers will do everything in their power to protect their malware to
achieve success in their attack campaign.
A successful malware is one that has the ability to evade detection and analysis for it to
function as intended by the attacker. Evading detection enables it to reach its target and
execute unimpeded. Evading analysis enables it to conceal its real purpose when subjected
to malware analysis and reversing. To achieve this, the malware must employ protective
mechanisms for it to survive long enough to accomplish its directive.
For a malware to be successful, the malware writers must be able to deal with what
their creation is up against. The malware faces these two foes:
The security product
The security analysts and researchers
A collection of security products, consisting of both software and hardware, is what
stands between the attackers and the individual or organization they are attacking. As
much as possible, they want their malware to be able to evade whatever detection
technology these security products are employing. To do this, attackers familiarize
themselves with the different technologies used by security products so they can come up
with ways to circumvent those technologies. If the malware can evade these technologies,
it has a better chance of executing and maintaining a foothold in the target system.
Of course, if there is an infection or system compromise, the system will be scrutinized
by incident responders or security professionals within the company or from a third party.
A captured malware must have the capability to protect itself from analysis. The main idea
here is to buy more time. The more time it takes for analysts to break a malware, the more
time the attackers have to do whatever they need to do on the compromised system or
network. Malware that requires continuous access will need a strong protective
mechanism, while other malware might not need any protection at all such as malware
used in a hit-and-run attack that usually lasts minutes or hours. A malware used in these
types of attacks usually does not need protective mechanisms.
LINGO
A hit-and-run attack is an attack that happens in a short period of time,
usually in less time than it takes for the company to deploy a solution to stop the
malware.
No matter how many protective mechanisms are used, they can be broken. It just takes
time, and it depends on the difficulty level of the protective mechanism being used. The
more layers there are, the more time it takes. And if each layer proves to be more difficult
than expected, then it becomes more time-consuming.
LINGO
Breaking a malware is a phrase used to describe removing all protective
mechanisms employed by malware.
As mentioned, attackers want to defeat the security product and the security analysts
and researchers. Almost all protective mechanisms are designed with these goals in mind,
which means a malware writer has to consider how to protect the malware whether it is at
rest or in motion against security products designed to stop malware and from analysts and
researchers eager to dissect the malware to uncover each bit and byte of its functionality.
Entry-Point Obscuring
An entry point is a pointer to the location of an executable’s first instruction. It points to
the location where the execution formally starts. For a malware, the entry point almost
always points to the start of the malware code. This is especially true for infected host
files. Therefore, hiding it is advantageous for the malware because of the following:
Antivirus (AV) scanners use the entry point to find the malware code and
match the malware signatures the scanners have in their databases.
With the entry point, reversers are able to disassemble and trace the code
through the use of disassemblers and debuggers.
Hiding the malware code’s entry point protects the malware from both analysis and
scanning. The protective mechanism that hides a malware code’s entry point is known as
entry-point obscuring (EPO). The EPO technique is popular with file-infecting malware.
This is because an infected file will always have two sets of code: the malware code and
the original host file code. The trick is to hide the malware code by pointing to some
benign code. To see how this works, you need to understand how a typical infected host
file executes, as shown in Figure 4-1.
Polymorphism
Attackers recognized that an improvement had to be made from the basic malware
encryption that they were using, so they introduced a new malware technology known as
the mutation engine. The mutation engine, which is part of the malware code, basically
alters the code of another application without changing the application’s functions. With
the introduction of the mutation engine, it is now possible to alter the
encryption/decryption engine code without changing its functionality. The three
components are now different in every infection. This new form of malware encryption is
known as polymorphism. As defined by Merriam-Webster, polymorphism is “the quality
or state of existing in or assuming different forms.” This is exactly what polymorphic
malware is.
Still, polymorphic malware has a weakness, as shown in Figure 4-5. A polymorphic
malware still needs to decrypt the encrypted malware code in memory, and every time the
malware code is decrypted, it is constant. It shows its original form. This makes it possible
for a signature to be created to detect the malware code in memory or through antivirus
emulation techniques. Polymorphic malware is highly effective in defeating static
scanning but not the more advanced dynamic scanning.
Figure 4-5 Different generations of polymorphic infections look the same in memory
when decrypted.
Metamorphism
The attackers had to come up with a way to counteract the AV technologies used to detect
encrypted and polymorphic malware. And so they did. They introduced a new form of
encrypted malware known as metamorphic malware, as shown in Figure 4-6.
Figure 4-6 Metamorphic malware infections differ on disk and in memory.
Recognizing that a paradigm shift was needed, the attackers approached the problem
differently. They realized that they had a powerful technology on their side in the form of
the mutation engine. Instead of working with the three components of malware
encryption, they realized that the mutation engine could simply mutate the whole malware
code itself. This freed them from the inherent weaknesses of the basic malware encryption
and polymorphic techniques. With metamorphism, each malware infection is totally
different, both on disk and in memory. Although almost perfect, metamorphic malware
still has a weakness because for it to morph, it needs to analyze its own code and
reassemble it to its new form. If the mutation engine can do this, the reversers can do it as
well, but it takes a lot of time, and the formulated solution might be complicated for
existing AV technologies.
Anti-reversing
A sure way to understand malware is through reversing. No matter the protective
mechanism, reversing can shed light on how to beat it. The only enemies are time and
effort. Depending on the malware’s difficulty level, a reversing session can range from
minutes to months. For example, when Ultimate Packer for Executables (UPX) was first
used to pack and encrypt malware, it was pretty awesome. It enabled attackers to easily
distribute malware with far lesser resistance from security products and the prying eyes of
analysts and reversers. Almost all malware used it. But once the packing routine was
reversed, unpacking a malware packed with UPX using OllyDbg takes only minutes. Plus,
there are a lot of tools available for download that can unpack UPX in seconds.
As a rule of thumb, a malware is deemed successful in implementing anti-reversing
techniques when it takes a reverser longer to understand the malware than the malware
needs to survive. If an attack campaign uses a malware that needs only a couple of days
and it takes a reverser three days to solve that malware, the malware has already won.
The main idea of anti-reversing is to make the reversing process as difficult as possible
to the point that it seems impossible to reverse the malware. The most common anti-
reversing techniques used to protect static malware are the following:
Anti-decompilers
Anti-disassemblers
If a reverser or the tools he uses cannot decompile or disassemble a malware, the
reverser is denied access to the malware source code, and without the source code,
reversing cannot proceed. But there is a drawback in this protective mechanism. It works
only for decompilers and disassemblers supported by the malware. This is because
decompilers and disassemblers, like other software products, have their own proprietary
design, algorithm, and implementation. For example, a malware with anti-disassembler
capability can support only the IDA disassembler but not others such as Win32DASM. So
if a reverser uses IDA, it might not work as planned, but using Win32DASM might yield
the output the reverser desires since the anti-disassembler technology used by the malware
does not support Win32DASM. Usually, malware that uses anti-decompiler or anti-
disassembler protective mechanisms supports the most popular tool that reversers use.
Again, the main point is to make life difficult for reversers. It takes the reversers more
time and effort to reverse the malware. And if the malware is able to achieve this, that is,
buy more time for the malware to finish its directive, then the anti-reversing protective
mechanism has done its job.
NOTE
Entry-point obfuscation, code obfuscation through encryption, polymorphism,
and metamorphism also slow down reversing. So, in effect, these protective
mechanisms can also be viewed as anti-reversing technologies.
Anti-sandboxing
In rare cases, static analysis is enough to extract information from malware that reveals its
directive, but in most cases dynamic analysis is needed. As defined in Chapter 1, dynamic
analysis is the process of extracting information from malware through the use of system
monitoring tools and technologies. Usually, dynamic analysis is done by using a sandbox.
A sandbox can be manually driven, or it can be automated. The following are the two
most important components of a sandbox:
Sandbox environment
System monitoring tools
The sandbox environment is the system where the malware is executed. During
execution, the malware is supposed to do what it was designed to do. The system
monitoring tools make sure that everything the malware does on the system is captured
and logged for analysis purposes. If the malware does not execute in the sandbox, no
information is extracted, and the whole process fails. This is the key to beating a sandbox.
The malware must be intelligent enough to know whether it is running in a target system
or in a controlled sandbox.
Anti-sandboxing techniques usually cover two things.
Detection of sandbox environment
Detection of system monitoring tools
See Figure 4-7 for an illustration of anti-sandboxing technology in action.
Figure 4-7 Anti-sandboxing technology in action.
Detection of Sandbox Environment If a malware knows that it is running in a sandbox
or a malware test environment, it does not need to execute, so no information can be
captured during dynamic analysis. Most sandbox implementations are virtual because of
the many advantages this offers such as portability and easy restoration. So, for malware
to know whether it is running in a sandbox, it needs to know only whether it is running in
a virtualized environment. This led to the most popular anti-sandboxing technology: the
anti-virtualization technique. This technique simply detects telltale signs common to
virtual machines. If the malware senses any indication of it running in a virtualized
environment, it will simply exit and do nothing.
NOTE
Malware programs with only anti-virtualization techniques are often used for
opportunistic attacks, which result in more home users being infected because
most of them are not using virtualized systems.
Detection of System Monitoring Tools Not all sandboxes are implemented in a
virtualized environment. Bare-metal sandbox implementations are available as well. This
solves the anti-virtualization technique employed by most malware, but it costs more to
implement, and restoring images takes longer compared to the virtualized counterpart.
As previously mentioned, a sandbox has two important components: the sandbox
environment and the system monitoring tools. Without the system monitoring tools, no
information can be extracted from the running malware. In bare-metal implementations, a
malware relies on detecting the presence of system monitoring tools. This is the opening
the malware writers have to beat bare-metal sandbox implementations.
As with other software, system monitoring tools leave telltale signs or footprints in the
system whether they are running or not. The malware writers simply familiarize
themselves with these tools and the footprints they leave in the system and arm their
malware with the ability to detect the presence of these footprints. If a malware detects the
presence of any of these telltale signs, it exits and does nothing.
NOTE
Some instances of malware, especially malware used in targeted attacks, will
stop execution only if they detect system monitoring tools running, because most
enterprise production systems are virtualized.
Environment Lock
Malware is designed primarily to execute to do its job. If it does not execute in the target
system, then it has failed. But it must be intelligent enough to know whether it is running
in a target system or in a malware test environment.
Most of the time, malware is captured from a compromised system. It is then subjected
to static and dynamic analysis to extract information from it. The environment lock feature
protects the malware from dynamic analysis. The main idea of this protective mechanism
is to have the malware execute only in the environment it initially compromised. Getting
that malware out of that environment and have it execute in any other system, be it a
sandbox or just another system, will not work. This is because during its first execution on
its target system, the malware takes environment-specific markers—such as the hardware
ID, media access control (MAC) address, or anything that is unique to the system—as
variables or encryption keys and mutates itself by using these keys, which then become
the conditions for its execution. The resulting mutated malware will run only in the first
compromised system and nowhere else. If the malware is moved to another system and the
system-specific markers do not match, it will not be able to decrypt its code in memory
and execute. Capturing a malware with an environment lock feature and subjecting it to a
sandbox for dynamic analysis will not yield any result. This virtually defeats dynamic
analysis.
Anti-AV Scanning
The malware’s foremost nemesis has always been the AV product, and malware writers
know that their creations can be beaten if AV is able to scan and detect them. Detection
depends on the signatures the AV product has. It can specifically detect and identify a
malware if there is a signature that matches the malware’s characteristics. For malware
that is totally new and not covered by any specific detection, the AV product uses heuristic
detection. Depending on how the heuristic signature is written and the number of malware
samples that a heuristic signature is based upon, it can be effective or not. And to ensure
that the system is always protected, real-time scanning is always enabled. This is an AV
feature that lets it reside in memory, keeping a watchful eye on the file system on disk and
the programs loaded and executed in memory.
A malware can arrive in a target system in different ways; it depends on the deployment
technology used. The malware can be downloaded from the Internet or can arrive as an
attachment in e-mail. If this is the case, the malware typically undergoes static scanning.
Obviously, static scanning is easy to defeat given the available static malware protective
mechanisms the attackers use. So, almost all the time, malware gets into the system
undetected. Once the malware is executed in the target system, the AV product uses
dynamic scanning to inspect the malware during runtime. Depending on the current
signature database of the AV product, the malware might get detected using specific or
heuristic detection. But before any signature matching takes place, the AV scanner must be
able to find the malware code. It does not matter whether it’s static or dynamic scanning;
the scanning flow is the same, which is to find the right entry point to the malware code.
The only difference is that in dynamic scanning, the memory image of the malware is the
one that is being scanned. Given that the scanning flow is the same, some code
obfuscation techniques that worked in protecting static malware also work in protecting
dynamic malware. The most effective protective mechanism techniques that usually work
for both states of malware are entry-point obscuring and metamorphism.
Another anti-AV scanning technology used by malware to protect itself from scanning
is to simply turn off the AV product altogether and deny access to AV vendors’ websites.
The same concept as the one used in detecting the presence of system monitoring tools is
applied, but this time, the presence of AV products is the one being detected. Once
detected, the malware turns off the AV product. This works only if the malware is totally
new and not detected by the installed AV product. Given the protective mechanisms
available to attackers, this is not hard to do.
An easier anti-AV scanning alternative is to use a security product’s “Do Not Scan
List.” The malware simply adds itself to that list so every time a scan is performed, the
security product will skip the malware. Again, this works only if the malware is new and
not detected when it first compromises the target system.
Recap
In this chapter, I discussed protective mechanisms employed by malware. These
protective mechanisms are designed to protect malware against its two foes. They are as
follows:
The security product
The security analysts and researchers
I enumerated the two states of malware that the attackers concern themselves with
when protecting malware against security products and security researchers. They are as
follows:
Static
Dynamic
I then discussed the different protective mechanisms used to protect malware at each of
these states.
The following are the common protective mechanisms employed by static malware:
Entry-point obscuring
Basic malware encryption
Polymorphism
Metamorphism
Anti-reversing
The following list are the common protective mechanisms employed by dynamic
malware:
Anti-debugging
Anti-sandboxing
Environment lock
Anti-AV scanning
Network behavior protection
Familiarizing yourself with these protective mechanisms regardless of which malware
state they are employed in enables you to make adjustments to the analysis process so that
analysis can proceed.
CHAPTER
5
Malware Dependencies
Dependency Types
Malware, like any other software, has dependencies for it to function properly. The more
sophisticated the malware is, the more dependencies it has. This is true especially for
malware used for targeted attacks. For example, a malware that will be used to attack
Organization A will be designed to run only in endpoints present in Organization A. The
malware is able to accomplish this by adding a dependency that is present only in
Organization A’s endpoints. An example dependency is a logged-in username. If the
username is preceded by ORGA and has the format ORGA\username, then the malware
assumes that it is running in an endpoint in Organization A and thus will function
according to plan.
NOTE
Malware dependencies can be intended or unintended. They are intended if the
attacker needs them as conditions or triggers, and they are unintended if the
attacker designed the malware in a controlled lab and failed to take into
consideration that not all the dependencies the malware needs to run are present
in a target system.
Malware dependencies can range from the system’s characteristics, as discussed earlier,
to user-driven events. They are divided into the following:
Environment dependencies
Program dependencies
Timing dependencies
Event dependencies
User dependencies
File dependencies
Environment Dependencies
If all the systems in the world had uniform environments, malware analysis would be
easy. Then again, it would be easy for the attackers too. The way a malware operates is
confined within the environment’s digital physics. This is true for all software as well.
Each environment has its own rules of digital physics. As a consequence of this, a
malware written for one environment will not function in another environment. It is as
simple as that.
NOTE
Most malware writers design their malware to be environment-agnostic by
piggybacking on popular programs used across different environments such as a
multi-platform web browser.
Therefore, for a malware to successfully execute, it must be running in the right
environment. Dependency on the system environment is the most critical dependency of
all. Violate this and the malware is useless. This is why static malware handling and
storage are often done in an environment in which the malware will not run.
Environment dependencies include the following:
Operating system
System settings
Virtualization
Operating System
The operating system (OS) is the link between applications and system hardware. It is a
software platform that manages hardware, peripherals, and any other resources the system
uses. Without it, no application would be able to run or communicate with any hardware
resources such as the keyboard, mouse, and monitor. For an application to function
properly in a system, it must be written to run in the operating system that is present on
the system. Malware is an application, so it must be written, therefore, to run in the
operating system that is running on the target system.
An operating system dependency is quite self-explanatory. The malware has to be
executed in the operating system it was written for. But it is important to remember that
operating systems are not static; they are dynamic. This means there will be bugs
discovered that need to be fixed or features that need to be added to improve the operating
system’s functionalities. These fixes and improvements come in the form of service packs
(SPs).
TIP
Get the latest service pack or update for Windows from
http://windows.microsoft.com/en-us/windows/service-packs-
download#sptabs=win8other.
Different Windows versions can have different service pack levels. In some cases, a
malware will run on a Windows system only with the latest service pack, or in the case of
older malware, they might run properly only with older service packs installed. This is
because service packs introduce several updates and bug fixes that might impact or close
the holes that malware exploits to execute properly. Service packs also modify some
system structure that renders old malware to be useless because the new structure is
unsupported by the malware code. For example, disabling autorun, which is covered under
the Security Advisory (SA) 967940 update, has contributed to a decline in the autorun
capability exploiting malware and having sandboxes with this update installed will not be
able to properly see the autorun capabilities of these types of malware. Therefore, it is
important to be mindful of service pack changes that might affect malware execution.
TIP
Always keep different OS flavors and service packs on hand. You never know
when you will need them.
An executable written for a specific operating system will have a format specific to that
operating system. Only the operating system it is written for will be able to understand
that specific file format and thus execute the file. This is a good way to determine whether
a certain executable will run in a target system. There are lots of tools that can be used to
determine an executable’s file format. This enables you to know whether the file is worth
analyzing in the first place. For example, an executable file determined to be a Linux
executable is of no interest to you if you are concentrating on Windows executable files. If
this is the case, you do not need to analyze the file further.
In automated malware analysis systems, this is an important process in weeding out
files. Executable files or any other file format that is not supported by the automated
malware analysis system will not be submitted anymore. These files will be discarded,
which saves sandbox resources. Say a system receives 100,000 samples a day, but 30
percent of those samples are unsupported. If each file is processed for 30 seconds in the
sandbox, then weeding out those files saves the system 900,000 seconds, or 250 hours.
System Settings
System settings are another important aspect of successfully executing malware. A
restrictive setting might not be a good idea when it comes to providing malware with an
environment to properly run on. Although some malware is designed to circumvent even
the most restrictive settings, it is still a good idea to make a malware test environment
more malware friendly. This also includes a more relaxed setting for other key programs
that malware utilizes, such as Internet browsers.
TIP
In some cases, malware will expect a more restrictive setting, especially if it is
written for targeted attacks. If this is the case, always keep environment images
with restrictive settings.
You can find the Windows 7 security settings in the Control Panel, as shown in Figure
5-1.
Figure 5-1 Windows 7 security settings.
If you want malware to connect freely to the network resources it needs, you will have
to turn off or deactivate the network firewall. If you want the malware to do what it needs
to do in the host, you need to disable virus protection, spyware, unwanted software
protection, and Windows Defender, among others. User Account Control (UAC) will need
to be disabled as well so the malware can make whatever changes it needs to the system
during installation or infection.
Virtualization
You can implement a malware test environment in two ways: virtualized and bare metal.
Most implementations are virtualized because those implementations are cheaper (one
machine can host multiple guest OSs) and faster to restore. But with the rise of
virtualization-aware malware, they are not always the best choice unless the analyst
knows beforehand that the malware being analyzed is not virtualization-aware or virtual-
aware.
LINGO
Virtualization-aware, virtual-ware, and VM-aware all mean the same thing.
Although there are tricks that can be employed to fool the malware that it is not running
in a virtualized environment, it takes only a short amount of time for the malware writers
to circumvent this, especially if the trick is already public. If it is already in the public
domain, chances are the malware writers are already working for a solution to undermine
that specific trick. Therefore, it is always advisable to have a bare-metal system ready
when the need arises.
TIP
When people ask me which implementation I prefer, I always tell them that I
run an unknown malware in a virtualized environment first, and when nothing
happens, then I use my bare-metal environment.
Program Dependencies
Malware that has specific functions most of the time has program dependencies. Some
malware utilizes specific programs for it to achieve its directive. The programs or
applications the malware depends on are usually common on systems that are used
regularly but not in dynamic analysis systems. This is the reason why malware runs
successfully in a victim system but not in a test environment. To mitigate this, the test
environment or malware analysis system must mimic a system that is used for everyday
computing. Familiarizing yourself with the often-used program utilized by malware will
help you in setting up a test environment that is as close to a real-world computing system
that is being used regularly.
For example, most mass-mailing worms need the presence of an e-mail client. If no e-
mail client is installed, they will not work. The malware will not be able to send copies of
itself through e-mail. The most common e-mail client that is often abused by malware is
Outlook. Having Outlook installed in a target system will help in satisfying this program
dependency. But simply having Outlook may not be enough. In most cases, a mass-mailer
malware will need to read an existing address book to know where to send copies of itself.
An empty address book will not work; the address book must have entries.
TIP
Put entries in the address book of a malware test environment that point to e-
mails that you control. This will help you determine whether the mass-mailer is a
success and what kind of e-mail is being sent. This is good for formulating an
anti-spam solution.
Attackers understand that not all target systems will have Outlook, especially those
systems that are owned by home users. If this is the case, mass-mailers will often utilize
Outlook Express, which comes with Windows. To make sure that the malware can
successfully utilize it, Outlook Express must be configured, and the address book must be
populated. Take note that newer versions of Windows do not have Outlook Express
anymore, but if the test environment uses a flavor of Windows with Outlook Express, it
must be configured to make the system more malware friendly.
Another popular program that malware is often dependent on is the Internet browser.
Everybody who owns or has access to a computer, be it a desktop or mobile device, will
always use an Internet browser. This is why the browser is also arguably the most abused
program. It is not only used as a dependency but also used as an infection vector for
malware. An Internet browser is also a good candidate for exploitation by the attackers,
especially if it has lots of vulnerabilities. An attacker can exploit any of the Internet
browser’s known vulnerabilities and deploy a malware to a target system.
The presence of vulnerabilities is not the only reason why Internet browsers are
important to attackers. Going back to program dependency, Internet browsers are our
windows to the Internet. Browsers enable all of us to access web-based services such as
webmail and social networks. A malware that wants to minimize program dependency on
something that is already installed on a possible target system that almost everybody uses
finds Internet browsers an attractive candidate. For example, a malware that wants to spam
e-mails can hook into an Internet browser so that every time a user logs in to a webmail
service, the malware can take over and send spammed copies of itself to the contact lists
of the compromised user and even reply automatically to new e-mails that are received. It
is therefore important to have an analysis system where malware like this is submitted to
have an Internet browser running and logged in to an active and controlled webmail
account.
Another example of a malware that finds Internet browsers useful is one that uses
social networks as an infection vector. These types of malware rely on a user to be logged
in to a certain social network for the malware to function properly. For example, the
Trojan known as Febipos takes advantage of a victim’s Facebook account once it
compromises the target machine. As described by Microsoft, it performs several social
network–related tasks such as liking a page, sharing a post, posting messages, joining a
group, inviting friends to a group, commenting on posts, and sending messages and links
via chat. For malware with similar behavior, it is important to fire up an Internet browser
first and then log in to a controlled social network account on the analysis system before
the malware is executed.
Aside from e-mail clients and Internet browsers, Portable Document Format (PDF)
readers, chat software, and file-sharing programs are among the programs that malware
utilizes for its own malicious purpose.
TIP
Always keep a collection of different versions of often-exploited programs just
in case they aren’t available for download anymore.
Having familiarity with how malware uses the different programs it is dependent on
ensures that it will execute as intended in the malware analysis system. A good malware
test environment must have all or some of these programs installed to increase the chance
of the malware executing properly and the analyst collecting data from the dynamic
malware.
Timing Dependencies
Timing is everything. This is also true for malware. Depending on the attack, a malware
might go dormant for a significant amount of time before striking, or it can strike
immediately after it has taken hold of a target system.
Timing dependencies usually have to do with a malware payload. A malware payload is
a malware function that reveals what it really is. It can be considered a malware’s main
directive. For example, a malware with a payload of deleting all files in the system can be
considered a Trojan because of its destructive directive. It is important to determine what a
malware’s payload is because it enables researchers and analysts to come up with
preventive measures and solutions to mitigate it.
Execution of a malware payload can be instant, or it can be based on a specific
condition such as date and time, which is known as a time trigger. A malware might wait
for a certain time in the day to execute its payload. For example, a malware might trigger
its information-stealing function every 3 a.m. when nobody is around. Or the malware
might wait for a specific date to activate its payload. The Conficker worm actually
grabbed headlines years ago that it was going to trigger some mysterious payload on April
1. Nothing happened. April 1 is April Fool’s Day after all.
TIP
To check whether a system is infected by Conficker, use the Conficker Eye
Chart located at www.confickerworkinggroup.org/infection_test/cfeyechart.html.
A timing dependency can also mean dormancy, where the malware sleeps or does
nothing for a certain amount of time. This can range from minutes to even months. This is
a common evasive technique against automated malware analysis systems. An analysis
system gives malware only a limited time to execute. It is usually 30 seconds to 3 minutes.
Because of this timing dependency, the malware will not execute, and therefore no
malware activity will be recorded. This is why it is wise to have a manually driven
analysis system for special malware such as malware with a timing dependency.
A telltale sign that a malware might have a timing dependency is a function that
enables it to determine the local system time. In the old days, it was easy to manipulate
malware that had timing dependencies. A simple change in the system date and time to
coincide with the malware’s trigger usually did the trick. Obviously, the malware writers
were aware of this. The malware writers knew that system date and time could be
manipulated, especially in malware-testing environments. To mitigate this, the attackers
programmed their malware to check Network Time Protocol (NTP) servers to determine
the real current date and time. NTP synchronizes the time across computer systems. Of
course, malware checking NTP servers works only if the compromised system is online.
Event Dependencies
As I discussed in the previous section, the execution of a malware payload can depend on
timing. It can be instant, or it might take a longer period of time. The exact time or length
of time before a malware executes its function or payload is called a time trigger. But this
is not the only trigger there is. There is also another that is based on a specific condition.
This condition can be an event or series of events. It is called an event trigger.
An event can be anything that goes on inside the system. Some examples are pressing a
key, clicking the mouse, moving the mouse pointer to a certain location, putting the
system to sleep, shutting down, and starting up. These events can trigger a malware
payload. For example, On Windows, a key press combination of Alt+Prtscrn is used to
capture the active window as an image in the clipboard. An information stealer malware
might use this as an event trigger to save the current clipboard for later exfiltration. A
more complex event can be the execution of an Internet browser followed by a series of
keystrokes that spells out an online banking site. This event can trigger a keylogger,
desktop capturer, or memory scraper with the purpose of stealing banking credentials.
An event can also be outside the system. For example, a social media or website update
can be considered an event. If a certain monitored social media site or website posts
something that triggers a malware to act, then that posting is considered a malware trigger
event. This is especially useful for botnets that are utilized for spamming jobs. A botnet
agent can simply monitor a specific product’s website for an announcement, and once an
announcement is done, the botnet sends out its spam e-mails that could be carrying
malware. For example, if the botnet wants to send spam about a new Apple product, it can
simply monitor Apple’s website for any announcement of a new product and then trigger
its spam to potential victims announcing that they have won that new product and all the
user needs to do is to click a link to claim the prize or download or double-click an
attachment.
Malware that has event dependencies is challenging when submitted to an automated
analysis system. The only time an automated analysis system will succeed in executing the
malware is when all of the events are satisfied and thus triggering the malware. In actual
practice, malware with event dependencies is often analyzed manually to fully understand
its capabilities. Only then will those events be added to an automated analysis system.
Spotting malware that has event dependencies depends on the functions it exhibits.
Malware that has functions monitoring any system events or external resource such as
online feeds will likely have a payload that is event-triggered.
User Dependencies
Some malware depends on targeted users to achieve its directives. It takes advantage of
users in two ways, as follows:
Compromise accomplice
Roles and access
Compromise Accomplice
As much as possible, malware writers want their malware to be able to compromise a
target without any form of user interaction. The more silent and hidden the malware is, the
less chance it has of being detected. But there are cases where malware needs the user to
accomplish its task, and as a result, the users become accomplices to the infection of their
own systems.
Users being used by malware as unwitting accomplices to its initial stage of
compromise is nothing new. Some malware has always been dependent upon the users to
do what the malware cannot do such as bypassing security features that only the user can
disable. This is especially true when malware needs the user to click buttons for the
malware installation to proceed. Scareware such as fake AV malware is notorious for this.
Since it has disguised itself as a legitimate security product to fool the user, the user
simply clicks whatever the malware wants the user to click to have the fake AV malware
installed on the system. This is a good method of bypassing Windows UAC. Socially
engineering the user to grant the malware administrator rights is one sure way of getting
the malware installed on the target system. For this type of user dependency to be
successful, the malware must be able to fool users through social engineering or scare
tactics, which are techniques used by scareware, and get them to do anything that the
malware or disguised malware wants them to do.
Recap
In this chapter, I discussed the different malware dependencies and how each affects the
successful execution of malware. They are as follows:
Environment dependencies
Program dependencies
Timing dependencies
Event dependencies
User dependencies
File dependencies
Knowing a malware’s dependencies is critical to ensuring that it is able to execute all of
its intended function in a controlled environment. This is key when extracting information
during dynamic analysis. A malware that is running successfully in a controlled
environment enables you to capture more data to understand the malware’s main directive.
PART
II
Malware Research Lab
CHAPTER
6
Malware Collection
N ow that you have an idea of the different classes of malware, the different
technologies used to deploy malware, the different protective mechanisms
malware employs to protect itself, and the different dependencies malware has to
execute properly in a target system, you are ready to tackle malware.
The ability to analyze, scrutinize, and examine malware requires the use of computer
systems that are set up for the purpose of unraveling the mysteries of malware. These
computer systems serve as the malware analyst’s research lab, commonly known as a
malware research lab. A malware research lab is a collection of systems fully under the
control of malware researchers and analysts. It is not for production nor does it serve any
other purpose besides the research and analysis of malware. A malware research lab
consists of different systems that have a special purpose, the most common of which are
the following:
Malware collection lab
Static analysis lab
Dynamic analysis lab
A malware collection lab is a system or collection of systems designed solely to collect
malware samples from different sources. A static analysis lab is designed to gather data
from malware while it is at rest, and a dynamic analysis lab is designed to gather data
from malware while it is in motion.
In this chapter, I will concentrate on malware collection. I will discuss the different
sources of malware samples and the ways of collecting them from these sources.
The following are the most common sources of malware samples:
Your own backyard
Free sources
Research mailing lists
Sample exchange
Commercial sources
Honeypots
Before malware analysis can begin, you must have malware samples on hand. Malware
has to be available. It is therefore important that you first familiarize yourself with the
different sources of malware.
Free Sources
If you don’t have the time or energy to devote yourself to helping your friends and
relatives with their computer woes, you can always get malware samples from free
sources. There are lots of well-meaning researchers who devote time and effort to helping
the security community; one of the most awesome things they do is make malware
samples available to those who will be using them for research. The following are some of
the free sources:
Contagio
KernelMode.info
MalShare.com
Malware.lu
Malware Blacklist
Malwarebytes forum
Malekal’s Forum
Open Malware
Tuts4You
VirusShare.com
VX Heaven
Malware trackers
TIP
There is always a risk of infection when using these sources. Please be
responsible when clicking links and downloading files. It is always best to access
these resources from a machine that is isolated from any production or home
network.
Contagio
Contagio is operated by Mila Parkour, a well-known researcher in the security community
based in Washington, D.C. Contagio has two excellent sources of malware samples:
Contagio Malware Dump and Contagio Sample Exchange.
KernelMode.info
KernelMode.info, a forum for kernel-mode exploration, is a good source for discussing
and exchanging malware samples and anything related to it. Registration is required to
join.
From the main page, as shown in Figure 6-8, clicking the Malware forum leads to
topics covering the hottest malware and also to forums where you can request malware
samples and view completed malware requests.
Figure 6-8 KernelMode.info main page.
MalShare.com
MalShare.com, as stated in its splash page, shares samples collected from online scraping
of blacklists and not from any interaction of the owner of the site with customers or
clients without their consent. To be able to request samples, the user must have an API
key and know the sample’s MD5 hash. But before that can happen, you must agree to the
legal disclaimer at http://malShare.com. After agreeing to the legal disclaimer, you are
taken to http://api.malShare.com, as shown in Figure 6-9, where you can request a sample.
Figure 6-9 MalShare.com sample request page.
To get an API key, you must send an e-mail request to api@MalShare.com with the
subject “API Key Request.” The body of the e-mail must contain the user’s name and e-
mail address. Figure 6-10 shows what the e-mail request looks like.
Figure 6-10 API key request e-mail format.
Malware.lu
Malware.lu, as shown in Figure 6-11, is a good source for malware samples and malware
information articles. It is operated by itrust consulting located in Luxembourg.
Registration is required to access the sample repository. To request an account, as
explained on the site, send an e-mail to register@malware.lu with the desired username
and a short explanation of why you want to have an account.
Figure 6-11 Malware.lu main page.
Malware Blacklist
Malware Blacklist, located at http://malwareblacklist.com, not only contains malware
samples but also contains the biggest repository of malicious uniform resource locators
(URLs), as shown in Figure 6-12.
Figure 6-12 Malware Blacklist main page.
Registration is required to download the samples. To register, click Login and then
click Create A Free Account. A contact form page, as shown in Figure 6-13, will open.
The user must provide all the information asked in the contact form to be able to
successfully register.
Figure 6-13 Malware Blacklist contact form.
NOTE
Sometimes there is a limit on the number of downloads a free user can get. The
reasons for this can vary. One of the most common reasons is user reputation. A
user who contributes more will be able to download more.
Malwarebytes Forum
The Malwarebytes forum is a good source for anything about malware including malware
removal. The main forum is located at http://forums.malwarebytes.org. But the main page
of interest is the Newest Malware Threats forum. A direct link to this forum is
http://bit.ly/13xUEvm.
To gain access to samples, registration is not enough. A registered user has to contact
the forum administrators/moderators to ask for access to download samples. This is one
way of ensuring that nobody can just download samples and that only experts who have
experience in handling malware will be able to do so. This minimizes the risk of having
unwanted malware infection or, worse, an outbreak.
Malekal’s Forum
Malekal’s Forum is a French forum where malware samples are collected daily and
compressed in a single ZIP file that can be downloaded on a daily basis. Malekal’s Forum
is located at http://malwaredb.malekal.com. You can find the ZIP file containing the daily
samples on the lower-right side of the page, as shown in Figure 6-14. Just click the ZIP
icon to download the daily collection.
Figure 6-14 Malekal’s Forum main page.
Open Malware
Open Malware is not only a good source for malware samples but a good source for
security-related articles. The main page, as shown in Figure 6-15, is located at
http://openmalware.org.
Figure 6-15 Open Malware main page.
Searching for malware in Open Malware is easy. You can use a hash or part of the
malware name. For example, using Conficker as a search argument yields 20 matches, as
shown in Figure 6-16.
Figure 6-16 Open Malware result for Conficker search.
You can then download the samples you need. But before downloading the sample, you
need to have a Google account and agree to grant Open Malware the right to view the
following:
Basic information about the account
The e-mail address
Figure 6-17 shows the splash page that prompts the user to accept these terms.
Figure 6-17 Open Malware splash page that prompts users to give access to their
Google accounts.
Notice that in the results page in Figure 6-16, the domain name is
http://gtisc.gatech.edu. This is Georgia Tech’s GTISC, which stands for Georgia Tech
Information Security Center. Clicking Home on the results page brings the user to
http://oc.gtisc.gatech.edu:8080, which is the main page for the search. It does not have any
links to any articles. It simply has a search box similar to the one on Open Malware’s main
page. It has a minimalist design that gets the job done, especially if your main purpose is
searching for malware samples.
Tuts4You
Tuts4You is a forum that caters not only to sharing malware samples but also to educating
the user in the art of malware analysis and reversing. This is a good source for anyone
who wants to get into battling the malware threat. The forum is located at
http://forum.tuts4you.com. From there, you can search for malware samples or any other
topics that might interest you. For example, if you want to download StuxNet samples
posted by other community members, a simple search for StuxNet will bring you to the
page, as shown in Figure 6-18, where you can share in the discussion and download the
StuxNet sample.
Figure 6-18 Tuts4You Stuxnet search result.
VirusShare.com
VirusShare.com is a no-frills malware sample–sharing site. The most pertinent
information about the malware and the download link are right there in front of you, as
shown in Figure 6-19.
Figure 6-19 VirusShare.com sample information.
Aside from downloading samples individually, which can be done by clicking the
download icon in the upper left of the sample information page, you can also download
large collections of malware samples. You can find the link to the samples and instructions
on how to do this in the “Torrents” section of the page.
Registration is needed to be able to download samples. As posted in the site, access to
the site is granted via invitation only. You must send an e-mail request to
admin@virusshare.com explaining who you are and why you need access.
VX Heaven
VX Heaven, located at http://vxheaven.org, is a good source for classic malware. It
contains malware source code, encryption and mutation engines, malware kits, malware
simulators, and utilities for malware collection. In addition to those mentioned, VX
Heaven contains lots of articles concerning malware technologies.
Malware Trackers
Malware trackers are a good source of in-the-wild malware. An in-the-wild or wild
malware is one that is released intentionally or accidentally into the world that has caused
infection and compromise or is currently infecting or compromising systems. In other
words, these are malware samples that have been used in or are currently being used in an
attack campaign.
The following are the most popular malware trackers:
ZeuS tracker
SpyEye tracker
Palevo tracker
These malware trackers are a good source of wild malware and are good sources of
command and control (C2) servers, malware download domains, and domain drop zones.
In addition to providing this useful information, these malware trackers also provide
malicious domains and Internet Protocol (IP) blacklists for download so users can use
these blacklists (or blocklists as they are referred to by the trackers) to protect systems
under their control. Snort rules and IP blacklists for iptables are also available for
download.
ZeuS Tracker
ZeuS Tracker tracks the latest active Zeus infections. The main page is
https://zeustracker.abuse.ch, but the page where wild Zeus samples can be downloaded is
https://zeustracker.abuse.ch/monitor.php?browse=binaries, as shown in Figure 6-20.
SpyEye Tracker
SpyEye Tracker tracks the latest SpyEye infections. The main page is
https://spyeyetracker.abuse.ch, but the page where wild SpyEye samples can be
downloaded is https://spyeyetracker.abuse.ch/monitor.php?browse=binaries, as shown in
Figure 6-21.
Palevo Tracker
Palevo Tracker tracks the latest Palevo (also known as Mariposa Butterfly, Rimecud, and
Pilleuz) infections. The main page is https://palevotracker.abuse.ch, as shown in Figure 6-
22. As of this writing, I did not find any ways to download Palevo samples, but since the
MD5 hash of the samples are displayed, they can be used to query other free malware
sources that have been discussed previously. Also, the wealth of information available on
the tracker page, including the sample’s Anubis and VirusTotal report and the availability
of blacklists, is more than enough evidence to show how important this malware tracker
is.
Sample Exchange
Most security companies are involved in malware sample exchange or sharing. Sample
exchange is done on a periodic basis, usually weekly or monthly. The main idea here is
that all members of the sample exchange dump all of the new malware samples that they
have collected during a given time period and then organize them in a way that follows
the agreed-upon sample exchange protocols; in return, they get access to the samples
being shared by the other members.
The main reason why security companies do sample exchange is to make sure all users
are protected regardless of who their security provider is. In my opinion, this is a noble
activity by security companies since it is more about providing protection than making a
profit.
Another advantage of being a security professional is that if you work for a security
company that is involved in some sort of sample exchange, then there is no need to exert
much effort in other ways of procuring malware samples for research purposes.
Commercial Sources
Malware samples, especially fresh ones, are considered commodities. This is why there
are businesses out there that sell malware samples to vetted companies for the purpose of
research. These commercial sources of malware usually specialize in the collection of
malware in the wild. They build their malware collection with the sole purpose of selling
the malware.
Purchasing malware samples from these sources is sometimes the most practical way
for a company that is doing malware research to get malware samples. Instead of investing
time and money in building systems to collect malware, it is often much more feasible to
just buy them. Sometimes the juice is not worth the squeeze; it is like outsourcing the
process of building and maintaining systems to collect malware to a commercial source.
Honeypots
Even with the different sources available to get your hands on malware samples, it is
always better to learn how to build systems that collect malware. In malware collection,
honeypots are the main systems used to collect malware automatically.
As defined in most literature,1 a honeypot is an information system resource whose
value lies in unauthorized or illicit use of that resource. The idea behind this methodology
is to lure in attackers such as automated malware. As a consequence, the automated
malware used in the attack can be collected and then studied in detail.
There are two general types of honeypots.2
Low-interaction
High-interaction
Low-interaction honeypots2 offer limited services to the attacker. They emulate
services or operating systems, and the level of interaction varies with the implementation.
The risk tends to be low. In addition, deploying/maintaining these honeypots tends to be
easy. With the help of low-interaction honeypots, it is possible to learn more about attack
patterns and attacker behavior.
High-interaction honeypots, on the other hand, offer the attacker a real system to
interact with. More risk is involved when deploying a high-interaction honeypot; for
example, special provisions are created to prevent attacks against systems that are not
involved in the setup. They are normally more complex to set up and maintain.
NOTES
Low-interaction honeypots are emulated, while high-interaction honeypots are
real systems.
Depending on the need, a honeypot system can be emulated or implemented as a real
system. There are pros and cons to this. Low-interaction honeypots have fewer risks of
infection than high-interaction ones. Deployment and maintenance are easier in low-
interaction honeypots compared to high-interaction honeypots, making low-interaction
honeypots more scalable. But one advantage a high-interaction honeypot has over a low-
interaction honeypot is the ability to study the attack in more detail because high-
interaction honeypots, being based on a real system, offer full system functionality,
making high-interaction honeypots much more expressive. In other words, low-interaction
honeypots score high on scalability, while high-interaction honeypots score high on
expressiveness.
Dionaea
Dionaea offers both of these advantages: the scalability of low-interaction honeypots and
the expressiveness of high-interaction honeypots. Dionaea, as defined by its creator, is a
system intended to trap malware that exploits vulnerabilities exposed by services offered
to a network with the ultimate goal of gaining a copy of the malware.
NOTES
Before Dionaea, there was Nepenthes. But it is not available in most
repositories anymore. Dionaea is actually meant to be a successor of Nepenthes,
and it is advised not to use Nepenthes anymore and use Dionaea instead.
Dionaea can be installed in different Linux flavors as mentioned on its homepage, but in
this lab, you will install Dionaea in Ubuntu 64-bit 12.04 LTS.
NOTE
If you are new to Ubuntu, you can visit http://www.ubuntu.com for more
details. Also, how to set up Ubuntu will be discussed in the next chapter.
What You Need:
Ubuntu 64 bit 12.04 LTS
Steps:
1. Install Dionaea dependencies.
2. Compile and install Dionaea.
3. Check for successful installation.
4. Update Dionaea.
Step 1: Install Dionaea Dependencies
Some dependencies are provided by apt-tree, while some need to be installed from source.
To begin installing, please open a terminal window in Ubuntu and execute the following
commands.
Dependencies Provided by apt-tree
Install liblcfg.
Install libemu.
Install libev.
Install Cython.
Install libpcap.
Step 2: Compile and Install Dionaea
Compile and install Dionaea next.
The –H switch displays Dionaea’s help menu together with its default values, while the
–h switch simply displays the help menu.
Step 4: Update Dionaea
A freshly installed Dionaea does not need to be updated, but as time passes, it is always
good to regularly update your Dionaea installation. To do this, execute the following
commands inside the clone folder of Dionaea. This is the folder produced by the git clone
command in step 2.
If a message saying “Already up-to-date” is shown, then you’re good to go; otherwise,
issue the following command:
After the update, it is always good to make sure your config file is up to date. To do
this, issue the following command:
Once you have installed Dionaea, you can visit http://dionaea.carnivore.it/#running for
more information on how to use and configure Dionaea.
Recap
In this chapter, I defined what a malware research lab is and the common purpose it
serves. The following are the types of labs:
Malware collection lab
Static analysis lab
Dynamic analysis lab
In addition, I concentrated the discussion on one purpose of the malware research lab:
malware collection. I enumerated the different sources of malware and showed that not all
of them require a lab setup, but it is always good practice to browse online malware
sources from a system that is totally isolated and is designed solely for the purpose of
collecting malware.
The following are the different sources of malware I discussed:
Your own backyard
Free sources
Contagio
KernelMode.info
MalShare.com
Malware.lu
Malware Blacklist
Malwarebytes forum
Malekal’s Forum
Open Malware
Tuts4You
VirusShare.com
VX heaven
Malware trackers
Research mailing lists
Sample exchange
Commercial sources
Honeypots
Knowing the different sources of malware and how to collect them is important in your
journey of analyzing malware.
Tools
In this chapter, I discussed and made use of the following tools:
Free online antivirus scanners
Trend Micro HouseCall http://housecall.trendmicro.com/
F-Secure Online Scanner http://www.f-
secure.com/en/web/home_global/online-scanner
Free malware removal tools
Microsoft Security Essentials http://windows.microsoft.com/en-
us/windows/security-essentials-download
Comodo Cleaning Essentials http://www.comodo.com/business-
security/network-protection/cleaning_essentials.php
Kaspersky Security Scan http://www.kaspersky.com/free-virus-scan
Rootkit detectors
Rootkit Revealer by
Microsoft http://download.cnet.com/RootkitRevealer/3000-2248_4-
10543918.html
TDSSKiller by
Kaspersky https://support.kaspersky.com/us/viruses/utility#TDSSKiller
Startup examination tools
Autoruns by Microsoft http://technet.microsoft.com/en-
us/sysinternals/bb963902.aspx
Autorun Analyzer by Comodo http://www.comodo.com/business-
security/network-protection/cleaning_essentials.php
Boot analyzer tools
Gmer’s MBR.EXE http://www.gmer.net
MbrScan http://eric71.geekstogo.com/tools/MbrScan.exe
MBR Backup http://www.trojanhunter.com/products/mbr-backup/
Boot Sector Explorer http://www.pendriveapps.com/boot-sector-
explorer-backup-and-restore-mbr/
Nate’s MBR and Boot Sector Analyzer http://www.aqfire.com/boot/
WinHex MBR / boot sector editor http://www.winhex.com/disk-
editor.html
Process examination tools
Process Explorer by Microsoft http://technet.microsoft.com/en-
us/sysinternals/bb896653.aspx
KillSwitch by Comodo http://www.comodo.com/business-
security/network-protection/cleaning_essentials.php
Honeypots
Dionaea http://dionaea.carnivore.it
1 Microsoft Technet: http://technet.microsoft.com/en-US/.
2
Malware, Rootkits & Botnets by Christopher C. Elisan, published by McGraw-Hill.
CHAPTER
7
Static Analysis Lab
C ollecting malware samples can be as easy as going online and downloading the
samples from a website where malware samples are shared freely, or it can be as
difficult as extracting the samples from an infected system using different kinds of
system forensics tools. But one thing is certain once a malware sample is collected. The
first step in determining its true nature is to have it undergo static analysis.
Static analysis is the process of extracting data from a file while the file is at rest, or
static. From this data, information is formulated to determine whether the file is malicious.
Static analysis was successful during the early days of computer viruses, but as malware
became complicated and able to apply protective mechanisms such as encryption while
the malware is static, static analysis usually comes up short when it comes to determining
a file’s true behavior and, in the case of malware, the malware’s main directive. But this is
no reason to discount static analysis altogether. Static analysis can still offer a glimpse,
albeit limited, of the suspicious file’s nature. So, static analysis is still a useful first step in
the process of determining the malware’s true directive.
The process of static analysis is made possible by different file inspection tools and the
system where all these tools are correctly installed and configured. Static analysis is not
possible without the right combination of these two.
In this chapter, I will focus on the system where static analysis is conducted. I will
discuss how to set up a static analysis lab that will host different file inspection tools.
Anonymous Communication
A static analysis lab can also be used to conduct research online or download tools or
malware samples from different sources. It is always good to have any malware research
lab anonymized in case there is a need to do these tasks. It is a precaution to protect the
systems from being blocked by attackers or, worse, become a target of their distributed
denial-of-service (DDOS) attack. You also do not want the organization where the
malware research lab is located to be tagged by attackers.
TIP
It is always good practice to anonymize all malware research labs.
NOTE
Some researchers prefer a separate system to do online research, but it is still
good to have the system anonymized so nothing will be traced back to the
researcher or organization doing the research.
It is also important to consider backup and restoration of the static analysis lab in case
of failure. As you know, all computer systems carry the risk of failure one way or another.
It is better to be prepared for this scenario so static analysis operation can continue without
any significant downtime.
Windows
When creating a static analysis lab running on Windows, I always opt for Windows 7 32-
bit. The main reason for me choosing 32-bit is to cater to most static analysis or file
inspection tools that are widely used today. Take note that this is a personal preference;
please feel free to use 64-bit if you desire to do so. Most tools will run there too, and it’s
just a matter of time that all the tools will run seamlessly in 64-bit.
Installing Windows is quite easy and well documented already, so I will not delve into
it that much. Instead, I will focus more on solving issues relating to its installation,
especially those that are common in installing Windows in a bare-metal environment.
Some of the issues are the following:
“A required CD/DVD drive device driver is missing” error
Systems shipped without CD/DVD drives
“A required CD/DVD drive device driver is missing” Error Most researchers use a
Microsoft Developer Network (MSDN) subscription to download various flavors of
Windows ISO images and burn them onto a disc. This is a common practice. But using
this type of installer disc and not the one provided by the computer manufacturer to set up
Windows often leads to an error message that pops up during installation. The error
message is “A required CD/DVD drive device driver is missing.” This is easily solved by
using the installation discs provided by the manufacturer or invoking the restoration
procedure using the OS backup that came pre-loaded on the computer’s hard disk. But in
most cases, the installation discs are no longer available or accessible, and the hard disk
has been reformatted to fit the researcher’s need, thus losing whatever restoration files that
are there. So, the only choice is to use a Windows installation disc burned from MSDN-
provided Windows ISOs.
The main reason for the error message appearing during installation is because
Windows 7 installation discs do not have all the system drivers for all manufacturers.
Windows 7’s generic drivers do not work either.
When the disc is inserted and the option to boot using the disc drive is activated, the
Basic Input/Output System (BIOS) spins the drive and checks whether the disc is
bootable. If it is, it loads the data from the installation disc. Control is then passed to
Windows so it can proceed with the installation. Since most of the data Windows needs to
continue installation is on the disc, it needs to be able to read the contents of the disc. But
then when it tries to control the disc to read data, Windows is not able to do it because it
does not have the correct drivers to do it. This is because the BIOS was not able to or does
not have the capability to pass the disc driver it used to Windows. As a result, Windows
has no interface to control the disc drive, and the error message, “A required CD/DVD
drive device driver is missing” appears. For Windows to have the ability to control the
disc drive, the user has to provide the driver.
Take note that the driver Windows 7 needs is not the one that comes with or is provided
by the disc drive manufacturer but the RAID/SATA/IDE driver of the motherboard. You
can download this driver from the computer manufacturer’s website, or you can ask the
manufacturer to send you a copy on a disc.
The driver files are usually compressed in ZIP or RAR format. Make sure they are
decompressed and copy them to the installation disc, a thumb drive, or a separate partition
in the hard disk. When Windows 7 asks for the drivers during installation, browse to the
folder where the drivers are located, and installation will proceed unless the drivers are
wrong. If the drivers are wrong, make sure you find the right one and try again. If
everything is OK, you should be good to go.
If after the first reboot Windows 7 spits out an error about the digital signature being
invalid or needing verification because it does not recognize the newly installed driver,
simply reboot the machine and press the button that will bring you to the BIOS boot
option. Once inside, disable the driver signature enforcement capability, save, and reboot
again. This should fix the problem.
LAB 7-1: Extracting and Copying Drivers to the Windows 7 Installation Media
System Shipped Without CD/DVD Drives Most laptops today, especially the thin and
lightweight ones, ship with no disc drives. However, there is an option to buy an external
disc drive, but I find this to be bulky, especially if the aim is to travel with the static
analysis lab. In cases like this, I use a thumb drive or a USB stick as the installation
medium for Windows 7.
To create a thumb drive or a USB Windows 7 installer, you need to do the following:
1. Create a bootable USB stick.
2. Copy the Windows installation file to the USB stick.
3. Copy important drivers and other tools to the USB stick.
A bootable thumb drive that has the Windows 7 installation files should be treated
similar to a bootable Windows 7 installation disc. Everything else is the same except the
media. It is good to have all the drivers copied into the thumb drive. This makes it easy to
install the drivers. For me, I always use a Bluetooth-connected mouse rather than the
touchpad because of its sensitivity. Having my Bluetooth mouse driver in the thumb drive
enables me to use my mouse immediately while going through the rest of the installation.
It is also good to have all the tools the analyst needs on the thumb drive. This speeds up
the installation of tools because they are in one location and also serves as a good backup
of all the essential tools needed to conduct static analysis.
NOTE
The assumption here is that disk 1 represents the USB stick. If there are
multiple internal hard disks installed or an external hard drive connected, the
USB stick will be assigned a different disk number, so please be mindful of that.
The previous command lines result in a formatted USB stick with an NTFS file
system and WIN7 as its label. Figure 7-4 shows the whole DiskPart session.
Figure 7-4 DiskPart session.
5. Look for BootSect.EXE. BootSect.EXE, as defined by Microsoft, updates the
master boot code for hard disk partitions to switch between BOOTMGR and
NTLDR. This tool can also be used to restore the boot sector on your computer. It is
a replacement for FixFAT and FixNTFS. You can find it inside the boot folder of the
Windows installer CD. BootSect.EXE requires escalated privileges. The command
line must be running at the same privilege level for this tool to work; you can do this
by right-clicking the command prompt and choosing the Run As Administrator
option. Figure 7-5 shows the context menu.
Microsoft understood that something like this is needed so it came up with a tool that
makes the creation of a bootable Windows 7 USB installer much easier. You can
download the tool from
http://images2.store.microsoft.com/prod/clustera/framework/w7udt/1.0/en-us/Windows7-
USB-DVD-tool.exe. It is called the Windows 7 USB/DVD Download Tool.
LAB 7-3: Creating a Bootable USB Stick Windows 7 Installer Using the Windows 7
USB/DVD Download Tool
In this lab, you’ll create a bootable USB stick using the Windows 7 USB/DVD Download
Tool.
What You Need:
USB stick with at least 8GB of available space
System running Windows 7
Windows 7 ISO
Driver files and other tools
Windows 7 USB/DVD Download Tool
Steps:
1. Download the Windows 7 USB/DVD Download Tool from
http://images2.store.microsoft.com/prod/clustera/framework/w7udt/1.0/en-
us/Windows7-USB-DVD-tool.exe.
2. Install the tool. Take note that the Windows 7 ISO must match the Windows 7
system where the tool is being installed.
3. Execute the tool and follow these steps:
A. Choose the ISO file.
B. Choose the USB media type.
C. Insert the USB device.
D. Begin copying to create bootable USB device.
If all steps are followed correctly and the Windows versions match, the creation
of a bootable USB device will be successful, as shown in Figure 7-8.
Figure 7-8 Bootable USB device created successfully.
4. Test the USB stick to see whether it can boot and invoke the Windows
installation.
Ubuntu
Ubuntu, as described in its official documentation, is a complete desktop Linux operating
system, freely available with both community and professional support. The Ubuntu
community is built on the ideas enshrined in the Ubuntu Manifesto: that software should
be available free of charge, that software tools should be usable by people in their local
language despite any disabilities, and that people should have the freedom to customize
and alter their software in whatever way they see fit. You can find the full documentation
at https://help.ubuntu.com.
For an Ubuntu static analysis lab, I always opt for the version that has long-term
support (LTS). As of the book’s writing, the latest LTS version is Ubuntu 14.04.1 LTS.
LTS versions usually come with five years of security and maintenance updates. Ubuntu
14.04 was released in the summer of 2014, so it gives you until 2019 for updates.
You can download Ubuntu from http://www.ubuntu.com/download/desktop. Installing
Ubuntu is simple. All that is needed is to follow the detailed documentation at
http://www.ubuntu.com/download/desktop/install-desktop-long-term-support. Ubuntu can
be installed using a DVD or USB stick. You can find instructions on how to burn an
Ubuntu DVD installer in Windows at www.ubuntu.com/download/desktop/burn-a-dvd-on-
windows. You can find instructions on how to create a bootable Ubuntu installer USB
stick at http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-windows.
The apt-get update command syncs the package index files with their sources. These
sources are usually reached via the Internet. After everything is synchronized, issuing the
apt-get upgrade command starts the installation of the newest versions of all software
packages installed on the system.
Escalated privilege is needed to accomplish the update, which is the reason for the
additional use of sudo in the command line (sudo is short for “superuser do”). Once this
command is used, you must input a root or superuser password.
In this lab, you will protect Firefox using its built-in security and privacy options.
What You Need:
System with Firefox installed
Steps:
1. If you have not done so, please download the latest version of Firefox from
http://www.mozilla.org/en-US/firefox/new/. As of this book’s writing, the latest
version of Firefox is 25.0.
2. Choose Firefox | Options | Options. The Firefox menu is on the upper-left side
of the browser window.
3. Click the Privacy icon and apply the following options:
A. In the Tracking section, make sure that Tell Sites I Do Not Want To Be
Tracked is selected.
B. In the History section, choose Firefox Will: Never Remember History.
This will restart the browser, so you need to choose Firefox | Options | Options
again.
C. In the Location Bar section, choose When Using The Location Bar,
Suggest: Nothing.
When you’re done, the Options | Privacy window should look like Figure 7-10.
Aside from the privacy and security options available to Firefox users, add-ons and
plug-ins can be installed in the browser to enhance the security and privacy of Firefox.
Some of the add-ons that I think are useful for these purposes are the following:
NoScript
BetterPrivacy
RequestPolicy
Web of Trust (WOT)
Adblock Plus
The following paragraphs are how each plug-in is described by its creator or publisher.
NoScript is a Firefox extension that provides extra protection for Firefox, Seamonkey,
and other Mozilla-based browsers. It allows JavaScript, Java, Flash, and other plug-ins to
be executed only by trusted websites of the user’s choice. NoScript also provides
protection against cross-site scripting (XSS) and clickjacking. NoScript is free and open
source.
BetterPrivacy serves to protect against special long-term cookies, a new generation of
“supercookie” that silently conquered the Internet. This new cookie generation offers
unlimited user tracking to industry and market research. Concerning privacy, Flash
cookies are critical. This add-on was made to make users aware of those hidden, never-
expiring objects and to offer an easier way to view and manage them since browsers are
unable to do that for the user. Flash cookies (local shared objects [LSOs]) are pieces of
information placed on the user’s computer by a Flash plug-in. Those supercookies are
placed in central system folders and are frequently used like standard browser cookies.
BetterPrivacy has the capability to list and manage Flash cookies, that is, to remove those
objects automatically on browser start and exit or by a configurable timer function while
certain desired Flash cookies can be excluded from automatic deletion.
RequestPolicy is an extension that improves the privacy and security of the user’s
browsing session by giving the user control over when cross-site requests are allowed by
webpages that the user visited.
WOT is a website reputation and review service that helps users make informed
decisions about whether to trust a website when searching, shopping, or surfing online.
WOT simply shows the website reputations in the form of traffic lights next to search
results when a user uses Google, Yahoo, Bing, or any other supported search engine.
Clicking the light icon displays more information about the website’s reputation and other
users’ opinions about that website.
Adblock Plus allows the user to regain control of the Internet and view the Web the
way the user wants to, that is, without annoying advertisements, tracking, and banner
displays. The add-on is supported by more than 40 filter subscriptions in dozens of
languages that automatically configure it for purposes ranging from removing online
advertising to blocking all known malware domains.
LAB 7-5: Protecting Firefox Using Add-ons and Plug-ins
In this lab, you will protect Firefox using available add-ons and plug-ins.
What You Need:
System with Firefox installed
Steps:
1. Choose Firefox | Add-ons.
2. Go to the search bar located on the upper right, look for the following plug-
ins, and install them one by one:
A. NoScript
B. BetterPrivacy
C. RequestPolicy
D. WOT
E. Adblock Plus
NOTE
Read the description of each plug-in to have an idea of what it does and offers.
TIP
These are third-party plug-ins, and they may carry certain risks. Make sure
you understand the consequences of installing third-party applications, add-ons,
and plug-ins.
Restrict Access
It is always good practice to have the least privilege account running when using a system
and give or use escalated or admin privilege only when needed. In the static analysis lab,
the main tips when it comes to restricting access include the following:
Run under the least privileged account.
Give tools admin access only when needed.
Run Under the Least Privileged Account Anyone who has experienced or has been
compromised with malware knows the importance of having a least privileged account
currently logged in when the malware is attempting to infect the system. A least privileged
account usually will have no or limited access to resources that the malware needs to
successfully compromise a system. Although it is possible that the malware has
technology to get around this, it is still important to make life difficult for the malware.
And if malware ever became successful in compromising a system with a least privileged
account currently logged in, there is less damage because of limited access to vital system
resources.
Take note that the default account in older versions of Windows such as Windows
2000, Windows XP, and Windows Server 2003 is the administrator, and it has escalated
privileges. If your desired Windows static analysis lab will use any of the previously
mentioned versions of Windows, it is important to create a standard user account before
doing any form of static analysis just to be on the safe side.
Give Tools Admin Access Only When Needed Most static analysis tools will function
without the need for escalated privileges or admin access. Therefore, it is always good
practice to run a static analysis tool under the context of the currently logged-in least
privilege user. The only time a static analysis tool must be granted escalated privileges is
when it requires it to function properly.
Proxy Servers
The most common way to stay anonymous online is through the use of proxy servers. A
proxy server, also known as a proxy, is a system that acts as an intermediary between a
computer or a local network and the Internet. In other words, it acts as a middleman
between the local systems and the Internet. It does this by intercepting all connections
from the local systems and having them all come through one port. The proxy then
forwards the connections to the Internet or another network through another port. Since
there is no direct access between the local systems and the Internet, it is difficult to
identify the exact computer making the connection or request. As a result, the attackers
won’t be able to put tabs on the system or static analysis lab doing the research.
NOTE
A proxy server not only provides security but also provides increased
performance when browsing since it caches frequently visited websites.
It is important to keep in mind that communications from the local systems to the proxy
server and from the proxy server to the Internet are not encrypted. So if there is data there
that can identify the local system behind the proxy server in any way, it is possible that the
cover can be blown.
TIP
The best way to protect communication between the local system to the proxy
server and from the proxy server to the Internet is by using HTTP Secure
(HTTPS).
Lots of free proxies are available on the Internet. The following are some online
resources containing lists of free proxy servers:
Hide My Ass! http://hidemyass.com/proxy/
Proxy 4 Free http://www.proxy4free.com
Samair.RU http://www.samair.ru/proxy/
Public Proxy Servers http://www.publicproxyservers.com/proxy/list1.html
These proxy servers are open to anybody. But since they are free, they may suffer from
limited or controlled bandwidth; therefore, they may not be as fast or reliable as you want.
And there is a high chance that these proxy servers will permanently disappear without
notice, so they might be good only for temporary anonymization. This is why it is
important to always have a fresh list of publicly available proxy servers.
TIP
Free proxies carry several privacy risks. Make sure you understand the privacy
policy of the free services before using them. Free services often come with a
price, and that price has to do with giving up some of your privacy or
information. Use these services at your own risk.
For those who want a more reliable proxy service that will not disappear without
notice, the best way is to subscribe to a paid proxy service. Another alternative, if you
have the budget and resource, is to create your own.
Tor
Tor, also known as the onion router, is another popular way of anonymizing online
activities. It is free and open source. It supports multiple platforms such as Windows,
Mac, and Linux. It also supports Android. Tor, as described in its main page, is a network
of virtual tunnels allowing people and groups to improve their privacy and security on the
Internet. It also enables software developers to create new communication tools with
built-in privacy features. Tor provides the foundation for a range of applications that allow
organizations and individuals to share information over public networks without
compromising their privacy.
Tor is well documented and can be found at
https://www.torproject.org/docs/documentation.html.en.
In this lab, you will create a virtualized Ubuntu desktop that is hosted on a Windows box
using VMware Player.
What You Need:
Windows host OS
VMware Player
Ubuntu LTS ISO
Steps:
1. Download the latest LTS version of Ubuntu from
http://www.ubuntu.com/download/desktop.
2. Download VMware Player from
http://www.vmware.com/go/downloadplayer.
3. Install VMware Player.
4. Open VMware Player and click Create A New Virtual Machine, as shown in
Figure 7-13.
Figure 7-13 VMware Player.
5. Choose Installer Disc Image File (ISO): and browse to the location of the
Ubuntu ISO file.
6. Click Next and supply the needed information such as username and
password for the Ubuntu user. The succeeding windows will ask for the virtual
machine name, disk capacity, and other needed information to create the virtual
machine.
7. After supplying the needed information, click Finish to create the virtual
machine.
8. Wait while VMware Player boots up using the ISO image as its boot disk,
simulating an Ubuntu startup disk installation.
9. Proceed with the Ubuntu installation by following what is presented on the
Ubuntu installation screen.
In this lab, you will create a virtualized Ubuntu desktop that is hosted on a Windows box
using VirtualBox.
What You Need:
Windows host OS
VirtualBox
Ubuntu LTS ISO
Steps:
1. Download the latest LTS version of Ubuntu from
http://www.ubuntu.com/download/desktop.
2. Download VirtualBox from https://www.virtualbox.org/wiki/Downloads.
3. Install VirtualBox.
4. Open VirtualBox and click New, as shown in Figure 7-14, to start the
creation of a virtual machine.
Figure 7-14 VirtualBox.
5. In the next window, provide the preferred name of the virtual machine.
Choose Linux in the Type drop-down menu and choose Ubuntu (32 bit) or Ubuntu
(64 bit) in the Version drop-down menu. Then click Next.
TIP
Typing Ubuntu in the Name field will automatically change the type to Linux
and the version to Ubuntu (64 bit).
6. On the succeeding window, provide the desired memory size and hard drive
settings.
7. Once everything is done, you can start the virtual machine by clicking the
Start button represented by an arrow sign pointing to the right.
8. The first time the virtual machine starts, it will ask for a startup disk.
Browse to the location of the Ubuntu LTS ISO.
9. Proceed with the Ubuntu installation by following what is presented on the
Ubuntu installation screen.
Recap
In this chapter, I discussed the static analysis lab. I identified what makes an effective and
well-configured lab. The parameters are as follows:
Can host different file inspection tools regardless of the OS the tools are
written for
Can mitigate possible infection through hardening the system
Can mitigate the possibility of the lab becoming a staging point by malware
and attackers by isolating the lab from any production network
Can go to different online resources anonymously
I then identified the basic steps in setting up a static analysis lab, which are as follows:
Choose the hardware.
Install the operating system.
Harden the lab.
Anonymize the lab.
Isolate the lab.
Back up and restore.
I tackled how to solve Windows installation problems, especially if the hardware of
choice is a laptop with a disc drive but no device driver available or does not come with a
disc drive.
I discussed how to harden the lab by following the most common steps, which are as
follows:
Update and patch.
Protect the web browser.
Restrict access.
I also discussed how to anonymize the lab using common solutions such as the
following:
Proxy servers
Virtual private networks
Online anonymizers
Tor
I also stressed the importance of isolating the lab as a precaution just in case something
happens such as the mishandling of malware.
I then touched on setting up a virtualized static analysis lab using VMware Player and
VirtualBox.
Last but definitely not the least, I discussed the importance of backup and restoration in
case the lab fails. With a process like this in place, there will be minimal downtime in case
of failure.
Tools
In this chapter, I discussed and made use of the following tools:
Windows 7 USB/DVD Download
Tool http://images2.store.microsoft.com/prod/clustera/framework/w7udt/1.0/en-
us/Windows7-USB-DVD-tool.exe
Secunia Online Software
Inspector http://secunia.com/vulnerability_scanning/online/
Firefox add-ons and plug-ins
NoScript
Better Privacy
RequestPolicy
Web of Trust (WOT)
Adblock Plus
Proxy servers
Hide My Ass! http://hidemyass.com/proxy/
Proxy 4 Free http://www.proxy4free.com
Samair.RU http://www.samair.ru/proxy/
Public proxy
servers http://www.publicproxyservers.com/proxy/list1.html
Virtual private network services
Private Tunnel https://www.privatetunnel.com
VPNBook http://www.vpnbook.com
JustFreeVPN http://www.justfreevpn.com
VPN Account http://www.VPN Account.org
L2TP VPN Service http://www.freel2tpvpn.com
OkayFreedom VPN https://www.okayfreedom.com
VPN Access http://freevpnaccess.com
Hotspot Shield Ad Supported http://www.hotspotshield.com
CyberGhost http://cyberghostvpn.com
Free UK & US VPN http://www.ukusvpn.com
Free VPN for UK http://www.vpnforuk.com
Premium VPN with Public IP http://www.truvpn.com
Free ProXPN http://proxpn.com
Online anonymizers
Anonymouse http://anonymouse.org/anonwww.html
Free Web Proxy http://www.vpnbook.com/webproxy
Online Anonymizer http://online-anonymizer.com
Hide My Ass! Web Proxy http://hidemyass.com/proxy/
KProxy https://www.kproxy.com
Megaproxy http://www.megaproxy.com/freesurf/
Tor, the onion
router https://www.torproject.org/docs/documentation.html.en
VMware Player http://www.vmware.com/go/downloadplayer
VirtualBox https://www.virtualbox.org/wiki/Downloads
Clonezilla http://clonezilla.org/downloads.php
CHAPTER
8
Dynamic Analysis Lab
S etting up the static analysis lab gave you a good foundation that you can build on
when setting up a dynamic analysis lab. Dealing with Windows errors during
installation and anonymizing and isolating the lab are among the topics that will
help you to set up a dynamic analysis lab.
Using a static analysis lab offers you a glimpse of the nature of malware from the data
gathered with the malware at rest. Although the data might not be enough to come up with
any definite information to fully determine a malware’s behavior or directive, static
analysis is still a useful first step in the malware analysis process. The next step that builds
upon static analysis is dynamic analysis. With dynamic analysis, you are able to observe
malware in its natural environment. You are able to monitor the malware’s behavior while
it is running in an environment that mimics the system the malware is designed to target. It
is analogous to an organism being studied in a small, contained area that mimics its natural
habitat. The only difference is that it is a controlled and simulated environment. The
controlled environment where dynamic analysis is being conducted that is designed to
mimic a malware’s target environment is known as the dynamic analysis lab. This is
where malware behavior can be observed, monitored, and recorded.
In this chapter, I will discuss how to build an effective dynamic analysis lab by making
it as close to the desired environment as possible for malware to thrive. I will also discuss
how to make sure that the dynamic analysis lab is backed up and restored in case of failure
so there will be minimal downtime.
In this lab, you will be installing VMware Player in Ubuntu. For this purpose, you will be
using the 64-bit version of Ubuntu and VMware Player for Linux.
What You Need:
System running Ubuntu 14.04.01 LTS or later
VMware Player for Linux installer
Steps:
1. Register for a VMware account at https://my.vmware.com/web/vmware/login.
2. Download VMware Player for Linux at
http://www.vmware.com/go/downloadplayer. For the purpose of this lab, you will be
using VMware Player for Linux 64-bit. As of this writing, the latest version is 6.0.3.
3. Open a terminal window and change to the directory where VMware Player
was downloaded.
4. Install the required dependencies first.
5. Install VMware Player. Take note that the VMware Player version may vary.
Enter the filename you have downloaded and simply follow this pattern:
In this lab, you will be uninstalling VMware Player in Ubuntu. For this purpose, you will
be using the 64-bit version of Ubuntu and VMware Player for Linux.
What You Need:
System running Ubuntu 14.04.01 LTS or later
VMware Player for Linux installed
Steps:
1. Open a terminal window.
2. Execute the following command line to invoke the VMware Player window:
In this lab, you will be installing VirtualBox in Ubuntu. For this purpose, you will be
using the 64-bit version of Ubuntu and VirtualBox for Linux.
What You Need:
System running Ubuntu 14.04.01 LTS or later
VirtualBox for Linux installer
Steps:
1. Download VirtualBox Linux from
https://www.virtualbox.org/wiki/Linux_Downloads.
2. Choose the flavor that is for Ubuntu 14.04 and download the 64-bit version.
3. Open a terminal window and change to the directory where VirtualBox was
downloaded.
4. Install the VirtualBox dependencies.
Just to avoid confusion, take note of the L and the number 1 character in libsdl1,
that is, libsd(L)(1).
5. Install VirtualBox for Linux. Take note that the filename will vary depending
on the current version that is available.
6. After successful installation, execute VirtualBox. Figure 8-3 shows the main
page. You can do this by clicking the Ubuntu unity panel located at the top left and
typing VirtualBox.
Figure 8-3 VirtualBox main page.
LINGO
The Ubuntu unity-panel is also known as home, Big Freaking Button, BFB,
and simply panel.
In this lab, you will be uninstalling VirtualBox in Ubuntu. For this purpose, you will be
using the 64-bit version of Ubuntu and VirtualBox for Linux.
What You Need:
System running Ubuntu 14.04.01 LTS or later
VirtualBox for Linux installed
Steps:
1. Open a terminal window.
2. Execute the following command to uninstall VirtualBox for Linux:
If you forgot the name of the exact package, you can get a list of packages installed by
issuing the following command:
This will display the packages in alphabetical order. Simply look for virtualbox, and
you will know exactly what the package name is. In this specific lab, it is virtualbox-4.3.
TIP
You can save the output from a command line to a file just by typing >
filename at the end of the command line.
In this lab, you will configure Internet Explorer to be malware friendly. You will use
Internet Explorer 11 for the purpose of this lab.
What You Need:
System running Windows 7
Internet Explorer 11 installed
Steps:
1. Open Internet Explorer 11.
2. Click the cog icon in the upper-right corner of the Internet Explorer window.
This will show a drop-down menu.
NOTE
A cog icon usually symbolizes settings or options in a software menu.
3. Choose About Internet Explorer. Figure 8-6 shows the About Internet
Explorer window.
In this lab, you will configure Mozilla Firefox to be malware friendly. As of this writing,
the updated version of Firefox is 32.0.3. If there are changes in future versions regarding
the settings you will manipulate, there shouldn’t be any problems. The changes in
manipulating the settings are usually minimal, and the same principles will still apply.
What You Need:
System running Windows 7
Mozilla Firefox installed
Steps:
1. Open Mozilla Firefox.
2. Go to the upper-right corner and click the menu button represented by three
parallel horizontal lines.
NOTE
Three parallel horizontal lines usually represent menu buttons in graphic-
friendly user interface (UI) designs.
3. Click Options. Figure 8-10 shows the Mozilla Firefox Options window.
In this lab, you will configure Google Chrome to be malware friendly. As of this writing,
the version of Google Chrome is 37.0.2062.124. If there are changes in future versions
regarding the settings you will manipulate, there shouldn’t be any problems. The changes
in manipulating the settings are usually minimal, and the same principles will still apply.
What You Need:
System running Windows 7
Google Chrome installed
Steps:
1. Open Google Chrome.
2. Go to the upper-right corner and click the menu button represented by three
parallel horizontal lines.
3. Click Settings.
4. Another way to go to Settings is by typing the following in the address bar:
chrome://settings.
5. Click Show Advanced Settings at the bottom of the page.
6. Under Privacy, click the Content Settings button. A window pop-up will then
appear.
7. Navigate down the page and look for Pop-Ups. Toggle the radio button to
Allow All Sites To Show Pop-Ups.
8. Navigate further downward and look for Unsandboxed Plug-In Access.
Toggle the radio button to Allow All Sites To Use A Plug-In To Access Your
Computer.
9. Below Unsandboxed Plug-In Access is Automatic Downloads. Under
Automatic Downloads, toggle the radio button to Allow All Sites To Download
Multiple Files Automatically.
10. Click Done at the bottom of the pop-up window.
11. Close the Settings page.
Although you want Internet browsers to be malware friendly, there will be instances
when you want them to be secure as possible, especially if you are analyzing a malware
that has the ability to bypass Internet browser security and privacy features.
Install Commonly Exploited Software
Typically the most popular software is often the most abused because it gives the malware
the potential to have greater target coverage. Attackers spend hours finding vulnerabilities
in this type of software that they can exploit. Now, there are lots of software that falls into
this category, but for the purpose of brevity, I will concentrate on three often abused by
attackers, listed here:
Microsoft Office
Adobe Flash Player
Adobe Reader
Microsoft Office is included not only because of its macro capabilities but also because
it is widely used in homes, schools, and businesses. Although there is not that much macro
malware around, it is still good to have Office installed, especially if you are going to
create enticing Office files. Having enticing files in Microsoft Office format but no Office
installed might make attackers suspicious. A malware can always have a built-in
functionality to detect programs installed in a system. A malware may refuse to steal any
documents if the appropriate program for it does not exist in the system, especially if it is
targeting a user or non-server system. This is one precaution malware writers take to beat
honeypots with enticing files.
TIP
If you are going to use bait files for information stealers, make sure that the
appropriate program for those files are installed. For example, Excel worksheets
and Word documents must have Office Windows installed on the system.
Adobe Flash Player and Adobe Reader are also widely used and are free, making them
good targets for attackers to exploit. Adobe Reader’s ability to run JavaScript makes it a
good platform for attackers. Adobe Flash Player, on the other hand, is exploited through
malformed Flash files that the browser loads.
TIP
The safest places to download Adobe Reader and Adobe Flash Player from are
http://get.adobe.com/reader and http://get.adobe.com/flashplayer, respectively.
In this lab, you will configure Microsoft Office to be malware friendly. The version of
Microsoft Office being used is Microsoft Office 2010. Even if you have a different
version of Office installed, the same menu options and principles of making the software
malware friendly still apply. If there are changes in how a menu is presented, they will be
minimal.
What You Need:
System running Windows 7
Microsoft Office installed
Steps:
1. Open Microsoft Word.
2. Click the File tab under Help click Options. The Word Options window will
pop up, as shown in Figure 8-11.
LAB 8-13: Setting a Non-persistent Image in VirtualBox Using the Command Line
In this lab, you set up a non-persistent image in VirtualBox using the command line in
Windows.
What You Need:
System running Windows
VirtualBox installed
A working VirtualBox image
Steps:
1. Open a Windows command line.
2. Go to the VirtualBox folder. Its default location is C:\Program
Files\Oracle\VirtualBox.
3. Type and execute the following command line:
LAB 8-14: Creating a Non-persistent Bare-Metal System Using Deep Freeze Standard
In this lab, you see how to use Deep Freeze Standard to create a non-persistent bare-metal
system.
What You Need:
System running Windows
Deep Freeze Standard installed
Steps:
1. Download and install Deep Freeze Standard from
http://www.faronics.com/products/deep-freeze/standard/. A 30-day trial version is
available.
2. Once installed, launch Deep Freeze Standard by pressing the Shift key and
double-clicking the Deep Freeze Standard icon, represented by a polar bear, found in
the notification area of the Windows taskbar.
3. Enter the password to unlock Deep Freeze Standard. This is the password you
set during installation.
4. On the Status tab, choose Boot Frozen. This sets the bare-metal system to not
record any changes. After every bootup, the bare-metal system goes back to its clean
state.
TIP
Make sure you have done what needs to be done to the bare-metal dynamic
analysis system before freezing it. If you forget to do something or need to update
a setting or program, simply reboot to a clean state, set the status to Boot Thawed
or Boot Thawed On Next, and make the necessary changes to the bare-metal
system. Once done, set the status back to Boot Frozen.
5. Click OK.
6. You can also click Apply and Reboot for the changes to take effect and reboot
the machine.
Host OS
Aside from backing up the golden images of a virtualized dynamic analysis lab, it is also
important to back up the host OS. This ensures that if the host OS fails, there is no need to
restore it from scratch and reconfigure it again to support the virtualized dynamic analysis
lab. Sometimes the process of backing up the host OS is the most effective way to back up
the whole dynamic analysis infrastructure because the backup also contains the golden
images already. As a result, the system can resume its normal function after restoration,
and there is no need to restore the golden images from their separate backups. The only
thing that needs to be considered here is the space that will be taken up by backing up the
host OS with the golden images.
In this lab, you will be creating a Clonezilla Live in a USB flash drive that can be used to
boot up a machine with no disc drive.
What You Need:
USB flash drive with at least 8GB of space
System running Windows
Internet connection
Steps:
1. Format the USB flash drive and choose FAT as the file system. Windows will
format it as FAT32, which is the default.
2. Download Tuxboot from http://sourceforge.net/projects/tuxboot/files/. As of
this writing, the latest version is Tuxboot 0.6.
3. Execute Tuxboot. Make sure the machine is connected to the Internet.
Tuxboot will need to download the latest Clonezilla Live files during this process.
4. Fill in the following options, as shown in Figure 8-12:
Figure 8-12 Tuxboot preferred options.
A. On-Line Distribution: clonezilla_live_stable | 2.2.4-12-i486 (latest as of
this writing)
B. Type: USB Drive
C. Drive: The drive letter of the USB flash drive
TIP
Clicking Update in On-Line Distribution updates the version of Clonezilla Live
to the latest one that supports the Windows version where Tuxboot is running.
5. Click OK. Tuxboot will then proceed with the following steps, as shown in
Figure 8-13:
Figure 8-13 Tuxboot process.
A. Downloading Files The current version of Clonezilla Live is being
downloaded by Tuxboot.
B. Extracting and Copying Files Downloaded files will be loaded to the
USB flash drive.
C. Installing Bootloader This enables the USB flash drive to become
bootable.
D. Installation Complete, Reboot Everything is set, and the USB is ready
to be used.
6. Click the Reboot Now button to reboot the system.
7. As displayed in the Tuxboot window, after rebooting, select the USB boot
option in the BIOS boot menu.
8. You now have a bootable Clonezilla Live USB installation.
In this lab, you will use Clonezilla Live to back up a hard disk partition.
What You Need:
Clonezilla Live bootable USB flash drive
System running in Windows
Steps:
1. Make sure the system is shut down and powered off.
2. Insert the bootable Clonezilla Live USB flash drive.
3. Power on the system, go to the BIOS setup, and boot using the USB flash
drive. Different systems have different ways of doing this. Please consult your
system’s manual.
4. After successful reboot using the USB flash drive, the Clonezilla Live splash
page is displayed.
5. Click Enter to activate Clonezilla Live. This is the default highlighted option
in the Clonezilla Live menu. The system will then initialize.
6. Choose your language. English is the default.
7. Choose a policy for handling keymaps. Don’t Touch Keymap is the default.
There’s no need to change this. Just press Enter.
8. Click Enter again to start Clonezilla.
9. Choose the default setting, which is Device-Image Work With Disks Or
Partitions Using Images.
10. The next window will ask where the Clonezilla image will be saved to or
read from. For this purpose, you will use the Local_dev option. If you want to use
an external hard drive or USB flash drive to save to and read the image from, you
can insert it now.
11. Choose the partition where you want to save the image.
12. Choose the directory where you want the image to be saved.
13. Choose the desired wizard mode. For this purpose, I will be using Beginner.
Feel free to use Expert and experiment further.
14. The next window asks whether to save the whole disk or parts of the disk.
Since you are saving only a partition, choose Saveparts.
15. Input the name for the saved image and press Enter.
16. Choose the source partition, press the spacebar to mark the selection, and
click Enter. This is the partition you will back up.
17. Choose whether to check and repair the file system before saving it. If you
have time, you can do this, but if you are in a hurry, simply choose Skip. I strongly
suggest doing some checking when creating a backup of your system.
18. Follow the prompts to start the backup process. Backup might take a long
time, especially if the save location is an external hard drive. A 50GB partition
might take at least 30 minutes to back up.
19. After backup is done, you can choose Poweroff mode to shut down the
system.
20. Turn on the system again and browse to the location of the saved image to
verify it is there. Take note that the saved image is not a single file but rather a
collection of different files. The name you assigned during the backup process is the
name of the folder where these files are located.
In this lab, you will use Clonezilla Live to restore a hard disk partition from an image
backup.
What You Need:
Clonezilla Live bootable USB flash drive
System running in Windows
Saved Clonezilla Live image file
Steps:
1. Make sure the system is shut down and powered off.
2. Insert the bootable Clonezilla Live USB flash drive.
3. If applicable, insert the external hard drive or USB flash drive where the
Clonezilla Live image is saved. This step can be skipped because Clonezilla Live
will let you insert any external media later in the process.
4. Power on the system, go to the BIOS setup, and boot up using the USB flash
drive. Different systems have different ways of doing this. Please consult your
system’s manual.
5. After successful reboot using the USB flash drive, the Clonezilla Live splash
page is displayed.
6. Click Enter to activate Clonezilla Live. This is the default highlighted option
in the Clonezilla Live menu. The system will then initialize.
7. Choose your language. English is the default.
8. Choose a policy for handling keymaps. Don’t Touch Keymap is the default.
There’s no need to change this. Just press Enter.
9. Click Enter again to start Clonezilla.
10. Choose the default setting, which is Device-Image Work With Disks Or
Partitions Using Images.
11. The next window will ask where the Clonezilla image will be saved to or
read from. For this purpose, you will use the Local_dev option. If you want to use
an external hard drive or USB flash drive to save to and read image from, you can
insert it now.
12. Choose the partition where the saved image is located.
13. Go to the folder where the saved image is located.
14. Choose the desired wizard mode. For this purpose, I will be using Beginner.
Feel free to use Expert and experiment further.
15. The next window is asking what Clonezilla Live functionality is needed.
Since you are restoring an image to a local partition, choose Restoreparts and click
Enter.
16. Clonezilla Live will ask which image file to restore. Choose the appropriate
one and click Enter.
17. Choose the target partition to be overwritten by the image backup and click
Enter.
18. Follow the prompts to initiate the restoration process. The restoration
process may take some time depending on the system’s I/O speed. A restoration of
50GB partition can be at least 20 minutes.
19. After restoration is done, you can choose Poweroff mode to shut down the
system.
20. Remove the Clonezilla Live bootable flash drive and any external hard
drives connected to the system.
21. Reboot the system and check whether the restoration is successful.
Recap
In this chapter, I discussed how to set up a dynamic analysis lab. I identified the basic
steps, which are as follows:
1. Choose the hardware.
2. Install the operating system.
3. Make the lab malware friendly.
4. Anonymize the lab.
5. Isolate the lab.
I also discussed the importance of restoration time when it comes to dynamic analysis
labs. I explored the different methods and tools that you can use to restore a virtualized
dynamic analysis lab and a bare-metal dynamic analysis lab to a clean state.
I stressed the importance of backing up what you have built so if ever a failure or an
internal lab malware outbreak occurs, you can restore quickly with minimal downtime. I
identified the important things that need to be backed up. They are as follows:
The golden image
Host OS
Other systems supporting the lab
In this chapter, the most important thing is making the dynamic analysis lab malware
friendly. It is the key to success that will enable your dynamic analysis lab to successfully
execute a malware so monitoring and recording of its behavior is possible.
Tools
Virtualization software
VMware Player http://www.vmware.com/go/downloadplayer
VirtualBox https://www.virtualbox.org/wiki/Downloads
VirtualPC http://www.microsoft.com/en-US/download/details.aspx?
id=3702
Trusted Adobe download sites
Adobe Reader http://get.adobe.com/reader
Adobe Flash Player http://get.adobe.com/flashplayer
Deep Freeze Standard by Faronics http://www.faronics.com/products/deep-
freeze/standard/
Clonezilla http://clonezilla.org/download.php
Tuxboot http://sourceforge.net/projects/tuxboot/files/
1 Microsoft Technet: http://technet.microsoft.com/en-US/.
PART
III
Malware Inspection
CHAPTER
9
The Portable Executable File
M alware inspection is where the excitement begins. This is the process where you
actually dissect the malware sample and find out what it is capable of doing. But
as with any inspection or analysis exercise, a process has to be followed to get
the most out of the activity. And in a malware inspection activity (more popularly known
as a malware analysis activity), there are steps that needed to be followed to effectively
analyze malware.
Going back to the malware analysis process discussed in Chapter 1, the malware goes
through multiple steps of analysis to get to the bottom of its malicious directive, as shown
in Figure 9-1.
In this lab, you will use Dependency Walker to identify the DLL dependencies of PE files.
What You Need:
System running Windows 7
Dependency Walker
Steps:
1. Download Dependency Walker from http://www.dependencywalker.com.
2. Extract Dependency Walker from the downloaded ZIP file.
3. Execute depends.exe.
4. Choose File | Open and choose depends.exe.
5. The window, as shown in Figure 9-2, shows that depends.exe uses nine DLL
files. If any of these files are corrupted or missing, Dependency Walker will not
work.
6. To export this information to a text file, choose File | Save As.
7. In the next window, choose Text With Import/Export Lists (*.txt) in Save As
Type and click Save.
Figure 9-2 Dependency Walker dependencies.
DOS MZ Header
All PE files start with the DOS MZ header. It is located at offset 0 of a PE file. It was put
there just in case the program is executed in a system running Disk Operating System
(DOS). When the PE format was still being developed, most systems were still running
DOS. So, the developers recognized that there was a possibility that an executable
designed to run in the new Windows environment would be executed in a DOS
environment. The DOS MZ header was placed there to enable a DOS operating system to
recognize the PE file as a valid executable file so it can execute the DOS stub, which is
discussed in the next section.
Figure 9-4 shows an example of a DOS MZ header. The hex values 4Dh and 5Ah
represent MZ, which is the initial of Mark Zbikowski, who is the one of the original
architects of the Microsoft Disk Operating System (MS-DOS).
Figure 9-4 DOS MZ Header of Calc.EXE.
DOS Stub
The DOS stub is a valid DOS executable file. As discussed in the previous section, the
DOS MZ header enables DOS to recognize the PE file as a valid executable in DOS so the
DOS stub can be executed. The main purpose of executing the DOS stub is to tell the user,
in case the program was executed under DOS, that the program is for Windows. The stub
simply displays a message that the program cannot be run in DOS mode. You can easily
see the string in the DOS stub, as shown in Figure 9-5.
PE Header
The PE file header, or simply PE header, is where the fun begins. This structure contains
the important fields that the PE loader needs. As discussed previously and as shown in
Figure 9-3, the PE header is not located at the start of the file. That location is occupied by
the DOS MZ header and DOS stub. The location of the PE header can be found in offset
0x3C relative to the start of the file. The 4-byte value starting at address 0x3C represents
the address of the PE header relative to the start of the file. So, looking at Figure 9-4,
which shows the DOS MZ header of Calc.EXE, you can determine that the address of the
PE header is at 0xF0 because the 4 bytes starting from 0x3C are F0h 00h 00h 00h. Take
note that x86 processors use little-endian architecture, so data is actually read from right
to left. This means that the least significant byte is stored in the smallest address. In the
previous example, the least significant byte is F0h, located in address 0x3C. The next
significant byte is 00h, 00h, and 00h, located respectively in 0x3D, 0x3E, and 0x3F. So
when you write it, the order of the bytes is 00h 00h 00h F0h. 0x3C, being the smallest
address, contains the lowest significant byte, which is F0h.
If the 4 bytes seen at the starting address 0x3c are 04h, 03h, 02h, 01h, then the highest
significant byte is 01h, and the least significant byte is 04h. It will be written as 01h 02h
03h 04h.
Figure 9-6 shows the start of the PE header at location 0xF0.
Figure 9-6 PE header of Calc.EXE.
The start of the PE header is PE\0\0 or the hex values 50h 45h 00h 00h. This is called
the PE signature and, as stated previously, indicates the start of the PE header.
When a PE file is executed, the PE loader goes directly to the PE header. The PE loader
bypasses the DOS MZ header and DOS stub and proceeds directly to the PE header. As
previously discussed, the location of the start of the PE header is found in offset 0x3C of
the file. The PE loader reads the address in this offset and goes to that address, which is
the start of the PE header.
The PE header contains lots of essential fields utilized by the PE loader. It is actually a
general term for the related structure of type IMAGE_NT_HEADERS. The structure is
laid out as shown in Figure 9-7.
In this lab, you will install the pefile module to a system running Ubuntu.
What You Need:
System running Ubuntu 14.04.1
Python 2.7.6
pefile
Steps:
1. Check whether Python is installed by typing python in the command line.
2. If Python is installed, the python command will result in opening the Python
command-line environment. If this is the case, simply type exit() to exit the
environment.
In this lab, you will write a Python script that will display three things about a PE file.
Address of entry point
Image base
Number of sections
What You Need:
System running Ubuntu 14.04.1
Python 2.7.6
pefile
calc.EXE from Windows 7
Steps:
1. Create a Python script file.
2. Write the following code:
3. After creating the Python script, change it to executable mode by issuing the
following command:
4. Execute your script. Make sure that calc.EXE is in the same folder as your
script.
Section Table
As shown in Figure 9-3, the section table is located between the PE header and the PE
file’s sections. The section table contains information about the sections immediately
following it in the PE structure. Think of a section table like a phone book. Each entry in
the phone book contains information about a person. The more people who are listed, the
thicker the phone book is. The number of entries in the section table depends on the
number of sections contained in the image file. But unlike a phone book that contains
hundreds of thousands of entries, a section table usually has only five. The number of
entries (or sections, for that matter) is defined in the NumberOfSections field in the PE
header.
The section table is also referred to as the IMAGE_SECTION_HEADER. Table 9-4
contains the fields of this structure. Take note that the offset is relative to the start of each
entry.
Table 9-4 IMAGE_SECTION_HEADER Entries
It is important to note that the section names have only eight characters reserved for
them. If an image has more than eight characters for a section name, the name field will
contain a forward slash (/) followed by an ASCII representation of a decimal number that
is an offset into the string table. An image that has more than eight characters for a section
name is anything but an executable file. Executable files only support section names up to
eight characters, and they do not use a string table.
The last field in the section table defines the image characteristics. It is aptly called the
Characteristics field. Table 9-5 describes the flag values of this field.
Table 9-5 Characteristics Field Values Defined
NOTE
In the section table, the sections are sorted according to their relative virtual
address rather than alphabetically.
Another useful tool that can be used to dump PE information is pedump. It is a Ruby
implementation that can be used in Linux-based systems such as Ubuntu. It supports both
32- and 64-bit PE files. It also supports old file formats such as DOS and Windows NE
(New Executable) file format, which is the file format of Windows versions before
Windows 95. You can find more information about pedump at https://github.com/zed-
0xff/pedump.
pedump can dump the following information:
MZ/NE/PE header
DOS stub
“Rich” header
Data directory
Sections
Resources
Strings
Imports and exports
VS_VERSIONINFO parsing
PE packer/compiler detection
pedump also offers an online service where users can upload PE files for analysis. The
website is located at http://pedump.me.
In this lab, you will install pedump and use it to dump information of a PE file.
What You Need:
System running Ubuntu 14.04.1
Ruby
pedump
calc.EXE from Windows 7
Steps:
1. Install Ruby. As of this writing, the recommended version is 2.1.3.
A. Install Ruby dependencies.
B. Install Ruby.
2. Install pedump.
3. Go to the folder where calc.EXE is located and issue the following command
line:
In this lab, you will write a Python script that will display the section information of a PE
file.
What You Need:
System running Ubuntu 14.04.1
Python 2.7.6
pefile
calc.EXE from Windows 7
Steps:
1. Create a Python script file.
2. Write the following code:
3. After creating the Python script, change it to executable mode by issuing the
following command:
4. Execute your script. Make sure that calc.EXE is in the same folder as your
script.
To convert the RVA to the actual address, which is the target address, simply reverse the
process by adding the load address to the RVA.
NOTE
The virtual address is simply an RVA with the HMODULE added in.
HMODULE is the same as the load address.
PE Import Functions
Previously, I discussed that the .idata section contains function and data information that
the program imports from other dynamic link libraries. The .idata section is also referred
to as the import table of the executable image. This table contains all the information that
the PE loader needs to determine the addresses of the functions that the executable image
is importing so it can be patched into the executable image. These functions are called
import functions because they are the ones being “imported” by the executable. Therefore,
import functions are functions that do not reside in the caller’s module or program but are
called by the caller from another module or program such as a DLL. The caller module
only contains information about the functions it is calling from another module, which can
be one or more DLLs. The information includes the function names and the names of the
dynamic link libraries from which they are imported. This information can be found in the
import table.
NOTE
Import functions reside in DLLs.
The import table starts with an array of IMAGE_IMPORT_DESCRIPTORs. Each DLL
that the executable image or the PE executable file links to will have its own
IMAGE_IMPORT_DESCRIPTOR. If the PE file imports from five DLLs, it will have
five IMAGE_IMPORT_DESCRIPTORs in its .idata section. Take note that there is no
field indicating how many IMAGE_IMPORT_DESCRIPTORs are in an executable
image’s .idata section. The only way to determine this is to count the number of
IMAGE_IMPORT_DESCRIPTORs there are and stopping count only when an
IMAGE_IMPORT_DESCRIPTOR with null field values is encountered. This signals the
last element of the IMAGE_IMPORT_DESCRIPTOR array. Table 9-6 shows the
IMAGE_IMPORT_DESCRIPTOR structure.
Table 9-6 IMAGE_IMPORT_DESCRIPTOR Structure
IMAGE_THUNK_DATA is a union of DWORD size containing the RVA or pointer to
an IMAGE_IMPORT_BY_NAME structure and not the structure itself. The
IMAGE_IMPORT_BY_NAME structure, on the other hand, contains information about
an import function. Table 9-7 shows the IMAGE_IMPORT_ BY_NAME structure.
3. After creating the Python script, change it to executable mode by issuing the
following command:
4. Execute your script. Make sure that calc.EXE is in the same folder as your
script.
PE Export Functions
Functions that are imported by an image usually come from a DLL file. As far as the
image is concerned, it is importing the functions, but as far as the DLL is concerned, it is
exporting the function. In short, when an image, usually a dynamic link library file, makes
functions and data available for other PE files, it is effectively exporting code or data. And
the code and data that is being exported is known as an export function.
The .edata section contains information about functions being exported by a PE file.
The .edata section is also known as the export table. An export table usually contains the
following:
Tables of function names
Entry point addresses
Export ordinal values
An export table or .edata section starts with an IMAGE_EXPORT_DIRECTORY
structure and then is followed by the data pointed to by the fields in this structure. Table 9-
8 shows the IMAGE_EXPORT_DIRECTORY structure.
Table 9-8 IMAGE_EXPORT_DIRECTORY Structure
In this lab, you will write a Python script that will display the export information of a PE
file.
What You Need:
System running Ubuntu 14.04.1
Python 2.7.6
pefile
comctl32.DLL from Windows 7 or any DLL file you have
Steps:
1. Create a Python script file.
2. Write the following code:
3. After creating the Python script, change it to executable mode by issuing the
following command:
4. Execute your script. Make sure that comctl32.DLL is in the same folder as
your script.
5. Take note that running this script with a PE file with no exports will display
the following message:
When it comes to exporting functions, there is one feature that PE files can do, which is
export forwarding. Export forwarding is a feature of export functions that has the ability to
forward and export to another DLL. Let’s look at an example published by Microsoft
regarding export forwarding.
In Windows NT, Windows 2000, and Windows XP, the KERNEL32 HeapAlloc
function is forwarded to the RtlAllocHeap function exported by NTDLL. Forwarding is
performed at link time by a special syntax in the EXPORTS section of the .DEF file.
Using HeapAlloc as an example, KERNEL32’s DEF file would contain the following:
How can you tell whether a function is forwarded rather than exposed normally? It is
somewhat tricky. Normally, the EAT contains the RVA of the exported symbol. However,
if the function’s RVA is inside the exports section, as given by the VirtualAddress and Size
fields in the DataDirectory, the symbol is forwarded.
When a symbol is forwarded, its RVA obviously can’t be a code or data address in the
current module. Instead, the RVA points to an ASCII string of the DLL and symbol name
to which it is forwarded.
In this lab, you will write a Python script that will display all available information of a
PE file.
What You Need:
System running Ubuntu 14.04.1
Python 2.7.6
pefile
calc.EXE from Windows 7
Steps:
1. Create a Python script file.
2. Write the following code:
3. After creating the Python script, change it to executable mode by issuing the
following command:
4. Execute your script. Make sure that calc.EXE is in the same folder as your
script.
Recap
In this chapter, I discussed what the PE file format is, how it is structured, and what tools
you can use to decipher it. You took a look at the different components of the PE file
format, listed here:
DOS MZ header
DOS stub
PE header
Section table
Sections
I described each component and how it is structured. I described the different fields and
the common entry values each has within each structure. Aside from all of this, you also
tackled what a relative virtual address is and how the PE file imports and exports
functions.
Tools
Dependency Walker http://www.dependencywalker.com
pefile https://code.google.com/p/pefile/
pedump https://github.com/zed-0xff/pedump
pedump online PE file submission http://pedump.me/
CHAPTER
10
The Proper Way to Handle Files
U nderstanding the Portable Executable (PE) file is a must, as you saw in the
previous chapter. You were able to discover the different characteristics of the PE
file and what makes it tick. With this newfound basic knowledge of PE files, you
are now better equipped to understand Windows malware.
When it comes to malware inspection, you always start with an unknown file. You have
no idea, at first, whether the file is malicious. Therefore, it is important to handle the file
with great care to avoid any unwanted incidents that might lead to a malware outbreak.
In this chapter, I will discuss how to properly handle unknown files. You will look at
the file’s analysis life cycle, from transport to storage, and how to handle files in the right
way to prevent anything from unauthorized access to compromise of the files. I will also
discuss how to properly store files that are found to be malicious or verified to be
malware.
Transfer
Files that need to be analyzed will usually come from an external source. If this is the
case, you need to practice great care when moving the file from the source to the analysis
machines. You have to consider the following:
The file must not be in an executable state.
The file must not be accessible to unauthorized users.
The source of the file must be verifiable.
Non-executable State
When a file is transferred, it is important that it is not in an executable state. For Windows
executable files, it is easy to make an executable file not in an executable state or, in short,
non-executable. You can simply rename the file’s extension. For example, you can rename
an .EXE file as .EX_, .EX1, or .EXE.XXX. The main idea here is that you change the
original extension to a non-executable extension but won’t forget what the original
extension was.
In this lab, you will install and use p7zip to compress files and decompress an archive file.
P7zip is the equivalent of 7zip in Linux systems.
What You Need:
System running Ubuntu 14.04.1
Steps:
1. Install p7zip in Ubuntu.
2. After successful installation, the system can now support 7zip files or files
with the .7Z extension.
3. To compress a file, right-click it and click Compress on the context menu. In
this example, I will be using calc.EXE, but please feel free to use any file available.
4. Once the Compress window opens, set the filename extension to .7z and
rename the archive file as you want. The default name of the archive file is usually
the original filename of the file being compressed. In this example, I will rename the
archive to calc-compress.
5. Set the location where you want to save the archive file. The default location
is the current directory where the file being compressed is.
6. Click Other Options to set the password. In this section, you will also have the
option to encrypt the filenames of the compressed files and to split the archive into
volumes.
7. Once the password is set and options chosen, such as encrypting the file list,
click Create to create the archive file. Figure 10-1 shows the Compress window with
the options chosen.
Figure 10-1 Compress window.
8. To decompress an archive file, right-click it and choose Extract Here. In this
example, you will be decompressing calc-compress.7z. This is the archive you just
created.
9. A dialog box asking for a password, as shown in Figure 10-2, will be
displayed. Input the password and click OK to extract the file.
The best way to really protect files from unauthorized access is to use public-key
cryptography. Public-key cryptography, also known as asymmetric cryptography, requires
two unique and separate keys: the private and the public key. Although unique, the two
cryptographic keys are related mathematically. As its name suggests, the public key is
available publicly. Anyone can have access to it. The private key, on the other hand, is
secret and confidential. Only the owner must have access to it.
To keep the file confidential or free from unauthorized access, the public key is used to
encrypt the file, and then the private key, which is in the possession of the owner, is the
only key that can decrypt it. This ensures that the file can be accessed only by the person
or entity the file is intended for.
TIP
It is always good practice to still compress the file to be analyzed and protect it
with a password before encrypting it with a public key.
In Ubuntu, the most common tool used for creating and managing key pairs is GnuPG
or gpg. It uses OpenPGP as its encryption standard. OpenPGP, as stated in
http://www.openpgp.org, is a non-proprietary encryption protocol using public key
cryptography. It is based on PGP as originally developed by Phil Zimmermann. The
OpenPGP protocol defines standard formats for encrypted messages, signatures, and
certificates for exchanging public keys.
4. A screen with selections as listed here will appear. The latest version that
came with Ubuntu 14.04.1 as of this writing is 1.4.16.
5. Select (1), which is the default, by typing 1 and pressing Enter. This enables
encryption and signing.
6. The program will then ask what keysize you want. The default is 2048. To
choose this, simply press Enter.
7. The next step is to set how long the key should be valid. For this experiment,
you will set the key to not expire. This is the default. Simply press Enter to choose
this option.
TIP
If you choose a key that does not expire, make sure to revoke the key when you
no longer need it.
8. Confirm your selection by typing y when asked whether the option chosen is
correct.
9. You will then need to input your real name, a comment, and an e-mail
address, as shown in Figure 10-3.
13. Perform the actions as instructed. The best way to do this is to do as much
activity as you can in your system. Once gpg is satisfied, it will display the screen
shown in Figure 10-4.
In this lab, you will be setting the key you just created as the default in your .bashrc to
allow applications using GPG to automatically use your key.
What You Need:
System running Ubuntu 14.04.1
Generated keys
Steps:
1. Open a terminal window in Ubuntu and enter the following command:
2. Once the .bashrc file is open, add the following line at the end of the file:
In this lab, you will upload your public key to Ubuntu Keyserver so it is available to
anyone who needs it to communicate securely with you.
What You Need:
System running Ubuntu
Generated keys
Steps:
1. Determine your public key by displaying your key information. To do this,
open a terminal window and enter the following command. In this example, the
GPGKEY is BB7BCC97.
2. Export the key to http://keyserver.ubuntu.com/ by issuing the following
command:
In this lab, you will be backing up and restoring both your private and public keys.
What You Need:
System running Ubuntu 14.04.1
Generated keys
Steps:
1. Determine your public key by displaying your key information. To do this,
open a terminal window and enter the following command. In this example, the
GPGKEY is BB7BCC97.
9. If the displayed key information matches the one you are restoring, then
restoration is successful.
There will be instances wherein you will not need your keys anymore, probably
because it was compromised or you simply want to replace them with a new key pair. In
cases like this, the only way to make sure that the key is no longer valid and to tell other
users that the key is no longer in use or reliable is to revoke the keys.
The only way to revoke a key pair is with a revocation key; without a revocation key, a
key pair cannot be revoked. This is a safety precaution so no unauthorized user can revoke
a key easily. It is important to treat the revocation key as you would your private key.
Keep it safe and secure.
In this lab, you will create a revocation certificate that you can use to revoke your existing
key pair.
What You Need:
System running Ubuntu 14.04.1
Generated keys
Steps:
1. Create a revocation certificate. In this example, you will be revoking
GPGKEY BB7BCC97.
2. gpg will ask whether you really want to create a revocation certificate for your
key. Enter y and press Enter to proceed.
3. It will then ask the reason for the revocation. Select the appropriate reason or
simply enter 0 for no reason specified and press Enter.
4. After deciding which reason is appropriate, gpg will ask you for an optional
description. You can skip this by simply pressing Enter.
5. Once you have made your choice, it will display the reason and description as
a summary and ask whether it is OK. If everything is good, enter y and press Enter
to proceed.
6. A dialog box will pop up asking for a passphrase to unlock the secret key, as
shown in Figure 10-6.
12. If revocation was successful, you should see a label saying the key is
revoked, as shown here. In this example, the key was created on November 21,
2014, and was revoked on December 5, 2014.
13. To make sure that other users are notified that the key has been revoked, you
must upload the revocation certificate to a keyserver. In this example, you used
Ubuntu Keyserver.
14. When users update their key database, they will see that your key has been
revoked.
Revoking a key is not the end of the key pair. There are instances where you realize
that your key pair has not been compromised or probably you have revoked it by mistake.
If this is a case, there is hope. A revoked key pair can still be unrevoked. Take note that
this works only as long as you did not send the revocation certificate to a key server.
2. Once the revoked key has been exported to mykey.gpg, you need to split it
into multiple parts.
3. Listing the contents of the folder where the terminal is active will reveal files
with names starting with 0000. These are the multiple parts of BB7BCC97.
8. Once you have deleted the revocation key, you can combine the remaining
parts minus the 000002-002.sig. This can be done by issuing the following
command:
9. Next, you have to delete the revoked BB7BCC97. To do this, issue the
following command:
12. If the displayed key does not have the revoked label, then the restoration has
been successful.
gpg gives the user the ability to edit a generated key pair. Usually when it comes to
editing key pairs, the most common information that is edited is the expiration date.
Sometimes a user wants to make the keys valid until the end of time or simply just wants
the keys to be valid until a certain date. The edit function of gpg gives the user the
capability to change the expiration date of a key pair.
In this lab, you will be changing the expiration date of your key pair.
What You Need:
System running Ubuntu 14.04.1
Generated keys
Steps:
1. Find the GPGKEY or key ID of the key you want to edit by issuing the
following command:
3. This will bring you inside the gpg shell. Inside the shell, you can use the list
command to list your keys.
4. If you want to work with a subkey, simply invoke the key command followed
by the index of the subkey you want to work on. In this example, you will be
working on the primary key. The primary key is the default, so there’s no need to do
anything, but in case you are working with multiple subkeys, issuing the command
key 0 sets you up with the primary key.
8. You will then need to enter your password to unlock the secret key and make
the changes to the expiration date active.
9. After successfully changing the expiration date, a summary of the key will be
displayed, but this time the expiration is set to never.
10. Exit the gpg shell by entering quit and pressing Enter. The system will ask
you whether you want to save changes. Enter y and press Enter to confirm the
changes and exit the gpg shell.
In this lab, you will use gpg to encrypt and decrypt a file.
What You Need:
System running Ubuntu 14.04.1
Steps:
1. Open a terminal window.
2. Choose a file you want to encrypt. In this example, you will be using calc.
EXE.
3. Encrypt the file by issuing the following command:
The best way to lock out unauthorized users from accessing a file being transported is
to encrypt it using the public key of the intended recipient.
LAB 10-10: Encrypting a File with the Public Key of the Intended Recipient
The purpose of encrypting using a public key of the intended recipient is to make sure that
the intended recipient is the only one who can decrypt the file by using the recipient’s
private key. In this lab, you will be encrypting a file using the public key of the intended
recipient.
What You Need:
System running Ubuntu 14.04.1
Intended recipient’s public key
Steps:
1. Alice (alice@alicesemail.fake) wants to send Bob (bob@bobsemail.fake) an
encrypted file. In this example, I will use calc.EXE. Alice uses Bob’s public key to
encrypt calc.EXE.
2. In the previous command line, Alice used Bob’s public key associated with
his e-mail. This means that Bob is the only one who can decrypt the file using his
private key. If Alice wants to decrypt the file, she needs to add her public key.
3. If Alice wants to add more recipient, she can simply follow the same format
as shown previously.
4. Once Bob gets the encrypted file, he can decrypt the file using his private key
by issuing the following command:
5. Bob will be asked a password to unlock his key. Once the correct password is
supplied, the file will be decrypted.
NOTE
As an added level of security, the file is actually compressed in addition to
encrypted.
TIP
If you want to send multiple files, it is best to compress and password protect
all the files first using a file compressor such as p7zip and then use GPG to
encrypt the resulting archive file using the intended recipient’s public key.
Verifiable Source
Another thing to be considered when it comes to transferring a file for analysis is to make
sure that it came from the source it was supposed to come from. The receiver must be able
to verify the source of the file. When the file came from e-mail, it was easy to verify
where it came from. But you know that e-mail (or anything else that can be used to
transport or publish a file for download) can be compromised. So if you are paranoid and
want to make sure that the file did came from the person it is supposed to, private key
signing is the answer.
LINGO
Private key signing means encrypting something using a private key. It can be
decrypted using the public key of the signer.
In the previous section, I discussed what private and public keys are and how the public
key is used to encrypt the file so that only the private key of the recipient can be used to
decrypt the file. In this section, it is more about verifying the source. So, the process is
reversed. The sender or source signs or encrypts the file using his private key, and it can
be decrypted only using the signer’s public key. Private key signing ensures that the file
came from the real source it is supposed to come from. This ensures the integrity of the
file.
Since the file can be decrypted by the signer’s public key, this means anybody who has
access to the public key can have access to the file. This is the reason why the process of
signing is done on top of encrypting the file using the public key of the receiver. Anybody,
including the intended receiver, can verify the source of the file, but only the receiver,
using his private key, can decrypt the file after verifying the source. This combination of
private key signing and public key encryption ensures file integrity and confidentiality.
LAB 10-11: Signing a File
In this lab, you will be signing a file using your private key so the intended recipient can
verify that the file indeed came from a trusted source, which is you.
What You Need:
System running Ubuntu 14.04.1
Generated keys
Steps:
1. Open a terminal window and enter the following command. In this example,
you will be signing calc.EXE.
2. The system will ask for a passphrase to unlock your secret key. After
supplying the password, the file will be signed.
NOTE
For added security, the file for signing is compressed and then signed.
3. The signed file is calc.exe.sig.
4. To verify the signature, enter the following command:
7. During the decryption, gpg will display the key of the signer similar to what
was displayed when the private key of the sender was verified.
NOTE
The way unknown files are transferred is the same as how known malware files
are transferred. As previously mentioned, unknown files must be treated like they
are malware. It is better to be safe than sorry.
Now you have an idea of how to do the following:
Compress and password protect a file
Encrypt using a public key of the intended recipient
Sign using your private key so the source can be verified
It is a good idea to combine these three before transferring or transporting a file.
Analysis
After an unknown file has been transferred from the verified source, the next step is to
analyze it. The analysis can be done manually or through an automated system. As I
discussed in previous chapters, static analysis requires the file to be static, or at rest. This
means you do not need to execute the file to get the information you need when
conducting static malware inspection. Since this is the requirement, you do not need to do
anything with the file after it is decrypted and decompressed. There is no need to revert
the file into an executable state. The only time a file is needed to be in an executable state
is during dynamic analysis, which I will discuss in future chapters.
Therefore, when it comes to handling a file during analysis, it stays in its non-
executable state. This is the same state the file was in when being transferred from source
to destination. The only action needed is to decrypt and decompress it. Any form of
analysis, except for dynamic analysis, must always handle the file in a non-executable
state.
Storage
Analysis answers the question, “Is the file malicious?” Some research organizations
discard the files that are benign and keep only those that are deemed malicious. In this
section, I will concentrate more on storing files that are deemed malicious or verified to be
malware, including the metadata of the files.
NOTE
Some research organizations keep the files found to be benign for whitelisting
purposes.
Storing files deemed malicious follows almost the same concept as when a file is being
transferred. This means that when a file is stored, it must be in a non-executable state and
must be inaccessible to unauthorized users.
To effectively store malicious or malware files, it must in line with the following
principles:
Confidentiality
Integrity
Availability
This is also known as the CIA model or triad. CIA is an acronym for confidentiality,
integrity, and availability. This is a set of guidelines and policies that help an organization
in protecting data and information. Confidentiality restricts or limits the access to data and
information to those who are authorized. Integrity ensures that the data and information
have not been modified or altered in any way, therefore maintaining its trustworthiness
and accuracy. Availability ensures that the data and information are accessible to
authorized users when needed without delay.
In your case, you are protecting malware files. Some may comment that this is going
overboard, but when it comes to malware, in my humble opinion, there is no going
overboard, especially if it has something to do with preventing any sample leaks. You do
not want these files or information about these files to fall into the wrong hands
(especially the files because they either can be used in their original form or can be
modified to be much more resilient in an attack campaign). Also, you do not want any
inadvertent execution of malware files that may cause a malware outbreak.
NOTE
“Wrong hands” includes not only the bad guys but also good guys who do not
know how to properly handle malware.
Confidentiality
You need to make sure that neither malware samples nor information about these samples
reaches any unauthorized entities. This is considered sensitive data and information, so
preventing unauthorized access is of paramount importance. I touched on this already in
the previous section by using password-protected compressed files and public key
cryptography. In most cases, and as widely practiced, the state of malware when it is
transferred is the same as how it is stored, which means it undergoes compression and
encryption. When a file for analysis is received and then proven to be malware after
analysis, it undergoes the following:
Converted into a non-executable state
Compressed and password protected
Encrypted
When it comes to compressing with password protection, some malware research group
or companies have their own password that is different from the ones commonly used
such as infected, virus, and novirus. As an added precaution, the password-protected
compressed file is encrypted. It can be encrypted using public key cryptography, and only
the private keys of the authorized users or researchers can decrypt it. Or the drive or data
storage where the files reside is encrypted, and the only ones who can decrypt the data
storage are those who have knowledge of and access to the needed credentials or tokens.
In short, encryption when it comes to storage can occur by using the following:
Public key cryptography
Whole data storage encryption
Also, when it comes to confidentiality, it is important to consider data transmission and
the security of the credentials needed to access to data. If for some reason the credentials,
such as usernames, passwords, tokens, and private keys, are compromised and the
malware samples and information are intercepted during transmission or a location, such
as a backup, is breached, then no matter how strong the encryption is, the data and
information can be stolen. Therefore, it is important to also secure the assets where the
data and information resides and the credentials that grant access to them.
Integrity
As I defined earlier, integrity ensures that the data and information has not been modified
or altered in any way, therefore maintaining its trustworthiness and accuracy.
There are lots of causes that can contribute to data integrity violations. Some of them
are as follows:
System error
User error
Malware
Malicious actor
Data in storage or static data can be corrupted because of system error. Static data can
be corrupted if the hardware or storage device starts to malfunction or starts deteriorating,
causing bad sectors that can result in some data being lost. Sadly, disks today can be
corrupted without being detected. This is because of the complexity of disk technology
that has multiple points of failure such as a faulty disk controller that can cause data not to
be written where it is supposed to be written on disk causing corrupt data. There are also
cases wherein data is hosted in a very old system that is just waiting for a nudge to break
down.
System error can also be caused by software. Buggy and poorly designed software can
cause data modification without the knowledge of the user or the system.
Data that is transmitted, or dynamic data, is also susceptible to corruption, especially if
it is being transmitted through unreliable networks. Unreliable networks usually corrupt
data that pass through them because of intermittent connection losses. Without any error
checking, the data that is transferred from the source might be different once it reaches the
receiver.
User error also plays a role in violating data integrity. Using a tool or software in an
incorrect manner while dealing with data can corrupt the data. A user can also
inadvertently destroy or delete data without knowing it, especially if the user is not well
trained to handle that sort of data.
Aside from system and user error, there is a more sinister cause that can contribute to
data integrity violation, which is malicious intent. Malicious intent to destroy or violate
the integrity of data must be considered at all times. It can be carried out through the use
of malware or unauthorized breach by an attacker or group of attackers. Therefore, it is
important to consider the security of where the data is stored and how it is accessed.
Regular checks of software that can be exploited through vulnerabilities must be done.
This includes but is not limited to the operating system and the different kinds of software
used to manage data.
To help ensure data integrity, the following are common techniques used in the
industry:
Data replication
Parity computations
Checksum
Data replication is the simplest way of ensuring data integrity. The main idea here is to
have multiple copies of the data and then have regular integrity checks comparing the
copies. If one copy is different, then that is flagged as corrupt data and corrected by
overwriting it with the right copy. Although this is the simplest way and the easiest to
implement, it is not scalable. It is inefficient as data grows. The storage needs multiply
depending on how many copies there are, and the time needed to do integrity checking
between the copies can become very long.
LINGO
Data replication is also known as mirroring.
Parity computations are used in RAID drive arrays, such RAID-3, RAID-4, and RAID-
5, for fault tolerance and validating data written to the RAID array by calculating the data
in two drives and storing the resulting calculation on a third one. The Exclusive OR
(XOR) logical operator is used to calculate parity across the RAID array. The main idea
here is that if one drive fails, it can be replaced, and the data can be rebuilt from the other
two drives.
NOTE
RAID drives have a “hot-swappable” drive on standby to replace a failed or
corrupted drive.
Getting the checksum of the data (in this case, the malware samples) and storing it in
one place is another method of integrity checking. This is a well-known method. It
actually reminds me of Microsoft Anti-Virus (MSAV) during the DOS days. The main
idea here is to get the checksum of the data and then using it to check whether that data
changed. Checksums can be as simple as a hash.
Availability
Availability ensures that the data is accessible or available when needed. The ideal is no
downtime. But since we do not live in an ideal world, there will be downtime. The main
idea is to have as little downtime as technically possible. This can be achieved by having
the system, both hardware and software, working in tip-top shape. A good way to ensure
this is periodic and proper maintenance of the systems where the data is hosted. And if
something fails, there has to be immediate response in repairing or replacing the failed
component.
The most common way to achieve availability is through redundancy. This ensures that
if one site is down, the other sites can take over, and the availability of data is not affected
in any way. When it comes to availability, there shouldn’t be any denial of service.
Recap
In this chapter, I discussed how to properly handle an unknown file during the whole file’s
analysis life cycle. I discussed each stage of the life cycle, as listed here, and how to
properly handle files in each of the stages:
Transfer
Analysis
Storage
I identified three ways to properly handle files during transfer or transport by making
sure that the file meets the following conditions:
In a non-executable state
Inaccessible to unauthorized users
Came from a verifiable or trustworthy source
When it comes to the second stage, which is analysis, I stressed the importance of
having the file remain in a non-executable state all the time except when it undergoes
dynamic analysis.
Last but not least, I discussed how to properly store files. I discussed the CIA triad and
how it can be applied to protecting malware files.
Tools
Compression tools
WinZip http://www.winzip.com
WinRAR http://www.rarlab.com
7zip http://www.7-zip.org
p7zip http://p7zip.sourceforge.net/
GnuPG http://www.gnupg.org
CHAPTER
11
Inspecting Static Malware
T he previous two chapters gave you an overview of the Portable Executable (PE)
file and the proper way of handling unknown files and those that are found to be
malicious. They introduced you to concepts that needed to be understood and done
before you can begin malware analysis. Now that you have an understanding of these
concepts and an increased awareness of the dangers and pitfalls that you might face if you
do not follow them, you are now ready to analyze malware.
In this chapter, I will discuss how to inspect static malware, a process also known as
static malware analysis or simply static analysis. I will go through the step-by-step
process of analyzing static malware and the tools needed to accomplish your goal of
extracting information from static malware.
In this lab, you will create a script that computes a file’s MD5 and SHA-1 hash.
What You Need:
System running Ubuntu 14.04.1
Python 2.7.6
Calc.EXE from Windows 7
Steps:
1. Create a Python script file.
2. Write the following code:
3. After creating the Python script, change it to executable mode by issuing the
following command:
4. Execute your script. Make sure that calc.EXE is in the same folder as your
script.
5. The output should look like the following. Take note that depending on your
calc.EXE, the hash might be different.
NOTE
The file command-line tool also displays whether a binary is packed or not as
long as the packer is included in its signature database.
In some cases, a script is much more desirable when identifying file types. For
instances like this, you can use a Python script to identify file types.
In this lab, you will create a script that identifies file type of a given file.
What You Need:
System running Ubuntu 14.04.1
Python 2.7.6
Calc.EXE from Windows 7
Steps:
1. Install python-pip. (You can skip this if pip is already installed.)
5. After creating the Python script, change it to executable mode by issuing the
following command:
6. Execute your script. Make sure that calc.EXE is in the same folder as your
script.
Antivirus Detection
When it comes to figuring out whether a file is malicious, a good indicator is the result of
an antivirus product scan. This process also helps in determining the possible family of
the malware. Take note that I am not talking in absolutes here because there is always the
possibility of a false positive and misnaming of malware detection. In the analysis
process, you use antivirus detection simply as an indicator to help you identify the
maliciousness of a file and its possible malware family group.
There are two ways to subject a file to an antivirus scan. They are as follows:
On-premise antivirus scanning
Online antivirus scanning
On-premise antivirus scanning means you have the antivirus product installed in a
system you control. It can be a set of different virtualized machines hosting different
antivirus products each or an offline tool that utilizes different antivirus product engines to
scan a file for possible infection. In an on-premise setup, the management of the system,
such as updating scan signatures and ensuring uptime, is your responsibility. So, aside
from hardware and software license cost, there is also maintenance cost. One thing that is
important to remember is that no matter what the implementation is, the main idea is that
you control the system and all the data and information produced by the system.
Online antivirus scanning is a cheaper alternative because there is no hardware and
software to manage and maintain. Plus, most online antivirus scanning services are free or
can be accurately described as having a zero dollar cost. The caveat is that whatever files
you submit to them eventually become their property, and they can do whatever they want
with those files and the information collected from those files by their systems. In reality,
it is not really free. Some online antivirus scanning companies that offer this service for
free sell the files and information gathered from those files.
The most popular online antivirus scanning service is Google’s VirusTotal, as shown in
Figure 11-2. It is the most trusted and widely used in the industry.
In this lab, you will experiment using VirusTotal Public API. Since VirusTotal already has
detailed documentation on how to do this, the lab will refer to the documentation and let
you experiment on your own.
What You Need:
VirusTotal Public API
Steps:
1. Request the VirusTotal Public API from VirusTotal.
2. Read and familiarize yourself with the documentation at
https://www.virustotal.com/en/documentation/public-api/.
3. Accomplish the following capabilities:
A. Sending and scanning files
B. Rescanning already submitted files
C. Retrieving file scan reports
4. Feel free to experiment with other features and capabilities mentioned in the
documentation.
Some antivirus vendors offer their own online scanning service that highlights their
antivirus product or scan engine. Some of them are the following:
Dr. Web http://www.drweb-online.com/en/online_check.asp
Fortiguard Online Virus
Scanner http://www.fortiguard.com/antivirus/virus_scanner.html
Alternatively, antivirus vendors offer a way for users to submit samples to them for
analysis. Unlike an online scanning service where the result of the scan is posted
immediately, the user has to wait for a response from the vendor. The response usually
comes via e-mail. This means that when a user submits a sample, the user has to give up
some information such as an e-mail address.
The following are some vendors that offer sample submission services to users:
F-Secure Sample Analysis http://www.f-
secure.com/en/web/labs_global/submit-samples/sas
Sophos https://secure2.sophos.com/en-us/support/contact-support/sample-
submission.aspx
Antivirus vendors offering these services for free not only help the user but also
themselves, the antivirus companies. This is because they are able to collect suspicious
samples for free. It is crowdsourcing at its best. Also, this helps the different antivirus
vendors get a pulse of what’s going on in the digital world. If there is a set of samples
being submitted (hundreds or even thousands of times in a short period of time), chances
are these samples are hot and attention must be given to them.
Aside from on-premise and online virus scanning services, there is another alternative.
This alternative relies more on the open source community. This caters to researchers who
do not have a budget to create their own on-premise antivirus scanning infrastructure and
do not want to submit any samples to an online antivirus scanning service provider. The
alternative is using ClamAV.
ClamAV, as described by its publisher, is an open source (General Public License
[GPL]) antivirus engine designed for detecting Trojans, viruses, malware, and other
malicious threats. It provides a high-performance multi-threaded scanning daemon,
command-line utilities for on-demand file scanning, and an intelligent tool for automatic
signature updates. The ClamAV virus databases are updated regularly and posted online
for download by users. This is a cheaper alternative to the on-premise virus scanning
infrastructure and does not carry the privacy concerns of submitting samples to online
antivirus scanning service providers.
You can find more information and download links for ClamAV at
http://www.clamav.net.
In this lab, you will install and use ClamAV to scan files for possible infection.
What You Need:
System running Ubuntu 14.04.1
Steps:
1. Install ClamAV.
In this lab, you will install and use ClamTK to scan files for possible infection.
What You Need:
System running Ubuntu 14.04.1
Steps:
1. Install ClamTK.
If you need a new virus definition added to ClamAV and the most updated virus
definitions found in http://lurker.clamav.net/list/clamav-virusdb.html does not include it,
you can create your own signature and add it to your ClamAV virus definition.
In this lab, you will pack a file using the most common packer of all, UPX.
What You Need:
System running Ubuntu 14.04.1
Calc.EXE from Windows 7
UPX
Steps:
1. Install UPX.
2. Pack calc.EXE.
3. Check whether calc.EXE has been successfully packed using the file
command-line tool.
In this lab, you will create a script that can detect whether a binary is packed and, if it is,
what packer was used to pack it.
What You Need:
System running Ubuntu 14.04.1
Python
UserDB.TXT
Packed binary, preferably from the previous lab, 11-8
Steps:
1. Create a Python script file.
2. Write the following code:
3. After creating the Python script, change it to executable mode by issuing the
following command:
4. Execute your script. Make sure that the packed file is in the same folder as
your script.
NOTE
In the script, ep_only stands for scan entry point only. If it is set to True, the
script will scan only the entry point, but if it is set to False, the script will scan
the whole body of the file, making the scanning process slower.
TIP
UserDB.TXT can be modified to include new packer signatures.
Identifying whether a file is packed is just half the battle. The challenging part is to
unpack it. An unpacked and unencrypted file makes it easier for analysts and researchers
to proceed in the static analysis process. There are lots of tools out there that can unpack a
protected binary, especially if the packer used is common. For those packers that do not
have unpackers, reverse engineering is the key to unpacking the file. The analyst then has
to weigh whether the time needed to unpack the binary manually is worth it or just
proceed directly to dynamic analysis. In most cases, the latter is chosen.
Most PE tools that are available in the market have the ability to unpack packed
binaries. One of my favorites is PE Explorer (http://www.heaventools.com/overview.htm).
It supports unpacking of UPX, Upack, and NsPack.
For packed binaries that are not supported by most tools, I usually go to this site to find
an unpacker: http://www.woodmann.com/crackz/Packers.htm. Again, do not execute any
of the tools published on this site in a production network. Always treat tools such as this
with great caution and suspicion. It is always better to use these tools in a controlled
environment.
PE Structure Verification
Another indicator of whether a file is malicious is a malformed PE structure. A malformed
PE structure often indicates an infection or a sloppy way of hiding malicious code. Having
knowledge of the PE structure is critical in this static analysis technique. An abnormal
field value, a non-standard section, or anything that appears off is a good candidate for
further investigation.
TIP
In Chapter 9, I discussed the PE file structure. It is always good to refer to that
chapter as reference when it comes to the different fields and their possible
values.
Strings Analysis
A file sample that is unencrypted can reveal a lot by looking at the strings found in its
code. Just by extracting strings, you can identify a lot of things from a possible malware
sample. The following are the more interesting ones:
Location of malicious dropped files
Name of the dropped files
Domain name of a possible command-and-control (C&C) server
Internet Protocol (IP) address of a possible C&C server
Aside from these, another set of strings might be of interest, especially if it comes to
tying the malware samples to their writers or the threat actors that are using them. Some
strings might contain the following information:
Dedications
Political statements
Group affiliations and mottos
Incendiary messages
In this lab, you will use the command-line strings that come with Ubuntu to extract strings
from files.
What You Need:
System running Ubuntu 14.04.1
Unpacked and unencrypted binary
Steps:
1. Open a terminal window.
2. Type the following command. You will use the unpacked version of calc.EXE
from Windows 7.
3. If you want to save the output to a text file, issue the following command:
4. Examine the output, and you will notice a lot of useful information such as
libraries and function calls that the program needs to run.
In this lab, you will use strings.EXE from Sysinternals to extract strings from files.
What You Need:
System running Windows
strings.EXE from Sysinternals
Steps:
1. Download strings.EXE from http://technet.microsoft.com/en-
us/sysinternals/bb897439.
2. Open a command prompt and go to the folder where strings.EXE is saved.
3. Issue the following command. You will use the unpacked version of calc.EXE
from Windows.
4. If you want to save the output to a text file, issue the following command:
5. Examine the output, and you will notice a lot of useful information such as
libraries and function calls that the program needs to run.
Recap
In this chapter, I discussed different static analysis steps and techniques to get as much
information as you can from a static file. They are as follows:
File type identification
Antivirus detection
Protective mechanisms identification
PE structure verification
Strings analysis
I also discussed different tools that are available to you from Windows and Ubuntu.
You also created some scripts that will help you in your static analysis process.
Tools
MD5SUM http://www.etree.org/md5com.html
Microsoft File Checksum Integrity Verifier http://www.microsoft.com/en-
us/download/details.aspx?id=11533
PEiD http://woodmann.com/BobSoft/Pages/Programs/PEiD
ClamAV http://www.clamav.net
Sample submission online services
F-Secure Sample Analysis http://www.f-
secure.com/en/web/labs_global/submit-samples/sas
Sophos https://secure2.sophos.com/en-us/support/contact-
support/sample-submission.aspx
Malware scanning services
VirusTotal by Google https://www.virustotal.com
VirSCAN http://www.virscan.org
Metascan by OPSWAT https://www.metascan-online.com
Jotti http://virusscan.jotti.org
Dr. Web http://www.drweb-online.com/en/online_check.asp
Fortiguard Online Virus
Scanner http://www.fortiguard.com/antivirus/virus_scanner.html
Packers
Armadillo http://www.siliconrealms.com/armadillo.php
ASPack http://www.aspack.com/aspack.html
ASProtect32 http://www.aspack.com/asprotect32.html
ASProtect64 http://www.aspack.com/asprotect64.html
PECompact http://bitsum.com/pecompact/
UPX http://upx.sourceforge.net/
PE Explorer http://www.heaventools.com/overview.htm
Packers and Unpackers http://www.woodmann.com/crackz/Packers.htm
Sysinternals Strings.EXE http://technet.microsoft.com/en-
us/sysinternals/bb897439
CHAPTER
12
Inspecting Dynamic Malware
Dynamic Analysis
When it comes to observing malware behavior, it can be divided into two parts.
Host behavior
Network behavior
In the early years of malware, dynamic analysis was confined to analyzing a malware’s
host behavior. The early malware did not have any network functionality. A dynamic
analysis lab was a single isolated system. But with the advances of malware and its ability
to communicate remotely with other malware and with its controller, it is a must to
analyze its network behavior as well. Therefore, when it comes to dynamic analysis
collecting and analyzing, both the malware host and the network behavior must be studied.
File System
Changes in the file system help you determine how the malware installs and protects itself
in the system during the initial stages of infection and upon successful system
compromise. It can also offer a view of how malware achieves persistency through
malware component placement, especially if it utilizes nonregistry techniques such as
utilizing the StartUp folder.
File system changes can also be a good indicator of malware directive, especially if it
has something to do with destroying files. It can also offer a glimpse of how it spreads
through other systems such as infecting other files or creating bogus files for copying in
local and network share folders.
There are three changes to the file system that you need to monitor.
Added files
Deleted files
Modified files
Added Files As previously mentioned, during the malware installation stage, the
malware usually drops a copy of itself and other components it needs to function. Most
malware nowadays is deployed or installed using a dropper, downloader, or hybrid of
both. If the malware utilizes a dropper or a downloader, the installation of malware
components is similar to the installation of legitimate software. The only difference is that
the dropper or downloader deletes a copy of itself after control is passed to the malware
components.
It is important to record all files that have been added to the system because chances
are these are all malware components and getting hold of these files and where they are
located is key to understanding how the malware installs itself in the system and how each
file functions. In modern malware, each component has a separate function that
complements each other. The following are the most common malware components:
Main malware file
Bot agent
Rootkit component
Regeneration component
Attack component
Configuration files
A malware package can contain one or a combination of any of the mentioned
components.
The main malware file is the one that utilizes the other components to ensure its
success. The bot agent is the one responsible for communicating to the attacker via
command and control (C&C) or to any network resource the malware needs. The rootkit
component possesses the rootkit technology that enables the malware to hide in the
system. The regeneration component is the one responsible for rebuilding malware if one
of its components is removed or any entry in the registry has been modified. The attack
component defines the malware’s main directive. This component contains the
functionality the malware needs to conduct the attack. If the malware is designed for a
distributed denial-of-service (DDOS) attack, this component will contain DDOS
functionality. If the malware is more for data exfiltration, this component will contain
information-stealing capabilities. Getting hold of this component is critical in
understanding the malware’s capability and directive. Last but definitely not the least, the
configuration file contains information for other components. It can contain system
targets, special instructions, updated network resources, or any information the malware
needs to function. Usually, configuration files are used to change the malware’s behavior
based on the attacker’s need.
NOTE
Older malware attacks consist of only a single file; that is, the malware itself
and all the component functions are coded into the malware itself, and updating
any functionality means updating the whole malware file. Modern malware is
modular. Each component is a separate file for easy updates by the attacker.
Getting a copy of all these components enables the researcher or analyst to understand
the malware’s behavior better.
LINGO
Modularized malware is malware whose functions are assigned to different
files and not coded into a single malware code.
It is also important to remember that most malware authors do not want to reinvent the
wheel. If the functionalities they need are present in existing tools, they will use those
tools as a separate module or simply copy that tool’s code into the malware code. For
example, if a malware wants to download files via File Transfer Protocol (FTP), it might
use known FTP download tools. This is why it became common during the heyday of
network worms that malware usually utilized network tools used by network
administrators. The advantage of this is that the tools will not be flagged as malware
because they are known to be benign tools. It came to the point that malware specifically
written to compromise servers already assumes that the tools it needs are already installed
there because these are the same tools used by network administrators to manage their
servers.
Deleted Files Not counting droppers and downloaders, in some cases malware will
delete files in the system that pose a threat to its existence. The following are the most
common files deleted by malware during installation:
System restore files
Configuration files
Security product files
If a malware is designed to be destructive and its main directive is to delete files,
knowing what files were deleted will aid in identifying the malware’s main file target and
what files needed to be restored.
Modified Files When file infectors ruled the threat landscape, the best way to tell
whether a system was infected was by identifying all modified files and flagging them as
possibly infected by a virus. This is the main reason why early antivirus solutions relied
on cyclic redundancy check (CRC) and checksum. The idea here is that if a file’s CRC
changes unexpectedly from the previous check, it is infected.
In today’s threat landscape, the importance of identifying modified files during
compromise is still important. It usually is an indication of system or third-party software
files infected by malware or modified for a specific purpose that will aid the malware in
its operation. One operation is extortion. Malware such as CryptoLocker and CryptoWall
encrypts important document files so that they cannot be accessed or read by the user. A
series of modified document files can signal the presence of a ransomware that locks files
for ransom.
File modification can also aid malware when it comes to persistency. One example is
the modification of a .INI file to get itself started on every bootup. In the DOS days, the
most common file that was modified to get malware to start up on every bootup was
AUTOEXEC.BAT.
Registry
Modifications to the registry are usually made to achieve persistency. The following are
the common registry entries modified by malware to achieve persistency.1 The registry
keys are grouped according to the autostart technique utilized by malware to achieve
persistency.
Boot execution
HKLM\System\CurrentControlSet\Control\Session Manager
Loading of driver and services
HKLM\System\CurrentControlSet\Services
Upon logon
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
HKLM\Software\Microsoft\Windows\CurrentVersion\ RunOnce
HKLM\Software\Microsoft\Active Setup\Installed Components
Loading of Explorer shell extensions
HKLM\Software\Classes\*\ShellEx\ContextMenuHandlers
HKLM\Software\Classes\Directory\ShellEx\ContextMenuHandlers
HKLM\Software\Classes\Directory\ShellEx\DragDropHandlers
HKLM\Software\Classes\Folder\ShellEx\ContextMenuHandlers
HKLM\Software\Classes\Folder\ShellEx\DragDropHandlers
Loading of browser extensions
HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\Browser
Helper Objects
HKLM\Software\Microsoft\Internet Explorer\Extensions
Please take note that this also applies to other registry hives such as HKEY_
CURRENT_USER and specific user profile hives. A user profile hive, as defined by
Microsoft, contains specific registry information pertaining to the user’s application
settings, desktop, environment, network connection, and printers. User profile hives are
located under the HKEY_USERS key.
Upon infection, some malware disables REGEDIT to prevent any user from viewing
the registry. One disadvantage of this protective mechanism is that it raises suspicion that
the system is compromised.
NOTE
Similar to the file system, a malware can add, modify, or delete a registry key
depending on the malware’s purpose.
In this lab, you will use installation/uninstallation tools to determine system changes made
by malware. These tools are designed to create uninstallers to effectively remove any
software that is installed, but they are also useful in tracking changes made by malware.
The tool you will use in this experiment is a classic tool called InstallRite.
This lab works well if you have in your possession a malware sample. If you do not
have one, please review previous chapters on how to collect malware samples.
What You Need:
System running Windows
Malware sample
Steps:
1. Download and install InstallRite from
http://www.softpedia.com/get/System/System-Info/InstallRite.shtml.
2. Start InstallRite. Figure 12-1 shows the InstallRite main window.
Figure 12-1 InstallRite main window.
3. Click Install New Software And Create An InstallKit and follow the prompts,
as shown in Figures 12-2 to 12-4.
In this lab, you will use installation/uninstallation tools to determine system changes made
by malware. These tools are designed to create uninstallers to effectively remove any
software that is installed, but they are also useful in tracking changes made by malware.
The tool you will use in this experiment is Uninstall Tool by CrystalIdea Software.
This lab works well if you have in your possession a malware sample. If you do not
have one, please review the previous chapters on how to collect malware samples.
What You Need:
System running Windows
Malware sample
Steps:
1. Download and install Uninstall Tool from
http://www.crystalidea.com/uninstall-tool.
2. Take note that this is not free software, but it can be used as a trial for 30 days.
3. Start Uninstall Tool. Figure 12-7 shows the main window. As you can see, the
Uninstaller tab displays all installed software.
Memory
The system’s memory is where the action takes place. Code and data are decrypted in
memory. Having the ability to monitor and capture unencrypted code and data from
memory is one of the best ways to understand a malware’s behavior.
LAB 12-3: Analyzing Running Processes in Memory Using Process Explorer
In this lab, you will use Process Explorer to analyze a malware’s running process.
What You Need:
Infected Windows system
Sysinternals Suite
Steps:
1. Download and install Sysinternals Suite from
https://technet.microsoft.com/en-us/sysinternals/bb842062.aspx.
2. Extract the downloaded ZIP file to your desired folder.
3. Go to that folder, look for Process Explorer (procexp.exe), and open it.
4. If you do not want to download the whole Sysinternals Suite and want only
Process Explorer, you can download it from https://technet.microsoft.com/en-
us/sysinternals/bb896653.
5. In this experiment, you will be using the infected Windows system you used
in previous experiments where you ran the infected malware. For this specific lab, I
will use the system infected with the VOHO malware.
6. Figure 12-16 shows Process Explorer running in a system infected by VOHO
malware.
Figure 12-16 Process Explorer running in an infected system.
7. You know from the monitoring tools you used that VPTray.exe is one of the
files installed by the VOHO malware. It can easily be spotted in the Process
Explorer window.
8. Hovering the mouse pointer over the VPTray.exe process will reveal its
location on disk. Figure 12-17 shows this.
Figure 12-17 Process Explorer reveals the path of a running process.
NOTE
This capability of revealing the path of a running process is useful, especially
if you want to map a process to a file when doing system forensics and you have
no idea which of the processes are malicious.
9. Double-clicking the process will reveal its properties, as shown in Figure 12-
18. Another way of revealing its properties is by right-clicking the running process
and clicking Properties.
Figure 12-18 Running process properties TCP/IP tab.
10. From here, you can look at the different tabs to reveal information about the
running process. The TCP/IP tab shown in Figure 12-18 reveals its network
capability.
11. One interesting tab is the Threads tab, as shown in Figure 12-19.
Figure 12-19 Running process properties Threads tab.
12. Clicking the Stack button reveals the stack for that specific process thread.
Figure 12-20 shows the stack for this specific malware.
In this lab, you will determine whether the malware process you identified and analyzed
using Process Explorer is persistent or has the capability to start up after every shutdown
or reboot. For this specific purpose, you will be using Sysinternals Autoruns.
What You Need:
Infected Windows system
Sysinternals Suite
Steps:
1. Download and install Sysinternals Suite from
https://technet.microsoft.com/en-us/sysinternals/bb842062.aspx.
2. Extract the downloaded ZIP file to your desired folder.
3. Go to that folder, look for Autoruns (autoruns.exe), and open it.
4. If you do not want to download the whole Sysinternals Suite and want only
Autoruns, you can download it from https://technet.microsoft.com/en-
us/sysinternals/bb963902.aspx.
5. In this experiment, you will be using the infected Windows system you used
in previous experiments where you ran the infected malware. For this specific lab, I
will use the system infected with the VOHO malware.
6. Figure 12-24 shows Autoruns running in a system infected with VOHO
malware.
In this lab, you will be using Wireshark to analyze malware’s network behavior.
What You Need:
Infected Windows system
Wireshark
Steps:
1. Download and install Wireshark from https://www.wireshark.org/. Take note
that you will be prompted to install WinPcap if you do not have it on your system.
2. In this experiment, you will be using the infected Windows system you used
in previous experiments where you ran the infected malware. For this specific lab, I
will use the system infected with the VOHO malware.
3. Figure 12-28 shows the Wireshark main window.
Figure 12-28 Wireshark main window.
4. To start the capture session, select an interface to monitor on the left-side
menu under the Start button and then click the Start button. Take note that Wireshark
needs to run under administrator mode.
5. Once the capture session starts, you can see the TCP connection to the
destination address that has been shown in the TCPView session in your previous
lab. Figure 12-29 shows this.
Figure 12-29 Capture session showing malware connection to its network resource.
6. Once the connection session has been identified, it can be further analyzed by
expanding the data shown in the second window below the capture session. Figure
12-30 shows the expanded view of the session.
7. From here you can view a lot of information about the packet.
Figure 12-30 Expanded view of a session in Wireshark.
Recap
In this chapter, I discussed how to analyze dynamic malware. I touched on how virtual
and bare-metal environments can complement each other instead of making a hard choice
of just using one and not the other. I discussed the two areas of dynamic analysis that is
important in getting to the bottom of modern malware’s behavior. They are as follows:
Analyzing host behavior
Analyzing network behavior
In analyzing host behavior, I broke it down into monitoring and collecting data from
the following areas of the dynamic analysis lab or target system:
File system
Registry
Memory
I discussed different tools and techniques in your lab to accomplish your goal of
monitoring and recording data gathered from malware as it behaves on the host system
and as it leaves traces while communicating through the network.
I also discussed the limitations of dynamic analysis to end the chapter so that there is
clear understanding of the advantages you can get from conducting dynamic analysis
while also recognizing that not all information can be gathered because it is dependent on
the malware’s ability to execute within the environment.
Tools
Sysinternals Suite https://technet.microsoft.com/en-
us/sysinternals/bb842062.aspx
System monitoring tools
InstallRite http://www.softpedia.com/get/System/System-
Info/InstallRite.shtml
Uninstall Tool http://www.crystalidea.com/uninstall-tool
Memory analysis tools
Process Explorer https://technet.microsoft.com/en-
us/sysinternals/bb896653
Autoruns https://technet.microsoft.com/en-
us/sysinternals/bb963902.aspx
Network analysis tools
TCPView https://technet.microsoft.com/en-
us/sysinternals/bb897437.aspx
Wireshark https://www.wireshark.org/
1 Malware, Rootkits & Botnets by Christopher C. Elisan, published by McGraw-Hill.
CHAPTER
13
Tools of the Trade
I n malware analysis, it is important to have the right tools. Familiarity with these tools
and how to use them properly is the difference between success and failure in
malware analysis. The use of tools to perform malware analysis has been discussed
throughout this book. In previous chapters, I discussed how to use certain tools to perform
static and dynamic malware analysis.
The right tools together with the right skills are a powerful combination when faced
with a difficult malware to analyze.
In this chapter, you will take a look at more tools that are important when it comes to
malware analysis. I consider them tools of the trade.
Sysinternals Suite
As discussed in previous chapters, Sysinternals is an indispensible tool. It comes as a suite
containing all the tools, or you can download each tool separately if you do not want to
get the whole package.
You can download the suite from https://technet.microsoft.com/en-
us/sysinternals/bb842062.aspx, and if you want to download just a specific tool from the
suite, simply click the name of the tool you want from the page pointed to by the link, and
you will be all set.
Yara
Yara is a versatile pattern-matching tool. As claimed on its website, it is indeed the
pattern-matching Swiss Army knife for malware researchers and everyone else. Yara is a
tool aimed at, but not limited to, helping malware researchers to identify and classify
malware samples. With Yara, you can create descriptions of malware families or whatever
you want to describe based on textual or binary patterns.1
A description is also known as a Yara rule. Each rule consists of a set of strings and a
Boolean expression, which determines its logic. The strings, which comprise the textual or
binary patterns, are then used as signatures to detect a possible match based on the logic
written in the rule.
Figure 13-1 is an example of a Yara rule taken from https://github.com/plusvic/yara.
9. Type the following command line to check whether Yara was installed
successfully:
10. If the help section of Yara is displayed, you now have Yara successfully
installed on your system.
2. The previous strings make up the file’s CLSID found in file offset 0x9A7. It
might be different from the CLSID that your Calc.EXE has. To check, run the
following command line, browse to the mentioned offset, and adjust the rule
appropriately. It is also possible that the CLSID is found in a different offset.
The first argument is the rule file, and the second argument is the file to be
scanned.
5. If the strings match what is in the file, the following output is displayed:
calc_match is the name of the rule, and calc.exe is the file that matches it.
6. Open the yara_rule.txt file and add another string from file offset 0x6F0. But
instead of using its text equivalent, use hex values representing the string. Change
the condition to $b, which means that the rule will use only $b as the matching
string. Comment out the $a string using /* and */ and then save the file.
7. Run Yara to check for a match. If the strings are written correctly, there will
be a positive match.
8. Open the yara_rule.txt file, uncomment the $a string, and modify the
condition to $a or $b. This means that if any of the strings are present in the file, it
will be a positive match. The final rule will look like this:
In this lab, you will install Yara support for Python so you can utilize it in a Python script.
What You Need:
System running Ubuntu 14.04.1
Yara
Python
Steps:
1. Install python-dev using the command line in a terminal window.
2. Build and install the yara-python extension. From the terminal window, go to
the folder where Yara was extracted. From Lab 13-1, the folder is yara-3.3.0. The
folder name changes based on the version of Yara you downloaded. As of this
writing, the latest is 3.3.0. From inside the yara-3.3.0 folder, issue the following
commands:
4. If the command line is not letting you make the necessary changes to
/etc/ld.so.conf, you can use gedit as an alternative. From a terminal window, issue
the following commands:
5. Add the line /usr/local/lib without the quotes at the end of the file.
6. Save and close the file.
7. In the terminal window, run the command to load the config file.
10. If there are no errors, this means that the installation is successful. Type
exit() to exit the development environment.
In this lab, you will create a Python script that utilizes Yara rules to classify files.
What You Need:
System running Ubuntu 14.04.1
Yara
Python
Calc.EXE from Windows
Steps:
1. Create a Python script file and write the following code:
2. After creating the Python script, change it to executable mode by issuing the
following command:
3. Execute your script. Make sure that yara_rule.txt and calc.EXE are in the
same folder as your script.
Cygwin
Cygwin is a tool that gives you that Linux feeling in Windows. Cygwin is a large
collection of GNU and open source tools that provide functionality similar to a Linux
distribution in Windows. But it is not a way to run native Linux apps on Windows nor is it
a way to magically make Windows programs aware of Unix functionalities. Instead,
Cygwin is a DLL that provides substantial POSIX application programming interface
(API) functionality.2 The Cygwin DLL is cygwin1.dll.
Cygwin provides a quick and easy way for analysts to have access to some GNU
command lines from Windows without switching operating systems.
In this lab, you will install Cygwin in a Windows box, specifically Window 7.
What You Need:
System running Windows 7
Cygwin
Steps:
1. Download Cygwin from https://www.cygwin.com. For this purpose, you will
be downloading the 64-bit version. The downloaded file is setup-x86_64.exe.
2. Install Cygwin and follow the prompts. Figure 13-2 shows the installation
window of Cygwin. Click Next.
Debuggers
In computer science, debugging is the process of finding errors or bugs in a program or a
device. The tools that are used for debugging are called debuggers. In DOS, a reliable tool
for this is Debug.COM, but the world of debuggers has come a long way after that.
In malware analysis, debugging is the process of tracing code to find out what it does.
It is a step-by-step tracing of malware code to determine its true intention. This is why
debugging is a critical ingredient of reverse engineering.
For the purpose of this book, debugging is a helpful process to determine whether a
binary is encrypted, packed, or neither. Learning this skill is needed, especially if the
packer or cryptor is new and no PEiD or Yara signature exists yet to detect it. Remember,
any file that is encrypted or packed usually renders static analysis useless. But if a
malware is unpacked or decrypted through the use of tools, it will be easy to get
information from it using static analysis; thus, you have more data to help you classify
whether a file is malicious and even cluster it with its group or malware family for better
identification.
The following are most common debuggers that are used in malware analysis:
OllyDbg
Immunity Debugger
Windows Debuggers
OllyDbg
OllyDbg is a classic tool that is still popular with malware analysts today. You can
download it from http://www.ollydbg.de/. One great thing about OllyDbg, called Olly for
short, is that there is a wealth of plug-ins available for download all over the Internet to
make debugging easier. A search for OllyDbg plug-ins will yield lots of resources when it
comes to useful plug-ins. But as with other things available freely on the Web, exercise
caution when downloading and using them.
Immunity Debugger
Immunity Debugger is a debugger that boasts of features that are deemed friendly for
security experts. You can download it from http://debugger.immunityinc.com/. On its
main page, it is described as a powerful new way to write exploits, analyze malware, and
reverse engineer binary files. It can also be extended by using a large and well-supported
Python API.
Windows Debuggers
The most common Windows debuggers are WinDbg, KD, and NTKD. The one that
encompasses all, at least in my humble opinion, is WinDbg. WinDbg is Microsoft’s own
Windows debugger. It is part of the Windows Driver Kit, but it can also be downloaded as
a stand-alone tool from https://msdn.microsoft.com/en-
us/windows/hardware/hh852365.aspx.
WinDbg is thought to have an “inside” advantage compared to other debuggers because
it is written specifically for Windows. It has the following features:
Kernel mode debugging
User mode debugging
Managed debugging
Unmanaged debugging
Remote debugging
Ability to attach to a process
Ability to detach from a process
It basically covers all the bases of other Windows debuggers such as KD and NTKD.
You can find more information about KD and NTKD from https://msdn.microsoft.com/en-
us/library/windows/hardware/hh406279%28v=vs.85%29.aspx.
Disassemblers
A disassembler is a tool that breaks down a binary into assembly code. A disassembler is
often used in tandem with a debugger. A debugger follows the assembly code in memory,
and the output of the disassembler serves as a map or a good indicator whether the code
being traced in memory is still in line with the disassembled code. Sometimes there will
be differences, which means that either the debugging session is going to a dead end or
the disassembled code is not as reliable probably because the malware has an anti-
disassemble capability.
The most popular disassembler is IDA. It is also considered a debugger. IDA is a little
pricey, but the good thing about it is that there is always a free version available that is for
non-commercial use. You can download it from https://www.hex-
rays.com/products/ida/support/download.shtml.
IDA is a powerful tool. I suggest downloading a free copy of it and playing around with
it. There are lots of resources from its website that will help you get started. The more you
use it, the better you will become at using IDA.
Memory Dumpers
Memory dumpers are tools that dump a running process from memory. There are a
handful of process dumpers available such as Microsoft’s ProcDump, but the most useful
tools, in my humble opinion, when it comes to malware analysis are LordPE and
Volatility.
LordPE
LordPE is a tool that can dump a process from memory and has the ability to edit basic PE
header information. You can download the tool from
http://www.woodmann.com/collaborative/tools/index.php/LordPE.
Volatility Framework
Volatility is a free, useful memory dump analyzer. It is a single, cohesive framework that
supports 32-bit and 64-bit Windows, Linux, Mac, and Android systems. It is a Python-
based framework that allows users to analyze an OS environment from a static dump file.
Being Python-based makes Volatility versatile. It can be programmed to do almost
anything a memory dump analyzer can do. To get started on Volatility, visit
https://code.google.com/p/volatility/wiki/VolatilityIntroduction.
PE Viewers
PE viewers are tools that provide a glimpse of a PE file. There are lots of PE viewers
available depending on your needs. The following are some of them:
Hiew
Heaventools PE Explorer
PEview
Dependency Walker
Resource Hacker
Hiew
Hiew is a classic PE viewer. It has the ability to not only view and edit files of any length
in text and hex but also disassemble a PE file. Some of the features are as follows:
x86-64 disassembler and assembler
View and edit physical and logical drive
Pattern search in disassembler
Built-in simple 64-bit decrypt/crypt system
Block operations: read, write, fill, copy, move, insert, delete, crypt
Multifile search and replace
Unicode support
You can find more information about the tool at http://www.hiew.ru/.
Heaventools PE Explorer
PE Explorer has all the capabilities of a typical PE viewer. The following are the extra
features it offers:
API function syntax lookup
Dependency scanner
Section editor
Unpacker support for UPX, Upack, and NsPack
PE Explorer is not free, but it offers a 30-day trial version. You can download it from
http://www.heaventools.com/overview.htm.
PEview
PEview, as stated on its website, provides a quick and easy way to view the structure and
content of PE and COFF files. It displays header, section, directory, import table, export
table, and resource information within EXE, DLL, OBJ, LIB, DBG, and other file types.
You can download it from http://wjradburn.com/software/.
Dependency Walker
Dependency Walker, as discussed in previous chapters, is a free utility that scans any 32-
bit or 64-bit Windows module and builds a hierarchical tree diagram of all dependent
modules.
You can download Dependency Walker from http://www.dependencywalker.com/.
Resource Hacker
Resource Hacker is a freeware utility to view, modify, rename, add, delete, and extract
resources in 32-bit and 64-bit Windows executables and resource files. It incorporates an
internal resource script compiler and decompiler and works on all Windows operating
systems, at least up to Windows 7.
You can download Resource Hacker from http://www.angusj.com/resourcehacker/.
PE Reconstructors
PE reconstructors are tools that have the ability to reconstruct a portable executable file
from memory or from a dump file given that these tools have all the information they
need such as the entry point, relative virtual address, and size. The most common PE
reconstructor used in malware analysis is ImpREC by MackT. It has the ability to rebuild
the import address table (IAT) from a memory dump. You can download the tool from
http://www.woodmann.com/collaborative/tools/index.php/ImpREC.
The tools discussed so far are stand-alone, and each has their own purpose. Combining
their use to solve a malware analysis problem or use case is not a foreign idea. For
example, manually unpacking a malware is one problem that all malware analysts and
researchers have faced throughout the years. The right combination of tools can help a
malware analyst and researcher break a packed or encrypted malware.
In this lab, you will use the different tools discussed so far to manually unpack a packed
malware. The malware that you will use specifically for this lab has the following
characteristics:
MD5 c0c9c7ea235e4992a67caa1520421941
SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709
SHA256 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b-
934ca495991b7852b855
What You Need:
Debuggers
Disassemblers
Static analysis tools
Dynamic analysis tools
System running Windows
Packed malware
Steps:
1. The first thing to do is to use PEiD to determine whether it is packed.
2. Figure 13-4 shows the output of PEiD. As you can see, PEiD did not detect
anything. Even its Entropy shows that the file is not packed.
In this snippet, the CALL instruction pushes the next instruction’s address, which
is found in the EIP to the stack, and jumps to the function’s address, which in this
case is the address of the next instruction, POP EAX. After executing the next
instruction POP EAX, EAX will contain the address of the POP EAX instruction,
which is just 3 bytes before the string that contains a function name. The next
instruction is an unconditional jump instruction (JMP) that jumps over the string.
The next instruction that will be executed is ADD EAX, 3. After the execution of
this instruction, EAX will be pointing to a null-terminated string containing the
function name.
This technique is repeated in a loop for many functions that are actually used by
the malware but were hidden by the packer such as GetModuleHandleA,
GetOutputDebugString, and so on. The function names are saved in local variables
so they can be accessed later when the IAT is reconstructed in memory.
Figure 13-23 shows this whole thing in the session.
Rootkit Tools
Finding a rootkit is tricky. It takes a lot of patience to uncover one. Couple that with the
right combination of tools, and a rootkit can be revealed. One of my favorite tools that
helps in analyzing malware with rootkit capabilities is Rootkit Unhooker. It’s a classic
tool, but it is still useful.
Some of its capabilities include the following:
SSDT hooks detection and restoration
Shadow SSDT hooks detection and restoration
Hidden processes detection, termination, and dumping
Hidden drivers detection and dumping
Hidden files detection, copying, and deletion
Code hooks detection and restoration
You can download Rootkit Unhooker from
http://www.antirootkit.com/software/RootKit-Unhooker.htm.
Rootkit Revealer is another classic rootkit tool. Unfortunately, Microsoft has
discontinued it, but it can still be downloaded from different file hosting sites. Just be
careful when downloading this file from non-Microsoft sources; it might come with some
extra “bonus content.” But if you are adventurous, one site you can download this from is
http://download.cnet.com/RootkitRevealer/3000-2248_4-10543918.html.
Wireshark
Wireshark is a popular, versatile, and easy-to-use tool when it comes to capturing network
traffic, as demonstrated in Lab 12-6 in the previous chapter.
You can download Wireshark from https://www.wireshark.org/.
TCPDump
TCPDump is a command-line packet analyzer tool. It is an open source tool commonly
used for monitoring or sniffing network traffic. It captures and displays packet headers
and everything that you need to know to understand a target file’s network
communication.
You can download TCPDump from http://www.tcpdump.org/.
TCPView
TCPView is part of Sysinternals Suite. It is a tool that shows detailed listings of all
Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) endpoints on
your system, including the local and remote addresses and the state of TCP connections.3
Lab 12-5 in the previous chapter shows how to use TCPView.
You can download TCPView from https://technet.microsoft.com/en-
us/sysinternals/bb897437.aspx.
As previously stated, combining the use of different tools to solve a malware analysis
problem or use case is not a foreign idea. In the previous lab, you manually unpacked a
packed malware. This is a problem every malware analyst and researcher has faced, but
there is one more that proves to be equally or even more of a headache than packed
malware. It’s a malware with rootkit capabilities. The right combination of tools can help
a malware analyst and researcher reveal the presence of a rootkit in an infected system.
This is made possible if you know what to look for and how to correctly analyze a rootkit.
In this lab, you will perform a complete analysis of a user-mode rootkit using the tools
discussed in this book. You will look at the different indicators of a rootkit and how to
find them.
The malware that you will use specifically for this lab has the following characteristics:
MD5 b4024172375dca3ab186648db191173a
SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709
SHA256 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b-
934ca495991b7852b855
What You Need:
Static analysis tools
Dynamic analysis tools
Sysinternals Suite
PE viewers
Network capturing tools
System running Windows
Rootkit malware
Steps:
1. You will perform basic static analysis on the file before you do anything else.
2. You start by calculating the file’s hashes. Hashes are often used as unique
identifiers of files. The following are the resulting hashes:
MD5 b4024172375dca3ab186648db191173a
SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709
SHA256 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b-
934ca495991b7852b855
SHA512 cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc-
83f4a921d36ce9ce47d0d13c5d85f2b
0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
SSDeep 12288:tcJkcAWoVBMRLuDHt9pH4jZ/6v5hLl4sk8rEvCV1MK
SK:gTr+OpuDH8N4Xw8AKfnSK
ImpHash ef471c0edf1877cd5a881a6a8bf647b9
MD5 has been an industry standard for a long time, but because of MD5
collisions, it is always better to get more hashes. ImpHash is a relatively new hash
that was created from the import table rather than the raw data of the file. ImpHash
is only for PE files.
3. Aside from hashes serving as unique identifiers, it will also allow you to look
for this sample in publicly available malware databases such as VirusTotal and even
look at publicly available sandboxes to see whether it has been analyzed already.
Remember that all the information you get helps you in analyzing malware,
especially if you are struggling.
4. Check the file type. Usually, when you get a sample, it is always assumed that
it is a PE file, but this is not always the case. Also, using the different file type
checkers in your arsenal such as PEiD and a Python script powered with Yara will
help you identify not only the file type but also whether the file is packed, encrypted,
or neither.
5. For this file, you will use the easiest way to determine the file type. You will
use GNU file command.
The output tells you that this file is UPX compressed. You will find out later if it
is indeed UPX compressed.
6. Get the strings present in the file. You can do this by using the GNU
command strings or SysInternals strings.exe in Windows. Here is a partial list of the
strings found in the file:
7. From the strings output, notice the following strings: UPX0, UPX1, UPX!,
and AutoIt. The first three are indicators that the file is packed by UPX, and the
fourth string indicates that there might be an AutoIt script embedded in the file,
which might be a second packer.
8. Investigate the file’s PE characteristics. You can do this using PEView. Figure
13-41 shows the file’s compile time. The compile time is found inside the PE
structure as a member called TimeDateStamp in the NT headers. The compile time
value should be taken into limited consideration because this value can be faked
easily.
Figure 13-41 PEView showing the compile time of the file.
9. Figure 13-42 shows the file’s machine value. The machine value is a member
in the NT headers structure, and it can have one of two values: 0x014C, which
indicates a 32-bit Windows PE file, or 0x8664, which indicates a 64-bit Windows PE
file.
Figure 13-42 PEView showing the file’s machine value.
10. Looking at the PEView windows, it is easy to notice one section name.
Sometimes the PE section name can give you some information about the file. In
this example, the PE section names that can be seen are UPX0, UPX1, and .rsrc, as
shown in Figure 13-43. UPX0 and UPX1 indicate that the file has been packed with
UPX. PEView is the third tool that confirms the file is packed with UPX. The first
two are the GNU file and strings command line.
Figure 13-43 PEView showing UPX section.
11. The section named .rsrc suggests that the file contains a resource section.
This is a good place to extract some useful information. For this purpose, you will
use Resource Hacker, which allows you to look at the resources embedded into the
binary, as shown in Figure 13-44. Notice the suspicious little resource SCRIPT that
is under RCDATA. This may be the AutoIt script in an encrypted format.
Figure 13-44 Resource Hacker view of .rsrc.
12. Get Imports/Exports information. A great tool for this specific purpose is
Dependency Walker. This tool shows all the libraries imported by the binary and
which functions are imported from each library (green) as well as all the exported
functions of each library and the binary, if any. Figure 13-45 shows this.
Figure 13-45 Dependency Walker.
13. Some of the information including the MD5 hash, strings, size, and compile
time can be collected using Malcode Analyst Pack. This also enables you to submit
the file to VirusTotal or simply run a query to check whether security products
already detect the file.
14. You can now proceed to dynamic analysis. You will be using a clean
malware analysis system that you built from previous labs. For this example, you
will be using a virtual machine.
15. Run Process Explorer, Process Monitor, and TCPView in the malware
analysis system (guest OS) or sandbox. Doing this will start their monitoring
functionality.
TIP
Having these tools run in clean systems makes you familiar with the output of
these tools in a clean system, which is good for baselining. Doing this will give
you experience spotting something out of the ordinary in case you are using these
tools to determine a possible infection and not for analyzing a specific malware
sample.
16. Run Wireshark in promiscuous mode on the host OS. Make sure you are
capturing communication traffic on the network adapter that the VM is connected to.
In this lab, the name of the interface is vmnet8.
17. Once everything is set, run the malware sample.
18. Watch closely and take notes on both TCPView’s and Process Explorer’s
windows. In Process Explorer, look for any new processes/children exiting and
dying. New sessions/processes are green, and those that are killed are red. In
TCPView, look for any network sessions being created and dropped. See Figures 13-
46, 13-47, and 13-48.
32. Regarding malicious activity, at first glance it might seem that the file C:\
Windows\directx.sys dropped by the malware is a driver and that the malware has
kernel mode capabilities, but this is not the case. The filename was carefully picked
in order for it to blend in with the rest of the files in that folder. If you look at the
contents of the file, you will see clear text separated by newline characters.
This file is where the malware keeps a list of currently running processes.
33. You may have noticed that most suspicious registry events were initiated by
a process named Explorer.EXE, which was running even before you ran the
malware on the machine and is actually a legitimate Windows process that is
responsible for Windows’ graphical user interface (GUI) environment. Also, you
may have noticed that some suspicious events happened more than once and were
sometimes initiated by a few different processes that are also legitimate and were
running before you infected the machine. The simple explanation for this is that this
malware is creating a thread that runs the malware inside all processes that are
already running on the machine. This process is called code injection or thread
injection. When malware is injecting itself into a process, it is doing it to hide its
process from showing when process listing occurs. This technique is usually utilized
by a user mode rootkit.
34. Aside from code injection, another technique that is commonly used by user
mode rootkits is hooking. User mode hooks are implemented in many creative ways;
the most common techniques are IAT modification and inline patching.
In IAT modification, the malware changes the IAT of each binary that is loaded by
the OS in memory and changes the imported libraries and functions to their own
malicious version of the same library containing the same functions with “extra
functionality.”
With inline patching, the malware will patch the code of the library in memory in
a way that prior to the execution of the function, it will jump to the malware’s code,
and after executing the malicious code, it will jump back to the original function and
continue with the original function’s execution flow.
Both methods will not be detected by checking whether any of the operating
system’s file integrity was compromised because the malware is doing all its work in
memory. As a result, no traces will be found in the original files in the file system.
NOTE
Hooking techniques such as IAT modification and inline patching are also used
by legitimate applications/programs; therefore, the existence of hooks does not
necessarily mean that the machine is infected with malware.
35. To check for hooks, you will scan the machine using Rootkit Unhooker. At
this point, you should resume the VM and run Rootkit Unhooker. To scan for user
mode hooks, go to the Code Hooks tab and click the Scan button. If there are code
hooks on the infected system, it should look like Figure 13-53.
Figure 13-53 Rootkit Unhooker output.
36. Save the output by going to the Report tab and clicking the Scan button.
Uncheck all boxes except Code Hooks and click OK. Once the report is done, copy
the text and save it to a file.
37. The complete output with the result is shown here:
38. From this output, you can definitely say that you are dealing with a user
mode rootkit. Also based on this output, this malware hooks functions in
wininet.DLL and ws2_32.dll, which are libraries that deal with network
communications and Hypertext Transfer Protocol (HTTP). By hooking functions in
these libraries, the malware may be able to tamper with network traffic and set up a
man-in-the-middle attack.
39. Next is dump analysis. This is done by taking a memory dump of the
malicious process. In this case, the malware injected itself into each one of the
running processes, with Explorer.EXE being the most significant. You will therefore
pick Explorer.EXE as your memory dump’s target. You can use either Process
Explorer or Rootkit Unhooker to take a memory dump.
40. Dump a process with Process Explorer. Right-click the target process, which
is Explorer.EXE, and go to Create Dump | Create Full Dump; then save the dump
file. You can name the file MEMORY.DMP. See Figure 13-54.
TIP
The output of strings is really huge; it’s always a good idea to redirect the
output to a file and review it with a text editor.
44. The following is the output from strings:
45. Grep for specific patterns such as http. You can do this together with strings
by using a pipe.
In this lab, you will perform a complete analysis of a kernel mode rootkit using the tools
discussed in this book. The sample used for this lab is Hacker Defender version 1.00.
What You Need:
Static analysis tools
Dynamic analysis tools
Sysinternals Suite
PE viewers
Network capturing tools
OSR driver loader
System running Windows
Rootkit malware
Steps:
1. You begin with basic dynamic analysis of the sample by running it in a virtual
environment malware analysis system and monitoring all processes, the registry, and
the file system by using the techniques discussed in Lab 13-7. Take note that the
username of the analysis system is Jean, so you will see this in the output of the tools
and some screenshots in this lab.
2. After infecting the VM, you monitor the following events in Process Monitor.
Here is the ProcMon output:
3. The following are some things that are noticeable in the dynamic analysis
session:
A file named hexdefdrv.sys was written in C:\Documents and Settings\
<User>\Desktop\hxdef100.
A service named HackerDefender100 was created by writing values to the
registry.
This tells you that the malware is possibly installed as a kernel mode driver on
the system, which is used to gain kernel rootkit capabilities.
4. Notice that all the files related to the malware have vanished. In Figure 13-56,
you can see that the listed directory in the File Explorer doesn’t actually exist on the
desktop.
Figure 13-56 File listing of hxdef100.
5. When you try to find the newly installed service in the Services snap-in by
going to Run, typing services.msc, and clicking Enter, you will not be able to find it
in the listing, as shown in Figure 13-57.
Figure 13-57 Running services in the local machine.
6. Another way to check the service status and parameters is through the
command line by running the following command:
7. In this case, you want to check about a service named HackerDefender100.
You know this through the output of Process Monitor.
8. The following output reveals that the service exists, but it is hidden from any
user mode application that tries to list the system’s services:
27. Add a second line under [operating systems]. The second line is the same as
the first line plus the parameters for debugging. The resulting Boot.INI file should
look like the following:
28. Pay attention to the /debugport=COM? and replace it with the right COM
port number for the serial port you added earlier to the debugged machine. In the
setup used to create this lab, it is COM2.
29. Reboot the debugee and use the second option in the BootLoader: Microsoft
Windows XP Professional With Kernel Debugging.
30. Once this is done, you can run WinDbg on the debugger machine. But
before you attach to the debugee, you need to configure the symbols in WinDbg.
31. Choose File | Symbol File Path or simply press CTRL+S. Set the search path to
SRV*<your_symbol_path>*http://msdl.microsoft.com/download/symbols. The
<your_symbol_path> should be replaced in your VM with the path to your symbols.
In the VM you used to make this lab, it is C:\ WebSymbols.
32. Attach to the debuggee. Choose File | Kernel Debug or simply press CTRL+K.
33. Set the baud rate to 115200 and set the COM port to the same port number
as configured for the debugger machine, as shown in Figure 13-63. Then click OK.
You are now ready to do some kernel debugging.
49. Among the list of modules produced, you can see your suspicious hxdefdrv.
sys module, which is loaded in the address 0xBAFA300. Take note that this address
might be different in your own experiment.
50. Now you can dump all of the loaded modules along with your malicious
driver by running the following command, as shown in Figure 13-69:
51. You should now have a directory full of .sys files in this format: driver.
<address>.sys.
52. Since your driver was loaded in 0xBAFA3000, you should look for driver.
bafa3000.sys.
NOTE
Another thing that can be interesting is checking for any SSDT hooks by
running vol.py ssdt –f <.vmem_path>. You did not do it for this lab because this
specific malware is not using SSDT hooking.
53. Now you can take the dumped file and feed it in IDA for analysis.
54. Once it is loaded in IDA, you should land on DriverEntry, as shown in
Figure 13-70.
Automated Sandboxes
In previous chapters, I discussed how to build your own malware analysis system. In this
section, you will delve more into making an automated malware analysis system.
There are lots of automated sandboxes available. Some of them are software based, and
some are hardware based. Some are free, while some cost a lot of money.
When it comes to open source automated sandboxes, my personal favorite is Cuckoo. It
is completely open source, which means that aside from looking at its internals, you can
modify and customize it as you want. Plus, you can use the skills you have learned in
previous chapters to create the guest OS that will run the malware.
When Cuckoo processes a binary, it produces the following output:4
Native functions and Windows API call traces
Copies of files created and deleted from the file system
Dump of the memory of the selected process
Full memory dump of the analysis machine
Screenshots of the desktop during the execution of the malware analysis
Network dump generated by the machine used for analysis
These outputs can be presented in the following formats to make it more consumable to
end users:
JavaScript Object Notation (JSON) report
Hypertext Markup Language (HTML) report
Malware Attribute Enumeration and Characterization (MAEC) report
MongoDB interface
HPFeeds interface
You can learn more about Cuckoo at http://www.cuckoosandbox.org/.
In this lab, you will install and configure Cuckoo 1.1 on a host running Ubuntu 14.04
LTS. It will also explain the process of installing a Cuckoo agent on a guest virtual
machine running Windows XP with Service Pack 3.
This lab is divided into the following major steps:
1. Preparing the host
2. Installing Cuckoo
3. Preparing the guest
4. Installing the agent
5. Configuring Cuckoo
6. Running Cuckoo
What You Need:
System running Ubuntu 14.04
Windows XP with SP3 virtual machine (you will be using VirtualBox as your
virtualization software)
Steps:
1. Prepare the host.
A. Install Python on your Ubuntu machine. This is necessary because all the
components of Cuckoo are written in Python.
H. If you encounter an error while building pydeep, make sure to install the
necessary libraries for python-dev using the following command:
I. A network sniffer such as tcpdump is necessary to capture the network
traffic while malware is running.
2. Install Cuckoo.
A. Start by creating a new user dedicated to your sandbox. Make sure to add
the new user to the group of users running VirtualBox. In this lab, you will make
the user cuckoo and the group vboxusers.
B. Add the new user to the list of sudoers on the host. The visudo tool lets
you edit the /etc/sudoers file.
C. Once the sudoers file is opened, add the following line at the end:
B. Copy the agent.py file to the Startup folder on your guest VM. On a
Windows XP machine, the location of the Startup folder is typically at
C:\Documents and Settings\<user>\Start Menu\Programs\Startup. This will
ensure that the agent is launched every time the guest VM is booted. When you
execute the file, it spawns a Python window informing you that the agent started
on the guest VM, as shown in Figure 13-80.
If you do not plan on using the default SQLite DBMS, you need to specify the
connection string to your database in cuckoo.conf. For example, if you have MySQL
installed on your host, your string will look like this:
where:
cuckooDB is the database name.
cuckoo is a user who has full privileges on cuckooDB.
{pass} is the password for the previous user.
Here is auxillary.conf:
Here is virtualbox.conf:
WinXP is the name given to the guest VM, and 192.168.56.2 is its static IP
address.
Here is reporting.conf:
This is important for the web interface to be able to pull data from the Mongo
database.
C. As for the rest of the configuration files, there are no changes necessary.
6. Run Cuckoo.
A. Start Cuckoo by navigating to its directory on the host machine and
running the following command:
B. You can submit a file for analysis using the following command line:
C. The submission Python script has many options. Please refer to the
Cuckoo documentation to get more information on the usage of the submission
tool.
D. For every file analyzed by the sandbox, Cuckoo assigns a task ID to it.
Analysis reports are saved in cuckoo/storage/analysis. Use the task ID to find
the corresponding subdirectory of the analysis files.
E. You can also submit samples using the web interface. First you will need
to start the web server.
Recap
In this chapter, I discussed the common malware analysis use cases and how they should
determine what goes inside a malware analyst’s toolbox.
I also noted that regardless of the use case a malware analyst is trying to satisfy, there
are tools that are considered indispensable when it comes to malware analysis. I call them
tools of the trade. They are as follows:
Sysinternals Suite
Yara
Cygwin
Debuggers
Disassemblers
Memory dumpers
PE viewers
PE reconstructors
Malcode Analyst Pack
Rootkit tools
Network capturing tools
Automated sandboxes
Free online automated sandbox services
Combining these tools the right way gives analysts and researchers a potent weapon in
tackling the most difficult malware. In this chapter, you combined these tools to solve the
most challenging use cases analysts and researchers always face. They are as follows:
Manually unpacking a packed malware
Analyzing a user mode rootkit
Analyzing a kernel mode rootkit
It is important to note that there are more tools out there; the main thing is to find a tool
that you are comfortable with and that satisfies your use cases.
Tools
Sysinternals Suite https://technet.microsoft.com/en-
us/sysinternals/bb842062.aspx
Yara https://github.com/plusvic/yara
Cygwin https://www.cygwin.com
Debuggers
OllyDbg http://www.ollydbg.de/
Immunity Debugger http://debugger.immunityinc.com/
Windows debuggers
WinDbg https://msdn.microsoft.com/en-
us/windows/hardware/hh852365.aspx.
KD and NTKD https://msdn.microsoft.com/en-
us/library/windows/hardware/hh406279%28v=vs.85%29.aspx
Disassembler
IDA https://www.hex-rays.com/products/ida/support/download.shtml
Memory dumpers
LordPE by
y0da http://www.woodmann.com/collaborative/tools/index.php/LordPE
Volatility
Framework https://code.google.com/p/volatility/wiki/VolatilityIntroduction
PE viewers
Hiew http://www.hiew.ru/
Heaventools PE Explorer http://www.heaventools.com/overview.htm
PEview http://wjradburn.com/software/
Dependency Walker http://www.dependencywalker.com/
Resource Hacker http://www.angusj.com/resourcehacker/
PE reconstructors
ImpREC by
MackT http://www.woodmann.com/collaborative/tools/index.php/ImpREC
Malcode Analyst
Pack http://www.woodmann.com/collaborative/tools/index.php/Malcode_Analysis_Pack
Rootkit tools
Rootkit Unhooker http://www.antirootkit.com/software/RootKit-
Unhooker.htm
Rootkit Revealer http://download.cnet.com/RootkitRevealer/3000-
2248_4-10543918.html
Network capturing tools
Wireshark https://www.wireshark.org/
TCPDump http://www.tcpdump.org/
TCPView https://technet.microsoft.com/en-
us/sysinternals/bb897437.aspx
OSR driver loader http://www.osronline.com/article.cfm?article=157
Automated sandboxes
Cuckoo http://www.cuckoosandbox.org/
Free online automated sandbox services
Anubis http://anubis.iseclab.org/
Comodo Instant Malware Analysis http://camas.comodo.com/
Comodo Valkyrie http://valkyrie.comodo.com/
EUREKA Malware Analysis Internet Service http://eureka.cyber-
ta.org/
Malwr https://malwr.com/submission/
MalwareViz https://www.malwareviz.com/
Payload Security https://www.hybrid-analysis.com/
ThreatExpert http://www.threatexpert.com/submit.aspx
ThreatTrack Public Malware
Sandbox http://www.threattracksecurity.com/resources/sandbox-malware-
analysis.aspx
VICheck https://www.vicheck.ca/
1 Yara: https://plusvic.github.io/yara/.
2
Cygwin: https://www.cygwin.com/.
3
Microsoft Technet: http://technet.microsoft.com/en-US/.
4 Cuckoo Sandbox: http://www.cuckoosandbox.org/.
PART
IV
Appendixes
APPENDIX
A
Tools List
This appendix lists all the tools discussed throughout the book.
Free online antivirus scanners
Trend Micro’s HouseCall http://housecall.trendmicro.com/
F-Secure Online Scanner http://www.f-
secure.com/en/web/home_global/online-scanner
Free malware removal tools
Microsoft Security Essentials http://windows.microsoft.com/en-
us/windows/security-essentials-download
Comodo Cleaning Essentials http://www.comodo.com/business-
security/network-protection/cleaning_essentials.php
Kaspersky Security Scan http://www.kaspersky.com/free-virus-scan
Rootkit detectors
Rootkit Revealer by
Microsoft http://download.cnet.com/RootkitRevealer/3000-2248_4-
10543918.html
TDSSKiller by
Kaspersky https://support.kaspersky.com/us/viruses/utility#TDSSKiller
Startup examination tools
Autoruns by Microsoft http://technet.microsoft.com/en-
us/sysinternals/bb963902.aspx
Autorun Analyzer by Comodo http://www.comodo.com/business-
security/network-protection/cleaning_essentials.php
Boot analyzer tools
Gmer’s MBR.EXE http://www.gmer.net
MbrScan http://eric71.geekstogo.com/tools/MbrScan.exe
MBR Backup http://www.trojanhunter.com/products/mbr-backup/
Boot Sector Explorer http://www.pendriveapps.com/boot-sector-
explorer-backup-and-restore-mbr/
Nate’s MBR and Boot Sector Analyzer http://www.aqfire.com/boot/
WinHex, MBR/boot sector editor http://www.winhex.com/disk-
editor.html
Process examination tools
Process Explorer by Microsoft http://technet.microsoft.com/en-
us/sysinternals/bb896653.aspx
KillSwitch by Comodo http://www.comodo.com/business-
security/network-protection/cleaning_essentials.php
Honeypots
Dionaea http://dionaea.carnivore.it
Windows 7 USB/DVD Download
Tool http://images2.store.microsoft.com/prod/clustera/framework/w7udt/1.0/en-
us/Windows7-USB-DVD-tool.exe
Secunia Online Software
Inspector http://secunia.com/vulnerability_scanning/online/
Firefox add-ons and plug-ins
NoScript
Better Privacy
RequestPolicy
Web of Trust (WOT)
Adblock Plus
Proxy servers
Hide My Ass! http://hidemyass.com/proxy/
Proxy 4 Free http://www.proxy4free.com
Samair.RU http://www.samair.ru/proxy/
Public proxy
servers http://www.publicproxyservers.com/proxy/list1.html
Virtual private network services
Private Tunnel https://www.privatetunnel.com
VPNBook http://www.vpnbook.com
JustFreeVPN http://www.justfreevpn.com
VPNAccount http://www.vpnaccount.org
L2TP VPN Service http://www.freel2tpvpn.com
OkayFreedom VPN https://www.okayfreedom.com
VPNAccess http://freevpnaccess.com
Hotspot Shield Ad Supported http://www.hotspotshield.com
CyberGhost http://cyberghostvpn.com
Free UK & US VPN http://www.ukusvpn.com
Free VPN for UK http://www.vpnforuk.com
Premium VPN with Public IP http://www.truvpn.com
Free ProXPN http://proxpn.com
Online anonymizers
Anonymouse http://anonymouse.org/anonwww.html
Free Web Proxy http://www.vpnbook.com/webproxy
Online Anonymizer http://online-anonymizer.com
Hide My Ass! Web Proxy http://hidemyass.com/proxy/
KProxy https://www.kproxy.com
Megaproxy http://www.megaproxy.com/freesurf/
Tor, the onion
router https://www.torproject.org/docs/documentation.html.en
VMware Player http://www.vmware.com/go/downloadplayer
VirtualBox https://www.virtualbox.org/wiki/Downloads
Clonezilla http://clonezilla.org/downloads.php
Virtualization software
VMware Player http://www.vmware.com/go/downloadplayer
VirtualBox https://www.virtualbox.org/wiki/Downloads
VirtualPC http://www.microsoft.com/en-US/download/details.aspx?
id=3702
Trusted Adobe download sites
Adobe Reader http://get.adobe.com/reader
Adobe Flash Player http://get.adobe.com/flashplayer
Deep Freeze Standard by Faronics http://www.faronics.com/products/deep-
freeze/standard/
Clonezilla http://clonezilla.org/download.php
Tuxboot http://sourceforge.net/projects/tuxboot/files/
Dependency Walker http://www.dependencywalker.com
pefile https://code.google.com/p/pefile/
pedump https://github.com/zed-0xff/pedump
pedump online PE file submission http://pedump.me/
Compression tools
WinZip http://www.winzip.com
WinRAR http://www.rarlab.com
7zip http://www.7-zip.org
p7zip http://p7zip.sourceforge.net/
GnuPG http://www.gnupg.org
MD5SUM http://www.etree.org/md5com.html
Microsoft File Checksum Integrity Verifier http://www.microsoft.com/en-
us/download/details.aspx?id=11533
PEiD http://woodmann.com/BobSoft/Pages/Programs/PEiD
ClamAV http://www.clamav.net
Sample submission online services
F-Secure Sample Analysis http://www.f-
secure.com/en/web/labs_global/submit-samples/sas
Sophos https://secure2.sophos.com/en-us/support/contact-
support/sample-submission.aspx
Malware scanning services
VirusTotal by Google https://www.virustotal.com
VirSCAN http://www.virscan.org
Metascan by OPSWAT https://www.metascan-online.com
Jotti http://virusscan.jotti.org
Dr. Web http://www.drweb-online.com/en/online_check.asp
Fortiguard Online Virus
Scanner http://www.fortiguard.com/antivirus/virus_scanner.html
Packers
Armadillo http://www.siliconrealms.com/armadillo.php
ASPack http://www.aspack.com/aspack.html
ASProtect32 http://www.aspack.com/asprotect32.html
ASProtect64 http://www.aspack.com/asprotect64.html
PECompact http://bitsum.com/pecompact/
UPX http://upx.sourceforge.net/
PE Explorer http://www.heaventools.com/overview.htm
Packers and unpackers http://www.woodmann.com/crackz/Packers.htm
Sysinternals Strings.EXE http://technet.microsoft.com/en-
us/sysinternals/bb897439
Sysinternals Suite https://technet.microsoft.com/en-
us/sysinternals/bb842062.aspx
System monitoring tools
InstallRite http://www.softpedia.com/get/System/System-
Info/InstallRite.shtml
Uninstall Tool http://www.crystalidea.com/uninstall-tool
Memory analysis tools
Process Explorer https://technet.microsoft.com/en-
us/sysinternals/bb896653
Autoruns https://technet.microsoft.com/en-
us/sysinternals/bb963902.aspx
Network analysis tools
TCPView https://technet.microsoft.com/en-
us/sysinternals/bb897437.aspx
Wireshark https://www.wireshark.org/
Yara https://github.com/plusvic/yara
Cygwin https://www.cygwin.com
Debuggers
OllyDbg http://www.ollydbg.de/
Immunity Debugger http://debugger.immunityinc.com/
Windows debuggers
WinDbg https://msdn.microsoft.com/en-
us/windows/hardware/hh852365.aspx.
KD and NTKD https://msdn.microsoft.com/en-
us/library/windows/hardware/hh406279%28v=vs.85%29.aspx
Disassembler
IDA https://www.hex-rays.com/products/ida/support/download.shtml
Memory dumpers
LordPE by
y0da http://www.woodmann.com/collaborative/tools/index.php/LordPE
Volatility
Framework https://code.google.com/p/volatility/wiki/VolatilityIntroduction
PE viewers
Hiew http://www.hiew.ru/
Heaventools PE Explorer http://www.heaventools.com/overview.htm
PEview http://wjradburn.com/software/
Dependency Walker http://www.dependencywalker.com/
Resource Hacker http://www.angusj.com/resourcehacker/
PE reconstructors
ImpREC by
MackT http://www.woodmann.com/collaborative/tools/index.php/ImpREC
Malcode Analyst
Pack http://www.woodmann.com/collaborative/tools/index.php/Malcode_Analysis_Pack
Rootkit tools
Rootkit
Unhooker http://www.antirootkit.com/software/RootKitUnhooker.htm
Rootkit Revealer http://download.cnet.com/RootkitRevealer/3000-
2248_4-10543918.html
Network capturing tools
Wireshark https://www.wireshark.org/
TCPDump http://www.tcpdump.org/
TCPView https://technet.microsoft.com/en-
us/sysinternals/bb897437.aspx
OSR driver loader http://www.osronline.com/article.cfm?article=157
Automated sandboxes
Cuckoo http://www.cuckoosandbox.org/
Free online automated sandbox services
Anubis http://anubis.iseclab.org/
Comodo Instant Malware Analysis http://camas.comodo.com/
Comodo Valkyrie http://valkyrie.comodo.com/
EUREKA Malware Analysis Internet Service http://eureka.cyber-
ta.org/
Malwr https://malwr.com/submission/
MalwareViz https://www.malwareviz.com/
Payload Security https://www.hybrid-analysis.com/
ThreatExpert http://www.threatexpert.com/submit.aspx
ThreatTrack Public Malware
Sandbox http://www.threattracksecurity.com/resources/sandbox-malware-
analysis.aspx
VICheck https://www.vicheck.ca/
APPENDIX
B
List of Laboratories
T hroughout the book, there are labs that are designed to help you in your quest to
analyze malware. This appendix lists all the laboratories contained in the book.
LAB 6-1: Installing Dionaea
LAB 7-1: Extracting and Copying Drivers to the Windows 7 Installation Media
LAB 7-2: Creating a Bootable USB Stick Windows 7 Installer
LAB 7-3: Creating a Bootable USB Stick Windows 7 Installer Using the Windows 7
USB/DVD Download Tool
LAB 7-4: Protecting Firefox Using Built-in Options
LAB 7-5: Protecting Firefox Using Add-ons and Plug-ins
LAB 7-6: Creating a Virtualized Ubuntu Desktop Using VMware Player
LAB 7-7: Creating a Virtualized Ubuntu Desktop Using VirtualBox
LAB 8-1: Installing VMware Player in Ubuntu
LAB 8-2: Uninstalling VMware Player in Ubuntu
LAB 8-3: Installing VirtualBox in Ubuntu
LAB 8-4: Uninstalling VirtualBox in Ubuntu
LAB 8-5: Disabling Automatic Updates in Windows 7
LAB 8-6: Disabling User Account Control in Windows 7
LAB 8-7: Making Internet Explorer Malware Friendly
LAB 8-8: Making Mozilla Firefox Malware Friendly
LAB 8-9: Making Google Chrome Malware Friendly
LAB 8-10: Making Microsoft Office Malware Friendly
LAB 8-11: Making Adobe Reader Malware Friendly
LAB 8-12: Setting a Non-persistent Image in VirtualBox
LAB 8-13: Setting a Non-persistent Image in VirtualBox Using the Command Line
LAB 8-14: Creating a Non-persistent Bare-Metal System Using Deep Freeze
Standard
LAB 8-15: Creating a Clonezilla Live in USB Flash Drive
LAB 8-16: Backing Up a Partition Using Clonezilla Live
LAB 8-17: Restoring a Partition Using Clonezilla Live
LAB 9-1: Using Dependency Walker to Determine a PE File’s Dependencies
LAB 9-2: Installing pefile in Ubuntu
LAB 9-3: Using a Python Script to Display PE Header Information
LAB 9-4: Installing and Utilizing pedump
LAB 9-5: Using a Python Script to Display PE Section Information
LAB 9-6: Using a Python Script to Display PE Import Information
LAB 9-7: Using a Python Script to Display PE Export Information
LAB 9-8: Using a Python Script to Display All PE Information
LAB 10-1: Installing and Using p7zip
LAB 10-2: Creating a Private and Public Key Pair
LAB 10-3: Setting the Key as the Default
LAB 10-4: Uploading Your Key to Ubuntu Keyserver
LAB 10-5: Backing Up and Restoring Your Key Pair
LAB 10-6: Revoking a Key Pair
LAB 10-7: Unrevoking a Key Pair
LAB 10-8: Changing the Expiration Date of a Key Pair
LAB 10-9: Encrypting and Decrypting a File Using GnuPG
LAB 10-10: Encrypting a File with the Public Key of the Intended Recipient
LAB 10-11: Signing a File
LAB 11-1: Using a Python Script to Compute MD5 and SHA-1
LAB 11-2: Using PEiD
LAB 11-3: Using a Python Script That Identifies File Type
LAB 11-4: Getting Started with the VirusTotal Public API
LAB 11-5: Using ClamAV for File Scanning
LAB 11-6: Using ClamTK for File Scanning
LAB 11-7: Writing a Signature for ClamAV
LAB 11-8: Packing a File Using UPX
LAB 11-9: Using a Python Script to Identify Packed Binaries
LAB 11-10: Extracting Strings from Files (Ubuntu)
LAB 11-11: Extracting Strings from Files (Windows)
LAB 12-1: Detecting System Changes Using InstallRite
LAB 12-2: Detecting System Changes Using Uninstall Tool
LAB 12-3: Analyzing Running Processes in Memory Using Process Explorer
LAB 12-4: Quickly Inspecting Whether a Process Is Persistent
LAB 12-5: Analyzing Network Behavior Using TCPView
LAB 12-6: Analyzing Network Behavior Using Wireshark
LAB 13-1: Installing Yara
LAB 13-2: Creating a Yara Rule
LAB 13-3: Installing Yara Support for Python
LAB 13-4: Using a Python Script That Utilizes Yara Rules
LAB 13-5: Installing Cygwin
LAB 13-6: Manually Unpacking a Packed Malware
LAB 13-7: Analyzing a User Mode Rootkit
LAB 13-8: Analyzing a Kernel Mode Rootkit
LAB 13-9: Installing and Configuring Cuckoo
APPENDIX
C
Volatility Framework
This appendix lists basic plug-ins for the Volatility framework.
Index
Please note that index links point to page beginnings from the print edition. Locations are
approximate in e-readers, and you may need to page down one or more times after
clicking a link to get to the indexed material.
Numbers
0x55AA setting, end-of-sector markers, 36–37
7zip, 272–274, 295
64-bit format, PE file, 267
A
access
hardening static analysis lab, 171–172
protecting transferred files, 271–272
user dependency attacks on, 101–105
active rootkits, detecting, 113–114
ActiveX control (OCS) files, implemented as DLLs, 234
ActiveX settings, Microsoft Office, 211
Adblock Plus add-on, Firefox, 171
ADD EAX/3, Immunity Debugger, 393, 396
ADD EAX/3/JMP EAX, Immunity Debugger, 394, 397
added files, monitoring file system for, 323–325
add-ons, Firefox, 170–171, 185
admin access, hardening static analysis lab for, 172
Adobe
Flash Player, 209, 227
Flash Reader, 209, 212–213, 227
trusted download sites, 227
ad-supported software, 46
adware, 46
anonymizing
all malware research labs, 150–151
dynamic analysis labs, 214
with online anonymizers, 176–177
with proxy servers, 173–174
static analysis labs, 172–173
with Tor, 177
with VPNs, 174–177
Anonymouse, 176–177, 185
anti-AV scanning, dynamic malware, 83–84
anti-debugging, dynamic malware, 80
anti-decompilers, static malware, 79
anti-disassemblers, static malware, 79
anti-reversing, 78–79
anti-sandboxing, dynamic malware, 80–82
anti-virtualization, 82
antivirus definitions, 10
antivirus detection, static analysis, 306–308
antivirus scanners
detecting malware code snippets, 9–10
dynamic malware protection, 83–84
early solutions, 325
entry-point obscuring from, 72–74
fake, 43, 45
malware collection with, 112, 145
malware disabling, 94–95
as static analysis lab tool, 149–150
Anubis, 481
appending parasitic viruses, 34
application control, software vulnerabilities, 61
apt-get command-line tool, Unbuntu, 165
Armadillo, 310, 316
ASPack, 310, 316
ASProtect32, 311, 316
ASProtect64, 311, 316
asymmetric cryptography. See public-key cryptography
attack component, monitoring file system, 324
attributes, hiding malware via, 322
AUTOEXEC.BAT, malware modifying, 326
automated malware analysis
event dependency challenges, 100
overview of, 15–20
weeding out non-supported file formats, 94
automated sandboxes
automated malware analysis via, 17–20
configuring Cuckoo, 477–479
Cuckoo website, 484
free online services, 480–482
installing Cuckoo, 472–477
output formats of Cuckoo, 469–470
overview of, 17–20, 469
running Cuckoo, 479–480
setting up Cuckoo, 470–471
Automatic Updates
disabling for Cuckoo installation, 474
disabling in Windows 7, 198–199
Autorun Analyzer by Comodo, 114–115, 117, 146
Autoruns by Microsoft
inspecting for persistent process, 344–347
as memory analysis tool, 354
as startup examination tool, 114–115
website, 146
autostart techniques
malware persistency using, 321
registry keys used by malware, 326
auxillary.conf, Cuckoo, 477–478
availability, and file storage, 294–295
B
backdoors, 40
backups
dynamic analysis lab, 218–225
key pairs, 278–280
static analysis lab, 182–183
bare-metal environment
dynamic analysis in virtual vs., 318
for dynamic analysis labs, 188–189, 197, 217–219
malware test environment in, 94–96
Better Privacy add-on, Firefox, 170
binders, 28
blacklists
domain fluxing protecting malware from, 85–86
Malware Blacklist, 124–128
blackmail of employees, using PPI, 103–104
blue screen of death (BSOD) joke program, 45–46
boot analyzer tools, 116–117, 146
boot execution, registry keys used by malware, 326
boot sector
Boot Sector Explorer, 116, 146
BootSect.EXE, 158, 160
multipartite viruses, 36–37
viruses, 36
BOOT.INI file, booting Windows in Debug mode, 456–459
bot agent, monitoring file system, 324
botnets, using event triggers, 100
breaking a malware, 71
breakpoint, Immunity Debugger, 382–384
browser extensions, and registry keys, 326
BSOD (blue screen of death) joke program, 45–46
BSON packages, installing Cuckoo, 471
.bss section, PE files, 257
buffer overflows, 62–64
bugs, software flaws vs., 61
C
C&C (command-and-control)
abusing legitimate services in, 86–87
anonymizing dynamic analysis lab, 214
domain fluxing in, 85–86
IP fluxing in, 85–86
malware communication to, 84–85
C2. See C&C (command-and-control)
Calc.EXE, 237, 238
CALL EAX instruction, Immunity Debugger, 378, 380
CALL instruction, Immunity Debugger, 376–377
CALL to OutputDebugStringA, Immunity Debugger, 394–398
CCE (Comodo Cleaning Essentials)
opening AutoRuns from, 115
scanning for malicious files, 112
website, 146
CD/DVD drives, Windows installation issues, 153–162, 197
Characteristics field, IMAGE_SECTION_HEADER, 250–254
chats, 57–58, 98
checksum
early antivirus solutions using, 325
ensuring data integrity, 294
CIA (confidentiality, integrity, and availability) triad, file storage, 291–295
ClamAV, 307–309, 316
ClamTK, 308–309
classes. See malware classes
clean state restoration, dynamic analysis lab, 215–218
clean tools, remediating malware infection, 11
Clonezilla
backing up and restoring systems, 220–225
backing up/restoring static analysis lab, 183
website, 227
Clonezilla Live
backing up partition, 223–224
creating in USB flash drive, 220–222
defined, 220
restoring partition, 224–225
Clonezilla SE (server edition), 220
CnC. See C&C (command-and-control)
code analysis, Immunity Debugger
Analyze Code menu option, 385–386, 388
Immunity Debugger, 398, 400
code injection, analyzing user mode rootkit, 430
code patching, entry-point obscuring via, 73–74
code reuse, DLL advantages for, 233
code snippets, malware, 9–10
COM files, 30, 32–33
commercial sources, malware collection from, 138–139
communications, malware, 84–87
Comodo Cleaning Essentials. See CCE (Comodo Cleaning Essentials)
Comodo Instant Malware Analysis, 481
Comodo Valkyrie, 481
companion virus infections, 31–32
compression
encrypting file with public key, 287
for password-protected compressed files, 272–274
computer viruses
as first infectors, 28–30
mainly infecting physical media, 50–51, 55–56
conditional breakpoint, Immunity Debugger, 382–383
conference badge scanning, 104–105
Conficker worm
checking for system infection, 98
Open Malware results on, 131
time trigger, 98
utilizing DGA, 86
confidentiality, file
ensuring, 288–290
password-protection for. See password-protected compressed files
storage and, 291–292
configuration files
deleted by malware, 325
monitoring file system for, 324
Contagio, 120–122
context menu, Windows 7 installer, 158, 160
Control Panel (CPL) files, implemented as DLLs, 234
coverage, of malware infection vectors, 53
CPL (Control Panel) files, implemented as DLLs, 234
CRC (cyclic redundancy check), 325
cross-platform macro viruses, 35
.CRT section, PE file, 257
crypters, encrypting malware code, 310
CryptoLocker, 325
CryptoWall, 325
Cuckoo
configuring, 477–479
installing, 472–477
output formats of, 469–470
overview of, 469
running, 479–480
setting up, 470–471
cuckoo.conf, Cuckoo, 477–478
customer information, marketing/sales attacks for, 104–105
CyberGhost, 175, 185
cyclic redundancy check (CRC), 325
Cygwin, 364–367
D
data
advanced malware research, 11
detecting malware infection, 9–10
extracting from malware, 4
ransomware as encryption/destruction of, 42–43
replicating for data integrity, 294
Data Execution Prevention (DEP), 211
.data section, PE file, 257
DCC (direct client-to-client) file transfer requests, IRC worms, 39
.debug section, PE file, 259
debuggers
anti-debugging of dynamic malware, 80
debugging kernel mode rootkit, 453–469
Immunity Debugger. See Immunity Debugger
OllyDbg, 368, 483
overview of, 367–368
using disassemblers with, 369
Windows, 368–369, 483
decompilers, 5, 79
decoupled infection vectors, 55, 58–59
decrypters, 310
decrypting files
in private key signing, 289
using GnuPG, 286
Deep Freeze Standard by Faronics, 217–218, 227
default key, in public-key cryptography, 277
deleted files, monitoring file system for, 325
DEP (Data Execution Prevention), 211
dependencies
determining PE file, 234–236
dynamic analysis limitations, 12
environment, 92–96
event, 99–100
file, 105–106
installing for Cuckoo, 471
overview of, 90–91
program, 96–98
recap of, 106
timing, 98–99
user, 100–105
Dependency Walker
analyzing user mode rootkit, 412, 415
determining DLL dependencies of PE file, 234–236
as PE viewer, 371, 483
website, 268
deployment
DLL advantages for, 233
of infection vectors. See infection vectors
desktop hardware
dynamic analysis lab, 189–190
static analysis lab, 151–152
desktop recorders, 42
destructive functionality, of information stealers, 106
device driver (DRV) files, implemented as DLLs, 234
device driver error, Windows OS installation, 153–155
DGA (domain generation algorithm), in domain fluxing, 85–86
DHCP (Dynamic Host Control Protocol) server, dynamic analysis lab, 220
digital fraud, 43–44
Dionea, 146
direct client-to-client (DCC) file transfer requests, IRC worms, 39
direct infection, 29
directive, identifying malware, 322–323
disassemblers
debugging using, 80
decompilers vs., 5
IDA, 483
protecting static malware with anti-disassemblers, 79
as tools of the trade, 369
diskpart command, 157–159
DLL (dynamic link library)
advantages of, 233–234
Cygwin as, 364–367
determining dependencies of malware, 234–235
OCS, CPL and DRV files implemented as, 234
PE import functions in, 260–263
.DLL file extension, PE files, 233–234
documents, chosen by information stealers, 105–106
domain fluxing, 85–86
domain generation algorithm (DGA), in domain fluxing, 85–86
domains
malware communication via, 84–85
network behavior protection, 85–87
protecting Web browser from malicious, 167–171
dormancy, with timing dependency, 99
DOS DMZ header, PE file format, 235–237
DOS stub, PE file format, 237–238
downloader, deploying malware via, 319–321
Dr. Web, 306, 316
drive-by download site, 58
DriverEntry, 461–462
drivers
analyzing kernel mode rootkit on, 447, 449–453, 461–469
registry keys used by malware, 326
Windows installation issues, 153–162
droppers, deploying malware via, 319–321
DRV (device driver) files, implemented as DLLs, 234
dummy social media accounts, 213–214
dynamic analysis
analyzing user mode rootkit, 413–436
automated malware analysis via, 17–20
complemented by static analysis, 17
environment lock defeating, 83
lab, 7
limitations of, 12, 352
overview of, 7–8
process, 13–14
tools, 7
dynamic analysis lab
backup and restore, 218–225
hardware for, 189–190
image, 190
installing OS, 191–197
isolating, 214–215
overview of, 188–189
recap of, 226
restore to clean state, 215–218
tools, 226–227
dynamic analysis lab, malware friendly
anonymizing, 214
dummy social media accounts, 213–214
enticing files, 213
installing commonly exploited software, 208–213
Internet browser, 201–208
overview of, 198–201
Dynamic Host Control Protocol (DHCP) server, dynamic analysis lab, 220
dynamic link library. See DLL (dynamic link library)
dynamic malware
defined, 69
as malware in motion, 4
overview of, 69–70
dynamic malware, inspecting
analyzing host behavior, 319–347
analyzing network behavior, 348–352
limitations of, 352
recap of, 353
tools, 353–354
virtual vs. bare metal, 318
dynamic malware, protective mechanisms
anti-AV scanning, 83–84
anti-debugging, 80
anti-sandboxing, 80–82
environment lock, 83
network behavior protection, 84–87
overview of, 79
recap of, 88
E
.edata section, PE file, 258, 263–267
eight characters, section names of executable files, 250
e-mail
as common infection vector, 9, 56–57
coverage of infection via, 53
decoupled infection vectors via, 55
infection-vector-hosting infection vectors via, 60
malware at rest using, 69
malware collection from, 111
phishing attacks on executives/senior management, 102
program dependency of mass mailers, 96–98
speed of infection via, 51–52
spoofing addresses in marketing and sales, 104
encrypted malware
as anti-reversing technology, 79
defined, 12
during execution, 74–76
limitations of static analysis, 12
polymorphic, 76–77
as protective mechanism, 310
encryption
of file using GnuPG, 286
of file with public key of intended recipient, 286–287
online anonymity using VPNs, 174–177
encryption/decryption engine, 74–77
end user license agreement (EULA), spyware, 47
end-of-sector marker, boot sector, 36–37
enticing files, dynamic analysis lab, 213
environment dependencies, of malware, 92–96
environment lock, protecting dynamic malware, 83
EPO (entry-point obscuring), malware
overview of, 72–74
as protective mechanism, 84
slowing down reversing, 79
EULA (end user license agreement), spyware, 47
EUREKA Malware Analysis Internet Service, 481
evasion technologies, 70
event dependencies, 99–100
event triggers, malware, 99–100
.EXE file extension
as common file extension of PE files, 233–234
as executable files, 30–34
executable files
dynamic analysis using, 289
as file infectors, 30–34
executable state, transferring files when not in, 271
executives, user dependency attacks on, 101–102
expiration date, changing key pair, 284–285
exploits, vulnerabilities vs., 62
Explorer.EXE
injected malware in, 430, 443
registry keys used by malware, 326
export forwarding, PE files, 265–266
export functions, PE files, 263–267
external hard drives, for static analysis lab, 152
extortion operation, malware, 325
F
fake antivirus (AV) programs, 43, 45
fakeware, 44–45
false alarms/negatives/positives, 10
familiarization with malware, malware analyst, 21–22
fast (IP) fluxing, 86
Febipos, Trojan, 97
file dependencies, 105–106
file formats
malware operating system dependency and, 93–94
Portable Executable. See PE (Portable Executable) file format
file handling
analysis, 290
analysis life cycle, 270
overview of, 270
recap of, 295
storage, 290–295
tools, 295
transfer. See file transfer
file infectors
executables, 30–34
macros, 34–35
malware encryption used by, 75–76
as multipartite virus component, 36–37
overview of, 29–30
scripts, 35–36
file inspection tools, static analysis lab, 148
file offset, 259
file scanners, 9–10
file sharing
as infection vector, 61
malware using, 98
worms and, 38
file system, monitoring for dynamic malware, 323–326
file transfer
backing up/restoring key pair, 278–280
changing expiration date of key pair, 284–285
creating private/public key pair, 275–276
downloading/installing p7zip, 272–274
encrypting file with public key of intended recipient, 286–287
encrypting/decrypting using GnuPG, 286
not in executable state, 271
only to authorized users, 271–272
with public-key cryptography, 274
revoking key pair, 280–283
setting key as default, 277
transferring files in, 271
unrevoking key pair, 283–284
uploading key to Ubuntu Keyserver, 278–279
verifying source of file, 288–290
file type checkers
analyzing user mode rootkit, 409–410
GNU file command. See GNU command
PEiD. See PEiD file type detector tool
Yara. See Yara
file type execution hierarchy, companion viruses, 32
file type identification, in static analysis, 300–303
filename extensions
.EXE and .DLL for PE files, 233–234
executable files transferred by changing, 271
of information stealers, 105
installing and using 7zip, 273
filename obfuscation, 322
files
analysis life cycle of, 270
extracting suspicious, 118–119
malware friendly for dynamic analysis lab, 213
financial data, user dependency attacks on, 103–104
Firefox
add-ons, 170–171, 185
built-in options protecting, 167–169
making malware friendly, 206–207
firewall
disabling for Cuckoo installation, 474
executing malware by disabling, 94–95
Flash cookies, managing with BetterPrivacy, 170
Flash Player, Adobe, 209, 227
Flash Reader, Adobe, 209, 212–213, 227
flaws, software bugs vs., 61
for malicious files with. See malware collection
Fortiguard Online Virus Scanner, 306, 316
free online automated sandbox services, 480–482
Free ProXPN, 175, 185
Free UK & US VPN, 175, 185
Free VPN for UK, 175, 185
Free Web Proxy, 176, 185
F-Secure Online Scanner, 112, 145
F-Secure Sample Analysis, 307, 316
function names as strings in code, Immunity Debugger, 388, 391
Fusion for Mac, 191
G
generic clean tools, 11
GMER, 116, 146
GNU command
accessing with Cygwin, 364–367
analyzing memory dump, 437–439
analyzing user mode rootkit, 409–410
GnuPG (gpg)
creating key pairs in Ubuntu, 274
protecting files. See public-key cryptography
golden image, dynamic analysis lab backup, 218–219
Google Chrome, making malware friendly, 207–208
graphic files, chosen by information stealers, 106
greyware, types of, 45–47
guest VM, for Cuckoo, 472, 474–477
H
Hacker Defender. See kernel mode rootkit, analyzing
Hacktools, 46
hardening static analysis lab
mitigating infection with, 149–150
overview of, 163–164
protecting Web browser, 165–171
restricting access, 171–172
updating and patching, 164–165
hardware
for dynamic analysis lab, 189–190
for static analysis lab, 151–152
hashes, static analysis of user mode rootkit, 409
heap overflow, as software vulnerability, 63–64
Heaventools PE Explorer, 483
heuristic detection, AV products using, 83
hex editors, 116–117
HIDDEN attribute, companion viruses, 32
Hidden files and folders, used by malware, 322
Hide My Ass! 174, 185
Hide My Ass! Web Proxy, 176, 186
hiding in plain sight, malware, 322
hiding using attributes, malware, 322
Hiew, as PE viewer, 370, 483
high-interaction honeypots, 139–144
hijacking, using IM and chat, 58
hit-and-run attacks, 71
honeypots
Dionea, 140–144, 146
malware collection from, 139–140
hooking
analyzing kernel mode rootkit for, 466
analyzing user mode rootkit for, 430–435, 440–443
host behavior, dynamic malware analysis of
file system, 323–326
memory, 335–347
overview of, 319–323
registry, 326–335
host programs
detecting malware infection, 9
dynamic analysis lab backup of, 219–220
file infectors attaching to, 29
overwriting virus infections in, 30–31
remediating malware infection, 10–11
in virtualized dynamic analysis lab, 192
Hotspot Shield Ad Supported, 175, 185
HR (human resources), user dependency attacks on, 103–104
hybrid malware installer functions, 320
I
IAT (import address table)
analyzing user mode rootkit for hooking, 430–435
manually unpacking packed malware and, 373, 388, 391
modifying with user mode hooks, 430, 432
rebuilding with ImpREC, 372, 400, 403
ID assignment, in static analysis, 299–300
IDA
analyzing kernel mode rootkit, 463, 466–468
determining if file is packed, 373, 375
overview of, 369
unpacked binary loaded in, 403, 405
website, 483
.idata section, PE file, 258, 260–263
identity theft, attacks on HR resulting in, 103–104
ILOVEYOU worm, 53, 56
IM (Instant Messaging)
as infection vector, 57–58
infection-vector-hosting infection vectors via, 60
social networking as infection vector, 58–59
worms, 39
IMAGE_DATA_DIRECTORY, 246–248
IMAGE_EXPORT_DIRECTORY, 263–264
IMAGE_IMPORT_DESCRIPTORs, 260–261
IMAGE_OPTIONAL_HEADER, 243–246
IMAGE_RESOURCE_DIRECTORY, 257–258
IMAGE_SECTION_HEADER, 249–254
IMAGE_THUNK_DATA, 261
Imf command, analyzing kernel mode rootkit, 462
Immunity Debugger, 368
Immunity Debugger, unpacking packed malware
0x0041B385 address, reaching, 385, 387
ADD EAX/3 is revealed, after, 393, 396
ADD EAX/3/JMP EAX, adding, 394, 397
after breakpoint, 384
after taking jump, 398–399
Analyze Code menu option, 385–386, 388
analyzing code, 398, 400
CALL EAX instruction, reaching, 378, 380
CALL instruction, reaching desired, 376–377
CALL to OutputDebugStringA, 394–398
conditional breakpoint/traceover, 382–383
debugging session of packed file in, 373, 375–376
ESI value, 380, 382
function names as strings in code, 388, 391
hitting loop, 387, 390
infamous technique, 393, 396
JMP EAX, reaching, 383–385, 391, 393
JMP instruction, after taking, 383–385
JMP instruction, following, 378–379
memory map, 379, 381
obfuscated or scrambled code, 377–378
OEP in, 398, 401
string pointer technique, 391, 392
unaligned address, showing, 392, 395
import address table. See IAT (import address table)
import functions, PE file, 260–263
ImpREC
malware process attached to, 400, 403–404
as PE reconstructor, 372
website, 484
in the wild, noteworthy malware found, 15
indicators of compromise (IOCs), 19
infamous technique, Immunity Debugger, 393, 396
infect machine, 15
infection
detecting presence of, 9–10
hardening static analysis lab to mitigate, 149–150
malware encryption during, 75–76
preventing spread of, 8–9
remediating, 10–11
infection vectors
boot sector viruses as, 36
coverage dimension of, 53
defined, 9
e-mail as, 56–57
file infectors as. See file infectors
file shares as, 61
IM and chat as, 57–58
Internet browser as, 97
multipartite viruses as, 36–37
overview of, 28, 50–51
physical media as, 55–56
potential, 65
recap of, 65–66
shelf life dimension of, 54
social networking as, 58–60
software vulnerabilities as, 61–65
speed dimension of, 51–52
stealth dimension of, 52–53
types of, overview, 54–55
URL links as, 60–61
infection-vector-hosting (IVH) infection vectors, 60
information stealers
enticing files for dynamic analysis lab, 213
as malware with file dependencies, 105–106
overview of, 41–42
spyware vs., 47
.INI file, modified by malware, 325–326
inline patching, 430–435
inspection. See malware inspection
installation, DLL advantages for, 233
installation discs, Windows 7, 153
InstallRite, 327, 353
Instant Messaging. See IM (Instant Messaging)
integrity, ensuring file, 288–290, 292–294
Internet browser
hardening static analysis lab, 165–171
making Firefox malware friendly, 206–207
making Google Chrome malware friendly, 207–208
making IE malware friendly, 200–205
malware using, 97–98
Internet connection, for malware analysis, 320
Internet Explorer, making malware friendly, 200–205
Internet worms, 40
IOCs (indicators of compromise), 19
IP (or fast) fluxing, 86
IRC worms, 39
isolation
of dynamic analysis lab, 214–215
of static analysis lab, 150, 178
IT department, attacks on, 103
IVH (infection-vector-hosting) infection vectors, 60
J
JavaScript, script viruses in, 35
JMP EAX, Immunity Debugger, 383–385, 391, 393
JMP instruction, Immunity Debugger, 378–379, 383–385
joiners, 28
joke greyware, 45–46
Jotti, 305, 316
jump, Immunity Debugger, 398–399
JustFreeVPN, 175, 185
K
Kaspersky, TDSSKiller by, 113, 115
Kaspersky Security Scan, 112, 146
KD, Window debugger, 368–369, 483
Kernel Debugging, 459–469
kernel mode rootkit, analyzing
booting Windows in Debug mode, 456–459
checking service status, 448–449
creating serial ports, 453–456
with dynamic analysis, 443–453
with Rootkit Revealer, 449–453
saving snapshot of dynamic analysis session, 453
tools needed, 443
using IDA, 466–468
using Kernel Debugging, 459–469
using Volatility, 463–465, 468–469
VMware setup on virtual machine, 453–456
KernelMode.info, 122–123
keyloggers, as information stealers, 42
keywords, used by information stealers, 105
KillSwitch by Comodo, 118–119, 146
KProxy, 176, 186
L
L2TP VPN Service, 175, 185
laboratories, used in this book, 496
laptop hardware
for dynamic analysis lab, 189–190
for static analysis lab, 151–152
last-in first-out (LIFO) data structure, stack overflow, 62–63
laws, against threat actors, 11
least privileged account, static analysis lab access, 172
legitimate services, hiding malware communications with, 86–87
life cycle, file analysis, 270
LIFO (last-in first-out) data structure, stack overflow, 62–63
Linux
file type identification in static analysis, 300–301
using WINE to run Windows static analysis tools, 6
live infected (compromised) systems, malware analysis vs., 111
local network worms, 39–40
local system time, detecting malware, 99
logon, registry keys used by malware, 326
long-term support (LTS), Ubuntu static analysis lab, 163
loop, Immunity Debugger hitting, 387, 390
LordPE
dumping desired process into PE Editor, 398–399, 401–402
EntryPoint value modified to reflect RVA of OEP, 402
as memory dumper, 369
website, 483
low-interaction honeypots, 139–140
LTS (long-term support), Ubuntu static analysis lab, 163
M
machinery.conf, Cuckoo, 477–478
macro viruses, 34–35
MAGE_IMPORT_BY_NAME, PE files, 261–262
main malware file, monitoring file system for, 324
malcode, 72
Malcode Analyst Pack, 405–406, 484
Malekal’s Forum, 127, 129
malfind plug-in, 441
malicious actor, causing data integrity violations, 293
MalShare.com, 123–124
malware, causing data integrity violations, 293
Malware, Rootkits & Botnets: A Beginner’s Guide, 321, 322
malware analysis
automated process of, 15–20
dynamic, 7–8
effective malware analyst, 20–22
limitations of, 11–12
live infected (compromised) systems vs., 111
manual process of, 14–15
overview of, 4
process, 13–14, 232
purpose of, 8–11
recap of, 22–23
and reverse engineering, 5
static, 6–7
tools of the trade. See tools of the trade
malware analyst
effective, 20–22
tools of the trade. See tools of the trade
malware at rest
analyzing. See static analysis lab
defined, 4
as static malware. See static malware, inspecting; static malware, protective
mechanisms
Malware Blacklist, 124–128
malware classes
backdoors, 40
defined, 19
fakeware, 44–45
greyware, 45–47
infectors, 28–37
information stealers, 41–42
network worms, 37–40
overview of, 26–27
ransomware, 42–43
recap of, 47
remote-access Trojan (RAT), 40–41
scareware, 43–44
Trojan Horse, 40
malware collection
from commercial sources, 138–139
extracting suspicious files, 118–119
from honeypots, 139–144
inspecting running processes, 117–118
inspecting startup programs, 114–117
looking for active rootkits, 113–114
overview of, 110
from own backyard, 111–119
recap of, 144–145
from research mailing lists, 137–138
from sample exchange, 138
scanning for malicious files, 112
tools, 145–146
malware collection, free sources
Contagio, 120–122
KernelMode.info, 122–123
Malekal’s Forum, 127, 129
MalShare.com, 123–124
Malware Blacklist, 124–128
malware trackers, 134–137
Malwarebytes forum, 126–127
Malware.lu, 124, 126
Open Malware, 127–128, 130–132
overview of, 120
Tuts4You, 132–134
VirusShare.com, 132–134
VX Heaven, 134
malware dependencies. See dependencies
malware deployment. See infection vectors
malware family, 19
malware friendly
anonymizing, 214
creating enticing files, 213
creating/utilizing dummy social media accounts, 213–214
dynamic analysis lab setup as, 198–201
installing commonly exploited software, 208–213
Internet browser, 201–208
malware in motion
defined, 4
as dynamic malware. See dynamic malware
malware infection vectors. See infection vectors
malware inspection
of dynamic malware. See dynamic analysis
overview of, 232
of static malware. See static analysis
Windows PE file. See PE (Portable Executable) file
malware outbreak, 38
malware package, 320
malware payload, 98–99
malware removal tools, 112, 146
malware research labs
anonymizing all, 150–151
dynamic analysis. See dynamic analysis lab
gathering samples. See malware collection
overview of, 110
static analysis. See static analysis lab
malware sandboxes. See automated sandboxes
malware scanning services, 316
malware test environments, 7, 17–20
malware trackers
overview of, 134–135
Palevo Tracker, 137
SpyEye Tracker, 135–136
Zeus Tracker, 135–136
Malwarebytes forum, 126–127
Malware.lu, 124, 126
malware-serving domain, 58
MalwareViz, 481
Malwr, 481
manual malware analysis, 14–16
marketing, user dependency attacks on, 104–105
mass mailers
overview of, 38
program dependency of, 96–98
MBR (Master Boot Record)
boot analyzer tools for, 115–116
hex editors imaging, 116–117
malware infection of, 115
multipartite viruses infecting, 36–37
MBR Backup, 116, 146
MbrScan, 116, 146
MD5SUM, 299, 315
MegaProxy, 176, 186
Melissa worm, 53, 56
memory
analysis tools, 354
analyzing running processes using Process Explorer, 337–344
DLL advantages for, 233
heap overflows and, 63–64
inspecting for persistent process, 344–347
understanding malware behavior in, 335
memory dump
analyzing user mode rootkit, 436–439
LordPE for, 369, 483
overview of, 369
Volatility framework for, 370, 483
memory infection, 29
memory map, Immunity Debugger, 379, 381
memory scanners, 9–10
memory scrapers, as information stealers, 42
metamorphic malware
as anti-reversing technology, 79
static malware protected as, 77–78
weakness of, 78
Metascan by OPSWAT, 305, 316
Microsoft Developer Network (MSDN). See MSDN (Microsoft Developer Network)
subscription
Microsoft File Checksum Integrity Verifier, 299, 315
Microsoft Office
as good target for attackers, 208–209
making malware friendly for dynamic analysis lab, 209–211
writing macro viruses in, 35
Microsoft Security Essentials, 112, 146
MiFi personal hotspot, 178
modified files, monitoring file system for, 325–326
modular architecture, DLL, 233–234
modularized malware, 324
mongodb, installing Cuckoo, 470
MSDN (Microsoft Developer Network) subscription
accessing different flavors of Windows via, 191
downloading Windows ISO images, 153
installing OS in virtualized environment, 191
multipartite viruses, 36–37
mutation engine
of metamorphic malware, 77–78
of polymorphic malware, 76–77
MYDOOM worm, 53
MZ header, DOS, 235–236
N
names, PE file sections, 256–257
Nate's MBR and Boot Sector Analyzer, 116, 146
Nepenthes, 140
network behavior
dynamic malware analysis of, 348–352
network analysis tools, 354
protection, 84–85
network capturing tools
analyzing kernel mode rootkit. See kernel mode rootkit, analyzing
analyzing user mode rootkit. See rootkit, analyzing user mode
overview of, 407
TCPDump, 407, 484
TCPView, 407–408, 484
Wireshark, 407, 484
network sniffers, 10, 471
Network Time Protocol (NTP), timing dependency, 99
network worms
file-sharing, 38
IM, 39
Internet, 40
IRC, 39
local, 39–40
mass mailers, 38
overview of, 37–38
Newest Malware Threats forum, 124–128
non-critical users, user dependency attacks on, 105
non-executable state
file analysis in, 290
transferring files in, 271
NoScript add-on, Firefox, 170
noteworthy malware, 15–16
NTKD, Window debugger, 368–369, 483
NTP (Network Time Protocol), timing dependency, 99
NXDOMAINS, detecting domain fluxing, 86
O
obfuscation
Immunity Debugger, 377–378
limitations of static analysis, 12
OCS (ActiveX control) files, implemented as DLLs, 234
OEP, Immunity Debugger, 398, 400–402
OkayFreedom VPN, 175, 185
OllyDbg, 78, 368
one-way communication, in malware attacks, 84–85
onion router (Tor), 177, 186
Online Anonymizer, 176, 185
online anonymizers
hardening static analysis lab, 172–173
malware research labs using, 150–151
proxy servers as, 173–174
tools, 185–186
Tor as, 177
VPNs as, 174–177
Web proxies as, 176–177
online antivirus scanning
ClamAV for, 307–309
free services, 304–306
highlighting AV product/scan engine, 306–307
overview of, 303
sample submission services, 307
online references
automated sandbox services, 481
AV scanners, 112
backing up/restoring static analysis lab, 183
boot analyzer tools, 116
checking for Conficker infection, 98
Deep Freeze Standard, 217–218
Dionea, 144
dynamic analysis lab tools, 226–227
file compression tools, 272
Firefox download, 167
free sources of malware. See malware collection, free sources
hex editors, 116
inspecting running processes, 118
inspecting startup programs, 114
latest software vulnerabilities, 65
latest Windows service pack/update, 93
malware collection tools, 145–146
online anonymizers, 174–177
OpenPGP protocol, 274
Portable Executable file tools, 268
proxy servers, 174
rootkit detection, 113
static analysis lab tools, 184–186
static analysis tools, 315–316
tools in this book, 487
Unbuntu download, 163
updating and patching, 165
virtual private networks, 175
Windows 7 USB/DVD Download Tool, 162
on-premise antivirus detection, 303
Open Malware, 127–128, 130–132
OpenPGP protocol, 274
operating system
extracting suspicious files using different, 118–119
installing for dynamic analysis lab, 191–197
installing Windows for static analysis lab. See Windows installation
operating system dependency, 92–94
opportunistic attacks, 53, 57
OSI (Secunia Online Software Inspector), 165, 185
OSR driver loader, 484
Outlook, malware using, 96–97
Outlook Express, malware using, 97
overwriting virus infections, 30–31
P
P2P (peer-to-peer) file sharing, as malware infection vector, 61
p7zip, 272–274, 295
packed files, Immunity Debugger for, 373, 375–376
packed malware, 309
packers
identifying protective mechanisms, 310–311
resources, 316
Packers and Unpackers, 316
Palevo Tracker, 137
parasitic virus infections, 32–34
parity computations, data integrity, 294
passing control, 29–30
passphrase, revoking key pair, 281–282
password-protected compressed files
adding public-key cryptography to, 274
confidentiality with, 292
encrypting with public key of intended recipient, 286–287
transferring files for analysis as, 271–274
patches, hardening static analysis lab, 164–165
patience, of malware analyst, 21–22
pattern matching tool, Yara, 363–364
Payload Security, 481
PDF (Portable Document Format) readers, malware using, 98
PE (Portable Executable) file
64-bit format, 267
export functions, 263–267
import functions, 260–263
malware inspection and, 232
overview of, 233–235
recap of, 267
relative virtual address, 259–260
tools, 268
PE (Portable Executable) file format
DOS MZ header, 235–237
DOS stub, 237–238
general view of, 237
overview of, 235
PE header, 237–248
recap of, 267
section table, 248–256
sections, 256–259
structure verification in static analysis, 313
tools, 268
unpacking packed binaries with, 313
PE Editor, unpacking packed malware manually, 398–403
PE Explorer, 313, 316, 371
PE file header
IMAGE_DATA_DIRECTORY, 246–248
IMAGE_FILE HEADER, 240–241
IMAGE_OPTIONAL_HEADER, 243–246
installing pefile in Ubuntu, 241
overview of, 237–241
Python displaying information on, 242–243
structure of, 239
PE reconstructors
IDA. See IDA
ImpREC, 372, 484
manually unpacking packed malware. See unpacking packed malware
manually
overview of, 371–372
PEiD. See PEiD file type detector tool
PEView. See PEView
tools of the trade. See PE reconstructors
PE viewers
Dependency Walker. See Dependency Walker
Heaventools PE Explorer, 483
Hiew, 483
PEView. See PEView
Resource Hacker, 483
tools of the trade for, 370–371
PE32+, PE file 64-bit format, 267
PE32+ format, 64-bit PE file, 267
PECompact, 311, 316
pedump
dumping PE information with, 254
installing and utilizing, 254–255
website, 268
pedump online PE file submission, 268
pefile tool, 241, 268
PEiD file type detector tool
analyzing user mode rootkit, 409
determining if file is packed, 372–373
file type identification with, 300–303
website, 315
when to choose, 356
persistency, malware
analyzing, 322
analyzing file system, 323, 325–326
analyzing registry, 326
personal private information (PPI), attacks on human resources for, 103–104
PEView
analyzing user mode rootkit, 409–413
defined, 370
determining if file is packed, 373–374
as PE viewer, 370–371, 483
phishing attacks, 102, 104
physical media
as infection vector for computer viruses, 55–56
malware at rest using, 69
speed of infection via, 51–52
as stealthiest infection vector, 53
plug-ins, basic Volatility, 500
polymorphic malware
as anti-reversing technology, 79
static malware protected as, 76
weakness of, 77
pop-ups, adware, 46
Portable Document Format (PDF) readers, malware using, 98
Portable Executable file. See PE (Portable Executable) file
PPI (personal private information), attacks on human resources for, 103–104
Premium VPN with Public IP, 175, 185
prepending parasitic viruses, 34
presence of malware, 9–11
prevention, spread of malware, 8–9
privacy
making Google Chrome malware friendly, 208
making IE malware friendly, 204
proxy server risks, 174
VPN risks, 175
privacy options, Firefox, 167–168, 170–171
private key
in public key cryptography. See public-key cryptography
verifying source by signing file with, 288–290
Private Tunnel, 175, 185
privilege escalation, as software vulnerability, 64
process, of malware analysis
analyzing using Process Explorer, 337–344
automated, 15–20
inspecting for persistency, 344
manual, 14–15
static and dynamic analysis in, 13–14
process examination tools, 117–118, 146
Process Explorer
analyzing user mode rootkit, 413–416
inspecting running processes, 118, 337–344
memory analysis tool, 354
website, 146
Process Monitor
analyzing kernel mode rootkit, 443–447
analyzing user mode rootkit, 413, 417–418, 422–430
with Process Monitor, 443–447
profile hives, registry keys used by malware, 326
program dependencies, 96–98
protective mechanisms, malware
dynamic malware, 79–87
overview of, 68, 70–71
recap, 87–88
in static analysis, 310–313
static malware, 71–79
two states of, 68–69
Proxy 4 Free, 174, 185
proxy servers
downloading services, 185
online anonymity with, 173–174
online anonymity with virtual, 174–177
Public Proxy Servers, 174, 185
public-key cryptography
backing up/restoring key pair, 278–280
changing expiration date of key pair, 284–285
confidentiality with, 292
creating private/public key pair, 275–276
encrypting file with public key of intended recipient, 286–287
encrypting/decrypting using GnuPG, 286
protecting files from unauthorized access, 274
revoking key pair, 280–283
setting key as default, 277
unrevoking key pair, 283–284
uploading key to Ubuntu Keyserver, 278–279
pydeep, installing for Cuckoo, 471
Python, installing for Cuckoo, 470–471, 473
Python script
displaying all PE information, 266–267
displaying information on PE file header, 242–243
displaying PE export information, 264–265
displaying PE import information, 262–263
displaying PE section information, 255–256
identifying packed binaries with, 312
installing pefile in Ubuntu, 241
R
ransomware
fake, 43
malware file modifications, 325
overview of, 42–43
scareware vs., 44
RAT (remote-access Trojan), 40–41
.rdata section, PE file, 259
real-time packers, 310–311
redundancy, ensuring availability, 294–295
REGEDIT, malware disabling, 327
registry
detecting system changes via InstallRite, 327–330
detecting system changes via Uninstall Tool, 331–337
malware persistency using, 326
malware using autostart, 326–327
relative virtual address. See RVA (relative virtual address), PE file
.reloc section, PE file, 258
remediation
advanced malware research for, 11
of malware infection, 10–11
remote-access Trojan (RAT), 40–41
reporting.conf, Cuckoo, 477–478
Request Policy add-on, Firefox, 170
research
advanced malware, 11
automated malware analysis, 15–20
becoming familiar with malware, 21
mailing lists, 137–138
malware labs for. See malware research labs
manual malware analysis, 14–15
Resource Hacker
extracting resource information from file, 411–412, 414
as PE viewer, 371, 483
restore
dynamic analysis lab, 215–225
key pairs, 278–280
static analysis lab, 182–183
restrictive system settings, malware, 94–95
RET (return address), stack overflows, 63
reverse engineering
also known as reversing, 13
beating malware protective mechanisms, 78
debugging in, 80
in malware analysis, 5, 13–20
malware anti-reversing techniques, 78–79
unpacking packed files, 313
reversing. See reverse engineering
revoking key pair
overview of, 280–283
unrevoking, 283–284
risk
dynamic analysis as high, 8
static analysis as low, 6–7
roles, user dependency attacks on, 101–105
rootkit
hiding malware in, 322
looking for active, 324
rootkit, analyzing user mode
checking for code injection, 430
checking for hooking, 430–435
with dump analysis, 436–443
with dynamic analysis, 413–436
with file type checkers, 409–410
malware used, 408
PE characteristics of file, 410–413
with static analysis, 409–413
tools needed, 408
rootkit detectors, 113–114, 146
rootkit tools
overview of, 406–407
Rootkit Revealer, 113–114, 146, 449–453
Rootkit Unhooker, 431–435, 484
.rsrc section, PE file, 257
Ruby, installing and utilizing pedump, 255
running processes, inspecting, 117–118
RVA (relative virtual address), PE file
IMAGE_OPTIONAL_HEADER for, 244
overview of, 259–260
sorting sections in section table, 254
S
sales, user dependency attacks on, 104–105
Samair.RU, 174, 185
sample exchange, malware collection from, 138
sample submission online services, 307, 316
sandboxing. See also automated sandboxes
anti-sandboxing of dynamic malware, 80–82
overview of, 7
protecting graphic files with, 106
scan patterns, 10
scanning services, malware, 316
scareware, 43–44
schedules, patch update, 164–165
script viruses, as file infectors, 35–36
scripts, protecting Web browser from malicious, 167–171
section table, PE file format
of dumped process, 400, 403
as IMAGE_SECTION_HEADER, 249–254
installing/utilizing pedump, 254–255
overview of, 248
Python script displaying information for, 255–256
sections, PE file format, 256–259
Secunia OSI (Online Software Inspector), 165, 185
security
confidentiality and, 292
files deleted by malware, 325
Firefox options, 168–171
making IE malware friendly, 202–203
malware writers defeating, 70–71
training executives/senior management in, 102
senior management, user dependency attacks on, 101–102
service packs (SPs), malware OS dependency and, 93
services
analyzing kernel mode rootkit, 448–449
registry keys used by malware, 326
SHA-1, ID assignment in static analysis, 299–300
shared folders, spreading local network worms, 39
shelf life, of malware infection vectors, 54
sigclass, 283–284
signature database, 10
signature word, boot sector, 36–37
signatures
AV products detecting malware via, 83
using private key for, 288–290
writing for ClamAV, 309
single-platform macro viruses, 35
snail mail, attacks via, 102
social engineering
spreading mass mailers via e-mail, 38
spreading worms via, 37
using e-mail infection vector, 56–57
social networking
dummy account for dynamic analysis lab, 213–214
as infection vector, 58–60
training executives on risk of posting on, 102
using Internet browser for malware in, 97
software vulnerabilities
as buffer overflows, 62–64
free vulnerability scanners detecting, 164–165
as infection vector, 61–62
installing for dynamic analysis lab, 208–213
obtaining latest, 65
as privilege escalation, 64
shelf life of infection vectors in, 54
stealthiness of infection vectors in, 52–53
as zero-day attack, 64
Sophos, 307, 316
specific clean tools, 11
speed, of malware infection vectors, 51–52
spoofing e-mail addresses, 104
spread of malware, preventing, 8–9
SPs (service packs), malware OS dependency and, 93
SpyEye Tracker, 135–136
spyware, 46–47, 94–95
SQLAlchemy, installing Cuckoo, 471
ssdeep, installing for Cuckoo, 471
stack overflow, software vulnerability, 62–63
startup examination tools, 114–117, 146
static analysis
after file is transferred from verified source, 289
automated malware analysis via, 17–20
limitations of, 11–12
malware analysis process, 13–14
tools, 6–7
of user mode rootkit, 409–413
static analysis lab
anonymous communication, 150–151
backing up and restoring, 182–183
host file inspection tools, 149
mitigating becoming a malware staging point, 150
mitigating possible infection, 149–150
overview of, 148–149
process of static analysis, 148
recap of, 183–184
tools, 184–186
virtualized, 178–182
static analysis lab setup
anonymizing lab, 172–177
choosing hardware, 151–152
hardening lab, 163–172
installing Ubuntu OS, 162–163
installing Windows OS. See Windows installation
isolating lab, 178
overview of, 151
static malware, defined, 69
static malware, inspecting
antivirus detection, 303–309
file type identification, 300–303
ID assignment, 299–300
overview of, 298–299
PE structure verification, 313
protective mechanisms identification, 310–313
recap of, 315
strings analysis, 313–315
tools, 315–316
static malware, protective mechanisms
anti-reversing, 78–79
encryption, 74–76
entry-point obscuring, 72–74
metamorphism, 77–78
overview of, 71–72
polymorphism, 76–77
recap of, 87
stealth
backdoors using, 40
of malware infection vectors, 52–53
storage, file
availability, 294–295
confidentiality, 291–292
integrity, 292–294
overview of, 290–291
string pointer technique, Immunity Debugger, 391, 392
strings analysis
analyzing memory dump with GNU command, 437–439
of static malware, 313–315
Submit page, Cuckoo, 479–480
SubSeven by mobman, RAT, 41
sudo (superuser do), Ubuntu updates, 165
sudoers, installing for Cuckoo, 472
Superlab, 15
superuser do (sudo), Ubuntu updates, 165
suspicious files, extracting, 118–119
Sysinternals Strings, EXE, 316
Sysinternals Suite
analyzing kernel mode rootkit. See kernel mode rootkit, analyzing
analyzing network behavior using TCPView, 348–349
analyzing user mode rootkit. See rootkit, analyzing user mode
inspecting for persistency, 344–347
as tool of the trade, 357–358
system error, in data integrity violations, 293
System folder, malware in, 320, 322
system monitoring tools
anti-sandboxing detecting, 82
in dynamic analysis, 7
inspecting dynamic malware with InstallRite, 327–330
inspecting dynamic malware with Uninstall Tool, 331–337
resources, 353
System Restore, after Windows Update, 164
system restore files, deleted by malware, 325
system scanner, detecting malware infection, 9
system settings dependency, malware, 94–95
T
targeted attacks, 53, 57
task ID, Cuckoo, 479
taxonomy. See malware classes
TCPDump
installing for Cuckoo, 471
network capturing tool, 484
TCPView
analyzing network behavior, 348–349
analyzing user mode rootkit, 413–416
network analysis tool, 354
network capturing tool, 484
TDSSKiller by Kaspersky, 113, 115, 146
technical users, user dependency attacks on, 103
Temporary folders, malware installing components in, 320
.text section, PE file, 257
third-party marketers, 104
thread injection, user mode rootkit analysis for, 430
threat actors, 11
threat ecosystem, 51
ThreatExpert, 481
ThreatTrack Public Malware Sandbox, 481
thumb drives. See USB (universal serial bus) sticks
time trigger, 98, 99
timing dependencies, 98–99
TLINK32 EXEs, 259
.tls section, PE file, 258
TlsAlloc, 258
TlsGetValue, 258
tools
creating protective mechanism for malware, 310
discussed in this book, 487
dynamic analysis, 7
dynamic analysis lab, 226–227
familiarization with analysis, 21–22
file handling, 295
malware collection, 145–146
PE file, 268
static analysis, 6–7, 315–316
static analysis lab, 184–186
tools of the trade
automated sandboxes, 469–480
Cygwin, 364–366
debuggers, 367–369
disassemblers, 369
free online automated sandbox services, 480–482
malcode analyst pack, 405–406
malware analysis use cases, 356
malware analyst toolbox, 357
memory dumpers, 369–370
network capturing tools. See network capturing tools
PE reconstructors. See PE reconstructors
PE viewers, 370–371
recap of, 482–483
rootkit tools, 406–407
summary review of, 483–484
Sysinternals Suite, 357–358
Yara, 358–364
Tor (onion router), 177, 186
traceover, Immunity Debugger, 382–383
trackers, malware, 134–137
transfer of files. See file transfer
Trend Micro HouseCall, 112, 145
Trojan Horses
overview of, 40
remote-access Trojan, 41–42
using Internet browser, 97
trust, malware taking advantage of, 58
Trust Center, Microsoft Office, 210
Tuts4You, 132–133
Tuxboot, 221–222, 227
two-way communications, malware attacks, 84–85
U
UAC (User Account Control)
executing malware by disabling, 94–95, 200–201
making Adobe Reader malware friendly, 213
scareware and, 44
Ubuntu
creating virtualized desktop via VirtualBox, 181–182
creating virtualized desktop via VMware Player, 179–181
creating/managing key pairs. See public-key cryptography
extracting strings from files, 314
extracting suspicious files, 118–119
as host OS for virtualized dynamic analysis lab, 192
installing and using 7zip, 272–274
installing Dionea, 140–144
installing for static analysis lab, 162–163
installing pefile in, 241
installing VirtualBox in, 195–196
installing VMware Player in, 192–194
private key signing, 288–290
uninstalling VirtualBox in, 196–197
uninstalling VMware Player in, 194–195
updating and patching in, 165–166
UI (user interface)
menu buttons in graphic-friendly design, 206
remote-access Trojan, 41
Ultimate Packer for Executables. See UPX (Ultimate Packer for Executables)
unauthorized access, protecting transferred files from, 271–272
Uninstall Tool, 331–337, 353
universal serial bus sticks. See USB (universal serial bus) sticks
unpackers, 310, 313
unpacking packed malware manually
determining if file is packed, 372–373
EntryPoint value modified to reflect RVA of OEP, 402
imports found by ImpREC, 402, 404
ImpREC found OEP, 402, 404
LordPE dumping desired process, 401–402
malware process attached to ImpREC, 400, 403
malware used, 372
section table of dumped process, 400, 403
tools for, 372
unpacked binary loaded in IDA, 403, 405
using debugger. See Immunity Debugger, unpacking packed malware
unpatched systems, collecting malware samples with, 40
unrevoking key pair, 283–284
Update Manager, Ubuntu, 165–166
updates
Cygwin, 366
Dionea, 144
hardening static analysis lab, 164–165
making OS malware friendly by disabling, 198–199
malware OS dependency and, 93
using manufacturer method for, 45
UPX (Ultimate Packer for Executables)
packing file using, 311–312
resources, 316
reversing, 78
user mode rootkit analyzed for, 410–411
URL links, as infection vectors, 60–61
USB (universal serial bus) sticks
attacking executives/senior management via, 102
creating bootable Windows 7 installer, 156–162
creating Clonezilla Live in, 220–222
hardware for static analysis lab, 152
as infection vector, 53, 55–56
installing Windows in bare-metal system, 197
User Account Control. See UAC (User Account Control)
user dependency, malware
compromise accomplice, 100–101
executives and senior management, 101–102
HR and finance, 103–104
marketing and sales, 104–105
non-critical users, 105
technical users, 103
using roles and access, 101
user error, in data integrity violations, 293
user interface (UI)
menu buttons in graphic-friendly design, 206
remote-access Trojan, 41
user lockout, ransomware as, 43
user mode rootkit. See rootkit, analyzing user mode
UserDB.TXT database, 300–303, 313
users, installing Cuckoo, 472
V
VA (virtual address), 259–260
VBS (Visual Basic Script), script viruses in, 35
verifiable source, transferring files for analysis from, 288–290
verify switch, 289
VICheck, 481
VirSCAN, 304, 316
virtual address (VA), 259–260
virtual environment
analyzing kernel mode rootkit in. See kernel mode rootkit, analyzing
dynamic analysis in bare metal vs., 318
dynamic analysis labs, backup, 218–219
dynamic analysis labs, clean slate restoration, 215–216
dynamic analysis labs, setting up, 188–189
dynamic analysis labs, Windows installation, 191–196
static analysis labs in, 178–182
Virtual PC by Microsoft, 191
virtual-aware malware, 96, 188–189
VirtualBox
Cuckoo installation/configuration, 470, 472–474, 478
downloading, 186
virtualized dynamic analysis lab, 191, 195–197, 215–216
virtualized static analysis lab, 178–179, 181–182
Volatility support for, 439
website, 226
virtualization dependency, malware, 94–96
virtualization software, dynamic analysis lab tools, 226
virtualization-aware, 96
virtualized static analysis lab, 178–179
VirtualPC, 226
VirusShare.com, 132–134
VirusTotal by Google
analyzing user mode rootkit, 409
antivirus scanning service, 304–306
website, 316
Visual Basic Script (VBS), script viruses in, 35
VM-aware, 96
.VMEM files, 439–443
VMware
downloading, 186
kernel mode rootkit analysis setup, 453–456
for virtualized dynamic analysis lab, 191, 192–195
for virtualized static analysis lab, 178–181
VMware Player
creating dynamic analysis lab, 191–195
website, 226
Volatility framework
analyzing kernel mode rootkit, 463–465, 468–469
basic plug-ins for, 500
dump analysis with, 439–443
as memory dump analyzer, 370
website, 483
VPNBook, 175, 185
VPNs (virtual proxy servers), 174–177, 185
vulnerabilities
exploits vs., 62
software. See software vulnerabilities
VX Heaven, malware collection from, 134
W
Web of Trust (WOT) add-on, Firefox, 170–171
whale-phishing attacks, 102, 104
whitelisting, 18–19, 61
WinDbg
analyzing kernel mode rootkit, 453–454, 459–469
website, 483
as Window debugger, 368
Windows
debuggers, 368–369
extracting strings from files, 314–315
malware installing components in folders, 320
PE file. See PE (Portable Executable) file
static analysis tools, 6
Windows 7 USB/DVD Download Tool
creating bootable USB stick, 160, 162–163
website, 184
Windows Defender, 94–95
Windows installation
in bare-metal system, 197
for dynamic analysis lab, 190–197
for static analysis lab, 152–162
Windows Update, 164
WINE (Wine Is Not an Emulator), 6
WinHex MBR / boot sector editor, 116, 146
WinRAR, 272, 295
WinZIP, 272, 295
Wireshark
analyzing user mode rootkit, 414, 417–420
detecting presence of malware, 10
network analysis tool, 350–352, 354
network capturing tool, 484
Word Options window, Microsoft Office, 210
worms
coverage of infection via, 53
network, 37–40
using e-mail infection vector, 56–57
WOT (Web of Trust) add-on, Firefox, 170–171
X
x86-based CPU jump instruction, boot sector viruses, 36
XCOPY.EXE session, 158, 161
Y
Yara
analyzing user mode rootkit, 409
creating Yara rule, 360–362
installing, 359–360
installing for Cuckoo, 471
installing support for Python, 362–363
pattern matching tool, 358–359
Python script and, 363–364
Z
Zbikowski, Mark, 236
zero dollar cost, online antivirus scanning services, 304–306
zero-day vulnerabilities, 52, 64
Zeus Tracker, 135–136
zones, making IE malware friendly, 202–203