J'essaie actuellement d'analyser le trafic USB entrant en utilisant USBPcap + Python/dpkt, avec une souris USB optique comme périphérique d'entrée.Comment lire depuis stdin en utilisant dpkt.pcap.Reader?
Après le lancement de fichier batch contenant la commande
USBPcapCMD.exe -d \\.\USBPcap7 -o - | pipetest.py
le code suivant fonctionne parfaitement:
# pipetest.py
# sniffing for USB-mouse activities
import sys
import dpkt, struct
try:
f = open('c:\\users\\user\\downloads\\test.pcap','wb')
while True:
inpt = sys.stdin.read(34) # package length
f.write(inpt)
except KeyboardInterrupt:
f.close()
f = open('c:\\users\\user\\downloads\\test.pcap','rb')
pcap = dpkt.pcap.Reader(f)
print
for ts, buf in pcap:
data = struct.unpack("b"*7, buf[-7:]) # 7-byte leftover with mouse info
print data
f.close()
sortie est:
34
34
34
34
34
34
34
34
34
34
34
34
^C
(3, 4, 0, 0, 0, 0, 0) <---|
(3, 0, 0, 0, 0, 0, 0) |
(3, 4, 0, 0, 0, 0, 0) <---|
(3, 0, 0, 0, 0, 0, 0) |------ Four clicks with mouse wheel
(3, 4, 0, 0, 0, 0, 0) <---|
(3, 0, 0, 0, 0, 0, 0) |
(3, 4, 0, 0, 0, 0, 0) <---|
(0, 0, 0, 9, 0, 1, 7)
Malheureusement, j'ai un problème avec Analyse LIVE des données capturées. Comment puis-je obtenir dpkt.pcap.Reader() pour travailler avec sys.stdin au lieu d'ouvrir ('foo.pcap')?
P.S. Je peux sûrement faire
USBPcapCMD.exe -d \\.\USBPcap2 -o - | "C:\Program Files\Wireshark\Wireshark.exe" -k -i -
comme le montre official mini-tutorial mais je voudrais effectuer le trafic USB en temps réel à l'aide sniffeur USB + Python.
P.P.S. Python/PyUSB + libusb-win32 fonctionne parfaitement mais j'ai besoin d'USBPcap! :)