fping, nmap: IP 스캔 :: 행복한 프로그래머

posted by 쁘로그램어 2017. 12. 23. 15:29

주로 VM(Virtual Machince)을 생성하고 IP를 할당해서 사용하고 있습니다.

특정 네트워크 대역에서 어떤 IP가 미사용인지 체크하는 방법을 소개합니다.

검색해보니 fping과 nmap이라는 tool을 사용하면 되겠네요.

저는 우분투(Ubuntu) 환경에서 설치하고 사용해보았습니다.


# fping 이란?

fping은 인터넷 제어 메시지 프로토콜 (ICMP) 에코 요청을 사용하는 ping과 같은 명령입니다.

ping은 하나의 ip만 설정하지만, fping은 ip 대역을 설정해주어 그 대역에 어느 ip가 ping이 되는지 알수있습니다.

즉 특정 ip 대역에서 어느 ip로 통신이 되는지 확인할때 활용하면 좋을거 같습니다.


# fping 설치

$ apt install fping


# fping 사용법 확인

root@xos:~# fping --help

fping: invalid option -- '-'


Usage: fping [options] [targets...]

   -a         show targets that are alive

   -A         show targets by address

   -b n       amount of ping data to send, in bytes (default 56)

   -B f       set exponential backoff factor to f

   -c n       count of pings to send to each target (default 1)

   -C n       same as -c, report results in verbose format

   -D         print timestamp before each output line

   -e         show elapsed time on return packets

   -f file    read list of targets from a file ( - means stdin) (only if no -g specified)

   -g         generate target list (only if no -f specified)

                (specify the start and end IP in the target list, or supply a IP netmask)

                (ex. fping -g 192.168.1.0 192.168.1.255 or fping -g 192.168.1.0/24)

   -H n       Set the IP TTL value (Time To Live hops)

   -i n       interval between sending ping packets (in millisec) (default 25)

   -l         loop sending pings forever

   -m         ping multiple interfaces on target host

   -n         show targets by name (-d is equivalent)

   -p n       interval between ping packets to one target (in millisec)

                (in looping and counting modes, default 1000)

   -q         quiet (don't show per-target/per-ping results)

   -Q n       same as -q, but show summary every n seconds

   -r n       number of retries (default 3)

   -s         print final stats

   -I if      bind to a particular interface

   -S addr    set source address

   -t n       individual target initial timeout (in millisec) (default 500)

   -T n       ignored (for compatibility with fping 2.4)

   -u         show targets that are unreachable

   -O n       set the type of service (tos) flag on the ICMP packets

   -v         show version

   targets    list of targets to check (if no -f specified)


# fping 사용 예시

$ fping -g 10.10.2.0/24

10.10.2.1 is alive

10.10.2.2 is alive

10.10.2.3 is alive

10.10.2.6 is alive

10.10.2.7 is alive

10.10.2.9 is alive

10.10.2.10 is alive

10.10.2.11 is alive

10.10.2.14 is alive

...... 생략 ......

10.10.2.4 is unreachable

10.10.2.5 is unreachable

10.10.2.8 is unreachable

10.10.2.12 is unreachable

10.10.2.13 is unreachable

10.10.2.15 is unreachable

10.10.2.17 is unreachable

10.10.2.18 is unreachable

10.10.2.19 is unreachable

10.10.2.20 is unreachable



위의 결과를 보면 10.10.2.11은 어떤 장비에서 IP를 할당해서 사용중이고,

10.10.2.12는 IP가 할당되지 않을 것을 확인할 수 있습니다.


# nmap이란?

- 호스트 또는 네트워크의 IP 및 PORT를 스캐닝하는 툴입니다.

- 호스트나 네트워크를 스캐닝 할 때, 아주 유용한 시스템 보안툴인 동시에, 해커에게는 강력한 해킹툴이다.


# nmap 설치

$ apt install nmap


# nmap 사용법 확인

$ nmap --help

Nmap 6.40 ( 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-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 separted 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

  --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


# nmap 사용 예시

root@xos:~# nmap -sP 10.10.2.10-20

Starting Nmap 6.40 ( http://nmap.org ) at 2017-12-23 15:24 KST

Nmap scan report for 10.10.2.11

Host is up (0.69s latency).

MAC Address: 8C:DC:D4:AF:0A:E8 (Unknown)

Nmap scan report for 10.10.2.14

Host is up (0.69s latency).

MAC Address: 52:54:00:11:93:29 (QEMU Virtual NIC)

Nmap scan report for 10.10.2.16

Host is up (0.69s latency).

MAC Address: 38:63:BB:45:0D:98 (Unknown)

Nmap scan report for 10.10.2.17

Host is up (0.69s latency).

MAC Address: 8C:DC:D4:AF:0A:94 (Unknown)

Nmap done: 11 IP addresses (4 hosts up) scanned in 2.56 seconds


※ 참고 사이트 ※
https://stackoverflow.com/questions/503171/send-a-ping-to-each-ip-on-a-subnet
https://stackoverflow.com/questions/14038606/fastest-way-to-ping-a-network-range-and-return-responsive-hosts