Ejemplo n.º 1
0
 def test_scapy_sniffer(self):
     send_data = [
         Ether(src="99:54:8f:91:12:f6", dst="44:35:a2:a6:d0:bd") /
         IPv6(src="fe80::1", dst="fe80::2") / ICMPv6EchoRequest(),
         Ether(src="44:35:a2:a6:d0:bd", dst="99:54:8f:91:12:f6") /
         IPv6(src="fe80::2", dst="fe80::1") / ICMPv6EchoReply(),
         Ether(src="1f:db:ed:9c:26:6e", dst="18:39:3c:e8:1f:ad") /
         IPv6(src="2001:db8:8a5a:4020:f160:162:c83d:527d",
              dst="2001:db8:2932:29c9:35eb:9377:ae68:634d") /
         UDP(sport=31245, dport=8788) / b"abcdef",
         Ether(src="18:39:3c:e8:1f:ad", dst="1f:db:ed:9c:26:6e") /
         IPv6(src="2001:db8:2932:29c9:35eb:9377:ae68:634d",
              dst="2001:db8:8a5a:4020:f160:162:c83d:527d") /
         UDP(sport=8788, dport=31245) / b"12345",
     ]
     sniffer = AsyncSniffer()
     sniffer.start()
     self.spawn.expect(r"Initializing L2listen with arguments")
     self.spawn.expect(r"Bound socket to '(.*)'\s")
     remote = self.spawn.match.group(1)
     # wait a bit to avoid race where socket is not bound yet
     time.sleep(.5)
     for packet in send_data:
         time.sleep(.001)  # some spacing for test stability
         self.assertEqual(len(raw(packet)),
                          self.comm_sock.sendto(raw(packet), remote))
     for packet in send_data:
         self.spawn.expect(r"Receiving on L2listen with arguments")
     results = sniffer.stop()
     self.assertIsNotNone(results)
     self.assertEqual(len(send_data), len(results))
     for pkt in send_data:
         self.assertIn(Ether(raw(pkt)), results)
Ejemplo n.º 2
0
 def test_scapy_srp1(self):
     send_data = Ether(src="99:54:8f:91:12:f6", dst="44:35:a2:a6:d0:bd") / \
         IPv6(src="fe80::1", dst="fe80::2") / \
         ICMPv6EchoRequest()
     exp_reply = Ether(src="44:35:a2:a6:d0:bd", dst="99:54:8f:91:12:f6") / \
         IPv6(src="fe80::2", dst="fe80::1") / \
         ICMPv6EchoReply()
     self._test_sndrcv1(srp1, "L2socket", send_data, exp_reply)
Ejemplo n.º 3
0
    def test_it_should_deliver_a_packet_from_ethx_to_tr3(self):
        self.ethx_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.router(3).global_ip(iface=1)))/ICMPv6EchoReply())

        self.assertEqual(1, len(self.n.router(3).received(iface=1)))
Ejemplo n.º 4
0
    def test_it_should_deliver_a_link_local_packet_from_ethx_to_tr1(self):
        self.ethx_s.accept(IPv6(src=str(self.ethx_t.link_local_ip()), dst=str(self.n.router(1).link_local_ip(iface=1)))/ICMPv6EchoReply())

        self.assertEqual(1, len(self.n.router(1).received(iface=1)))

        p = self.n.router(1).received(iface=1)[0]

        self.assertFalse(p.haslayer(Ether))

        self.assertTrue(p.haslayer(IPv6))
        self.assertEqual(self.ethx_t.link_local_ip().short_form(), p.getlayer(IPv6).src)
        self.assertEqual(self.n.router(1).link_local_ip(iface=1).short_form(), p.getlayer(IPv6).dst)
Ejemplo n.º 5
0
    def test_it_should_not_deliver_a_packet_from_ethx_to_tn4(self):
        self.ethx_s.accept(IPv6(src=str(self.ethy_t.global_ip()), dst=str(self.n.node(4).global_ip()))/ICMPv6EchoReply())

        self.assertEqual(0, len(self.n.node(4).received()))
Ejemplo n.º 6
0
    def test_it_should_deliver_a_packet_from_ethy_to_tn4(self):
        self.ethy_s.accept(IPv6(src=str(self.ethy_t.global_ip()), dst=str(self.n.node(4).global_ip()))/ICMPv6EchoReply())

        self.assertEqual(1, len(self.n.node(4).received()))

        p = self.n.node(4).received()[0]

        self.assertFalse(p.haslayer(Ether))

        self.assertTrue(p.haslayer(IPv6))
        self.assertEqual(self.ethy_t.global_ip().short_form(), p.getlayer(IPv6).src)
        self.assertEqual(self.n.node(4).global_ip().short_form(), p.getlayer(IPv6).dst)