IPスプーフィング対策

■IPスプーフィング対策
 iptablesか、sysctl.confで対応できる。
 勿論、両方やる方が望ましいですが、それでも、それだけで終わりではありません。

 また、iptablesのルールが増えて見難く、必要な設定を見逃しそうだと思うなら、「sysctl.conf」だけにするのもアリ。
 vmnet8のIPマスカレード環境のゲストにホストからチェック。

 Linux Iptables Avoid IP Spoofing And Bad Addresses Attacks
 http://www.cyberciti.biz/tips/linux-iptables-8-how-to-avoid-spoofing-and-bad-addresses-attack.html

■squeezeではコメントアウトされている。
 コメントアウトを外せば、再起動後も有効となる。

$ sudo grep "net.ipv4.conf.all.rp_filter=1" /etc/sysctl.conf
#net.ipv4.conf.all.rp_filter=1

$ echo 1 | sudo tee /proc/sys/net/ipv4/conf/default/rp_filter
1

$ sudo sysctl -A 2>&1 | grep "net.ipv4.conf.all.rp_filter"
net.ipv4.conf.all.rp_filter = 1

■iptablesの場合は以下を参考に。

 参考:[computing] 今週の成果: iptables
 http://d.hatena.ne.jp/takehikom/20110326/1301076471

■nmapで開いてるポートを確認する。

$ sudo nmap -P0 -p 1-65535 -sT 192.168.188.188 | grep ^[0-9]
22/tcp   open  ssh
25/tcp   open  smtp
53/tcp   open  domain
80/tcp   open  http

■hping3で確認。

$ apt-cache search ^hping
hping3 - Active Network Smashing Tool

$ apt-cache show hping3 | grep ^Desc -A 9
Description: Active Network Smashing Tool
 hping3 is a network tool able to send custom ICMP/UDP/TCP packets and
 to display target replies like ping does with ICMP replies. It handles
 fragmentation and arbitrary packet body and size, and can be used to
 transfer files under supported protocols. Using hping3, you can test
 firewall rules, perform (spoofed) port scanning, test network
 performance using different protocols, do path MTU discovery, perform
 traceroute-like actions under different protocols, fingerprint remote
 operating systems, audit TCP/IP stacks, etc.  hping3 is scriptable
 using the Tcl language.

■偽IP:「192.168.188.100」を使って通信

$ sudo /usr/sbin/hping3 -V 192.168.188.188 -c 4 -p 80 -S -a 192.168.188.100

--- 192.168.188.188 hping statistic ---
4 packets transmitted, 0 packets received, 100% packet loss
round-trip min/avg/max = 0.0/0.0/0.0 ms
using vmnet8, addr: 192.168.188.1, MTU: 1500
HPING 192.168.188.188 (vmnet8 192.168.188.188): S set, 40 headers + 0 data bytes

■IP偽装をしなければ、SYN/ACKで返ってくる。

$ sudo /usr/sbin/hping3 192.168.188.188 -c 4 -p 80 -S -n

--- 192.168.188.188 hping statistic ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.4/0.8/1.3 ms
HPING 192.168.188.188 (vmnet8 192.168.188.188): S set, 40 headers + 0 data bytes
len=44 ip=192.168.188.188 ttl=64 DF id=0 sport=80 flags=SA seq=0 win=5840 rtt=1.3 ms
len=44 ip=192.168.188.188 ttl=64 DF id=0 sport=80 flags=SA seq=1 win=5840 rtt=1.2 ms
len=44 ip=192.168.188.188 ttl=64 DF id=0 sport=80 flags=SA seq=2 win=5840 rtt=0.4 ms
len=44 ip=192.168.188.188 ttl=64 DF id=0 sport=80 flags=SA seq=3 win=5840 rtt=0.5 ms

■nmapではMACも偽装できるようだ。

$ man nmap | grep -A 10 "          FIREWALL/IDS EVASION AND SPOOFING"
           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

■さすがに「lo」に偽装することは出来ない。

$ sudo nmap -e vmnet8 -P0 192.168.188.188 -S 127.0.0.1 -sS --spoof-mac 00:00:00:00:00:00
Starting Nmap 5.00 ( http://nmap.org ) at 2012-09-04 23:47 JST
Spoofing MAC address 00:00:00:00:00:00 (Xerox)
Nmap done: 1 IP address (0 hosts up) scanned in 0.47 seconds

■IP偽装だけだとはじきます。

$ sudo nmap -e vmnet8 -P0 192.168.188.188 -S 192.168.188.100 -sS

Starting Nmap 5.00 ( http://nmap.org ) at 2012-09-04 23:57 JST
All 1000 scanned ports on vmsqueeze.localdomain (192.168.188.188) are filtered
MAC Address: 00:XX:XX:XX:XX:XX (VMware)

Nmap done: 1 IP address (1 host up) scanned in 21.43 seconds

■同じセグメントの偽IPと偽MACアドレスの対でチェックするとすり抜けます。

 多段のセグメントを通りぬけることは出来ませんが、、
 内部に侵入後の偵察行為だけならこれで充分かも知れません。
 loggerコマンドでiptables風のログを残して混乱や発見の遅れを得ることも可能です。
 LAN側のIP/MACアドレスの対を知られることはなかなか危険です。

 IPマスカレードでなくきちんとセグメントを分けなければいけませんね。。。

$ sudo nmap -e vmnet8 -P0 192.168.188.188 -S 192.168.188.100 -sS --spoof-mac 00:XX:XX:XX:XX:11

Starting Nmap 5.00 ( http://nmap.org ) at 2012-09-04 23:34 JST
Spoofing MAC address 00:XX:XX:XX:XX:11 (VMWare)
Interesting ports on vmsqueeze.localdomain (192.168.188.188):
Not shown: 992 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
25/tcp   open  smtp
53/tcp   open  domain
80/tcp   open  http
MAC Address: 00:XX:XX:XX:XX:XX (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.32 seconds