Metasploit - Framework-A Quick Reference PDF
Metasploit - Framework-A Quick Reference PDF
CONTENTS
Basics of Penetration Testing
Setting up the Box
Introduction to metasploit
Information Gathering
Vulnerability Assessment
Exploitation
Evading Firewall and Antivirus
Post Exploitation
Chapter 1
Basics of Penetration Testing
Vulnerability:
Illustration:
Vivek owns a USB modem to access the internet. The modem has
a limited plan of 1GB 3G data. One day while working on a project
for hours together Vivek realizes that he had exceeded his limit of
1GB data but was still able to use the Internet.
The modem updates itself about the usage of data each time it
connects to the server. Hence even if Vivek had exceeded the limit
of 1GB was still able to use internet because there was no update
modem received about exceeding the limit. It was only when Vivek
disconnects the modem and connects it again, he understand the
update mechanism of the modem.
Now since Vivek knows about the update mechanism flaw, he uses
the modem to his full advantage.
This flaw of update mechanism is a VULNERABILTY of the USB
Modem.
Exploit:
In terms of cyber security, taking advantage of a known
flaw(vulnerability) in system hardware or the software in order to
compromise the system security and gain access or harm the
system is known as Exploitation, and the piece of code that does
the above is known as an EXPLOIT.
Illustration:
According to Greek Mythology, Achilles was a Greek warrior and
a hero of the Trojan war, a war fought between Troy and the
Greeks.
Achilles was known to be The Invincible because he was a son of
a god. His mother tried him to make invincible by dipping him in
the river, but he was left vulnerable at the heel from where his
mother was holding him while dipping him in the river.
At almost end of the Trojan war, Paris The Prince of Troy gets to
know this vulnerability(heel). Paris shoots a poisonous arrow at
Achilles' heel and Achilles dies.
So in the context of Computer Science the Achilles' heel was
vulnerable, which Paris took advantage of. The act of Paris
shooting the arrow at Achilles heel is EXPLOITATION, and the
poisonous arrow is an EXPLOIT.
PAYLOAD:
In terms of cyber security, payloads are the programs that are
executed on the victim machine after exploitation. This may
include compromising the systems security and gaining complete
privileges or deploying malicious software etc.,
Note:
Payload has its own different meanings in context with metasploit
and with networking.
Listener:
Listener is a component that needs to be setup on the attacker
machine in cases where the victim machine would try to make a
connection to the attacker, so the listener would take care and
handle the incoming connection. We come across such scenarios
when the security level of the victim machines are high and an
attacker would require inside-out connection for exploitation.
Social Engineering:
Social Engineering is an act of manipulating people for the purpose
of information gathering, gaining access to systems or even frauds.
What is Penetration Testing?
Penetration Testing (often called Pentest) is the process of testing the
security level of a single machine or a complete network by simulating
attacks on these machine and providing proper solutions to overcome these
security flaws.
The evaluation of security on these machines reveal the flaws that exist in
the hardware or the software and misconfigurations a network suffers from.
And to what extent these flaws can be taken advantage of, to breach the
security and gain access into these machines and networks.
The metasploit framework is one of the major part of the Penetration
Testing Process. This framework allows the pen tester to evaluate until
what extent the flaws on a machine can cause harm and grant privileges to
the attacker.
Penetration Testing Process is carried out in a well defined manner. This
process has different phases where each phase has its own necessity and
importance.
Phases of Penetration Testing Process:
1. Information Gathering
2. Scanning
3. Vulnerability Assessment
4. Exploitation
5. Post Exploitation
6. Reporting
The Need of Penetration Testing:
If the companies do not find what is vulnerable in their networks or
machines and patch them before an attacker gets hands on it, then that
might land them into big trouble.
Cyber crimes have been on a all time high in the last decade. Things like
web defacement, stealing of private information etc., could damage any
organizations reputation. Hence no organization would like to risk against
such attacks.
Phases of Penetration Testing:
Phase 1:Information Gathering
Information gathering, also known as Reconnaissance is a initial phase of
penetration testing where the Pen Tester start gathering information of the
target network or a machine.
Information gathering is basically of two types, active and passive.
Passive information gathering involves collecting information about the
target network or the machine without directly interacting with them.
For example searching whois records and other information available
online.
Active information gathering involves collecting information about the
victim by directly interacting with the machine. Active information
gathering may reveal a lot of information about the victim for example, the
emails, phone numbers etc.,
Phase 2 : Scanning
Scanning is the pre phase attack where the pen tester starts scanning the
networks.
Scanning is generally of three types
Network Scanning:
Network scanning includes scanning of the whole network to find which
system on the network are working or alive currently and which are not.
Network scanning reveals the IP addresses of the computers which are
currently up and can be scanned.
Example Angry IP scanner:
Port Scanning:
After successfully Network scanning is completed, network scanning
reveals the list of IP addresses are up and running, the pen tester then starts
scanning the ports on each machine. The scanned ports reveal the
applications that are running on the systems. Port scanning reveals the
Operating systems running on each of the machines in the network.
Vulnerability Scanning:
Vulnerability scanning is a part of the vulnerability assessment phase.
Penetration Testing requires tools like Metasploit, Nessus and Nmap. These
tools are available for premium downloads if one wishes to buy them or the
free versions of these tools are always available.
Tools required:
1. Metasploit
2. Nessus
3. Nmap
Windows Setup:
If you are a windows user and if you wish to stick to windows for the
penetration testing then Metasploit for Windows can be downloaded from
the official Rapid7 website.
http://www.rapid7.com/products/metasploit/download.jsp
For Vulnerability Scanning you can use Nexpose or Acunetix. Both are
windows based vulnerability scanners. Nexpose is again a development of
Rapid 7, and can be downloaded for their official website.
http://www.rapid7.com/products/nexpose/
http://www.backtrack-linux.org/downloads/
Libraries:
REX:
REX stands for Ruby EXploitation library. It is considered to be the most
basic library for most of the functions.REX deals with sockets, protocols
and shell interfaces. It is designed in such a way that it does not depend on
anything other than the default install. The REX library contains various set
of classes and modules which are applicable for further extensions to
projects. Some of the important classes are
Assembly – Helps in generating assembly codes on a fly, since they
are very important for writing exploits.
Encoding – The rex library allows the users to encode the buffers
using different XOR algorithms. These encoders are used in the
encode module.
Exploitation – At times some of the vulnerabilities need to be
exploited in a similar manner i.e., the way they are attacked are
similar. To avail flexibility REX provides the exploitation classes
which serve similar purposes.
Sockets – Sockets is one of the most important set of classes in REX
library. It provides important classes to establish connections on the
remote machine.
MSF Core:
MSF core contains a set of classes that provide an interface to the modules
and plugins. It is contains both auxiliaries and exploits.
Exploits relating to HTTP, FTP, Oracle, SQL, SMB
Auxiliaries relating to Scanner, Fuzzers, Report, dos etc. The auxiliary
module of MSF core makes use of the REX libraries.
MSF Base:
While the MSF core implements some of the abstract sessions, MSF Base
implements some of the concrete implementations. Two of the major
sessions implemented in the MSF Base are Command shell and
Meterpreter.
Interfaces:
Msfcli:
Msfcli is a command line interface for metasploit. Msfcli is good when
testing and developing new exploits and also good for learning the
framework. But it has a major drawback that it can handle only one shell at
a time making it difficult for the client side attacks. It also doesn’t support
any of the advanced automation features. It is a great tool for a tester who
knows exactly what inputs has to be given to the console. Msfcli has a
major advantage of directing output to other tools and also taking inputs
from some other tools.
The Msfcli is used directly for the shell terminal itself.
Figure 7 MSFcli
MSF Console:
MSFConsole is the most popular interface for metasploit. It allows access
to possibly all the options available in metasploit. Once the user gets hands
on msf console they would appreciate the ease of use of msfconsole. It is
infact the most easy way to access and use The Metasploit Framework.
Although Metasploit Framework has been going under constant changes
since it was released, the basic metasploit usage commands remains the
same.
Exploits:
Exploits are programs that help the intruder to take an advantage of the
vulnerability that are present on the victim system.
Auxiliary:
Auxiliary modules are the exploits without payloads, which do not get you
a control over the victim system but performs functions like scanning,
sniffing, fingerprinting and automating tasks.
Posts:
Post is the collection of scripts and programs that an intruder can use on the
victim system to perform various actions after he/she has gained access of
the system. Those actions may include editing registries, setting up
backdoors and further gaining access to internal network.
Payloads:
Payloads are the programs that the attacker sends to the victim after
exploiting the vulnerability, and the program is executed on the victim’s
machine. It gives the attacker control over the victim machine. Running a
shell is the most common payload. The type of payload the attacker might
choose depends on certain constraints, one of them is the memory buffer
available on the victim system for the payload to execute.
Payloads are on the whole divided into three types
Singles: Singles are completely standalone and simple codes that
might be as simple as creating another user on the victim machine or
running a small application.
Stagers: Stagers are generally used to create a network between the
attacker and the victim. It allows the attacker to initially use a small
payload to load larger payloads on the target machine. So stager is
basically taking care of the restrictions that occur in single payloads.
Stages: The various payload stages allow the attacker to have
advanced control over the victim. An example of stages is
Meterpreter.
Netcraft
-> Netcraft is an online service which provides web server, operating
system, domain name server detection etc.,
NS Lookup:
NS Lookup is a command line tool available in various operating systems
which is used for querying IP address, domain name system and various
other things. It is present in Windows as well as many Linux flavours.
Figure 22 NS Lookup
Google Dorks:
Google dorks is a way to dig information about the websites, web servers
etc., This information is revealed due to inappropriate configuration of the
servers and the websites.
This is an example of a google dork which reveals the admin login page of
the website.
After importing the file, we can apply queries to the imported data
and use them for further testing.
Few of these programs can help detect the kind of services they are
running, and there are other programs that help evaluating the
number of ports open on the machine.
Chapter 5
Vulnerability Assessment
Vulnerability assessment is an automated program which looks for
weaknesses in the remote computers or networks. The vulnerability
scanners comes to conclusion about the vulnerability based on the
response it receives to the packets sent to it.
Scanning with Nessus:
Installing Nessus:
-> Nessus comes pre installed in the operating system that we are currently
using for penetration testing(i.e. Backtrack 5 R3).
-> But before we start using Nessus directly we need to enable it.
-> To enable Nessus we need to register on the tenable.com as a user.
-> And to use free Nessus we need to register for the home feed.
http://www.tenable.com/products/nessus/nessus-homefeed
-> After registering we would receive a mail with the activation code on our
email.
Pen testers can put general queries to the vulnerability database to fetch the
information.
---> use
The use command is used to set the exploit.
--->show
The show command is used to see the list of exploits, payloads and
also options that are to be set for successful exploitation.
Victim Machine:
-> Windows XP Service Pack 2
-> Using the search command we can find the exploit for this
vulnerability.
-> After we have found the exploit which we were looking for, the
next step is to set the exploit for use.
-> To do so we use the use command
STEP 2:
-> After we have set the exploit, the next thing to do is to look for
an appropriate payload for the exploit.
-> In the previous definitions we have seen that a payload is
something that is going to execute on a remote machine after the
remote machine has been exploited.
-> So in this let us choose a payload that fetches us a command
prompt of the remote machine.
Note: We have not selected any specific exploit target, and is set to
automatic targeting.
STEP 4:
-> The last and the final step of the process is to exploit.
-> This is done using the exploit command.
Figure 59 No Suspicion
But in case the victim is smart enough to take a look at the
processes running on his machine he would find a background
command prompt on his machine which would create suspicion.
STEP 2:
-> Set options required for the above exploit.
This would start a server and load all the browser based exploits to
the server.
It is a little bit time consuming process so be patient and wait for
all the exploits to load.
-> As soon as the victim puts the ip address in the browser the
following code is executed by the server.
Figure 72 Encoding
-> This would create a file on the desktop named Process Exp.exe.
Step 3:
-> The next step is to send the file we recently created to the
victim.
-> And simultaneously we need to set up a listener on our machine.
-> We will be setting up a listener using msfcli which would listen
for incoming connections.
-> Execute the following command to setup a listener.
-> After executing the command wait for the victim to run the file
we sent.
-> After we have successfully evaded the antivirus the next most
important thing to do is to kill the antivirus.
Figure 79 Exploiting
Meterpreter > ?
This would display a huge list of options that come along with
meterpreter. Meterpreter allows the attacker to execute scripts on
the victim machine and one of those scripts is killav.rb
The killav.rb is a ruby script that can be executed remotely from
the attacker machine to shut down the antivirus. Though this script
does not guarantee 100% success, making a little bit of changes to
the script by ourselves would make it work perfect.
Step 1:
-> After getting the access through meterpreter, check all the list of
processes running on the system using ps command.
Meterpreter > ps
Figure 80 PS command
From the list note down all the processes that are associated with
the antivirus.
avgwdsvc.exe
avgui.exe
avgidsagent.exe
avgrsx.exe
avgcsrvx.exe
The killav.rb script searches for any antivirus processes from a list.
Step 2:
All we need to do is to edit the killav.rb script and add these
processes to it.
To edit the script go to the following directory.
-> User ID
Figure 85 Getuid
Figure 93 Dump
Figure 94 Data dump Files
Privilege Escalation
Clearing Logs: