콤푸타/해킹&보안

nmap 옵션 정리

어둠의다크 2025. 7. 8. 09:42
728x90

nmap 옵션은 항상 잘 기억이 안난다. 그래서 내가 볼려고 정리를 해본다.

nmap이 뭔지 모른다면, 네트워크 공부를 좀 더 하고 다시 이 글을 보면 좋겠다.

 

1. Nmap 사용하기

https://nmap.org/book/man.html 여기 페이지에 굉장히 상세하게 정리되어 있다. 또는 다음 도움말을 참고해보자.

Nmap 7.97 ( https://nmap.org )
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:
  Can pass hostnames, IP addresses, networks, etc.
  Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254
  -iL <inputfilename>: Input from list of hosts/networks
  -iR <num hosts>: Choose random targets
  --exclude <host1[,host2][,host3],...>: Exclude hosts/networks
  --excludefile <exclude_file>: Exclude list from file
HOST DISCOVERY:
  -sL: List Scan - simply list targets to scan
  -sn: Ping Scan - disable port scan
  -Pn: Treat all hosts as online -- skip host discovery
  -PS/PA/PU/PY[portlist]: TCP SYN, TCP ACK, UDP or SCTP discovery to given ports
  -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
  -PO[protocol list]: IP Protocol Ping
  -n/-R: Never do DNS resolution/Always resolve [default: sometimes]
  --dns-servers <serv1[,serv2],...>: Specify custom DNS servers
  --system-dns: Use OS's DNS resolver
  --traceroute: Trace hop path to each host
SCAN TECHNIQUES:
  -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
  -sU: UDP Scan
  -sN/sF/sX: TCP Null, FIN, and Xmas scans
  --scanflags <flags>: Customize TCP scan flags
  -sI <zombie host[:probeport]>: Idle scan
  -sY/sZ: SCTP INIT/COOKIE-ECHO scans
  -sO: IP protocol scan
  -b <FTP relay host>: FTP bounce scan
PORT SPECIFICATION AND SCAN ORDER:
  -p <port ranges>: Only scan specified ports
    Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9
  --exclude-ports <port ranges>: Exclude the specified ports from scanning
  -F: Fast mode - Scan fewer ports than the default scan
  -r: Scan ports sequentially - don't randomize
  --top-ports <number>: Scan <number> most common ports
  --port-ratio <ratio>: Scan ports more common than <ratio>
SERVICE/VERSION DETECTION:
  -sV: Probe open ports to determine service/version info
  --version-intensity <level>: Set from 0 (light) to 9 (try all probes)
  --version-light: Limit to most likely probes (intensity 2)
  --version-all: Try every single probe (intensity 9)
  --version-trace: Show detailed version scan activity (for debugging)
SCRIPT SCAN:
  -sC: equivalent to --script=default
  --script=<Lua scripts>: <Lua scripts> is a comma separated list of
           directories, script-files or script-categories
  --script-args=<n1=v1,[n2=v2,...]>: provide arguments to scripts
  --script-args-file=filename: provide NSE script args in a file
  --script-trace: Show all data sent and received
  --script-updatedb: Update the script database.
  --script-help=<Lua scripts>: Show help about scripts.
           <Lua scripts> is a comma-separated list of script-files or
           script-categories.
OS DETECTION:
  -O: Enable OS detection
  --osscan-limit: Limit OS detection to promising targets
  --osscan-guess: Guess OS more aggressively
TIMING AND PERFORMANCE:
  Options which take <time> are in seconds, or append 'ms' (milliseconds),
  's' (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m).
  -T<0-5>: Set timing template (higher is faster)
  --min-hostgroup/max-hostgroup <size>: Parallel host scan group sizes
  --min-parallelism/max-parallelism <numprobes>: Probe parallelization
  --min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>: Specifies
      probe round trip time.
  --max-retries <tries>: Caps number of port scan probe retransmissions.
  --host-timeout <time>: Give up on target after this long
  --scan-delay/--max-scan-delay <time>: Adjust delay between probes
  --min-rate <number>: Send packets no slower than <number> per second
  --max-rate <number>: Send packets no faster than <number> per second
FIREWALL/IDS EVASION AND SPOOFING:
  -f; --mtu <val>: fragment packets (optionally w/given MTU)
  -D <decoy1,decoy2[,ME],...>: Cloak a scan with decoys
  -S <IP_Address>: Spoof source address
  -e <iface>: Use specified interface
  -g/--source-port <portnum>: Use given port number
  --proxies <url1,[url2],...>: Relay connections through HTTP/SOCKS4 proxies
  --data <hex string>: Append a custom payload to sent packets
  --data-string <string>: Append a custom ASCII string to sent packets
  --data-length <num>: Append random data to sent packets
  --ip-options <options>: Send packets with specified ip options
  --ttl <val>: Set IP time-to-live field
  --spoof-mac <mac address/prefix/vendor name>: Spoof your MAC address
  --badsum: Send packets with a bogus TCP/UDP/SCTP checksum
OUTPUT:
  -oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,
     and Grepable format, respectively, to the given filename.
  -oA <basename>: Output in the three major formats at once
  -v: Increase verbosity level (use -vv or more for greater effect)
  -d: Increase debugging level (use -dd or more for greater effect)
  --reason: Display the reason a port is in a particular state
  --open: Only show open (or possibly open) ports
  --packet-trace: Show all packets sent and received
  --iflist: Print host interfaces and routes (for debugging)
  --append-output: Append to rather than clobber specified output files
  --resume <filename>: Resume an aborted scan
  --noninteractive: Disable runtime interactions via keyboard
  --stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML
  --webxml: Reference stylesheet from Nmap.Org for more portable XML
  --no-stylesheet: Prevent associating of XSL stylesheet w/XML output
MISC:
  -6: Enable IPv6 scanning
  -A: Enable OS detection, version detection, script scanning, and traceroute
  --datadir <dirname>: Specify custom Nmap data file location
  --send-eth/--send-ip: Send using raw ethernet frames or IP packets
  --privileged: Assume that the user is fully privileged
  --unprivileged: Assume the user lacks raw socket privileges
  -V: Print version number
  -h: Print this help summary page.
EXAMPLES:
  nmap -v -A scanme.nmap.org
  nmap -v -sn 192.168.0.0/16 10.0.0.0/8
  nmap -v -iR 10000 -Pn -p 80

 

1-1. Nmap 기본 사용 방법

Usage: nmap [Scan Type(s)] [Options] {target specification}

 

2. Nmap 옵션

2-1. Target Specification (대상 지정)

옵션 설명
<target> IP, 도메인, 서브넷 모두 가능. 192.168.0.0/24
-iL <file> 스캔할 대상 목록 파일로 읽기
-iR <num> 랜덤으로 대상 선택 (테스트용)
--exclude 특정 호스트 제외
--excludefile 제외할 대상 목록 파일로 읽기

 

2-2. Host Discovery (호스트 발견)

옵션 설명
-sL List Scan. 스캔 안 하고 대상 목록만 나열.
-sn Ping Scan. 포트 스캔은 하지 않고 호스트가 살아있는지만 확인.
-Pn Ping 무시. 호스트를 항상 살아있는 것으로 간주. 방화벽이 ICMP 차단 시 유용.
-PS/PA/PU/PY TCP SYN/ACK, UDP, SCTP Ping. ICMP 못쓸 때 포트 기반 Ping.
-PE/PP/PM ICMP Echo, Timestamp, Netmask Request.
-PO IP 프로토콜 Ping.
-n DNS 해석 안 함 (속도↑)
-R 항상 DNS 해석.
--dns-servers 사용자 정의 DNS 서버 지정.
--system-dns OS의 DNS 리졸버 강제 사용.
--traceroute 대상까지 홉 경로 추적.

 

2-3. Scan Techniques (스캔 기술)

포트 스캔에도 여러 가지 방법이 존재한다.

옵션 설명
-sS TCP SYN Scan (스텔스 스캔, Half-Open)
-sT TCP Connect() Scan (완전 연결) — 권한 부족 시
-sA TCP ACK Scan — 방화벽 규칙 파악
-sW TCP Window Scan — 더 세밀한 방화벽 분석
-sM TCP Maimon Scan — 특이한 FIN/ACK 스캔
-sU UDP Scan
-sN/-sF/-sX TCP Null/FIN/Xmas Scan — 방화벽 회피 실험
--scanflags TCP 플래그 직접 지정
-sI Idle Scan — 좀비 호스트로 스텔스 스캔
-sY/-sZ SCTP INIT/COOKIE-ECHO Scan
-sO IP 프로토콜 스캔 (TCP/UDP 외의 프로토콜 식별)
-b FTP Bounce Scan — FTP 중계 가능 여부 확인

 

2-4. Port Specification(포트 옵션)

옵션 설명
-p 스캔할 포트 지정. -p 22,80,443
--exclude-ports 제외할 포트 지정.
-F Fast scan. 기본 Top 100 포트만 스캔.
-r 포트를 순차적으로 스캔. 기본은 무작위.
--top-ports <num> 가장 흔한 포트 개만 스캔.
--port-ratio 사용 빈도 기준으로 포트 필터링.

 

2-5. Service/Version Detection(서비스/버전 스캔)

옵션 설명
-sV 열려 있는 포트의 서비스 버전 감지
--version-intensity 탐지 강도 (0~9)
--version-light 최소한의 프로브만 (속도↑)
--version-all 가능한 모든 프로브 시도
--version-trace 버전 감지 디버깅 출력

 

2-6. NSE(Nmap Scripting Engine) Script Scan

옵션 설명
-sC 기본 NSE 스크립트 사용 (default 카테고리)
--script 특정 Lua 스크립트 지정
--script-args 스크립트에 파라미터 전달
--script-args-file 스크립트 인자 파일로 전달
--script-trace 스크립트 송수신 데이터 출력
--script-updatedb NSE DB 업데이트
--script-help 스크립트별 도움말 표시

 

2-7. OS Detection

옵션 설명
-O 운영체제 탐지 (패킷 특성 기반)
--osscan-limit 가능성 높은 대상만 OS 탐지
--osscan-guess 불확실할 때 OS를 더 공격적으로 추측

 

2-8. Timing & Performance

옵션 설명
-T0 ~ -T5 스캔 속도 템플릿. 0(조용) ~ 5(매우 빠름). IDS 우회 시 T0~T2
--min-hostgroup 병렬 호스트 그룹 최소값
--max-hostgroup 병렬 호스트 그룹 최대값
--min-parallelism 최소 병렬 프로브 수
--max-parallelism 최대 병렬 프로브 수
--min-rtt-timeout 최소 RTT
--max-retries 최대 재전송 횟수
--host-timeout 호스트별 제한 시간
--scan-delay 프로브 간 딜레이
--min-rate 최소 전송 속도
--max-rate 최대 전송 속도

 

2-9. Firewall/IDS Evasion and Spoofing

옵션 설명
-f 패킷 분할(Fragment)
--mtu MTU 크기 지정
-D 디코이(Decoy) 호스트 사용
-S Source IP 스푸핑
-e 특정 인터페이스 사용
-g Source Port 지정
--proxies HTTP/SOCKS 프록시 중계
--data/--data-string/--data-length 패킷에 사용자 정의 데이터 삽입
--ip-options IP 옵션 필드 설정
--ttl TTL 변경
--spoof-mac MAC 주소 스푸핑
--badsum 잘못된 체크섬 사용

 

2-10. Output

옵션 설명
-oN/-oX/-oS/-oG Normal/XML/Script Kiddie/Grepable 출력
-oA 위 3가지 출력 동시 생성
-v Verbose 출력
-d Debug 출력
--reason 포트 상태의 이유 출력
--open 열려있는 포트만 표시
--packet-trace 패킷 송수신 내용 보기
--iflist 인터페이스/라우팅 정보 출력
--append-output 결과 덮어쓰기 대신 이어쓰기
--resume 중단된 스캔 재개
--noninteractive 스캔 중 상호작용 입력 금지

 

2-11. MISC(기타)

옵션 설명
-6 IPv6 스캔
-A 종합 스캔(버전, 스크립트, OS, traceroute)
--datadir 사용자 데이터 경로 지정
--send-eth Ethernet 프레임 사용
--privileged 관리자 권한으로 가정
-V 버전 확인
-h 도움말

 

3. 그 외 팁들

3-1. CIDR 표기법 지원

nmap 192.168.0.0/24

192.168.0.1부터 192.168.0.254까지 모든 호스트를 스캔한다.

 

3-2. IP 범위 표시 지원

nmap 10.0.0-5.1-254

10.0.0.1 ~ 10.0.5.254까지 스캔.

 

3-3. 스캔 모드

-sS: TCP SYN Scan. half open scan이라고도 한다. 대상 포트에 SYN 패킷을 보내고 SYN/ACK를 받으면 포트가 열린 것으로 확인. RST를 보내 연결을 완료하지 않고 종료. IDS 탐지 회피에 용이

-sT: TCP Connect Scan. 완전한 TCP 연결 수행

-sU: UDP Scan. UDP는 세션이 존재하는 연결 지향 통신이 아니기 때문에 3-way HS가 없음. 그런데, RFC에 의하면 닫힌 UDP는 ICMP Unreachable 패킷을 반송해야 하기 때문에 빈 패킷을 보내고 ICMP 패킷을 탐지함으로써 UDP 스캔 가능

 

728x90