Pentest Nmap
Pentest Nmap
Identify Misconfigurations:
Improper configurations, such as unnecessary open ports or outdated services, can be identified
during scanning and can lead to vulnerabilities that can be exploited.
Prioritize Exploits:
Scanning helps identify which vulnerabilities are present in the target system, allowing testers to
prioritize which ones to exploit based on risk or ease of exploitation.
1. Active Scanning
Active scanning involves directly interacting with the target system by sending probes or requests to
it. These interactions generate network traffic that can be detected by security mechanisms such as
firewalls, intrusion detection systems (IDS), or intrusion prevention systems (IPS). The goal of active
scanning is to gather detailed information about the target, such as open ports, services, versions,
and other vulnerabilities.
2. Passive Scanning
Passive scanning involves gathering information about the target without directly interacting with it.
Instead of sending requests or probes to the target, passive scanning relies on listening to and
observing traffic that is already present on the network. This could include monitoring DNS queries,
network traffic, or other publicly available data sources. Passive scanning is stealthier than active
scanning because it doesn't generate network traffic that can be detected by the target.
3/121
Limited Scope:
Passive scanning provides less detailed information because it relies on external observations rather
than directly probing the target.
Requires Access to Network Traffic:
Passive scanning often requires access to the target's network traffic or external data sources, such
as public-facing websites or DNS records, which may limit its effectiveness in some scenarios.
May Not Detect All Vulnerabilities:
Passive scanning cannot actively detect certain types of vulnerabilities (e.g., open ports or
misconfigurations that would be identified through active probing).
4/121
TARGET SPECIFICATION
1. SCAN SINGLE IP:
nmap <ip>
5/121
3. SCAN A NETWORK RANGE:
nmap 192.168.10.20-30
6/121
4. SCAN A DOMAIN:
nmap <domain>
nmap scanme.nmap.org
9/121
DONT BE CONFUSED WHAT IS msf ,i have added my target
machine ip in /etc/hosts as host.
11/121
15. PORT SCAN THE TOP X PORTS:
nmap <ip> --top-ports 2000
12/121
16. LEAVING OFF INITIAL PORT IN RANGE MAKES
THE SCAN START AT PORT 1:
nmap <ip> -p- 65535
13/121
14/121
15/121
16/121
TIMING TECHNIQUES
1. PARANOID IDS EVASION:
Attackers can adjust the timing of their attack packets (delaying or spreading out the attack over
time) to avoid triggering the IDS. By sending low-volume or spaced-out malicious packets, they may
avoid detection in a system that looks for high-volume, burst-like activities.
nmap -T0 <ip>
17/121
within the specified time frame, it will stop scanning that host and move on to the next one. This is
useful for speeding up scans when targeting hosts that may be slow or unresponsive.
nmap -- --host-timeout <time> <ip>
nmap --host-timeout 30s <target-ip>
EXAMPLE INPUT: 1s, 4m , 2h
18/121
Here’s a breakdown of each option:
1. --min-rtt-timeout <time>
Description: This option sets the minimum amount of time Nmap will wait for a response from the
target. If the round-trip time (RTT) to the target is shorter than this value, Nmap will still wait for at
least this duration.
Usage: Useful to prevent Nmap from assuming the network is faster than it is, or to avoid triggering
rate limits on remote systems.
Example: --min-rtt-timeout 100ms means Nmap will wait at least 100 milliseconds for each
response.
2. --max-rtt-timeout <time>
Description: This option sets the maximum amount of time Nmap will wait for a response. If the RTT
is greater than this value, Nmap will still wait no longer than the specified timeout.
Usage: Useful to limit how long Nmap will wait for a response, preventing extremely long delays if a
host is very slow or unresponsive.
Example: --max-rtt-timeout 1s means Nmap will wait no longer than 1 second for a response from
the target.
3. --initial-rtt-timeout <time>
Description: This option sets the initial RTT timeout value, which is used to estimate the RTT at the
start of the scan. Nmap uses this value to start the scan and adjusts dynamically based on network
conditions as the scan progresses.
Usage: Useful for fine-tuning how aggressive the scan will be at the beginning, particularly if you
know the network is unusually slow or fast.
Example: --initial-rtt-timeout 200ms sets the starting timeout to 200 milliseconds.
--min-hostgroup <size>: This option sets the minimum number of hosts to scan in
parallel. If the scan involves multiple hosts, Nmap will attempt to scan at least this
many hosts simultaneously. If the number of hosts to be scanned is smaller than the
specified value, Nmap will use that number of hosts for the scan.
--max-hostgroup <size>: This option sets the maximum number of hosts to scan
in parallel. If you're scanning a large number of hosts, this option controls how many
hosts Nmap will scan at once. A higher number can speed up the scan but may also
increase network load or detection risk.
20/121
10. PROBE PARELLELIZATION:
nmap --min-parellelism/--max-parellelism <numprobe> <ip>
nmap --min-parallelism 10 --max-parallelism 50 <target-ip>
EXAMPLE INPUT: 10; 1
1. --scan-delay <time>
Description: This option introduces a delay between sending probes to the same host. It is useful for
slowing down your scan to make it less likely to trigger Intrusion Detection Systems (IDS) or firewalls
21/121
that might flag rapid scanning.
Usage: You can specify a fixed delay between every probe sent, helping reduce the overall speed of
the scan. This can be useful for stealthier scans, especially on sensitive or well-secured networks.
Example: --scan-delay 1s would set a 1-second delay between probes sent to the same host.
2. --max-scan-delay <time>
Description: This option sets the maximum amount of time Nmap will
wait between probes. If you are using timing templates or have Nmap
adjust delays dynamically based on network conditions, this option
ensures that the maximum delay doesn’t exceed the set limit.
Usage: This is useful if you are trying to control the maximum delay during a scan that is being
adjusted dynamically. You can control how long Nmap waits between probes sent to the target.
Example: --max-scan-delay 2s would ensure that Nmap never waits more than 2 seconds between
probes during the scan.
--scan-delay 500ms: Nmap will wait 500 milliseconds between sending probes to the same host. This
will slow down the scan, reducing the risk of detection or overwhelming the target.
--max-scan-delay 2s: If Nmap dynamically adjusts the delay during the scan (based on network
conditions), the maximum delay will be limited to 2 seconds.
--max-retries <tries>: This option sets the maximum number of retries Nmap will attempt for each
probe if no response is received. If the target does not respond to a probe, Nmap will resend the
probe up to <tries> times before giving up on that particular probe.
<tries>: The <tries> argument specifies how many times Nmap will retry a probe if it doesn't
receive a response. The default value is typically 10 retries, but you can lower or increase it
depending on your needs.
22/121
13. SEND PACKETS NO SLOWER THAN <NUMBER>
PER SECOND:
In Nmap, the --min-rate <number> option allows you to set the minimum rate at which packets (or
probes) are sent during a scan. This option is useful for controlling the scan speed, especially in
cases where you want to ensure a minimum rate of scan activity. By adjusting the rate, you can fine-
tune how aggressively Nmap scans the target.
nmap --min-rate <number> <ip>
nmap --min-rate 1000 <target-ip>
EXAMPLE INPUT: 100
23/121
14. SEND PACKETS NO FASTER THAN <NUMBER>
PER SECOND:
In Nmap, the --max-rate <number> option is used to control the maximum rate at which packets (or
probes) are sent during a scan. This option is useful for limiting the scan speed, which can help
reduce the likelihood of detection, prevent overwhelming the target network, or avoid triggering
security alarms.
24/121
25/121
HOST DISCOVERY
HOST DISCOVERY TECHNIQUES:
netdiscover
arp-scan -l
arp-scan <ip>/cidr
26/121
What Happens During a Ping Scan (-sn):
Nmap will send ICMP echo requests (ping) to check if the host is alive.
It may also use ARP requests (for local networks) or other probes to identify live
systems.
It does not scan any open ports on the target hosts; it simply checks their availability.
ARP PING
UDP PING
ICMP PING
TCP PING -----. SYN PING TCP && ACK PING TCP
IP PROTOCOL PING
ADVANTAGE: MORE EFFICIENT AND ACCURATE THAN OTHER HOST DISCOVERY TECHNIQUES.
USEFUL FOR SYSTEM DISCOVERY WHERE OTHER ONE MAY NEED TO SCAN LARGE ADDRESS SPACE.
28/121
ADVANTAGE: USEFUL FOR LOCATING ACTIVE DEVICES:
29/121
nmap -sn -PS <ip>
The command nmap -sn -PI <ip> is used to perform a "ping scan"
(-sn) with the ICMP Echo Request (-PI) to determine whether a host is
alive on a network. Let’s break it down:
-sn: This option tells Nmap to perform a ping scan. It will only discover whether the
30/121
target hosts are up (alive) without performing any port scanning. Essentially, Nmap will
skip the port scan phase and just check if the host is responding to certain types of
probes (such as pings).
-PI: This option specifies the use of ICMP Echo Request (ping) as the method for
discovering live hosts. It sends an ICMP Echo Request to the target, and if the host
responds with an ICMP Echo Reply, Nmap will consider the host to be "up."
<ip>: This is the target IP address (or range) that you want to check.
32/121
IPv6 Neighbor Discovery Scan with nmap: You can use nmap to perform an IPv6 Neighbor Discovery
(ND) scan with the -6 option to specify an IPv6 scan and the -sn option for a "ping scan," which
discovers hosts in the network.
Neighbor Spoofing:
Just like ARP poisoning in IPv4, attackers can exploit ND to perform man-in-the-middle (MITM) attacks
or Denial of Service (DoS) attacks by sending spoofed Neighbor Advertisements. This could mislead
devices to send traffic to an attacker rather than the intended destination.
ND Flooding:
An attacker could flood the network with Neighbor Solicitation and Neighbor Advertisement
messages to overload devices or disrupt communication.
Secure ND:
It's important to protect ND in IPv6 networks by using features like Secure Neighbor Discovery
(SEND), which uses cryptographic certificates to prevent spoofing and malicious activity.
Conclusion:
IPv6 Neighbor Discovery (ND) is a critical protocol for local network communication in IPv6. It
performs functions like neighbor identification, address autoconfiguration, and router discovery.
Tools like nmap can be used for ND-based discovery scans in IPv6 networks, making it easier to
identify active devices. However, like other network discovery protocols, ND can be vulnerable to
various types of attacks if not secured properly.
33/121
18. USE FRAGMENTATION SCANNING AND EXAMINE
THE RESPONSE:
This option tells nmap to fragment the packets it sends. When the fragmentation option (-f) is
enabled:
The scan packets are broken into smaller fragments, which are then sent separately. This can be
useful to evade detection by firewalls and intrusion detection systems (IDS/IPS) that might not
reassemble fragmented packets, or it can confuse systems that rely on inspecting the full packet.
Note: Some networks and firewalls may block fragmented packets or reassemble them
and inspect them for suspicious activity. Fragment the packets to make the scan less
detectable by firewalls or intrusion detection systems.
34/121
19. NO SCAN LIST TARGETS ONLY:
#nmap -sL <ip>
35/121
-n: This option tells Nmap to skip DNS resolution. Normally, Nmap resolves IP addresses to domain
names (if possible), but with -n, it won't perform that lookup. This can speed up the scan if DNS
resolution is unnecessary.
nmap -R <IP>
36/121
What Happens When You Use -R?
Reverse DNS Lookup: For each IP address that Nmap scans, it will attempt to find the associated
domain name (if available) by performing a reverse DNS lookup.
Hostname Discovery: If a valid reverse DNS record exists for an IP, Nmap will display the
corresponding hostname alongside the IP address in its output.
Useful for Identification: This can help identify hosts by their domain names, especially if the target
IP belongs to an organization with associated reverse DNS records.
37/121
However, there may be cases where you want to rely on the DNS resolver that is configured on the
operating system (e.g., /etc/resolv.conf on Linux or system DNS settings on Windows) instead.
In this example, Nmap will query Google's DNS servers for resolving example.com to an IP address,
rather than using the default DNS servers configured on your system.
==============================================================
==============================================================
==============================================================
==============================================================
==============================================================
==============================================================
==================================
==============================================================
==============================================================
==============================================================
==============================================================
==============================================================
==============================================================
==================================
40/121
hosts by sending various types of packets (e.g., TCP, UDP,
ICMP) to a target.
Here are the key hping3 commands used for host discovery:
_____________________________________________________________________________________________
_____________________________________________________________________________________________
__________
1. ICMP Echo Request (Ping)
This method sends an ICMP Echo Request to a target to check if it responds with an ICMP Echo Reply,
indicating that the host is alive (similar to a regular "ping").
hping3 -1 <target_ip>
-1: This option tells hping3 to use ICMP (i.e., send an ICMP Echo Request).
<target_ip>: The IP address of the host you want to check.
Example:
hping3 -1 192.168.1.1
This will send an ICMP Echo Request to 192.168.1.1 and display the response if the host is alive.
_____________________________________________________________________________________________
_____________________________________________________________________________________________
__________
41/121
-S: This option sends a SYN packet (part of the TCP handshake).
-p <port>: Specify the target port to which the SYN packet will be sent.
<target_ip>: The IP address of the target.
Example:
hping3 -S -p 80 192.168.1.1
This will send a SYN packet to port 80 on 192.168.1.1. If the host is alive and the port is open, the host
will reply with a SYN-ACK packet.
==============================================================
===========================================================
hping3 -A -p 80 192.168.1.1
42/121
This will send a TCP ACK packet to port 80 of 192.168.1.1 and waits for an RST response, indicating
that the host is alive.
==============================================================
===========================================================
hping3 -F -p 80 192.168.1.1
This sends a TCP FIN packet to port 80 on 192.168.1.1. If the host is alive, it may send an RST reply
for closed ports.
==============================================================
===========================================================
5. UDP Ping
This sends a UDP packet to a target port. If the port is open and the host responds with a UDP reply, it
indicates the host is alive.
Example:
hping3 -2 -p 53 192.168.1.1
This sends a UDP packet to port 53 (DNS) on 192.168.1.1 and waits for a UDP reply to determine if the
host is alive.
43/121
==============================================================
===========================================================
Example:
==============================================================
===========================================================
This option sends packets as fast as possible, effectively flooding the target.
-S: Send a TCP SYN packet.
-p <port>: Specify the port to send packets to.
<target_ip>: The target IP.
Example:
==============================================================
===========================================================
44/121
hping3 --traceroute -p 80 192.168.1.1
This will perform a traceroute to 192.168.1.1 on port 80.
==============================================================
===========================================================
45/121
PORT SCANNING
THE PORT SCANNING TECHNIQUES ARE
CATEGORIZED ACCORDING TO THE TYPE OF THE
PROTOCOL USED FOR COMMUNICATION.
1. TCP SCANNING --→ OPEN TCP SCANNING METHOD, STEALTH
TCP SCANNING METHOD, THIRD PARTY AND SPOOFED TCP
SCANNING METHOD
2. UDP SCANNING
3. SCTP SCANNING -----→ SCTP INIT SCANNING, SCTP COOKIE
ECHO SCANNING
4. SSDP SCANNING
5. IPV6 SCANNING
46/121
Closed Ports: If a "destination unreachable" message is returned from the target, the
port is considered closed.
Filtered Ports: If no response is received, the port is marked as "filtered," meaning a
firewall or other security device may be blocking the traffic.
Root privileges are not required for a TCP Connect scan since the scan uses the
operating system's normal networking functions to establish connections.
47/121
Detection by firewalls and IDS: Since this scan completes the full TCP handshake, it
can be easily detected by firewalls or intrusion detection systems (IDS) as it
generates more noticeable traffic compared to stealthier scans like SYN scans (-sS).
This scan is often used when no other scanning methods are available, or when a
user does not have root/administrator privileges.
48/121
TCP SYN Scan is one of the most commonly used scanning techniques because it is fast and stealthy
compared to other methods like the TCP Connect scan (-sT).
It works by sending a SYN packet (the initial packet in the TCP handshake) to the target ports.
Depending on the response, Nmap determines the state of the port:
Open port: If the port is open, the target will respond with a SYN-ACK packet, indicating
the port is open.
Closed port: If the port is closed, the target will respond with a RST (reset) packet.
Filtered port: If the port is protected by a firewall or if the response is not received, the
port is considered filtered.
Why "stealth"?:
Unlike the TCP Connect scan (-sT), which completes the full three-way handshake, a SYN scan only
sends the initial SYN packet and waits for a response. This minimizes the chance of detection
because the connection is never fully established.
Advantages:
Faster than the TCP Connect scan because it doesn't complete the handshake.
Less likely to be detected by intrusion detection systems (IDS) and firewalls since it doesn't complete
the connection.
Useful for evading detection in networks with strict monitoring.
Limitations:
Requires root/administrator privileges because raw packets are sent, which is not allowed for normal
user accounts.
Can still be detected by more advanced firewalls and intrusion detection systems that monitor for
incomplete or unusual traffic patterns.
When running nmap -sS -vv, the output might look like this:
Key Considerations:
Root Privileges: Since SYN scanning requires raw socket access to send SYN
packets, you may need to run this command as root (or with sudo on Unix-based
systems).
Firewall and IDS/IPS Detection: Although SYN scanning is less likely to be
detected than full connection scans, firewalls and intrusion detection systems (IDS/
IPS) may still detect this type of scan, especially if the target is specifically
49/121
configured to log unusual connection attempts.
50/121
SCTP INIT Scan is a type of scan used to detect open ports on a target system that
uses the SCTP (Stream Control Transmission Protocol).
SCTP is a transport-layer protocol, similar to TCP and UDP, but it is primarily used for
51/121
telecommunication systems and signaling protocols. While SCTP is not as widely
used as TCP or UDP, it may still be employed in some specialized networks.
Key Considerations:
Root Privileges:
Like other advanced Nmap scan types, the SCTP INIT scan may require root or administrator
privileges because it involves sending raw packets, which is restricted for normal user accounts.
On Unix-like systems (Linux/macOS), use sudo to run the command if necessary:
SCTP Availability:
This scan is only useful if the target system is running applications or services that use SCTP. If SCTP
is not supported or in use, the scan will not return meaningful results.
Detection by Firewalls/IDS:
Although SCTP INIT scan is generally stealthier than a full connection scan (like TCP Connect scans),
advanced firewalls or intrusion detection systems (IDS) might still recognize and log these types of
scans based on traffic patterns.
52/121
-sN (TCP Xmas Scan):
The TCP Xmas scan works by sending a TCP packet with the FIN, URG, and PSH flags set, which is
known as a "Christmas tree" packet because all the flags are turned on (hence the name).
This scan can be used to detect open ports by observing the response behavior:
If the port is open, there will be no response from the target.
If the port is closed, the target will send a RST packet.
The Xmas scan is also considered a stealthy scan, but it can be easily detected if the target system is
well-configured.
Root privileges are generally required to send raw packets, so on Linux or macOS, you might need to
prepend sudo:
7.XMASS SCAN:
nmap -sX -vv <ip>
53/121
Breakdown of the Command:
-sX (TCP Xmas Scan):
The TCP Xmas Scan gets its name because it sets all the TCP flags that are usually
used in the protocol. Specifically, it sends a TCP packet with the FIN, URG, and PSH
flags set.
These flags are typically used in normal communication but are not usually set all at
54/121
once. The combination of these flags makes the packet look unusual, like a
"Christmas tree" with all the lights on (hence the name).
How it works:
When this type of packet is sent to a port:
If the port is open: The target system usually does not respond (since it's not
expecting a FIN/URG/PSH combination).
If the port is closed: The target will typically respond with a RST (reset) packet to
indicate that the connection is not available.
If the port is filtered: The response may be dropped by firewalls or intrusion
prevention systems, making the port appear to be "filtered" (no response).
Considerations:
Root Privileges: Like other advanced Nmap scans, the Xmas scan may require root or administrative
privileges because it sends raw packets. You might need to run the command as sudo on Linux/
macOS:
Detection:
While the Xmas scan can be stealthier than traditional scans (like TCP connect scans), it is still
detectable by advanced firewalls, intrusion detection systems (IDS), or intrusion prevention systems
(IPS) that are specifically configured to look for unusual traffic patterns or malformed TCP flags.
Compatibility:
The Xmas scan might not work well on all systems. Some systems, especially modern ones, are
configured to discard such unusual packets, making the scan ineffective or causing false negatives
(the scan may report ports as filtered even if they are open).
Limitations:
The Xmas scan is not as commonly used or as effective on modern networks as it once was because
many systems are now designed to detect or block these types of scans.
If a firewall or IDS/IPS detects this traffic, the scan could be blocked, and the results may not be
accurate.
8. FIN SCAN:
nmap -sF -vv <ip>
55/121
The TCP FIN scan works by sending a TCP packet with the FIN (Finish) flag set to the target port. The
FIN flag is usually used to indicate that the sender has finished sending data and wants to terminate
the connection.
However, in the case of a scan, this flag is sent without initiating a proper TCP handshake, which can
help the scan evade detection by certain firewalls or intrusion detection systems (IDS) that might not
expect this kind of packet.
How it works:
If the port is open: The target system will ignore the FIN packet (since it's not expecting to close a
connection) and will not send any response.
If the port is closed: The target will typically respond with a RST (reset) packet, indicating that the
port is closed.
If the port is filtered: If there is a firewall or other filtering device between you and the target, you
may not receive any response, or the response could be an ICMP unreachable message.
This behavior makes the FIN scan a stealthy scan. It's not as obvious as a SYN scan or a TCP Connect
scan, which follow the normal TCP handshake process and are easier to detect.
56/121
Considerations:
Root Privileges:
As with many Nmap scans, the FIN scan may require root or administrative privileges because it
involves sending raw packets. On Linux or macOS, you might need to use sudo:
Detection:
While the FIN scan is considered stealthier than other types of scans (like a SYN scan), it can still be
detected by advanced firewalls, intrusion detection/prevention systems (IDS/IPS), or even modern
operating systems.Some systems are configured to ignore unexpected FIN packets, or they may
block or log the attempt.
9. NULL SCAN:
nmap -sN -vv <ip>
57/121
In Nmap, a Null Scan is a type of scan that sends a TCP packet with no flags set in the TCP header.
This scan is primarily used to evade detection because it doesn't follow the usual TCP protocol rules
for initiating or terminating connections. The Null Scan can help identify open ports by exploiting the
behavior of certain systems or firewalls.
Response Behavior:
The response to the Null Scan depends on the state of the target port:
If the port is open: The target system will ignore the packet. It won't respond to it because the packet
is not part of a legitimate connection request.
If the port is closed: The target system will usually send a RST (Reset) packet to indicate that the
connection is not available.
If the port is filtered: If there is a firewall or packet filter in between, the target may not respond or
58/121
could send an ICMP unreachable response.
Stealth:
The Null Scan is considered a stealthy scan because it doesn't initiate a full TCP handshake (no SYN/
ACK exchange), making it harder to detect by intrusion detection/prevention systems (IDS/IPS) that
are looking for more standard connection attempts.
It can bypass certain firewalls or packet filters that only look for normal connection requests but not
for unusual traffic like Null Scan packets.
Nmap Command for a Null Scan:
The Null Scan can be performed in Nmap with the -sN option:
This option tells nmap to use the TCP Maimon scan. This scan type is a rare and
somewhat obscure scanning technique that attempts to exploit a quirk in the TCP
protocol stack. It's designed to send packets that are FIN-PSH (FIN + PUSH
flags) to the target. The goal is to elicit a response from the target without fully
establishing a connection. It's considered stealthy because it doesn’t complete the
handshake, but not all firewalls or intrusion detection systems are bypassed by it.
Important Considerations:
Stealth: The -sM scan can be somewhat stealthy because it doesn't complete the TCP handshake, but
it may still be detectable by advanced intrusion detection/prevention systems (IDPS).
59/121
Legality: Always make sure you have permission to scan a target. Unauthorized scanning of
networks and systems can be illegal.
This option tells nmap to perform a TCP ACK scan. The purpose of this scan is to map out firewall
rules and determine whether a target is protected by a firewall or filtering device.
Important Considerations:
Firewalls and IDS/IPS: Modern firewalls and Intrusion Detection Systems (IDS) or Intrusion Prevention
Systems (IPS) might still detect and log these types of scans, though they are generally stealthier
60/121
than others.
Legal and Ethical: Always ensure that you have authorization to scan the network or system you're
targeting. Unauthorized scanning may violate laws and regulations.
The command nmap -sA ttl 100 -vv <ip> combines a TCP ACK scan, with specific settings for TTL
(Time to Live), and increases verbosity. Let's break down each part of the command:
Components:
nmap: The tool for network discovery and security auditing, used to scan and identify hosts,
services, and vulnerabilities.
-sA: This specifies a TCP ACK scan. The ACK scan is used to map out firewall rules or determine if a
host is behind a firewall or filtering device. It works by sending TCP packets with the ACK flag set, and
the responses from the target can reveal whether ports are filtered or not.
61/121
instructing nmap to send packets with a TTL of 100.
<ip>: This is the target IP address that you are scanning. Replace <ip> with the actual IP address or
domain of the system you want to scan.
Example Command:
Use Cases:
Firewall and Filtering Detection: This scan is typically used to determine whether a firewall is in place
and which ports are filtered, without attempting to connect to services on those ports.
Manipulating Scan Characteristics: The TTL setting can be useful in cases where you want to modify
how the scan behaves in terms of routing or how intermediate devices like routers interpret the
packets.
Important Considerations:
Firewalls and IDS/IPS:
Although the ACK scan is relatively stealthy, modern firewalls or Intrusion Detection/Prevention
Systems (IDS/IPS) may still detect unusual TTL values, even if the scan itself is not immediately
visible.
Legality:
Always ensure that you have permission to scan the target system. Unauthorized scanning can be
illegal and may violate the Computer Fraud and Abuse Act (CFAA) or similar laws depending on your
location.
62/121
Components of the Command:
nmap: The command-line tool used for network discovery and security auditing. It helps to scan
hosts, services, and vulnerabilities on a network.
<ip>: This is the target IP address you are scanning. Replace <ip> with the actual IP address (or
domain name) of the system you want to scan.
Example Command:
Use Cases:
Firewall and Filtering Device Detection: This combined scan can help you understand firewall
behavior and deduce whether ports are open, closed, or filtered.
OS Fingerprinting: The TCP Window scan can sometimes provide information about the operating
system of the target based on how it handles window sizes.
Port Scanning in Complex Environments: The use of both ACK and Window scans helps when there
are firewalls or other filtering devices in place, as these scans do not rely on completing the full TCP
handshake.
63/121
Example Output (with -vv verbosity):
You might see output like the following, showing detailed information for each port scanned:
...
Key Points:
-sA (TCP ACK Scan): Helps to determine if a firewall is in place and whether certain ports are filtered.
-sW (TCP Window Scan): Attempts to identify open or closed ports by inspecting the TCP window size
in responses.
Verbose Output (-vv): Provides detailed information about the scan’s progress and results.
Considerations:
Firewalls and IDS/IPS: Modern firewalls and Intrusion Detection/Prevention Systems (IDS/IPS) can
sometimes detect these types of scans, especially when combined with verbose output.
Accuracy: The Window scan (-sW) may not always be as reliable as a traditional SYN scan,
particularly if the target is behind an advanced firewall or filtering system.
Legality: Always make sure you have permission to scan the target system. Unauthorized scanning
may be illegal and subject to penalties under various cybersecurity laws.
-Pn: This option disables host discovery. By default, nmap attempts to determine
whether a target is up (alive) before scanning it by sending a variety of probes (like ICMP
echo requests, or SYN packets). When you use -Pn, nmap skips this host discovery
phase and assumes that the target is up. This is useful when scanning hosts that may
block ICMP or other discovery probes (for example, firewalled hosts).
-p-: This option tells nmap to scan all 65,535 TCP ports. By default, nmap scans the
most common 1,000 ports, but with -p-, it will scan every port from 1 to 65535.
-sI <ZOMBIE HOSTNAME>: This is the key option in your command. It specifies an Idle
scan using a zombie host:
The -sI option activates Idle scan, which is a type of stealth scan that allows the attacker
to scan a target without directly interacting with it. Instead, it sends packets through a
third-party machine, which acts as the zombie.
The zombie host (in this case <ZOMBIE HOSTNAME>) is used to send the probes to the
64/121
target system. The target system will respond to the zombie host, not to the actual
scanning machine. This can allow the attacker to perform the scan without revealing
their own IP address.
The Zombie Host must be chosen carefully. It needs to be a machine that can send
packets to the target and respond to requests without being suspicious (i.e., it must not
have any obvious connection to the attacker).
Idle scan is based on manipulating the IP ID field of the IP header, so it only works under
certain conditions (e.g., the target system and zombie host must behave in a predictable
manner).
<TARGET HOSTNAME>: This is the target you want to scan. Replace <TARGET
HOSTNAME> with the actual IP address or hostname of the system you wish to scan.
Example Command:
Scan all 65,535 ports on 192.168.1.1 using the Idle scan technique.
The attacker sends packets to the target host, but the actual packets are relayed through a zombie
host (i.e., a third party).
The target responds to the zombie, not the attacker.
By analyzing the responses from the target (through the zombie), the attacker can infer whether the
target port is open or closed by observing the IP ID field in the responses.
Use Case:
Stealth Port Scanning: This scan is typically used by attackers who want to perform a stealth scan of
a target without directly communicating with it. It's useful when the attacker wants to avoid detection
or log tracing. Network Reconnaissance: If an attacker knows of a vulnerable zombie host and wants
to probe a target’s open ports without revealing their own IP address, they would use this technique.
Limitations:
Zombie Host Requirements: The zombie host must have an open port that is not being filtered or
blocked. Additionally, the target host and zombie must behave predictably, especially in terms of IP
ID increments. This makes finding a suitable zombie host difficult.
65/121
Nmap scan report for 192.168.1.1
Host is up (0.0034s latency).
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
...
Important Considerations:
Legal and Ethical: Unauthorized scanning of networks is illegal in many countries. Always ensure you
have permission to scan a system.
Detection: Although the scan tries to mask the attacker's IP, skilled network administrators may still
be able to detect unusual traffic patterns indicative of a zombie scan.
In nmap, you can scan for devices or services that are using SSDP by performing a specialized scan.
SSDP typically runs over UDP port 1900 and can be discovered with specific nmap flags.
66/121
nmap -p U:1900 --open <target_ip_or_network>
Where:
-p U:1900: This specifies scanning for UDP port 1900, which is the port
used by SSDP.
U: specifies that the port should be scanned for UDP (instead of the
default TCP).
--open: This option ensures that nmap only reports open ports, which
helps filter out unnecessary results.
<target_ip_or_network>: Replace this with the IP address or range of IPs
you want to scan. For example, 192.168.1.0/24 to scan all devices on your
local network.
Example:
If you want to scan for SSDP devices on a local network (192.168.1.0/24), the command would look
like this:
Example Output:
If devices are found, the output might look like this:
67/121
1900/udp open upnp
...
This would indicate that devices at 192.168.1.10 and 192.168.1.15 are running SSDP
services (UPnP services), which are commonly associated with printers,
cameras, routers, and other IoT devices.
Additional Considerations:
UDP vs. TCP: SSDP operates over UDP and not TCP. Therefore, always specify UDP port 1900 (U:1900)
to ensure you're scanning the right protocol.
Service Discovery:
While nmap can identify devices that are advertising SSDP services, the actual service details (e.g.,
device information or capabilities) are typically retrieved via a different process, such as by sending
SSDP queries to the device using tools like curl or specialized SSDP clients.
Security Implications:
SSDP can expose sensitive information about devices on your network. It has been a target for
certain types of attacks, like DDoS amplification attacks, where SSDP is misused to amplify malicious
traffic. Therefore, it's important to ensure that unnecessary devices using SSDP are properly
secured.
Summary:
To scan for SSDP services, use the -p U:1900 option in nmap.
You can use the --open flag to only report open services, and specify the target IP range.
SSDP is commonly used for device discovery in UPnP environments, but it can be a security concern
if left unprotected.
68/121
nmap -6 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Aggressive Scan:
An aggressive scan performs multiple tests, including OS
detection, version detection, script scanning, and
traceroute:
nmap -6 -A 2001:0db8:85a3:0000:0000:8a2e:0370:7334
70/121
SERVICE DISCOVERY
Service discovery in nmap refers to the process of identifying
which services are running on a target system, which ports
those services are running on, and sometimes identifying the
version and details of those services. This is essential for
security assessments, as it helps to understand which
services are exposed on the network, and potentially identify
vulnerabilities related to those services.
nmap provides several options to discover and identify services running on a target. These options
can be combined in various ways to enhance the accuracy and depth of the discovery process.
Example:
nmap -sV <target_ip>
Where:
-sV: This option enables service version detection. It causes nmap to query open ports
to determine the software and version of the service running on each port.
What the command does:
Scans the target IP for open ports.
Probes the open ports to identify the services and their versions (e.g., Apache, OpenSSH,
71/121
FTP).
Example Output:
Example:
nmap -A <target_ip>
Where:
OS details: Linux 3.10 - 4.11, Linux 4.12 - 4.19, Linux 5.0 - 5.6
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
72/121
Example:
nmap --script=http-title -p 80 <target_ip>
This will use the http-title script to retrieve the title of a website running on port 80 (if the service is
an HTTP server).
Running Multiple Scripts:
You can also run multiple scripts with the -sC option, which activates a set of default scripts for
various services.
Example:
nmap -sC -p 80,443,8080 <target_ip>
Where:
-sC: Runs the default scripts included with nmap, which covers a wide range of service
discovery and security checks.
-p 80,443,8080: Limits the scan to the specified ports.
Example:
nmap -Pn -sV 192.168.1.0/24
Where:
73/121
-Pn: Skips the host discovery phase and assumes that all hosts in the range are up.
-sV: Performs service version detection.
This can be useful when scanning multiple hosts, especially if you're sure the hosts are
live, or when you're dealing with firewalled hosts that block ping probes.
Example:
Where:
Practical Example:
If you want to do a full service discovery on all hosts in your local network and identify versions and
operating systems, you could run:
nmap -A -p 1-65535 192.168.1.0/24
This will Scan all 65,535 TCP ports on each host in the 192.168.1.0/24 network. Use the Aggressive
Scan (-A) to detect services, versions, operating systems, and run default scripts.
Conclusion:
Service discovery with nmap is a powerful tool for understanding the services running on a network
and assessing the security of those services. By using options like -sV, -A, and the nmap scripting
engine, you can gather detailed information about services and their potential vulnerabilities.
Always ensure that you have permission to scan the network or system in question.
75/121
OS DISCOVERY
OS Fingerprinting and Discovery in Nmap
Nmap (Network Mapper) is a powerful open-source tool for network
discovery and security auditing. One of its key features is OS
fingerprinting, which helps determine the operating system (OS) of a
target host based on network responses to a variety of probes.
1. OS Fingerprinting in Nmap
OS fingerprinting in Nmap works by sending various probes to the target machine and analyzing the
responses. By examining these responses, Nmap compares them to a database of known OS
signatures to estimate which operating system is running on the target.
nmap -O <target>
76/121
This command attempts to detect the operating system of the target IP.
4. Advanced OS Detection
You can combine OS detection with other Nmap options to refine the results or perform additional
tests:
Enable aggressive scan (-A): This runs OS detection along with version detection, script scanning,
and traceroute, providing a more comprehensive discovery.
nmap -A <target>
77/121
78/121
Increase verbosity (-v): Use this to see more details about the scan process.
nmap -v -O <target>
Use the -sS option: To perform a SYN scan (stealth scan), which is typically quicker than a full TCP
connect scan.
5. OS Detection Results
If Nmap successfully detects the OS, the output might look something like this:
If Nmap cannot conclusively determine the OS, it will provide a guessed OS with an associated
confidence level, e.g.,:
OS guesses:
Linux 3.x or 4.x (96%)
Linux 2.6.32 - 3.x (85%)
79/121
Vulnerabilities specific to the operating system.
Network behavior and potential attack surface.
Service versions and configuration weaknesses.
7. Limitations of OS Detection
Accuracy: OS fingerprinting is not always 100% accurate, especially if firewalls, intrusion detection
systems (IDS), or other filtering devices block or alter network packets.
Detection Evasion: Some OSs can be configured to respond in ways that obscure their real identity,
making it harder for Nmap to determine the exact OS.
HERE:
-i ---------→ IS INTERFACE
-p ----------→ ITPUT THE LISTENING INTERFACE IN PROMISCUOUS MODE.
-O --------→ OUTPUT
When you use the --osscan-limit option, Nmap will restrict the OS detection process to only the most
80/121
likely OS guesses, essentially avoiding any tests that are less likely to provide useful information.
This can speed up the scan and reduce the number of probes sent.
--osscan-guess
The --osscan-guess option tells Nmap to make more aggressive guesses when determining the
target's operating system during an OS scan (using the -O flag). It forces Nmap to be more lenient
with its OS fingerprinting and allow less certain guesses about the operating system, even if the
evidence is not very strong.
Without --osscan-guess: Nmap will only report OS candidates that it is very confident about. It will not
report guesses where the evidence is unclear or weak.
With --osscan-guess: Nmap will report a wider range of OS guesses, even if the evidence is not
entirely conclusive. This can increase the number of possible OS matches Nmap will report.
--fuzzy
The --fuzzy option is closely related to --osscan-guess and further increases the fuzziness of the OS
detection. When used in combination with --osscan-guess, --fuzzy makes Nmap even more
aggressive in its OS detection guesses.
With --fuzzy: Nmap will include OS guesses that are even less certain or more speculative. It takes
"guessing" a step further by allowing very fuzzy or improbable OS guesses based on marginal
evidence.
81/121
Example:
By default, Nmap will try several different probes and attempts to identify the operating system of
the target. If the target is behind a firewall or a filtering device, or if the system's responses are
inconsistent or fragmented, Nmap might not be able to accurately determine the OS in one attempt.
The --max-os-tries option allows you to specify the maximum number of retries Nmap should make
when trying to detect the OS.
--max-os-tries
82/121
16. MANUAL BANNER GRABBING :
CONNECT TO THE PORT AND INVESTIGATE THE RESPONSE.
# nc -vn <ip> 21
83/121
18. OS DISCOVERY USING IPv6 FINGERPRINTING:
#nmap -6 <ip>
84/121
SCANNING BEYOND FIREWALL
THROUGH FIREWALLS AND IDS CAN PREVENT MALICIOUS TRAFFIC FROM
ENTERING A NETWORK , ATTACKERS CAN MANAGE TO SEND INTENDED
PACKETS TO THE TARGET BY EDITING AND IDS OR FIREWALL THROUGH
THE FOLLOWING TECHNIQUES:
1. PACKET FRAGMENTATION
2. SOURCE ROUTING
3. SOURCE PORT MANIPULATION
4. IP ADDRESS DECOY
5. IP SPOOFING
6. MAC SPOOFING
7. CREATING CUSTOM PACKETS
8. RANDOMIZE HOST ADDRESS AND SENDING BAD CHECKSUM
9. PROXY SERVERS
10. ANONYMIZERS
11. FTP BOUNCE SCANNING
12. EXOTIC SCAN FLAGS
13.SET YOUR OWN OFFSET SIZE
Firewalls: Firewalls that analyze traffic at the IP layer may detect and block suspicious patterns in
packets. Fragmenting packets can make it harder for these systems to see the full content of the
packet, especially if they're blocking scans based on the full content or flags.
Intrusion Detection Systems (IDS)/Intrusion Prevention Systems (IPS): IDS/IPS tools often look for
suspicious signatures or abnormal traffic patterns. Fragmented packets can evade detection by
splitting the attack signature into smaller parts.
Network Filters: Some network filters or monitoring systems might not reassemble fragmented
packets and thus fail to detect the scan or attack.
However, while fragmentation can help bypass certain detection mechanisms, it doesn't guarantee
complete evasion, and it can also make the scan more detectable depending on how the network
devices handle fragmented packets.
85/121
option.
nmap -f <target>
This will send fragmented packets to the target, attempting to avoid detection.
86/121
This would break packets into smaller fragments of up to 128 bytes each.
Nmap Packet Construction: Nmap creates a normal packet for the scan (e.g., a SYN scan, ICMP echo
request, etc.).
Fragmentation: It then splits this packet into smaller segments, each with its own fragment offset
and more fragment flag, as per the IP header.
Transmission: Nmap transmits these fragmented packets to the target machine.
Reassembly: The target machine is responsible for reassembling the fragments back into the original
packet before processing it. If the target does not reassemble packets correctly, the scan may fail or
produce incorrect results.
Not Always Effective: Some IDS/IPS devices or firewalls are capable of reassembling fragmented
packets and detecting suspicious activity. Advanced firewalls might inspect individual fragments
before reassembly, making fragmentation ineffective in some cases.
Legal and Ethical Concerns: Using fragmentation to evade detection could be seen as an attempt to
circumvent security controls, which could lead to legal and ethical concerns, especially in
unauthorized scans.
87/121
Fragmentation and Firewall Behavior: Some firewalls might block fragmented packets altogether.
Firewalls that operate at lower network layers might drop fragmented packets to prevent evasion
techniques.
Detection by Advanced IDS/IPS: Advanced systems often employ deep packet inspection (DPI) and
can detect fragmented packets based on patterns or anomalies in the fragment structure, reducing
the effectiveness of fragmentation.
--send-eth: This option sends packets directly at the Ethernet level, bypassing some network layers
like IP. It’s useful for advanced scanning but doesn’t specifically control fragmentation.
-D (Decoy Scan): Instead of fragmenting packets, decoys are used to make the scan seem like it’s
coming from multiple sources. This is a form of evasion, though it doesn’t rely on fragmentation.
-T (Timing Template): You can adjust the scan timing using -T to control the rate at which packets are
sent. A slower scan may evade detection better than a fast one, without the need for fragmentation.
88/121
This will perform a SYN scan and fragment the packets to potentially bypass firewall or IDS detection.
2. SOURCE ROUTING:
Source Routing is a technique where the sender of a packet can specify the route that the packet
should take through the network. Essentially, the sender can dictate the sequence of IP addresses
(routers) the packet should pass through before reaching its destination.In Nmap, source routing is a
feature that allows you to specify a route for the packets to follow, which can be used to evade
network security systems or potentially identify network topologies. However, this feature is rarely
used and may be limited due to its security implications. Many modern routers and firewalls block or
discard packets that attempt to use source routing, as it can be exploited for malicious purposes,
such as evading detection or bypassing security devices.
89/121
1.Why Use Source Routing?
In the context of Nmap, source routing can be used to:
Evade Detection: By directing packets through certain routers, you might avoid detection by a
firewall, intrusion detection system (IDS), or other security devices on the path.
Identify Network Topology: It can help an attacker or network administrator discover the routing path
between two systems, which can be useful in mapping the network structure.
Bypass Network Filters: If a firewall or filter blocks traffic from certain IP addresses or ranges, source
routing can potentially bypass these filters by specifying a route through another network path.
However, source routing is rarely used in modern networks due to the security concerns outlined
below.
Loose Source Routing: The sender specifies a route, but the packet is allowed to take any
path between the specified routers. The packet must pass through at least the listed
routers, but it can take any intermediate route.
Strict Source Routing: The packet must strictly follow the specified route, passing
through each of the listed routers in the order specified by the sender. No intermediate
routers are allowed.
Blocked by Modern Security Devices: Most modern routers and firewalls prevent or discard packets
with source routing headers due to security concerns. Source routing can be exploited for malicious
activities, such as DoS (Denial of Service) attacks, network mapping, or evading security controls. As
a result, source routing is often disabled by default in modern network equipment.
Not Supported by All Networks: Even if source routing is supported by a few devices, it is not
guaranteed that all routers or intermediate devices in the network path will honor the source routing
header. This could lead to fragmented, incomplete, or dropped packets.
90/121
Security Concerns: Source routing can be used by attackers to forge the path that a packet takes,
potentially bypassing security controls or discovering information about the internal network. As a
result, many network security administrators disable or filter source routing to avoid security
vulnerabilities.
Deprecation and Obsolescence: Source routing is considered an obsolete and risky feature in modern
networking. Many organizations explicitly block it due to the risks of misuse.
If the routers and the target system allow source routing, the scan will proceed as expected. If source
routing is blocked by intermediate devices, the packets may not reach their destination, or the scan
may fail.
91/121
Example Command:
This command tells Nmap to send packets with a source port of 80 (HTTP), which is commonly
allowed through firewalls, to the target.
Evasion of Detection: Some firewalls, IDS, or intrusion prevention systems (IPS) might be set up to
detect or block scans that come from certain source ports. By changing the source port, you can
potentially avoid detection or bypass filtering mechanisms.
Mimicking Legitimate Traffic: Many networks allow traffic from well-known ports like 80 (HTTP), 443
(HTTPS), or 53 (DNS). By using these source ports, you can disguise a scan as legitimate traffic,
making it harder to detect as a probe or attack.
Bypassing Port-Specific Filtering: Some security devices block or flag specific ports commonly
associated with malicious activity, such as port 6660-6669 (commonly used by IRC). By changing the
source port, you can circumvent this kind of filtering.
Firewall Bypass:
Some firewalls may block scans that come from random or non-standard ports. By setting the source
port to a common port (e.g., port 80 for HTTP), you can increase the chances of your scan passing
92/121
through the firewall undetected.
Similarly, port 443 is commonly used for HTTPS traffic, which may be allowed through firewalls and
other network security systems.
93/121
Spoofing Limits: While changing the source port is useful for evasion, if you're attempting to perform
port spoofing or more advanced evasion techniques, it might be necessary to combine source port
manipulation with other techniques like fragmentation, decoy scans, or timing options.
Legal and Ethical Considerations: It’s important to ensure that you have authorization before running
any Nmap scans, especially if you are using techniques meant to evade detection. Unauthorized
scanning can be considered illegal or malicious activity.
4. IP ADDRESS DECOY:
In Nmap, an IP address decoy is a technique used to conceal the true source of a scan by sending the
scan from multiple decoy IP addresses along with the actual IP address. This can help obscure your
identity, making it harder for the target system or network security systems (like Intrusion Detection
Systems, or IDS) to identify the source of the scan.
Example Command:
This command uses the -D option, which tells Nmap to use decoys. In this
example:
RND:10 means Nmap will use 10 randomly chosen decoy IP addresses in
94/121
addition to the real source IP.
<target-ip> is the target you want to scan.
Options for Using Decoys in Nmap
Random Decoys (RND:<number>): You can tell Nmap to generate a
certain number of random decoys.
For example:
Mixing Random and Specific Decoys: Nmap allows you to combine both random and specific decoys.
For example:
Avoiding Overuse of Decoys: Using too many decoys may make your scan more noticeable or
increase the load on the network. It's important to find a balance.
95/121
Limitations and Considerations
Legitimate Traffic Confusion:
If the decoy IPs are not properly chosen or are too numerous, it could confuse legitimate network
traffic or make the scan more detectable in some cases.
Accuracy of Results:
Using decoys may lead to some false positives in your scan results. Since the packets originate from
multiple IP addresses, the scan might produce incomplete or misleading results.
Decoy Detection:
Advanced IDS and network monitoring systems may detect unusual patterns of scanning from
multiple decoys, especially if they are IPs not seen in the network before.
Legal and Ethical Issues:
Always ensure that you have permission to perform such scans. Unauthorized scanning, especially
with decoys, can be considered malicious and may be illegal in many jurisdictions.
Example Scenarios
This command will scan the target 192.168.1.1 and use 5 random IP addresses as decoys.
Conclusion
Decoy scanning is a powerful Nmap feature for enhancing stealth and obscuring the true origin of a
scan. By using the -D option to add multiple decoy IP addresses, you can help bypass network
security measures, avoid detection, and make your scanning activities more difficult to trace.
However, it's important to be mindful of the limitations, ethical considerations, and the potential for
scan inaccuracies when using decoys.
5. IP SPOOFING:
IP Spoofing in Nmap refers to the technique of modifying the source IP address of packets to make it
appear as though the scan is coming from a different address than the actual one. This can be useful
for evading detection, hiding the true origin of the scan, or bypassing network security controls that
rely on IP-based filtering.
Key Points:
The IP address in the packet’s header is modified, and the packet appears to come from a spoofed IP.
The target system may respond to the spoofed IP, but the response won’t reach the actual scanning
machine, because the source IP is not real.
This technique can be useful for stealth scans, but it has limitations because the response traffic will
be sent to the spoofed IP, not your actual machine.
How to Perform IP Spoofing in Nmap
Nmap provides a built-in option to spoof the source IP using the --source-ip option. This lets you set a
custom source IP for outgoing packets.
Example Command:
97/121
For example:
98/121
nmap -sS --source-ip 192.168.1.100 10.0.0.1
This performs a SYN scan (-sS) on the target 10.0.0.1 with the source IP 192.168.1.100.
Practical Considerations
Use of Randomized IPs:
While you can spoof a specific IP, some advanced users might use randomized or even multiple IP
addresses to make it harder for a target to recognize the real source of the scan. This is similar to the
decoy scanning method mentioned earlier.
Advanced Techniques:
IP spoofing is often combined with other techniques, such as fragmentation or stealth scanning (e.g.,
using SYN scans or FIN scans), to make the scan even more difficult to detect.
Conclusion
IP spoofing in Nmap can be an effective way to mask the true origin of a network scan. By using the
--source-ip option, you can change the source IP address of packets to appear as if the scan is
coming from another address. However, it’s important to understand the limitations and ethical
concerns associated with IP spoofing. It can be useful for avoiding detection or evading security
measures, but it also has drawbacks, such as the inability to receive responses from the target.
Always use these techniques with caution and ensure you have proper authorization before
conducting any scans.
6. MAC SPOOFING:
In Nmap, you can spoof or change the MAC address used in your network scans using the --spoof-
mac option. This can be useful for various reasons, including privacy or evading detection by
network security systems.
99/121
This command will make Nmap send packets with the MAC address 00:11:22:33:44:55 when
scanning the host at 192.168.1.1.
In this case, Nmap will use a random MAC address associated with Apple.
Important Notes:
Root/Administrator Privileges:
To change the MAC address, you typically need root or administrative privileges on the system
running Nmap.
Limited Scope:
MAC spoofing in Nmap affects the local network packets. For scans over the internet or between
different networks, it won't be as effective in masking your identity or origin.
Detection:
Some security systems may still be able to detect anomalies or inconsistencies in MAC addresses if
they have additional monitoring tools in place.
MAC spoofing is a simple but powerful technique for evading detection or changing your apparent
network identity during a scan.
100/121
7. CREATING CUSTOM PACKETS:
In Nmap, creating custom packets involves crafting specific packet types and behaviors to tailor
your scan for particular needs, such as evading firewalls, performing stealth scans, or testing the
effectiveness of intrusion detection systems (IDS). While Nmap does not have a built-in feature for
creating arbitrary custom packets, you can use several features and options to simulate custom
behaviors. Here are a few ways to approach this:
This sends packets from source port 12345 to port 80 of the target.
TCP SYN Scan (-sS): This is a stealth scan that sends SYN packets and doesn't complete the TCP
handshake.
TCP ACK Scan (-sA): This sends ACK packets to infer information about firewall rules without opening
a connection.
UDP Scan (-sU): This sends UDP packets to detect open ports that respond with ICMP "port
101/121
unreachable" messages when closed.
102/121
Example: Crafting a Custom ICMP Echo Request Packet
This will show you detailed information about every packet that Nmap sends and receives.
Conclusion:
While Nmap is not specifically designed for arbitrary packet crafting, its flexibility with options like
custom payloads, source ports, and scanning types allows users to simulate a variety of custom
traffic patterns. For highly specialized packet crafting, you might need to look at additional tools like
nping (from Nmap's suite), or other packet crafting utilities like Scapy, which provide deeper control
over packet creation and manipulation.
Example:
104/121
105/121
This will randomize the order of scanning hosts within the 192.168.150.0/24 network.
2. Sending a Bad Checksum
To send a bad checksum, nmap provides the --send-eth and --spoof-mac options. However, nmap
doesn't have a direct option to modify or deliberately cause a bad checksum, but you can use other
techniques or tools for crafting bad checksums (like scapy or manually manipulating packets).
In the context of nmap, sending a bad checksum could typically be achieved by:
Using a custom script or tool like scapy to create packets with bad checksums and inject them into
the network.
Sending malformed packets using nmap might be possible with --
data-length or --randomize-hosts to modify packet content, but
this doesn't directly "create" a bad checksum.
Alternative: Using a Packet Crafting Tool (e.g., Scapy) If you want to specifically create a packet with a
bad checksum, it's easier to use a tool like Scapy, which allows you to craft packets with incorrect
checksums. Here's an example of how you might do this using Scapy:
106/121
This command will randomize the host order for a SYN scan (-sS).
107/121
If you specifically need to generate packets with bad checksums and randomization, I recommend
using scapy for the checksum manipulation and nmap for network scanning separately.
9. PROXY SERVERS:
In nmap, proxy servers can be used to route your scan traffic through an intermediary, helping you
obscure your scanning source or bypass network restrictions. While nmap does not natively support
proxies for all types of scans, it can use SOCKS proxies and HTTP proxies with specific options.
Application-level proxies, particularly for the Web, have become popular due to perceived security
and network efficiency (through caching) benefits. Like firewalls and IDS, misconfigured proxies can
cause far more security problems than they solve. The most frequent problem is a failure to set
appropriate access controls. Hundreds of thousands of wide-open proxies exist on the Internet,
allowing anyone to use them as anonymous hopping points to other Internet sites. Dozens of
organizations use automated scanners to find these open proxies and distribute the IP addresses.
Occasionally the proxies are used for arguably positive things, such as escaping the draconian
censorship imposed by the Chinese government on its residents. This “great firewall of China” has
been known to block the New York Times web site as well as other news, political, and spiritual sites
that the government disagrees with. Unfortunately, the open proxies are more frequently abused by
more sinister folks who want to anonymously crack into sites, commit credit card fraud, or flood the
Internet with spam.
While hosting a wide-open proxy to Internet resources can cause numerous problems, a more serious
condition is when the open proxies allow connections back into the protected network. Administrators
who decide that internal hosts must use a proxy to access Internet resources often inadvertently
allow traffic in the opposite direction as well. The hacker Adrian Lamo is famous for breaking into
Microsoft, Excite, Yahoo, WorldCom, the New York Times, and other large networks, usually by
exploiting this reverse-proxy technique.
Nmap does not presently offer a proxy scan-through option, though it is high on the priority list. the
section called “SOLUTION: Hack Version Detection to Suit Custom Needs, such as Open Proxy
Detection” discusses a way to find open proxies using Nmap version detection. In addition, plenty of
dedicated free proxy scanners are available on Internet sites such as Packet Storm. Lists of
thousands of open proxies are widespread as well.
108/121
port 9050.
Using an HTTP Proxy: You can also route your scans through an HTTP proxy using the --proxy option.
This might be helpful for bypassing restrictions on HTTP traffic or to obfuscate the scan origin.
This would route the scan through the HTTP proxy at 192.168.1.100 on port 8080.
Performance:
Routing traffic through a proxy, especially an HTTP or SOCKS proxy, can significantly slow down the
scan due to the additional overhead.
109/121
Scanning Accuracy:
Using proxies can sometimes lead to inaccurate scan results, as network characteristics may differ
between your machine and the proxy server (e.g., latency, routing paths, etc.).
10. ANONYMIZERS:
In nmap, anonymizers are methods or tools used to hide the origin of your scan or to obfuscate your
IP address. This is useful in situations where you want to perform scanning without revealing your
real IP address, to protect your privacy, or to bypass network restrictions. The most commonly used
anonymizers with nmap are Tor (via SOCKS proxy) and VPNs. These are not native features of nmap
but can be integrated using proxy options.
Example Command:
Example Setup:
Connect to a VPN:
Use your VPN client (e.g., OpenVPN, WireGuard, or a commercial VPN service) to connect to the VPN.
Run the Nmap Scan: Once connected to the VPN, your IP address will be the one assigned by the
VPN, and the scan will appear to originate from that address.
nmap <target>
Using a VPN in conjunction with nmap effectively masks your IP and ensures that the scan traffic
comes from the VPN’s exit node, not your local machine.
Proxychains is a popular Linux tool that can route network traffic through a chain of proxies, including
Tor or HTTP proxies.
Setting up Proxychains with Nmap:
Install proxychains on your system (e.g., sudo apt install proxychains on Debian-based systems).
Configure proxychains by editing /etc/proxychains.conf to include your proxies (e.g., SOCKS5, HTTP).
Run nmap through proxychains:
Conclusion:
Using anonymizers in nmap is a great way to protect your identity and maintain privacy during a
network scan. Tor and VPNs are the most common options, but they come with limitations such as
slower performance and scan incompatibility with certain types of scanning techniques. For stronger
anonymity, combining multiple proxies in a proxy chain can offer additional layers of obfuscation.
Always be mindful of the ethical and legal implications of scanning networks, especially when using
anonymizers to hide your identity.
abhishek~>
nmap -p 22,25,135 -Pn -v -b XXX.YY.111.2
scanme.nmap.org
Starting Nmap ( https://nmap.org )
Attempting connection to ftp://anonymous:-wwwuser@@XXX.YY.111.2:21
Connected:220 JD FTP Server Ready
Login credentials accepted by ftp server!
Initiating TCP ftp bounce scan against scanme.nmap.org (64.13.134.52)
Adding open port 22/tcp
Adding open port 25/tcp
Scanned 3 ports in 12 seconds via the Bounce scan.
Nmap scan report for scanme.nmap.org (64.13.134.52)
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
135/tcp filtered msrpc
112/121
12. Exotic Scan Flags
The previous section discussed using an ACK scan to map out which target network ports are filtered.
However, it could not determine which of the accessible ports were open or closed. Nmap offers
several scan methods that are good at sneaking past firewalls while still providing the desired port
state information. FIN scan is one such technique. In the section called “ACK Scan”, SYN and ACK
scans were run against a machine named Para. The SYN scan showed only two open ports, perhaps
due to firewall restrictions. Meanwhile, the ACK scan is unable to recognize open ports from closed
ones. Example 10.6 shows another scan attempt against Para, this time using a FIN scan. Because a
naked FIN packet is being set, this packet flies past the rules blocking SYN packets. While a SYN scan
only found one open port below 100, the FIN scan finds both of them.
Many other scan types are worth trying, since the target firewall rules
and target host type determine which techniques will work. Some
particularly valuable scan types are FIN, Maimon, Window, SYN/FIN, and
NULL scans.
114/121
NMAP SCRIPT ENGINE (NSE)
The Nmap Script Engine (NSE) is a powerful feature of Nmap that allows
users to automate a variety of network scanning tasks, from service
discovery to vulnerability detection. NSE uses Lua scripting language to
write custom scripts that can interact with network services and perform
various types of tasks. These scripts can be used to detect
vulnerabilities, gather information, and exploit weaknesses, making
Nmap a versatile tool for network administrators, penetration testers,
and security professionals.
SCRIPTS LOCATION :
/usr/share/nmap/scripts
115/121
Malware Detection Scripts:
These scripts help to identify signs of malware or suspicious activities on a target.
Exploit Scripts:
These scripts are used to attempt to exploit vulnerabilities that have been discovered.
Default Scripts:
These are scripts that are enabled by default during a standard Nmap scan. They provide general
information about the host being scanned.
Miscellaneous Scripts:
A collection of other scripts that don't fall into the categories above, but still offer useful functionality.
smb-os-fingerprint:
Gathers information about the SMB operating system.
ssl-cert:
Retrieves SSL certificate details from an SSL/TLS service.
smtp-commands:
Checks the SMTP service to see what commands are supported.
116/121
http-methods:
This script checks for which HTTP methods are allowed (e.g., GET, POST, DELETE) on a web server.
vuln-cve-xxxx:
Many scripts are named after specific CVEs (Common Vulnerabilities and Exposures) that they are
designed to test, e.g., smb-vuln-ms17-010 tests for the MS17-010 vulnerability.
http-sql-injection:
Attempts to find SQL injection vulnerabilities on a web server by sending various types of payloads.
ssh-brute:
Performs brute-force attacks against SSH services, trying common usernames and passwords to
gain access.
ftp-brute:
Similar to ssh-brute, but targets FTP services.
dns-nsid:
This script attempts to retrieve the name server identifier (NSID) from a DNS server.
http-robots.txt:
Retrieves the robots.txt file from a web server, which may reveal hidden paths or security
information.
dns-brute:
This script performs brute-force domain name system (DNS) name resolution, attempting a large
number of subdomain names against a given domain.
ssl-heartbleed:
This tests if a server is vulnerable to the Heartbleed bug in OpenSSL, which can expose sensitive
memory content.
http-malware-host:
Detects if the web server is serving malware or hosting malicious content.
smb-enum-shares:
Enumerates shared resources on a target SMB server.
ftp-syst:
Retrieves system information from an FTP server.
117/121
ALL_NMAP_SCRIPTS_LIST.pdf
118/121
DETECT WAF
Detecting WAF
Web application firewalls (WAF) may drop malicious requests, such as those with SQL injections, or
otherwise interfere with enumeration or testing:
119/121
OUTPUT RESULTS
1. NORAMAL OUTPUT TO THE FILE “NORMAL.FILE”
nmap <ip> -oN normal.file
120/121
9. DISPLAY THE REASON A PORT IS IN A
PARTICULAR STATE, SAME OUTPUT AS -VV
nmap <ip> --reason
121/121