From ab08f456467bcab83c505742abf6f18e5c8d7a6c Mon Sep 17 00:00:00 2001 From: gpotter2 <gabriel@potter.fr> Date: Sat, 25 Feb 2017 20:03:59 +0100 Subject: [PATCH] Fix manufdb detection on windows --- scapy/arch/windows/__init__.py | 5 +++++ scapy/data.py | 8 +++++--- test/regression.uts | 11 +++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/scapy/arch/windows/__init__.py b/scapy/arch/windows/__init__.py index c6b345a0..5968fc2f 100755 --- a/scapy/arch/windows/__init__.py +++ b/scapy/arch/windows/__init__.py @@ -6,11 +6,13 @@ """ Customizations needed to support Microsoft Windows. """ + import os,re,sys,socket,time, itertools import subprocess as sp from glob import glob import tempfile +#import scapy.data from scapy.config import conf, ConfClass from scapy.error import Scapy_Exception, log_loading, log_runtime, warning from scapy.utils import atol, itom, inet_aton, inet_ntoa, PcapReader @@ -259,6 +261,9 @@ class WinProgPath(ConfClass): ) self.cscript = win_find_exe("cscript", installsubdir="System32", env="SystemRoot") + if self.wireshark != "wireshark": + manu_path = load_manuf(os.path.sep.join(self.wireshark.split(os.path.sep)[:-1])+os.path.sep+"manuf") + scapy.data.MANUFDB = conf.manufdb = MANUFDB = manu_path conf.prog = WinProgPath() if conf.prog.powershell == "powershell": diff --git a/scapy/data.py b/scapy/data.py index 5a463119..14cb15e3 100644 --- a/scapy/data.py +++ b/scapy/data.py @@ -147,7 +147,8 @@ class ManufDA(DADict): if oui in self: return ":".join([self[oui][0]]+ mac.split(":")[3:]) return mac - + def __repr__(self): + return "\n".join(["<%s %s, %s>" % (i[0], i[1][0], i[1][1]) for i in self.__dict__.items()]) @@ -165,12 +166,12 @@ def load_manuf(filename): lng=shrt else: lng = l[i+2:] - manufdb[oui] = shrt,lng + manufdb[oui] = shrt, lng except Exception,e: log_loading.warning("Couldn't parse one line from [%s] [%r] (%s)" % (filename, l, e)) except IOError: #log_loading.warning("Couldn't open [%s] file" % filename) - pass + return "" return manufdb @@ -179,6 +180,7 @@ if WINDOWS: ETHER_TYPES=load_ethertypes("ethertypes") IP_PROTOS=load_protocols(os.environ["SystemRoot"]+"\system32\drivers\etc\protocol") TCP_SERVICES,UDP_SERVICES=load_services(os.environ["SystemRoot"] + "\system32\drivers\etc\services") + # Default value, will be updated by arch.windows MANUFDB = load_manuf(os.environ["ProgramFiles"] + "\\wireshark\\manuf") else: IP_PROTOS=load_protocols("/etc/protocols") diff --git a/test/regression.uts b/test/regression.uts index bd13bbef..f8bf0b17 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -650,6 +650,17 @@ send_and_sniff(IP(dst="secdev.org")/ICMP()) send_and_sniff(IP(dst="secdev.org")/ICMP(), flt="icmp") send_and_sniff(Ether()/IP(dst="secdev.org")/ICMP()) +############ +############ ++ ManuFDB tests + += __repr__ + +conf.manufdb + += check _resolve_MAC + +assert conf.manufdb._resolve_MAC("00:00:63") == "HP" ############ ############ -- GitLab