Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . NMAP Tutorial: Basics to Advanced

NMAP Tutorial: Basics to Advanced

 Nmap("Network Mapper") is an open-source and free tool that’s widely used for network discovery purposes. It’s capable of performing both host discovery and service detection, as well as doing a content analysis of the traffic it receives. Common uses for Nmap include vulnerability discovery, system security auditing, and detecting cyber attacks. You can run Nmap on a command line or in a web browser. To get the most out of Nmap, you should familiarize yourself with its features and usage.

Nmap can be used to find open ports on a remote host or network, and check whether a host or network has been compromised. It can also be used to test your own server or network to identify weak spots. Another common use case is in vulnerability assessment: using Nmap to test the connection between your website and your users to see whether your application is open to exploitation. 

When used properly, Nmap can be a very powerful tool. However, using it incorrectly can also cause problems. For example, sending a request with a Nmap scan that includes a lot of output will likely consume a lot of network bandwidth. This type of scan is called promiscuous mode and can cause network congestion if not used properly. Sending a request with a light Nmap scan may not cause any extra traffic but is still likely to return inaccurate results. 

Nmap can also be used for malicious purposes. Connecting a vulnerable system to a large network of malicious systems can help spread infection. Using Nmap to scan networks for vulnerabilities is also a risky proposition. It is likely to return inaccurate or even misleading results. Nmap is an open-source tool and is widely used by Nessus and other security researchers. Therefore, it is likely to be well-regarded by the community.

1. Nmap Scan Types

Scan TypeDetails
TCP SCANA TCP scan is used to ensure that a three-way handshake has been completed between you and a selected target system. Even though it is very noisy, a TCP scan can be detected with little to no effort. This is because the services may log the sender's IP address and may trigger an intrusion detection system.
UDP SCANThe UDP scan checks whether there is any UDP port open and listens for incoming connections on the target machine. Contrary to TCP, UDP does not offer any way to cure a positive result by sending a response with a positive acknowledgment. As a result, UDP scans may sometimes produce false positives. This type of scan is usually quite slow because computers, in general, slow down their responses to this kind of traffic in order to be on the safe side.
SYN SCANIn a SYN scan, a TCP connection is established by first creating a SYN packet and sending it to the server. This is unlike a normal TCP scan, which just generates a SYN packet. The response to these specially crafted packets is also analyzed by Nmap to produce scan results.
ACK SCANTo be able to monitor whether a particular port is filtered or not, ACK scans are employed. This guarantees to be very valuable when trying to spy on firewalls or their existing protocols. Simple packet filtering allows established connections, whereas a more complex firewall might not.
FIN SCANThe FIN scan is a stealthy TCP connection scan that sends a TCP FIN packet instead of a SYN packet. The computer may either send an RST packet (reset packet) back if it receives this input or send a FIN scan (finishing process) that may falsely generate positives and negatives, but it may elude some IDS systems and other countermeasures.
NULL SCANA null scan is exactly what it sounds like: It leaves all of the header fields blank. Null packets are usually not valid and a few targets may not be able to handle them, but it is possible for them to be. Against a specific type of windows target, also known as null packet scanning, it is possible to produce unreliable results. On the other hand, as an effective way to get through windows, it is usually possible.
XMAS SCANXMAS scans are very covert in nature. Because of the way their TCP protocol operates, computers running Windows will not react to Xmas scans in any way. The scan's name comes from the set of flags that are turned on within the packet that is being sent out for scanning. XMAS scans are used to manipulate the PSH, URG, and FIN flags found in the TCP header.
RPC SCANRPC scans are used to discover remote procedure calls (RPC) machines that respond to Remote Procedure Call services (RPC). RPC services can be run on a variety of ports, making it hard to identify from a normal scan whether RPC services are running or not. It is generally a good idea to conduct an RPC scan periodically to learn where they are operating.
IDLE SCANIDLE Scan is one of the less popular types of scans because it requires the host to be controlled. The packets are bounced off an external host in order to conceal their origins. Malicious attacks are limited to only those packets that are bounced off the internal host. It is one of the more controversial choices in Nmap because it is primarily used for malicious attacks.

Category-wise diverse NMAP commands with examples are explained in the following section.

2. Target Specification

Switch ExampleDescription
 nmap 192.168.1.3Scan a specific IP address
 nmap 192.168.1.2 192.168.2.3Scan specific IP addresses
 nmap 192.168.1.7-254Scan specific range of IP addresses
 nmap ramdom.doman.orgScans a domain
 nmap 192.168.1.1/29Scans a single IP using CIDR notation
-iLnmap -iL text.txtScans a target from a file
-iRnmap -iR 200Scans random 200 hosts
–excludenmap -exclude 192.168.1.2Exclude the listed hosts

3. Scan Techniques

SwitchExampleDescription
-sSnmap 192.167.1.2 -sSTCP SYN Scan
-sTnmap 192.168.1.1 -sTTCP Connect Scan
-sUnmap 192.168.1.1 -sUUDP scan
-sAnmap 192.168.1.1 -sATCP ACK Scan
-sWnmap 192.168.1.1 -sWTCP Window scan
-sMnmap 192.168.1.1 -sMTCP Maimon scan

4. Host Discovery

SwitchExampleDescription
-sLnmap 192.168.1.6-9 -sLCreates targets List only
-snnmap 192.168.1.2/29 -snThis disables port scans and does host discovery only.
-Pnnmap 192.168.1.2-5 -PnThis disables host discovery and allows port scan only.
-PSnmap 192.168.1.2-5 -PS22-25,80

TCP SYN ping on port x.

Port 80 is by default

-PAnmap 192.168.1.2-5 -PA22-25,80

TCP ACK ping on port x.

Port 80 is by default

-PUnmap 192.168.1.3-7 -PU53

Enables UDP ping on port x.

Port 40125 is by default

-PRnmap 192.168.1.2-3/24 -PRARP ping on the local network
-nnmap 192.168.1.2 -nDisables DNS resolution

5. Port Specification

SwitchExampleDescription
-pnmap 192.168.1.9 -p 27Scan a specific port
-pnmap 192.168.1.9 -p 27-100Scan a port range
-pnmap 192.168.1.9 -p U:53,T:27-40,80Scans multiple TCP and UDP ports
-p-nmap 192.168.1.9 -p-
Scan all ports
-pnmap 192.168.1.9 -p http,httpsScans based on the service name
-Fnmap 192.168.1.9 -FScan 100 ports in fast manner
–top-portsnmap 192.168.1.9 -top-ports 1015Scans the top “x” ports
-p-65535nmap 192.168.1.8 -p-65535Skips the initial port in the range and starts the scan from port 1
-p0-nmap 192.168.1.9 -p0-Skips end port in the range and starts the scan to go through to the port 65535

6. Service and Version Detection

SwitchExampleDescription
-sVnmap 192.168.1.9 -sVHelps in determining the version of the service 
-sV –version-intensitynmap 192.168.1.9 -sV -version-intensity 9To increase the Intensity level between 0 to 9. The higher the number higher is possibility of correctness
-sV –version-lightnmap 192.168.1.9 -sV -version-lightThis enables light mode. This has a lower possibility of correctness but is faster.
-sV –version-allnmap 192.168.1.9 -sV -version-allThis enables an intensity level  of 9. This has a higher possibility of correctness but is slower.
-Anmap 192.168.1.8 -AThis enables OS detection, version detection, and script scanning.

7. OS Detection

SwitchExampleDescription
-Onmap 192.168.1.8 -OTCP/IP stack fingerprinting is used for remote OS detection.
-O –osscan-limitnmap 192.168.1.8 -O -osscan-limitThe TCP port scan will not attempt OS detection on those hosts that do not have at least one open and one closed port.
-O –osscan-guessnmap 192.168.1.8 -O -osscan-guessMakes Nmap guess more competently
-O –max-os-triesnmap 192.168.1.8 -O -max-os-tries 1
This set the maximum number “x” of OS detection attempts against a target

8. Timing and Performance

SwitchExampleDescription
-T0nmap 192.168.1.8 -T0Paranoid (0) Timing
-T1nmap 192.168.1.8 -T1Sneaky (1) Timing
-T2nmap 192.168.1.8 -T2Polite (2) Timing
-T3nmap 192.168.1.8 -T3Normal (3) Timing
-T4nmap 192.168.1.8 -T4Aggressive (4) Timing
-T5nmap 192.168.1.8 -T5Insane (5) Timing
SwitchExample inputDescription
–host-timeout <time>5s; 10m; 5hAfter this long, give up on the target.
–min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>5s; 10m; 5hHow long it takes to return a probe round trip.
–min-hostgroup/max-hostgroup <size<size>20; 512Specifies host scan group sizes for parallelization
–min-parallelism/max-parallelism <numprobes>10; 1This probes parallelization
–scan-delay/–max-scan-delay <time>10ms; 5s; 10m; 3hThis adjusts the delay between probes
–max-retries <tries>5Specifies the maximum number retries for port scan probe retransmissions
–min-rate <number>10This sends packets at a minimum speed of <number> per second
–max-rate <number>250This sends packets at a maximum speed of <number> per second

9. NSE Scripts

SwitchExampleDescription
-sCnmap 192.168.1.9 -sCDefault NSE scripts are used to scan.
–script defaultnmap 192.168.1.9 -script defaultThis scans with default NSE scripts 
–scriptnmap 192.168.1.9 -script=bannerSingle script scanning
–scriptnmap 192.168.1.9 -script=http*Wildcard scanning
–scriptnmap 192.168.1.9 -script=http,bannerTwo scripts scanning
–scriptnmap 192.168.1.9 -script "not intrusive"Default scanning without intrusive scripts
–script-argsnmap -script snmp-sysdescr -script-args snmpcommunity=admin 192.168.1.9NSE script scanning with scipts

10. Useful NSE Script Examples

CommandDescription
nmap -Pn -script=http-sitemap-generator interviewbit.com Map generator for HTTP site
nmap -n -Pn -p 80 -open -sV -vvv -script banner,http-title -iR 1000Search random web servers
nmap -Pn -script=dns-brute interviewbit.comThis gusses sub-domains by brute forcing on DNS hostnames
nmap -n -Pn -vv -O -sV -script smb-enum*,smb-ls,smb-mbenum,smb-os-discovery,smb-s*,smb-vuln*,smbv2* -vv 192.168.1.1Run safe SMB scripts
nmap -script whois* interviewbit.comQuery for whois 
nmap -p80 -script http-unsafe-output-escaping interviewbit.comVulnerabilities detection on cross websites
nmap -p80 -script http-sql-injection interviewbit.comSQL injections detection

11. Firewall / IDS Evasion and Spoofing

SwitchExampleDescription
-fnmap 192.168.1.9 -fSmall fragmented IP packets are used in requested scans (including ping scans). More difficult for packet filters
–mtunmap 192.168.1.9 -mtu 32Set the offset size yourself
-Dnmap -D 192.168.9.102,192.168.9.103,192.168.9.104,192.168.9.523Scans from the spoofed IPs are send via this
-Snmap -S www.interviewbit.com www.scaler.com Scans Scaler from InterviewBit 
-gnmap -g 53 192.168.1.9Uses the given port number
–proxiesnmap -proxies http://192.168.1.9:8080, http://192.168.9.2:8080 192.168.1.9This relays connections via HTTP or SOCKS4 proxy
–data-lengthnmap -data-length 200 192.168.1.9This adds random data to the sent packets

12. Output

SwitchExampleDescription
-oNnmap 192.168.1.9 -oN result.fileAdds the output to the result.file that is in normal format
-oXnmap 192.168.1.9 -oX result.fileAdds the output to the result.file that is in XML format
-oGnmap 192.168.1.9 -oG result.fileAdds the output to the result.file that can be grepable
-oAnmap 192.168.1.9 -oA resultsAll three major formats are displayed via this
-oG –nmap 192.168.1.9 -oG -Shows grepable output on the screen
–append-outputnmap 192.168.1.9 -oN file.file -append-outputAdds a scan to the previous scanned file
-vnmap 192.168.1.9 -vVerbosity level is increase via this
-dnmap 192.168.1.9 -dDebugging level is increase via this
–reasonnmap 192.168.1.9 -reasonShows the reason for the given state of the port
–opennmap 192.168.1.9 -openOpen ports are shown
–packet-tracenmap 192.168.1.9 -T4 -packet-tracePackets sent and received are shown
–iflistnmap -iflistHost interfaces and routes are shown
–resumenmap -resume scaler.fileScan is resumed

13. Other Useful NMAP Commands

CommandDescription
nmap -iR 10 -PS22-25,80,113,1050,35000 -v -snOnly ports x are scanned, no ports are discovered.
nmap 192.168.1.9-1/25 -PR -sn -vvOnly show ARP discovery on the local network, no port scan.
nmap -iR 20 -sn -tracerouteNo port scan - just traceroute to specific targets.
nmap 192.168.1.9-40 -sL -dns-server 192.168.1.9Queries the Internal DNS for detecting hosts and then lists targets

Conclusion

In this document, we’ve covered the basics of Network Mapper (NMAP), its features and some of the important cheat sheets. NMAP is the supreme source of port scan information, the foundation for most security enumeration during the initial phases of a penetration test. It has a number of settings and when you first start out using it it may be difficult to figure out. You can follow the guide for running Nmap on a Mac OS X or Linux machine. The beauty of the Nmap tool is that it’s designed to work with text output. This means that you do not have to be an expert in Linux or Bash Scripting in order to use this amazing tool. The code examples are very easy to follow and you will be up and running with Nmap in no time. 

Now, it’s time for you to head out and try what we’ve covered here and more. More than memorizing syntax, do pay attention to practising them and solving problems.

NMAP MCQ

1.

Which of the following commands scans random hosts?

2.

Which of the following commands is for IP Protocol Ping?

3.

Which of the following commands create a host list?

4.

Which of the following commands sends IP packets?

5.

Which of the following commands perform a sequential port scan?

Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.