diff --git a/run_scapy.bat b/run_scapy.bat index 6c7cf92975764dbb1c751ce143a5dd392d6fec64..ba19aa5e9445a1d453c1f00c0d9e4e6a5bf1590a 100644 --- a/run_scapy.bat +++ b/run_scapy.bat @@ -1,3 +1,3 @@ @echo off set PYTHONPATH=%cd% -python -m scapy +python -m scapy.__init__ diff --git a/scapy/arch/windows/__init__.py b/scapy/arch/windows/__init__.py index a80cbce37c99bf79691b21d119740994c8b635d9..f80eaf2b726edceafd89ae1b3857a17d95353210 100755 --- a/scapy/arch/windows/__init__.py +++ b/scapy/arch/windows/__init__.py @@ -3,14 +3,16 @@ ## Copyright (C) Philippe Biondi <phil@secdev.org> ## This program is published under a GPLv2 license -import os,re,sys,socket +import os,re,sys,socket,time from glob import glob from scapy.config import conf,ConfClass -from scapy.error import Scapy_Exception,log_loading -from scapy.utils import atol -from scapy.base_classes import Gen +from scapy.error import Scapy_Exception,log_loading,log_runtime +from scapy.utils import atol, inet_aton, inet_ntoa, PcapReader +from scapy.base_classes import Gen, Net, SetGen import scapy.plist as plist -from scapy.sendrecv import debug +from scapy.sendrecv import debug, srp1 +from scapy.layers.l2 import Ether, ARP +from scapy.data import MTU, ETHER_BROADCAST, ETH_P_ARP conf.use_pcap = 1 conf.use_dnet = 1 @@ -18,6 +20,7 @@ from scapy.arch import pcapdnet from scapy.arch.pcapdnet import * LOOPBACK_NAME="lo0" +WINDOWS = True def _where(filename, dirs=[], env="PATH"): @@ -51,8 +54,8 @@ def win_find_exe(filename, installsubdir=None, env="ProgramFiles"): class WinProgPath(ConfClass): _default = "<System default>" # We try some magic to find the appropriate executables - pdfreader = _default - psreader = _default + pdfreader = win_find_exe("AcroRd32") + psreader = win_find_exe("gsview32.exe", "Ghostgum/gsview") dot = win_find_exe("dot", "ATT/Graphviz/bin") tcpdump = win_find_exe("windump") tcpreplay = win_find_exe("tcpreplay") @@ -102,11 +105,11 @@ class NetworkInterface(object): def _update_pcapdata(self): """Supplement more info from pypcap and the Windows registry""" - # XXX: We try eth0 - eth9 by bruteforce and match by IP address, + # XXX: We try eth0 - eth29 by bruteforce and match by IP address, # because only the IP is available in both pypcap and dnet. # This may not work with unorthodox network configurations and is # slow because we have to walk through the Windows registry. - for n in range(10): + for n in range(30): guess = "eth%s" % n win_name = pcapdnet.pcap.ex_name(guess) if win_name.endswith("}"): @@ -159,7 +162,10 @@ class NetworkInterfaceDict(IterableUserDict): for i in pcapdnet.dnet.intf(): try: # XXX: Only Ethernet for the moment: localhost is not supported by dnet and pcap - if i["name"].startswith("eth"): + # We only take interfaces that have an IP address, because the IP + # is used for the mapping between dnet and pcap interface names + # and this significantly improves Scapy's startup performance + if i["name"].startswith("eth") and "addr" in i: self.data[i["name"]] = NetworkInterface(i) except (KeyError, PcapNameNotFoundError): pass @@ -243,7 +249,11 @@ def read_routes(): gw = match.group(3) netif = match.group(4) metric = match.group(5) - intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest)) + try: + intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest)) + except OSError: + log_loading.warning("Building Scapy's routing table: Couldn't get outgoing interface for destination %s" % dest) + continue if not intf.has_key("addr"): break addr = str(intf["addr"]) @@ -296,6 +306,9 @@ def getmacbyip(ip, chainCC=0): return mac return None +import scapy.layers.l2 +scapy.layers.l2.getmacbyip = getmacbyip + try: import readline console = readline.GetOutputFile() @@ -511,7 +524,7 @@ L2socket: use the provided L2socket except KeyboardInterrupt: break s.close() - return PacketList(lst,"Sniffed") + return plist.PacketList(lst,"Sniffed") import scapy.sendrecv scapy.sendrecv.sniff = sniff diff --git a/scapy/crypto/cert.py b/scapy/crypto/cert.py old mode 100755 new mode 100644 diff --git a/scapy/packet.py b/scapy/packet.py index 641cf4f4b234fb320a76d6b85a06bfe2ffb72e35..4e3c893c6ce6485a9503b8298d754ab613592250 100644 --- a/scapy/packet.py +++ b/scapy/packet.py @@ -354,7 +354,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary if filename is None: fname = get_temp_file(autoext=".eps") canvas.writeEPSfile(fname) - os.system("%s '%s.eps' &" % (conf.prog.psreader,fname)) + subprocess.Popen([conf.prog.psreader, fname+".eps"]) else: canvas.writeEPSfile(filename) @@ -365,7 +365,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary if filename is None: fname = get_temp_file(autoext=".pdf") canvas.writePDFfile(fname) - os.system("%s '%s.pdf' &" % (conf.prog.pdfreader,fname)) + subprocess.Popen([conf.prog.pdfreader, fname+".pdf"]) else: canvas.writePDFfile(filename) diff --git a/scapy/plist.py b/scapy/plist.py index 716727a04ac71183584bf89791d332707199f3f0..4cb01a7aa88eab6460773d8a590e1d14669f47e5 100644 --- a/scapy/plist.py +++ b/scapy/plist.py @@ -3,7 +3,7 @@ ## Copyright (C) Philippe Biondi <phil@secdev.org> ## This program is published under a GPLv2 license -import os +import os,subprocess from config import conf from base_classes import BasePacket,BasePacketList from packet import Padding @@ -363,7 +363,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis if filename is None: filename = get_temp_file(autoext=".ps") d.writePSfile(filename) - os.system("%s %s.ps &" % (conf.prog.psreader,filename)) + subprocess.Popen([conf.prog.psreader, filename+".ps"]) else: d.writePSfile(filename) print @@ -376,7 +376,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis if filename is None: filename = get_temp_file(autoext=".pdf") d.writePDFfile(filename) - os.system("%s %s.pdf &" % (conf.prog.pdfreader,filename)) + subprocess.Popen([conf.prog.pdfreader, filename+".pdf"]) else: d.writePDFfile(filename) print diff --git a/test/import_tester b/test/import_tester old mode 100755 new mode 100644