CEH Module 3
CEH Module 3
CEH Module 3
3.1 SCANNING
Scan Types
Scanning Tools
The goal of scanning is to ultimately find vulnerable targets that you can exploit!
Can be:
Active (engage the target for information)
Passive (sniff traffic for information)
Discovery Scan
Find potential targets
Port Scan
See what services hosts are running
Vulnerability Scan
See if those services are vulnerable to hacking
Other Scans
Map hostnames - IP addresses - MAC addresses
Identify additional supported protocols
Stealthy alternatives to port scans
Tools include:
Nmap
Ettercap
Metasploit
Cain & Abel
TCP SYN, ACK, FIN, etc. packets to common ports such as 80 or 443
ICMP timestamp
Used by network routers to synchronize their system clocks for time and date
SCTP Init
A newer Layer 4 protocol that can manage sessions
Uses a heartbeat to immediately notify if a connection is down
Available in some versions of Linux and Solaris
A client and server will each have its own port in a conversation
Usually not the same port
Registered
1024 - 49151
Services can additionally request the use of these ports from the operating system
Dynamic
49152 - 65535
Operating system temporarily assigns a dynamic port to a client process
The port is “returned” to the OS when the client process ends
Client and server ports are usually not the same
Server listens on well-known port for incoming connection attempts
Client process, identified by its own port, attempts to make a connection
The server can accept or reject the connection attempt
Usually based on if there is a listening service on that port
Can also have firewall filtering or other policies that block connections from specific clients
51111
Client Server
192.168.1.100 192.168.1.200
Port Numbers (TCP, unless noted) Service
21 FTP commands
22 SSH
23 Telnet
25 SMTP
53 (TCP or UDP) DNS
80 HTTP
88 Kerberos
110 POP3
111 (TCP or UDP) *nix portmapper
Port Numbers (TCP, unless noted) Service
135 Microsoft Remote Procedure Call (RPC)
139 SMB (legacy)
143 IMAP4
161 SNMP
(TCP or UDP; only UDP is used at this time)
162 SNMP traps
(TCP or UDP; only UDP is used at this time)
389 LDAP
443 HTTPS
445 Microsoft-ds (authentication used by SMB)
3389 RDP
Look for open TCP or UDP ports
An open port indicates a listening service
Might have exploitable vulnerabilities
Attacker sends ACK probe packet with a random sequence number to target
No response = protected (filtered) by firewall
RST = port is closed
TTL-based
Send 1000s of ACKs to different TCP ports
Analyze TTL field in RST packets received
If less than the boundary value of 64, then port is open
If greater than 64, then port is closed
Window-based
Send 1000s of ACKS to different TCP ports
If WINDOW value of RST received has non-zero value, then port is open
Stealthier than a SYN scan
Does not attempt to start a TCP connection
Used to discover firewall rules / evade detection by IDS
TCP flags are raised in an unusual / illegal pattern
Types include:
XMAS Scan (PSH, URG, FIN)
Null Scan
FIN Scan
Note: We will examine TCP scans in greater detail when we study NMAP and Firewalls
No handshake involved
UDP is a stateless protocol
Sometimes a UDP closed port will return an ICMP port unreachable message
Headers
Banner Grabbing
IP:
TTL
64 = Linux / FreeBSD
Don’t
Fragment
Flag
AKA OS fingerprinting
A way to determine the operating system running on the remote target system
Some services identify themselves when queried
Error messages can reveal information about the service or OS
You can use banner grabbing to identify the service and/or OS version
Responses are compared with a database Sniffing network traffic on the target
to determine the OS allows attacker to determine OS
Response from different Oses vary Page extensions in a URL may assist the
because of differences in the TCP/IP attacker in determining versions
stack
Many tools can grab banners from various services
FTP, SSH, HTTP, SMTP, POP3, IMAP4, DNS, Telnet, Microsoft-DS, Microsoft netbios-ssn, etc.
Can help you focus your attacks on specific services
ID Serve
Identifies the make, model, and version of any web site’s server software
Can also used to identify non-HTTP (non-web) Internet servers: FTP, SMTP, POP, NEWS, etc.
Netcraft
Reports a site’s operating system, web server, and netblock owner together with a graphical view at the
time of the last reboot for each computer in the site
Netcat
A command-line utility
Reads and writes data across network connections using TCP/IP
Telnet
A command-line remote connection utility
Will attempt to open a session to whatever port you specify
Will display any response received from the server
telnet <target IP> <port number>
Most modern FTP servers now have the PORT command disabled
TCP 1900
Enables devices like personal computers, Wi-Fi, Mobile devices, printers etc. to
discover each other
Establish connections for sharing services and data
Also for entertainment purposes
Intended to be used on residential networks
TOOLS
A highly flexible open source tool for scanning networks
Command-line based for Linux and Windows
GUI version of NMAP
Uses NMAP syntax
Created for Windows users
Command line network scanning
Packet crafting
Can perform various scan types
Used for:
Host discovery
Network security auditing
Firewall testing
Manual path MTU discovery
Advanced traceroute
Remote OS fingerprinting
Remote uptime estimating
TCP/IP stack auditing
Packet Count
Source Port
Unfiltered Port is accessible but Nmap doesn’t know if its open or closed.
Only used in ACK scan which is used to map firewall rulesets.
Other scan types can be used to identify whether the port is open.
Open/filtered Nmap is unable to determine between open and filtered.
The port is open but gives no response.
No response could mean that the probe was dropped by a packet
filter or any response is blocked.
Closed/filtered Nmap is unable to determine whether port is closed or filtered
Only used in the IP ID idle scan
Usually routers dynamically choose the best route to send the packet to its
destination
The IP header OPTIONS field allows the sender to specify the route
Admins often disable source routing support on routers for security reasons
The sender can specify:
EXACTLY which hops a packet must pass
through (Strict Source Routing)
SOME of the hops a packet must pass
through (Loose Source Routing)
Specified in the [options] field
You can specify up to 9 hops
Useful if you know there is an alternate Security
route you can use to go around a firewall Strict Source Routing
Perhaps a dialup connection that would Loose Source Routing
ordinarily not be used Record Route
Timestamp
This Wireshark capture shows that Strict Source Routing was set in the IP header of
the captured packet
Two source routes were inserted into the header
One was the sender’s outbound address
A stateless firewall might be configured to allow packets through that appear to be
from a server
E.g. set the TCP source port to 80 makes the packet appear to come from a webserver
Moo Dharma
31337 Pentester
Scan against Windows 10 with Windows Defender firewall dropped
No firewall or stateless;
SYN scan returns 4
SYN open ports - no firewall
ACK
Scan against Windows 10 with Windows Defender firewall turned on
Windows Defender =
stateful firewall
SYN
Stateful firewall
ACK
Scan against CentOS 7 with firewall turned off
No firewall or stateless;
SYN SYN scan returns 3
open ports - no firewall
ACK
Scan against CentOS 7 with firewall turned on
iptables = stateful firewall
ACK
Port scanning the firewall’s front-facing IP might show ports the firewall itself uses
A firewall that NATs and port forwards will present the target ports as if they are its
own ports
To distinguish between a permitted port and the firewall’s management port:
Open a browser to that port
Banner grab that port
Use nmap –sV to interrogate that port
These are little more stealthy than a SYN scan
They can sneak past some stateless firewalls and packet filtering routers
With SYN bit off, they can go past rules that look for SYN raised and ACK set to 0
You’ll need to add -sV to disambiguate open | filtered ports
Technique Purpose
FIN Scan Sets only the FIN bit - breaks the rules of TCP; should be accompanied by ACK
NULL Scan Does not set any TCP bits - breaks the rules; every packet should have some bit set
XMAS Scan FIN, URG, PSH raised - illogical combination
UDP scanning is very slow because nmap must wait for timeout on each port
A Linux kernel will also rate-limit ICMP destination unreachable messages to 1 / second
The the biggest challenges with UDP scanning is that open ports rarely respond to
empty probes
Those ports for which Nmap has a protocol-specific payload are more likely to get
a response and be marked open
For the rest, the target TCP/IP stack simply passes the empty packet up to a
listening application
which usually discards it immediately as invalid
If ports in all other states would respond, then open ports could all be deduced by
elimination
Unfortunately, firewalls and filtering devices also drop packets without responding
If Nmap receives no response after several attempts, it cannot determine whether
the port is open or filtered or filtered by a firewall
Adding service versioning to a UDP scan helps disambiguate the responses
Used to determine exactly which device permits/blocks a port
Good for probing past a firewall into an internal network
Can be used to probe past multiple daisy-chained firewalls
You can manipulate the IP TTL in a scan to distinguish between:
A protected server that does not have that port open
An intermediate firewall that blocks the port from being reached by the scanner
A firewall will return ICMP Type 11, Code 0 (Time Exceeded) if:
The port is allowed
The probe TTL expires at the firewall
Probe must be sent to a live final target
Does not matter if the final target actually listens on that port
Nmap itself will report the port status as filtered
It’s looking for a TCP response, not an ICMP response
A firewalker will notice the ICMP response and report the port as permitted
Packet
expires at
firewall
Because the tool is searching for ICMP errors, it is not necessary to actually reach the
protected host server
If there are multiple packet filtering routers/firewalls in the path, they are all tested
Note: These tools assume there are multiple hops between the attacker and the target firewall.
They may not work as expected in all scenarios.
• Scan TCP ports 8079 – 8080
• Send probes out eth0
• No name resolution
• Firewall (target) is 192.168.1.1
• Server (metric) is 192.168.0.1
Proxy Workbench
A proxy server that displays data passing through it in real time
You can examine TCP/IP connections, view history, save to a file, view a socket connection
diagram
Tor
Routing through the deep web for privacy protection, defense against network
surveillance/traffic analysis
CyberGhost
Anonymous browsing and access to blocked/censored content
Replaces the user’s original IP with an address of their choice
Test web apps by capturing and For Mobile Devices
manipulating your browser’s Online VPN/Proxy service:
interaction with the server: • Shadowsocks
Burp Suite • CyberGhost VPN
These tools run on • Hotspot Shield
Charles your own computer • NetShade
Fiddler
Client app to manage your various
proxy/VPN connections:
Proxy clients: • Proxy Manager
Proxifier
Create a proxy (and other services) on
SocksChain your mobile device:
• Servers Ultimate
Your original packets are encrypted and encapsulated (hidden) inside other packets
You send your traffic to a VPN server on the Internet, in some other part of the world
Your traffic looks like it originated from where the VPN server is
Not where you actually are
I’m in Africa. I need to connect to my bank in the USA.
Because of a high risk of fraud, my bank’s firewall
blocks IP addresses from Africa. So I make a VPN
connection to a server in Belgium. The firewall
doesn’t mind connections originating from Europe.
VPN Tunnel
VPN client app running on your computer/phone
VPN server of your choosing (somewhere on the Internet)
VPN protocols to encapsulate and encrypt your data
Common protocols today:
IPSEC
SSTP
Secure Socket Tunneling Protocol
HTTP/TLS
OpenVPN
TLS-encrypted payload over TCP or UDP
Legacy protocols:
L2TP
Encapsulation + Encapsulating Security Payload (ESP)
PPTP
Point-to-Point Tunneling Protocol
Generic Routing Encapsulation (GRE) + Point-to-Point Protocol (PPP)
They functionally accomplish the same thing
Both are used to hide your true origin
NETWORKS
REVIEW
INTRO TO
Scanning is part of active reconnaissance
ETHICAL
Scanning discovers possible targets on a network:
Live hosts
HACKING
Open ports
Protocols
REVIEW
Service and operating system versions
Can include banner grabbing
HACKING
22 SSH 139 SMB (legacy)
23 Telnet 143 IMAP4
25
REVIEW
53 (TCP or UDP)
SMTP
DNS
161 (UDP)
162 (UDP)
SNMP
SNMP traps
80 HTTP 389 LDAP
88 Kerberos 443 HTTPS
110 POP3 445 Microsoft-ds
111 (TCP or UDP) *nix portmapper 3389 RDP
INTRO TO
TCP uses a three-way handshake to establish sequence numbers and start a session
ETHICAL
SYN, SYN-ACK, ACK
HACKING
FIN, ACK, FIN, ACK
A TCP SYN scan (aka stealth or half-open scan) does not complete the handshake
A TCPREVIEW
Connect scan (aka full or open scan) does complete the handshake
You can also scan raising various TCP flags to test a firewall
You can perform a UDP port scan, but no handshake is involved,
and you might not receive any response from the target
INTRO TO
Port scanning is the immediate prelude to vulnerability testing
ETHICAL
Some scanning tools perform discovery, port scanning, and vulnerability testing all in one
comprehensive scan
HACKING
Packet crafting manipulates TCP/UDP/IP headers to:
Probe open ports
REVIEW
Test firewalls / IDS
You can perform SSDP scans to identify vulnerable home and small
office networks
Nmap is the primary scanning tool used by hackers
Zenmap is a GUI version of nmap for Windows
Hping can also perform scans and packet crafting
INTRO TO
You can use a number of tactics to evade firewall and IDS detection when scanning:
ETHICAL
Source routing
Fragmentation
HACKING
Source port manipulation
Decoys
REVIEW
Address spoofing
Slow timing