Understanding Malware Behaviour Through
Understanding Malware Behaviour Through
traffic analysis
Master Thesis
submitted to the Faculty of the
Escola Tècnica d’Enginyeria de Telecomunicació de Barcelona
Universitat Politècnica de Catalunya
by
Marta Galindo Quintana
In partial fulfillment
of the requirements for the master in
Cybersecurity ENGINEERING
3
Abstract
This project was developed as the final Thesis for the Master’s degree in Cybersecurity
at Universitat Politècnica de Catalunya (and in collaboration with Aalborg University
Copenhagen). The task for the project was to perform an analysis on the banking trojan
TrickBot and understand its traffic behaviour. In order to achieve this, an adequate closed
sandbox environment had to be designed and implemented. As such, a system was made
consisting of Cuckoo Sandbox and VirtualBox, where multiple TrickBot binaries were
submitted and analyzed dynamically. Not enough samples behaved as it was expected
from them, so another environment was deployed in order to simulate the attack of a
banking trojan. With this second system, the task of understanding the credential stealing
process was accomplished, and the project was therefore successful as it would serve as a
guide to future malware analyses.
4
Contents
List of Figures 7
List of Tables 8
1 Introduction 9
1.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2 Work Plan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3 Deviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4 Gantt diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.5 Structure of document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 Results 52
4.1 Infrastructure 1: TrickBot analysis in Cuckoo Sandbox . . . . . . . . . . . 52
4.1.1 App.Any.Run executable 1 . . . . . . . . . . . . . . . . . . . . . . . 52
4.1.2 App.Any.Run executable 2 . . . . . . . . . . . . . . . . . . . . . . . 56
4.1.3 Results Infrastructure 1 . . . . . . . . . . . . . . . . . . . . . . . . 61
4.2 Infrastructure 2: Web Injection Analysis . . . . . . . . . . . . . . . . . . . 62
5
4.3 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5 Conclusions 64
6 Future development 65
References 66
A Appendix 68
A.1 Python C&C Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
A.2 Self-Signed Certificate for Paypal server . . . . . . . . . . . . . . . . . . . . 69
6
List of Figures
1 Project’s Gantt diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2 Static Web Injection TrickBot [12] . . . . . . . . . . . . . . . . . . . . . . . 15
3 Dynamic Web Injection TrickBot [12] . . . . . . . . . . . . . . . . . . . . . 16
4 Architecture 1 for dynamic malware analysis . . . . . . . . . . . . . . . . . 22
5 Architecture 2 for dynamic malware analysis . . . . . . . . . . . . . . . . . 23
6 Cuckoo Sandbox Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7 Configuration Virtual Machine Host - Ubuntu . . . . . . . . . . . . . . . . 24
8 Configuration Virtual Machine Guest - Windows 7 . . . . . . . . . . . . . . 25
9 IPv4 Settings for Windows 7 VM . . . . . . . . . . . . . . . . . . . . . . . 26
10 INetSim HTML Default page . . . . . . . . . . . . . . . . . . . . . . . . . 27
11 Burp Proxy Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
12 INetSim and Burp joined with Cuckoo . . . . . . . . . . . . . . . . . . . . 29
13 AntiVM detection signatures captured in Cuckoo . . . . . . . . . . . . . . 30
14 Web Interface Cuckoo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
15 Analysis Configurations from Cuckoo’s Web Interface . . . . . . . . . . . . 33
16 Baseline Cuckoo Analysis of Guest Machine Windows 7 . . . . . . . . . . . 34
17 Original Home Page Paypal . . . . . . . . . . . . . . . . . . . . . . . . . . 41
18 Original Log In Page Paypal . . . . . . . . . . . . . . . . . . . . . . . . . . 42
19 nslookup response for paypal.com . . . . . . . . . . . . . . . . . . . . . . . 43
20 Certificate Error with DNS Spoofing . . . . . . . . . . . . . . . . . . . . . 44
21 Website Identification with installed CA certificate . . . . . . . . . . . . . 45
22 Paypal’s self-signed Certificate . . . . . . . . . . . . . . . . . . . . . . . . . 46
23 Flow System 2 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
24 InetSim and C&C servers up and running . . . . . . . . . . . . . . . . . . 48
25 Outcome of execution of the Attack Script . . . . . . . . . . . . . . . . . . 49
26 Home page of Paypal website hosted in INetSim server . . . . . . . . . . . 50
27 Sign In page of Paypal website hosted in INetSim server . . . . . . . . . . 50
28 Loading page of Paypal website hosted in INetSim server . . . . . . . . . . 51
29 Stolen Credentials displayed in C&C server. . . . . . . . . . . . . . . . . . 51
30 Indicators Of Compromise of Trickbot’s sample 1 [37]. . . . . . . . . . . . . 52
31 Summary Cuckoo Analysis of TrickBot’s sample 1. . . . . . . . . . . . . . . 53
32 Network Cuckoo Analysis of TrickBot’s sample 1. . . . . . . . . . . . . . . 53
33 VirusTotal detection of link as C&C server. . . . . . . . . . . . . . . . . . 54
34 HTML file loaded for HTTP response for malicious sample running on
Cuckoo Sandbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
35 Indicators Of Compromise of Trickbot’s sample 2 [39]. . . . . . . . . . . . . 56
36 Summary Cuckoo Analysis of TrickBot’s sample 2 . . . . . . . . . . . . . . 56
37 Word malicious document of TrickBot’s sample 2. . . . . . . . . . . . . . . 57
38 Network Cuckoo Analysis of TrickBot’s sample 2. . . . . . . . . . . . . . . 57
39 Cuckoo’s request and response to C&C servers from TrickBot’s sample 2. . 58
40 Malicious processes deployed in Any.Run TrickBot’s sample 2. . . . . . . . 58
41 Registry changes performed by SVCHOST process in Any.Run TrickBot’s
sample 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7
42 Modified files by SVCHOST ’s parent process in Any.Run TrickBot’s sample
2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
43 Failed HTTP request in Any.Run from TrickBot’s sample 2. . . . . . . . . 60
44 Process Cuckoo Analysis of TrickBot’s sample 2. . . . . . . . . . . . . . . . 60
List of Tables
1 Use Case 1 for System 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2 Use Case 2 for System 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3 Use Case 3 for System 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4 Use Case 1 for System 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5 Use Case 2 for System 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6 Use Case 3 for System 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
7 Use Case 4 for System 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
8
1 Introduction
Over the last years, the increase in use of online banking websites has led to a major
increase in cyber-attacks to these sites and its users. Right after banks offered online ser-
vices by the year 2000, attackers started targeting these websites in order to find a way
to exploit them. When banking online infrastructures developed in strength, hackers de-
viated their attacks to the users of the online banking services, which originated the birth
of Banking Trojans [1]. Trojans take their name after the classic Trojan horse strategy,
and they are programs that use malicious code masqueraded as trusted applications. This
family of malware focuses on stealing user’s credentials and, consequently, their money.
In order to stop these attacks and protect the Internet community, malware analyses are
performed. These consist on understanding the behaviour of the malicious files or URLs
that infect victims’ systems. The output of these analyses helps with the prevention,
mitigation and elimination of said threats. Malware analysis can be performed either
dynamically or statically. While dynamic analysis is behaviour-based, static analysis is
signature-based. This means that code is executed for a dynamic analysis, but not for a
static one. For the latter, instead of running the malware in a controlled environment, its
code is examined thanks to disassemblers.
Among the most ”popular” banking trojans stands TrickBot, born in 2016 and active to
this day. It was considered the second most prevalent banking trojan worldwide in 2020
[2], and it was designed to steal financial information from its victims’ infected systems.
TrickBot spreads via spam emails that contain attached Microsoft files (Excel or Word)
which, once they are opened and their macros are enabled, unpack their malicious content
into the fooled victim. Then, the trojan connects to its corresponding attacker-controlled
infrastructure, and waits for the user to connect to a targeted banking website. When this
happens, TrickBot performs a web injection attack, which is one of the pillars on which
this project is based. Web injection occurs once the trojan has infected the targeted system
and all it has left to do is wait quietly and listen to the system’s traffic. Then, when the
victim tries to access one of the targeted banking websites (previously defined by the
malware developer), the trojan steals his or her credentials to enter into the bank site.
The amount of available information on the Internet about the web injection part of
TrickBot’s attack is shockingly small compared to the one about the previous part of the
process. Moreover, despite all the updates and upgrades that antivirus software perform,
TrickBot keeps evolving and its developers keep coming up with new ideas to evade
antivirus and also malware analysis.
9
1.1 Objectives
The problem to be looked at for this Master Thesis was around the topic of TrickBot’s
traffic behaviour in a closed sandbox environment. The actual problem was setting up
an adequate environment for different versions of TrickBot’s samples to run in and then
carrying out a dynamic analysis of the traffic produced by said samples. The main focus of
this network study was on the web injection and the credential stealing processes, as well as
on the connections between the trojan and the outside attacker-controlled infrastructures
(the Command and Control servers).
This project was developed in collaboration with Aalborg University Copenhagen, and it
hoped to contribute to the understanding of how to perform a safe and efficient dynamic
malware analysis. It also aimed to enlighten TrickBot’s credential stealing and web injec-
tion operations, as well as its relationships with the C2 servers. In the long term, these
findings are expected to help protecting the users of online banking services. Also, this
would not only help defeating the famous TrickBot, but also his banking trojans siblings.
In order to achieve this, three research questions were formulated:
How can an analysis environment for TrickBot’s traffic be designed and imple-
mented?
How does TrickBot steal banking credentials from its victims?
How does TrickBot’s web injection process work?
10
drawn from them.
1.3 Deviations
Unfortunately, there were dome deviations from the original plan: downloading malware
and having it perform smoothly on a virtual machine all the way through its last phase
was not a simple task, and it got more complicated than expected. This is because most
of the downloaded malicious samples detected they were running in a fake environment
and changed the course of their original behaviour. Some versions’ C&C servers were
already down by the time of the analysis, and other samples needed unique private keys
to decrypt their malicious payloads. All these stones on the road made it unfeasible to
provide a complete analysis on how TrickBot’s web injection process works. Instead, a
deviation was taken and a simulation on the credentials stealing was performed. For
this, a very similar infrastructure to the previous deployed one was used, but rather
than studying the fingerprints that malware left behind, the opposite process was carried
out: a homemade malware was created and executed. This custom binary simulated the
stealing of credentials from a victim, so it also contributed to the goal of understanding
the performance of banking trojans.
11
1.4 Gantt diagram
Now
12
2 State of the Art
This State of the Art chapter includes a background review on the trojan that this project
aimed to study: TrickBot, and it contains recent research done on the subject matter.
This section also introduces the technologies applied for the development of the project
and its correspondent tools: virtualization with VirtualBox, sandboxing with Cuckoo,
fake services with INetSim, interception of traffic with Burp and website cloning with
HTTrack. This aims to provide a better understanding of them and how they were used
during the project. Then, a brief introduction to DNS Spoofing and SSL certificates, also
applied to the project, ends the chapter.
13
document that the user downloads [6]. These documents are generated using EternalBlue
[8], an exploit that takes advantage of a series of Microsoft software vulnerabilities [9]. In
addition to phishing emails, the trojan can also be deployed through lateral movement
via the protocol SMBv1 (Server Message Block) [10].
When the malicious attachment is downloaded by the victim, a macro is enabled and it
exfiltrates the information to the attacker-controlled infrastructure. In order to obfuscate
content and evade detection, this script encodes both server-side and client-side files [10].
(Note: this could be a problem for the future development of this project, as the keys of
this encryption are obviously not available for malware testers.) Once the initial malware
binary is loaded into the %AppData% folder of the host, it creates two victim identification
files in that same directory: group tag, which contains an unique ID of the infected host,
and client id, which contains an ID of the current infection campaign or version of the
configuration [11].
In order to ensure persistence upon termination or a system restart, TrickBot creates a
scheduled task (taskeng.exe) on the system startup, so that whether if there is an attempt
of killing the process, or if the computer is restarted, TrickBot is automatically restarted
by the Task Scheduler Engine. It also attempts to disable any possible antivirus protection
such as Windows Defender [12].
When all the previous steps are completed, TrickBot connects with a server (via an HTTP
GET request) to reveal the victim’s public IP. Then, it starts downloading different mod-
ules and configuration files in the %AppData% \Roaming folder, with names such as
”Modules”, ”winapp”, ”netdefender” and ”services”, depending on the TrickBot version
[6]. The files are loaded encrypted from the botnet command and control (C2) servers,
and the purposes of these modules are the following [3]:
injectDll32 module: monitors websites that banking applications use and injects
into the browser in order to get the users’ credentials when they log into them.
networkDll32 : scans the network and steals personal credentials and other relevant
network information.
pwgrab32 : steals credentials and information such as names, passwords, cookies,
search history, autofills and HTTP posts, from popular applications and search
engines like Filezilla, Microsoft Outlook, WinSCP, Google Chrome, Mozilla Firefox,
Internet Explorer and Microsoft Edge.
importDll32 : steals browsing history, plugins, cookies and other browser data.
systeminfo32 : gathers information like the OS, CPU, memory, user accounts and
lists of installed programs and services of the infected system.
mailsearcher32 : collects email addresses for spam campaigns by searching the in-
fected system’s files.
shareDll32 : helps Trickbot spread itself secretly across the network by moving lat-
erally via network shares.
When all the initial configurations are on place, the bot is ready to receive commands, so
14
it begins to execute and inject the different processes that the modules explained above
are responsible for [11].
At this point in the attack process of TrickBot, all the downloaded libraries are ran into
Svchost processes (svchost.exe), which enable the execution of the DLL files. Now, when
a targeted bank‘s webpage is visited through Chrome, Firefox, Internet Explore or Edge,
the web injection process begins [3] [6], and there are two different methods that can be
used: redirection attacks and server-side injections [12]. Let’s see what they do:
Redirection attacks (static injection): when victims navigate to certain targeted
banking websites, they are redirected to fraudulent web site replicas which are
hosted on the Command and Control (C&C or C2) server. This is done thanks
to the HTML or JavaScript codes injected into the browser by the running mali-
cious processes. Once the redirection has been completed, the victim is displayed
an alternate webpage updated with the attacker’s malicious code so that, when he
or she tries to log in the website, the C&C server harvests the victim’s information.
It should be noted that this kind of redirection attack has not been observed since
September of 2019. This process can be seen in Figure 2.
Server-side injections (dynamic injection): the web inject server injects additional
code into the webpage after it is retrieved from the original banking site. This code
is injected before it is returned to the client, so that when the victim submits his
or her credentials, this information is redirected to the C2 server through the use of
form-grabbers. This process can be seen in Figure 3.
In both methods, when comparing the URL addresses from a clean machine and an
infected machine, both websites look alike and it is not possible to tell apart which one
of the websites corresponds to the infected machine [6]. However, when examining the
source code of the website, it can be appreciated that the codes differ from each other,
and the injected codes contain cookie information [3].
15
Figure 3: Dynamic Web Injection TrickBot [12]
16
municate among them privately; this means hiding from both the user and the host.
NAT Network: internal network where outbound connections allowed too.
Host-only networking: connectivity between a host and one (or more) virtual ma-
chines, but not to the Internet.
2.4 INetSim
INetSim is a software that simulates common internet services like DNS, HTTP, SMTP
or POP3 in a lab environment. This project was born in the need of performing network
analyses of unknown malware samples without compromising the network, and it provides
fake services which can be configured by the user [17].
The INetSim tool can work in two different modes:
fake mode: the fake server delivers a pre-configured file depending file extension in
the HTTP requests. With this default mode, the same file is delivered for different
requests if the extension is the same.
real mode: the server delivers existing files from a web root directory, responding
with specific HTML files that correspond, not only to the file extension in the HTTP
request, but also to the file name. Also, the HTML files can access the resources in
the web root directory, such as images, gifs and other HTML files.
2.5 Burp
Burp is a security testing application created by PortSwigger, and it contains multiple
features to support both automated and manual security testing of web applications. It
includes different tools such as a proxy server, that can be used to intercept, inspect and
modify the traffic between the browser and the end application. Burp also provides a
vulnerability scanner, as well as a repetitor to modify and resend individual requests to
the server [18].
17
2.6 Evasion Techniques
Malware’s behaviour in a closed sandbox environment can vary from the one in a non-
controlled system. Depending on how it was developed, malware is triggered by different
artifacts of the infected system, and these said artifacts can vary from a normal system
to a controlled one in order to avoid begin analyzed [19]. This could be a problem for the
development of the project, as the samples could remain dormant if they detected that
they were running in a sandbox.
The basic checks performed by malware for anti-sandbox are: MAC address detection,
process discovery, registry detection, hook function check and hard drive size check [20].
The lack of user activity can also give a clue on the type of environment. Also, there are
some artifacts that are only characteristic to be left behind by the virtual environments.
These are [19]:
HKLM/SOFTWARE/Oracle/VirtualBox Guest Additions
HKLM/HARDWARE/ACPI/DSDT/BOX
WINDOWS/system32/drives/vmmouse.sys
WINDOWS/system32/vboxhook.dll
WINDOWS/system32/vboxdisp.dll
When the malware executing finds any of these, it may stop running, which makes the
task of studying it very hard.
In order to solve this problem, there are some evasion techniques that can be studied and
implemented in the environment so that it looks more realistic at the eyes of the malware
[19]:
Removing VirtualBox Guest Additions
Add and update programs to the guest VM
Run anti-vm detection scripts
2.7 HHTrack
HHTrack is a free and offline software browser utility that allows to download and clone
a World Wide Web site from the Internet to a local directory. It builds all directories
recursively, getting HTML, images and other files from the chosen servers, and it arranges
all these files as in the original site’s relative link-structure. The result is an offline mirrored
website that can be navigated as if it was online [21].
18
2.8 DNS Spoofing
The Domain Name System (DNS) is Internet’s phonebook and it translates domain names
to IP addresses. With this protocol, it is possible to temporarily store in the Operating
System the website name with its correspondent address in order to speed up the resolution
process; however, this cache can be poisoned. The poisoning (or pollution) of the DNS
cache consists on inserting unauthorized domain names or IP addresses into it. With
this, attackers can ”spoof” DNS responses that look as if they came from legitimate DNS
servers and redirect their victims to the wrong destinations [22].
19
3 Methodology and Project Development
This chapter explains the project methodologies used to answer the research questions
laid out in section 1.1, as well as the problems found along the way and how these were
addressed.
20
Use Case Name Run the TrickBot binary in a Windows environment.
Description The TrickBot samples have to be run in a Windows Guest machine.
Actor User
The malicious binary cannot infect neither the outside world or the
Requirements physical computer on which the analysis is performed, so the Guest VM
needs to be a safe environment without access to the Internet.
The samples are submitted from the Host machine to the Guest
Flow
machine, where they can run ”freely”.
21
3.1.3 System Design
In order to fulfill the requirements defined in the section above, different designs were con-
sidered. The first chosen layout was formed by four main elements: two virtual machines
(one with Ubuntu and the other one with Windows 7), Cuckoo sandbox and INetSim. In
this system, the Ubuntu machine would perform as the Host for Cuckoo sandbox, while
the Windows machine would perform as the Guest and it would be run inside the Host
as a VM. INetSim would be the provider of services for the guest, and its server would be
hosted in the Ubuntu machine, too. Here is the overview of how the environment would
be set up:
The Host of Cuckoo’s infrastructure is the one that runs the core component of the
sandbox and manages the whole analysis process; it is the underlying operating system
on which Cuckoo runs. On the other hand, the Guests are the isolated environments where
the malware samples get actually safely executed and analyzed [16].
For this architecture, the Cuckoo host (with OS Ubuntu 16) would be deployed as a Virtual
Machine in VirtualBox 6.1, which would be installed in the memory of an external SSD
connected to a laptop running Windows 10. Inside the Ubuntu VM, VirtualBox (5.2)
would be installed. In this second Virtual Box, the Guest VM with OS Windows 7 would
be running.
Regarding INetSim, it would be installed in Ubuntu’s system. The fake server would
be deployed and connected to the Windows 7 virtual machine with a Host-Only network
interface, so that the guest VM could only have access to the services provided by INetSim.
The problem with this design was that, considering the behaviour of INetSim, all HTTP
requests for the same extension files would get the same response from INetSim’s server,
even if they were different (see section 2.4). In order to be able to modify the responses
from INetSim to the guest Windows machine, another element was introduced in the
design: BurpSuite. This tool would allow the interception and alteration of the traffic
22
between the victim machine and the INetSim server, and it would have to be installed in
the Ubuntu 16 machine. This way, the final set up would look as it follows:
The flow of this system for the malware analysis process would be the following one:
23
From Cuckoo’s web interface or command line, a malware sample is submitted to the Host,
where the user can define the settings on which the binary will be executed. Then, the Host
activates the Guest VM and places the malware sample inside the Guest’s system. During
the execution of TrickBot, the agent gathers information about what is going on inside
the VM, such as registry changes or network connections. Once the test is completed, this
data dump is sent to the Cuckoo’s analyzer which, after analyzing it, will send the results
back to the host to be displayed in the Web interface, or to be inspected in the storage
directories.
The first step of the installation was to install VirtualBox (6.1) in the laptop running
Windows 10. Then, the first virtual machine was deployed with 200GB of memory, 2
processors, 4GB of RAM and the operating system Linux Ubuntu (16.04 64-bit desktop).
24
Once the Ubuntu machine was deployed, the installation of Cuckoo Sandbox began. The
documentation on the Cuckoo website [24] on how to do this was very straight-forward.
First, Python 2.7 was installed (Python 3 is not supported by Cuckoo [25]), as well
as MongoDB for the deployment of Cuckoo’s web interface, and VisualCode for edit-
ing code and configuration files. Also, some software packages from the apt repositories
were required: python-pip, python-dev, libffi-dev, libssl-dev, python-virtualenv,
python-setuptools, libjpeg-dev, zlib1g-dev and swig. In order to capture and dump
the network activity performed by the malware during its execution, the network sniffer
tcpdump was installed.
After the Ubuntu host was set up, a cuckoo user was created in the machine and added
to the vboxusers group. From now on, this would be the user for installing and running
the Cuckoo sandbox, and for creating and running the guest machines. Cuckoo was in-
stalled in an isolated Python virtual environment [26], and its working directory (CWD)
was /home/cuckoo/.cuckoo. Before being able to edit Cuckoos’s configuration files, more
software had to be installed.
VirtualBox 5.2 was installed in the Linux system, as well as its Extension Pack. The reason
for installing an older version than the most recent one, was that cuckoo only supports 4.3,
5.0, 5.1 and 5.2 [25]. Once VirtualBox was installed inside the Ubuntu virtual machine,
the Guest machine could be set up, following the steps defined in Cuckoo’s documentation
[27]. First, a 32-bit Windows 7 image was downloaded (Windows 10 is not supported by
Cuckoo), and the virtual machine was deployed with 50GB of memory, 1 processor and
1GB of RAM.
25
Then, Python 2.7 was installed in the guest machine, along with Pillow (for capturing the
screen of the machine). Also, in order to make the guest vulnerable and being able to study
the malware, Windows Firewall and the Automatic Updates of the machine were disabled.
As it was mentioned in section 2.1, TrickBot is introduced in systems via a Microsoft Word
or Excel document, so Microsoft Office had to be installed in the Windows 7 machine,
too. Once the Guest was up and running, a Host-Only adapter (vboxnet0 ) was created
in the Host VM, so that the Guest VM could have access to the host, but not to the
Internet. Then, in the Windows 7 VM configuration, that adapter was set as the only one
for the machine. With this configuration, the IP address of the host was set automatically
to 192.168.56.1 for the vboxnet0 interface. However, the guest’s IPv4 settings had to be
configured manually:
The Guest’s machine IP was set to 192.168.56.101 and, its default gateway was set to the
Host’s IP 192.168.56.1, as well as its preferred DNS server, so that all the requests would
go directly to the server of INetSim.
Last, per-analysis routing in Cuckoo required IP forwarding to be enabled, so it was
configured from Ubuntu’s terminal:
$ echo 1 | sudo tee -a /proc/sys/net/ipv4/ip_forward
$ sudo sysctl -w net.ipv4.ip_forward=1
26
INetSim
Now that both host and guest were ready and connected by a Host-Only network adapter,
INetSim could be installed in the host. An INetSim working directory inetsim wd was
created in /home/cuckoo in order to keep the original configuration files as a backup.
From this directory, the server would be set up and launched. INetSim was configured so
that it could simulate all the needed services on the configured IP address of the host;
for that, in the file inetsim.conf in /home/cuckoo/inetsim wd/inetsimconf/, the service
bind address was set up: service bind address 192.168.56.1 . Also, in order for the
domain name to resolve to the IP address of the Ubuntu host, in the same file, the DNS
default ip was defined: dns default ip 192.168.56.1 .
In order to test whether INetSim had been properly configured, the server was started
with: $ sudo inetsim --data data --conf inetsimconf/inetsim.conf
and, from the Windows 7 VM, http://google.com was accessed. Instead of the Google
website, the default HTML INetSim page appeared:
Now that INetSim was up and running, the only set up left to do was editing Cuckoo’s
configuration files stored in the CWD /home/cuckoo/.cuckoo, taking into account that
the IPs of the host and the guest were 192.168.56.1 and 192.68.56.101, respectively. First,
in /conf/cuckoo.conf, the machinery and the result server were set:
machinery = virtualbox
[resultserver]
# Result server used to receive behavioural logs
ip = 192.168.56.1
Secondly, in /conf/routing.conf, INetSim was configured so that Cuckoo knew where to
find the INetSim instance in order to route all traffic to it:
[inetsim]
# Route a VM to your local InetSim setup
enabled = yes
server = 192.168.56.1
It needs to be taken into account that the Cuckoo Rooter would have to be launched in
order to use INetSim with the sandbox. The Cuckoo Rooter provides root access for some
commands to Cuckoo (which usually runs as non-root) [28].
27
Then, before setting up the file /conf/virtualbox.conf, a Python file agent.py had to be
transferred from Cuckoo’s directory /agent to the guest machine’s Startup folder. What
this agent would do is launch a small API server for the host to talk to [27]. In order to
prevent the console window from spawning, which could alert the trojan running in the
sandbox environment, the file was renamed to agent.pyw. The first snapshot of the Win-
dows 7 system was taken while the machine was running, and it was named ’Snapshot1’.
This was achieved by executing the following commands in Ubuntu’s terminal:
$ VBoxManage snapshot Win7 take Snapshot1 --pause
$ VBoxManage controlvm Win7 poweroff
$ VBoxManage snapshot Win7 restorecurrent
Next, in the Cuckoo configuration file for VirtualBox (/conf/virtualbox.conf ), the mode
was set to GUI (for interaction with the Guest machine while the binaries were executing).
Also, the Windows 7 machine was chosen as the destination for the malicious binaries,
as well as the snapshot from which the machine would start the Guest VM, and also to
which it would be restored after every submit.
[virtualbox]
mode = gui
[cuckoo1]
label = Win7
snapshot = Snapshot1
In order to make the interaction with the sandbox more visual, the web interface was also
set up. For this, MongoDB had to be set up and started. It was also necessary to have
both the rooter and the Cuckoo debugger up and running. The web interface server was
set up to run in 0.0.0.0:8081, so that it would not conflict with Burp proxy (which would
redirect the HTTP requests to port 8080).
Burp
The last part of the implementation process consisted on configuring Burp. The goal of
adding this proxy to the set up was to intercept both requests and responses between the
guest machine (where TrickBot would be running) and the INetSim server. This way, the
delivered resources to the malware could be altered to make it believe they came from the
real Command and Control servers. Before configuring Burp, the INetSim configuration
had to be modified: in the file inetsim.conf in /home/cuckoo/inetsim wd/inetsimconf/,
the fields http bind port and https bind port were changed from 80 and 443 to 8080
and 8443, respectively. This way, Burp could be configured to listen on ports 80 for HTTP
and 443 for HTTPS and then redirect to INetSim’s interface (192.168.56.1) on ports 8080
and 8443 for HTTP and HTTPS, respectively.
28
Figure 11: Burp Proxy Settings
By default, Burp intercepts HTTP requests without any problem; however, in order to
intercept HTTPS requests and responses, a Burp’s CA certificate had to be installed in
the Internet Explorer browser of the Windows 7 VM. Burp uses this certificate installed
as Trusted Root to create and sign a TLS certificate for each visited host, allowing the
browsing of HTTPS URLs as normal [18].
When Burp was finally configured, the final set up with Cuckoo, INetSim and Burp would
look as it is shown next:
Now that the environment was set up, some TrickBot binaries could be downloaded and
submitted to the Windows 7 VM from Cuckoo. Many websites were accessed for this
purpose but, the most useful ones in the end were Any.Run [29] and VirusTotal [30]. In
the first one, the samples could be downloaded directly from the website: the ones labeled
as TrickBot were filtered and downloaded into the Ubuntu VM. However, for accessing
VirusTotal’s malware database, a request had to be made to the site. When this request
was approved, a random set of malicious samples was provided. This set was then gone
over in order to find the trojan needed for this project. Two types of binaries could be used
29
for the experiments: executable files and Word documents. All these files were downloaded
from the Ubuntu machine usually in a .zip file protected with the password infected, and
were unziped before being submitted to the sandbox.
After submitting multiple binaries, the signatures detected in Cuckoo during the analyses
showed that most of the binaries were not working as expected because, before starting
their performance, they ran some checks on the environment and detected that it was a
virtual machine, as it was explained in the Evasion Techniques section (2.6):
Because of this, some anti-VM scripts had to be executed in the machine. The first choice
for bypassing Cuckoo detection was Zer0m0n, a driver for Cuckoo Sandbox, chosen be-
cause it supported Ubuntu as host and Win 7 x32 as guest. During the execution of the
malware, it performs a kernel analysis, which is harder to detect or bypass than the clas-
sical userland analysis. This driver logs kernel activity during the malware execution and,
in order to log the calls, parameters, registry operations and loading kernel components,
overwrites the pointers to new functions [31]. However, this first script did not work, so
the antivm detection script from nsmfoo was run next. This second script helps to create
templates that can be used with VirtualBox in order to make VM detection harder. It
uses available settings without modifying the VBox base and it creates the following files
[32]:
One shell script: to be used from the host OS (Ubuntu) and applied to the guest
machine (Win7).
A dump of the DSDT used in the template script beforehand mentioned.
A Windows Powershell file to be used inside the guest (Win7) virtual machine. It is
designed to handle the settings that the host cannot and it needs to be run twice.
These scripts went through everything known for a virtual machine that could be refer-
enced within VirtualBox and edited or removed them; for example, the system’s serial
30
number was changed. They also created some random files at the Desktop of the Windows
7 machine in order to make the environment more realistic. The extension of said files
were .txt, .pdf, .docx, .doc, .xls, .xlsx, .zip, .png, .jpg, .jpeg, .gif, .bmp, .html, .htm, .ppt
and .pptx. Apart from running this script, the Virtual Guest Additions were removed
from the guest VM.
After these changes in the guest VM, some trojans still detected that they were in a fake
environment; however, it was a smaller number of them.
31
The first submissions were made from the terminal, without enforcing the timeout on the
analysis. This action also required the activation of the virtual environment, and it was
performed using the following commands:
$ . venv/bin/activate
$ cuckoo submit /path_to_binary
The binaries could also be submitted from the web interface, which made it easier for the
proper configurations to be set up:
Once the sample to be run was chosen and uploaded, the user could define the settings
on which the malicious file would be run. For most of the experiments in this project, the
chosen settings were: using INetSim for network routing, enforcing a custom timeout and
disabling simulated human interaction so that it was possible to interact with the GUI of
Guest VM and so that it could be used to access banking websites without the random
clicks of the simulation getting in the way.
32
Figure 15: Analysis Configurations from Cuckoo’s Web Interface
Once the configurations had been chosen, the analysis could start and the chosen sample
would be executed from the Windows 7 VM (starting it in the previously defined and
restored snapshot). When the GUI of the guest machine was enabled, VirtualBox would
be launched and it would be possible to interact with the Windows 7 guest machine while
the submitted binary performed its malicious activities on the back. This allowed to try
to access different banking websites in order to later study the reaction of the binary to
this actions.
After the analysis was done running, the generated reports could be seen in the folder
.cuckoo/storage/analyses. Inside it, the following files and directories could be found:
analysis.log: trace of the execution in the guest environment (creation of processes,
files and errors).
dump.pcap: network dump (packet traffic) generated by tcpdump.
memory.dmp: memory dump of analysis machine.
files/ : dumped files that the malware operated on.
files.json: meta information of the processes that touched the files in the previous
folder.
logs/ : raw logs generated by Cuckoo’s process monitoring.
reports/ : reports in JSON format.
33
shots/ : screenshots taken during the malware execution of the guest’s desktop.
tlsmaster.txt: TLS Master Secrets captured during the analysis.
These files could be examined either from the terminal or from the web interface (where
they were displayed formatted in a more legible and easy to understand way).
INetSim also generates its own report that covers all the connections made during the
time that the server was running. These reports are stored in /var/log/inetsim/report,
and they are saved as plain text files. The information on the connections could also be
checked at the Cuckoo network’s analysis.
Baseline analysis
Before submitting malicious binaries, a non-malicious file (a pdf in this case) was submit-
ted in order to have a reference point of how the system behaves without any malicious
executable running inside. This way, it would be easier to distinguish between what Trick-
Bot was doing from what the system itself was doing.
In the figure above, the baseline analysis results from Cuckoo are shown. As a simple
.pdf file was submitted, all the activity identified as malicious, would correspond to just
normal checks from the system itself. Among these, there were HTTP requests from the
Windows Update system and some other actions whose studies are out of the scope of
this thesis, but that would be taken into account later in order to not get them mistaken
with actual malicious actions.
34
Any.Run analysis
The previously mentioned app Any.Run used to download TrickBot samples, also provides
the functionality of running malware analysis in the platform, within a limited time, but
with ”real” access to the internet [29]. This online sandbox service was useful for this
project, as it allowed to run the same binaries as in the created environment with Cuckoo
and INetSim and check whether the submitted binaries were performing as expected or if,
on the contrary, the fake Internet server was stopping them from downloading key files.
Any.Run also provided analysis of the submitted binaries, which made the task of choosing
the ”best” samples easier. This online tool also helped identify whether the Command
and Control servers correspondent to each one of the samples was still active or not, and,
if they were, if it would be possible to download the information and files provided by
them to the trojans. Then, these different files could be provided as a response to the
requests of the samples running in Cuckoo’s guest VM through Burp.
3.1.6 Troubleshooting
In order to understand how the web injection works with real C&C servers, a binary
with working final processes svchost.exe would be needed, because they are the ones in
charge of performing the web injection, as it was explained in section 2.1. Also, thanks
to this processes, the targeted websites could be identified, as well as the C2 servers’ IPs.
However, there are many TrickBot versions, and each of them has its own C2 servers, as
well as its own target websites. So, without these svchost.exe processes, it is not possible
to study some random C&C servers with some random banking websites, as it would be
like looking for a needle in a haystack. Of course, without them, the study on the web
injection process cannot be carried out.
After many submits of different binaries, none of them deployed the process svchost.exe for
the web injection in the created Cuckoo sandbox environment. There were many reasons
for this: some binaries detected that they were running in a fake environment and did not
proceed as it was expected from them; despite having executed the antivm scripts, some
trails still gave away the environment’s nature. Additionally, the trojans that could not
connect to their correspondent C&C servers were not getting the needed resources to run.
Even though for this last samples the delivered files and information from old requests
could be downloaded from the Any.Run app and then provided to the Cuckoo sandbox
through Burp, they required the encryption key for decrypting these files, so it was not
possible to modify this information in order to make it match the updated one. This is
because these encryption keys are unique for each infected machine, so reusing data from
other infections was not an option in the end [12].
Even though the first research question about how to create an analysis environment for
TrickBot’s traffic had already been answered in this part of the project, the two others had
not. This problem forced the project to take a different direction and try to simulate how
the process of stealing banking credentials would be done and how it would be studied.
35
3.2 Web Injection Study
The first part of the project tried to address all the research questions set out in section
1.1. However, only the first question about how to create an environment to analyze
TrickBot’s traffic was answered successfully. There were still some gaps left to solve from
the other two: How does TrickBot steal banking credentials from its victims? And how
does the web injection process work?
This is why the second part of the project focused on creating a system to steal banking
credentials from a victim with the tools available and the time left. In order to have
continuity with the previous section 3.1, the plan was to reuse the previous infrastructure
and stick to TrickBot’s flow and methods as much as possible.
36
site, so that the credentials would be sent to another server (that would need to be
set up outside the victim’s system) after their submission. Regarding the detection
of the targeted site, it would have to be either done manually, or set up in Burp.
INetSim would not be needed in this scenario.
After studying these three possibilities, the chosen option was B, as it was not as simple
as A, and also not as complicated as C, for which there was no time left for implementing.
This is because the initial goal of the project was to study this process of code injection
from actual binaries; however, as this was not possible, it would take a lot of additional
research to figure out how it would have worked. If recreating the whole process had been
the initial goal all along, if would have been possible to implement option C. Unfortunately,
for the moment, the course of this project had to follow option B.
37
Use Case Name Victim uses Internet as usual, except for targeted websites.
The user of the system can access Internet as usual and navigate
Description
through the websites, except for the targeted ones.
Actor Victim
Have an Internet connection.
Requirements
Define one or more targeted websites.
The user browses through the Internet without any problems or being
Flow
redirected anywhere, until trying to access a targeted website.
Victim accesses the fake website in the C&C server where he or she
Use Case Name
can enter the credentials for the banking site.
The C&C server hosts an exact replica of the targeted website page
Description with a form that would usually work for entering the bank’s private
area.
Actor Attacker
Have a custom C&C server hosting a replica of the banking website.
Requirements Have the form that usually redirects to the user’s personal area
redirected to the attackers.
The fake website is displayed for the victim, but he or she cannot be
Flow able to see the difference in plain sight. The victim can submit the
credentials to the private are of the bank in the usual form.
38
Use Case Name Victim’s credentials are sent to the attacker’s server.
After the user enters the credentials in the fake page, these are sent
Description
to another server, where the attackers can access them.
Actor Attacker
Redirect the credentials form.
Requirements
Have another server for retrieving the information.
Victim enters the credentials and these are sent to an attacker’s
Flow server, instead of to the original banking site. The victim is
redirected to a loading page.
39
server from inside the victim’s system (Windows 7 VM, in this case), this was the option
chosen in order to make it more realistic. This resulted in Burp not acting as a proxy
anymore for this second part of the project.
Once the location where the redirection would happen was decided, it was time to design
the method. The main problem was which network adapters to choose for the Windows
machine to connect to Ubuntu, where the INetSim server would be hosted. Once again,
multiple options were considered:
Setting up two network interfaces: Host-Only to connect to INetSim, and NAT to
connect to the Internet. In this scenario, a script would choose the DNS server to
use depending on the request (NAT’s DNS server for normal traffic and Host-Only’s
DNS server for requests to Paypal).
Only using a NAT network adapter and redirecting the requests to Paypal to the
INetSim server hosted in 192.168.56.1. In this scenario, DNS Spoofing (introduced
in section 2.8) would be used to redirect the Paypal requests to INetSim.
The problem with the first option was that it was very hard to identify the destinations
of the victim’s request in order to choose the correspondent DNS server. This is why, in
the end, DNS Spoofing was the chosen method to be used for the redirection of Paypal’s
website to the fake web server. This attack consists on modifying the IP address of a
determined domain in the DNS cache so that, when the system’s user tries to access that
domain, he or she is redirected instead to the poisoned IP [34].
To sum up, this second part of the project would use both previously created VMs with
Ubuntu 16 and Windows 7 connected by a NAT network adapter (figure 4 but without
Cuckoo for analysis). In Ubuntu’s VM, the INetSim server would be hosting a replica of
the Paypal website and, in Windows’ VM, a DNS Spoofing ”attack” would be performed in
order to poison the victim’s cache and redirect the requests to Paypal to INetSim, instead.
In an scenario where the victim types his or her credentials in the INetSim fake server
and submits them, this information is sent to another server also hosted in Ubuntu’s VM,
where the ”attacker” would be waiting. This second set up aimed to answer the question
of how does TrickBot steal banking credentials by simulating said process.
40
was http fakemode, where http fakemode was set from yes to no. Now, with the real
mode activated, the files desired to return had to be placed in INetSim’s webroot direc-
tory /home/cuckoo/inetsim wd/data/http/wwwroot. It has to be taken into account that
Cuckoo would not be a part of this second environment, as there is no danger on any
malicious binary to escape to the network or the host system.
In order to clone Paypal’s website, HTTrack (introduced in section 2.7) was used. With
this tool, the plan was to replicate both Home and Sign In pages of the Paypal’s website
(see figures 17 and 18), in order to make it as realistic as possible, so that the victim
could see the main page before clicking on the button to log in. If the Sign In page was
the only one hosted in the INetSim server, it would look suspicious and, as the real mode
in INetSim was enabled, it was possible to create the environment with more than one
HTML file.
Let’s take a look at the original look of both home and sign in Paypal’s website pages:
41
Figure 18: Original Log In Page Paypal
Once HTTrack was downloaded in the Ubuntu VM, both the main and the sign in pages
of Paypal’s site were downloaded with HTTrack:
$ httrack https://www.paypal.com/home
$ httrack https://www.paypal.com/signin
Each one of them was stored in its own directory /paypal/home/www.paypal.com/home.html
and /paypal/signin/www.paypal.com/signin.html, along with the corresponding CSS files
and other needed resources.
Then, the downloaded directories were merged in the INetSim web root directory /inet-
sim wd/data/http/wwwroot, where the home.html file was renamed to index.html in order
to have it as the default home page for the server. Another file myaccount.html was cre-
ated in the same directory in order to be displayed when the victim’s credentials were
submitted. This last file only shows a loader for the victim to believe that he or she is
being redirected to his or her Paypal account. So, to sum up, there are three HTML files
in the INetSim server’s web root directory:
index.html : main page of www.paypal.com
signin.html : log in page
myaccount.html : loading page after log in
Now, it was time to rearrange the pages in order to make them perform as the C&C
server. First, the button in the home page redirecting to the real Sign In page (top right
in capture 17) had to be configured in order for it to lead to the custom Sign In page of
the fake server, placed in the same directory. For this, the href code of the button was
changed from www.paypal.com/signin to just signin.html. This was the only change
needed for the main page. Then, for the file signin.html, in the action field of the login form,
action="/signin.html" was replaced with action="http://192.168.56.1:3000". This
42
critical change would redirect the credentials to a server that would retrieve and display
them for the attacker to see. The details of this server are explained next.
Once the InetSim server was all set, another one was created with the purpose of receiving
the credentials submitted by the victim. This second C&C server was deployed with
Python on the same IP as the Paypal server (192.168.56.1), but it was set to listen on
port 3000. This server’s responsibilities were to get the whole string that the signin.html
page sent, parse it to get both user and password, display it and, finally, redirect the user
to the fake html page myaccount.html that would display a loading message. The code of
this server is displayed in Appendix A.1.
After setting up the C&C servers, the redirection of the requests to Paypal’s site was
configured. As it was mentioned before, this process would be implemented with a cus-
tom DNS Spoofing attack. The ideal DNS Spoofing would be started by the svchost.exe
process; however, as in this project it was not possible to get one to perform in the cre-
ated environment, it was implemented in a script that would be run in the Windows 7
machine. The goal was to change the DNS record of paypal.com to the C&C server’s
IP 192.168.56.1, where INetSim would be up and running and ready to provide the fake
services to the user. So, instead of having 64.4.250.36 or 64.4.250.37 as the DNS response
to www.paypal.com (as the command’s output nslookup indicates in figure 19), it would
be 192.168.56.1.
In order to achieve DNS cache poisoning, the following commands had to be executed
from the Windows 7 command line [35]:
$ ipconfig/flushdns
$ echo 192.168.56.1 www.paypal.com >> c:\windows\System32\drivers\etc\hosts
$ echo 192.168.56.1 paypal.com >> c:\windows\System32\drivers\etc\hosts
The first command flushes all DNS records, it resets them so that the DNS cache can be
edited from scratch. The second command inserts the crafted DNS record in the file hosts
in c:/windows/System32/drivers/etc/, where the DNS cache is stored.
The idea was for the user to access www.paypal.com in the Internet Explorer browser and
then the fake website would be displayed. However, at first, when the user was redirected
to the server in 192.168.56.1, the browser would not allow to go further because of a
certificate problem.
43
Figure 20: Certificate Error with DNS Spoofing
This happened because, as part of the SSL handshake process, the server would need to
send a valid certificate for paypal.com which contains the public key, as it was explained
in section 2.9.
To solve this problem, a self-signed certificate for the server had to be deployed. The
steps for this process were followed from a laboratory on certificates of the course Network
Security from the Master of Cybersecurity in UPC [36]. The steps followed for this process
were:
1. Install openssl in Ubuntu VM.
2. Create the Root Certificate Authority (CA).
3. Generate the certificate for the CA: TFM Root CA
4. Self-sign the certificate for the CA.
5. In the server’s certificate request, set paypal.com as a Subject Alternative Name
(SAN) in order to specify Paypal’s DNS as an additional subject identity.
6. Generate the certificate request for the server.
7. Sign Paypal’s certificate in the CA.
The commands used for creating these certificates are in Appendix A.2.
When the web certificates for paypal ppserver.crt.pem and ppserver.key.pem were created,
they were copied in the directory : /inetsim wd/data/certs so that the INetSim server
44
would provide the right certificates to the browser. Also, this change had to be notified
in the inetsim.conf configuration file in the sections https ssl keyfile and https ssl certfile
where the following changes were made:
1. https ssl keyfile default key.pem was replaced with
https ssl keyfile ppserver.key.pem
2. https ssl certfile default cert.pem was replaced with
https ssl certfile ppserver.crt.pem
Also, the CA certificate had to be imported to the Windows victim’s system as a Trusted
Root Certificate Authority in order for the self-signed Paypal certificate to be identified
as valid. This can be done both from the Internet Explorer browser, or from the Windows
7 command line:
$ certutil.exe -addstore root TFM_CA.cer
This command would be in the same script as the DNS Spoofing commands in order to
execute them all together.
Now that the Root certificate had been installed in the victim’s system, the self-signed
Paypal’s certificate was recognised as a valid one, and the user could be smoothly redi-
rected to the Command and Control server. When displaying Paypal’s custom website,
the site was identified as secure, and the Website Identification looked as it is shown in
the following image:
It can be seen that it is the self-signed certificate of the CA that is identifying the custom
Paypal site as secure, as it is itself who signed its certificate. The details of Paypal’s
webserver certificate show that the issuer for this certificate is the CA created beforehand:
45
Figure 22: Paypal’s self-signed Certificate
46
3.2.6 System Testing
The final flow of this second system would the following:
So, the system would work as follows: first, the Windows 7 victim machine would have
to be connected to the Internet via the NAT to the Ubuntu host machine. Then, both
INetSim and C&C servers would be launched from the Ubuntu host machine with the
script stored in the directory cuckoo scripts/ and named web injection.sh, which contains
the following code:
gnome-terminal -- /bin/sh -c ’echo "INETSIM"; cd inetsim_wd/;
echo ********** | sudo -S systemctl stop inetsim.service;
echo ********** | sudo -S inetsim --data data --conf inetsimconf/inetsim.conf;
bash’
gnome-terminal -- /bin/sh -c ’python cc_server/cc_server.py’
47
The script above first launches the INetSim server, after stopping any other services that
could be already running. Then, the Python server is launched from another terminal.
Once the C&C servers are up and running, the Windows 7 machine could be started
from VirtualBox, and the ”malicious” .bat script would be executed from it. This would
start the process created as a replacement of the web injection attack for stealing the
banking credentials. This script text.bat file executes the DNS spoofing attack and the
fake certificate installation, and it contains the following code:
:: This batch file simulates TrickBot Web Injection
:: DNS Spoofing
ipconfig/flushdns
echo 192.168.56.1 www.paypal.com >> c:\windows\System32\drivers\etc\hosts
ipconfig/displaydns
:: Trusted Root Certificate for CC server
certutil.exe -addstore root TFM_CA.cer
The outcome from the script above is displayed below:
48
Figure 25: Outcome of execution of the Attack Script
In the image above, it can be appreciated how the DNS records for www.paypal.com and
paypal.com have been poisoned and they now point to the INetSim server. The details of
the CA certificate can also be seen in the terminal and be compared to the issuer in figure
21.
Of course, before executing this script, the certificate file TFM CA.cer had to be imported
to the Windows 7 machine and placed in the same directory as the script in order to be
accessible to it. It has to be taken into account that all these steps were supposed to be
executed by a process created by the malicious TrickBot binary or, at least, a process
49
that simulated its behaviour. However, because of the complications found and the lack
of time at this point of the project, these last steps had to be done manually by accessing
the victim’s machine directly.
Once that the Windows 7 machine had been ”infected”, it was only a matter of time
before the user tried to access the Paypal website. When this happened, he or she would
be redirected to the InetSim server in 192.168.56.1, as it is shown next:
Then, when the user clicks on the Sign In button, as he or she is now navigating in the
fake server, the redirection will be to the fake sign in page:
50
When comparing the images above, it can be appreciated that they do not differ from
the original Paypal pages (see figures 17 and 18). Even the URLs displayed are the same
ones, and the page is identified as secure with the lock on the search bar.
After entering the credentials on this fake login page, when the user submits the inserted
data, he or she will be redirected to the loading page:
Meanwhile, on the server side, the InetSim server would have redirected the credentials
to the Python C2 server, where they will be parsed and displayed:
If these credentials are compared to the ones on image 27, it can be seen that they are
the same.
Now the attacker would be in possession of the needed information to access the victim’s
bank accounts while the victim waits innocently for the Paypal site to load.
In order to appreciate the resemblance between the flow of original static web injection
process and the developed custom one, figures 2 and 23 can be compared.
51
4 Results
After developing a malware analysis environment to study TrickBot’s behaviour and sim-
ulating an attack to steal banking credentials, these were the results obtained for each
one of the experiments:
This executable looked very promising for the experiment, so it was submitted to the
Cuckoo sandbox in order to study its behaviour. After running it for the first time in the
Windows 7 VM, the analysis of sample was displayed in the web interface:
52
Figure 31: Summary Cuckoo Analysis of TrickBot’s sample 1.
Figure 31 just shows a general analysis of the submitted sample: size, type of file, and
signatures. On the other hand, figure 32 shows a more specific analysis on the malicious
actions that the sample has performed in the VM during its execution. Some of these
warnings were ignored because the baseline analysis (section 3.1.5) showed that they were
rudimentary actions performed by te Windows 7 VM itself. The most suspicious signatures
(and the most interesting for the purpose of this project) are the network ones. Among
the HTTP requests, it can be seen how the sample has tried to connect to a server that,
at first sight, can appear to be a Liverpool news website. However, when submitting this
link to VirusTotal, it identifies it as a malicious Command and Control server:
53
Figure 33: VirusTotal detection of link as C&C server.
Considering the previous analysis on Any.Run [37], the response to this HTTP requests
from the C&C servers provides encoded HTML files to the malicious sample. The hy-
pothesis that these HTML files should contain more resources for the TrickBot sample
to elevate privileges and infect the victim’s system was consolidated after checking that
the sample would not perform any more malicious actions inside the system after sending
the HTTP requests. This was because in Cuckoo Sandbox, the responses from the C&C
servers were fake, so the malware did not get the needed resources to continue while, in the
original analysis in Any.Run [37], it did. So, in order to provide these files to the running
malware, the HTML files were downloaded from the Any.Run analysis. Unfortunately,
when trying to provide them on the C2 responses to the Windows 7 VM, Burp collapsed
because they were too big to handle.
54
Figure 34: HTML file loaded for HTTP response for malicious sample running on
Cuckoo Sandbox
On top of that, when trying to submit this same sample again to App.Any.Run to check
whether the C2 servers were still active or not, the response received from the server was
different from the one on the original analysis. Instead of getting a 200 OK response,
the server responded with a 203 Non-Authoritative Information. This 203 code means
that the petition was satisfactory, but the content has been modified by a proxy since
its 200 OK origin [38]. Also, the responses’ payloads from the C2 servers were different
and, even if the first URLs accessed by the malicious binary were detected as malicious
by VirusTotal, the links that they redirected to, were not. It can only be assumed that,
by the time they were accessed, the servers were already down.
Any.Run also offered the possibility of downloading specific executable files, so the fi-
nal binary identified by the app as TrickBot was downloaded and submitted to Cuckoo
Sandbox on a parallel analysis. However, it was not enough, as the sample needed the
previous processes that elevated privileges in order to perform as expected and steal the
web credentials. At this point, any hopes of getting any new information by testing this
sample in Cuckoo were gone.
55
4.1.2 App.Any.Run executable 2
The second promising binary was also downloaded from Any.Run [39]. It was chosen
because its analysis was the one explained in Any.Run’s report about TrickBot [40], and
its IOCs indicated that svchost.exe was among its deployed processes:
Cuckoo sandbox’s summary of this sample indicated that the type of file submitted was
a Microsoft Word document:
56
When this Word document was opened in the sandbox, it required the user to enable the
macros in order to see the ”full” content:
The macros were enabled manually thanks to the GUI mode of Cuckoo’s Guest machine.
Then, TrickBot unpacked itself into the Windows 7 system and it tried to connect to a
C&C server, as it can be seen in Cuckoo’s later network analysis:
The requested file from TrickBot to its C&C server had a PGP (Pretty Good Privacy)
extension. These type of files are digital signatures or security keys and they are used
to decrypt files and verify users’ identities [41]. This means that this file’s purpose was
probably to decrypt TrickBot’s payload in order to infect the Windows machine. The PGP
file was downloaded from Any.Run [39], and provided to the Guest machine through Burp.
To accomplish this, TrickBot’s sample was submitted again to Cuckoo Sandbox and, this
time, the request from the malware to the C&C server was intercepted with Burp, as well
as the response (which was INetSim’s default). This response was then altered in order
to provide the file metro.pgp to the Guest.
57
Figure 39: Cuckoo’s request and response to C&C servers from TrickBot’s sample 2.
Even though this task seemed to had been successfully achieved (see picture 39), there
was no deployment of the svchost.exe processes after that, as it was expected to happen
when inspecting Any.Run’s original analysis on the same sample. On Cuckoo’s process
tree, only timeout processes were spotted, as it can be seen in picture 44 at the end of
this section.
It was mentioned in the state of the art (section 2.1) that TrickBot’s encryption keys are
unique for each infected machine, so this must be the reason why the trojan running in
Cuckoo Sandbox was not able to use the old PGP file to decrypt its payload.
Going back to the online analysis, it can be seen that this sample actually loads three
different svchost.exe processes.
In fact, the second one makes multiple registry changes in order to disable the requirements
of a certificate to be trusted (CertificateTransparencyEnforcementDisabledForUrls). This
is applied to a series of urls that, unsurprisingly, are from banking websites.
58
Figure 41: Registry changes performed by SVCHOST process in Any.Run TrickBot’s
sample 2.
Apart from the registry changes of the svchost process, the online analysis of its parent
also shows the creation of files in the program directory. These files in particular are the
ones referred to in section 2.1 as the modules in charge of monitoring banking websites
and injecting into the browser for credential stealing.
Figure 42: Modified files by SVCHOST ’s parent process in Any.Run TrickBot’s sample 2.
The original analysis provided interesting general information on the behaviour of Trick-
Bot’s sample; however, it did not show how the malware would react to the user accessing
one of the targeted sites, only how it would wait ready for this to happen. So, for now the
web injection process stayed a mystery. In order to give some light into the web injection,
even if did not come from Cuckoo, the sample was run in Any.Run again. The purpose
of this was to try to access one of the targeted banking sites before timeout, and see how
59
the malware would react. However, the HTTP request for the PGP file did not receive
any response so, again, the project was stuck because of encryption keys and C&C servers
that were already down.
60
4.1.3 Results Infrastructure 1
After an exhaustive search for a sample of TrickBot that allowed to study the web injection
process in Cuckoo sandbox, no useful ones were found.
The ideal procedure with the deployed infrastructure would have consisted on detecting
TrickBot’s web injection using Cuckoo to analyze the HTTP traffic between the guest
system and the Internet (INetSim, in this case). The idea was to extract the injection code
from the HTTP requests; for example, for a static injection attack the HTTP requests
with injected code on the browser would have provided a great deal of information that
could have been inspected either at the end of the Cuckoo analysis and also on the fly
with Burp. This would have helped answer the research question on how does the web
injection process work.
Despite the difficulties to perform the analysis described above, a great deal of information
about TrickBot, malware analysis environments and Command and Control servers was
found on the analyses performed. From the different experiments, it is clear that each
variant of TrickBot is very different from their sisters: even though they follow the same
line of behaviour, they all differ from each other in some way: some of them download
their resources from a Command and Control server right at the beginning of the infection
process, while others only access them to get the necessary files to unencrypt the unpacked
resources. Depending on TrickBot’s version, the injection processes can be either dynamic
or static (despite not having witnessed any of them), and even the techniques for detecting
whether a binary is running in a virtual environment or not can vary from one another.
Carrying out a dynamic analysis on a sample that connects to C2 servers can become
a challenging task if the servers are already down by the time of the study. Having the
malware create a new key for each one of the infected systems, does not make things
easy either, specially if these are required to connect to these servers, or to unencrypt
the data and payloads of the binaries. However, these results actually provide an extra
value to the research question posed at the beginning of this project (How can an analysis
environment fro TrickBot’s traffic be designed and implemented?) because, even if the
created environment was not as perfect as it was expected for the desired analysis of the
traffic, these findings can be used and applied to future developments of malware analysis
environments.
61
4.2 Infrastructure 2: Web Injection Analysis
For this second infrastructure, the malware was designed instead of downloaded, so the
results for the experiment have to be studied from a different perspective. It is obvious
that the custom web injection simulator deployed in section 3.2 is far from how it was
studied in the Literature Review (section 2.1) that TrickBot would actually perform. In
real life, the malware uses the downloaded libraries injected into the svchost.exe process
to listen to the traffic in the system and intercept the requests to the banking sites. It also
injects the code for either the redirection to the C&C server where a replica of the site
is hosted (static attack), or for the redirection of the response from the banking server
to the web inject servers (dynamic attack). All these actions were expected to be studied
when submitting the binaries in section 4.1 in order to do a deeper analysis on them.
However, because of the encountered complications, a script to perform DNS Spoofing
and simulate the redirection to a server hosting a fake website substituted the injection
study. In this results section it will be seen how the two last research questions about the
credential stealing and web injection operations have been answered, even if it was not
the way it was expected at the beginning of the project.
The result of the second part of this project is a system that infects the victim’s operating
system (from inside), poisons its DNS cache and installs a Trusted Root Authority Cer-
tificate. The DNS Spoofing achieves the redirection of the user from the site paypal.com
to a crafted server that hosts a malicious replica of it. In this clone of the web, the form
that would normally allow a user to sign in to his or her Paypal’s account, leaks the log
in information to another server hosted by the attackers, stealing the credentials of said
user.
Comparing this system to a redirection attack that TrickBot would perform, the DNS
Spoofing process substitutes the listening of the victim’s traffic until one of the targeted
sites is accessed. The cache poisoning also covers what would be the web injection part
where the malicious deployed processes inject the code into the browser in order to redirect
the victim to the attacker’s custom server. The phase of this project that simulated the
cloning of a banking site in order to display it to the victim as the original one was
a successful task that really resembled its TrickBot model. As it was seen in section
3.2.6, only a few lines of code were needed in order to transform the original website
(downloaded with the free tool HTTrack) into an altered one that redirected sensible
data to an attacker’s server.
If the homemade malware was submitted in Cuckoo, it could be detected by checking the
DNS network analysis, where it would be seen how the IP to which paypal.com should
resolve is not the same to the one providing the services to the ”malware”.
62
4.3 Discussion
A combination of both deployed infrastructures gave a wide vision on TrickBot’s behaviour
and also on malware traffic analysis. One of the interpretations from the development of
this project was that even if sandboxing can be a very efficient and safe way of analyzing
malware, too much safeness can backfire and get in the way of the study. Also, as interest-
ing as it can be to focus an study on only one part of the life cycle of an specific malware,
it could probably be more efficient to broaden this study to the whole life cycle of the
malware. This would give a better understanding of its purposes and methods rather than
trying to run many different versions without fully understanding what could be going
wrong with each one of them.
In addition to this, the dynamic analysis on various samples of TrickBot, a malware
that requires external connections to its Command and Control servers, showed that a
combination of both static and dynamic analysis would lead to a better understanding of
the trojan. Once again, this is because even if a previous analysis was done on TrickBot,
there are so many versions running around and behaving so differently that trying to
understand only one small part of them can lead to confusion and mix up of the different
infection mechanisms among the multiple versions.
Regarding the complexity of TrickBot’s attack, it seemed that, from an attacker’s perspec-
tive, the most simple part of this whole process would be the last one, which only requires
to host a cloned website and change a few lines of its code. On the other hand, taking
into account how fast malware can be identified and warned about nowadays, keeping
the updated Command and Control servers up and running can hold a bigger complexity.
There are multiple tools such as VirusTotal and Any.Run that keep the world updated
on the new C2 servers and malicious files. This last thought also applies to the first steps
of TrickBot’s behaviour that involve downloading and encrypting the resources, as well
as elevating privileges and staying hidden from antivirus software (remember that for the
first project Windows Defender was deactivated). And last, but not least, a trick as simple
as having a Word document macros enabled must really simplify the infection process for
an attacker to enter into the victim’s computer.
63
5 Conclusions
The objectives proposed at the beginning of this project have been partially achieved:
in order to answer the first research question of the objectives ”How can an analysis
environment for TrickBot’s traffic be designed and implemented?, a closed sandbox envi-
ronment where malicious TrickBot samples could be safely submitted was designed and
implemented. During the development of this system, a better understanding on virtual
machines, their network connections and how to adapt them for dangerous malware anal-
ysis was acquired. Also, many useful tools such as INetSim and Burp were discovered, as
well as how to integrate them with a sandbox. A very powerful tool was found in Cuckoo
Sandbox, as it provided a wide range of options for the submission of samples. It also
provided detailed and explained analyses after those, which helped to get a better under-
standing on the trojan’s behaviour, specially on its generated traffic and its connections
with the Command and Control servers. However, the development of this project would
not have been possible without the help of online tools such as Any.Run. The combina-
tion of this two provided both the flexibility from Cuckoo and, of course, the Internet
connection of Any.Run, as well as its previous analyses that served as a guideline for the
ones later run at Cuckoo sandbox.
While the execution of multiple safe dynamic analyses was a success, the desired enlight-
ening over the web injection process from these was not. The main responsible factors for
this were the outdated Command and Control servers, the anti virtual machine detec-
tion mechanisms and the unique encryption keys needed for accessing the full payloads of
the samples. However, the research question ”How does TrickBot’s web injection process
work?” did not remain fully unanswered, as from both systems there was some information
gathered on this attack. For example, the first infrastructure provided some knowledge
about the trojan’s Command and Control servers which, as it was studied in the Litera-
ture Review in section 2.1, played a very important part on the web injection process. The
analyses obtained from Any.Run also helped to understand better how TrickBot prepares
for the web injection attack. Moreover, the second system required a deep understanding
on all the possible methods for web inject, before choosing the most suitable one for the
simulation that would be later carried out.
On the other hand, the second infrastructure implemented during the project did con-
tribute to answer the second research question from the objectives: ”How does TrickBot
steal banking credentials from its victims?”. Designing the simulation implied thinking
as a hacker and contemplating multiple possibilities of how to infect the victim’s system
and steal the sensible data.
Both the development of the sandboxing system and the results and findings obtained
from it are expected to serve as a guide to future malware analyses, which will be able
to follow the most convenient recommendations according to the requirements for each
specific study. On the long term, this will also help to protect the customers of online
banking services, as the more it is known about banking trojans, the easier it will be to
defeat them.
64
6 Future development
When looking at the project and what was achieved through the finished system, several
aspects could have been done in a different way or improved. The first area would be to
find a TrickBot sample that actually gets to the point of performing web injection process
and study it from the Cuckoo Sandbox.
Another area that was discussed during the project (specifically in section 3.2.1) but
turned out to be too much work, was the implementation of the dynamic injection process
for the second system. This would consist on having Burp acting as the webinject server
and injecting the code on the response to the victim’s request. The injection code would
be added manually on the interception of the request from the banking site, so that the
credentials would be sent to another server (that would need to be set up outside the
victim’s system) after their submission. Regarding the detection of the targeted site, it
would have to be either done manually, or set up in Burp.
Regarding the anti-vm detection problems, some samples detected the virtual environment
even after the execution of the scripts described in section 3.1.4. A possible solution for
this could be to modify one by one all the artifacts that differ between the real and the
fake environments and that give away the virtual machines, complicating the malware
analyses.
Finally, in order to fulfill the long-term objective of the project to protect the users of
online banking services from TrickBot, a study on how to detect this trojan, as well as
how to stop it from infecting its victims should be carried out in continuity to this project.
65
References
[1] R. Cohen, “Banking Trojans: A Reference Guide to the Malware Family Tree,” F5
Labs, Aug 2019.
[2] J. Johnson, “Top banking trojans worldwide 2020,” Statista, May 2021.
[3] R. Celik and A. Gezer, “Behavioral Analysis of Trickbot Banking Trojan with its
New Tricks,” International Journal of Technology and Engineering Studies, vol. 5,
2019.
[4] L. Llc, “Analysis of TrickBot Malware – the most prolific COVID-19 themed mal-
ware,” Jul 2020.
[5] “Trickbot still alive and well,” Jan 2021.
[6] A. Gezer, G. Warner, C. Wilson, and P. Shrestha, “A flow-based approach for Trick-
bot banking trojan detection,” Computers and Security, vol. 84, 2019.
[7] “TrickBot comes up with new tricks: attacking Outlook and browsing data,” Nov
2020.
[8] “Spyware.TrickBot,” Nov 2020.
[9] “BacktrackAcademy: Usando el exploit EternalBlue de la NSA.”
[10] “TrickBot disrupted,” 2021.
[11] M. Salinas and J. M. Holguı́n, “Malware report - Evolution of Trickbot,” 2017.
[12] “Blog: TrickBot: Not Your Average Hat Trick - A Malware with Multiple Hats,” Apr
2021.
[13] “¿Qué es la virtualización?,” Mar 2018.
[14] “Oracle VM VirtualBox,” 2021.
[15] “Virtual networking,” 2021.
[16] “Sandboxing — Cuckoo Sandbox v2.0.7 Book,” 2021.
[17] T. Hungenberg and M. Eckert, “INetSim: Internet Services Simulation Suite,” 2020.
[18] P. Swigger, “Burp Suite - Application Security Testing Software,” 2021.
[19] T. Muhovic, “Behavioural analysis of malware using custom sandbox environments,”
2020.
[20] T. Roccia, “An overview of malware self-defense and protection,” 2016.
[21] X. Roche, “HTTrack - Website copier,” 2017.
[22] B. Lazarevski, “Anatomy of a DNS Cache Poisoning Attack,” oct 2021.
[23] J. H. Serrano, “Transport Layer Security (TLS),” oct 2020.
66
[24] “Sandboxing — Cuckoo Sandbox v2.0.7 Book - Installation - Preparing the Host,”
2021.
[25] “Sandboxing — Cuckoo Sandbox v2.0.7 Book - Installation - Preparing the Host -
Requirements,” 2021.
[26] “Virtual Python Environment builder,” 2021.
[27] “Sandboxing — Cuckoo Sandbox v2.0.7 Book - Installation - Preparing the Guest,”
2021.
[28] “Sandboxing — Cuckoo Sandbox v2.0.7 Book - Usage - Cuckoo Rooter,” 2021.
[29] “Interactive Online Malware Analysis Sandbox - ANY.RUN,” 2021.
[30] “VirusTotal,” 2021.
[31] C. Cybersécurité, “Antivmdetection - zer0m0n,” 2014.
[32] M. Keri, “Antivmdetection - nsmfoo,” 2019.
[33] G. Warner, “What sites is Trickbot targeting?,” Mar 2020.
[34] S. Son and V. Shmatikov, “The hitchhiker’s guide to DNS cache poisoning,” in Inter-
national Conference on Security and Privacy in Communication Systems, pp. 466–
483, Springer, 2010.
[35] A. Colvin, “Adding Windows DNS Records Via Command-Line,” 2013.
[36] J. H. Serrano, “Implementing a root Certification Authority with OpenSSL,” Infor-
mation Security Group of Universitat Politècnica de Catalunya, Oct 2020.
[37] “TrickBot malicious sample 1 from ANY.RUN,” in
https://app.any.run/tasks/ec82a42b-9050-4508-af40-67fe3b8eb3c4/, Any.Run,
Apr 2021.
[38] “203 non-authoritative information,” 2021.
[39] “TrickBot malicious sample 2 from ANY.RUN,” in
https://app.any.run/tasks/6620ae24-f5d1-4769-9a23-c4b55952ba09/, Any.Run,
Mar 2019.
[40] “Trickbot — Malware Trends Tracker,” 2019.
[41] “PGP Encrypt File,” 2021.
67
A Appendix
A.1 Python C&C Server
import SocketServer
import SimpleHTTPServer
import urllib
import shutil
PORT = 3000
HOSTNAME = ’www.paypal.com/myaccount.html’
class MyProxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
url=self.path[1:]
self.send_response(200)
self.end_headers()
self.copyfile(urllib.urlopen(url), self.wfile)
def do_POST (self):
self.query_string = self.rfile.read(int(self.headers[’Content-Length’]))
parsed = self.query_string.split(’+&’)
for p in parsed:
if p.find(’login_email’) != -1:
dummy = p.partition(’login_email’)[2]
mail = dummy[1:].partition(’&captchaCode’)[0]
if p.find(’login_password’) != -1:
dummy = p.partition(’login_password’)[2]
psw = dummy[1:].partition(’&captcha’)[0]
print(’POST: ’, mail, psw)
self.send_response(301)
self.send_header(’Location’,’https://www.paypal.com/myaccount.html’)
self.end_headers()
68
A.2 Self-Signed Certificate for Paypal server
#-----INSTALLING OPENSSL IN UBUNTU
sudo apt-get install libssl-dev
69
Locality Name (eg, city) []:Copenhagen
Organization Name (eg, company) [Internet Widgits Pty Ltd]:TFM TrickBot
Organizational Unit Name (eg, section) []:Certificate
Common Name (e.g. server FQDN or YOUR name) []:TFM Root CA
Email Address []:
70
#-----Check the CA cert
openssl x509 -noout -text -in cacert.pem
ls newcerts/
cat serial
#-----Send it to ca at rootca/requests/ppserver.csr.pem
cp ppserver.crs.pem ../rootca/requests/
71
#-----Sign it (in ca)
cd ../rootca
openssl ca -config openssl.cnf -extensions server_cert
-in requests/ppserver.crs.pem -out certs/ppserver.crt.pem
Using configuration from openssl.cnf
Enter pass phrase for ./private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 14132630866361607082 (0xc42130e5233463aa)
Validity
Not Before: Dec 21 14:11:15 2021 GMT
Not After : Dec 21 14:11:15 2022 GMT
Subject:
countryName = DK
stateOrProvinceName = Copenhagen
organizationName = TFM TrickBot
organizationalUnitName = Paypal Web Server
commonName = paypal
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Subject Key Identifier:
27:A9:97:30:AE:06:5A:6E:0D:94:A1:27:16:92:3D:8E:D4:DD:FE:6D
X509v3 Authority Key Identifier:
keyid:26:52:25:02:9A:DE:D1:47:59:DC:6C:28:4B:39:79:17:58:59:B7:FE
72