2012년 11월 23일 금요일

NMAP 의 친구 NPING 으로 패킷생성을 자유롭게

스캐너로 유명한 NMAP 의 친구 Nping 을 소개한다. Nping 은 네트워크 패킷 생성 도구이자, 그 응답의 시간측정, 분석 기능을 제공한다. Nping 은 다양한 프로토콜을 지원하고 각 프로토콜의 헤더를 조정할 수 있다. Ping 과 같이 어렵지 않게 사용할 수 있다. 네트워크 성능 측정에도 이용될 수 있는데, ARP Poisong, DoS 공격 등과 같은 트래픽 생성도 가능하다. Nping 은 2009년 구글 Summer of Code 로 부터 처음 시작되었다고 한다.

주요기능은,
- TCP, UDP, ICMP, ARP 패킷 생성
- 여러개의 호스트 및 포트 지정 가능
- Non 루트 유저를 위한 모드 제공
- 고급사용을 위한 에코모드
- 이더넷 프레임 생성 지원
- IPv6 지원
- 리눅스, 맥, 윈도우 에서 동작
- 자유롭게 커스트마이징이 가능한 점

다운로드는 Nmap 페이지에서 받을 수 있으며, 링크 경로는 다음과 같다:

http://nmap.org/download.html


Nping 도움말을 보면 누구나 쉽게 사용할 수 있을만큼 어렵지 않다. 다양한 옵션이 존재하고 몇 가지 사용 예제를 살펴보자.


1. ICMP 타입이 time 인 트래픽 전송 

--icmp-type 으로 옵션을 정할 수 있고 --delay 라는 것을 사용해 약간의 지연을 사용하였다.

# nping --icmp --icmp-type time --delay 500ms 192.168.163.131

Starting Nping 0.6.01 ( http://nmap.org/nping ) at 2012-11-12 08:13 KST
SENT (0.0476s) ICMP 192.168.163.1 > 192.168.163.131 Timestamp request (type=13/code=0) ttl=64 id=29186 iplen=40
RCVD (0.0545s) ICMP 192.168.163.131 > 192.168.163.1 Timestamp reply (type=14/code=0) ttl=128 id=6091 iplen=40
SENT (0.5477s) ICMP 192.168.163.1 > 192.168.163.131 Timestamp request (type=13/code=0) ttl=64 id=29186 iplen=40
RCVD (0.5503s) ICMP 192.168.163.131 > 192.168.163.1 Timestamp reply (type=14/code=0) ttl=128 id=6092 iplen=40
SENT (1.0479s) ICMP 192.168.163.1 > 192.168.163.131 Timestamp request (type=13/code=0) ttl=64 id=29186 iplen=40
RCVD (1.0504s) ICMP 192.168.163.131 > 192.168.163.1 Timestamp reply (type=14/code=0) ttl=128 id=6093 iplen=40
SENT (1.5490s) ICMP 192.168.163.1 > 192.168.163.131 Timestamp request (type=13/code=0) ttl=64 id=29186 iplen=40
RCVD (1.5494s) ICMP 192.168.163.131 > 192.168.163.1 Timestamp reply (type=14/code=0) ttl=128 id=6094 iplen=40
SENT (2.0491s) ICMP 192.168.163.1 > 192.168.163.131 Timestamp request (type=13/code=0) ttl=64 id=29186 iplen=40
RCVD (2.0503s) ICMP 192.168.163.131 > 192.168.163.1 Timestamp reply (type=14/code=0) ttl=128 id=6095 iplen=40

Max rtt: 6.901ms | Min rtt: 0.326ms | Avg rtt: 2.694ms
Raw packets sent: 5 (200B) | Rcvd: 5 (200B) | Lost: 0 (0.00%)
Tx time: 2.00268s | Tx bytes/s: 99.87 | Tx pkts/s: 2.50
Rx time: 3.00379s | Rx bytes/s: 66.58 | Rx pkts/s: 1.66
Nping done: 1 IP address pinged in 3.12 seconds

2. 포트 8001 번에 TCP 데이터를 포함해 한번 전송하기 


# nping --tcp --data "0xAAAAAAAA" -p 8001 -c 1 192.168.163.131

HEX 문자열을 이용하는 경우는 --data  를 사용하고 문자열을 나열하는 경우는 --data-string 을 이용한다.

# nping --tcp --data-string "PacketInside.com" -p 8001 -c 1 -v4 192.168.163.131

Starting Nping 0.6.01 ( http://nmap.org/nping ) at 2012-11-12 08:27 KST
SENT (0.0549s) TCP [192.168.163.1:32834 > 192.168.163.131:8001 S seq=3357278597 ack=0 off=5 res=0 win=1480 csum=0xA0C0 urp=0] IP [ver=4 ihl=5 tos=0x00 iplen=56 id=3146 foff=0 ttl=64 proto=6 csum=0xa6a0]
0000   45 00 00 38 0c 4a 00 00  40 06 a6 a0 c0 a8 a3 01  E..8.J..@.......
0010   c0 a8 a3 83 80 42 1f 41  c8 1c 01 85 00 00 00 00  .....B.A........
0020   50 02 05 c8 a0 c0 00 00  50 61 63 6b 65 74 49 6e  P.......PacketIn
0030   73 69 64 65 2e 63 6f 6d                           side.com    

만약 data 크기를 지정하는 경우 --data-length 옵션도 같이 사용한다.

3. 목적지 호스트 포트 80, 443 에 TCP 패킷 전송

# nping -c 1 --tcp -p 80,433 packetinside.com

Starting Nping 0.6.01 ( http://nmap.org/nping ) at 2012-11-12 08:35 KST
SENT (0.1624s) TCP 192.168.10.40:18421 > 216.239.34.21:80 S ttl=64 id=37098 iplen=40  seq=3387806461 win=1480
SENT (1.1626s) TCP 192.168.10.40:18421 > 216.239.34.21:433 S ttl=64 id=37098 iplen=40  seq=3387806461 win=1480

Max rtt: N/A | Min rtt: N/A | Avg rtt: N/A
Raw packets sent: 2 (80B) | Rcvd: 0 (0B) | Lost: 2 (100.00%)
Tx time: 1.00146s | Tx bytes/s: 79.88 | Tx pkts/s: 2.00
Rx time: 2.00254s | Rx bytes/s: 0.00 | Rx pkts/s: 0.00
Nping done: 1 IP address pinged in 2.20 seconds


4. 포트 범위를 지정하여 TCP 패킷 전송 

# nping 192.168.163.135 -c 1 --tcp -p 133-135

Starting Nping 0.6.01 ( http://nmap.org/nping ) at 2012-11-23 08:06 KST
SENT (0.0915s) TCP 192.168.163.1:19166 > 192.168.163.135:133 S ttl=64 id=20239 iplen=40  seq=1059400174 win=1480 
RCVD (0.0919s) TCP 192.168.163.135:133 > 192.168.163.1:19166 RA ttl=128 id=4388 iplen=40  seq=0 win=0 
SENT (1.0921s) TCP 192.168.163.1:19166 > 192.168.163.135:134 S ttl=64 id=20239 iplen=40  seq=1059400174 win=1480 
RCVD (1.0925s) TCP 192.168.163.135:134 > 192.168.163.1:19166 RA ttl=128 id=4390 iplen=40  seq=0 win=0 
SENT (2.0937s) TCP 192.168.163.1:19166 > 192.168.163.135:135 S ttl=64 id=20239 iplen=40  seq=1059400174 win=1480 
RCVD (2.0942s) TCP 192.168.163.135:135 > 192.168.163.1:19166 SA ttl=128 id=4391 iplen=44  seq=705789072 win=8192 <mss 1460>

5. TCP 패킷 생성시 좀더 다양하게 옵션 조절하기 


출발지 IP 는 -S 로 지정하고 ID 값을 9999 그리고 TTL 은 225 로 설정하였다. --badump-ip 를 사용해 의도적으로 잘못된 체크섬 값을 사용하게 했다. 거기다 MTU 도 점보 프레임 크기인 9000 을 사용했다.

# nping -S 1.1.1.1 --id 9999 -ttl 225 --badsum-ip --mtu 9000 --tcp -p 135 192.168.163.133

No.     Time           Source                Destination           Protocol Length Info
   1027 1817.197206000 1.1.1.1               192.168.163.133       TCP      60     24613 > epmap [SYN] Seq=0 Win=1480 Len=0

세부적인 데이터를 tshark 를 통해 다음과 같이 살펴보자. 의도한 대로 데이터가 잘 만들어져 전송되었는지 말이다.

Frame 1027: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Internet Protocol Version 4, Src: 1.1.1.1 (1.1.1.1), Dst: 192.168.163.133 (192.168.163.133)
    Version: 4
    Header length: 20 bytes
    Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
        0000 00.. = Differentiated Services Codepoint: Default (0x00)
        .... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
    Total Length: 40
    Identification: 0x270f (9999)
    Flags: 0x00
        0... .... = Reserved bit: Not set
        .0.. .... = Don't fragment: Not set
        ..0. .... = More fragments: Not set
    Fragment offset: 0
    Time to live: 225
    Protocol: TCP (6)
    Header checksum: 0x4c91 [correct]
    Source: 1.1.1.1 (1.1.1.1)
    Destination: 192.168.163.133 (192.168.163.133)
Transmission Control Protocol, Src Port: 24613 (24613), Dst Port: epmap (135), Seq: 0, Len: 0
    Source port: 24613 (24613)
    Destination port: epmap (135)
    [Stream index: 57]
    Sequence number: 0    (relative sequence number)
    Header length: 20 bytes
    Flags: 0x002 (SYN)
        000. .... .... = Reserved: Not set
        ...0 .... .... = Nonce: Not set
        .... 0... .... = Congestion Window Reduced (CWR): Not set
        .... .0.. .... = ECN-Echo: Not set
        .... ..0. .... = Urgent: Not set
        .... ...0 .... = Acknowledgment: Not set
        .... .... 0... = Push: Not set
        .... .... .0.. = Reset: Not set
        .... .... ..1. = Syn: Set
            [Expert Info (Chat/Sequence): Connection establish request (SYN): server port epmap]
                [Message: Connection establish request (SYN): server port epmap]
                [Severity level: Chat]
                [Group: Sequence]
        .... .... ...0 = Fin: Not set
    Window size value: 1480
    [Calculated window size: 1480]
    Checksum: 0x8604 [validation disabled]

0000  00 0c 29 8b 6f f8 00 50 56 c0 00 08 08 00 45 00   ..).o..PV.....E.
0010  00 28 27 0f 00 00 e1 06 4c 91 01 01 01 01 c0 a8   .('.....L.......
0020  a3 85 60 25 00 87 20 7c 3c be 00 00 00 00 50 02   ..`%.. |<.....P.
0030  05 c8 86 04 00 00 00 00 00 00 00 00               ............

6. ARP 패킷 전송 


# nping 192.168.163.135 -c 2 --arp

Starting Nping 0.6.01 ( http://nmap.org/nping ) at 2012-11-23 08:13 KST
SENT (0.0630s) ARP who has 192.168.163.135? Tell 192.168.163.1
RCVD (0.0634s) ARP reply 192.168.163.135 is at 00:0C:29:8B:XX:XX
SENT (1.0636s) ARP who has 192.168.163.135? Tell 192.168.163.1
RCVD (1.0640s) ARP reply 192.168.163.135 is at 00:0C:29:8B:XX:XX

7. ECHO 클라이언트/서버

1) --echo-server 로 동작시킨다. passphrase 로 public 을 사용하였다.

# nping --echo-server "public" -vvv

Starting Nping 0.6.01 ( http://nmap.org/nping ) at 2012-11-23 08:16 KST
Packet capture will be performed using network interface eth0.
Waiting for connections...
Server bound to 0.0.0.0:9929
[1353626220] Connection received from 192.168.163.135:49275
[1353626220] Good packet specification received from client #0 (Specs=9,IP=4,Proto=6,Cnt=5)
[1353626220] NEP handshake with client #0 (192.168.163.135:49275) was performed successfully
[1353626225] Client #0 (192.168.163.135:49275) disconnected

2) 이후 클라이언트에서 --echo-client 로 TCP RST 패킷을 전달하였다. 위 에코서버 로그에서 접속상태를 확인할 수 있다.

C:\play>nping --echo-client "public" 192.168.163.1 --tcp --flags rst

Starting Nping 0.6.01 ( http://nmap.org/nping ) at 2012-11-23 08:16 대한민국 표
준시
SENT (0.6870s) TCP 192.168.163.135:50411 > 192.168.163.1:80 SR ttl=64 id=41968 i
plen=40  seq=133370060 win=1480
SENT (1.7030s) TCP 192.168.163.135:50411 > 192.168.163.1:80 SR ttl=64 id=41968 i
plen=40  seq=133370060 win=1480
SENT (2.7190s) TCP 192.168.163.135:50411 > 192.168.163.1:80 SR ttl=64 id=41968 i
plen=40  seq=133370060 win=1480
SENT (3.7340s) TCP 192.168.163.135:50411 > 192.168.163.1:80 SR ttl=64 id=41968 i
plen=40  seq=133370060 win=1480
SENT (4.7500s) TCP 192.168.163.135:50411 > 192.168.163.1:80 SR ttl=64 id=41968 i
plen=40  seq=133370060 win=1480

참고로 윈도우 사용자는 NMAP 을 설치하면 해당 프로그램 경로안에 NPING 을 찾을 수 있다.

댓글 없음:

댓글 쓰기