예제 #1
0
class SecurityExtension(scapy.Packet):
    name = "SCION Security Extension"
    fields_desc = [
        scapy.BitEnumField('next_hdr', None, 8, scapy.IP_PROTOS),
        scapy.ByteField('hdr_len', None),
        scapy.XByteField('extType', 0x2),
        scapy.ByteEnumField("secMode", 0x0, {
            0x0: "AES-CMAC",
            0x1: "HMAC_SHA256",
            0x2: "Ed25519",
            0x3: "GCM_AES128"
        }),
        scapy.XBitField('metadata', 0xffffffff, 4 * 8),
        scapy.MultipleTypeField([
            (scapy.XBitField('authenticator', None,
                             16 * 8), lambda pkt: pkt.secMode == 0x0),
            (scapy.XBitField('authenticator', None,
                             32 * 8), lambda pkt: pkt.secMode == 0x1),
            (scapy.XBitField('authenticator', None,
                             64 * 8), lambda pkt: pkt.secMode == 0x2),
            (scapy.XBitField('authenticator', None,
                             16 * 8), lambda pkt: pkt.secMode == 0x3),
        ], scapy.StrField("authenticator", None)),
    ]

    def extract_padding(self, p):
        # TODO fix when removing hard-coded v4
        return "", p

    def post_build(self, pkt, pay):
        if self.hdr_len == None:
            self.hdr_len = len(pkt)
            pkt = pkt[:1] + struct.pack('B', int(self.hdr_len / 8)) + pkt[2:]
        return pkt + pay
예제 #2
0
class HopField(scapy.Packet):
    IMMUTABLE_FLAGS = 0x0  # TODO
    FLAGS = 0
    RANGE_SKIP_FLAGS = 1
    RANGE_END = 8
    RANGE_BEFORE_MAC = 5
    name = 'SCION Hop field'
    fields_desc = [
        scapy.XBitField('flags', 0x0, 8),
        scapy.ByteField('expiry', 63),
        scapy.BitField('ingress_if', None, 12),
        scapy.BitField('egress_if', None, 12),
        scapy.XBitField('mac', None, 3 * 8),  # TODO
    ]

    def extract_padding(self, p):
        return "", p
예제 #3
0
assert sys.version_info >= (
    3,
), "Due to incompatibilities around handling bytes, this only works under Python 3"

from scapy.all import Ether, IP, UDP
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import cmac
from cryptography.hazmat.primitives.ciphers import algorithms

HF_MAC_KEY = b'\0' * 15 + b'\x47'  # 128w0x47

SCION_ADDR_TYPE = {1: 'ipv4', 2: 'ipv6', 3: 'svc'}

ISDField = scapy.ShortField
ASField = lambda name, default: scapy.XBitField(name, default, 6 * 8)


def raw(packet):
    return str(packet)  # would be bytes in python3


class UnixTimeField(scapy.IntField):
    def i2repr(self, pkt, x):
        if x is None: return None
        return time.strftime('%d %b %Y %H:%M:%S UTC', time.gmtime(x))


class ISD_AS(scapy.Packet):
    name = 'ISD-AS'
    fields_desc = [