[nmap] nmap 명령어/사용법
* 정보통신망법
제48조(정보통신망 침해행위 등의 금지)
① 누구든지 정당한 접근권한 없이 또는 허용된 접근권한을 넘어 정보통신망에 침입하여서는 아니 된다.
② 누구든지 정당한 사유 없이 정보통신시스템, 데이터 또는 프로그램 등을 훼손·멸실·변경·위조하거나 그 운용을 방해할 수 있는 프로그램(이하 "악성프로그램"이라 한다)을 전달 또는 유포하여서는 아니 된다.
③ 누구든지 정보통신망의 안정적 운영을 방해할 목적으로 대량의 신호 또는 데이터를 보내거나 부정한 명령을 처리하도록 하는 등의 방법으로 정보통신망에 장애가 발생하게 하여서는 아니 된다.
[전문개정 2008.6.13.]
nmap : network mapper의 줄임말로 네트워크 스캔과 보안감사를 하는 오픈소스 툴이다.
[명령어]
gl@GL:~$ nmap -help
Nmap 7.60 ( 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/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 consecutively - 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
--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
SEE THE MAN PAGE (https://nmap.org/book/man.html) FOR MORE OPTIONS AND EXAMPLES
사용법 : nmap [Scan Type(s)] [Options] {target specification}
[Scan Type]
-sS(TCP SYN scan)
제한적인 방화벽에 의해 방해받지 않으며, TCP 연결을 완료하지 않기 때문에 상대적으로 눈에 띄지 않는다.
포트가 열려있는 경우에는 공격자가 SYN 패킷을 보내고 공격 대상으로부터 SYN/ACK 패킷을 받으면 그 즉시 RST 패킷을 보내 연결을 끊음으로써 로그를 남기지 않는다.
포트가 닫혀있는 경우에는 공격자가 SYN 패킷을 보내면 공격 대상으로부터 RST/ACK 패킷을 받는다.
-sT(TCP connect scan)
기본적인 TCP 스캔으로 완전한 TCP 연결을 맺어서 포트의 활성화 여부를 판단한다.
3-way handshaking 과정으로 신뢰성은 얻을 수 있지만, 로그가 남는다.
-sA(TCP ACK scan)
기본적으로 이미 연결된 세션은 허용된다는 점을 이용하는 스캔 방법이다. 그러므로 방화벽에 의해 방해받지 않는다.
ACK 패킷만을 보냄으로 포트의 활성화 여부를 판단한다.
-sW(TCP Window scan)
기본적으로 TCP ACK 스캔과 같다, 하지만 열린 포트와 닫힌포트를 구별하는 해주는 특징이 있다.
-sM(TCP Maimon scan)
FIN/ACK라는 점을 제외하면 NULL, FIN 및 Xmas 스캔과 정확히 동일하다.
-sU(UDP scans)
스캔하고자 하는 포트를 대상으로 어떠한 udp 포트가 열려있는지를 알아보기 위해 사용된다.
ICMP port unreachable 메시지를 받았다면 이 포트는 closed 상태이며, 다른 경우라 open 상태라고 할 수 있다.
-sN / sF / sX(TCP NULL, FIN, and Xmas scans)
세션을 완전히 연결하지 않는다는 점에서 로그를 남기지 않으며 방화벽을 몰래 지나칠 수 있다.
TCP 헤더를 조작하여 특수한 패킷을 만들어 보낸 후 그에 대한 응답으로 포트의 활성화 여부를 알 수 있다.
1. TCP NULL scan : TCP 헤더 내에 FIN 플래그를 설정하여 전송한다.
2. TCP FIN scna : TCP 헤더 내에 플래그 값을 설정하지 않는다.
3. TCP Xmas scan : TCP 해더 내에 ACK, FIN, RST, SYN, URG 플래그를 모두 설정하여 전송한다.
세개 scan 모두 전송하면 포트가 열려 있는 경우 응답이 없고, 포트가 닫혀있는 경우 RST 패킷이 돌아온다.
-sI <zombie host[:probeport]> (idle scan)
공격자 정보가 남지 않도록 하는 스캔 방법이다. 하지만, 느리고 복잡하다는 단점이 있다.
공격자가 미리 좀비 PC로 사용하고자 하는 호스트를 하나 구성해 두며 모니터링을 지속적으로 한다.
공격자는 타겟에게 패킷을 전송하면 타겟은 좀비 PC에게 패킷을 보낸다.
공격자는 좀비 PC에게 들어오는 패킷을 스캐닝할 수 있게 된다.
-sY(SCTP INIT scan)
SCTP는 TCP 및 UDP 프로토콜에 대한 비교적 새로운 대안으로, 대부분의 TCP 및 UDP 특성을 결합하고 멀티 홈 및 멀티 스트리밍과 같은 새로운 기능을 추가합니다.
-sZ(SCTP COOKIE ECHO scan)
SCTP COOKIE ECHO 스캔은 고급 SCTP 스캔입니다. SCTP 구현은 열린 포트에서 COOKIE ECHO 청크를 포함하는 패킷을 자동으로 삭제해야 하지만 포트가 닫혀 있으면 ABORT를 전송해야 한다는 사실을 활용합니다.
-sO(IP protocol scan)
호스트에서 지원하는 IP 프로토콜 (TCP, ICMP, IGMP 등)을 확인할 수 있다.
TCP 또는 UDP 포트 번호가 아닌 IP 프로토콜 번호를 순환하기 때문에 기술적으로 포트 스캔이 아니지만, -p 옵션을 사용하여 검색된 프로토콜 번호를 선택하고, 일반 포트 테이블 형식 내에서 결과를보고하며, 실제 포트 검색 방법과 동일한 기본 검색 엔진을 사용한다.
-b <FTP relay host> (FTP bounce scan)
익명 FTP 서버를 이용해 그 FTP 서버를 경우해서 호스트를 스캔한다. 이를 FTP 바운스 스캔이라 한다.
* PING scan
-sP : ICMP프로토콜의 ping을 사용하여 시스템의 가동 중인지 확인
-PS : TCP SYN을 보내 응답한다면 RST 패킷이 온다.
-PU : 빈 UDP 패킷을 보냄
[Options]
* Port Options
-p <port ranges> : 지정된 포트만 스캔
ex) -p22 / -p1-65535 / -p U:53,111,137,T:21-25,80,139,8080,S:9
-F : 고속 모드
-r : 연속적으로 포트를 스캔
* service version
-sV : 열린 포트를 조사하여 서비스/버전 정보를 확인
* OS detection
-O : 열린 포트의 운영체제 서비스 정보를 확인
* OUTPUT Options
-oN<filename> : <filename>으로 지정한 파일에 Nmap의 일반적인 결과를 저장
-oX<filename> : <filename>으로 지정한 파일에 XML 형식으로 Nmap의 출력 결과를 저장
-oG<filename> : <filename>으로 지정한 파일에 Nmap의 grepable 형식으로 출력 결과를 저장
-oA<filename> : 3가지의 출력 결과를 모두 각각의 파일명으로 출력
-v : verbose mode로 스캔에 대한 더 많은 정보를 출력
* Firewall/IDS evasion AND spoofing
-f : TCP 헤더를 쪼개 패킷 필터를 우회
-D <decoy1, decoy2, your-own-ip> : 유인 IP 여러 개를 포트 스캔을 같이 하여 어떤 호스트가 목표인지 판단 혼동
-S<ip address> : 패킷의 소스 주소를 지정
-e<interface> : 네트워크 인터페이스 장치를 지정
-g<portnum> : 패킷의 소스 포트 주소를 지정
* misc
-n : DNS lookup을 하지 않음
-R : DNS lookup을 함
-6 : IPv6 사용하여 대상을 스캔
-h : 도움말