---
title: "Enum - NMAP"
date: 2024-06-25
draft: false
---

**sudo nmap -sS 192.168.50.149**

SYN scanning 'stealth' - sending a SYN, receiving a SYN-ACK, but never returning the ACK - meaning request isn't sent to the application layer. This used to be called 'stealth' because previously, applications wouldnt bother logging this traffic. this is no longer the case, and is likely logged

**nmap -sT 192.168.50.149**

Connect scan - TCP Connect Scanning - full TCP connection. takes much longer.

`We may occasionally need to perform a connect scan using **nmap**, such as when scanning via certain types of proxies. We can use the **-sT** option to start a connect scan.` 

**sudo nmap -sU 192.168.50.149**
UDP. `When performing a UDP scan,10 Nmap will use a combination of two different methods to determine if a port is open or closed. For most ports, it will use the standard "ICMP port unreachable" method described earlier by sending an empty packet to a given port. However, for common ports, such as port 161, which is used by SNMP, it will send a protocol-specific SNMP packet in an attempt to get a response from an application bound to that port. `

**nmap -sn 192.168.50.1-253**
Network Sweep - `the host discovery process consists of more than just sending an ICMP echo request. Nmap also sends a TCP SYN packet to port 443, a TCP ACK packet to port 80, and an ICMP timestamp request to verify whether a host is available.` 
Searching for live machines using the **grep** command on a standard nmap output can be cumbersome. Instead, let's use Nmap's "greppable" output parameter, **-oG**,

```bash
kali@kali:~$ nmap -v -sn 192.168.50.1-253 -oG ping-sweep.txt
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-10 03:21 EST
Initiating Ping Scan at 03:21
...
Read data files from: /usr/bin/../share/nmap
Nmap done: 254 IP addresses (13 hosts up) scanned in 3.74 seconds
...

kali@kali:~$ grep Up ping-sweep.txt | cut -d " " -f 2
192.168.50.6
192.168.50.8
192.168.50.9
...
```

**nmap -sT -A 192.168.50.14**
we can go further and identify services running on specific ports by inspecting service banners with **-A** parameter which also runs various OS and service enumeration scripts against the target. .


****

**NSE - nmap scripting engine https://nmap.org/book/nse.html
```bash
We can use the NSE14 to launch user-created scripts in order to automate various scanning tasks. These scripts perform a broad range of functions including DNS enumeration, brute force attacks, and even vulnerability identification. NSE scripts are located in the /usr/share/nmap/scripts directory.
```
NSE scripts are located in the **/usr/share/nmap/scripts** directory.
To view more information about a script, we can use the **--script-help** option, which displays a description of the script

****
```bash
If we are conducting initial network enumeration from a Windows laptop with no internet access, we are prevented from installing any extra tools that might help us, like the Windows Nmap version. In such a limited scenario, we are forced to pursue the 'living off the land' strategy we discussed earlier. Luckily, there are a few helpful built-in PowerShell functions we can use.

The Test-NetConnection15 function checks if an IP responds to ICMP and whether a specified TCP port on the target host is open.

For instance, from the Windows 11 client, we can verify if the SMB port 445 is open on a domain controller as follows.

PS C:\Users\student> Test-NetConnection -Port 445 192.168.50.151

ComputerName     : 192.168.50.151
RemoteAddress    : 192.168.50.151
RemotePort       : 445
InterfaceAlias   : Ethernet0
SourceAddress    : 192.168.50.152
TcpTestSucceeded : True
```

```bash
The returned value in the TcpTestSucceeded parameter indicates that port 445 is open.

We can further script the whole process in order to scan the first 1024 ports on the Domain Controller with the PowerShell one-liner shown below. To do so we need to instantiate a TcpClient Socket object as Test-NetConnection send additional traffic that is non needed for our purposes.

PS C:\Users\student> 1..1024 | % {echo ((New-Object Net.Sockets.TcpClient).Connect("192.168.50.151", $_)) "TCP port $_ is open"} 2>$null
TCP port 88 is open
...
```

---
SCRIPTS ARE LOCATED AT:
` NSE scripts are located in the **/usr/share/nmap/scripts**`


---
### UDP 
```bash
nmap -sU -p- --min-rate 10000 --open 10.10.11.248
```

---
