示例#1
0
 def get_smbserver(self, add_credential=True, add_share=True):
     smbserver = SimpleSMBServer(listenAddress=self.address,
                                 listenPort=int(self.port))
     if add_credential:
         smbserver.addCredential(self.username, 0, self.lmhash, self.nthash)
     if add_share:
         smbserver.addShare(self.share_name, self.share_path)
     if self.server_smb2_support is not None:
         smbserver.setSMB2Support(self.server_smb2_support)
     return smbserver
示例#2
0
    def test_smbserver_share_put(self):
        """Test writing files to a shared folder.
        """
        server = SimpleSMBServer(listenAddress=self.address,
                                 listenPort=int(self.port))
        server.addCredential(self.username, 0, self.lmhash, self.nthash)
        server.addShare(self.share_name, self.share_path)
        self.start_smbserver(server)

        client = SMBConnection(self.address,
                               self.address,
                               sess_port=int(self.port))
        client.login(self.username, self.password)

        local_file = StringIO(self.share_new_content)

        client.putFile(self.share_name, self.share_new_file, local_file.read)
        self.assertTrue(exists(join(self.share_path, self.share_new_file)))
        with open(join(self.share_path, self.share_new_file), "r") as fd:
            self.assertEqual(fd.read(), self.share_new_content)

        # Check path traversal in put as in #1066
        with self.assertRaises(SessionError):
            client.putFile(self.share_name, join("..",
                                                 self.share_unjailed_file),
                           local_file.read)
        self.assertFalse(exists(self.share_unjailed_file))

        client.close()
示例#3
0
    def test_smbserver_share_list(self):
        """Test listing files in a shared folder.
        """
        server = SimpleSMBServer(listenAddress=self.address,
                                 listenPort=int(self.port))
        server.addCredential(self.username, 0, self.lmhash, self.nthash)
        server.addShare(self.share_name, self.share_path)
        self.start_smbserver(server)

        client = SMBConnection(self.address,
                               self.address,
                               sess_port=int(self.port))
        client.login(self.username, self.password)
        client.listPath(self.share_name, "/")

        # Check path traversal in list as in #1066
        with self.assertRaises(SessionError):
            client.listPath(self.share_name, "../impacket/")

        client.close()
示例#4
0
    def test_smbserver_share_get(self):
        """Test reading files from a shared folder.
        """
        server = SimpleSMBServer(listenAddress=self.address,
                                 listenPort=int(self.port))
        server.addCredential(self.username, 0, self.lmhash, self.nthash)
        server.addShare(self.share_name, self.share_path)
        self.start_smbserver(server)

        client = SMBConnection(self.address,
                               self.address,
                               sess_port=int(self.port))
        client.login(self.username, self.password)

        local_file = BytesIO()
        client.getFile(self.share_name, self.share_file, local_file.write)
        local_file.seek(0)
        self.assertEqual(local_file.read(), b(self.share_new_content))

        # Check unexistent file
        with self.assertRaises(SessionError):
            client.getFile(self.share_name, "unexistent", local_file.write)

        client.close()
示例#5
0
 def get_smbserver(self):
     return SimpleSMBServer(listenAddress=self.address,
                            listenPort=int(self.port))