티스토리 뷰

오늘은 간만에 사무실에 있는 관계로 nmap 에 대해서 간단히 소개좀 하려고 한다.

보통의 네트워크 엔지니어나 서버 엔지니어들은 tcpview에 대해서 알고 있으리라 본다.

PC나 서버에서 특정 호스트로의 포트 open 여부를 확인하는 작업은 트러블슈팅 시에 아주 중요한 요소이다.

tracert 로 경로를 추적하고 tracetcp (이 프로그램도 아주 유용하다) 등으로 포트 open 여부를 확인하는 작업을 병행하지만,

개인적으로 nmap 만큼이나 유용한 툴은 없으리라 생각한다.

그리고, 한가지 더 필요한 부분이 있는데, nmap을 포함한 스니퍼(sniffer)나 이더리얼(ethereal) 또는 이더픽(etherpeak) 등을 사용할 경우, winpcap 프로그램이 꼭 필요하니, 우선적으로 설치하기 바란다.

또한 nmap 프로그램은 해킹 시 필요한 필수 프로그램으로, 악용 시 네트웍 전체를 down시킬 수가 있으니 이용법을 꼭 숙지한 후 조심해서 사용하길 바란다.

---

nmap

 


nmap.exe를 실행하게 되면 아래와 같이 도움말이 표시된다.

.



D:\backup\nmap\nmap-5.50-win32\nmap-5.50>nmap
Nmap 5.50 ( http://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
  -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-trace: Show all data sent and received
  --script-updatedb: Update the script database.
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
  --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)
  --log-errors: Log errors/warnings to the normal-format output file
  --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 (http://nmap.org/book/man.html) FOR MORE OPTIONS AND EXAMPLES

수많은 기능 중 오늘은 서비스 port의 OPEN 여부를 확인하는 방법에 대해서 알아보겠다.


1. TCP 포트 OPEN 여부 확인


D:\backup\nmap\nmap-5.50-win32\nmap-5.50>nmap -p 8000 211.x.x.x
Starting Nmap 5.50 ( http://nmap.org/ ) at 2011-09-07 10:12 대한민국 표준시
Nmap scan report for 211.x.x.x
Host is up (0.00s latency).
PORT     STATE SERVICE
8000/tcp open  http-alt
MAC Address: 00:08:52:02:88:B5 (Davolink Co.)
Nmap done: 1 IP address (1 host up) scanned in 0.41 seconds
D:\backup\nmap\nmap-5.50-win32\nmap-5.50>

ip주소 211.x.x.x 에 대하여 tcp 8000 포트에 대한 OPEN 여부를 확인하였다.

PORT     STATE SERVICE
8000/tcp open  http-alt

이 부분에서 보는 바와 같이 tcp 8000 포트의 상태는 open 으로 http-alt 서비스에 해당하여 OPEN되어 있다. (다보링크 G/W에 대하여 테스트를 진행하였으며, 다보링크 웹접근 포트는 tcp8000 이다.)


2. UDP 포트 OPEN 여부 확인


D:\backup\nmap\nmap-5.50-win32\nmap-5.50>nmap -sU -p 8000 211.x.x.x
Starting Nmap 5.50 ( http://nmap.org/ ) at 2011-09-07 10:18 대한민국 표준시
Nmap scan report for 211.x.x.x
Host is up (0.0020s latency).
PORT     STATE  SERVICE
8000/udp closed irdmi
MAC Address: 00:08:52:02:88:B5 (Davolink Co.)
Nmap done: 1 IP address (1 host up) scanned in 0.42 seconds
D:\backup\nmap\nmap-5.50-win32\nmap-5.50>

-sU 옵션을 추가하여 UDP 포트에 대한 테스트를 시행하였지만, 상태가 closed로 해당 포트는 막혀있다.

이런 툴이 필요한 이유는 서비스 port의 OPEN 여부를 확인하기 위함이지만, 해당 서비스를 받기 위해서는 반드시 해당 포트를 통한 접근이 필요하기 때문에 사전 확인히 필요한 것이다.

ex. 외부에서 IP폰을 이용하여 인터넷전화를 하려고 한다.

외부(일반 가정집 등)에서 IP폰을 사용하기 위해서는 SIP 프로토콜 (MGCP나 H323도 있으나 통용적으로 SIP를 사용함)을 이용하여 SSW나 센트릭스로 접근을 해야만 한다.

SIP 프로토콜은 기본적으로 udp 5060 포트를 이용하여 서비스를 하며 (사업자간 보안을 위해 여러 포트들을 지정하여 사용하기도 함) 이 포트가 열려있지 않으면 서비스를 이용할 수가 없다.

일반적인 ISP나 SP에서는 SIP프로토콜 서비스를 위해 해당 포트를 허용해 놓지만, 일부 내/외부의 방화벽에서 보안을 위해 차단해 놓은 곳도 즐비하다.

우리회사는 KT 아날로그 10회선을 사용했지만, 금번 개편을 통해 all IP폰 체제로 전환을 하게 되었다. 이때 방화벽에서 udp 5060 포트를 허용해 줘야만 한다. 아니면 사업자에게 문의해 필요한 포트를 확인한 후 OPEN정책으로 허용해야 한다.

---

이를 위해 방화벽 포트가 차단되어 있을 경우와 허용했을 경우 2가지에 대해 nmap 툴로 확인해 보겠다.

1. 차단 되었을 때


D:\backup\nmap\nmap-5.50-win32\nmap-5.50>nmap -sU -p 5060 211.x.x.x
Starting Nmap 5.50 ( http://nmap.org/ ) at 2011-09-07 10:32 대한민국 표준시
Nmap scan report for 211.x.x.x
Host is up (0.0020s latency).
PORT     STATE  SERVICE
5060/udp closed sip
MAC Address: 00:1E:8C:66:F7:7C (Asustek Computer)
Nmap done: 1 IP address (1 host up) scanned in 0.41 seconds
D:\backup\nmap\nmap-5.50-win32\nmap-5.50>

2. 허용 되었을 때


D:\backup\nmap\nmap-5.50-win32\nmap-5.50>nmap -sU -p 5060 211.x.x.x
Starting Nmap 5.50 ( http://nmap.org/ ) at 2011-09-07 10:28 대한민국 표준시
Nmap scan report for 211.x.x.x
Host is up (0.00s latency).
PORT     STATE         SERVICE
5060/udp open|filtered sip
Nmap done: 1 IP address (1 host up) scanned in 0.64 seconds
D:\backup\nmap\nmap-5.50-win32\nmap-5.50>

차단된 호스트에서는 SIP 서비스를 이용할 수 없으니 IP폰을 이용할 수가 없다.

허용된 호스트에서는 SIP 프로토콜을 이용하여 정상적인 전화 통화가 가능하다.

---

최근들어 인터넷전화 해킹으로 인한 과금우회 해킹을 피해가 발생한 보도를 봤는데,

이러한 인터넷전화 해킹은 H323 ID를 가로채는 기술보다는 SIP 계정을 가로채는 기술을 이용한 해킹이 대부분이다.

SIP프로토콜은 패킷의 내용에 SIP 계정 및 암호가 텍스트 형식으로 실려 전송되면서 인증되는 방식이라, 해킹에 쉽게 노출이 되게 마련이다. 서비스 업체에서는 보안에 대한 경각심을 가져야 할 것이다.

내가 sipvicious를 이용하여 SIP 통신을 하는 IP폰과 IP PBX 사이에서 패킷을 캡쳐해 봤는데, 인증 ID와 password가 텍스트 형식으로 이쁘게 캡쳐되었다.

인터넷전화의 보안이 심각한 문제로 대두된다.

---

오늘은 nmap을 이용한 서비스 포트 허용 여부 확인에 대해서 알아보았으며,
내일은 nmap의 또다른 강점인 포트 스캔에 대해서 알아보도록 하겠다.

이 포트스캔은 well known port number 를 통하여 서비스 포트의 허용 여부를 알아내어, 취약한 서비스 포트를 통한 해킹 시도 시 이용된다.

해커들의 필수품인 nmap 툴, 내일 다시 파고들어 보겠다.

---

ps. nmap 자료가 필요하신 분은 구글 자료실에서 손쉽게 구할 수 있으며,

도움이 필요하시면 덧글이나 메일로 남겨주시면 되겠습니다.



댓글