Py RAT
Py RAT
Py RAT
pyRAT
Nikolaos Themelis
I hereby declare that except where specific reference is made to the work of others, the
contents of this thesis are original and have not been submitted in whole or in part
for consideration for any other degree or qualification in this, or any other university.
This thesis is my own work and contains nothing which is the outcome of work done in
collaboration with others, except as specified in the text and Acknowledgements. This
thesis contains fewer than 10,000 words including appendices and bibliography and
has fewer than 20 figures.
Nikolaos Themelis
October 2018
Acknowledgements
This project would not have been possible without the support of many people. Many
thanks to my supervisor, Mr. Monogioudis Ioannis who helped make some sense of the
confusion in the beginning and for providing guidance and feedback throughout this
project. Finally, a big thanks to my parents and my friends who endured this long
process with me, always offering support.
Abstract
Given today’s radically increasing number of cyber attacks, information security has
become one of the most complex and important issues of concern at the world’s leading
organizations. This has motivated a large number of penetration testers to indulge and
develop tools and techniques, similar to those used by real hackers, to attack systems
in order to reveal security flaws. The aim of this thesis was to design and implement a
tool (pyRAT) which automates the generation of Metasploit payload executables that
have the ability to invade systems without getting detected by most antivirus solutions.
pyRAT meets all the requirements of usability and makes use of the penetration testing
tool, called Metasploit Framework along with its features. The exploitation process
has the intention of gaining access to the vulnerable system by creating a meterpreter
session between the user and the target system. pyRAT is developed, strictly, for
educational purposes and its ultimate goal is to be a helpful tool during the process of
a penetration test. Any other malicious or illegal use of this tool is not recommended.
Overall, this work has provided a great learning opportunity in the area of ethical
hacking using penetration testing.
Περίληψη
List of Figures xv
Acronyms xvii
1 Introduction 1
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Problem statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Scope and purpose of the thesis . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Objectives of the thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Structure of the thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Theoretical Background 5
2.1 Information Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Penetration testing - Malware . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.1 Penetration testing . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.2 Malware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 General Information about the Metasploit Project . . . . . . . . . . . . 7
2.4 How does the Metasploit Framework work . . . . . . . . . . . . . . . . 7
2.5 Metasploit Framework Components . . . . . . . . . . . . . . . . . . . . 9
2.5.1 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5.2 Metasploit Interfaces . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5.3 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.6 Exploiting a system using the Metasploit Framework . . . . . . . . . . 11
2.7 Famous vulnerabilities and exploits - Meterpreter . . . . . . . . . . . . 12
2.7.1 Famous vulnerabilities and exploits . . . . . . . . . . . . . . . . 12
2.7.2 Meterpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.8 Bypassing IDs and antivirus detection . . . . . . . . . . . . . . . . . . 13
2.9 Related Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
xiv Contents
4 pyRAT Presentation 21
4.1 General information about pyRAT . . . . . . . . . . . . . . . . . . . . 21
4.1.1 Tool Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.1.2 Tool Configuration . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.1.3 User Access Levels . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.1.4 Installation and Logging In . . . . . . . . . . . . . . . . . . . . 22
4.2 pyRAT GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2.1 Starting window . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2.2 Choosing exploit . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2.3 Choosing payload . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.2.4 Payload options . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.2.5 Scanning payload with ClamAV . . . . . . . . . . . . . . . . . . 27
4.2.6 Scanning payload in VirusTotal . . . . . . . . . . . . . . . . . . 28
4.2.7 ClamAV’s results . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.2.8 Final ClamAV’s results after hiding the payload . . . . . . . . . 30
4.3 Exploitation: Proof of Concept (PoC) . . . . . . . . . . . . . . . . . . . 31
6 References 35
AV Antivirus
DB Database
IT Information Technology
NOP No OPeration
OS Operating System
Introduction
1.1 Background
Nowadays, it is common knowledge, that the world has become a global village thanks
to the widespread use of the internet. The benefits of information for organizations are
innumerous. Increased dependency on information by organizations, though, has led to
an increase on the dependence of the CIA (Confidentiality, Integrity and Availability)
paradigm of information. As a result of the above, in today’s globally interconnected
economy, information security has become one of the most complex issues of concern
at the world’s leading organizations. Organizations that want to be successful have
information security at the top of their priorities. It is now more than evident, that it
is almost impossible for an enterprise in today’s information economy to transact its
business with ineffective information security. In the meanwhile, individual actions
have the potential to cause great damage. Securing today’s enterprise networks involves
more than simply patch management, firewalls, and user education; it requires frequent
realworld validation of what works and what fails. This is what penetration testing is
all about. Penetration testing probes the systems of an organization for weaknesses
and identifies what the organization needs to do to defend itself from a real intrusion.
This thesis focuses on the Metasploit Framework. This open source platform, that is
part of many of the penetration tester tool kits, provides a consistent, reliable library
of constantly updated exploits and offers a complete development environment for
building new tools and automating every aspect of a penetration test. Thus, based on
Metasploit and for the purposes of the current thesis, an antivirus evasion tool, called
pyRAT, was developed.
2 Introduction
Moreover, a confusion still exists in developing tools with a Graphical User Inter-
face that simultaneously take advantage of Metasploit’s features, and more specifically,
the ability of developing and executing exploit code against remote target machines.
Additionally, there was no desktop tool with the ability of generating Metasploit
payload executables that, with the use of some efficient obfuscation techniques, could
bypass most antivirus solutions. As a consequence, and based on the points that were
mentioned previously, this thesis discusses and presents a Metasploit-based desktop
application for antivirus evasion that can be used as a handy tool for penetration
testers with experience; or even for beginners.
6. Documentation
Theoretical Background
Threats to sensitive and private information come in many different forms, such
as malware and phishing attacks, identity theft and ransomware. Most people have
experienced software attacks of some sort. To deter attackers and mitigate vulner-
abilities at various points, multiple security controls are implemented. This should
minimize the impact of an attack. To be prepared for a security breach, companies and
security groups should have an Incident Response Plan (IRP) in place. This should
allow them to contain and limit the damage, remove the cause and apply updated
defense controls.[2]
6 Theoretical Background
2.2.2 Malware
The term malware is a contraction of malicious software. More specifically, malware is
any piece of software that was written with the intent of doing harm to data, devices
or to people. Viruses, worms, phishing attacks, Trojans, spyware are only some kinds
of malware.[4] The terms that are mainly encountered in this work are Virus and Trojan.
Virus
Viruses attach themselves to clean files and infect other clean files. They can spread
uncontrollably, damaging a system’s core functionality and deleting or corrupting files.
They usually appear as an executable file.
Trojan horse
• can launch an exploit from a compromised machine against another target and
import files from numerous vulnerability scanners
8 Theoretical Background
2.5.1 Libraries
The core of Metasploit Framework is composed of libraries. These libraries are
responsible for an interaction with various parts of the Metasploit Framework, such as
modules, plugins, interfaces and sessions.
• REX - Ruby Extension Library, is the most fundamental component of the entire
architecture. It handles sockets, protocols, servers and text transformations (SSL,
HTTP, Base64).
• Core - The Core library (msfcore) implements interfaces for exploit modules,
sessions, and plugins interaction.
• Base - The Base library (msfbase) is built on top of the Core library and provides
wrapper routines and utility classes.
• Metasploit Express and Metasploit Pro are open-core commercial editions with a
web interface and additional features for easier automation of basic penetration
tests. More specifically:
and an advanced Pro Console for generating dynamic payloads for antivirus
bypass.
• MSFgui - MSFgui is a Java based graphical interface with the additional benefit
of connecting to a remote msfrpcd session on a remote host.
2.5.3 Modules
Modules are components that can plug into Metasploit Framework core and they have
defined structure and interface. These components perform specific actions, such as
exploitation and scanning. There are several module types available, categorized by
the action that they perform. More specifically:[7]
• Payload - It is the malicious code that will be executed on the targeted machine
following a successful exploitation. The payload enables the user to define how he
wants to connect to the shell and what he wants to do to the target system after
the compromise. A payload can open, for example, a Meterpreter or a command
shell.
• NOPs - They can be used to bypass the standard IDS and IPS NOP sled
signatures by toggling the processor flags or altering the state of registers in order
to facilitate buffer overflows during attacks.
• Payload encoders - When exploits must bypass antivirus defenses, these mod-
ules encode the payload so that it cannot be detected enabling the attacker to
evade the IDS and IPS signatures.
To choose exploits and payloads, some information about the target system is
needed, such as the Operating System’s version. This information can be gleaned with
port scanning and OS fingerprinting tools such as Nmap. In addition, vulnerability
scanners such as Nexpose and OpenVAS can detect target system security flaws.
2.7.2 Meterpreter
Meterpreter is an advanced, dynamically extensible payload that uses in-memory DLL
injection stagers and is extended over the network at runtime. It communicates over the
stager socket and provides a comprehensive client-side Ruby API. It features command
history, tab completion, channels, and more. Meterpreter is stealthy, it resides entirely
in memory and writes nothing to disk. By default, it uses encrypted communications
and leaves limited forensic evidence and impact on the victim machine. The most
2.8 Bypassing IDs and antivirus detection 13
Most antivirus software rely on signature matching to locate viruses and other malware.
They examine each executable for strings of code known to be present in viruses and
create an alarm when a suspect string is detected. Many of Metasploit’s attacks rely
on files that may possess a signature that, over time, has been identified by antivirus
vendors. In response to this, the Metasploit Framework allows standalone executables
to be encoded to bypass detection. Unfortunately, extensive testing of these executables
at public sites, such as virustotal.com, have lessened their effectiveness in bypassing
the AV software.
Furthermore, many tools that used to hide the payloads, such as crypters, pack-
ers, Metasploit’s encoders, now they are easily detected by most antivirus solutions.
Thus, the best tactic is to write custom payloads and keep them simple to be away
from antivirus detection rather than creating payloads using popular frameworks. In
the following chapters, it will be demonstrated how pyRAT manages to bypass most
antiviruses. It is important to notice, though, that the results shown in this thesis
may change when someone reads and then uses the tool as antivirus signatures are
constantly updated.
14 Theoretical Background
This chapter presents the tools, technologies and methodologies that have been used
for the development of the application.
Kali Linux has over 600 pre-installed tools which are geared towards various information
security tasks, such as penetration testing, security research, computer forensics and
reverse engineering; including Armitage (a graphical cyber attack management tool),
Nmap (a port scanner), Wireshark (a packet analyzer), John the Ripper password
cracker, Aircrack-ng (a software suite for penetration-testing wireless LANs), Burp
Suite and OWASP ZAP web application security scanners and, of course, Metasploit
Framework. These tools can be used for a number of purposes, most of which involve
exploiting a victim network or application, performing network discovery, or scanning
a target IP address. Many tools from Backtrack were eliminated to focus on the most
16 Technologies used for the development of pyRAT
Finally, the tool’s GUI is designed with the use of Tkinter. Tkinter is the most
commonly used GUI Programming toolkit for Python and is a thin object-oriented
layer on top of Tcl/Tk.
and from any device that has a terminal and supports Ruby.
3.4 Msfvenom
Msfvenom was used for the generation of the payload executables. Msfvenom is a
combination of msfpayload and msfencode putting both of these tools into a single
Framework instance. The Metasploit Framework had included these useful tools
for quite some time. These tools were extremely useful for generating payloads in
various formats and encoding these payloads using various encoder modules. Msfvenom
replaced both msfpayload and msfencode as of June 8th, 2015.[15]
The main advantages of msfvenom are:
• Increased speed
3.5.2 pyClamd
For the automated use of ClamAV the use of pyClamd was necessary. pyClamd is a
python interface to Clamd (ClamAV daemon). pyClamd adds virus detection capabili-
ties to the python software in an efficient and easy way and is released as open-source
software.[17][18]
3.6 peCloak
The main goal of pyRAT was to generate payload executables that could bypass most
antiviruses. This was accomplished with the use of peCloak. peCloak is a simple
proof-of-concept python script that automates multiple tricks to hide a malicious
windows executable in order to evade common antivirus solutions. peCloak is used in
pyRAT as an obfuscator for the generated payloads. More specifically, peCloak uses
3.6 peCloak 19
simple XOR, ADD and SUB instructions in the encoder to defeat signature based
detection. Its goal is to defeat any sandbox-based, heuristic run time detections that
might be employed by an AV product and finally, to minimize the static nature of the
decoding/heuristic code that would be included in the modified executable to avoid
having it become a signature for AV detection.[19][20]
Chapter 4
pyRAT Presentation
not be able to ‘listen’ anything from the victim’s machine and the attack will not be
successful even if the antivirus has been bypassed.
Figure 4.1 shows the starting window of pyRAT. By pressing the "Show Exploits"
button, pyRAT starts the first phase.
24 pyRAT Presentation
Next step, is to setup a listener in Metasploit and wait for the victim to open the
malicious file to get a meterpreter shell; if everything is done right. Thus, in order
to start the listener to test the payload, the malicious user could use the following
commands in msfconsole:
32 pyRAT Presentation
Finally, after tricking the victim to open the executable file, the malicious user will
be waiting on his machine for the meterpreter to open. With the meterpreter active,
the attacker will have fully compromised the victim’s machine.
Figure 4.11 shows that after following the previous steps, a meterpreter was activated
and the target system’s details are revealed through the meterpreter command "sysinfo".
Chapter 5
The last chapter of this thesis presents the conclusions that have been made during
the preparation, work and implementation of pyRAT. Finally, and to go a step further
in this thesis’ approach, the future work that could be done to improve this tool, is
mentioned.
5.1 Conclusions
In this thesis, a Metasploit-based desktop tool was developed using Python and its
modules. This application takes advantage of the Metasploit Framework and its
features. The main objective of the work was to present this technology and to show in
a simple and clear way how to achieve an invasion on a system effectively and stealthy
without getting caught by the majority of antiviruses. It is also worth mentioning
that pyRAT can be an important tool for those who want to practise themselves with
Metasploit’s exploits and penetration testing in general.
References
[4 ] "What is Malware?"
https://www.avg.com/en/signal/what-is-malware
[5 ] "Metasploit Framework"
https://metasploit.help.rapid7.com/docs/msf-overview
[7 ] "Veil-Framework"
https://github.com/Veil-Framework/Veil
[9 ] "Offensive Security"
https://www.offensive-security.com/
36 References
[14 ] "SpiderLabs/msfrpc"
https://github.com/SpiderLabs/msfrpc/tree/master/python-msfrpc
[15 ] "MSFvenom"
https://www.offensive-security.com/metasploit-unleashed/msfvenom/
[20 ] "peCloakCapstone/peCloak.py"
https://github.com/v-p-b/peCloakCapstone/blob/master/peCloak.py
Appendix A
Kali Linux OS
pyRAT - version 1.0
1. Download pyRAT from https://github.com/nikosthem/pyRAT/
or clone it with: git clone https://github.com/nikosthem/pyRAT.git
If all goes well, the following response will be shown in the console, which
tells the IP address, username, and password that will be used for the connection
to the msgrpc server:
38 How to install and run pyRAT