How to scan networks with NMAP

Search for a command to run...

No comments yet. Be the first to comment.
In this series, I am going to be talking about the concepts and tools for cyber security from beginner to advanced user.
John the Ripper is one of the most loved and versatile hash password-cracking tools out their. It combines speed, ease of use and reliability. But first of what is a hash? What is a hash? Hashing is taking a data of any length and turning it into a f...
During in the process of reverse engineering binaries, a common problem arises. How do I reverse engineer stripped binaries? There are no symbols to break on, offsets change, scripts don't work, and you ask yourself why am I doing this? Luckily there...

When I was learning how to tackle pwn challenges in CTFs, I had a tough time finding a single, clear guide that could show me the ropes of actually carrying out these exploits. That's why I decided to put together a complete guide that covers everyth...

Using python to capture and project data

Intro This is a write-up for PicoCTF 2022: Buffer Overflow 1. This is one of my favourite challenges to do. I recommend solving it for yourself before you read this write-up. What is a Buffer Overflow? Before we get started we need to first know what...

What is a BadUSB? A BadUSB is a USB device that acts as a keyboard and injects preprogrammed keystrokes into a computer. A BadUSB is Indistinguishable from a generic keyboard, making it near impossible to detect and patch. You can setup reverse shell...

Nmap, short for Network Mapper, is one of the most commonly used ethical hacking tools used to scan for any information about networks; like open ports, open services and basic vulnerability searching. When it comes to hacking into networks, knowledge is power. Nmap gives you a lot of it. It is also a very popular program due to its ease of use and clean installation along with its standalone scripts.
When you have been given an IP of a network you need to know what services are running on the machine. You thus, need to know which ports are open to connect to that service. Ports are necessary for making multiple network requests or having multiple services available. But there are 65,535 ports on any given machine. This is when Nmap comes in. The main uses of Nmap according to their official page is:
-sT)For anyone that doesn't know what the TCP protocol is, it is a connection-based protocol. In basic terms, before you send any data between two devices you first must make a stable connection. To form this connection, you must do something called a "three-way handshake".
When you first make a connection to a server, you must first send an SYN flag. The server will then acknowledge this packet and respond with an SYN/ACK flag. Finally, our computer will reply with an ACK flag. Now you communicate whatever you want to. In plain English, it sounds like this.

This type of scan is slower and is generally easier to be detected by intrusion detection systems. This scan is the default without root access scan type.
-sS)The SYN scan commonly referred to as "Half-open" scans, or "Stealth" scans, is similar to the TCP but it does not complete the full "three-way handshake".
The first two parts of the TCP and SYN scan are the exact same. You first send a SYN flag. The server will then acknowledge this connection and send back an SYN/ACK flag. This is when it differs. Now you send an RST back. An RST flag means this connection should be immediately terminated.

This is more of a "stealthy" scan than the TCP scan and will fool old intrusion detection systems. This scan requires root permission as it needs to be able to create raw packets, this is reserved for root users.
-sU)UDP is a stateless protocol. What this means is, that it doesn't do a back-and-forth handshake like TCP. UDP connections rely on sending packets to a target port and hoping that they make it and none of them goes missing. While this is helpful for connections that aim for speed over quality it is not the best for scanning ports due to the lack of acknowledgment. This makes UDP harder and much slower to scan.
-O)Nmap can also provide information about the operating system using TCP/IP fingerprinting. This is also enabled by default with the aggressive switch (-A).
-sV)Enables version detection.
-A)Aggressive scanning enables Os detection, version detection, script scanning, and traceroute.
-T<0-5>)The switch -T sets timing and aggressiveness (higher is faster). -T5 would be an incredibly fast scan that assumes you are on an extremely fast and reliable network. -T0 would be for evading intrusion detection system. This scan would be an incredibly long time and would not give too much information.
-p)By default, if you don't have this flag you will scan the top 1000 common ports.
> nmap -p 973 [MACHINE IP]
nmap -sV -p 22,53,110,143,4564 198.116.0-255.1-12 [MACHINE IP]
nmap -p 76–973 [MACHINE IP]
> nmap -p- [MACHINE IP]
--top-ports flag to specify the top n ports.> nmap --top-ports 10 scanme.nmap.org
-sC)I will not get too much into this but if you use -sC to scan ports, then it will scan with default NSE scripts that are considered useful for discovery.
If I want a quick and dirty scan on a network to find the service, Os and basic open ports.
nmap -sC -sV -T4 [MACHINE IP]
If you want to launch a stealth scan on a network and try to determine the Operating System and services.
nmap -sV -p 22,53,110,143,4564 198.116.0-255.1-127
If you want to launch a TCP scan on a machine.
nmap -sT -p 22,53,110,143,4564 198.116.231.43
Nmap is an incredibly useful program for anyone who deals with networks daily. I am barely showing you the top of the iceberg. There is a full dedicated scripting engine, quite a few more types of scans and hundreds of other options. I highly recommend NMAP
I recommend you check out the documentation of Nmap here.
https://www.networkworld.com/article/3296740/what-is-nmap-why-you-need-this-network-mapper.html
https://www.linuxadictos.com/en/Nmap.html
https://linux.die.net/man/1/nmap
https://tryhackme.com/room/furthernmap