2017-09-17 59 views
1

我正在關注這本書,名爲暴力python,並在CH5中,它會通過腳本來查找iphone wifi端的mac地址。並通過增加最後一個字節來檢查藍牙是否打開。基本上找到一個在隱藏模式下有藍牙的iPhone。Python scapy prn發送rcv錯誤

我很困惑爲什麼腳本出錯了。我能做些什麼來防止將來出現這種錯誤?

這裏是下面的腳本:

#!/usr/bin/python 
# -*- coding: utf-8 -*- 

from scapy.all import * 
from bluetooth import * 


def retBtAddr(addr): 
    btAddr=str(hex(int(addr.replace(':', ''), 16) + 1))[2:] 
    btAddr=btAddr[0:2]+":"+btAddr[2:4]+":"+btAddr[4:6]+":"+\ 
    btAddr[6:8]+":"+btAddr[8:10]+":"+btAddr[10:12] 
    return btAddr 

def checkBluetooth(btAddr): 
    btName = lookup_name(btAddr) 
    if btName: 
     print '[+] Detected Bluetooth Device: ' + btName 
    else: 
     print '[-] Failed to Detect Bluetooth Device.' 


def wifiPrint(pkt): 
    iPhone_OUI = 'd0:23:db' 
    if pkt.haslayer(Dot11): 
     wifiMAC = pkt.getlayer(Dot11).addr2 
     if iPhone_OUI == wifiMAC[:8]: 
      print '[*] Detected iPhone MAC: ' + wifiMAC 
      btAddr = retBtAddr(wifiMAC) 
      print '[+] Testing Bluetooth MAC: ' + btAddr 
      checkBluetooth(btAddr) 


conf.iface = 'wlan1mon' 
sniff(prn=wifiPrint) 

錯誤消息我接收:

sudo python 10-iphoneFinder.py 
Traceback (most recent call last): 
    File "10-iphoneFinder.py", line 34, in <module> 
    sniff(prn=wifiPrint) 
    File "/home/rb/.local/lib/python2.7/site-packages/scapy/sendrecv.py", line 620, in sniff 
    r = prn(p) 
    File "10-iphoneFinder.py", line 26, in wifiPrint 
    if iPhone_OUI == wifiMAC[:8]: 
TypeError: 'NoneType' object has no attribute '__getitem__' 

回答

0

在Scapy的,在​​層的addr2字段是一個條件字段中,所以它可以具有當嗅探的分組沒有這樣的字段時,值爲None

下面是我們如何能寫的wifiPrint()功能:

IPHONE_OUI = 'd0:23:db:' 

def wifiPrint(pkt): 
    if Dot11 in pkt: 
     wifiMAC = pkt[Dot11].addr2 
     if wifiMAC is not None and wifiMAC.startswith(IPHONE_OUI): 
      print '[*] Detected iPhone MAC: ' + wifiMAC 
      btAddr = retBtAddr(wifiMAC) 
      print '[+] Testing Bluetooth MAC: ' + btAddr 
      checkBluetooth(btAddr) 

作爲一個側面說明,腳本是不是真的很好編碼,至少可以這樣說。也許從它學習Scapy(甚至是Python)並不是一個好主意。