Skip to content
Snippets Groups Projects
Commit f0ae619f authored by Phil's avatar Phil
Browse files

Merge

parents 97a52eb8 0568cf7e
No related branches found
No related tags found
No related merge requests found
@echo off @echo off
set PYTHONPATH=%cd% set PYTHONPATH=%cd%
python -m scapy python -m scapy.__init__
...@@ -3,14 +3,16 @@ ...@@ -3,14 +3,16 @@
## Copyright (C) Philippe Biondi <phil@secdev.org> ## Copyright (C) Philippe Biondi <phil@secdev.org>
## This program is published under a GPLv2 license ## This program is published under a GPLv2 license
import os,re,sys,socket import os,re,sys,socket,time
from glob import glob from glob import glob
from scapy.config import conf,ConfClass from scapy.config import conf,ConfClass
from scapy.error import Scapy_Exception,log_loading from scapy.error import Scapy_Exception,log_loading,log_runtime
from scapy.utils import atol from scapy.utils import atol, inet_aton, inet_ntoa, PcapReader
from scapy.base_classes import Gen from scapy.base_classes import Gen, Net, SetGen
import scapy.plist as plist 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_pcap = 1
conf.use_dnet = 1 conf.use_dnet = 1
...@@ -18,6 +20,7 @@ from scapy.arch import pcapdnet ...@@ -18,6 +20,7 @@ from scapy.arch import pcapdnet
from scapy.arch.pcapdnet import * from scapy.arch.pcapdnet import *
LOOPBACK_NAME="lo0" LOOPBACK_NAME="lo0"
WINDOWS = True
def _where(filename, dirs=[], env="PATH"): def _where(filename, dirs=[], env="PATH"):
...@@ -51,8 +54,8 @@ def win_find_exe(filename, installsubdir=None, env="ProgramFiles"): ...@@ -51,8 +54,8 @@ def win_find_exe(filename, installsubdir=None, env="ProgramFiles"):
class WinProgPath(ConfClass): class WinProgPath(ConfClass):
_default = "<System default>" _default = "<System default>"
# We try some magic to find the appropriate executables # We try some magic to find the appropriate executables
pdfreader = _default pdfreader = win_find_exe("AcroRd32")
psreader = _default psreader = win_find_exe("gsview32.exe", "Ghostgum/gsview")
dot = win_find_exe("dot", "ATT/Graphviz/bin") dot = win_find_exe("dot", "ATT/Graphviz/bin")
tcpdump = win_find_exe("windump") tcpdump = win_find_exe("windump")
tcpreplay = win_find_exe("tcpreplay") tcpreplay = win_find_exe("tcpreplay")
...@@ -102,11 +105,11 @@ class NetworkInterface(object): ...@@ -102,11 +105,11 @@ class NetworkInterface(object):
def _update_pcapdata(self): def _update_pcapdata(self):
"""Supplement more info from pypcap and the Windows registry""" """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. # because only the IP is available in both pypcap and dnet.
# This may not work with unorthodox network configurations and is # This may not work with unorthodox network configurations and is
# slow because we have to walk through the Windows registry. # slow because we have to walk through the Windows registry.
for n in range(10): for n in range(30):
guess = "eth%s" % n guess = "eth%s" % n
win_name = pcapdnet.pcap.ex_name(guess) win_name = pcapdnet.pcap.ex_name(guess)
if win_name.endswith("}"): if win_name.endswith("}"):
...@@ -159,7 +162,10 @@ class NetworkInterfaceDict(IterableUserDict): ...@@ -159,7 +162,10 @@ class NetworkInterfaceDict(IterableUserDict):
for i in pcapdnet.dnet.intf(): for i in pcapdnet.dnet.intf():
try: try:
# XXX: Only Ethernet for the moment: localhost is not supported by dnet and pcap # 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) self.data[i["name"]] = NetworkInterface(i)
except (KeyError, PcapNameNotFoundError): except (KeyError, PcapNameNotFoundError):
pass pass
...@@ -243,7 +249,11 @@ def read_routes(): ...@@ -243,7 +249,11 @@ def read_routes():
gw = match.group(3) gw = match.group(3)
netif = match.group(4) netif = match.group(4)
metric = match.group(5) metric = match.group(5)
try:
intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest)) 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"): if not intf.has_key("addr"):
break break
addr = str(intf["addr"]) addr = str(intf["addr"])
...@@ -296,6 +306,9 @@ def getmacbyip(ip, chainCC=0): ...@@ -296,6 +306,9 @@ def getmacbyip(ip, chainCC=0):
return mac return mac
return None return None
import scapy.layers.l2
scapy.layers.l2.getmacbyip = getmacbyip
try: try:
import readline import readline
console = readline.GetOutputFile() console = readline.GetOutputFile()
...@@ -511,7 +524,7 @@ L2socket: use the provided L2socket ...@@ -511,7 +524,7 @@ L2socket: use the provided L2socket
except KeyboardInterrupt: except KeyboardInterrupt:
break break
s.close() s.close()
return PacketList(lst,"Sniffed") return plist.PacketList(lst,"Sniffed")
import scapy.sendrecv import scapy.sendrecv
scapy.sendrecv.sniff = sniff scapy.sendrecv.sniff = sniff
... ...
......
File mode changed from 100755 to 100644
...@@ -354,7 +354,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary ...@@ -354,7 +354,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary
if filename is None: if filename is None:
fname = get_temp_file(autoext=".eps") fname = get_temp_file(autoext=".eps")
canvas.writeEPSfile(fname) canvas.writeEPSfile(fname)
os.system("%s '%s.eps' &" % (conf.prog.psreader,fname)) subprocess.Popen([conf.prog.psreader, fname+".eps"])
else: else:
canvas.writeEPSfile(filename) canvas.writeEPSfile(filename)
...@@ -365,7 +365,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary ...@@ -365,7 +365,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary
if filename is None: if filename is None:
fname = get_temp_file(autoext=".pdf") fname = get_temp_file(autoext=".pdf")
canvas.writePDFfile(fname) canvas.writePDFfile(fname)
os.system("%s '%s.pdf' &" % (conf.prog.pdfreader,fname)) subprocess.Popen([conf.prog.pdfreader, fname+".pdf"])
else: else:
canvas.writePDFfile(filename) canvas.writePDFfile(filename)
... ...
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
## Copyright (C) Philippe Biondi <phil@secdev.org> ## Copyright (C) Philippe Biondi <phil@secdev.org>
## This program is published under a GPLv2 license ## This program is published under a GPLv2 license
import os import os,subprocess
from config import conf from config import conf
from base_classes import BasePacket,BasePacketList from base_classes import BasePacket,BasePacketList
from packet import Padding from packet import Padding
...@@ -363,7 +363,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis ...@@ -363,7 +363,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis
if filename is None: if filename is None:
filename = get_temp_file(autoext=".ps") filename = get_temp_file(autoext=".ps")
d.writePSfile(filename) d.writePSfile(filename)
os.system("%s %s.ps &" % (conf.prog.psreader,filename)) subprocess.Popen([conf.prog.psreader, filename+".ps"])
else: else:
d.writePSfile(filename) d.writePSfile(filename)
print print
...@@ -376,7 +376,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis ...@@ -376,7 +376,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis
if filename is None: if filename is None:
filename = get_temp_file(autoext=".pdf") filename = get_temp_file(autoext=".pdf")
d.writePDFfile(filename) d.writePDFfile(filename)
os.system("%s %s.pdf &" % (conf.prog.pdfreader,filename)) subprocess.Popen([conf.prog.pdfreader, filename+".pdf"])
else: else:
d.writePDFfile(filename) d.writePDFfile(filename)
print print
... ...
......
File mode changed from 100755 to 100644
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment