Table of Contents

Developer/Security 542 Web App Penetration Testing and Ethical Hacking

March 7-12, 2011

Instructor: Kevin Johnson

Elluminate being used for video broadcast to about 30 remote students

Sponsers:

Quote from a tee shirt: I am a bomb Technician, if you see me running, try to keep up.

Breaks:

Lunch:

Randy's Cell 250-7681

Day 1 The Attacker's View of the Web

Why the Web ..1.3

Open Source Vulnerability Bulletin Board, OSVBB

Web App Pen Testing ..1.8

Security Testing should be part of Job description

Web Site Server Architecture ..1.13

The HTTP Protocol ..3.20

HTTP/1.1 defined in RFC 2616

http://tools.ietf.org/rfc2616

original design considerations

http://www.w3.org/Protocols/DesignIssues.html

Example HTTP Request ..1.22
GET http://www.google.com HTTP/1.1
Accept: */*
Accept-Language: en-us
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; NET CLR 1.1.4322; .NET CLR 2.0.50727) Paros/3.2.13
Host: www.google.com
Proxy-Connection: Keep-Alive
Cookie:PREF=ID=6aa36b...:LM=11198...:GM=1:S=CZy0...
Content-length:0
User-Agent ..1.23

Mozilla/4.0 - This signifies that the browser is compliant with the standards set by netscape

MSIE 7.0 - Internet Explorer 7.0 is the software type

Windows NT 5.1 - This browser is running on Windows XP

NET CLR 1.1.4322; .NET CLR 2.0.50727 - These two versions of the .NET client are supported

Paros/3.2.13 - added by Paros

* McAffee dropp(ed) App Firewall if “scanalert” (is)was in the user agent field

Origin Server ..1.25

rfc2616

Same Origin Policy ..1.26

Prevents scripts from running code from another site.

HTTP Request Methods ..1.31
GET
POST
HEAD
TRACE
OPTIONS
CONNECT
PUT
DELETE

Check if OPTIONS is enabled - it is not necessary.

HTTP Response Codes ..1.36

Exercise: Examining HTTP Requests and Responses ..1.38

$ nc www.sec542.org 80
POST /form_auth/login.php HTTP/1.0
Content-Length: 42

user=testuser&pass=opensesame&button=Login

Client Authentication ..1.46

paros - as a simple proxy - a new fork is zap by owasp

examples use this for Authentication

Exercise: Client Authentication ..1.64

cd /usr/bin/samurai/paros
java -jar paros.jar

Session Tracking ..1.74

SSL ..1.82

SSL v2, turn it off

Exercise: Analyzing SSL ..1.88

Penetration Testing Types and Methods ..1.94

Web App Pen Test Components ..1.102

Reporting and Presenting Findings ..1.111

  1. Executive summary ..1.114
  2. Introduction ..1.115
  3. Methodology ..1.116
  4. Findings - includes recommendations ..1.117
  5. Conclusions .. 1.118

Chris Dickerson - Just released a sample report

Data Collection Tools ..1.120

Attack Methodology ..1.125

Types of Flaws ..1.135

JavaScript for Pen Testers ..1.140

Inline HTML

as a script tag

<script>alert("Sec542 Rocks")</script>

as part of an HTML item

<img src="images/logo.gif" onload="javascript:alert('Loaded');">

loaded from another document

<script src=http://www.inguardians.com/malicious.js>

Statements, Variables, Functions & Events ..1.145

The DOM, Methods and Properties ..1.153

AJAX and XMLHttpRequest ..1.160

Exercise: JavaScript ..1.166

copy the HTML file from the JavaScript directory and the DVD to your desktop

Between Head tags add:

Between <head> and </head> tags, add:
<script>alert("Hello World!");</script>

Test index.html

Change to

<script src="attack.js"></script>

Create a file called attack.js and put in it:

alert("Hello World!");

Test index.html

change attack.js to

function formChange() {
  document.forms[1].action="http://www.sec542.org/"
  document.forms[1].sushi.value="Toro"
}

In the index.html file:

<body onload="formChange();">

Reload the page in the browser. Submit the form to see the URI change

Add this to the attack.js file

function createCookie() {
     document.cookie = "userid=kevin;expires=Fri, 27-Feb-2009;path=/";
}

In the index.html file, add the mouseover event

<form id="login" onmouseover=alert(document.cookie);" name="login" action="#" method="post">

Day 2 Reconnaissance and Mapping

Python scripting

Creating Custom Scripts for Penetration Testing ..2.4

Python for Penetration Testing ..2.6

Exercise: Python Scripting ..2.16

create a file beginning with

#!/usr/bin/python
chmod 755 custom.py
#!/usr/bin/python

import httplib
conn = httplib.HTTPConnection("www.sec542.org")
url = "/python/index.php
conn.request('GET',url)
reps = conn.getresponse()

print resp.getheader("Server")
print resp.getheader("Date")
print resp.getheader("Cookie")

n = 1
outfile = open("results.txt","a")
while n<=100:
  conn = httplib.HTTPConnextion("www.sec542.org")
  url = "/python/index.php?id="+str(n)
  conn.request('GET',url)
  resp = conn.getresponse()
  print resp.getheader("Server")
  print resp.getheader("Date")
  print resp.getheader("Cookie")
  respcode = resp.status
  outfile.write(result)
  n+=1

Reconnaissance ..2.23

Target Selection ..2.26

Whois and DNS Records ..2.29

whatis whois

whois for fbcgalax.org, www2.sans.org, www3.sans.org

Looking at hosted services

nslookup ..2.33
nslookup [host] [DNS_server]

set debug gives more information

nslookup is depricated on Linux for dig

dig ..2.34
Fierce ..2.36

Simple scanner designed to find hosts within a domain by Robert “RSnake” Hansen and updated to 2.0 by Joshua “Jabra” Abraham

Lookup various hosts in a domain

perl fierce.pl -dns sec542.org

Scan an IP range

perl fierce.pl -range 192.168.1.0-255 -dnsservers ns1.sec542.org

Perform reverse lookups after finding CNAMEs

perl fierce.pl -dns sec542.org -wide -output output.txt

Exercise: DNS Harvesting ..2.37

nslookup mail.sec542.org
dig sec542.org
dig sed542.org mx

perform zone transfer

dig AXFR sec542.org
host -la sec542.org

Fierce

cd /usr/bin/samurai/fierce2

run fierce with a DNS name specified

fierce -dns sec542.org

run fierce on an IP range

fierce -range 192.168.1.0-255 -dnsservers 192.168.1.41

External Information Sources ..2.45

ip:72.14.204.147

Google directives ..2.48
site:www.sans.org
inurl:phpinfo
intitle:"Admin Login"
link:sans.org
ext:xls
Google Modifiers to Focus Searches ..2.49

Quotes for literal matches

"sans Web Application"

“-” omits pages or pages with specific strings from results

site:sans.org -site:www.sans.org
site:sans.org -handlers
Google Groups ..2.50
author:kevin@inguardians.com
insubject:"Problems with my code"
SensePost's Aura ..2.53
Foundstone's SiteDigger ..2.54
SensePost's Wikto ..55
cDc's Goolag Scanner ..2.56
Google Alerts ..2.58
Newsgoups ..2.60
Social Networks ..2.61
Automated Social Network Parsing ..2.62

Robin Wood created gpscan.rb to search Google profiles for specific targets

./gpscan.rb Microsoft

http://www.digininja.org/projects/gpscan.php

Jason Wood created the LinkedIn user name generator Reconnoiter

./usernameGen.py InGuardians 10

http://www/jwnetworksconsulting.com/blog

Maltego ..2.65

Mapping ..2.68

Mapping Phase Components ..2.69

Port Scanning, OS Fingerprinting & Version Detection ..2.70

Nmap Port Scanner ..2.71
sudo nmap -sV -O www.inguardians.com
Passive OS Fingerprinting with P0f ..2.73

Exercise: Gathering Server Info ..2.82

sudo nmap -sV -O www.inguardians.com
printf "GET / HTTP/1.0\n\n" | nc -v www.inguardians.com 80

(This does not work on my laptop.)

HTTPrint ..2.79

Side note:

Netcraft Detection ..2.80

Exercise: Gathering Server Info ..2.82

$ nc www.sec542.org 80
HEAD / HTTP/1.0
<enter><enter>
$ nc www.sec542.org 443
HEAD / HTTP/1.0
<enter><enter>

(No SSL, so it cannot connect.)

nmap -sV www.sec542.org

Analyzing SSL Support ..2.88

Scripting OpenSSL ..2.90

Test for SSLv2

openssl s_client -connect www.aoe.vt.edu:443 -ssl2

Test for NULL Cipher (clear text)

openssl s_client -connect www.aoe.vt.edu:443 -cipher NULL

Verify SSLv3

openssl s_client -connect www.aoe.vt.edu:443 -ssl3

script from sslthing

if ! [ $1]; then
  echo syntax: $0 host:sslport [-v]
  exit
fi

if ! [ -e $ossl ]; then
  echo The path to openssl is wrong, please edit $0
  exit
fi

## Request available ciphers from openssl and test them for ssl in -ssl2 -tls1
for ssl in -ssl2 -tls1
do
  echo Testing `echo $ssl | cut -c2- | tr "a-z "A-Z"'...
  $ossl ciphers $ssl -v | while read line
  do
    ciphers=`echo $line | awk '{print $1}'`
    bits=`echo $line | awk '{print $5}' | cut -f2 -d\( | cut -f1 -d\)`
    if  ($ossl s_client $ssl -cipher $cipher -connect $1 < sslthing.tmp 2>&1 | grep ^New > /dev/null); then
      if [ $2 ]; then
        echo OK
      else
        echo $cipher - $bits bits
      fi
    else
      if [$2 ]; then
        echo Failed
      fi
    fi
  done | grep -v error
don
Using THC SSL Check to Evaluate Targets ..2.91
Using SSLDigger to Evaluate Targets ..2.92

Exercise: Testing SSL ..2.94

SSL Testing: Launching THC SSL Check ..2.96

Run the command using wine

$ TCHSSLCheck.exe www.sec542.org 443 > ~/THC_443.txt

Fixme messages won't affect the program

$ TCHSSLCheck.exe www.sec542.org 10000 > ~/THC_10000.txt
SSL Testing: Launching SSLThing ..2.97
cd /usr/bin/samurai/sslthing
./sslthing www.sec542.org:443 > ~/Thing_443.txt
./sslthing www.sec542.org:10000 > ~/Thing_10000.txt

Virtual Hosting and Load Balancers ..2.100

Bing

ip:<ip address>

Analyzing Software Configuration ..2.112

#!/bin/bash
for method in GET POST PUT TRACE CONNECT OPTIONS;
do
  printf "$method / HTTP/1.1\nHost: www.aoe.vt.edu\n\n | nc www.aoe.vt.edu 80
done

Exercise: Nikto ..2.118

cd /usr/bin/samurai/nikto
./nikto.pl -host www.sec542.org -Format HTM -output ~/nikto.html

Spidering a Site ..2.124

Robot Control ..2.126

robots.txt

User-agent: *
Disallow: /images/
Disallow: /css/

individual pages

These should both be use as different clients respect each of them

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

These are useful for controlling search engine spiders and where they go

<META NAME="ROBOTS" CONTENT="INDEX,NOFOLLOW">
<META NAME="GOOGLEBOT" CONTENT="NOARCHIVE">

Robot Exclusion Protocol - http://www.robotstxt.org

Automated Spidering with WebScarab ..2.128
Automated Spidering with Paros ..2.130
Automated Spidering with Burp Suite ..2.131
Automated Spidering with wget ..2.132
robots=off
Specialized Spidering Tools

Exercise: Web Spidering ..2.134

wget -r http://www.sec542.org --no-check-certificate
java -jar webscarab.jar
  spidering tab
  browse to site
  Fetch Tree
  Fetch Tree until no other pages are found
cd /usr/bin/samurai/burpsuite_v1.2
  java -jar burpsuite_v1.2.jar
  check spider running check box
cd /usr/bin/samurai/cewl
./cewl.rb http://www.sec542.org
./cewl.rb http://www.sec542.org -w ~/cewl_wordlist

Analyzing Spider Results ..2.144

Convert HTML to Text ..2.150
w3m -dump index.html > index.txt

Application Flow Charting ..2.151

Relationship Analysis ..2.156

Dreamweaver has notes for pages which get put in _notes with .mno extension

Exercise: OWASP DirBuster ..2.165

directory-list-2.3-small.txt
directory-list-2.3-medium.txt
directory-list-2.3-big.txt
directory-list-2.3-lowercase-2.3-big.txt
cd /usr/bin/samurai/DirBuster-1.0-RC1
java -jar DirBuster-1.0-RC1.jar
  Enter http://www/sec542.org in Target URL
  Browse to select word list
  other options as desired
  Select start

Session Analysis ..2.170

Session Token Predictability ..2.174
WebScarab Session Token Gathering and Analysis ..2.177

Exercise: Session Analysis ..2.179

Session Gathering: Testing Webmin ..2.181
cd /usr/bin/samurai
java -jar webscarab.jar
  Session ID Analysis
    Select session within "Previous Requests:" drop down
    Click Test
Session Gathering: Testing Jetty ..2.182

On Sec542 Target VM

cd Desktop/Jetty
./runjetty.sh

jetty runs on port 8080

Select "GET http://www.sec542.org:8080/examples/servlet/SessionExample 200 OK" from "Previous Requests:"
click Test
set the number of samples to 1000 and click fetch
switch to the analysis tab
Session Gathering: Using Burp Sequencer ..2.183
cd /usr/bin/samurai/burpsuite_v1.2
java -jar burpsuite_v1.2.jar
Clear Private Data including cookies in Firefox
Switch to Burp proxy and visit Jetty and Webmin bookmarks
Right Click SessionExample and select send to sequencer
Select sequencer tab the select each URL in turn and click "start capture".
click "analyze now"
click "Stop" when finished

Day 3 Server-Side Discovery

Who does Kevin Johnson follow:

Who are the up and coming people?

Vulnerability Discovery Overview ..3.4

Automated Web Application Vulnerability Scanners ..3.7

Grendel-Scan ..3.10

Mapping Mode ..3.12

* two methods

Discovery Plug-ins ..3.13

Grendel-Scan Exercise ..3.14

cd /usr/bin/samurai/grendel-scan
./grendel.sh

Enter the target URL's and click add (one at a time)

http://www.sec542.org
http://www.sec542.org/scanners

Output directory

/home/samurai/scanresults/grendel/

Select plug-ins

In the menu, select:

Scan -> Start Scan

Launch Firefox and select Grendel-Scan in the SwitchProxy toolbar

select the bookmark for BASE

This adds this url to the Grendel scan

open report.html in a browser.

w3af ..3.20

$ ./w3af_console
w3qf>>> plugins
w3af/plugins>>> output console,textfile
w3af/plugins>>> output config textFile
$ w3af_console -s filename

w3af Exercise ..3.33

cd /usr/bin/samurai/w3af
./w3af_gui

click profile menu and select new profile. Give it a name such as sec542

In the target URL, enter https://www.sec542.org/scanners

The Burb Suite ..3.40

Burp Suite Components ..3.42
Burp Proxy ..3.43
Burp Spider ..3.44
Burp Indruder ..3.45
Burp Repeater ..3.46
Burp Sequencer ..3.47
Burp Decoder ..3.48
Burp Comparer ..3.49

Exercise: Burb Suite ..3.50

SamuraiWTF ..3.57

Manual Verification Techniques ..3.61

Info Leakage and Dir Browsing ..3.63

Exercise: Directory Browsing ..3.69

Username Harvesting ..3.73

Exercise: Username Harvesting ..3.81

Command Injection ..3.86

Exercise: Command Injection ..3.89

SQL Injection ..3.100

Exercise: SQL Injection ..3.116

Blind SQL Injection ..3.120

Cross Site Scripting ..3.131

Exercise: XSS Exercise ..3.140

Cross Site Request Forgery ..3.153

Apache settings to turn off