A Quick Port Scanning Tutorial (2024)

  • Nmap Network Scanning
  • Chapter4.Port Scanning Overview
  • A Quick Port Scanning Tutorial

One of my goals in developing Nmap is to keep the most commonusage simple, while retaining the flexibility for custom and advancedscans. This is accomplished with the command-line interface byoffering dozens of options, but choosing sane defaults when they arenot specified. A newbie can start out with a command as simple asnmap <target>.Meanwhile, advanced users sometimes specify so many options that theirterminal line wraps around.

A similar balance must be struck with command output. The mostimportant results should stick out even to the occasional user whohasn't even read the man page. Yet the output should be comprehensive andconcise enough to suit professional penetration testers who run Nmapagainst thousands of machines daily. Users smart enough to read thisbook or the Nmap source code benefit from greater control ofthe scanner and insights into what Nmap output really means.

This tutorial demonstrates some common Nmap port scanningscenarios and explains the output. Rather than attempt to becomprehensive, the goal is simply to acquaint new users well enough tounderstand the rest of this chapter.

The simplest Nmap command is just nmap byitself. This prints a cheat sheet of common Nmap options and syntax.A more interesting command is nmap<target>, which does thefollowing:

  1. Converts <target> from a hostname into an IPv4 address using DNS. If an IP address is specified instead of a hostname this lookup is skipped.

  2. Pings the host, by default with an ICMP echo request packet and a TCP ACK packet to port 80, to determine whether it is up and running. If not, Nmap reports that fact and exits. I could have specified -Pn to skip this test. See Chapter3, Host Discovery (“Ping Scanning”).

  3. Converts the target IP address back to the name using a reverse-DNS query. Because of the way DNS works, the reverse name may not be the same as the <target> specified on the command-line. This query can be skipped with the -n option to improve speed and stealthiness.

  4. Launches a TCP port scan of the most popular 1,000 ports listed in nmap-services. A SYN stealth scan is usually used, but connect scan is substituted instead for non-root Unix users who lack the privileges necessary to send raw packets.

  5. Prints the results to standard output in normal human-readable format, and exits. Other output formats and locations (files) can be specified, as described in Chapter13, Nmap Output Formats. Example4.2 displays the results when scanme.nmap.org is used as <target>.

Example4.2.Simple scan: nmap scanme.nmap.org

# nmap scanme.nmap.orgStarting Nmap ( https://nmap.org )Nmap scan report for scanme.nmap.org (64.13.134.52)Not shown: 994 filtered portsPORT STATE SERVICE22/tcp open ssh25/tcp closed smtp53/tcp open domain70/tcp closed gopher80/tcp open http113/tcp closed authNmap done: 1 IP address (1 host up) scanned in 4.99 seconds

The first output line inExample4.2 simply gives the URL for downloading Nmap. The time Nmap started andversion number are normally provided as well, though these weregenerally removed from this book for consistency and to avoid linewrapping.

The next line provides the target IP address (IPv4 in thiscase), andreverse DNSname (also known as the PTR record)if it isavailable. Nmap promises to show the interesting ports, though allports scanned are accounted for. The ports considered mostinteresting because they are open or in a rarely-seen state for thathost are itemized individually. When many ports are in a singlenon-open state, they are considered a default state, and aggregated onto asingle line to avoid diluting the results with thousands ofuninteresting entries. In this case, Nmap notes that 994 ports arefiltered.

The interesting ports table comes next, and provides the keyscan results. The columns vary depending on options used, but inthis case provide the port number and protocol, state, and serviceprotocol for each port. The service here is just a guess made bylooking up the port in nmap-services. Theservice would be listed as unknown if any of theports had no name registered in that file. Three of these ports are openand three are closed.

Finally, Nmap reports some basic timing stats before it exits.These stats are the number of targets specified, the number of thosethat the ping scan found to be up, and the total time taken.

While this simple command is often all that is needed, advancedusers often go much further. In Example4.3, the scan is modified withfour options. -p0- asks Nmap to scan every possibleTCP port, -v asks Nmap to be verbose about it,-A enables aggressive tests such as remote OSdetection, service/version detection, and the Nmap Scripting Engine(NSE). Finally, -T4 enables a more aggressive timingpolicy to speed up the scan.

Example4.3.More complex: nmap -p0- -v -A -T4 scanme.nmap.org

# nmap -p0- -v -A -T4 scanme.nmap.orgStarting Nmap ( https://nmap.org )Completed Ping Scan at 00:03, 0.01s elapsed (1 total hosts)Scanning scanme.nmap.org (64.13.134.52) [65536 ports]Discovered open port 22/tcp on 64.13.134.52Discovered open port 53/tcp on 64.13.134.52Discovered open port 80/tcp on 64.13.134.52SYN Stealth Scan Timing: About 6.20% done; ETC: 00:11 (0:07:33 remaining)Completed SYN Stealth Scan at 00:10, 463.55s elapsed (65536 total ports)Completed Service scan at 00:10, 6.03s elapsed (3 services on 1 host)Initiating OS detection (try #1) against scanme.nmap.org (64.13.134.52)Initiating Traceroute at 00:1064.13.134.52: guessing hop distance at 9Completed SCRIPT ENGINE at 00:10, 4.04s elapsedHost scanme.nmap.org (64.13.134.52) appears to be up ... good.Nmap scan report for scanme.nmap.org (64.13.134.52)Not shown: 65530 filtered portsPORT STATE SERVICE VERSION22/tcp open ssh OpenSSH 4.3 (protocol 2.0)25/tcp closed smtp53/tcp open domain ISC BIND 9.3.470/tcp closed gopher80/tcp open http Apache httpd 2.2.2 ((Fedora))|_HTML title: Go ahead and ScanMe!113/tcp closed authDevice type: general purposeRunning: Linux 2.6.XOS details: Linux 2.6.20-1 (Fedora Core 5)Uptime guess: 2.457 days (since Thu Sep 18 13:13:24 2008)TCP Sequence Prediction: Difficulty=204 (Good luck!)IP ID Sequence Generation: All zerosTRACEROUTE (using port 80/tcp)HOP RTT ADDRESS[First eight hops cut for brevity]9 10.36 metro0.sv.svcolo.com (208.185.168.173)10 10.29 scanme.nmap.org (64.13.134.52)Nmap done: 1 IP address (1 host up) scanned in 477.23 seconds Raw packets sent: 131432 (5.783MB) | Rcvd: 359 (14.964KB)

Nmap certainly provided the requested verbosity in Example4.3! Fortunately the extraoutput is easy to understand. The first 13 new lines are runtimeinformation letting the user know what is happening as she staresexpectantly at the terminal, hoping for good news. Whatconstitutes good news depends on whether she is a systemsadministrator who has to fix problems, a pen-tester who needs someissues to report on, or a black-hat cracker trying to exploitthem. About a dozen similar lines were removed for brevity. The discovered open port lines provideas-it-happens notification of open ports so that she can start bangingon them before the scan even finishes. The scan timing lineprovides a completion time estimate, so she knows whether to keepstaring at the screen or have lunch. Since network conditions(latency, congestion, bandwidth, etc.) and packet filtering rules varyso much, the same scan options may take 30 seconds to complete againstone host and 45 minutes against another. If you want the current time estimate while scanning, just pressenter.

The port table shows no new ports. All the extra ports scannedare in the filtered state, raising the filtered port total from 994to 65,530. While there are no new itemized ports, the entries havechanged. A new VERSION column provides the application name and version details for the listening service. This comesfrom service detection, one of the features enabled bythe -A option.Another feature of service detection is that allof the service protocols in the SERVICE column have actually beenverified. In the previous scan, they were based on the relativelyflimsy heuristic of an nmap-services port number lookup.That table lookup happened to be correct this time, but it won'talways be.

Another feature added by -A is the NmapScripting Engine,which is discussed in depth inChapter9, Nmap Scripting Engine. The only script shown here is HTMLtitle. Dozens of other scripts exist, but none found usefuloutput for this machine. Thetracerouteresults were also addedby -A. This option is more efficient and morepowerful than most traceroute programs since probes are performed inparallel and Nmap uses scan results to determine a favorable probetype (TCP packets to port 80 in this case).

Most of the remaining new lines come from OS detection (alsoenabled by -A), which is discussed in depth inChapter8, Remote OS Detection. The final line shows that all this extrainfo came at a price—the scan took almost 100 times longer thanExample4.2, “Simple scan: nmap scanme.nmap.org” to complete (477seconds compared to 5).

A Quick Port Scanning Tutorial (2024)

FAQs

What are the responses to a port scan? ›

Port scan results reveal the status of the network or server and can be described in one of three categories: open, closed, or filtered. Open ports: Open ports indicate that the target server or network is actively accepting connections or datagrams and has responded with a packet that indicates it is listening.

How do I fast scan ports in Nmap? ›

By default, Nmap scans the 1,000 most popular ports of each protocol it is asked to scan. Alternatively, you can specify the -F (fast) option to scan only the 100 most common ports in each protocol or --top-ports to specify an arbitrary number of ports to scan.

How do I scan all ports 65535? ›

Scanning specific port ranges

There are several ways of using the Nmap -p option: Port list separated by commas: $ nmap -p80,443 localhost. Port range denoted with hyphens: $ nmap -p1-100 localhost. Alias for all ports from 1 to 65535: # nmap -p- localhost.

How many well-known ports are there in Tryhackme? ›

A standard network-enabled computer typically has a total of 65535 available ports. These ports are divided into three well-known categories: Well-Known Ports (0–1023): Ports in this range are reserved for widely-used and standardized services.

Is port scanning illegal? ›

It is legal. However every network makes its own rules and you must abide by them. For example, whether your ISP bans port scanning on their hosts (including their all of their customers) is up to them. They might also choose to ban the transmission of associated protocols completely.

What are the three types of responses for port security? ›

You can configure the port for one of three violation modes: protect, restrict, or shutdown.

What is the fastest port scanner? ›

Masscan is widely known as the fastest port scanner. It has both a command line and a graphical interface, and the default transmission rate is 100 packets per second. Onetwopunch is a powerful script that combines the features of unicornscan and Nmap tools for faster and more accurate results.

Which command is used for port scanning? ›

Port Scanning is one of the features of Nmap wherein the tool detects the status of the ports on active hosts in a network. The status of the ports can be open, filtered, or closed. Type Nmap in the command line to run Nmap.

What is the most powerful Nmap scan? ›

Port scanning.

One of the most powerful features of Nmap is Nmap Scripting Engine (NSE). NSE enables users to write scripts to automate various network tasks. Nmap uses Lua, an embedded programming language, for writing scripts.

Is RustScan better than Nmap? ›

Advantages of Rustscan over Nmap:

Speed: It is renowned for its rapid scanning capabilities. Its multithreaded architecture and optimized algorithms enable it to scan large networks significantly faster than traditional scanners like Nmap.

How to do full port scan? ›

TCP Connect Scan (-sT)

The TCP Connect Scan is the default scan type used by Nmap ports. It establishes a full TCP connection with the target system by completing the three-way handshake. It sends SYN packets to the target ports and waits for SYN-ACK responses to determine if the ports are open, closed, or filtered.

How do you tell Nmap to scan all ports? ›

-p0- asks Nmap to scan every possible TCP port, -v asks Nmap to be verbose about it, -A enables aggressive tests such as remote OS detection, service/version detection, and the Nmap Scripting Engine (NSE). Finally, -T4 enables a more aggressive timing policy to speed up the scan.

What port do hackers use? ›

Ports most targeted by attackers include ports 443 and 8080 (HTTP and HTTPS) No port is 100% secure and what determines the risk of a port is the way it is managed. To protect open ports, it is essential to use ports that encrypt traffic in order to make it difficult for hackers to access sensitive information.

How do I test all ports? ›

If you would like to test ports on your computer, use the Windows command prompt and the CMD command netstat -ano. Windows will show you all currently existing network connections via open ports or open, listening ports that are currently not establishing a connection.

What is UDP scanning? ›

A user diagram protocol (UDP) scan checks for any UDP ports that are deployed on a target. Conversely, the regular scan only scans the TCP ports. UDP scans are normally slower and more difficult than TCP scans.

What are the results of a port scan? ›

Port Scanning Results

A port scanner sends a UDP or TCP network packet that asks the port about its status. The results will uncover network or server status, which can be one of the following: open, closed and filtered.

How do I know if a port is responding? ›

Type "Network Utility" in the search field and select Network Utility. Select Port Scan, enter an IP address or hostname in the text field, and specify a port range. Click Scan to begin the test. If a TCP port is open, it will be displayed here.

What information can be found by running a port scan? ›

Port scanning is a popular method cyber criminals use to search for vulnerable servers. They often use it to discover organizations' security levels, determine whether businesses have effective firewalls, and detect vulnerable networks or servers.

What is a dropped response in port scan? ›

No response.

Also known as filtered or dropped, this involves neither acknowledging the request nor sending a reply. No response indicates to the port scanner that a firewall likely filtered the request packet, the port is blocked or there is no port there.

Top Articles
Best practices for secure online payment processing
7 Digital Marketing Trends to Watch Out For in 2024
Kreme Delite Menu
Ups Dropoff Location Near Me
Satyaprem Ki Katha review: Kartik Aaryan, Kiara Advani shine in this pure love story on a sensitive subject
Kraziithegreat
Otterbrook Goldens
Videos De Mexicanas Calientes
San Diego Terminal 2 Parking Promo Code
<i>1883</i>'s Isabel May Opens Up About the <i>Yellowstone</i> Prequel
Kris Carolla Obituary
Stream UFC Videos on Watch ESPN - ESPN
Cranberry sauce, canned, sweetened, 1 slice (1/2" thick, approx 8 slices per can) - Health Encyclopedia
Urban Dictionary Fov
Conduent Connect Feps Login
2024 U-Haul ® Truck Rental Review
Apne Tv Co Com
Images of CGC-graded Comic Books Now Available Using the CGC Certification Verification Tool
Invert Clipping Mask Illustrator
Honda cb750 cbx z1 Kawasaki kz900 h2 kz 900 Harley Davidson BMW Indian - wanted - by dealer - sale - craigslist
Tinker Repo
Halo Worth Animal Jam
Best Mechanics Near You - Brake Masters Auto Repair Shops
Ou Class Nav
Bolsa Feels Bad For Sancho's Loss.
Paris Immobilier - craigslist
Publix Near 12401 International Drive
San Jac Email Log In
The Monitor Recent Obituaries: All Of The Monitor's Recent Obituaries
Mercedes W204 Belt Diagram
Sf Bay Area Craigslist Com
Cbs Trade Value Chart Week 10
Plato's Closet Mansfield Ohio
Sitting Human Silhouette Demonologist
Powerball lottery winning numbers for Saturday, September 7. $112 million jackpot
آدرس جدید بند موویز
Closest 24 Hour Walmart
Case Funeral Home Obituaries
Crazy Balls 3D Racing . Online Games . BrightestGames.com
Blackwolf Run Pro Shop
Lovely Nails Prices (2024) – Salon Rates
Emulating Web Browser in a Dedicated Intermediary Box
Subdomain Finder
56X40X25Cm
Bbwcumdreams
Jimmy John's Near Me Open
Used Auto Parts in Houston 77013 | LKQ Pick Your Part
Billings City Landfill Hours
Amourdelavie
Otter Bustr
Lagrone Funeral Chapel & Crematory Obituaries
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 5983

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.