コード例 #1
0
ファイル: test_windivert.py プロジェクト: iroiro123/pydivert
class WinDivertUDPTestCase(BaseTestCase):
    def setUp(self):
        super(WinDivertUDPTestCase, self).setUp()
        # Initialize the fake tcp server
        self.server = FakeUDPServer(("127.0.0.1", 0), EchoUpperUDPHandler)
        self.driver = WinDivert(os.path.join(self.driver_dir, "WinDivert.dll"))

        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.start()

    def test_modify_udp_payload(self):
        """
        Tests injection of a UDP packet with modified payload
        """
        text = "Hello World!"
        client = FakeUDPClient(("127.0.0.1", self.server.server_address[1]), text.encode("UTF-8"))
        client_thread = threading.Thread(target=client.send)
        filter_ = "outbound and udp.DstPort == %s" % self.server.server_address[1]
        with Handle(filter=filter_) as handle:
            client_thread.start()

            packet = handle.receive()
            self.assertEqual(text.encode("UTF-8"), packet.payload)
            handle.send(packet)

            client_thread.join(timeout=10)
            self.assertEqual(text.upper(), client.response.decode("UTF-8"))

    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"))

    def tearDown(self):
        self.server.shutdown()
        self.server.server_close()
        super(WinDivertUDPTestCase, self).tearDown()
コード例 #2
0
ファイル: test_windivert.py プロジェクト: mhils/pydivert
class WinDivertUDPTestCase(BaseTestCase):
    def setUp(self):
        super(WinDivertUDPTestCase, self).setUp()
        # Initialize the fake tcp server
        self.server = FakeUDPServer(("127.0.0.1", 0), EchoUpperUDPHandler)
        self.driver = WinDivert()

        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.start()

    def test_modify_udp_payload(self):
        """
        Tests injection of a UDP packet with modified payload
        """
        text = "Hello World!"
        client = FakeUDPClient(("127.0.0.1", self.server.server_address[1]), text.encode("UTF-8"))
        client_thread = threading.Thread(target=client.send)
        filter_ = "outbound and udp.DstPort == %s" % self.server.server_address[1]
        with Handle(filter=filter_) as handle:
            client_thread.start()

            packet = handle.receive()
            assert text.encode("UTF-8") == packet.payload
            handle.send(packet)

            client_thread.join(timeout=10)
            assert text.upper() == client.response.decode()

    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)
            assert text.upper() == client.response.decode()

    def tearDown(self):
        self.server.shutdown()
        self.server.server_close()
        super(WinDivertUDPTestCase, self).tearDown()
コード例 #3
0
ファイル: test_windivert.py プロジェクト: rgom/pydivert
    def setUp(self):
        super(WinDivertUDPTestCase, self).setUp()
        # Initialize the fake tcp server
        self.server = FakeUDPServer(("127.0.0.1", 0), EchoUpperUDPHandler)
        self.driver = WinDivert(os.path.join(self.driver_dir, "WinDivert.dll"))

        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.start()
コード例 #4
0
ファイル: test_windivert.py プロジェクト: iroiro123/pydivert
    def setUp(self):
        super(WinDivertUDPTestCase, self).setUp()
        # Initialize the fake tcp server
        self.server = FakeUDPServer(("127.0.0.1", 0), EchoUpperUDPHandler)
        self.driver = WinDivert(os.path.join(self.driver_dir, "WinDivert.dll"))

        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.start()