So, whenever you hear of the mean little hackers who hack websites you hear of "port scanning". I understand what it is (looking for all open ports / services on a remote machine), however that begs the question:

Why would an attacker want to know what ports are open?

The only reason I see for this is looking for services that may or may not have the default username and password OR a vulnerability or something.

But seeing as the odds for this are quite low, why do hackers perform port scans? Is it purely for the reason above?

  • 6
    Rattling door knobs to see what's there (identify services through fingerprinting) and if a lock has been applied (has it been secured) or if the lock is busted (is the service vulnerable). Why? It's easily scriptable, takes little effort. Commented Apr 17, 2016 at 2:28
  • 9
    Because closed ports are kinda hard to work with... Commented Apr 17, 2016 at 17:18

6 Answers 6

  • To run an exploit, an attacker needs a vulnerability.
  • To find a vulnerability, the attacker needs to fingerprint all services which run on the machine (find out which protocol they use, which programs implement them and preferably the versions of those programs).
  • To fingerprint a service, the attacker needs to know that there is one running on a publicly accessible port.
  • To find out which publicly accessible ports run services, the attacker needs to run a port scan.

As you see, a port scan is the first reconnaissance step an attacker performs before attacking a system.

  • 7
    The first reconnaissance step is the passive information gathering , port scanning or port grabbing are active information gathering and they came after the passive stage.., just saying
    – Sarastro
    Commented Apr 17, 2016 at 0:18
  • 9
    @Sarastro that does not have to be true at all - one never needs to perform passive recon - it can be useful, but is not a required step
    – schroeder
    Commented Apr 17, 2016 at 0:57
  • 2
    @Sarastro that's also true - there is no required "first step", which makes your initial comment moot. So, I'm completely confused as to what you are trying to say.
    – schroeder
    Commented Apr 17, 2016 at 3:11
  • 2
    @Sarastro How do you imagine it possible to passively learn something about a remote system without sending any packets to it?
    – kasperd
    Commented Apr 17, 2016 at 10:15
  • 1
    @Sarastro Indeed. That would only be possible if you had insider intel on the system, but since script kiddies running Nmap on random hosts don't usually know about your system, active information gathering is their first step.
    – A. Darwin
    Commented Apr 17, 2016 at 14:07

Consider that I wanna rob your home ... Then I would look up for a way to get into. But your home has door locks that allows only your local(family) to access it so I will search for some other like way(ports) windows(other open public ports) to get into.And try to get some data. If ports will be open for ssh/ftp they try to exploit them. Try uploading files or bruteforce.

  • 5
    It's actually more low level than that. A port scan is like finding a building with either doors or windows before you decide to see if you can unlock and open any of them. You see, in the weird world of the internet there are buildings (computers) that have no doors or windows (open ports).
    – slebetman
    Commented Apr 18, 2016 at 3:33

As Girish points out, a port scan is like casing a house. Its a a very low noise activity when done from the internet, because you'll see dozens of port scans a day. It also gleans a small amount of information about the state of your machine, and that lets them tailor the next layer of the attack even more.

It's also dirt cheap! Doing a port scan costs the attacker almost nothing, and sometimes you get lucky. In The Art of Intrusion, Kevin Mitnick gives examples of where such attacks do pay off in real life. In a simple system, its easy to simply lock down all of the ports. In a more complicated IT network, its harder to prove there is no business logic reason for an open port, and first rule of IT is "do not upset the business," so they may be left open. Mitnick's book gave the example of one case where there was a jury rigged serial connection accidentally exposed to the internet. The attacker presumes it was a one time cludge to solve an issue which was never dismantled after its use was no longer required. Years later, it was actually the attack vector found and exploited by the hackers.

There are situations where port scans are avoided. Advanced Persistent Threats (APT) tend to operate on the LAN. While port scans from the internet are a daily affair, port scans originating on the LAN are quite a lot "louder." Given that APTs value stealth, they will often avoid port scans that, in other circumstances, might just be random pot shots taken to see if one gets lucky.


Have you ever tried to perform network communications with a rock? How about a network router that has no electricity? It's pretty boring, because you get no response.

So attackers try to use the most common network protocols, like TCP and UDP, which use numbers that are called "port numbers", or "ports". (SCTP also uses ports.)

If a port is closed, then there's typically one of two results: a response that indicates "Connection refused", or no response whatsoever. Well, either of those results are far less interesting than an "open" port, which simply means that the attacker can get some other type of response when trying to interact with the targeted device.

Port scanning can refer to scanning the entire possible range of port numbers (0 through 65535), or simply scanning from a list of likely ports (e.g., 80, 443, 25, 22) to see what IP addresses respond. IP addresses that respond to a port number are likely targets for attackers to focus additional efforts to interact with, particularly if the port number which responds is the number of a commonly used standard (e.g., TCP port 80 is the most common port for HTTP).

(Although people can use a port for a different purpose than what is standard, that is quite uncommon to do, mostly because a lot of software doesn't handle alternate port numbers as easily. For instance, the standard for web browsers is to require adding a colon, and the port number, if a non-standard port is used. Using standard port numbers can eliminate the need for people to type that information.)

Scanning a port also has advantages over trying to perform more elaborate interactions, like many network attacks. The required time and bandwidth is much lower, so scanning can be done much more quickly than attacks that are more elaborate.


Hacking has a "discovery phase". During the discovery phase you discover as much information about your target as possible. Port scanning is just one aspect of discovery. Most software will run on their default port and thus knowing which ports are open gives you some information as to what the machine is running. If port 80 and 443 are open then you're likely dealing with some form of webserver. Then you discover what webserver is running and what software the webserver is running. An open port means that something is listening on that port and that you can communicate with whatever is running on that port which is a potential entry for a hacker. Trying default username & password combinations is just one part of hacking. Using vulnerabilities in software running on the traget is another part and to discover what software is running port scanning is a good first step. If you don't know which ports are open you don't know to which ports you can send malicous packets to.


Once an application has answered on a specific port, that application could then be targeted for exploits. For instance, nmap will fingerprint and report software and applications found running on a server, sometimes with version information. Outdated versions will have publicly-known vulnerabilities, which software such as metaspoit could target.

This guy explains it well. As an analogy, an open port is like an open door. Once one door is opened, the device in question can be used to target other devices in the same network. The linked document explains how the author got into the Hacking Team's internal network and leaked their data.

  • "An open port is an open door [and a device with such an open door] can be used to target other devices in the same network." is incorrect. Maybe you're mixing it up with port forwarding, where the router forwards a port to another device? What an open port (i.e. getting a response when trying to connect to a port on a given IP address) really means is that there is an application running there that an attacker can target. See other answers.
    – Luc
    Commented Nov 2, 2018 at 14:16
  • @Luc: I believe that the analogy is meant to assume that if there is a program that can receive input on a given port, then that program can be used (either via intended function or bugs) to escalate privilege.
    – dotancohen
    Commented Nov 2, 2018 at 14:46
  • I see the edit and that part is correct, but the old part about "open port == open door == can be used to target other devices in the same network" is still wrong. If that were true, then port forwarding would be a very dangerous thing, but it's not. Please don't spread myths.
    – Luc
    Commented Nov 11, 2018 at 12:27
  • @Luc: Thank you for your input. Though in a pedantic sense you are not wrong, for purposes of answering the OP and others like him I believe that the analogy is helpful to understand the situation. The audience of this answer is not security researchers, rather layman who've stumbled across terms and are looking to understand them. All analogies break down, but good analogies get the point across.
    – dotancohen
    Commented Nov 11, 2018 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .