Cheat sheet for nmap
Scanning the target to get information
nmap -sn <Target Ip address>
-sS
flag used for stealth scan
Put up an decoy ip address which nmap uses to duplicate packets with source as the decoy IP and send it to server making the server learn that the ip addresses are coming >
sudo nmap -sS -D <Any decoy Ip address <Target ip address>
nmap -sS -D RND:10 <Target>
Can be used to spoof the ip address of our machine
oA
: Output in the three major formats at onceoG
: Greppable format outputscript=vuln
: executes all the vulnerable scripts
- TCP Connect Scans
(-sT)
- SYN "Half-open" Scans
(-sS)
- UDP Scans
(-sU)
- TCP Null Scans
(-sN)
- TCP FIN Scans
(-sF)
- TCP Xmas Scans
(-sX)
- TCP scan (-sT)
- SYN, SYN/ACK, ACK handhake happens and called complete handshake
- SYN scan (-sS)
- All scan only syn happens and [RST]. flag is sent
- NULL scan (-sN)
- Null scan, no flag is set . once the detection happens, [RST, ACK] is sent.
- Not accurate enough
- FIN scan (-sF)
- FIN scans (-sF) work in an almost identical fashion; however, instead of sending a completely empty packet, a request is sent with the FIN flag (usually used to gracefully close an active connection). Once again, Nmap expects a RST if the port is closed.
- Xmas (-sX)
- As with the other two scans in this class, Xmas scans (-sX) send a malformed TCP packet and expects a RST response for closed ports. It's referred to as an xmas scan as the flags that it sets (PSH, URG and FIN) give it the appearance of a blinking christmas tree when viewed as a packet capture in Wireshark.
- What networking constructs are used to direct traffic to the right application on a server? Ports
- How many of these are available on any network-enabled computer? 65535
- [Research] How many of these are considered "well-known"? (These are the "standard" numbers mentioned in the task) 1024
- What is the first switch listed in the help menu for a 'Syn Scan' (more on this later!)? -sS
- Which switch would you use for a "UDP scan"? -sU
- If you wanted to detect which operating system the target is running on, which switch would you use? -O
- -sV
- -v
- -vv
- -oA
- -oN
- -oG
- -A
- -T5
- -p 80
- -p 1000-1500
- -p-
- --script
- --script=vuln
- RFC 9293
- RST
- Xmas
- firewall evasion
- Microsoft Windows
Nmap sending ICMP packets to the possible hosts and detecting whether the host is up with that ip or not is called ping sweep (-sn)
nmap -sn 192.168.0.0/24
- ping -sn 192.16.0.0/16
To show the help menu of the script, use the following
nmap --script-help ftp-anon.nse
Nmap script engine has some catagories in which the scripts are devided and each catagories has a meaning. Some of the catogories are here. safe:- Won't affect the target intrusive:- Not safe: likely to affect the target vuln:- Scan for vulnerabilities exploit:- Attempt to exploit a vulnerability auth:- Attempt to bypass authentication for running services (e.g. Log into an FTP server anonymously) brute:- Attempt to bruteforce credentials for running services discovery:- Attempt to query running services for further information about the network (e.g. query an SNMP server).
- If we Execute the following command, using nmap script flag,
nmap --script=vuln <target>
Now the NSE
Executes all the scripts that are unuder a specific catagory that is, vuln
over the target.
- We can run a specific script specifying the script name.
--script=<script-name>
- we can also execute multple number of scripts using the comma seperated naming.
--script=<script 1>,<script 2>
- Script arguements. Some scripts require arguments (for example, credentials, if they're exploiting an authenticated vulnerability). These can be given with the --script-args Nmap switch. An example of this would be with the http-put script (used to upload files using the PUT method). This takes two arguments: the URL to upload the file to, and the file's location on disk Example:
nmap -p 80 --script http-put --script-args http-put.url='/dav/shell.php',http-put.file='./shell.php'
Note that the arguments are separated by commas, and connected to the corresponding script with periods (i.e. <script-name>.<argument>
).
- maxlist
We have a database list of scripts where the script name with its catogories are stored.
cat /usr/share/nmap/scripts/script.db | grep safe
script.db
has is the name of that nmap script database.
- smb-os-discovery.nse
- smb-brute
- ICMP
- --data-length
- N
- 999
- no -respons
- 5
- y