Exemple #1
0
    def test_modify_tcp_header_shortcut(self):
        """
        Tests injection of a packet with a modified tcp header using shortcutted send
        """
        fake_port = random_free_port()
        fake_addr = "10.10.10.10"
        srv_port = self.server.server_address[1]
        srv_addr = self.server.server_address[0]
        text = "Hello World!"
        client = FakeTCPClient((fake_addr, fake_port), text.encode("UTF-8"))
        client_thread = threading.Thread(target=client.send)

        f = "tcp.DstPort == %d or tcp.SrcPort == %d" % (fake_port, srv_port)
        with Handle(filter=f, priority=1000) as handle:
            # Initialize the fake tcp client
            client_thread.start()
            while True:
                packet = handle.receive()

                if packet.meta.is_outbound():
                    if packet.dst_port == fake_port:
                        packet.dst_port = srv_port
                        packet.dst_addr = srv_addr
                    if packet.src_port == srv_port:
                        packet.src_port = fake_port
                        packet.src_addr = fake_addr

                handle.send(packet)
                if hasattr(client, "response") and client.response:
                    break
            client_thread.join(timeout=10)
            self.assertEqual(text.upper(), client.response.decode("UTF-8"))
Exemple #2
0
    def test_modify_udp_header(self):
        """
        Tests injection of a packet with a modified udp header
        """
        fake_port = random_free_port()
        srv_port = self.server.server_address[1]
        text = "Hello World!"
        client = FakeUDPClient(("127.0.0.1", fake_port), text.encode("UTF-8"))
        client_thread = threading.Thread(target=client.send)

        f = "udp.DstPort == %d or udp.SrcPort == %d" % (fake_port, srv_port)
        with Handle(filter=f, priority=1000) as handle:
            # Initialize the fake tcp client
            client_thread.start()

            for i in range(2):
                packet = handle.receive()
                if packet.meta.is_outbound():
                    if packet.dst_port == fake_port:
                        packet.dst_port = srv_port
                    if packet.src_port == srv_port:
                        packet.src_port = fake_port

                handle.send(packet)

            client_thread.join(timeout=10)
            self.assertEqual(text.upper(), client.response.decode("UTF-8"))
Exemple #3
0
    def test_modify_tcp_header(self):
        """
        Tests injection of a packet with a modified tcp header
        """
        fake_port = random_free_port()
        srv_port = self.server.server_address[1]
        text = "Hello World!"
        client = FakeTCPClient(("127.0.0.1", fake_port), text.encode("UTF-8"))
        client_thread = threading.Thread(target=client.send)

        f = "tcp.DstPort == %d or tcp.SrcPort == %d" % (fake_port, srv_port)
        with Handle(filter=f, priority=1000) as handle:
            # Initialize the fake tcp client
            client_thread.start()
            while True:
                raw_packet, meta = handle.recv()
                packet = handle.driver.parse_packet(raw_packet)

                if meta.is_outbound():
                    if packet.dst_port == fake_port:
                        packet.dst_port = srv_port
                    if packet.src_port == srv_port:
                        packet.src_port = fake_port
                packet = handle.driver.update_packet_checksums(packet)

                handle.send((packet.raw, meta))
                if hasattr(client, "response") and client.response:
                    break
            client_thread.join(timeout=10)
            self.assertEqual(text.upper(), client.response.decode("UTF-8"))
Exemple #4
0
    def test_modify_tcp_header_shortcut(self):
        """
        Tests injection of a packet with a modified tcp header using shortcutted send
        """
        fake_port = random_free_port()
        fake_addr = "10.10.10.10"
        srv_port = self.server.server_address[1]
        srv_addr = self.server.server_address[0]
        text = "Hello World!"
        client = FakeTCPClient((fake_addr, fake_port), text.encode("UTF-8"))
        client_thread = threading.Thread(target=client.send)

        f = "tcp.DstPort == %d or tcp.SrcPort == %d" % (fake_port, srv_port)
        with Handle(filter=f, priority=1000) as handle:
            # Initialize the fake tcp client
            client_thread.start()
            while True:
                packet = handle.receive()

                if packet.meta.is_outbound():
                    if packet.dst_port == fake_port:
                        packet.dst_port = srv_port
                        packet.dst_addr = srv_addr
                    if packet.src_port == srv_port:
                        packet.src_port = fake_port
                        packet.src_addr = fake_addr

                handle.send(packet)
                if hasattr(client, "response") and client.response:
                    break
            client_thread.join(timeout=10)
            self.assertEqual(text.upper(), client.response.decode("UTF-8"))
Exemple #5
0
    def test_modify_udp_header(self):
        """
        Tests injection of a packet with a modified udp header
        """
        fake_port = random_free_port()
        srv_port = self.server.server_address[1]
        text = "Hello World!"
        client = FakeUDPClient(("127.0.0.1", fake_port), text.encode("UTF-8"))
        client_thread = threading.Thread(target=client.send)

        f = "udp.DstPort == %d or udp.SrcPort == %d" % (fake_port, srv_port)
        with Handle(filter=f, priority=1000) as handle:
            # Initialize the fake tcp client
            client_thread.start()

            for i in range(2):
                packet = handle.receive()
                if packet.meta.is_outbound():
                    if packet.dst_port == fake_port:
                        packet.dst_port = srv_port
                    if packet.src_port == srv_port:
                        packet.src_port = fake_port

                handle.send(packet)

            client_thread.join(timeout=10)
            self.assertEqual(text.upper(), client.response.decode("UTF-8"))
Exemple #6
0
    def test_modify_tcp_header(self):
        """
        Tests injection of a packet with a modified tcp header
        """
        fake_port = random_free_port()
        srv_port = self.server.server_address[1]
        text = "Hello World!"
        client = FakeTCPClient(("127.0.0.1", fake_port), text.encode("UTF-8"))
        client_thread = threading.Thread(target=client.send)

        f = "tcp.DstPort == %d or tcp.SrcPort == %d" % (fake_port, srv_port)
        with Handle(filter=f, priority=1000) as handle:
            # Initialize the fake tcp client
            client_thread.start()
            while True:
                raw_packet, meta = handle.recv()
                packet = handle.driver.parse_packet(raw_packet)

                if meta.is_outbound():
                    if packet.dst_port == fake_port:
                        packet.dst_port = srv_port
                    if packet.src_port == srv_port:
                        packet.src_port = fake_port
                packet = handle.driver.update_packet_checksums(packet)

                handle.send((packet.raw, meta))
                if hasattr(client, "response") and client.response:
                    break
            client_thread.join(timeout=10)
            self.assertEqual(text.upper(), client.response.decode("UTF-8"))