Ejemplo n.º 1
0
    def handleCreateResponse(self, request: DeviceCreateRequestPDU,
                             response: DeviceCreateResponsePDU):
        """
        Prepare to intercept a file: create a FileProxy object, which will only create the file when we actually write
        to it. When listing a directory, Windows sends a lot of create requests without actually reading the files. We
        use a FileProxy object to avoid creating a lot of empty files whenever a directory is listed.
        :param request: the device create request
        :param response: the device IO response to the request
        """

        isFileRead = request.desiredAccess & (
            FileAccessMask.GENERIC_READ | FileAccessMask.FILE_READ_DATA) != 0
        isNotDirectory = request.createOptions & CreateOption.FILE_NON_DIRECTORY_FILE != 0

        if isFileRead and isNotDirectory:
            remotePath = Path(request.path)
            mapping = FileMapping.generate(remotePath, self.config.fileDir)
            proxy = FileProxy(mapping.localPath, "wb")

            self.openedFiles[response.fileID] = proxy
            self.openedMappings[response.fileID] = mapping

            proxy.createObserver(
                onFileCreated=lambda _: self.log.info(
                    "Saving file '%(remotePath)s' to '%(localPath)s'", {
                        "localPath": mapping.localPath,
                        "remotePath": mapping.remotePath
                    }),
                onFileClosed=lambda _: self.log.debug(
                    "Closing file %(path)s", {"path": mapping.localPath}))
Ejemplo n.º 2
0
    def downloadFile(self, file: VirtualFile):
        remotePath = file.path
        mapping = FileMapping.generate(
            remotePath, self.config.fileDir,
            self.deviceRedirection.createDeviceRoot(file.deviceID), self.log)

        self.fileMappings[remotePath] = mapping
        self.deviceRedirection.sendForgedFileRead(file.deviceID, remotePath)
Ejemplo n.º 3
0
    def handleCreateResponse(self, request: DeviceCreateRequestPDU, response: DeviceCreateResponsePDU):
        """
        Prepare to intercept a file: create a FileProxy object, which will only create the file when we actually write
        to it. When listing a directory, Windows sends a lot of create requests without actually reading the files. We
        use a FileProxy object to avoid creating a lot of empty files whenever a directory is listed.
        :param request: the device create request
        :param response: the device IO response to the request
        """

        isFileRead = request.desiredAccess & (FileAccessMask.GENERIC_READ | FileAccessMask.FILE_READ_DATA) != 0
        isDirectory = request.createOptions & CreateOption.FILE_NON_DIRECTORY_FILE == 0

        if isFileRead and not isDirectory:
            mapping = FileMapping.generate(request.path, self.config.fileDir, self.deviceRoot(response.deviceID), self.log)
            key = (response.deviceID, response.fileID)
            self.mappings[key] = mapping
Ejemplo n.º 4
0
 def createMapping(self, mkdir: MagicMock, mkstemp: MagicMock, mock_open_object):
     mkstemp.return_value = (1, str(self.outDir / "tmp" / "tmp_test"))
     mapping = FileMapping.generate("/test", self.outDir, Path("filesystems"), self.log)
     mapping.getHash = Mock(return_value = self.hash)
     return mapping, mkdir, mkstemp, mock_open_object