Scan Your Network for Vulnerabilities With Nmap
Tags: security, networks
Published: 2019-04-14 04:29:30

---
title: Scan Your Network for Vulnerabilities With Nmap
published: true
description: A guide to using Nmap to scan networks and discover vulnerabilities.
tags: security, networks
canonical_url: https://www.explainhownow.com/2019/scan-networks-with-nmap/
cover_image: https://thepracticaldev.s3.amazonaws.com/i/vvjzeceeqo5st9mk4g0t.png
---

_Nmap is a free, open source tool for running scans on networks and discovering potential vulnerabilities. If you're a pentester, Nmap is a crucial part of your reconnaissance for understanding the landscape of what you're working with. As a developer or sysadmin, you should absolutely learn how to use Nmap to scan your networks! It gives you a "black box" view of what's going on in your network and allows you to view it the way hackers do. So if you can spot any issues - chances are, someone malicious already has!_

_Note: if you're a web developer hosting your website on a third-party service, you might not have permission to do networks scans. [AWS allows customers to carry out penetration tests](https://aws.amazon.com/security/penetration-testing/), but other hosters might not. Make sure you check first!_<br><br>
_Target audience:_
<div>
* _Developers_
* _Sysadmins_
* _Penetration testers_
</div><br>


<h3>Installing Nmap</h3>
Nmap is pretty easy to install on Windows and MacOS - check out the [official download page](https://nmap.org/download.html). I recommend using Zenmap, the GUI that comes with the Windows and MacOS download. Zenmap looks like this:

![zenmap preview](https://www.explainhownow.com/assets/images/zenmap_1.png)

If you're on Ubuntu or similar, you can instead run something like this: ```sudo apt-get install nmap```<br>

<h3>Scanning for Ports With Nmap</h3>
Nmap is a powerfully versatile tool with many options. So many that the people behind Nmap managed to [write a 468-page long book on it](https://nmap.org/book/).

I'll go over the basic usage of Nmap first, and then we can get into some of the fancier options. I'll use Yahoo.com at my target host since they've got an active bug bounty program and won't arrest me.

Here's a basic scan:```nmap -sS yahoo.com```

![zenmap scan](https://www.explainhownow.com/assets/images/zenmap_2.png)

The -sS flag performs a SYN scan, scanning many ports without ever completing a TCP connection. This is a great option if you don't want to be [too noisy](https://www.google.com/search?client=firefox-b-d&q=give+the+sysadmin+a+heart+attack). This shows us there are two open ports, 80 and 443 (for HTTP and HTTPS). Pretty much what we'd expect!<br><br>

Let's add another flag to this, -O.```nmap -sS -O yahoo.com```

![zenmap scan](https://www.explainhownow.com/assets/images/zenmap_3.png)

This time, we see the ports and also some guesses of what OS the server might be running. Knowing what OS is running on a server is an important part of reconnaissance since some vulnerabilities are OS-specific. For example, OpenSSH 5.3 is *ancient* and has exploits publicly available, and if you see it on a server, chances are it's vulnerable. The most notable exception to this is if the server runs Redhat OS, since Redhat has patched around OpenSSH 5.3's issues.

Side note: the -O flag is slow, so drop it from your scan if you don't need it.<br><br>

Let's check out another flag, -sV.```nmap -sS -O -sV yahoo.com```

Results:
```
PORT    STATE  SERVICE        VERSION
80/tcp  open   http-proxy     Apache Traffic Server
113/tcp closed ident
443/tcp open   ssl/http-proxy Apache Traffic Server
```

This time, we see the version of what software is running on the ports! This is crucial for discovering vulnerabilities since older software tends to have more exploits available. Try also throwing in the -v flag, which gives you more verbose information about the output.<br><br>

Next, let's try specifying what ports we want to check for instead of just doing a general scan. ```nmap -sS -sV -v -p 22 yahoo.com```

Results:
```
PORT   STATE    SERVICE VERSION
22/tcp filtered ssh
```

We can see that port 22 is filtered on Yahoo, which means we'd probably have a hard time attacking it. You can specify a range of ports by replacing _-p 22_ with something like _-p 1-165535_. The flag that I usually use is _--top-ports 1000_, which as the name implies, scans the most common 1000 ports. 

Putting it all together, this is what I'll usually run to get an overall look of the host:``` nmap -sS -sV -O -v --top-ports 1000 yahoo.com```

Here, we're doing a sneaky scan (sS), version detection (sV), operating system detection (O), verbose output (v), and scanning the top 1000 ports. 

Now you know the basics of port scanning with Nmap!<br><br>

<h3>Going Further</h3>


<h4>Scanning IP Ranges</h4>
Scanning IP ranges instead of a single host is useful if you're testing on your own servers. I don't recommend doing this on servers you don't own, since you might miss and scan someone who's not your target. 

Nmap uses CIDR notation, so you can just run something like this:```nmap -sV --top-ports 1000 192.168.1.0/24```

<h4>Timing</h4>
Nmap has five timing options, officially named: paranoid, sneaky, polite, normal, aggressive, insane. You can specify this with the T flag, e.g. -T0 for paranoid and -T5 for insane. By default, Nmap runs on "normal" mode, so -T3 does nothing. I'll usually run my scans on -T4 if I know it won't upset the client.<br><br>

<h4>File Output</h4>
If you want to save Nmap's results to a file for later, add the *-oN filename* flag. _-oX filename_ outputs results in XML format, which is useful if you've got scripts that process Nmap output.<br><br>

<h4>Scripts</h4>
Nmap comes with some scripts you can enable! I don't normally use them since I prefer other tools, but [here's a good guide explaining them](https://null-byte.wonderhowto.com/how-to/use-nmap-7-discover-vulnerabilities-launch-dos-attacks-and-more-0168788/).<br><br>

<h3>The Fun Part: Exploitation</h3>

![zenmap scan](https://www.explainhownow.com/assets/images/security_updates.png)

Now that we know what's running on a host, we want to exploit it.

Attacking networks is an entire topic of its own, but I'll cover some of the basics here!

<h4>Port 22: SSH</h4>
If the network has port 22 open and ssh running on it, that's a good starting point. If you can successfully manage to log in through SSH, well... that's a bad sign for the server.

First off, check the version of SSH that's running (recall that you can do this with the -sV flag). Google that version and chuck in the keyword "exploit". If it's an older version of SSH, you have good chances of finding publicly available exploits that you can just copy and run.

If that doesn't work, you still have a chance of getting a login. Go back to your terminal and run something like this:```ssh remote_username@remote_host```

"remote_username" can be any number of things, but the common names I'd check for are admin and root. Try [some common passwords](https://www.esquire.com/lifestyle/a25570880/top-passwords-2018/), and also try some company-specific things (does the network admin have a dog? kids? try their names). You can also try to run a [bruteforce](https://www.offensive-security.com/metasploit-unleashed/scanner-ssh-auxiliary-modules/) scan, but that's out of the scope of this post.<br><br>

<h4>Everything Else</h4>
SSH is a special case because of the severity of compromise possible if you get a login, but other services can be equally vulnerable.

Once you've run an Nmap scan with version detection enabled, see if anything other than just port 80 and 443 shows up. Google the name of any services you find and figure out what they do, and if any exploits are publicly available. You know how developers joke about ripping all their work off StackOverflow? Pentesters pretty much do the same but with [CVE (Common Vulnerabilities and Exposures) databases](https://www.cvedetails.com/). 

Once you've run out of services to Google public exploits for, you can double back and check if any of the services have login portals. For example, if the service is webmail, you can try logging in to it with netcat by trying out default usernames and passwords for that service.<br><br>

<h3>How do I fix my vulnerable server?</h3>

[That's not my department.](https://youtu.be/5V7me25aNtI?t=52)<br><br>


Check out these posts though:
<div>
* [How to Protect Your Server From Hackers, by 
Vitaliy Kolesov](https://dev.to/vkolesov/how-to-protect-your-server-from-hackers-4j6l)
* [7 Security Measures to Protect Your Servers](https://www.digitalocean.com/community/tutorials/7-security-measures-to-protect-your-servers)
* [Securing Amazon EC2 Instances](https://aws.amazon.com/answers/security/aws-securing-ec2-instances/)</div><br>


<h3>Keep in touch!</h3>
Like my posts? [Check out my Twitter!](https://twitter.com/kathyra_) I make bad jokes, reduce important social issues to juvenile satire, and occasionally rant about tech.

Want just the tech? [Subscribe to my email list to get notified of when new posts are released!](http://eepurl.com/gj1EpH)


_This post was originally published on [explainhownow.com](https://www.explainhownow.com/)_