Network Scanning
Live Host Discovery¶
Same subnet as NIC - ARP | Coverage: high, Accuracy: high
sudo nmap -sn -PR -n -T4 <cidr> -oA nmap_live_hosts_arp
Reasonably quick | Coverage: high, Accuracy: high
sudo nmap -sn -n -T4 --source-port 53 -PE -PP -PS7,9,13,21-23,25-26,37,53,79-81,88,106,110-111,113,119,135,139,143-144,179,199,389,427,443-445,465,513-515,543-544,548,554,587,631,646,873,990,993,995,1025-1029,1110,1433,1720,1723,1755,1900,2000-2001,2049,2121,2717,3000,3128,3306,3389,3986,4899,5000,5009,5051,5060,5101,5190,5357,5432,5631,5666,5800,5900-5901,6000-6002,6646,7070,8000,8008-8009,8080-8081,8443,8888,9000-9001,9090,9100,9102,9999-10001,32768,49152-49157 -PU53,67-69,111,123,135,137-139,161-162,445,500,514,520,631,996-999,1434,1701,1900,3283,4500,5353,49152-49157 --max-retries 2 --host-timeout 180s --min-parallelism 100 -vv -iL scope.txt -oA nmap_live_hosts
Balanced discovery | Coverage: medium, Accuracy: high
sudo nmap -sn -n -T4 -PE -PS22,80,135,389,443,445,3389,5985 -PA80 -PU53,161 --min-rate 2000 --max-rtt-timeout 1s --max-retries 2 --reason --stats-every 30s -iL ../scope.lst --excludefile discovery_resume_exclude.lst -oA nmap_live_hosts_balanced
Very quick | Coverage: medium, Accuracy: low
sudo nmap -sn -n -T5 --source-port 53 -PE -PP -PS22,80,443,445,3389,8080 -PA80,443 -PU53,161,40125 --min-rate 2000 --max-rtt-timeout 80ms --max-retries 0 --reason --stats-every 30s -v -iL scope.txt --excludefile exclude.txt -oA nmap_live_hosts_fast
Service Scan¶
Very quick TCP scan, top 100 ports
sudo nmap -sS -Pn -n -T5 --top-ports 100 --max-rtt-timeout 200ms --max-retries 0 --min-rate 2000 --min-hostgroup 256 --open --reason --stats-every 30s -v -iL live_hosts.txt --excludefile exclude.txt -oA nmap_fast_tcp
Very quick UDP scan, top 20 ports
sudo nmap -sU -Pn -n -T5 --top-ports 20 --max-rtt-timeout 200ms --max-retries 0 --min-rate 2000 --min-hostgroup 256 --open --reason --stats-every 30s -v -iL live_hosts.txt --excludefile exclude.txt -oA nmap_fast_udp
Common TCP
sudo nmap -sS -sV --version-light -Pn -n -T4 --top-ports 200 --open -iL scope.txt -oA nmap_quick_tcp
Common UDP
sudo nmap -sU -sV --version-intensity 0 -Pn -n -T3 -p 53,67-68,69,88,111,123,137-138,161-162,389,464,500,520,631,1434,1701,1812-1813,1900,2049,3389,3702,4500,5004-5005,5060,5353,5355,11211,4789 --max-retries 2 --open -iL scope.txt -oA nmap_comp_udp
All TCP + Common UDP
sudo nmap -sS -sU -sV --version-intensity 0 -Pn -n -T4 -p T:1-65535,U:53,67-69,111,123,135,137-139,161-162,445,500,514,520,631,996-999,1434,1701,1900,3283,4500,5353,49152-49154 --max-retries 2 --open -iL scope.txt -oA nmap_comp
All TCP
sudo nmap -sS -sV --version-intensity 0 -Pn -n -T4 -p- --max-retries 2 --open -iL scope.txt -oA nmap_comp_tcp
Web Service Scanning¶
https://github.com/projectdiscovery/httpx
Scan list of host:port for web services
httpx-toolkit -l host_port.lst -no-fallback -stats -si 10 -sc -title -cl -location -server -fr -ip | tee httpx.out
host_port.lstmust contain<ip>:<port>.
-no-fallbackwill attempt http and https for each<ip>:<port>combo
Extract all detected web servers into a list of URLs
cat httpx.out | awk '{print $1}' > web_servers_with_proto.lst
Output (web_servers_with_proto.lst):
http://<host>:<port>https://<host>:<port>
Gather screenshots of web services
gowitness scan file -f web_servers_with_proto.lst --screenshot-path gowitness_screenshots --log-scan-errors -D
Input:
[http(s)://]<host>:<port>, one per line.
Nmap XML extraction via XMLStarlet¶
Replace the XML filename with your Nmap scan's XML output file.
Live IPv4 addresses
xmlstarlet sel -t -m "//host[status/@state='up']/address[@addrtype='ipv4']" -v "@addr" -n nmap_live_hosts.xml
IPv4 addresses with at least one open port
xmlstarlet sel -t -m "//host[ports/port/state/@state='open']/address[@addrtype='ipv4']" -v "@addr" -n nmap_comp.xml
IPv4 addresses with TCP port 445 open
xmlstarlet sel -t -m "//host[ports/port[@protocol='tcp' and @portid='445' and state/@state='open']]/address[@addrtype='ipv4']" -v "@addr" -n nmap_comp.xml
Live hosts as original domains or IPv4 addresses
xmlstarlet sel -t -m "//host[status/@state='up']" -i "hostnames/hostname[@type='user']" -v "hostnames/hostname[@type='user'][1]/@name" -n -b -i "not(hostnames/hostname[@type='user'])" -v "address[@addrtype='ipv4']/@addr" -n nmap_live_hosts.xml
Open TCP ports as a comma-separated list
xmlstarlet sel -t -m "//port[@protocol='tcp'][state/@state='open']" -v @portid -n nmap_comp.xml | sort -n | uniq | paste -sd, - > open_tcp.lst
Open or open|filtered UDP ports as a comma-separated list
xmlstarlet sel -t -m "//port[@protocol='udp'][state/@state='open' or state/@state='open|filtered']" -v @portid -n nmap_comp.xml | sort -n | uniq | paste -sd, - > open_udp.lst
Append open TCP host:port pairs (domain or IP)
xmlstarlet sel -t -m "//host[status/@state='up']/ports/port[@protocol='tcp' and state/@state='open']" -i "count(../../hostnames/hostname[@type='user'])>0" -v "concat(../../hostnames/hostname[@type='user'][1]/@name,':',@portid)" -b -i "not(count(../../hostnames/hostname[@type='user'])>0) and ../../address[@addrtype='ipv4']" -v "concat(../../address[@addrtype='ipv4']/@addr,':',@portid)" -b -i "not(count(../../hostnames/hostname[@type='user'])>0) and ../../address[@addrtype='ipv6']" -v "concat('[',../../address[@addrtype='ipv6']/@addr,']:',@portid)" -b -n ./nmap_comp_svc.xml | sort -u >> raw_host_port.lst
AD Domain Controller Discovery¶
nameserveridentifies DNS resolvers;search/domainmay reveal the AD domain. For127.0.0.53, checkresolvectl statusfor upstream DNS.
Query a DNS server that resolves the AD domain. Output:
<priority> <weight> <port> <dc_fqdn>. SRV record reference