2014-10-01 24 views
1

我能夠在python混雜模式下嗅探數據包,同時使用下面的代碼連接到我的無線網絡。我已經徹底測試了這一點,並知道這個工作。我在我的網絡看到正常的報文:在沒有第三方庫的情況下在監聽模式下嗅探以太網數據包?

rawSocket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003)) 
packet = rawSocket.recvfrom(2048) 
ethernet_header = packet[0][0:14] 
ethernet_detailed = unpack("!6s6s2s", ethernet_header) 
print ethernet_detailed 

不過,我希望把它更進一步,在監視模式我的WiFi卡嘗試此,而不是連接到任何網絡。我知道我的卡支持Monitor模式,因爲它的阿法AWUS066NH。我使用下面的代碼將py卡置於監視模式。

os.system('ifconfig %s down' % interface) 
    os.system('iwconfig %s mode monitor' % interface) 
    os.system('ifconfig %s up' % interface) 

但是現在,當我運行上面相同的代碼,這是在混雜模式使用,我只能得到一個單一的數據包是誰的​​看起來像這樣('\x00\x00\x12\x00.H', '\x00\x00\x00\x02l\t', '\xc0\x00')

爲什麼我再也看不到比其他任何數據包描述的那個?另外我應該如何在監聽模式下嗅探?我想在沒有第三方的情況下做到這一點,但如果必須的話,我會這樣做。

+0

下面是一些網卡類似的人,他們似乎和你有相同的問題:http://www.backtrack -linux.org/forums/showthread.php?t=53559 - 他們沒有解決方案。 – 2014-10-01 07:33:05

回答

0

有在

ethernet_header = packet[0][0:14] 

額外lenth不要求

rawSocket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003)) 
packet = rawSocket.recvfrom(2048) 
ethernet_header = packet[0:14] 
ethernet_detailed = unpack("!6s6s2s", ethernet_header) 
print ethernet_detailed 
+0

這是不正確的。 'recvfrom()'將返回包含從其接收數據的數據和地址的元組。因此,'ethernet_header = packet [0] [0:14]'是正確的選擇。 – Fejs 2016-11-18 09:53:50

2

既然你把你的卡在監控模式下,你現在看到的802.11幀(信標,探測請求/迴應等)。

你在你的0:14字節範圍內看到的是你的卡預取捕獲的數據的無線電抽頭標頭的一部分。第三個字節表示無線電抽頭標頭長度爲0x12(18字節)。 Radio Tap Headers並不總是0x12,所以802.11數據從第三個字節+ 1的值開始。

相關問題