Skip to content
Snippets Groups Projects
regression.uts 317 KiB
Newer Older
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"):
	    return StringIO.StringIO(netstat_output)
        elif command == "ifconfig -l":
	    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":
	    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
str(EAPOL()) == '\x01\x00\x00\x00'

= EAPOL - Instantiation with specific values
str(EAPOL(version = 3, type = 5)) == '\x03\x05\x00\x00'

= EAPOL - Dissection (1)
s = '\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'
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 1)
assert(eapol.len == 0)
plorinquer's avatar
plorinquer committed

= EAPOL - Dissection (2)
s = '\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'
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 0)
assert(eapol.len == 5)
plorinquer's avatar
plorinquer committed

= EAPOL - Dissection (3)
s = '\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'
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 0)
assert(eapol.len == 14)
plorinquer's avatar
plorinquer committed

= EAPOL - Dissection (4)
req = EAPOL('\x03\x00\x00\x05\x01\x01\x00\x05\x01')
ans = EAPOL('\x03\x00\x00\x0e\x02\x01\x00\x0e\x01anonymous')
ans.answers(req)

= EAPOL - Dissection (5)
s = '\x02\x00\x00\x06\x01\x01\x00\x06\r '
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)
s = '\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'
eapol = EAPOL(s)
assert(eapol.version == 3)
assert(eapol.type == 0)
assert(eapol.len == 60)
assert(eapol.haslayer(EAP_FAST))
plorinquer's avatar
plorinquer committed

= EAP - Basic Instantiation
str(EAP()) == '\x04\x00\x00\x04'

= EAP - Instantiation with specific values
str(EAP(code = 1, id = 1, len = 5, type = 1)) == '\x01\x01\x00\x05\x01'

= EAP - Dissection (1)
s = '\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'
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)
s = '\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'
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)
s = '\x01\x01\x00\x06\r '
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)
s = '\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'
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)
s = '\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'
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)
s = '\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$'
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)
s = '\x02\xf1\x00\x06\x03+'
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)
Pierre Lorinquer's avatar
Pierre Lorinquer committed
= EAP - EAP_MD5 - Request - Dissection (8)
s = '\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'
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)
assert(eap[EAP_MD5].value == '\x86\xf9\x89\x94\x81\x01\xb3 nHh\x1b\x8d\xe7^\xdb')
assert(eap[EAP_MD5].optional_name == '')

= EAP - EAP_MD5 - Response - Dissection (9)
s = '\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'
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)
assert(eap[EAP_MD5].value == '\xfd\x1e\xffe\xf5\x80y\xa8\xe3\xc8\xf1\xbd\xc2\x85\xae\xcf')
assert(eap[EAP_MD5].optional_name == '')
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
s = "!\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"
p = NTP(s)
assert(isinstance(p, NTPHeader))
assert(p[NTPAuthenticator].key_id == 1)
assert(p[NTPAuthenticator].dgst.encode("hex") == 'ad79f3a1e5fcd032d26a1e27c3c1b60e')


= NTPHeader - KoD
s = '\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'
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
s = '#\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'
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
s = '\x16\x01\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 0)
assert(p.error == 0)
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
s = '\x16\x81\x00\x0c\x06d\x00\x00\x00\x00\x00\x04\xe5\xfc\xf6$'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 1)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 1)
assert(p.sequence == 12)
assert(isinstance(p.status_word, NTPSystemStatusPacket))
assert(p.status_word.leap_indicator == 0)
assert(p.status_word.clock_source == 6)
assert(p.status_word.system_event_counter == 6)
assert(p.status_word.system_event_code == 4)
assert(p.association_id == 0)
assert(p.offset == 0)
assert(p.count == 4)
assert(isinstance(p.data, NTPPeerStatusDataPacket))
assert(p.data.association_id == 58876)
assert(isinstance(p.data.peer_status, NTPPeerStatusPacket))
assert(p.data.peer_status.configured == 1)
assert(p.data.peer_status.auth_enabled == 1)
assert(p.data.peer_status.authentic == 1)
assert(p.data.peer_status.reachability == 1)
assert(p.data.peer_status.reserved == 0)
assert(p.data.peer_status.peer_sel == 6)
assert(p.data.peer_status.peer_event_counter == 2)
assert(p.data.peer_status.peer_event_code == 4)


= NTP Control (mode 6) - CTL_OP_READVAR (1) - request
s = '\x16\x02\x00\x12\x00\x00\xfc\x8f\x00\x00\x00\x00'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 0)
assert(p.op_code == 2)
assert(p.sequence == 18)
assert(p.status == 0)
assert(p.association_id == 64655)
assert(p.data == '')


= NTP Control (mode 6) - CTL_OP_READVAR (2) - reponse (1st packet)
s = '\xd6\xa2\x00\x12\xc0\x11\xfc\x8f\x00\x00\x01\xd4srcadr=192.168.122.1, srcport=123, dstadr=192.168.122.100, dstport=123,\r\nleap=3, stratum=16, precision=-24, rootdelay=0.000, rootdisp=0.000,\r\nrefid=INIT, reftime=0x00000000.00000000, rec=0x00000000.00000000,\r\nreach=0x0, unreach=5, hmode=1, pmode=0, hpoll=6, ppoll=10, headway=62,\r\nflash=0x1200, keyid=1, offset=0.000, delay=0.000, dispersion=15937.500,\r\njitter=0.000, xleave=0.240,\r\nfiltdelay= 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00,\r\nfiltoffset= 0.00 0.00 0.00 0.00 '
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 1)
assert(p.error == 0)
assert(p.more == 1)
assert(p.op_code == 2)
assert(p.sequence == 18)
assert(isinstance(p.status_word, NTPPeerStatusPacket))
assert(p.status_word.configured == 1)
assert(p.status_word.auth_enabled == 1)
assert(p.status_word.authentic == 0)
assert(p.status_word.reachability == 0)
assert(p.status_word.peer_sel == 0)
assert(p.status_word.peer_event_counter == 1)
assert(p.status_word.peer_event_code == 1)
assert(p.association_id == 64655)
assert(p.offset == 0)
assert(p.count == 468)
assert(p.data.load == 'srcadr=192.168.122.1, srcport=123, dstadr=192.168.122.100, dstport=123,\r\nleap=3, stratum=16, precision=-24, rootdelay=0.000, rootdisp=0.000,\r\nrefid=INIT, reftime=0x00000000.00000000, rec=0x00000000.00000000,\r\nreach=0x0, unreach=5, hmode=1, pmode=0, hpoll=6, ppoll=10, headway=62,\r\nflash=0x1200, keyid=1, offset=0.000, delay=0.000, dispersion=15937.500,\r\njitter=0.000, xleave=0.240,\r\nfiltdelay= 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00,\r\nfiltoffset= 0.00 0.00 0.00 0.00 ')
 

= NTP Control (mode 6) - CTL_OP_READVAR (3) - reponse (2nd packet)
s = '\xd6\x82\x00\x12\xc0\x11\xfc\x8f\x01\xd4\x00i0.00 0.00 0.00 0.00,\r\nfiltdisp= 16000.00 16000.00 16000.00 16000.00 16000.00 16000.00 16000.00 16000.00\r\n\x00\x00\x00'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 1)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 2)
assert(p.sequence == 18)
assert(isinstance(p.status_word, NTPPeerStatusPacket))
assert(p.association_id == 64655)
assert(p.offset == 468)
assert(p.count == 105)
assert(p.data.load == '0.00 0.00 0.00 0.00,\r\nfiltdisp= 16000.00 16000.00 16000.00 16000.00 16000.00 16000.00 16000.00 16000.00\r\n\x00\x00\x00')


= NTP Control (mode 6) - CTL_OP_READVAR (4) - request
s = '\x16\x02\x00\x13\x00\x00s\xb5\x00\x00\x00\x0btest1,test2\x00\x00\x00\x00\x01=\xc2;\xc7\xed\xb9US9\xd6\x89\x08\xc8\xaf\xa6\x12'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 0)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 2)
assert(len(p.data.load) == 12)
assert(p.authenticator.key_id == 1)
assert(p.authenticator.dgst.encode("hex") == '3dc23bc7edb9555339d68908c8afa612')


= NTP Control (mode 6) - CTL_OP_READVAR (5) - response
s = '\xd6\xc2\x00\x13\x05\x00s\xb5\x00\x00\x00\x00\x00\x00\x00\x01\x97(\x02I\xdb\xa0s8\xedr(`\xdbJX\n'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 1)
assert(p.error == 1)
assert(p.more == 0)
assert(p.op_code == 2)
assert(len(p.data.load) == 0)
assert(p.authenticator.key_id == 1)
assert(p.authenticator.dgst.encode("hex") == '97280249dba07338ed722860db4a580a')


= NTP Control (mode 6) - CTL_OP_WRITEVAR (1) - request
s = '\x16\x03\x00\x11\x00\x00\x00\x00\x00\x00\x00\x0btest1,test2\x00\x00\x00\x00\x01\xaf\xf1\x0c\xb4\xc9\x94m\xfcM\x90\tJ\xa1p\x94J'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 0)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 3)
assert(len(p.data.load) == 12)
assert(p.authenticator.key_id == 1)
assert(p.authenticator.dgst.encode("hex") == 'aff10cb4c9946dfc4d90094aa170944a')


= NTP Control (mode 6) - CTL_OP_WRITEVAR (2) - response
s = '\xd6\xc3\x00\x11\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x80z\x80\xfb\xaf\xc4pg\x98S\xa8\xe5xe\x81\x1c'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 1)
assert(p.error == 1)
assert(p.more == 0)
assert(p.op_code == 3)
assert(hasattr(p, 'status_word'))
assert(isinstance(p.status_word, NTPErrorStatusPacket))
assert(p.status_word.error_code == 5)
assert(len(p.data.load) == 0)
assert(p.authenticator.key_id == 1)
assert(p.authenticator.dgst.encode("hex") == '807a80fbafc470679853a8e57865811c')


= NTP Control (mode 6) - CTL_OP_CONFIGURE (1) - request
s = '\x16\x08\x00\x16\x00\x00\x00\x00\x00\x00\x00\x0ccontrolkey 1\x00\x00\x00\x01\xea\xa7\xac\xa8\x1bj\x9c\xdbX\xe1S\r6\xfb\xef\xa4'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 0)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 8)
assert(p.count == 12)
assert(p.data.load == 'controlkey 1')
assert(p.authenticator.key_id == 1)
assert(p.authenticator.dgst.encode("hex") == 'eaa7aca81b6a9cdb58e1530d36fbefa4')


= NTP Control (mode 6) - CTL_OP_CONFIGURE (2) - response
s = '\xd6\x88\x00\x16\x00\x00\x00\x00\x00\x00\x00\x12Config Succeeded\r\n\x00\x00\x00\x00\x00\x01\xbf\xa6\xd8_\xf9m\x1e2l)<\xac\xee\xc2\xa59'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 1)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 8)
assert(p.count == 18)
assert(p.data.load == 'Config Succeeded\r\n\x00\x00')
assert(p.authenticator.key_id == 1)
assert(p.authenticator.dgst.encode("hex") == 'bfa6d85ff96d1e326c293caceec2a539')


= NTP Control (mode 6) - CTL_OP_SAVECONFIG (1) - request
s = '\x16\t\x00\x1d\x00\x00\x00\x00\x00\x00\x00\x0fntp.test.2.conf\x00\x00\x00\x00\x00\x00\x00\x00\x01\xc9\xfb\x8a\xbe<`_\xfa6\xd2\x18\xc3\xb7d\x89#'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 0)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 9)
assert(p.count == 15)
assert(p.data.load == 'ntp.test.2.conf\x00')
assert(p.authenticator.key_id == 1)
assert(p.authenticator.dgst.encode("hex") == 'c9fb8abe3c605ffa36d218c3b7648923')


= NTP Control (mode 6) - CTL_OP_SAVECONFIG (2) - response
s = "\xd6\x89\x00\x1d\x00\x00\x00\x00\x00\x00\x00*Configuration saved to 'ntp.test.2.conf'\r\n\x00\x00\x00\x00\x00\x012\xc2\xbaY\xc53\xfe(\xf5P\xe5\xa0\x86\x02\x95\xd9"
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 1)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 9)
assert(p.count == 42)
assert(p.data.load == "Configuration saved to 'ntp.test.2.conf'\r\n\x00\x00")
assert(p.authenticator.key_id == 1)
assert(p.authenticator.dgst.encode("hex") == '32c2ba59c533fe28f550e5a0860295d9')


= NTP Control (mode 6) - CTL_OP_REQ_NONCE (1) - request
s = '\x16\x0c\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 0)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 12)
assert(p.data == '')
assert(p.authenticator == '')


= NTP Control (mode 6) - CTL_OP_REQ_NONCE (2) - response
s = '\xd6\x8c\x00\x07\x00\x00\x00\x00\x00\x00\x00 nonce=db4186a2e1d9022472e24bc9\r\n'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 1)
assert(p.error == 0)
assert(p.more == 0)
assert(p.op_code == 12)
assert(p.data.load == 'nonce=db4186a2e1d9022472e24bc9\r\n')
assert(p.authenticator == '')


= NTP Control (mode 6) - CTL_OP_READ_MRU (1) - request
s = '\x16\n\x00\x08\x00\x00\x00\x00\x00\x00\x00(nonce=db4186a2e1d9022472e24bc9, frags=32'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 0)
assert(p.error == 0)
assert(p.op_code == 10)
assert(p.count == 40)
assert(p.data.load == 'nonce=db4186a2e1d9022472e24bc9, frags=32')
assert(p.authenticator == '')

= NTP Control (mode 6) - CTL_OP_READ_MRU (2) - response
s = '\xd6\x8a\x00\x08\x00\x00\x00\x00\x00\x00\x00\xe9nonce=db4186a2e2073198b93c6419, addr.0=192.168.122.100:123,\r\nfirst.0=0xdb418673.323e1a89, last.0=0xdb418673.323e1a89, ct.0=1,\r\nmv.0=36, rs.0=0x0, WWQ.0=18446744073709509383, now=0xdb4186a2.e20ff8f4,\r\nlast.newest=0xdb418673.323e1a89\r\n\x00\x00\x00'
p = NTP(s)
assert(isinstance(p, NTPControl))
assert(p.version == 2)
assert(p.mode == 6)
assert(p.response == 1)
assert(p.error == 0)
assert(p.op_code == 10)
assert(p.count == 233)
assert(p.data.load == 'nonce=db4186a2e2073198b93c6419, addr.0=192.168.122.100:123,\r\nfirst.0=0xdb418673.323e1a89, last.0=0xdb418673.323e1a89, ct.0=1,\r\nmv.0=36, rs.0=0x0, WWQ.0=18446744073709509383, now=0xdb4186a2.e20ff8f4,\r\nlast.newest=0xdb418673.323e1a89\r\n\x00\x00\x00')
assert(p.authenticator == '')


plorinquer's avatar
plorinquer committed
+ NTP Private (mode 7) tests

= NTP Private (mode 7) - error - Dissection
s = '\x97\x00\x03\x1d@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
p = NTP(s)
assert(isinstance(p, NTPPrivate))
assert(p.response == 1)
assert(p.version == 2)
assert(p.mode == 7)
assert(p.request_code == 29)
assert(p.err == 4)
assert(p.nb_items == 0)
assert(p.data_item_size == 0)


= NTP Private (mode 7) - REQ_PEER_LIST (1) - request
s = '\x17\x00\x03\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\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\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\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\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
p = NTP(s)
assert(isinstance(p, NTPPrivate))
assert(p.response == 0)
assert(p.version == 2)
assert(p.mode == 7)
assert(p.request_code == 0)
assert(p.nb_items == 0)
assert(p.data_item_size == 0)


= NTP Private (mode 7) - REQ_PEER_LIST (2) - response
s = '\x97\x00\x03\x00\x00\x01\x00 \x7f\x7f\x01\x00\x00{\x03\x83\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
p = NTP(s)
assert(isinstance(p, NTPPrivate))
assert(p.response == 1)
assert(p.version == 2)
assert(p.mode == 7)