from scapy.config import conf from scapy.compat import raw from scapy.layers.inet import IP, TCP, TCPOptions from scapy.packet import NoPayload, Packet from scapy.error import warning, Scapy_Exception, log_runtime from scapy.volatile import RandInt, RandByte, RandNum, RandShort, RandString from scapy.sendrecv import sniff from scapy.modules import six from scapy.modules.six.moves import map, range if conf.route is None: # unused import, only to initialize conf.route import scapy.route # noqa: F401 _p0fpaths = ["/etc/p0f", "/usr/share/p0f", "/opt/local"] conf.p0f_base = select_path(_p0fpaths, "p0f.fp") conf.p0fa_base = select_path(_p0fpaths, "p0fa.fp") conf.p0fr_base = select_path(_p0fpaths, "p0fr.fp") conf.p0fo_base = select_path(_p0fpaths, "p0fo.fp") ############### # p0f stuff # ############### # File format (according to p0f.fp) : # # wwww:ttt:D:ss:OOO...:QQ:OS:Details # # wwww - window size # ttt - initial TTL # D - don't fragment bit (0=unset, 1=set)
import random from scapy.data import KnowledgeBase, select_path from scapy.config import conf from scapy.compat import raw, orb from scapy.packet import NoPayload from scapy.layers.inet import IP, TCP, TCPOptions from scapy.layers.http import HTTP, HTTPRequest, HTTPResponse from scapy.layers.inet6 import IPv6 from scapy.volatile import RandByte, RandShort, RandString from scapy.error import warning from scapy.modules.six import integer_types, string_types from scapy.modules.six.moves import range _p0fpaths = ["/etc/p0f", "/usr/share/p0f", "/opt/local"] conf.p0f_base = select_path(_p0fpaths, "p0f.fp") MIN_TCP4 = 40 # Min size of IPv4/TCP headers MIN_TCP6 = 60 # Min size of IPv6/TCP headers MAX_DIST = 35 # Maximum TTL distance for non-fuzzy signature matching WIN_TYPE_NORMAL = 0 # Literal value WIN_TYPE_ANY = 1 # Wildcard WIN_TYPE_MOD = 2 # Modulo check WIN_TYPE_MSS = 3 # Window size MSS multiplier WIN_TYPE_MTU = 4 # Window size MTU multiplier # Convert TCP option num to p0f (nop is handled separately) tcp_options_p0f = { 2: "mss", # maximum segment size 3: "ws", # window scaling