Network Scanning Techniques and Tools
Network Scanning Techniques and Tools
Introduction
Cybercriminals are always searching for vulnerabilities, and even a small gap can be enough for
them to strike. Network scanning is your first line of defense, helping identify active devices and
how they interact with internal and external systems. By uncovering hidden vulnerabilities through
specialized network protocols, it provides the insights needed to strengthen your defenses and keep
your network secure.
In this chapter, you will explore:
● Network scanning concepts and their role in identifying vulnerabilities
● Key scanning tools for assessing network security
● Techniques for host discovery and finding active devices
● Methods for port and service discovery to detect open ports and services
● OS discovery using banner grabbing and OS fingerprinting
● Approaches for scanning beyond IDS and firewalls
● Network scanning countermeasures to protect against unauthorized scans
Types of Scanning
There are several types of scanning techniques used in network security and penetration testing to
gather information and identify vulnerabilities. Some of them include:
● Port Scanning: This involves examining the open ports and the services operational on a
designated system. Port scanning, through the examination of TCP and UDP ports, assists in
identifying whether services are actively listening, thereby disclosing details regarding the
operating system and applications currently in operation. Active services that are listening may
expose the system to unauthorized access or misconfigurations, potentially leading to
vulnerabilities.
● Network Scanning: This process involves detecting active hosts and IP addresses within a
network. It may be conducted with malicious intent or to evaluate the network's security.
● Vulnerability Scanning: This method identifies known weaknesses in a system, checking for
exploitable vulnerabilities. A vulnerability scanner uses a scanning engine and a catalog of
known vulnerabilities and exploits for various servers. The scanner may look for issues like
backup files or directory traversal exploits. It helps ensure the security of a server by detecting
common flaws that can typically be fixed through updated patches or proper configuration.
TCP Communication
Internet Protocol (IP) traffic is primarily classified into two types: Transmission Control Protocol
(TCP) and User Datagram Protocol (UDP). TCP operates on a connection-oriented basis,
facilitating bidirectional communication following the successful establishment of a connection.
UDP, on the other hand, is a simpler protocol that operates without establishing a connection. It
transmits multiple messages as packets in segments. Unlike TCP, UDP does not incorporate
features for reliability, flow control, or error recovery within its IP packets. Due to its simplicity,
UDP headers are smaller in size, resulting in reduced network overhead compared to TCP.
Document
EXAM TIP: By mapping the network topology and analyzing TCP communication flags, attackers can gain a
comprehensive understanding of the target network. This insight allows for a more effective and targeted attack
strategy based on the network’s architecture and weaknesses.
The U.S. Department of Defense introduced the TCP/IP model by integrating elements from the
OSI Layer Model and its framework. The TCP and the IP are fundamental standards that form the
foundation of internet connectivity. IP specifies the methodology for data exchange between
computers over a network of interconnected routes, while TCP outlines the process for applications
to establish dependable communication channels within that network. IP is responsible for
addressing and routing, whereas TCP ensures that communication remains coherent and data
integrity is maintained throughout the exchange.
Document
Scanning Tools
Scanning tools play a crucial role in detecting active hosts, open ports, and services in operation, as
well as in collecting diverse information regarding a target network. These tools provide critical
data such as location details, NetBIOS information, and information about all TCP/IP and UDP
open ports. The insights gained from these tools enable ethical hackers to build a detailed profile
of the target organization and its network. By scanning the network for open ports on connected
devices, ethical hackers can uncover potential vulnerabilities, assess the network's security posture,
and identify entry points for further testing.
EXAM TIP: Tools like Nmap, Hping3, and Metasploit help gather detailed network information, such as open
ports, services, and OS details. This data is critical for understanding vulnerabilities and planning penetration testing
efforts.
Nmap
Another way to ping a host is to utilize Nmap to conduct a ping operation. To execute the following
command, please use the command prompt available in either Windows or Linux.
If the command successfully detects an active host and receives a response from the designated
host, it will return a message confirming that the targeted host's IP address, Media Access Control
(MAC) address, and network interface card vendor are operational.
In addition to ICMP echo request packets and ping sweeps, Nmap provides a quick scan option. To
initiate a quick scan, please enter the following command:
Nmap, in a nutshell, offers host discovery, port discovery, service discovery, operating system
version information, hardware address (MAC) information, service version detection,
vulnerabilities, and exploit detection using the Nmap Scripting Engine (NSE).
Note: The Nmap Scripting engine is the most powerful engine for network discovery, version
detection, vulnerability detection, and backdoor detection.
Hping3
Hping3 is a multifunctional command-line utility intended for network scanning and packet
crafting within the TCP/IP protocol suite. It accommodates a range of protocols, including TCP,
UDP, ICMP, and raw IP, rendering it an effective tool for activities such as network security
assessments, firewall evaluations, manual path MTU discovery, advanced traceroute operations,
remote operating system fingerprinting, uptime estimation, and TCP/IP stack evaluations. Hping3
transmits customized TCP/IP packets and analyzes responses from targets in a way similar to a
conventional ping program that utilizes ICMP replies.
The tool is capable of handling packet fragmentation, arbitrary packet body customization, and size
adjustments, allowing for the transfer of encapsulated files over supported protocols. It facilitates
the scanning of idle hosts, the practice of IP spoofing, and the anonymous probing of services,
thereby allowing for discreet network and host scanning. Hping3’s Traceroute mode facilitates file
transfers over covert channels and can verify host availability even when ICMP packets are blocked.
Its firewalk-like capabilities allow it to discover open ports behind firewalls. Additionally, it
performs manual path MTU discovery and enables remote operating system fingerprinting, making
it a comprehensive tool for both legitimate network diagnostics and potential exploitation
activities.
Using Hping, an attacker can analyze the behavior of an idle host to gather valuable information
about the target system. This includes details about the host's services, the ports supporting those
services, and the target's operating system. Such scans often serve as precursors to more intensive
probing or potential attacks.
The general syntax for conducting scans with Hping is as follows:
hping3 <options> <Target IP address>
"Use Hping3 to perform an ICMP scan on the target IP address [Link] and stop after 10
iterations."
Metasploit
Metasploit is a widely used open-source project designed to provide the tools, infrastructure, and
resources required for penetration testing and advanced security auditing. It serves as a valuable
asset for identifying security vulnerabilities, aiding penetration testing efforts, and supporting IDS
signature development. Metasploit simplifies the tasks of attackers, exploit developers, and payload
creators with its versatile and user-friendly design.
One of Metasploit's standout features is its modular approach, which allows users to combine any
exploit with any payload to achieve specific objectives. This flexibility makes it an essential tool for
automating the discovery and exploitation process while also offering comprehensive support for
Document
the manual testing phases of penetration tests. Metasploit Pro, the professional version, enhances
its capabilities by enabling users to scan for open ports and services, exploit identified
vulnerabilities, pivot through networks, gather evidence, and generate detailed test reports.
Host Discovery
Host discovery scanning involves identifying systems that are ‘alive’ and responding on a network.
It is an initial step in the network scanning process. This step is essential for conducting
comprehensive scans to detect open ports and services while avoiding unnecessary scans on
inactive systems. By determining which hosts are live, attackers or analysts can focus their efforts
and streamline the scanning process.
Document
Initially, you must know about the hosts that live in the targeted network. ICMP packets carry out
the process of finding live hosts in a network. The target replies to ICMP echo packets with an ICMP
echo reply. This response confirms that the host is currently active.
This section explores methods to identify live systems in a network using various ping scan
techniques. It also covers ping sweep methods for detecting active hosts and discusses tools
designed to perform efficient ping sweeps.
Host Discovery Techniques
Document
Host discovery techniques are used to identify active or live hosts within a network. As an ethical
hacker, it is essential to understand and utilize various types of host discovery methods to assess
network activity effectively. In Figure 3-07, you have learned some commonly used host discovery
techniques:
ARP ping scans are invaluable for identifying active hosts in a network environment, especially in
LANs, due to their accuracy and ability to bypass traditional IP-layer restrictions. This makes them
a critical tool for network administrators and ethical hackers conducting reconnaissance.
UDP Ping Scan
A UDP ping scan is similar to a TCP ping scan, but it uses the UDP protocol to identify active hosts
in a network. In this method, Nmap transmits UDP packets to the target system in order to assess
its status. By default, Nmap uses the uncommon port number 40,125 to send these UDP packets,
though this can be customized during the compile time by modifying the
DEFAULT_UDP_PROBE_PORT_SPEC parameter.
Attackers or network administrators utilize this method to detect live systems based on their
responses. A UDP response from the target indicates that the host is active and reachable.
Conversely, if the host is offline or unreachable, various error messages may be returned, such as
host or network unreachable or TTL exceeded, providing clues about the host's status.
In Zenmap, the graphical interface for Nmap, the -PU option is used to perform a UDP ping scan,
enabling easy configuration for users. This technique is effective for identifying live systems that
may not respond to other types of probes, making it an essential tool for network reconnaissance
and host discovery.
EXAM TIP: When traditional ICMP or TCP methods fail, consider using a UDP ping scan. This can help detect
live systems that do not respond to common protocols, especially when firewalls block other probes.
ICMP ECHO scanning is commonly employed on UNIX/Linux and BSD-based machines, as these
systems' TCP/IP stack implementations are configured to respond to ICMP ECHO requests, even
those directed at broadcast addresses. However, this technique is not effective in Windows-based
environments because the TCP/IP stack implementation in these systems does not reply to ICMP
probes aimed at broadcast addresses.
By leveraging ICMP ECHO ping scans, attackers and security professionals can efficiently identify
live devices and assess network configurations, providing a foundation for further analysis or
mitigation strategies.
Nmap facilitates ICMP ECHO ping scans using the -P option, enabling users to scan a target
network and identify live hosts. For enhanced efficiency, the number of ICMP pings sent in parallel
can be increased with the -L option, allowing users to adjust the intensity of the scan. Additionally,
the -T option can be used to tweak the ping timeout value, offering greater control over scan
responsiveness and timing.
Document
In Zenmap, the graphical interface for Nmap, the -PE option performs the ICMP ECHO ping scan.
The scan results display active hosts as "Host is up," providing clear feedback on the network's live
devices. These tools and options allow for flexible and effective ICMP scanning, accommodating
various network configurations and requirements.
ICMP ECHO Ping Sweep
An ICMP ECHO Ping Sweep is a fundamental network scanning technique used to identify which
IP addresses within a range correspond to live hosts. Unlike a single ping, which checks the
availability of a specific host, a ping sweep involves sending ICMP ECHO requests to multiple hosts
across a network. Active hosts respond with ICMP ECHO replies, allowing the scanner to map live
systems.
While effective, ping sweeps rank among the oldest and most time-consuming methods of network
scanning. Their simplicity and utility make them widely available across nearly all platforms.
Functioning like a "roll call" for systems on a network, active systems respond to ping queries from
other systems.
ICMP echo scanning involves sending ICMP probes to the broadcast or network address, which
distributes the probes to all host addresses within a subnet. Active hosts reply with ICMP ECHO
responses, enabling attackers or network administrators to identify live systems within the
network. Despite their limitations, ping sweeps remain a foundational approach in network
discovery.
To understand pings fully, it is essential to grasp the concept of the TCP/IP packet. When a system
sends a ping, it transmits a single packet over the network to a specified IP address. This packet
typically contains 64 bytes—56 bytes of data and 8 bytes for protocol header information. The
sender then listens for a return packet from the target system. If the network connections are stable
and the target system is operational, a successful return packet is received. However, disruptions
in communication or an inactive target system will result in no response.
Pings provide valuable insights, including the time taken for a packet to travel to the destination
and return, known as the "round-trip time." They also assist in resolving hostnames. For example,
if a ping to an IP address succeeds but fails when directed at a hostname, it indicates an issue with
the system's ability to map the name to the corresponding IP address.
Attackers or network administrators can use subnet mask calculators to determine the number of
hosts within a subnet.
Document
about the network's subnet mask, which is critical in identifying the network’s size and the range
of IP addresses within it.
As with the ICMP timestamp, the response to an address mask ping is conditional. The target host
may or may not provide the appropriate subnet mask value, depending on how the system
administrator configures it. In environments where traditional ICMP ECHO pings are blocked, the
address mask ping scan can still be effective in identifying active hosts, as it bypasses some of the
typical restrictions on standard ping methods.
The ICMP address mask ping scan is useful for attackers who want to gain information about the
network structure, especially when other methods are being filtered or blocked. In Zenmap, the -
PM option facilitates the execution of an ICMP address mask ping scan. This technique serves as
an alternative method for network discovery in cases where more common ping techniques are not
possible.
TCP SYN Ping Scan
The TCP SYN ping scan is a host discovery method that probes various target ports to verify system
availability and assess the presence of firewall rules. In this method, an attacker uses a tool like
Nmap to initiate the three-way handshake by sending an empty TCP SYN (synchronize) packet to
the target host. If the target system is active, it responds with a SYN-ACK (synchronize-
acknowledge) packet, indicating that the system is online. Once the attacker receives the SYN-ACK
packet, the connection is terminated by sending a TCP RST (reset) packet to the target, as the
objective—host discovery—has been completed.
Port 80 (the default HTTP port) is typically used for this scan, though a range of ports can be
specified. For example, by using a format such as -PS22-25,80,113,1050,35000 (with no spaces), the
probe will be executed against each specified port in parallel. In Zenmap, the -PS option performs
a TCP SYN ping scan to check for active hosts by sending SYN packets to specified ports.
The advantages of TCP SYN ping scans are significant. Firstly, as multiple machines can be scanned
in parallel, the scan avoids time-out errors that often occur when waiting for responses from target
systems. This parallel scanning increases efficiency and reduces delays. Secondly, TCP SYN ping
scans allow attackers to determine if a host is active without establishing a full connection. Since
the scan does not complete the three-way handshake and is terminated with a reset (RST) packet,
Document
no persistent connection is logged at the system or network level. This makes the scan more
stealthy, enabling attackers to carry out their discovery without leaving detectable traces.
TCP ACK Ping Scan
TCP ACK ping is a host discovery technique where the attacker sends an empty TCP ACK packet to
the target, commonly on port 80, to check for system responsiveness. Since there is no established
connection between the attacker and the target, the host responds to the incoming ACK packet
with an RST flag to terminate the request. The attacker's receipt of this RST packet indicates that
the target host is active. In Zenmap, the -PS option facilitates the execution of a TCP SYN ping scan.
One of the key advantages of the TCP ACK ping technique is its ability to bypass firewall
restrictions. Firewalls often block SYN packets, as they are commonly used for connection attempts,
but ACK packets are less likely to be filtered. This makes the ACK ping a useful method for probing
hosts, particularly in environments where firewalls are configured to block SYN ping packets.
IP Protocol Ping Scan
The IP Protocol Ping Scan is a host discovery method that involves sending IP ping packets using
various IP protocols to determine whether a host is online. This technique works by sending packets
with an IP header of a specified protocol number, much like TCP and UDP ping scans. By utilizing
different IP protocols, the scan attempts to elicit a response from the target host, signaling its
activity.
When no specific protocol is defined, the scan, by default, sends packets using the following
protocols: ICMP (protocol 1), IGMP (protocol 2), and IP-in-IP (protocol 4). These protocols are
commonly used for network management and communication. However, when targeting specific
protocols such as ICMP, IGMP, TCP (protocol 6), and UDP (protocol 17), the packets must include
the appropriate protocol headers. For non-TCP/UDP protocols, the packet consists solely of IP
header data.
Document
The IP Protocol Ping Scan offers flexibility for discovering hosts that might otherwise be concealed
behind firewalls or filtering mechanisms that block common ping methods. By using a range of
protocols, this scan increases the chances of successfully identifying active hosts. To customize the
default protocols used during the scan, users can modify the
DEFAULT_PROTO_PROBE_PORT_SPEC setting in the Nmap configuration file (nmap.h) during
compile time.
Host Discovery with AI
AI-powered technologies can significantly enhance and automate host discovery tasks, allowing
attackers to identify live hosts on a target network quickly and efficiently. With AI's capabilities,
attackers can streamline and automate the discovery process, removing much of the manual effort
involved.
Example:
An attacker could use a tool like ChatGPT to generate a specific prompt such as:
“Scan the target network [Link]/24 for active hosts and place only the IP addresses into a
file [Link].”
Table 3-2: Description of Nmap for identifying live host in a target server
EXAM TIP: Ping sweep tools such as SolarWinds and Angry IP Scanner check a range of IP addresses to discover
active devices. They can also carry out DNS lookups and identify MAC addresses, although firewalls might prevent
them from doing so.
If a closed port is encountered while using Full Open Scanning, the RST response is sent to the
incoming request to terminate the attempt. To perform a Full Open Scan, you must use the -sT
option for Connect Scan.
For example, consider the result illustrated in the figure 3-19 provided below. The Zenmap tool is
used to perform a Full Open Scan.
Document
Figure 3-26: Inverse TCP Flag Scan When the Port is Open
Figure 3-27: Inverse TCP Flag Scan When the Port is Closed
In this technique, attackers send probe packets to specific target ports to gather information. If the
port is open, the host typically does not respond, as it is configured to ignore unsolicited packets.
However, when the port is closed, the host sends an RST (reset) packet back. This behavior is based
on RFC 793, which states that a connection reset (RST/ACK) is returned when a port is closed.
Document
To exploit this, attackers use different flag configurations for probing the target, including:
FIN probe Only the FIN flag is set.
Xmas probe The flags URG, FIN, and PUSH are set.
NULL probe No flags are set.
SYN/ACK probe SYN and ACK flags are set.
Operating systems like Windows may ignore the RFC 793 standard, meaning no response is sent
for closed ports. This makes inverse TCP flag scanning more effective against UNIX-based systems,
where the RST/ACK response is more predictable and easier to detect.
Xmas Scan
An Xmas Scan is a type of scan that activates multiple flags, including the URG, PSH, and FIN flags,
creating an unusual condition for the receiver. When the target system receives such a packet, it
must decide how to handle the situation. If the port is inaccessible, the system will reply with a
single RST packet. If the port is open, some systems may respond as if the port is open, but modern
systems typically ignore or drop the request because the combination of flags is invalid.
On the other hand, a FIN Scan works only with operating systems that follow TCP/IP configurations
based on RFC-793. This scan method does not work with modern versions of Windows, such as
Windows XP or Windows Vista, as they handle the FIN flag differently and do not respond as older
systems would.
Step: 0 1
● Transmit a SYN+ACK packet to the Zombie in order to retrieve its IPID number.
Document
● Zombie is not waiting for SYN+ACK; hence, it responds with the RST packet. Its reply discloses
the IPID
● Extract IPID from the Packet
Step: 02
● This SYN packet is transmitted to the target using a forged IP address that appears to come
from a Zombie system.
● When the target's IP port is open, it sends a SYN+ACK packet to the Zombie in response. The
Zombie then replies to the target with an RST packet.
● If the port is closed, the target transmits an RST response to the Zombie; however, the Zombie
does not relay any response back to the target. IPID of Zombie is not incremented
Step: 03
● Send the SYN+ACK packet to Zombie again to receive and compare its IPID Numbers to the
IPID extracted in step 0 1 (i.e., 1234)
● Zombie responds with the RST packet. Its reply discloses the IPID
● Extract IPID from the Packet
● Compare the IPID
● The port is considered open if the IP Identification Number (IPID) increments by 2.
UDP Scan
Just like TCP-based scanning techniques, there are also methods for scanning UDP. However, it is
important to note that UDP is a connectionless protocol, meaning it does not establish a formal
Document
connection before sending data. UDP packets work with ports; no connection orientation is
required. No response will be received if the targeted port is open; however, if the port is closed, a
response message will be received stating, "Port unreachable." Most malicious programs, Trojans,
and spyware use UDP ports to access the target.
Advantage:
A UDP scan is less formal when it comes to open ports because it bypasses the overhead of a TCP
handshake. Nonetheless, in the event that ICMP responses are generated for inaccessible ports, the
total quantity of frames may surpass that of a typical TCP scan. Since Microsoft-based operating
systems rarely implement ICMP rate limiting, UDP scans can be performed very efficiently on
Windows-based devices.
Document
Disadvantage:
UDP scans provide limited information and only offer port availability. To obtain additional details,
such as version information, a version detection scan (-sV) or OS fingerprinting (-O) must be
conducted alongside the UDP scan. Furthermore, privileged access is required, making this option
only available to users with the appropriate permissions. Due to the higher volume of TCP traffic
on most networks, UDP scans typically exhibit lower efficiency than TCP scans.
The SCTP INIT scan is a fast technique that allows for scanning thousands of ports per second on
a network with minimal interference from firewalls, making it ideal for networks with stronger
security measures. This scan is similar to the TCP SYN scan but is stealthier and less intrusive
because it does not complete the full SCTP association, leaving the connection half-open.
Document
In this process, attackers initiate the connection by sending an INIT chunk to the target system. If
the target port is open, the system responds with an INIT+ACK bit. This acknowledges the request.
Figure 3-38: SCTP INIT Scan When a Port Is Not Listening (Closed)
In the event that the port is either closed or inactive, the response will consist of an ABORT chunk.
If there is no reply following several retransmissions, the port is considered to be filtered.
Additionally, filtered ports may also result from receiving an ICMP unreachable error from the
target server.
Figure 3-39: SCTP COOKIE ECHO scan result when a port is open
Document
Figure 3-40: SCTP COOKIE ECHO Scan Result for a Closed Port
The SCTP COOKIE ECHO scan is less noticeable than the INIT scan, making it more stealthy and
harder to detect. The system is unable to effectively differentiate between open and filtered ports,
frequently presenting both categories as "open|filtered" in the scanning results.
IPv6 Scan
IPv6 scanning is more challenging and complex compared to IPv4 due to the expanded address
space, which increases from 32 bits to 128 bits, providing a larger search space of 2^64 addresses
within a subnet. Traditional scanning methods are less feasible for IPv6 networks because of this
vast address space, and many scanning tools do not support ping sweeps on IPv6. Attackers often
collect IPv6 addresses from network activity, logs, or email headers for later port scanning. Once
an attacker compromises one host within an IPv6 subnet, they can probe all hosts using link-local
multicast addresses or by utilizing address schemes if the host numbers are sequential. However,
performing a full scan of IPv6 addresses is computationally intensive, and scanning a subnet could
take years at a conservative rate. Nmap supports IPv6 scanning, with the -6 option used in Zenmap
to perform these scans.
Port Scanning with AI
Document
Port scanning with AI allows attackers to automate and streamline the process of identifying open
ports on a target network. Using AI-powered tools, such as ChatGPT, attackers can quickly and
efficiently issue commands to Nmap for scanning tasks.
Example # 1
Attackers can ask AI models like ChatGPT to help them use Nmap by giving instructions like:
"Use Nmap to find open ports on target IP [Link]
The following Nmap command is designed to perform port scanning, service enumeration, and
version detection on a specific target IP address. The command identifies open ports, determines
the services running on those ports, and retrieves the versions of those services.
Document
Table 3-3: Description of the Nmap Command for Service Version Discovery
● Scan from a Favorable Network Location: Performing Nmap scans from the host's local
network typically provides better results and a higher degree of security, as it allows for internal
network defense-in-depth. External scanning, however, is necessary when performing firewall
tests or when assessing the network from the perspective of an external attacker. Choosing the
right scanning location can impact scan speed and accuracy.
● Increase Available Bandwidth and CPU Power: To further reduce scan times, increasing
available bandwidth or CPU power can make a significant difference. This can be achieved by
upgrading network lines or halting other bandwidth-intensive processes during the scan.
Additionally, Nmap’s congestion control algorithms prevent network flooding, ensuring that
the scan remains accurate and efficient while making the best use of available resources.
2. NULL Packet Test: Sends a TCP packet with no flags enabled (a NULL packet) to an open TCP
port.
3. Combination Flag Test: Sends a TCP packet with the URG, PSH, SYN, and FIN flags enabled
to an open TCP port.
4. ACK Test (Open Port): This test sends a TCP packet with the ACK flag enabled to an open
TCP port.
5. SYN Test (Closed Port): This test sends a TCP packet with the SYN flag enabled to a closed
TCP port.
6. ACK Test (Closed Port): This test sends a TCP packet with the ACK flag enabled to a closed
TCP port.
7. URG, PSH, and FIN Test: Sends a TCP packet with the URG, PSH, and FIN flags enabled to a
closed TCP port.
8. Port Unreachable (PU) Test: This test sends a UDP packet to a closed UDP port, aiming to
extract an "ICMP port unreachable" message from the target system.
9. TCP Sequence Ability (TSeq) Test: Sends six TCP packets with the SYN flag enabled to an
open TCP port to analyze the patterns in the initial sequence numbers (ISN) generated by the
TCP implementation.
These tests are designed to identify distinct patterns in the responses and compare them to a
signature database. This allows attackers or security professionals to identify the operating system
and its version with high accuracy. The active banner-grabbing technique provides critical insights
into the target system's characteristics, which can be used to identify potential vulnerabilities.
to gathering this information without triggering alarms, making them a preferred technique in
environments with active IDS/IPS systems.
The results from these scripts are displayed in both the Nmap normal and XML output formats,
providing detailed OS information about the target machine.
OS Discovery using IPv6 Fingerprinting
IPv6 fingerprinting is a technique used to identify the OS of a target machine by sending probes
and analyzing the responses, similar to IPv4 fingerprinting. In contrast, IPv6 incorporates more
sophisticated probes along with a dedicated OS detection engine specifically designed for IPv6
environments. Nmap transmits approximately 18 probes in a designated sequence to facilitate IPv6
operating system discovery. These probes include sequence generation (S1–S6), ICMPv6 echo
requests (IE1 and IE2), Node Information Queries (NI), Neighbor Solicitation (NS), UDP (U1), TCP
explicit congestion notification (TECN), and various TCP probes (T2–T7). This allows attackers to
identify the OS running on a target system using the distinct behaviors of IPv6. In Zenmap, the -6
option, along with the -O option, is used to perform OS discovery via IPv6 fingerprinting.
nmap -6 -O <target>
OS Discovery with AI
Attackers can leverage AI-powered technologies, such as ChatGPT, to automate and streamline OS
discovery tasks. By utilizing AI, attackers can quickly identify the operating systems running on
target IP addresses in a network.
Example:
The attacker uses chatGPT to use TTL ping commands to find the target OS, such as the following
prompt:
"Use TTL to identify the operating system running on the target IP address [Link]."
ping -c 1 [Link] && echo "Check the TTL value from the response to infer the OS (Linux/Unix: 64, Windows: 128)"
The command sequence begins with ping -c 1 [Link], which sends a single ICMP echo request to
the target IP address ([Link]) to verify if the host is reachable. If the ping is successful, indicated
by the use of &&, the subsequent command is executed. The next command, echo "Check the TTL
Document
value from the response to infer the OS (Linux/Unix: 64, Windows: 128)", displays a message
instructing the user to check the Time to Live (TTL) value in the response. The TTL value can help
determine the operating system: a TTL of 64 is commonly associated with Linux/Unix systems,
while a TTL of 128 typically corresponds to Windows systems. This process allows attackers to infer
the target system’s OS based on the TTL value from the ICMP response.
Develop and Execute a Custom Script to Automate Network Scanning Activities with AI
Attackers can leverage the power of AI to automate network scanning tasks, enhancing efficiency
and enabling the execution of custom scripts that gather detailed information about target systems.
By leveraging AI technologies like ChatGPT, attackers can craft tailored prompts to develop scripts
that streamline the process of discovering live hosts, identifying open ports, enumerating running
services, and detecting service versions within specific IP ranges.
Example:
An attacker could use a prompt such as:
"Develop a script that will automate network scanning efforts and find out live systems, open ports,
running services, service versions, etc. on target IP range [Link]/24."
Zenmap, a graphical interface for Nmap, provides support for SYN/FIN scans using IP
fragmentation, as demonstrated in the accompanying screenshot.
Source Routing
An IP datagram consists of multiple fields, including the IP options field, which stores source
routing information. This field specifies a list of IP addresses that determine the route the packet
takes to its destination. Typically, as an IP packet traverses a network, routers examine its
destination IP address to determine the next hop for forwarding.
Attackers exploit the source routing mechanism by embedding malformed packets with a
predefined route in the IP options field. This technique allows attackers to bypass intermediate
routers or gateways configured with firewalls and Intrusion Detection Systems (IDS) that might
otherwise block their packets. By enforcing a loose source routing mechanism, attackers specify a
partial path for the packet, allowing some routing flexibility. In contrast, a strict source routing
mechanism mandates that the packet follow an exact path defined by the attacker.
By manipulating the IP address path, attackers ensure that packets take an attacker-controlled
route, evading firewall-/IDS-configured routers and effectively reaching the target system
undetected. This strategy allows attackers to bypass network security controls and gain access to
sensitive systems. The accompanying figure 3-37 illustrates source routing, where the originator
specifies the packet's journey through the network.
While modern firewalls with application-level proxies and protocol-parsing capabilities can
mitigate this threat, source port manipulation remains effective against misconfigured or outdated
systems. In Zenmap, the -g or --source-port option allows users to specify a source port for this
purpose, facilitating the evasion of firewall rules. This makes it a powerful tool for attackers to
exploit vulnerabilities in network defenses.
IP Address Decoy
The IP address decoy technique involves generating or manually specifying fake IP addresses
(decoys) to hide the true source of a network scan. Mixing decoy IPs with the attacker's real IP
creates the illusion that multiple IPs are scanning the target simultaneously. This approach makes
it challenging for IDS or firewalls to determine the actual scanning source, complicating their
analysis and response.
Nmap, a popular network scanning tool, supports decoy scans with built-in options. Two primary
methods are:
● Using the -D RND:<number> option, Nmap automatically generates a specified number of random decoy IPs. For
example:
nmap -D RND:10 [target]
In this command, Nmap generates 10 decoy IPs and intermixes them with the real scanning IP.
● The -D option allows manual specification of decoy IP addresses. Optionally, the ME keyword can be used to
position the attacker’s real IP at a chosen spot in the list. For example:
nmap -D decoy1,decoy2,decoy3,...,ME,... [target]
Here, the attacker's real IP is inserted in the position marked as ME. If ME is omitted, Nmap places the real IP in
a random position.
IP Address Spoofing
IP Address Spoofing is a method of gaining unauthorized access to computers by pretending to
have a different IP address. An attacker illegally pretends to be any user's computer by sending
altered IP packets with a fake IP address. The spoofing method includes changing a header with a
fake source IP address, a checksum, and arrangement values. Packet-switched networking causes
an out-of-order series of incoming packets. When these out-of-order packets are received at the
destination, they are reassembled to extract the message.
Document
EXAM TIP: Be aware of IP address spoofing techniques where attackers alter packet headers to masquerade as
another system. Detection methods include checking TTL values and IP Identification (IPID).
IP spoofing can be detected by different techniques, including the direct TTL probing technique
and through IP Identification Number (IPID). In sending direct TTL probes, packets are sent to the
host suspected of sending spoofed packets, and responses are observed. IP spoofing can be detected
by comparing TTL values from the suspected host’s reply. If the TTL value is different from the one
in the fake packet, it will be a spoofed packet. However, TTL values can vary even in normal traffic,
and this technique identifies spoofing when the attacker is on a different subnet.
scanning, particularly when slower timing parameters are used, minimizing the risk of detection by
network monitoring systems and firewalls.
To randomize larger group sizes, the PING_GROUP_SZ parameter is in the nmap.h file can be
modified, followed by recompiling the program. Alternatively, you can create a target IP list using
the list scan command (-sL -n -oN), randomize it with a Perl script, and then provide the
randomized list to Nmap using the -iL option.
Sending Bad Checksums
Attackers may send packets with incorrect or false TCP/UDP checksums to bypass specific firewall
rules. Both TCP and UDP use checksums to ensure data integrity, but improperly configured
systems can reveal information when handling packets with invalid checksums. If a reply is
received, it likely originates from an IDS or firewall that has not verified the checksum. Conversely,
if there is no response or the packets are dropped, it indicates the system may be properly
configured. Nmap enables this technique with the --badsum option, which sends packets
containing invalid TCP, UDP, or SCTP checksums to the target host.
Proxy Servers
Proxy servers anonymize web traffic to ensure user privacy. When an individual seeks to utilize a
resource on a publicly accessible server, the proxy server functions as an intermediary. It facilitates
the interaction between the client and the server on behalf of the user. The request is initially routed
through the proxy server, which processes it, whether it is a web page request, file download, or
connection request to another server. Proxy servers are primarily used to provide access to the
World Wide Web (WWW) by bypassing IP address blocking.
Moreover, proxies provide anonymity, which is critical for attackers looking to cover their tracks
while performing malicious actions. They can also help attackers access restricted websites and
networks, bypassing network restrictions or geographical blocks. By using proxies, attackers can
hide their actions behind layers of anonymity, making it more difficult for security teams or law
enforcement to trace the attack's origin.
EXAM TIP: Attackers use proxy servers to hide their true IP and bypass network defenses. Proxy chaining
involves using multiple proxies to further hide the attacker's identity.
4. CyberGhost VPN
Proxy Switcher
A Proxy Switcher tool scans for the available proxy servers. Any proxy server can be used to mask
your IP address. The figure below shows the proxy server search process performed by the Proxy
Switcher tool.
Anonymizers
Anonymizer is a tool that fully hides or gets clear of identity-related details to make actions
impossible to track. The main reasons for using anonymizers are to reduce risk, spot and stop
information theft, get around limits and censorship, and perform activities online that cannot be
tracked.
Why Use an Anonymizer?
● Ensuring Privacy: Anonymizers make browsing activities untraceable, protecting user identity
until personal information is voluntarily disclosed.
Document
Types of Anonymizers
There are two types of anonymizers include:
1. Networked Anonymizers
It functions by routing user information through a series of interconnected computers before it
reaches the target website. This multi-node process significantly complicates traffic analysis,
making it difficult for anyone to trace the connection back to the original user. For example, if a
user requests to visit a web page, the request is first sent through intermediary computers, such as
A, B, and C, before finally reaching the destination website.
● Advantage: The layered routing structure makes traffic analysis highly complex, enhancing
user anonymity.
● Disadvantage: Each intermediary node in the communication path introduces a potential
vulnerability, as confidentiality may be compromised at any of these points.
2. Single-Point Anonymizers
It works by routing user information through a single intermediary website before forwarding it to
the target website. The target website's response is then passed back to the user through the same
intermediary. This process ensures the user's identity, including their IP address, remains hidden
from the target website.
Anonymizer Tools
Anonymizers utilize technologies like SSH, VPNs, and HTTP proxies to allow access to blocked or
censored internet content while often omitting advertisements.
Whonix:
Whonix is a specialized desktop operating system designed for high-level security and privacy. It
operates on a reconfigured Debian base within virtual machines and uses the Tor network for online
Document
anonymity. This setup mitigates malware threats and IP leaks while maintaining usability, making
it a robust tool for anonymous browsing and security.
AstrillVPN
Another tool for circumventing censorship is AstrillVPN. It is Virtual Private Network (VPN)
software that facilitates bypassing Internet censorship and accessing geo-blocked websites,
applications, and services by concealing the user’s IP address and location. It utilizes advanced data
encryption and secure transmission methods to safeguard user information. Additionally,
AstrillVPN does not log traffic data or DNS queries, ensuring that browsing activity and metadata
remain untraceable, thus offering robust privacy and security features.
Document
● Establish firewall and Intrusion Detection System (IDS) regulations to identify and prevent port
scanning attempts.
● Ensure the firewall inspects the data within each packet, not just the TCP header, to detect port
scanning attempts.
● Test port scanning tools against hosts on the network to ensure firewalls can detect port
scanning activity.
● Keep router, IDS, and firewall firmware updated with the latest releases.
● Configure firewalls to protect against fast port scans and SYN floods.
● Employ an IDS to detect OS detection attempts by hackers using tools like Nmap.
● Limit the number of open ports and filter the rest to reduce the risk of exploitation.
● Use custom firewall rules to block unwanted ports, including 135-159, 256-258, 389, 445, 1080,
1745, and 3268.
● Block unwanted services on open ports and update service versions to non-vulnerable versions.
● Configure border routers to block inbound ICMP messages and outbound ICMP Type 3
(Destination Unreachable) messages.
● Ensure firewalls and routers can block source-routing attempts by attackers.
● Prevent the bypassing of routing and filtering mechanisms through the use of source routing or
specific source ports.
● Test the network configuration with TCP and UDP port scans and ICMP probes to identify
accessible ports.
● Configure anti-scanning and anti-spoofing rules to protect against scanning attempts.
● Ensure commercial firewalls are patched, have defined anti-spoofing rules, and disable fast-
mode services.
● Use TCP wrappers to limit access based on domain names or IP addresses.
● Implement proxy servers to block fragmented or malformed packets.
● Conduct open port scans on empty hosts or honeypots to confuse or mislead port scanning
efforts.
● Use an IPS to detect port scans and blacklist malicious IP addresses.
● Implement port knocking to conceal open ports from unauthorized access.
● Implement egress filtering to control outbound traffic and detect internal hosts scanning
external targets.
● Use VLANs to isolate and restrict access between different types of traffic.
To identify spoofed packets, the hop count is determined by taking the difference between the TTL
(Time to Live) value in the response and the original TTL value in the outgoing packet. If the reply
TTL does not match the original packet's TTL, it suggests that the packet is spoofed. However, if
the attacker is aware of the hop count between the source and the target, they could manipulate
the TTL to avoid detection, leading to a potential false negative. This technique is more effective
when the attacker is in a different subnet from the victim, as the difference in hop count is more
detectable.
IP Identification Number
Users can spoof fake packets by watching the IP Identification (IPID) number in the IP packet
headers. The IPID increases by one with each new packet transmitted by the system. Every IP packet
on a network is assigned a unique IP identification number, which increases incrementally with
each transmission. To find spoofed packets, a test packet is sent to the source IP address of the
packet being checked, and the IPID number in the response is examined. The IPID value in the
response should be slightly greater than, but close to, the IPID value of the probe packet. If the
response packet's IPID is not close to the probe's IPID, it suggests that the source address is spoofed.
This technique is particularly effective even when the attacker and target are on the same subnet.
IP Spoofing Countermeasures
IP spoofing is a hacking technique where attackers impersonate trusted devices to infiltrate target
networks. To safeguard against such threats, robust countermeasures should be integrated into
network security protocols. Some key measures include:
Document
8. Other Measures:
● Strengthen website integrity and confidentiality by transitioning from IPv4 to IPv6 during the
development phase, leveraging IPv6’s advanced security features.
● Implement digital certificate authentication methods, including domain-based and two-way
certificate verification, to ensure secure communication and user/device authentication.
● Utilize a secure VPN when accessing public Internet services, such as free Wi-Fi and hotspots,
to safeguard data and prevent unauthorized interception.
● Deploy specialized mitigation devices, such as Behemoth scrubbers, for high-speed, deep-
packet inspection capable of analyzing up to 100 million packets per second to detect and block
malicious traffic effectively.
● Implement dynamic IPv6 address variation by using a random address generator to minimize
the duration of active vulnerabilities.
● Configure routers to encode information about fragmented packets entering the network for
enhanced monitoring and analysis.
● Enable routers to verify incoming data packets by comparing their signatures with stored
packet digests.
● Use Network Address Translation (NAT) modifications to conceal intranet hosts from the
external network, improving privacy and security.
● Configure internal switches to maintain DHCP static address tables, effectively filtering out
malicious spoofed traffic.
● Employ secure versions of communication protocols, such as HTTPS, SFTP, and SSH, which
provide encryption and authentication to protect data in transit.
Scanning Detection and Prevention Tools
Security professionals utilize advanced tools to detect network and port scanning attempts initiated
by attackers. These tools provide comprehensive visibility, real-time detection, and effective
prevention mechanisms to secure networks against malicious activities.
1. ExtraHop
ExtraHop offers complete visibility into network activities, enabling real-time detection and
intelligent responses to malicious scanning attempts. It can automatically discover and classify all
devices, including unmanaged IoT devices while identifying vulnerabilities. ExtraHop analyzes all
network interactions in real-time, including cloud transactions and encrypted SSL/TLS traffic, to
ensure comprehensive visibility. Its auto-discovery and device classification capabilities allow
security teams to monitor and evaluate all network communications effectively.
Document
There are many other tools available for detecting and preventing network scanning, which help
enhance network security by identifying scanning attempts and providing real-time responses.
These tools offer advanced analytics, threat detection, and automated prevention to safeguard
against malicious activities. Some notable tools include:
● Splunk Enterprise Security
● Scanlogd
● Vectra Detect
● IBM Security QRadar XDR
● Cynet 360 AutoXDR
Summary
Network scanning helps identify active hosts, open ports, and vulnerabilities using tools like Nmap
and Nessus.
Host discovery techniques, such as ICMP and ARP scanning, identify active devices, whereas port
and service discovery uncover potential vulnerabilities.
OS discovery techniques, such as banner grabbing, can help identify the operating system of devices
on the network.
Scanning beyond IDS and firewalls involves employing techniques such as decoy scans and IP
fragmentation to circumvent detection.
Countermeasures such as firewalls, IDS/IPS, ACLs, encryption, and network segmentation can
prevent unauthorized scans and protect against scanning attempts.
Document
Rate-limiting, NAT, and regular updates to network defenses enhance protection against malicious
scans.
MindMap
Practice Questions
2. What is the main difference between active and passive banner grabbing?
Document
5. What indication suggests that a port is not open during a UDP scan?
A. No reply from the target system.
B. SYN+ACK response from the port.
C. RST packet sent by the system.
D. ICMP Port Unreachable message.
7. Which of the following best describes the primary objective of the network scanning phase?
A. Exploit vulnerabilities on the system.
B. Find open ports and running services.
C. Patch vulnerabilities on devices.
D. Document the network topology.
12. Which type of scan involves sending ICMP ECHO requests to various IP addresses within a
subnet to detect active hosts?
A. ICMP Timestamp Ping Scan
B. ICMP Address Mask Ping Scan
C. ICMP ECHO Ping Sweep
D. TCP ACK Ping Scan
13. What does the Nmap command nmap –sX -v <ip address or range> perform?
A. Xmas Scan
B. Null Scan
C. FIN Scan
D. Stealth Scan
14. What happens when an Xmas Scan packet is sent to an open port on a modern system?
A. The port responds with a SYN-ACK packet.
B. The port sends an RST packet.
C. The request is ignored or dropped.
D. The port sends an ICMP echo reply.
15. Which scanning technique is most effective for stealthy port scanning?
A. UDP Scan
Document
16. Which scanning option in Zenmap is used to generate a list of hosts without scanning them?
A. -sL
B. -sU
C. -sS
D. –sY
17. What type of response does an open port provide during an SCTP COOKIE ECHO scan?
A. ABORT chunk
B. No response
C. SYN+ACK chunk
D. ICMP Unreachable error
19. What does a TTL value of 128 typically indicate during OS discovery?
A. Linux
B. macOS
C. Unix
D. Windows
21. Which method exploits the IP options field to bypass network security controls?
A. Source routing
B. SYN/FIN scanning
C. Fragmentation offset manipulation
D. Proxy chaining
Document
Answers
1. Answer: A
Explanation: OS discovery focuses on identifying the operating system and active services on a
target system. This information enables attackers to identify vulnerabilities specific to the detected
OS.
2. Answer: A
Explanation: Active banner grabbing sends crafted packets to the target system, eliciting
responses to identify OS or services. In contrast, passive banner grabbing relies on analyzing traffic
without engaging the target, making it harder to detect but potentially less informative.
3. Answer: B
Document
Explanation: SSDP enables the discovery of devices using Plug and Play capabilities without
requiring DHCP or DNS configurations. It simplifies network scanning by identifying devices
through multicast queries, especially in local environments with multiple networked devices.
4. Answer: A
Explanation: The SCTP COOKIE ECHO scan is unable to differentiate between open and filtered
ports reliably. This limitation occurs because both open and filtered ports often respond in a way
that appears similar, reducing the scan's effectiveness in detailed port analysis.
5. Answer: D
Explanation: In a UDP scan, closed ports typically send an ICMP Port Unreachable message.
Conversely, open ports usually remain silent, making it challenging to differentiate open ports from
those filtered by firewalls.
6. Answer: B
Explanation: Fingerprinting involves identifying the operating system and system architecture of
a target machine. Tools like Nmap perform this analysis by examining response patterns, such as
TTL values or TCP window sizes, to deduce the OS type and version.
7. Answer: B
Explanation: The network scanning phase identifies open ports and services to gather critical
reconnaissance information. This allows attackers to map potential attack vectors, paving the way
for targeted exploitation of discovered vulnerabilities.
8. Answer: B
Explanation: The FIN (Finish) flag is sent when a connection needs to terminate gracefully,
ensuring both sides agree on ending the session. This controlled closure minimizes disruption and
ensures data integrity.
9. Answer: C
Explanation: Nmap specializes in identifying open ports, network layout, and OS details but
cannot analyze hardware vulnerabilities. Such tasks require specialized tools like Nessus or
vulnerability scanners focused on hardware.
10. Answer: A
Explanation: UDP is termed "connectionless" because it does not establish connections or verify
data delivery. It lacks features like acknowledgment, retransmission, and error correction, making
it faster but less reliable than TCP.
Document
11. Answer: C
Explanation: Hping3's IP spoofing feature allows users to mask the source IP address of network
probes, making it more difficult for security systems to trace the origin of the scan. This technique
enhances anonymity during reconnaissance or attack activities.
12. Answer: C
Explanation: The ICMP ECHO Ping Sweep sends ICMP Echo requests (ping) to all IP addresses
in a subnet. Hosts that respond are considered live, providing valuable information about which
systems are active in a network.
13. Answer: A
Explanation: The -sX option in Nmap triggers an Xmas Scan, which sends TCP packets with the
FIN, URG, and PSH flags set. The scan’s name comes from the "Xmas tree" of flags, which can
confuse certain firewalls and intrusion detection systems.
14. Answer: C
Explanation: Modern systems typically ignore or drop Xmas Scan packets because the
combination of flags is invalid and not a standard request. As a result, the scan often goes
undetected or fails to elicit useful responses.
15. Answer: C
Explanation: The SCTP INIT Scan is a stealthy scanning method that only sends an INIT chunk
(connection request) and does not complete the handshake, making it less detectable by IDS or
firewalls.
16. Answer: A
Explanation: The—SL option in Zenmap performs a list scan that identifies hosts within a target
range but does not actively scan or probe them. This is useful for gathering a list of hosts without
triggering network alerts.
17. Answer: B
Explanation: In an SCTP COOKIE ECHO Scan, an open port generally does not respond,
dropping the packet without any reply. This lack of response helps attackers infer that the port
may be open or filtered.
18. Answer: A
Document
Explanation: The Time to Live (TTL) and TCP Window Size are key values used in OS discovery
because they are specific to the operating system’s networking behavior. By analyzing these, tools
like Nmap can determine the operating system running on the target system.
19. Answer: D
Explanation: A TTL value of 128 is most commonly associated with Windows operating systems.
This value is part of how Windows handles packet routing, and it's often used as a fingerprint for
OS detection.
20. Answer: B
Explanation: The Nmap Scripting Engine (NSE) uses pre-written scripts to automate tasks like OS
discovery. Scripts like smb-os-discovery help quickly identify the operating system and services
without manual intervention, improving scanning efficiency.
21. Answer: A
Explanation: Source routing involves manipulating the IP options field to specify a path that the
packet should take across the network. This technique allows packets to bypass intermediate
security devices, like firewalls, making it useful for stealth scanning.
22. Answer: B
Explanation: IP address spoofing enables an attacker to alter the source IP address in a packet
header, making the traffic seem as though it originates from a trusted device. This helps the
attacker remain anonymous and avoid detection by firewalls or IDS, as the true origin of the attack
is hidden.
23. Answer: B
Explanation: Proxy chaining is a technique where an attacker routes their internet traffic through
multiple proxies (intermediate servers). This makes it much more difficult for anyone monitoring
the traffic to trace it back to the source, as each proxy hides the true origin of the request, thus
adding an additional layer of anonymity.
24. Answer: D
Explanation: Anonymizers, such as Tor or VPNs, help mask a user's real IP address and location
by routing traffic through intermediate servers or networks. This allows the user to remain
anonymous online and bypass geographic or network-based restrictions, such as access to blocked
content or websites.
25. Answer: B
Document
Explanation: Packet fragmentation involves breaking a large packet into smaller pieces to evade
detection by IDS or firewalls. These security devices typically scan packets for malicious content,
but fragmented packets may not be fully reassembled, allowing malicious payloads to slip through
undetected. This method is often used in network attacks to avoid security measures.