Skip to content
Snippets Groups Projects
regression.uts 351 KiB
Newer Older
assert all(isinstance(LLTDAttribute(str(LLTDAttribute(type=i))), LLTDAttribute) for i in xrange(256))

= Large TLV
m1, m2, seq = RandMAC()._fix(), RandMAC()._fix(), 123
preqbase = Ether(src=m1, dst=m2) / LLTD() / \
           LLTDQueryLargeTlv(type="Detailed Icon Image")
prespbase = Ether(src=m2, dst=m1) / LLTD() / \
            LLTDQueryLargeTlvResp()
plist = []
pkt = preqbase.copy()
pkt.seq = seq
plist.append(Ether(str(pkt)))
pkt = prespbase.copy()
pkt.seq = seq
pkt.flags = "M"
pkt.value = "abcd"
plist.append(Ether(str(pkt)))
pkt = preqbase.copy()
pkt.seq = seq + 1
pkt.offset = 4
plist.append(Ether(str(pkt)))
pkt = prespbase.copy()
pkt.seq = seq + 1
pkt.value = "efg"
plist.append(Ether(str(pkt)))
builder = LargeTlvBuilder()
builder.parse(plist)
data = builder.get_data()
assert len(data) == 1
key, value = data.popitem()
assert key.endswith(' [Detailed Icon Image]')
assert value == 'abcdefg'

############
############
+ Test fragment() / defragment() functions

= fragment()
payloadlen, fragsize = 100, 8
assert fragsize % 8 == 0
fragcount = (payloadlen / fragsize) + bool(payloadlen % fragsize)
* create the packet
pkt = IP() / ("X" * payloadlen)
* create the fragments
frags = fragment(pkt, fragsize)
* count the fragments
assert len(frags) == fragcount
* each fragment except the last one should have MF set
assert all(p.flags == 1 for p in frags[:-1])
assert frags[-1].flags == 0
* each fragment except the last one should have a payload of fragsize bytes
assert all(len(p.payload) == 8 for p in frags[:-1])
assert len(frags[-1].payload) == ((payloadlen % fragsize) or fragsize)

= fragment() and overloaded_fields
pkt1 = Ether() / IP() / UDP()
pkt2 = fragment(pkt1)[0]
pkt3 = pkt2.__class__(str(pkt2))
assert pkt1[IP].proto == pkt2[IP].proto == pkt3[IP].proto

= fragment() already fragmented packets
payloadlen = 1480 * 3
ffrags = fragment(IP() / ("X" * payloadlen), 1480)
ffrags = fragment(ffrags, 1400)
len(ffrags) == 6
* each fragment except the last one should have MF set
assert all(p.flags == 1 for p in ffrags[:-1])
assert ffrags[-1].flags == 0
* fragment offset should be well computed
plen = 0
for p in ffrags:
    assert p.frag == plen / 8
    plen += len(p.payload)

assert plen == payloadlen

Pierre LALET's avatar
Pierre LALET committed
= defrag()
nonfrag, unfrag, badfrag = defrag(frags)
assert not nonfrag
assert not badfrag
assert len(unfrag) == 1

= defragment()
defrags = defragment(frags)
* we should have one single packet
assert len(defrags) == 1
* which should be the same as pkt reconstructed
assert defrags[0] == IP(str(pkt))
Pierre LALET's avatar
Pierre LALET committed
= Packet().fragment()
payloadlen, fragsize = 100, 8
assert fragsize % 8 == 0
fragcount = (payloadlen / fragsize) + bool(payloadlen % fragsize)
* create the packet
pkt = IP() / ("X" * payloadlen)
* create the fragments
frags = pkt.fragment(fragsize)
* count the fragments
assert len(frags) == fragcount
* each fragment except the last one should have MF set
assert all(p.flags == 1 for p in frags[:-1])
assert frags[-1].flags == 0
* each fragment except the last one should have a payload of fragsize bytes
assert all(len(p.payload) == 8 for p in frags[:-1])
assert len(frags[-1].payload) == ((payloadlen % fragsize) or fragsize)

= Packet().fragment() and overloaded_fields
pkt1 = Ether() / IP() / UDP()
pkt2 = pkt1.fragment()[0]
pkt3 = pkt2.__class__(str(pkt2))
assert pkt1[IP].proto == pkt2[IP].proto == pkt3[IP].proto

= Packet().fragment() already fragmented packets
payloadlen = 1480 * 3
ffrags = (IP() / ("X" * payloadlen)).fragment(1480)
ffrags = reduce(lambda x, y: x + y, (pkt.fragment(1400) for pkt in ffrags))
len(ffrags) == 6
* each fragment except the last one should have MF set
assert all(p.flags == 1 for p in ffrags[:-1])
assert ffrags[-1].flags == 0
* fragment offset should be well computed
plen = 0
for p in ffrags:
    assert p.frag == plen / 8
    plen += len(p.payload)

assert plen == payloadlen


############
############

= TCP options: UTO - basic build
gpotter2's avatar
gpotter2 committed
str(TCP(options=[("UTO", 0xffff)])) == b"\x00\x14\x00\x50\x00\x00\x00\x00\x00\x00\x00\x00\x60\x02\x20\x00\x00\x00\x00\x00\x1c\x04\xff\xff"

= TCP options: UTO - basic dissection
gpotter2's avatar
gpotter2 committed
uto = TCP(b"\x00\x14\x00\x50\x00\x00\x00\x00\x00\x00\x00\x00\x60\x02\x20\x00\x00\x00\x00\x00\x1c\x04\xff\xff")
uto[TCP].options[0][0] == "UTO" and uto[TCP].options[0][1] == 0xffff

= IP, TCP & UDP checksums (these tests highly depend on default values)
pkt = IP() / TCP()
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7ccd and bpkt.payload.chksum == 0x917c

pkt = IP(len=40) / TCP()
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7ccd and bpkt.payload.chksum == 0x917c

pkt = IP(len=40, ihl=5) / TCP()
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7ccd and bpkt.payload.chksum == 0x917c

pkt = IP() / TCP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7cc3 and bpkt.payload.chksum == 0x4b2c

pkt = IP(len=50) / TCP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7cc3 and bpkt.payload.chksum == 0x4b2c

pkt = IP(len=50, ihl=5) / TCP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7cc3 and bpkt.payload.chksum == 0x4b2c

pkt = IP(options=[IPOption_RR()]) / TCP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x70bc and bpkt.payload.chksum == 0x4b2c

pkt = IP(len=54, options=[IPOption_RR()]) / TCP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x70bc and bpkt.payload.chksum == 0x4b2c

pkt = IP(len=54, ihl=6, options=[IPOption_RR()]) / TCP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x70bc and bpkt.payload.chksum == 0x4b2c

pkt = IP() / UDP()
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7cce and bpkt.payload.chksum == 0x0172

pkt = IP(len=28) / UDP()
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7cce and bpkt.payload.chksum == 0x0172

pkt = IP(len=28, ihl=5) / UDP()
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7cce and bpkt.payload.chksum == 0x0172

pkt = IP() / UDP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7cc4 and bpkt.payload.chksum == 0xbb17

pkt = IP(len=38) / UDP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7cc4 and bpkt.payload.chksum == 0xbb17

pkt = IP(len=38, ihl=5) / UDP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x7cc4 and bpkt.payload.chksum == 0xbb17

pkt = IP(options=[IPOption_RR()]) / UDP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x70bd and bpkt.payload.chksum == 0xbb17

pkt = IP(len=42, options=[IPOption_RR()]) / UDP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x70bd and bpkt.payload.chksum == 0xbb17

pkt = IP(len=42, ihl=6, options=[IPOption_RR()]) / UDP() / ("A" * 10)
bpkt = IP(str(pkt))
assert bpkt.chksum == 0x70bd and bpkt.payload.chksum == 0xbb17
= DNS

* DNS over UDP
pkt = IP(str(IP(src="10.0.0.1", dst="8.8.8.8")/UDP(sport=RandShort(), dport=53)/DNS(qd=DNSQR(qname="secdev.org."))))
assert UDP in pkt and isinstance(pkt[UDP].payload, DNS)
assert pkt[UDP].dport == 53 and pkt[UDP].length is None
assert pkt[DNS].qdcount == 1 and pkt[DNS].qd.qname == "secdev.org."

* DNS over TCP
pkt = IP(str(IP(src="10.0.0.1", dst="8.8.8.8")/TCP(sport=RandShort(), dport=53, flags="P")/DNS(qd=DNSQR(qname="secdev.org."))))
assert TCP in pkt and isinstance(pkt[TCP].payload, DNS)
assert pkt[TCP].dport == 53 and pkt[DNS].length is not None
assert pkt[DNS].qdcount == 1 and pkt[DNS].qd.qname == "secdev.org."

= Layer binding

* Test DestMACField & DestIPField
pkt = Ether(str(Ether()/IP()/UDP(dport=5353)/DNS()))
assert isinstance(pkt, Ether) and pkt.dst == '01:00:5e:00:00:fb'
pkt = pkt.payload
assert isinstance(pkt, IP) and pkt.dst == '224.0.0.251'
pkt = pkt.payload
assert isinstance(pkt, UDP) and pkt.dport == 5353
pkt = pkt.payload
assert isinstance(pkt, DNS) and isinstance(pkt.payload, NoPayload)

* Same with IPv6
pkt = Ether(str(Ether()/IPv6()/UDP(dport=5353)/DNS()))
assert isinstance(pkt, Ether) and pkt.dst == '33:33:00:00:00:fb'
pkt = pkt.payload
assert isinstance(pkt, IPv6) and pkt.dst == 'ff02::fb'
pkt = pkt.payload
assert isinstance(pkt, UDP) and pkt.dport == 5353
pkt = pkt.payload
assert isinstance(pkt, DNS) and isinstance(pkt.payload, NoPayload)
+ Mocked read_routes() calls

= Truncated netstat -rn output on OS X
Guillaume Valadon's avatar
Guillaume Valadon committed
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.get_if_addr")
@mock.patch("scapy.arch.unix.os")
def test_osx_netstat_truncated(mock_os, mock_get_if_addr):
    """Test read_routes() on OS X 10.? with a long interface name"""
    # netstat & ifconfig outputs from https://github.com/secdev/scapy/pull/119
    netstat_output = """
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.1.1        UGSc          460        0     en1
default            link#11            UCSI            1        0 bridge1
127                127.0.0.1          UCS             1        0     lo0
127.0.0.1          127.0.0.1          UH             10  2012351     lo0
"""
    ifconfig_output = "lo0 en1 bridge10\n"
    # Mocked file descriptors
    def se_popen(command):
        """Perform specific side effects"""
        if command.startswith("netstat -rn"):
gpotter2's avatar
gpotter2 committed
            return StringIO.StringIO(netstat_output)
        elif command == "ifconfig -l":
gpotter2's avatar
gpotter2 committed
            ret = StringIO.StringIO(ifconfig_output)
            def unit():
                return ret
            ret.__call__ = unit
            ret.__enter__ = unit
            ret.__exit__ = lambda x,y,z: None
            return ret
        raise Exception("Command not mocked: %s" % command)
    mock_os.popen.side_effect = se_popen
    # Mocked get_if_addr() behavior
    def se_get_if_addr(iface):
        """Perform specific side effects"""
        if iface == "bridge1":
gpotter2's avatar
gpotter2 committed
            oserror_exc = OSError()
            oserror_exc.message = "Device not configured"
            raise oserror_exc
        return "1.2.3.4"
    mock_get_if_addr.side_effect = se_get_if_addr
    # Test the function
    from scapy.arch.unix import read_routes
    routes = read_routes()
    assert(len(routes) == 4)
    assert([r for r in routes if r[3] == "bridge10"])


test_osx_netstat_truncated()

+ Mocked read_routes6() calls

= Preliminary definitions
Guillaume Valadon's avatar
Guillaume Valadon committed
~ mock_read_routes6_bsd

import mock
import StringIO

def valid_output_read_routes6(routes):
    """"Return True if 'routes' contains correctly formatted entries, False otherwise"""
    for destination, plen, next_hop, dev, cset  in routes:
        if not in6_isvalid(destination) or not type(plen) == int:
            return False
        if not in6_isvalid(next_hop) or not type(dev) == str:
            return False
        for address in cset:
            if not in6_isvalid(address):
                return False
    return True

def check_mandatory_ipv6_routes(routes6):
    """Ensure that mandatory IPv6 routes are present"""
    if len(filter(lambda r: r[0] == "::1" and r[-1] == ["::1"], routes6)) < 1:
        return False
    if len(filter(lambda r: r[0] == "fe80::" and r[1] == 64, routes6)) < 1:
        return False
    if len(filter(lambda r: in6_islladdr(r[0]) and r[1] == 128 and \
            r[-1] == ["::1"], routes6)) < 1:
        return False
    return True


= Mac OS X 10.9.5
Guillaume Valadon's avatar
Guillaume Valadon committed
~ mock_read_routes6_bsd

@mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os")
def test_osx_10_9_5(mock_os, mock_in6_getifaddr):
    """Test read_routes6() on OS X 10.9.5"""
    # 'netstat -rn -f inet6' output
    netstat_output = """
Routing tables

Internet6:
Destination                             Gateway                         Flags         Netif Expire
::1                                     ::1                             UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en0/64                           link#4                          UCI             en0
fe80::ba26:6cff:fe5f:4eee%en0           b8:26:6c:5f:4e:ee               UHLWIi          en0
fe80::bae8:56ff:fe45:8ce6%en0           b8:e8:56:45:8c:e6               UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en0/32                           link#4                          UmCI            en0
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%en0/32                           link#4                          UmCI            en0
"""
    # Mocked file descriptor
    strio = StringIO.StringIO(netstat_output)
    mock_os.popen = mock.MagicMock(return_value=strio)
    # Mocked in6_getifaddr() output
    mock_in6_getifaddr.return_value = [("::1", IPV6_ADDR_LOOPBACK, "lo0"),
                                       ("fe80::ba26:6cff:fe5f:4eee", IPV6_ADDR_LINKLOCAL, "en0")]
    # Test the function
    from scapy.arch.unix import read_routes6
    routes = read_routes6()
    for r in routes:
        print r
    assert(len(routes) == 6)
    assert(check_mandatory_ipv6_routes(routes))

test_osx_10_9_5()


= Mac OS X 10.9.5 with global IPv6 connectivity
Guillaume Valadon's avatar
Guillaume Valadon committed
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os")
def test_osx_10_9_5_global(mock_os, mock_in6_getifaddr):
    """Test read_routes6() on OS X 10.9.5 with an IPv6 connectivity"""
    # 'netstat -rn -f inet6' output
    netstat_output = """
Routing tables

Internet6:
Destination                             Gateway                         Flags         Netif Expire
default                                 fe80::ba26:8aff:fe5f:4eef%en0   UGc             en0
::1                                     ::1                             UHL             lo0
2a01:ab09:7d:1f01::/64                  link#4                          UC              en0
2a01:ab09:7d:1f01:420:205c:9fab:5be7    b8:e9:55:44:7c:e5               UHL             lo0
2a01:ab09:7d:1f01:ba26:8aff:fe5f:4eef   b8:26:8a:5f:4e:ef               UHLWI           en0
2a01:ab09:7d:1f01:bae9:55ff:fe44:7ce5   b8:e9:55:44:7c:e5               UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en0/64                           link#4                          UCI             en0
fe80::5664:d9ff:fe79:4e00%en0           54:64:d9:79:4e:0                UHLWI           en0
fe80::6ead:f8ff:fe74:945a%en0           6c:ad:f8:74:94:5a               UHLWI           en0
fe80::a2f3:c1ff:fec4:5b50%en0           a0:f3:c1:c4:5b:50               UHLWI           en0
fe80::ba26:8aff:fe5f:4eef%en0           b8:26:8a:5f:4e:ef               UHLWIir         en0
fe80::bae9:55ff:fe44:7ce5%en0           b8:e9:55:44:7c:e5               UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en0/32                           link#4                          UmCI            en0
ff02::%lo0/32                           ::1                             UmCI            lo
"""
    # Mocked file descriptor
    strio = StringIO.StringIO(netstat_output)
    mock_os.popen = mock.MagicMock(return_value=strio)
    # Mocked in6_getifaddr() output
    mock_in6_getifaddr.return_value = [("::1", IPV6_ADDR_LOOPBACK, "lo0"),
                                       ("fe80::ba26:6cff:fe5f:4eee", IPV6_ADDR_LINKLOCAL, "en0")]
    # Test the function
    from scapy.arch.unix import read_routes6
    routes = read_routes6()
    assert(valid_output_read_routes6(routes))
    for r in routes:
        print r
    assert(len(routes) == 11)
    assert(check_mandatory_ipv6_routes(routes))

test_osx_10_9_5_global()


= Mac OS X 10.10.4
Guillaume Valadon's avatar
Guillaume Valadon committed
~ mock_read_routes6_bsd

@mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os")
def test_osx_10_10_4(mock_os, mock_in6_getifaddr):
    """Test read_routes6() on OS X 10.10.4"""
    # 'netstat -rn -f inet6' output
    netstat_output = """
Routing tables

Internet6:
Destination                             Gateway                         Flags         Netif Expire
::1                                     ::1                             UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en0/64                           link#4                          UCI             en0
fe80::a00:27ff:fe9b:c965%en0            8:0:27:9b:c9:65                 UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en0/32                           link#4                          UmCI            en0
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%en0/32                           link#4                          UmCI            en0
"""
    # Mocked file descriptor
    strio = StringIO.StringIO(netstat_output)
    mock_os.popen = mock.MagicMock(return_value=strio)
    # Mocked in6_getifaddr() output
    mock_in6_getifaddr.return_value = [("::1", IPV6_ADDR_LOOPBACK, "lo0"),
                                       ("fe80::a00:27ff:fe9b:c965", IPV6_ADDR_LINKLOCAL, "en0")]
    # Test the function
    from scapy.arch.unix import read_routes6
    routes = read_routes6()
    for r in routes:
        print r
    assert(len(routes) == 5)
    assert(check_mandatory_ipv6_routes(routes))

test_osx_10_10_4()


= FreeBSD 10.2
Guillaume Valadon's avatar
Guillaume Valadon committed
~ mock_read_routes6_bsd

@mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os")
def test_freebsd_10_2(mock_os, mock_in6_getifaddr):
    """Test read_routes6() on FreeBSD 10.2"""
    # 'netstat -rn -f inet6' output
    netstat_output = """
Routing tables

Internet6:
Destination                       Gateway                       Flags      Netif Expire
::/96                             ::1                           UGRS        lo0
::1                               link#2                        UH          lo0
::ffff:0.0.0.0/96                 ::1                           UGRS        lo0
fe80::/10                         ::1                           UGRS        lo0
fe80::%lo0/64                     link#2                        U           lo0
fe80::1%lo0                       link#2                        UHS         lo0
ff01::%lo0/32                     ::1                           U           lo0
ff02::/16                         ::1                           UGRS        lo0
ff02::%lo0/32                     ::1                           U           lo0
"""
    # Mocked file descriptor
    strio = StringIO.StringIO(netstat_output)
    mock_os.popen = mock.MagicMock(return_value=strio)
    # Mocked in6_getifaddr() output
    mock_in6_getifaddr.return_value = [("::1", IPV6_ADDR_LOOPBACK, "lo0")]
    # Test the function
    from scapy.arch.unix import read_routes6
    routes = read_routes6()
    for r in routes:
        print r
    assert(len(routes) == 3)
    assert(check_mandatory_ipv6_routes(routes))

test_freebsd_10_2()


= OpenBSD 5.5
Guillaume Valadon's avatar
Guillaume Valadon committed
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.OPENBSD")
@mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os")
def test_openbsd_5_5(mock_os, mock_in6_getifaddr, mock_openbsd):
    """Test read_routes6() on OpenBSD 5.5"""
    # 'netstat -rn -f inet6' output
    netstat_output = """
Routing tables

Internet6:
Destination                        Gateway                        Flags   Refs      Use   Mtu  Prio Iface
::/104                             ::1                            UGRS       0        0     -     8 lo0  
::/96                              ::1                            UGRS       0        0     -     8 lo0  
::1                                ::1                            UH        14        0 33144     4 lo0  
::127.0.0.0/104                    ::1                            UGRS       0        0     -     8 lo0  
::224.0.0.0/100                    ::1                            UGRS       0        0     -     8 lo0  
::255.0.0.0/104                    ::1                            UGRS       0        0     -     8 lo0  
::ffff:0.0.0.0/96                  ::1                            UGRS       0        0     -     8 lo0  
2002::/24                          ::1                            UGRS       0        0     -     8 lo0  
2002:7f00::/24                     ::1                            UGRS       0        0     -     8 lo0  
2002:e000::/20                     ::1                            UGRS       0        0     -     8 lo0  
2002:ff00::/24                     ::1                            UGRS       0        0     -     8 lo0  
fe80::/10                          ::1                            UGRS       0        0     -     8 lo0  
fe80::%em0/64                      link#1                         UC         0        0     -     4 em0  
fe80::a00:27ff:fe04:59bf%em0       08:00:27:04:59:bf              UHL        0        0     -     4 lo0  
fe80::%lo0/64                      fe80::1%lo0                    U          0        0     -     4 lo0  
fe80::1%lo0                        link#3                         UHL        0        0     -     4 lo0  
fec0::/10                          ::1                            UGRS       0        0     -     8 lo0  
ff01::/16                          ::1                            UGRS       0        0     -     8 lo0  
ff01::%em0/32                      link#1                         UC         0        0     -     4 em0  
ff01::%lo0/32                      fe80::1%lo0                    UC         0        0     -     4 lo0  
ff02::/16                          ::1                            UGRS       0        0     -     8 lo0  
ff02::%em0/32                      link#1                         UC         0        0     -     4 em0  
ff02::%lo0/32                      fe80::1%lo0                    UC         0        0     -     4 lo0 
"""
    # Mocked file descriptor
    strio = StringIO.StringIO(netstat_output)
    mock_os.popen = mock.MagicMock(return_value=strio)
    
    # Mocked in6_getifaddr() output
    mock_in6_getifaddr.return_value = [("::1", IPV6_ADDR_LOOPBACK, "lo0"),
                                       ("fe80::a00:27ff:fe04:59bf", IPV6_ADDR_LINKLOCAL, "em0")]
    # Mocked OpenBSD parsing behavior
    mock_openbsd = True
    # Test the function
    from scapy.arch.unix import read_routes6
    routes = read_routes6()
    for r in routes:
        print r
    assert(len(routes) == 5)
    assert(check_mandatory_ipv6_routes(routes))

test_openbsd_5_5()


= NetBSD 7.0
Guillaume Valadon's avatar
Guillaume Valadon committed
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.NETBSD")
@mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os")
def test_netbsd_7_0(mock_os, mock_in6_getifaddr, mock_netbsd):
    """Test read_routes6() on NetBSD 7.0"""
    # 'netstat -rn -f inet6' output
    netstat_output = """
Routing tables

Internet6:
Destination                        Gateway                        Flags    Refs      Use    Mtu Interface
::/104                             ::1                            UGRS        -        -      -  lo0
::/96                              ::1                            UGRS        -        -      -  lo0
::1                                ::1                            UH          -        -  33648  lo0
::127.0.0.0/104                    ::1                            UGRS        -        -      -  lo0
::224.0.0.0/100                    ::1                            UGRS        -        -      -  lo0
::255.0.0.0/104                    ::1                            UGRS        -        -      -  lo0
::ffff:0.0.0.0/96                  ::1                            UGRS        -        -      -  lo0
2001:db8::/32                      ::1                            UGRS        -        -      -  lo0
2002::/24                          ::1                            UGRS        -        -      -  lo0
2002:7f00::/24                     ::1                            UGRS        -        -      -  lo0
2002:e000::/20                     ::1                            UGRS        -        -      -  lo0
2002:ff00::/24                     ::1                            UGRS        -        -      -  lo0
fe80::/10                          ::1                            UGRS        -        -      -  lo0
fe80::%wm0/64                      link#1                         UC          -        -      -  wm0
fe80::acd1:3989:180e:fde0          08:00:27:a1:64:d8              UHL         -        -      -  lo0
fe80::%lo0/64                      fe80::1                        U           -        -      -  lo0
fe80::1                            link#2                         UHL         -        -      -  lo0
ff01:1::/32                        link#1                         UC          -        -      -  wm0
ff01:2::/32                        ::1                            UC          -        -      -  lo0
ff02::%wm0/32                      link#1                         UC          -        -      -  wm0
ff02::%lo0/32                      ::1                            UC          -        -      -  lo0
"""
    # Mocked file descriptor
    strio = StringIO.StringIO(netstat_output)
    mock_os.popen = mock.MagicMock(return_value=strio)
    # Mocked in6_getifaddr() output
    mock_in6_getifaddr.return_value = [("::1", IPV6_ADDR_LOOPBACK, "lo0"),
                                       ("fe80::acd1:3989:180e:fde0", IPV6_ADDR_LINKLOCAL, "wm0")]
    # Test the function
    from scapy.arch.unix import read_routes6
    routes = read_routes6()
    for r in routes:
        print r
    assert(len(routes) == 5)
    assert(check_mandatory_ipv6_routes(routes))

test_netbsd_7_0()
plorinquer's avatar
plorinquer committed

############
############
plorinquer's avatar
plorinquer committed

= EAPOL - Basic Instantiation
gpotter2's avatar
gpotter2 committed
str(EAPOL()) == b'\x01\x00\x00\x00'
plorinquer's avatar
plorinquer committed

= EAPOL - Instantiation with specific values
gpotter2's avatar
gpotter2 committed
str(EAPOL(version = 3, type = 5)) == b'\x03\x05\x00\x00'
plorinquer's avatar
plorinquer committed

= EAPOL - Dissection (1)
gpotter2's avatar
gpotter2 committed
s = b'\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
plorinquer's avatar
plorinquer committed
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 1)
assert(eapol.len == 0)
plorinquer's avatar
plorinquer committed

= EAPOL - Dissection (2)
gpotter2's avatar
gpotter2 committed
s = b'\x03\x00\x00\x05\x01\x01\x00\x05\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
plorinquer's avatar
plorinquer committed
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 0)
assert(eapol.len == 5)
plorinquer's avatar
plorinquer committed

= EAPOL - Dissection (3)
gpotter2's avatar
gpotter2 committed
s = b'\x03\x00\x00\x0e\x02\x01\x00\x0e\x01anonymous\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
plorinquer's avatar
plorinquer committed
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 0)
assert(eapol.len == 14)
plorinquer's avatar
plorinquer committed

= EAPOL - Dissection (4)
gpotter2's avatar
gpotter2 committed
req = EAPOL(b'\x03\x00\x00\x05\x01\x01\x00\x05\x01')
ans = EAPOL(b'\x03\x00\x00\x0e\x02\x01\x00\x0e\x01anonymous')
plorinquer's avatar
plorinquer committed
ans.answers(req)

= EAPOL - Dissection (5)
gpotter2's avatar
gpotter2 committed
s = b'\x02\x00\x00\x06\x01\x01\x00\x06\r '
plorinquer's avatar
plorinquer committed
eapol = EAPOL(s)
assert(eapol.version == 2)
assert(eapol.type == 0)
assert(eapol.len == 6)
assert(eapol.haslayer(EAP_TLS))
plorinquer's avatar
plorinquer committed

= EAPOL - Dissection (6)
gpotter2's avatar
gpotter2 committed
s = b'\x03\x00\x00<\x02\x9e\x00<+\x01\x16\x03\x01\x001\x01\x00\x00-\x03\x01dr1\x93ZS\x0en\xad\x1f\xbaH\xbb\xfe6\xe6\xd0\xcb\xec\xd7\xc0\xd7\xb9\xa5\xc9\x0c\xfd\x98o\xa7T \x00\x00\x04\x004\x00\x00\x01\x00\x00\x00'
plorinquer's avatar
plorinquer committed
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 0)
assert(eapol.len == 60)
assert(eapol.haslayer(EAP_FAST))
############
############
+ EAPOL-MKA class tests

= EAPOL-MKA - With Basic parameter set - Dissection
eapol = None
gpotter2's avatar
gpotter2 committed
s = b'\x03\x05\x00T\x01\xff\xf0<\x00Bh\xa8\x1e\x03\x00\n\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7\x00\x00\x00\x01\x00\x80\xc2\x01\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\xff\x00\x00\x10\xe5\xf5j\x86V\\\xb1\xcc\xa9\xb95\x04m*Cj'
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 5)
assert(eapol.len == 84)
assert(eapol.haslayer(MKAPDU))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU].basic_param_set.actor_member_id == b"\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7")
assert(eapol[MKAPDU].haslayer(MKAICVSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKAICVSet].icv == b"\xe5\xf5j\x86V\\\xb1\xcc\xa9\xb95\x04m*Cj")


= EAPOL-MKA - With Potential Peer List parameter set - Dissection
eapol = None
gpotter2's avatar
gpotter2 committed
s = b'\x03\x05\x00h\x01\x10\xe0<\xccN$\xc4\xf7\x7f\x00\x80q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6\x00\x00\x00}\x00\x80\xc2\x01\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x02\x00\x00\x10\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7\x00\x00\x00\x01\xff\x00\x00\x105\x01\xdc)\xfd\xd1\xff\xd55\x9c_o\xc9\x9c\xca\xc0'
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 5)
assert(eapol.len == 104)
assert(eapol.haslayer(MKAPDU))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU].basic_param_set.actor_member_id == b"q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6")
assert(eapol.haslayer(MKAPotentialPeerListParamSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKAPotentialPeerListParamSet].member_id_message_num[0].member_id == b"\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7")
assert(eapol[MKAPDU].haslayer(MKAICVSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKAICVSet].icv == b"5\x01\xdc)\xfd\xd1\xff\xd55\x9c_o\xc9\x9c\xca\xc0")

= EAPOL-MKA - With Live Peer List parameter set - Dissection
eapol = None
gpotter2's avatar
gpotter2 committed
s = b"\x03\x05\x00h\x01\xffp<\x00Bh\xa8\x1e\x03\x00\n\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7\x00\x00\x00\x02\x00\x80\xc2\x01\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x01\x00\x00\x10q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6\x00\x00\x00\x80\xff\x00\x00\x10\xf4\xa1d\x18\tD\xa2}\x8e'\x0c/\xda,\xea\xb7"
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 5)
assert(eapol.len == 104)
assert(eapol.haslayer(MKAPDU))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU].basic_param_set.actor_member_id == b'\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7')
assert(eapol.haslayer(MKALivePeerListParamSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKALivePeerListParamSet].member_id_message_num[0].member_id == b"q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6")
assert(eapol[MKAPDU].haslayer(MKAICVSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKAICVSet].icv == b"\xf4\xa1d\x18\tD\xa2}\x8e'\x0c/\xda,\xea\xb7")

= EAPOL-MKA - With SAK Use parameter set - Dissection
eapol = None
gpotter2's avatar
gpotter2 committed
s = b'\x03\x05\x00\x94\x01\xffp<\x00Bh\xa8\x1e\x03\x00\n\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7\x00\x00\x00\x03\x00\x80\xc2\x01\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x03\x10\x00(q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6\x00\x00\x00\x01\x00\x00\x00\x00q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x10q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6\x00\x00\x00\x83\xff\x00\x00\x10OF\x84\xf1@%\x95\xe6Fw9\x1a\xfa\x03(\xae'
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 5)
assert(eapol.len == 148)
assert(eapol.haslayer(MKAPDU))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU].basic_param_set.actor_member_id == b'\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7')
assert(eapol.haslayer(MKASAKUseParamSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKASAKUseParamSet].latest_key_key_server_member_id == b"q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6")
assert(eapol.haslayer(MKALivePeerListParamSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKALivePeerListParamSet].member_id_message_num[0].member_id == b"q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6")
assert(eapol[MKAPDU].haslayer(MKAICVSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKAICVSet].icv == b"OF\x84\xf1@%\x95\xe6Fw9\x1a\xfa\x03(\xae")

= EAPOL-MKA - With Distributed SAK parameter set - Dissection
eapol = None
gpotter2's avatar
gpotter2 committed
s = b"\x03\x05\x00\xb4\x01\x10\xe0<\xccN$\xc4\xf7\x7f\x00\x80q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6\x00\x00\x00\x81\x00\x80\xc2\x01\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x01\x00\x00\x10\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7\x00\x00\x00\x02\x03\x10\x00(q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x10\x00\x1c\x00\x00\x00\x01Cz\x05\x88\x9f\xe8-\x94W+?\x13~\xfb\x016yVB?\xbd\xa1\x9fu\xff\x00\x00\x10\xb0H\xcf\xe0:\xa1\x94RD'\x03\xe67\xe1Ur"
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 5)
assert(eapol.len == 180)
assert(eapol.haslayer(MKAPDU))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU].basic_param_set.actor_member_id == b"q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6")
assert(eapol.haslayer(MKASAKUseParamSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKASAKUseParamSet].latest_key_key_server_member_id == b"q\x8b\x8a9\x86k/X\x14\xc9\xdc\xf6")
assert(eapol.haslayer(MKALivePeerListParamSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKALivePeerListParamSet].member_id_message_num[0].member_id == b"\xbcj\x00\x96Ywz\x82:\x90\xd9\xe7")
assert(eapol.haslayer(MKADistributedSAKParamSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKADistributedSAKParamSet].sak_aes_key_wrap == b"Cz\x05\x88\x9f\xe8-\x94W+?\x13~\xfb\x016yVB?\xbd\xa1\x9fu")
assert(eapol[MKAPDU].haslayer(MKAICVSet))
gpotter2's avatar
gpotter2 committed
assert(eapol[MKAPDU][MKAICVSet].icv == b"\xb0H\xcf\xe0:\xa1\x94RD'\x03\xe67\xe1Ur")
plorinquer's avatar
plorinquer committed

= EAP - Basic Instantiation
gpotter2's avatar
gpotter2 committed
str(EAP()) == b'\x04\x00\x00\x04'
plorinquer's avatar
plorinquer committed

= EAP - Instantiation with specific values
gpotter2's avatar
gpotter2 committed
str(EAP(code = 1, id = 1, len = 5, type = 1)) == b'\x01\x01\x00\x05\x01'
plorinquer's avatar
plorinquer committed

= EAP - Dissection (1)
gpotter2's avatar
gpotter2 committed
s = b'\x01\x01\x00\x05\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
plorinquer's avatar
plorinquer committed
eap = EAP(s)
assert(eap.code == 1)
assert(eap.id == 1)
assert(eap.len == 5)
assert(hasattr(eap, "type"))
assert(eap.type == 1)
plorinquer's avatar
plorinquer committed

= EAP - Dissection (2)
gpotter2's avatar
gpotter2 committed
s = b'\x02\x01\x00\x0e\x01anonymous\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
plorinquer's avatar
plorinquer committed
eap = EAP(s)
assert(eap.code == 2)
assert(eap.id == 1)
assert(eap.len == 14)
assert(eap.type == 1)
assert(hasattr(eap, 'identity'))
assert(eap.identity == 'anonymous')
plorinquer's avatar
plorinquer committed

= EAP - Dissection (3)
gpotter2's avatar
gpotter2 committed
s = b'\x01\x01\x00\x06\r '
plorinquer's avatar
plorinquer committed
eap = EAP(s)
assert(eap.code == 1)
assert(eap.id == 1)
assert(eap.len == 6)
assert(eap.type == 13)
assert(eap.haslayer(EAP_TLS))
assert(eap[EAP_TLS].L == 0)
assert(eap[EAP_TLS].M == 0)
assert(eap[EAP_TLS].S == 1)
plorinquer's avatar
plorinquer committed

= EAP - Dissection (4)
gpotter2's avatar
gpotter2 committed
s = b'\x02\x01\x00\xd1\r\x00\x16\x03\x01\x00\xc6\x01\x00\x00\xc2\x03\x01UK\x02\xdf\x1e\xde5\xab\xfa[\x15\xef\xbe\xa2\xe4`\xc6g\xb9\xa8\xaa%vAs\xb2\x1cXt\x1c0\xb7\x00\x00P\xc0\x14\xc0\n\x009\x008\x00\x88\x00\x87\xc0\x0f\xc0\x05\x005\x00\x84\xc0\x12\xc0\x08\x00\x16\x00\x13\xc0\r\xc0\x03\x00\n\xc0\x13\xc0\t\x003\x002\x00\x9a\x00\x99\x00E\x00D\xc0\x0e\xc0\x04\x00/\x00\x96\x00A\xc0\x11\xc0\x07\xc0\x0c\xc0\x02\x00\x05\x00\x04\x00\x15\x00\x12\x00\t\x00\xff\x01\x00\x00I\x00\x0b\x00\x04\x03\x00\x01\x02\x00\n\x004\x002\x00\x0e\x00\r\x00\x19\x00\x0b\x00\x0c\x00\x18\x00\t\x00\n\x00\x16\x00\x17\x00\x08\x00\x06\x00\x07\x00\x14\x00\x15\x00\x04\x00\x05\x00\x12\x00\x13\x00\x01\x00\x02\x00\x03\x00\x0f\x00\x10\x00\x11\x00#\x00\x00\x00\x0f\x00\x01\x01'
plorinquer's avatar
plorinquer committed
eap = EAP(s)
assert(eap.code == 2)
assert(eap.id == 1)
assert(eap.len == 209)
assert(eap.type == 13)
assert(eap.haslayer(EAP_TLS))
assert(eap[EAP_TLS].L == 0)
assert(eap[EAP_TLS].M == 0)
assert(eap[EAP_TLS].S == 0)
plorinquer's avatar
plorinquer committed

= EAP - Dissection (5)
gpotter2's avatar
gpotter2 committed
s = b'\x02\x9e\x00<+\x01\x16\x03\x01\x001\x01\x00\x00-\x03\x01dr1\x93ZS\x0en\xad\x1f\xbaH\xbb\xfe6\xe6\xd0\xcb\xec\xd7\xc0\xd7\xb9\xa5\xc9\x0c\xfd\x98o\xa7T \x00\x00\x04\x004\x00\x00\x01\x00\x00\x00'
plorinquer's avatar
plorinquer committed
eap = EAP(s)
assert(eap.code == 2)
assert(eap.id == 158)
assert(eap.len == 60)
assert(eap.type == 43)
assert(eap.haslayer(EAP_FAST))
assert(eap[EAP_FAST].L == 0)
assert(eap[EAP_FAST].M == 0)
assert(eap[EAP_FAST].S == 0)
assert(eap[EAP_FAST].version == 1)
plorinquer's avatar
plorinquer committed

= EAP - Dissection (6)
gpotter2's avatar
gpotter2 committed
s = b'\x02\x9f\x01L+\x01\x16\x03\x01\x01\x06\x10\x00\x01\x02\x01\x00Y\xc9\x8a\tcw\t\xdcbU\xfd\x035\xcd\x1a\t\x10f&[(9\xf6\x88W`\xc6\x0f\xb3\x84\x15\x19\xf5\tk\xbd\x8fp&0\xb0\xa4B\x85\x0c<:s\xf2zT\xc3\xbd\x8a\xe4D{m\xe7\x97\xfe>\xda\x14\xb8T1{\xd7H\x9c\xa6\xcb\xe3,u\xdf\xe0\x82\xe5R\x1e<\xe5\x03}\xeb\x98\xe2\xf7\x8d3\xc6\x83\xac"\x8f\xd7\x12\xe5{:"\x84A\xd9\x14\xc2cZF\xd4\t\xab\xdar\xc7\xe0\x0e\x00o\xce\x05g\xdc?\xcc\xf7\xe83\x83E\xb3>\xe8<3-QB\xfd$C/\x1be\xcf\x03\xd6Q4\xbe\\h\xba)<\x99N\x89\xd9\xb1\xfa!\xd7a\xef\xa3\xd3o\xed8Uz\xb5k\xb0`\xfeC\xbc\xb3aS,d\xe6\xdc\x13\xa4A\x1e\x9b\r{\xd6s \xd0cQ\x95y\xc8\x1d\xc3\xd9\x87\xf2=\x81\x96q~\x99E\xc3\x97\xa8px\xe2\xc7\x92\xeb\xff/v\x84\x1e\xfb\x00\x95#\xba\xfb\xd88h\x90K\xa7\xbd9d\xb4\xf2\xf2\x14\x02vtW\xaa\xadY\x14\x03\x01\x00\x01\x01\x16\x03\x01\x000\x97\xc5l\xd6\xef\xffcM\x81\x90Q\x96\xf6\xfeX1\xf7\xfc\x84\xc6\xa0\xf6Z\xcd\xb6\xe1\xd4\xdb\x88\xf9t%Q!\xe7,~#2G-\xdf\x83\xbf\x86Q\xa2$'
plorinquer's avatar
plorinquer committed
eap = EAP(s)
assert(eap.code == 2)
assert(eap.id == 159)
assert(eap.len == 332)
assert(eap.type == 43)
assert(eap.haslayer(EAP_FAST))
assert(eap[EAP_FAST].L == 0)
assert(eap[EAP_FAST].M == 0)
assert(eap[EAP_FAST].S == 0)
assert(eap[EAP_FAST].version == 1)
plorinquer's avatar
plorinquer committed

= EAP - Dissection (7)
gpotter2's avatar
gpotter2 committed
s = b'\x02\xf1\x00\x06\x03+'
plorinquer's avatar
plorinquer committed
eap = EAP(s)
assert(eap.code == 2)
assert(eap.id == 241)
assert(eap.len == 6)
assert(eap.type == 3)
assert(hasattr(eap, 'desired_auth_type'))
assert(eap.desired_auth_type == 43)
= EAP - EAP_TLS - Basic Instantiation
str(EAP_TLS()) == b'\x01\x00\x00\x06\r\x00'

= EAP - EAP_FAST - Basic Instantiation
str(EAP_FAST()) == b'\x01\x00\x00\x06+\x00'

= EAP - EAP_MD5 - Basic Instantiation
str(EAP_MD5()) == b'\x01\x00\x00\x06\x04\x00'

Pierre Lorinquer's avatar
Pierre Lorinquer committed
= EAP - EAP_MD5 - Request - Dissection (8)
gpotter2's avatar
gpotter2 committed
s = b'\x01\x02\x00\x16\x04\x10\x86\xf9\x89\x94\x81\x01\xb3 nHh\x1b\x8d\xe7^\xdb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Pierre Lorinquer's avatar
Pierre Lorinquer committed
eap = EAP(s)
assert(eap.code == 1)
assert(eap.id == 2)
assert(eap.len == 22)
assert(eap.type == 4)
assert(eap.haslayer(EAP_MD5))
assert(eap[EAP_MD5].value_size == 16)
gpotter2's avatar
gpotter2 committed
assert(eap[EAP_MD5].value == b'\x86\xf9\x89\x94\x81\x01\xb3 nHh\x1b\x8d\xe7^\xdb')
Pierre Lorinquer's avatar
Pierre Lorinquer committed
assert(eap[EAP_MD5].optional_name == '')

= EAP - EAP_MD5 - Response - Dissection (9)
gpotter2's avatar
gpotter2 committed
s = b'\x02\x02\x00\x16\x04\x10\xfd\x1e\xffe\xf5\x80y\xa8\xe3\xc8\xf1\xbd\xc2\x85\xae\xcf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Pierre Lorinquer's avatar
Pierre Lorinquer committed
eap = EAP(s)
assert(eap.code == 2)
assert(eap.id == 2)
assert(eap.len == 22)
assert(eap.type == 4)
assert(eap.haslayer(EAP_MD5))
assert(eap[EAP_MD5].value_size == 16)
gpotter2's avatar
gpotter2 committed
assert(eap[EAP_MD5].value == b'\xfd\x1e\xffe\xf5\x80y\xa8\xe3\xc8\xf1\xbd\xc2\x85\xae\xcf')
Pierre Lorinquer's avatar
Pierre Lorinquer committed
assert(eap[EAP_MD5].optional_name == '')
= EAP - Layers (1)
eap = EAP_MD5()
assert(EAP_MD5 in eap)
assert(not EAP_TLS in eap)
assert(not EAP_FAST in eap)
assert(EAP in eap)
eap = EAP_TLS()
assert(EAP_TLS in eap)
assert(not EAP_MD5 in eap)
assert(not EAP_FAST in eap)
assert(EAP in eap)
eap = EAP_FAST()
assert(EAP_FAST in eap)
assert(not EAP_MD5 in eap)
assert(not EAP_TLS in eap)
assert(EAP in eap)


= EAP - Layers (2)
eap = EAP_MD5()
assert(type(eap[EAP]) == EAP_MD5)
eap = EAP_TLS()
assert(type(eap[EAP]) == EAP_TLS)
eap = EAP_FAST()
assert(type(eap[EAP]) == EAP_FAST)


plorinquer's avatar
plorinquer committed
+ NTP module tests

= NTP - Layers (1)
p = NTPHeader()
assert(NTPHeader in p)
assert(not NTPControl in p)
assert(not NTPPrivate in p)
assert(NTP in p)
p = NTPControl()
assert(not NTPHeader in p)
assert(NTPControl in p)
assert(not NTPPrivate in p)
assert(NTP in p)
p = NTPPrivate()
assert(not NTPHeader in p)
assert(not NTPControl in p)
assert(NTPPrivate in p)
assert(NTP in p)


= NTP - Layers (2)
p = NTPHeader()
assert(type(p[NTP]) == NTPHeader)
p = NTPControl()
assert(type(p[NTP]) == NTPControl)
p = NTPPrivate()
assert(type(p[NTP]) == NTPPrivate)


plorinquer's avatar
plorinquer committed
+ NTPHeader tests

= NTPHeader - Basic checks
len(str(NTP())) == 48


= NTPHeader - Dissection
gpotter2's avatar
gpotter2 committed
s = b"!\x0b\x06\xea\x00\x00\x00\x00\x00\x00\xf2\xc1\x7f\x7f\x01\x00\xdb9\xe8\xa21\x02\xe6\xbc\xdb9\xe8\x81\x02U8\xef\xdb9\xe8\x80\xdcl+\x06\xdb9\xe8\xa91\xcbI\xbf\x00\x00\x00\x01\xady\xf3\xa1\xe5\xfc\xd02\xd2j\x1e'\xc3\xc1\xb6\x0e"
plorinquer's avatar
plorinquer committed
p = NTP(s)
assert(isinstance(p, NTPHeader))
assert(p[NTPAuthenticator].key_id == 1)
assert(p[NTPAuthenticator].dgst.encode("hex") == 'ad79f3a1e5fcd032d26a1e27c3c1b60e')


= NTPHeader - KoD
gpotter2's avatar
gpotter2 committed
s = b'\xe4\x00\x06\xe8\x00\x00\x00\x00\x00\x00\x02\xcaINIT\x00\x00\x00\x00\x00\x00\x00\x00\xdb@\xe3\x9eH\xa3pj\xdb@\xe3\x9eH\xf0\xc3\\\xdb@\xe3\x9eH\xfaL\xac\x00\x00\x00\x01B\x86)\xc1Q4\x8bW8\xe7Q\xda\xd0Z\xbc\xb8'
plorinquer's avatar
plorinquer committed
p = NTP(s)
assert(isinstance(p, NTPHeader))
assert(p.leap == 3)
assert(p.version == 4)
assert(p.mode == 4)
assert(p.stratum == 0)
assert(p.ref_id == 'INIT')


plorinquer's avatar
plorinquer committed
= NTPHeader - Extension dissection test
gpotter2's avatar
gpotter2 committed
s = b'#\x02\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\xdbM\xdf\x19e\x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdbM\xdf\x19e\x89\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
plorinquer's avatar
plorinquer committed
p = NTP(s)
assert(isinstance(p, NTPHeader))
assert(p.leap == 0)
assert(p.version == 4)
assert(p.mode == 3)
assert(p.stratum == 2)


plorinquer's avatar
plorinquer committed
+ NTP Control (mode 6) tests

= NTP Control (mode 6) - CTL_OP_READSTAT (1) - request
gpotter2's avatar
gpotter2 committed
s = b'\x16\x01\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00'
plorinquer's avatar
plorinquer committed
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 0)
plorinquer's avatar
plorinquer committed
assert(p.more == 0)
assert(p.op_code == 1)
assert(p.sequence == 12)
assert(p.status == 0)
assert(p.association_id == 0)
assert(p.offset == 0)
assert(p.count == 0)
assert(p.data == '')


= NTP Control (mode 6) - CTL_OP_READSTAT (2) - response
gpotter2's avatar
gpotter2 committed
s = b'\x16\x81\x00\x0c\x06d\x00\x00\x00\x00\x00\x04\xe5\xfc\xf6$'
plorinquer's avatar
plorinquer committed
p = NTP(s)
assert(isinstance(p, NTPControl))