88
Name: Shaikh Jamal Uddin Entire Experience: Over 5 years of hardcore Information Security experience of consultancy and training for clients from Finance, Military, Energy, Shipping, and Telecom sectors. He has completed Computer Engineering from Sir Syed University (SSUET) – Karachi. Certifications: CPTE, CEH, ECSA, TCSE, MCSA, MCITP, MCS, BCSE, TCSP. About Trainer

Network Security Testing with NMAP Workshop1

Embed Size (px)

Citation preview

Page 1: Network Security Testing with NMAP Workshop1

• Name: Shaikh Jamal Uddin• Entire Experience: Over 5 years of hardcore Information Security

experience of consultancy and training for clients from Finance, Military, Energy, Shipping, and Telecom sectors. He has completed Computer Engineering from Sir Syed University (SSUET) – Karachi.

• Certifications: CPTE, CEH, ECSA, TCSE, MCSA, MCITP, MCS, BCSE, TCSP.

About Trainer

Page 2: Network Security Testing with NMAP Workshop1

Why Workshop ?Workshops are great for brainstorming , interactive learning , building relationships and problem solving.

Page 3: Network Security Testing with NMAP Workshop1

Introduction to Ethical Hacking

Foot printing & Reconnaissance

Scanning Networks

Enumeration

System Hacking

Trojans & Backdoors

Viruses & Worms

Sniffers

Social Engineering

Denial of Services (DoS)

Session Hijacking

Hacking Web Servers

Hacking Web Applications

SQL Injection

Hacking Wireless Networks

Hacking Mobile Platforms

Evading IDS, Firewalls & Honeypots

Buffer Overflow

Cryptography

Penetration Testing (Reporting)

CPTE &CEH

Page 4: Network Security Testing with NMAP Workshop1

Network Security Testing with NMAP

Page 5: Network Security Testing with NMAP Workshop1

NMAP (Network Mapper) is a security scanner used to discover hosts and services on a computer network, therefore creating a “map” of the network.

NMAP cab be used to:• map a network• enumerate hosts• enumerate services• obtain details about services

What is NMAP?

Page 6: Network Security Testing with NMAP Workshop1

NMAP send specially crafted packet to the target host and then analysis the responses

Active Probing

Page 7: Network Security Testing with NMAP Workshop1

4 Steps Performing Security Audit of Your

Network

Page 8: Network Security Testing with NMAP Workshop1

1. Map the Network

Page 9: Network Security Testing with NMAP Workshop1

2. Identify Hosts

Page 10: Network Security Testing with NMAP Workshop1

3. Identify Services

Page 11: Network Security Testing with NMAP Workshop1

4. Identify Services Details

Page 12: Network Security Testing with NMAP Workshop1

Power of NMAP - Examples# nmap 192.168.3.1

# nmap -sn 192.168.3.0/24 -v

# nmap -p 80 --script http-chrono \

Page 13: Network Security Testing with NMAP Workshop1

Installing NMAP

Page 14: Network Security Testing with NMAP Workshop1

NMAP is Free and Open Source Software - FOSS• Its Free• Open Source• http://nmap.org/download.html• Primary Interface is command line• ZenMAP, GUI• http://nmap.org/book/install.html• http://nmap.org/book/man.html

Page 15: Network Security Testing with NMAP Workshop1

Configure SSH on Linux Remote Service

Connect to Kali Remotely

Page 16: Network Security Testing with NMAP Workshop1

• First SSH need to be install/update

#apt-get install openssh-server

#service ssh start

• Verify that the server is up and listening using the “netstat” command

#netstat –antp |grep ssh

Now connect with “putty.exe” to your SSH linux servers (Kali/ ubuntu / redhat / centos)

SSHD | SSH Server

Page 17: Network Security Testing with NMAP Workshop1

Scan Phases and Basic Options

Page 18: Network Security Testing with NMAP Workshop1

nmap 192.168.10.201

Page 19: Network Security Testing with NMAP Workshop1

Nmap Gear stick – Get Stealthy• -sS• -sn• -iL file• --top-ports• -O• -sX• --open• -PU• --script• -PE• --traceroute• -sF• -oN file• -Pn

Page 20: Network Security Testing with NMAP Workshop1

Nmap Scan PhasesTarget Expansion

Host Enumeration

Reverse DNS Resolution

Port Scanning

Version Detection

OS Detection

Traceroute

Script Scanning

Output

Page 21: Network Security Testing with NMAP Workshop1

Target Expansion• Single 192.168.10.201• Namewww.domain.com• List 192.168.10,55.1,10• Range 192.168.10.2-29 172.16.-4.1 10.-.20.255• CIDR 192.168.128.240/29

Page 22: Network Security Testing with NMAP Workshop1

Combinations• 192.168.10.201 www.domain.com• 192.168-172.-.1,254• 50.50.50.65/28 www.domain.com ftp.domain.com

pop.domain.com

Page 23: Network Security Testing with NMAP Workshop1

Expansion Testing• -sL, list Scan• nmap –sL 192.168.10.1/29

Note: Cannot use –F (fast scan) –p (port scan)

Page 24: Network Security Testing with NMAP Workshop1

File Input• -iL file name (contains list of IPs, ranges & network)

Page 25: Network Security Testing with NMAP Workshop1

Reverse DNS Resolution• Nmap -p 80 www.domain.com• -n (disable rDNS)• -R (Enable rDNS)

Page 26: Network Security Testing with NMAP Workshop1

Port Scanning• Explicitly using -p flag• By reference using nmap-services

Page 27: Network Security Testing with NMAP Workshop1

-p flag• Single port: 443• List of ports: 80,81,443,21,8080• Rage: 135-139 / -1024 / -• Protocol: U:25 T:25

Page 28: Network Security Testing with NMAP Workshop1

nmap-services

Page 29: Network Security Testing with NMAP Workshop1

nmap-services• Name: ftp• Wildcard: http*• --top-ports count• --port-ratio frequency

Note: nmap scan the top 1000 ports by default

Page 30: Network Security Testing with NMAP Workshop1

nmap-services• -p 80,443,8080-8090• -p http,ftp*,25• -p U:53,123,161 T:1-1024,3306

Page 31: Network Security Testing with NMAP Workshop1

Output• Interactive (press enter)• --reason (includes result)• --open (only for open ports)• -o (save results in different formats)

- N, Normal- X, XML- G, grepable

Page 32: Network Security Testing with NMAP Workshop1

Host Enumeration and Network Mapping

Page 33: Network Security Testing with NMAP Workshop1

Nmap Scan PhasesTarget Expansion

Host Enumeration

Reverse DNS Resolution

Port Scanning

Version Detection

OS Detection

Traceroute

Script Scanning

Output

Page 34: Network Security Testing with NMAP Workshop1

NMAP send specially crafted packet to the target host and then analysis the responses

Active Probing

Page 35: Network Security Testing with NMAP Workshop1

Application

Presentation

Session

Transport

Network

Data link

Physical

Nmap operates at Network & Transport Layers

OSI Models

Page 36: Network Security Testing with NMAP Workshop1

Network Layer

Responsible for the movement or routing of packets across the network

Page 37: Network Security Testing with NMAP Workshop1

Transport Layer

Provides the flow of data between two hosts, for the application layer above

Page 38: Network Security Testing with NMAP Workshop1

Transport Layer

• Internet Control Message Protocol (ICMP)• User Datagram Protocol (UDP)• Transmission Control Protocol (TCP)

Page 39: Network Security Testing with NMAP Workshop1

ICMP

• Used to send messages from one computer to another or perform diagnostics

• Works on IP Layer and functions on TCP Layer

Page 40: Network Security Testing with NMAP Workshop1

UDP• Unreliable

- No guarantee of delivery- No error checking- No delivery validation

• Connectionless- No handshaking- No packet ordering- No duplicate protection

• Low overhead• Reduced latency

UDP is a perfect solution, strong example is DNS & Syslog

Page 41: Network Security Testing with NMAP Workshop1

TCP• Reliable• Ordered• Error-checked

Page 42: Network Security Testing with NMAP Workshop1

TCP Session

Page 43: Network Security Testing with NMAP Workshop1

Host Enumeration with TCP• -PS• -PA• nmap -n -sn -PE -PP -PM -PU -PS -PA 192.168.10.201

Note: Best for Network Auditing

Page 44: Network Security Testing with NMAP Workshop1

Traceroute• Nmap -n -p 80 --traceroute 192.168.10.1 / wateen.com

Note: Best technique to bypass firewall over port 80

Page 45: Network Security Testing with NMAP Workshop1

UDP and TCP Port Scanning

Page 46: Network Security Testing with NMAP Workshop1

Scan PhasesTarget Expansion

Host Enumeration

Reverse DNS Resolution

Port Scanning

Version Detection

OS Detection

Traceroute

Script Scanning

Output

Page 47: Network Security Testing with NMAP Workshop1

Host Enumeration• What function does the systems performs• What services does this offer• Is the system is Mail Server, Database Server, Web Server or

etc…• Nmap can help us to determine through port scanning

Page 48: Network Security Testing with NMAP Workshop1

Host Enumeration – How Port Scanning Help• We find the system with the open service port 25, recognized as a

mail server• Might have other applications associated with mail server running on

at the same time• Proper network security audit should be able to identify all services

running on a particular system

Page 49: Network Security Testing with NMAP Workshop1

Scan Options• -s (lower case)

- U, UDP- S, SYN- T, TCP/ Full- N, Null- F, FIN- X, Xmas- A, ACK

Page 50: Network Security Testing with NMAP Workshop1

Port Scan Results

Open

Application Reply

Closed

UDP: ICMP unreachable

TCP, RST

Error Message

ICMP 3,X/ Port Prohibited

Filtered

No Response

Page 51: Network Security Testing with NMAP Workshop1

UDP Port Scanningnmap -sU 192.168.3.1

nmap -sU –p 53 192.168.3.1 --reason

Page 52: Network Security Testing with NMAP Workshop1

TCP Connect Port Scanning• Nmap perform complete 3-way handshake, if the connection is

establish nmap terminate the connection with the reset packet• Very noisy and can detect easily• Bad idea to use this type of scan

nmap -sT 192.168.3.1

nmap -sT –p 80 192.168.3.1 --reason

Page 53: Network Security Testing with NMAP Workshop1

TCP Half-Open Port Scanning• Nmap perform half-open scan• By nmap uses this switch

nmap -sS 192.168.3.1

nmap -sS –p 80 192.168.3.1 --reason

Page 54: Network Security Testing with NMAP Workshop1

TCP Null,Fin,Xmas Port Scanning• Use only on last resort when IDS/IPS blocked your IP

nmap –sN –p 80,443 192.168.3.1nmap –sF –p 80,443 192.168.3.1nmap -sX –p 80,443 192.168.3.1

Page 55: Network Security Testing with NMAP Workshop1

TCP Ack Scanning• Send acknowledgement to existing ports and assume get reply

from ports• Very secure and undetectable

nmap -sA -p 80,443 192.168.3.1

Page 56: Network Security Testing with NMAP Workshop1

Performance and Timing

Page 57: Network Security Testing with NMAP Workshop1

Scan PhasesTarget Expansion

Host Enumeration

Reverse DNS Resolution

Port Scanning

Version Detection

OS Detection

Traceroute

Script Scanning

Output

Page 58: Network Security Testing with NMAP Workshop1

Performance vs Accuracy• These option effect on Host & Port scanning phases• If we scan a target and get immediate response then no need

to worried about performance issues or accuracy, because quickly & shortly target is there and port is open or closed

• If we don’t get a response it could be network is slower or congested, might be firewall is blocking access or all kind of things

• By default Nmap delay scan waiting and sending repeat probes, all attempt to be as accurate as possible but takes time because of scanning 1000 ports

• Network security testers can pick the right balance between speed and precision

Page 59: Network Security Testing with NMAP Workshop1

Arguments• Time

- ms- s (default)- m- h

• nmap --host-timeout 5m 192.168.3.1• nmap --host-timeout 3h 192.168.3.1

Page 60: Network Security Testing with NMAP Workshop1

Timings Templates• -T<0-5>

- 0, paranoid (for IDS evasion)

- 1, sneaky (for IDS evasion)

- 2, polite (slows down the scan to use less bandwidth and target machine resources)

- 3, normal (normal mode is the default so -T3 does nothing)

- 4, aggressive (speeds scans up by making the assumption that you are on a fast and reliable network)

- 5, insane (assumes that you are on an extraordinarily fast network and willing to sacrifice some accuracy)

Page 61: Network Security Testing with NMAP Workshop1

Timings Templates• nmap –T polite 192.168.3.1• nmap –T 4 polite 192.168.3.1

Page 62: Network Security Testing with NMAP Workshop1

Evading Firewalls and Other Sneakiness

Page 63: Network Security Testing with NMAP Workshop1

Scan PhasesTarget Expansion

Host Enumeration

Reverse DNS Resolution

Port Scanning

Version Detection

OS Detection

Traceroute

Script Scanning

Output

Page 64: Network Security Testing with NMAP Workshop1

Anti-Scanning Technologies

Firewalls Network Address Translation (NAT)

Intrusion Detection Systems (IDS)

Page 65: Network Security Testing with NMAP Workshop1

Firewalls • Firewall is a network security system that control network

traffic passing between two or more networks bases on a configured rule sets, its established a barrier between trusted & public networks

• It simply allow or deny packets or payload from source to destination or vice versa

• Decisions are primarily made based on a socket which is the source IP & Port & destination IP & Port

Page 66: Network Security Testing with NMAP Workshop1

Firewalls TypesPacket Filter- Stateless- Stateful

Application Proxy

sT (connect) –sS (half open)- passed according to the rule

Page 67: Network Security Testing with NMAP Workshop1

Firewalls Commonalities• Default deny policy• Rate Limiting

- ICMP (ping of death)- TCP- UDP- ARP

Page 68: Network Security Testing with NMAP Workshop1

Detecting Firewalls• --traceroute• - O• --badsum

Nmap --badsum 192.168.3.1

Page 69: Network Security Testing with NMAP Workshop1

Fragmentation• There are two other ways we might be evade

firewalls- Fragmentation field in IP Header

• Fragmentation helps evade firewalls• Firewalls will often pass the fragments & uninspected

through the target• Fragmentation is most effective when we choose the

fragment size that splits the TCP header in the different packets

Page 70: Network Security Testing with NMAP Workshop1

Fragmentation-f (8 bytes chunks)-f -f (16 bytes chunks)--mtu size (user defined chunks)

nmap -f 192.168.3.1nmap -mtu 24 192.168.3.1

Page 71: Network Security Testing with NMAP Workshop1

IDLE Scan• This type of scan finding the IDLE system• You can use any IDLE system on your network

nmap -sI <Source IP> <Destination IP>

Page 72: Network Security Testing with NMAP Workshop1

Intrusion Detection Systems - IDS• IDS is a device that monitor network traffic for

malicious activity and produces report about policy violations

• Its works in promiscuous mode and perform analysis of passing traffic for entire subnets

• Once attack is identified or abnormal behavior sensed an alert can be send to Network Administrator

• IDS can be configured to look many signed to attack including Signatures, Anomalies & Packet Rates

Page 73: Network Security Testing with NMAP Workshop1

Avoiding IDS Detection• -T (paranoid)• Set the performance templates sufficiently low to avoid

detection• -S <spoof source -IP Address>, -e interface• --spoof-mac

- Full MAC Address- Prefix- Vendor Name

nmap -e eth0 192.168.3.1nmap -S 192.168.1.1 192.168.3.1nmap --spoof-mac Cisco 192.168.3.1

Page 74: Network Security Testing with NMAP Workshop1

Decoys• We can hide our scan, flood the IDS with misleading data• IDS may see scan come from multiple source and wont know

for sure which one is really initiating the probes ( and you are innocent)

• This may significantly degrade the performance of scan

nmap -D 192.168.1.10, 192.168.1.11, 192.168.1.12 192.168.3.1

Page 75: Network Security Testing with NMAP Workshop1

OS & Service Version Detection

Page 76: Network Security Testing with NMAP Workshop1

Scan PhasesTarget Expansion

Host Enumeration

Reverse DNS Resolution

Port Scanning

Version Detection

OS Detection

Traceroute

Script Scanning

Output

Page 77: Network Security Testing with NMAP Workshop1

Port Scan Result

Page 78: Network Security Testing with NMAP Workshop1

Versioning OutputNmap tries to determine from their database• Service Protocol (http, https, ftp)• Application Name (Apache, IIS)• Version Name (2.2, 2.4, 7, 7.5, 8)• Hostname (FQDN)• Device Type• OS family

Page 79: Network Security Testing with NMAP Workshop1

Version Detection-sV--version-intensity <0-9> (default = 7)--version-light <0-9> (intensity = 2)--version-all<0-9> (intensity = 9)

nmap -sV --version-intensity 4 192.168.3.1nmap -sV -p 8080 192.168.3.1

Page 80: Network Security Testing with NMAP Workshop1

OS DetectionNmap is usefull for• Network Inventory• Support/Patching• Unauthorized Devices• OS detection is most effect if Nmap can find one open and one close

port

Page 81: Network Security Testing with NMAP Workshop1

OS Detection• -O

- --osscan-limit- --osscan-guess, --fuzzy- --max-os-tries num (default = 5)

nmap –O –p 80,81 192.168.3.1

Page 82: Network Security Testing with NMAP Workshop1

Nmap Scripting Engine

Page 83: Network Security Testing with NMAP Workshop1

Scan PhasesTarget Expansion

Host Enumeration

Reverse DNS Resolution

Port Scanning

Version Detection

OS Detection

Traceroute

Script Scanning

Output

Page 84: Network Security Testing with NMAP Workshop1

Nmap NSE Scripts• -sC

- --script = default http://nmap.org/nsedoc/ 484 scritps

• --script = scripts, script-category• Nmap contains 15 default scripts

- auth - dos - malware- discovery - intrusive - vuln- fuzzer - version - default- safe - brute - external- broadcast - exploit - safe

Page 85: Network Security Testing with NMAP Workshop1

Script Examplenmap -sC –p 80 www.cnn.com

nmap -sC --script=default -p 80 www.wateen.com -Pn

Page 86: Network Security Testing with NMAP Workshop1

Nmap Script CapabilitiesVersion Detection

Network Discovery

Vulnerability Detection

Backdoor Detection

Vulnerability Exploitation

Page 87: Network Security Testing with NMAP Workshop1

Script Examplenmap -p pptp -sV 12.49.222.65 50.242.75.238

nmap -p 80 --script http-headers,http-chrono www.wateen.com

nmap -p 80 --script http-email-harvest bbc.com

nmap --script ipidseq 8.8.8.8

nmap -p 23 --script telnet-brute --script-args userdb=user.lst,passdb=pass.lst 192.168.0.12

Page 88: Network Security Testing with NMAP Workshop1

Q & Ainteractive learning , building relationships and

problem solving's