def parseDirectoryControlRequest(self, deviceID: int, fileID: int, completionID: int, minorFunction: int, stream: BytesIO) -> DeviceIORequestPDU: self.minorFunctionsForParsingResponse[completionID] = MinorFunction( minorFunction) if minorFunction == MinorFunction.IRP_MN_NOTIFY_CHANGE_DIRECTORY: return DeviceIORequestPDU(deviceID, fileID, completionID, MajorFunction.IRP_MJ_DIRECTORY_CONTROL, minorFunction, stream.read()) else: informationClass = FileSystemInformationClass( Uint32LE.unpack(stream)) initialQuery = Uint8.unpack(stream) pathLength = Uint32LE.unpack(stream) stream.read(23) path = stream.read(pathLength) path = decodeUTF16LE(path)[:-1] self.informationClassForParsingResponse[ completionID] = informationClass return DeviceQueryDirectoryRequestPDU(deviceID, fileID, completionID, informationClass, initialQuery, path)
def onCreateResponse(self, response: DeviceCreateResponsePDU): super().onCreateResponse(response) if self.fileID is None: self.complete() return # Now that the file is open, start listing the directory. request = DeviceQueryDirectoryRequestPDU( self.deviceID, self.fileID, self.requestID, FileSystemInformationClass.FileBothDirectoryInformation, 1, self.path) self.sendIORequest(request)
def handleDirectoryListingResponse( self, response: DeviceQueryDirectoryResponsePDU): for info in response.fileInformation: try: isDirectory = info.fileAttributes & FileAttributes.FILE_ATTRIBUTE_DIRECTORY != 0 except AttributeError: isDirectory = False self.mitm.observer.onDirectoryListingResult( self.deviceID, self.requestID, info.fileName, isDirectory) # Send a follow-up request to get the next file (or a nonzero ioStatus, which will complete the listing). pdu = DeviceQueryDirectoryRequestPDU(self.deviceID, self.fileID, self.requestID, response.informationClass, 0, "") self.sendIORequest(pdu)