Scanning tools
Nmapβ
- Scans network by sending specially crafted packets
- Allows finding hosts on network with service, OS and firewall information
- Allows custom scripts written in LUA using NSE (Nmap Scripting Engine)
- π‘ Can be used to detect and/or exploit vulnerabilities
- E.g. can detect shellshock using nmap scripting engine
- Includes
- π€ Used often in movies including Matrix Reloaded, see the list
- See also Nmap | Network footprinting and Nmap | Vulnerability analysis.
Phases of an Nmap scanβ
- Script pre-scanning: Runs NSE scripts that are run once per execution for each targets, e.g.
dhcp-discover
. - Target enumeration: Resolves DNS names, CIDR network notations etc. to list of IPv4 or IPv6 addresses
- Host discovery (ping scanning): Checking if a host (or which hosts are) is alive before deeper investigation
- Reverse-DNS resolution: Provides IP numbers for hosts that are alive
- Port scanning: Probes are sent and remote port states are classified as
open
,closed
,filtered
- Version detection: Determines what server software is running on remote system
- OS detection: Determines OS that's running on the port
- Traceroute: Usually involves another round of reverse-DNS resolution for intermediate hosts.
- Script scanning: Runs most of the scripts rather than pre-scan and post-scan phases.
- Output: Prints results using different options e.g. XML
- Script post-scanning: Runs scripts that process results and deliver final reports and statistics
Common Nmap optionsβ
- π All options are important for a security tester to be able to use Nmap.
-n
(no resolution): Skips DNS resolution and scanning for DNS addresses-A
: Enable β’ OS detection β’ version detection β’ script scanning β’ traceroute--traceroute
: Enables trace routing--script
or-SC
: Activates custom script scanning
-s*
: port scan optionsβ
- Uses ICMP echo request, TCP SYN to port 443, TCP ACK to port 80, and an ICMP timestamp request.
-sn
- Also known as ping scan or host discovery
- Skips port scanning
- Common commands include:
-P*
: ping (host discovery) optionsβ
-P*
options are used to select different ping methods- User with
-sn
to skip port scanning and do host discovery only. - Common commands include:
Specifying portsβ
-p-
to scan all ports (1-65535
)-p
: only scan specified ports- E.g.
-p U:53,111,137,T:21-25,80,139,8080
- E.g.
-r
: Scan ports consecutively - don't randomize
-O
: OS fingerprintingβ
-O
is used for operating system fingerprinting- It's Far more effective if at least one open and one closed TCP port are found.
- Flag with
--osscan-limit
and Nmap will not try OS detection against hosts that do not meet this criteria.
- Flag with
--fuzzy
or--osscan-guess
switch: Nmap will guess more aggressively- βRequires
sudo
privileges - See also banner grabbing
-o*
: output optionsβ
-oX
for XML output.-oG
forgrep
able output to be able to use linuxgrep
command to search in text- β Not to be confused with
-O
(OS fingerprinting)
Faster scansβ
-T*
: Timing template- From slowest to fastest:
-T0
(paranoid),-T1
(sneaky),-T2
(polite),-T3
(normal | default),-T4
(aggressive) or-T5
(insane)
- From slowest to fastest:
-F
: Fast (limited port) scan- Nmap as default most common 1000 ports,
-F
reduces it to 100
- Nmap as default most common 1000 ports,
- β If the scan is too fast the system can drop the packets
- Risky because the system can cancel the whole scan when it detects for the first time.
Target specificationβ
nmap <target>
- Everything that isn't an option (or option argument) is treated as a target host specification
- Target can be IP address(es) or hostname(s) (resolved via DNS)
- Target can be specify single or multiple hosts:
- Scanning single host:
- E.g.
nmap 192.168.10.0
(IP address) ornmap localhost
(hostname)
- E.g.
- Scanning many hosts:
- CIDR style addressing
- E.g.
192.168.10.0/24
would scan the 256 hosts
- E.g.
- Octet range addressing (more flexible)
- E.g.
192.168.0-255.1-254
- Full octet scan:
192.168.0.*
- E.g.
- Using target list:
nmap -iL targets
- Scan multiple addresses using
nmap <target-1>, <target-2> ...
- E.g.
nmap privacy.sexy cloudarchitecture.io
- E.g.
- CIDR style addressing
- Scanning single host:
Hpingβ
- Open-source port scanner
- Sends custom ICMP, UDP, or TCP packets and then displays any replies
Hping vs Nmapβ
nmap
can scan a range of IP addresseshping
can only port scan one individual IP address
hping
is more lower level and stealthier thannmap
hping
does not support IPv6 whilenmap
does.
Common hping commandsβ
--tcp-timestamp
- Enables TCP timestamps
- Tries to guess the timestamp update frequency and the remote system uptime.
- β Many firewalls drop packets without timestamp.
-Q
or--seqnum
- Collects sequence numbers generated by target host
- Useful when you need to analyze whether TCP sequence number is predictable.
- Setting flags using
-F
(FIN
),-S
(SYN
),-R
(RST
),-P
(PUSH
),-A
(ACK
),-U
(URG
)
- Scanning entire subnet:
hping3 -1 10.0.1.x
- Listen to traffic (e.g. to sniff):
hping3 -9 HTTP -I eth0
- See also its man page
Mobile toolsβ
- IP Scanner for IOS
- Fing for IOS and Android