Top 30 Nmap Command Examples
Top 30 Nmap Command Examples
Nmap is short for Network Mapper. It is an open source security tool for network exploration, security scanning and auditing. However, nmap command comes with lots of options that can make the utility more robust and difficult to follow for new users. The purpose of this post is to introduce a user to the nmap command line tool to scan a host and/or network, so to find out the possible vulnerable points in the hosts. You will also learn how to use Nmap for offensive and defensive purposes.
[1]
nmap in action
what type of packet filters/firewalls are in use, and dozens of other characteristics. While Nmap is commonly used for security audits, many systems and network administrators find it useful for routine tasks such as network inventory, managing service upgrade schedules, and monitoring host or service uptime. It was originally written by Gordon Lyon and it can answer the following questions easily: 1. 2. 3. 4. 5. 6. 7. What computers did you find running on the local network? What IP addresses did you find running on the local network? What is the operating system of your target machine? Find out what ports are open on the machine that you just scanned? Find out if the system is infected with malware or virus. Search for unauthorized servers or network service on your network. Find and remove computers which don't meet the organization's minimum level of security.
Sample outputs:
Page 2 of 12
[4]
#9: Scan a network and find out which servers and devices are up and running
This is known as host discovery or ping scan: nmap -sP 192.168.1.0/24 Sample outputs: Host 192.168.1.1 is up (0.00035s latency). MAC Address: BC:AE:C5:C3:16:93 (Unknown) Host 192.168.1.2 is up (0.0038s latency). MAC Address: 74:44:01:40:57:FB (Unknown) Host 192.168.1.5 is up. Host nas03 (192.168.1.12) is up (0.0091s latency). MAC Address: 00:11:32:11:15:FC (Synology Incorporated) Nmap done: 256 IP addresses (4 hosts up) scanned in 2.80 second
Page 4 of 12
Page 5 of 12
Sample outputs: Starting Nmap 5.00 ( http://nmap.org ) at 2012-11-27 01:23 IST Interesting ports on 192.168.1.1: PORT STATE SERVICE 21/tcp closed ftp 22/tcp open ssh 23/tcp closed telnet 25/tcp closed smtp 80/tcp open http 110/tcp closed pop3 139/tcp closed netbios-ssn 443/tcp closed https 445/tcp closed microsoft-ds 3389/tcp closed ms-term-serv MAC Address: BC:AE:C5:C3:16:93 (Unknown) Nmap done: 1 IP address (1 host up) scanned in 0.51 seconds
#16: The fastest way to scan all your devices/computers for open ports ever
nmap -T5 192.168.1.0/24
nmap -O 192.168.1.1 nmap -O --osscan-guess 192.168.1.1 nmap -v -O --osscan-guess 192.168.1.1 Sample outputs:
Starting Nmap 5.00 ( http://nmap.org ) at 2012-11-27 01:29 IST NSE: Loaded 0 scripts for scanning. Initiating ARP Ping Scan at 01:29 Scanning 192.168.1.1 [1 port] Completed ARP Ping Scan at 01:29, 0.01s elapsed (1 total hosts) Initiating Parallel DNS resolution of 1 host. at 01:29 Completed Parallel DNS resolution of 1 host. at 01:29, 0.22s elapsed Initiating SYN Stealth Scan at 01:29 Scanning 192.168.1.1 [1000 ports] Discovered open port 80/tcp on 192.168.1.1 Discovered open port 22/tcp on 192.168.1.1 Completed SYN Stealth Scan at 01:29, 0.16s elapsed (1000 total ports) Initiating OS detection (try #1) against 192.168.1.1 Retrying OS detection (try #2) against 192.168.1.1 Retrying OS detection (try #3) against 192.168.1.1 Retrying OS detection (try #4) against 192.168.1.1 Retrying OS detection (try #5) against 192.168.1.1 Host 192.168.1.1 is up (0.00049s latency). Interesting ports on 192.168.1.1: Not shown: 998 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http MAC Address: BC:AE:C5:C3:16:93 (Unknown) Device type: WAP|general purpose|router|printer|broadband router Running (JUST GUESSING) : Linksys Linux 2.4.X (95%), Linux 2.4.X|2.6.X (94%), MikroTik RouterOS 3.X Aggressive OS guesses: OpenWrt White Russian 0.9 (Linux 2.4.30) (95%), OpenWrt 0.9 - 7.09 (Linux 2.4 No exact OS matches for host (If you know what OS is running on it, see http://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=5.00%D=11/27%OT=22%CT=1%CU=30609%PV=Y%DS=1%G=Y%M=BCAEC5%TM=50B3CA OS:4B%P=x86_64-unknown-linux-gnu)SEQ(SP=C8%GCD=1%ISR=CB%TI=Z%CI=Z%II=I%TS=7
nixCraft is GIT UL++++ W+++ C++++ M+ e+++ dPage 6 of 12
OS:)OPS(O1=M2300ST11NW2%O2=M2300ST11NW2%O3=M2300NNT11NW2%O4=M2300ST11NW2%O5 OS:=M2300ST11NW2%O6=M2300ST11)WIN(W1=45E8%W2=45E8%W3=45E8%W4=45E8%W5=45E8%W OS:6=45E8)ECN(R=Y%DF=Y%T=40%W=4600%O=M2300NNSNW2%CC=N%Q=)T1(R=Y%DF=Y%T=40%S OS:=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%R OS:D=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W= OS:0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=N)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID OS:=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S) Uptime guess: 12.990 days (since Wed Nov 14 01:44:40 2012) Network Distance: 1 hop TCP Sequence Prediction: Difficulty=200 (Good luck!) IP ID Sequence Generation: All zeros Read data files from: /usr/share/nmap OS detection performed. Please report any incorrect results at http://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 12.38 seconds Raw packets sent: 1126 (53.832KB) | Rcvd: 1066 (46.100KB)
See also: Fingerprinting a web-server and a dns server command line tools for more information.
#19: Scan a host using TCP ACK (PA) and TCP Syn (PS) ping
If firewall is blocking standard ICMP pings, try the following host discovery methods: nmap nmap nmap nmap -PS -PS -PA -PA 192.168.1.1 80,21,443 192.168.1.1 192.168.1.1 80,21,200-512 192.168.1.1
#22: Find out the most commonly used TCP ports using TCP SYN Scan
### Stealthy scan ### nmap -sS 192.168.1.1 ### Find out the most commonly used TCP ports using ### OS Fingerprinting ### nmap -sT 192.168.1.1 TCP connect scan (warning: no stealth scan
Page 7 of 12
### Find out the most commonly used TCP ports using TCP ACK scan nmap -sA 192.168.1.1 ### Find out the most commonly used TCP ports using TCP Window scan nmap -sW 192.168.1.1 ### Find out the most commonly used TCP ports using TCP Maimon scan nmap -sM 192.168.1.1
Starting Nmap 5.00 ( http://nmap.org ) at 2012-11-27 00:52 IST Stats: 0:05:29 elapsed; 0 hosts completed (1 up), 1 undergoing UDP Scan UDP Scan Timing: About 32.49% done; ETC: 01:09 (0:11:26 remaining) Interesting ports on nas03 (192.168.1.12): Not shown: 995 closed ports PORT STATE SERVICE 111/udp open|filtered rpcbind 123/udp open|filtered ntp 161/udp open|filtered snmp 2049/udp open|filtered nfs 5353/udp open|filtered zeroconf MAC Address: 00:11:32:11:15:FC (Synology Incorporated) Nmap done: 1 IP address (1 host up) scanned in 1099.55 seconds
## TCP Null Scan to fool a firewall to generate a response ## ## Does not set any bits (TCP flag header is 0) ## nmap -sN 192.168.1.254 ## TCP Fin scan to check firewall ## ## Sets just the TCP FIN bit ## nmap -sF 192.168.1.254 ## TCP Xmas scan to check firewall ## ## Sets the FIN, PSH, and URG flags, lighting the packet up like a Christmas tree ## nmap -sX 192.168.1.254
See how to block Xmas packkets, syn-floods and other conman attacks [10] with iptables.
nixCraft is GIT UL++++ W+++ C++++ M+ e+++ dPage 8 of 12
them and which were innocent decoys: nmap -n -Ddecoy-ip1,decoy-ip2,your-own-ip,decoy-ip3,decoy-ip4 remote-host-ip nmap -n -D192.168.1.5,10.5.1.2,172.1.2.4,3.4.2.1 192.168.1.5
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: zenmap 0 upgraded, 1 newly installed, 0 to remove and 11 not upgraded. Need to get 616 kB of archives. After this operation, 1,827 kB of additional disk space will be used. Get:1 http://debian.osuosl.org/debian/ squeeze/main zenmap amd64 5.00-3 [616 kB] Fetched 616 kB in 3s (199 kB/s) Selecting previously deselected package zenmap. (Reading database ... 281105 files and directories currently installed.) Unpacking zenmap (from .../zenmap_5.00-3_amd64.deb) ... Processing triggers for desktop-file-utils ... Processing triggers for gnome-menus ... Processing triggers for man-db ... Setting up zenmap (5.00-3) ... Processing triggers for python-central ... Type the following command to start zenmap: $ sudo zenmap Sample outputs
[14]
nixCraft is GIT UL++++ W+++ C++++ M+ e+++ dPage 10 of 12
The official Nmap project guide to network discovery and security Scanning [19]. The official Nmap project [20] home page. The nmap command has many more options, please go through man page or the documentation for more information. What are some of your favorite nmap command-line tricks? Share your favorite tips, tricks, and advice in the comments below.
Important Message from nixCraft: 4000+ howtos and counting! Want to read more Linux / UNIX howtos, tips and tricks? We request you to sign up for the following to ensure that you make the most from our guides / howtos: 1. RSS feed for nixCraft - Get intimated about our new howtos / faqs as soon as it is released. 2. Daily email newsletter or weekly newsletter - Get intimated about our new howtos / faqs as soon as it is released via email.
Article printed from nixCraft: Linux Tips, Hacks, Tutorials, And Ideas In Blog Format: http://www.cyberciti.biz/ URL to article: http://www.cyberciti.biz/networking/nmap-command-examples-tutorials/ URLs in this post: [1] Image: http://www.cyberciti.biz/networking/nmap-command-examples-tutorials/attachment/welcome-nmap/ [2] fully patched server with firewall: http://www.cyberciti.biz/tips/linux-iptables-examples.html [3] Debian / Ubuntu Linux: Install nmap Software For Scanning Network: http://www.cyberciti.biz/faq/install-nmap-debianubuntu-server-desktop-system/ [4] CentOS / RHEL: Install nmap Network Security Scanner: http://www.cyberciti.biz/faq/howto-install-nmap-on-centosrhel-redhat-enterprise-linux/ [5] OpenBSD: Install nmap Network Security Scanner: http://www.cyberciti.biz/faq/installing-nmap-network-portscanner-under-openbsd-using-pkg_add/ [6] ip command: http://www.cyberciti.biz/faq/howto-linux-configuring-default-route-with-ipcommand/ [7] route command: http://www.cyberciti.biz/faq/what-is-a-routing-table/ [8] netstat command: http://www.cyberciti.biz/faq/linux-unix-open-ports/ [9] identify a remote host apps and OS using the -O option: http://www.cyberciti.biz/faq/identify-remote-host-by-unixlinux-command/ [10] how to block Xmas packkets, syn-floods and other conman attacks: http://www.cyberciti.biz/tips/linux-iptables-10how-to-block-common-attack.html [11] decoys are scanning the target network too: http://www.cyberciti.biz/tips/nmap-hide-ipaddress-with-decoy-idealscan.html [12] zenmap the official network mapper: http://nmap.org/zenmap/ [13] apt-get command: http://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html [14] Image: http://www.cyberciti.biz/networking/nmap-command-examples-tutorials/attachment/nmap-usageexamples-output/ [15] How to use psad tool to detect and block port scan attacks in real time: http://www.cyberciti.biz/faq/linux-detect-portscan-attacks/ [16] Debian / Ubuntu Linux: Install and Configure Shoreline Firewall (Shorewall): http://www.cyberciti.biz/faq/debianubuntu-linux-shorewall-firewall-configuration/
nixCraft is GIT UL++++ W+++ C++++ M+ e+++ dPage 11 of 12
[17] CentOS / Redhat Iptables Firewall Configuration Tutorial: http://www.cyberciti.biz/faq/rhel-fedorta-linux-iptablesfirewall-configuration-tutorial/ [18] 20 Linux Server Hardening Security Tips: http://www.cyberciti.biz/tips/linux-security.html [19] The official Nmap project guide to network discovery and security Scanning: http://nmap.org/book/toc.html [20] The official Nmap project: http://nmap.org/
Copyrighted material Copyright 2004-2013 nixCraft. All rights reserved. This print / pdf version is for personal non-commercial use only. Unless otherwise indicated, the documents and graphics stored on this Web server, www.cyberciti.biz, are copyrighted. Links to these documents are permitted and encouraged. No copies may be made without permission. More details - http://www.cyberciti.biz/tips/copyright
Page 12 of 12