在mininet中测试arp欺骗

 我本来只用给出测试的拓补,以及仿真中使用的命令,本篇博客就算完事。最近csdn的博客系统,好像不允许发布全是英文内容的博客。所以,我要写点废话,便于在此记录我的所学。
 测试使用的拓补,2h1s.py

#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.link import TCLink
import time
import datetime
import subprocess
import os,signal
import sys
# https://segmentfault.com/a/1190000009562333
# arpspoof -i h2-eth0 -t 10.0.1.1 10.0.1.3
# 
#    h1----s1----h2------h3             
#
bottleneckbw=6
nonbottlebw=500;  
buffer_size =bottleneckbw*1000*30/(1500*8) 
net = Mininet( cleanup=True )
h1 = net.addHost('h1',ip='10.0.1.1')
h2 = net.addHost('h2',ip='10.0.1.2')
h3 = net.addHost('h3',ip='10.0.2.2')
s1 = net.addSwitch( 's1' )
c0 = net.addController('c0')
net.addLink(h1,s1,intfName1='h1-eth0',intfName2='s1-eth0',cls=TCLink , bw=nonbottlebw, delay='10ms', max_queue_size=10*buffer_size)
net.addLink(s1,h2,intfName1='s1-eth1',intfName2='h2-eth0',cls=TCLink , bw=bottleneckbw, delay='10ms', max_queue_size=buffer_size) 
net.addLink(h2,h3,intfName1='h2-eth1',intfName2='h3-eth0',cls=TCLink , bw=nonbottlebw, delay='50ms', max_queue_size=buffer_size)
net.build()
h1.cmd("ifconfig h1-eth0 10.0.1.1/24")
h1.cmd("route add default gw 10.0.1.3 dev h1-eth0")
h1.cmd('sysctl net.ipv4.ip_forward=1')

h2.cmd("ifconfig h2-eth0 10.0.1.2/24")
h2.cmd("ifconfig h2-eth1 10.0.2.1/24")
h2.cmd("ip route add to 10.0.2.0/24 via 10.0.2.2")
h2.cmd("ip route add to 10.0.1.0/24 via 10.0.1.1")
h2.cmd('sysctl net.ipv4.ip_forward=1')

h3.cmd("ifconfig h3-eth0 10.0.2.2/24")
h3.cmd("route add default gw 10.0.2.1 dev h3-eth0")
h3.cmd('sysctl net.ipv4.ip_forward=1')

net.start()
time.sleep(1)
CLI(net)
net.stop()

 参考[1]安装可以arp欺骗的软件。

sudo apt-get install dsniff

 启动mininet。

sudo su
xxxxx
python 2h1s.py

 测试h1 ping h3。

xterm h1
ping 10.0.2.2

 h1需要获取gateway的mac地址。h1的gateway为10.0.1.3。这个地址在这个微型网络中不存在。h1发送的arp包能够被h2截获,从而进行arp欺骗。h2可以向h1返回h2-eth0的mac地址。

xterm h2
arpspoof -i h2-eth0 -t 10.0.1.1 10.0.1.3

 测试h1 ping h3。 成功。
 如果你想实现一个arp欺骗的工具,在daemon模下,就必须开启网卡的混杂模式[2]。否则,主机网卡是不能向应用提交非本机IP的数据包的。可以参考[3]的实现。

	ifr.ifr_flags = ifr.ifr_flags | IFF_PROMISC;
	if (ioctl (sock, SIOCGIFFLAGS, &ifr) < 0) {
		perror("ioctl");
		exit(1);
	}

参考:
[1] 局域网ARP欺骗原理详解
[2] 混杂模式介绍
[3] arproxy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值