async def get_file(self, headers): headers = CIMultiDict(headers) if 'file' not in headers: raise KeyError('File key was not provided') packer = None display_name = payload = headers.get('file') if ':' in payload: _, display_name = packer, payload = payload.split(':') headers['file'] = payload if any(payload.endswith(x) for x in [y for y in self.special_payloads if y.startswith('.')]): payload, display_name = await self._operate_extension(payload, headers) if self.is_uuid4(payload): payload, display_name = self.get_payload_name_from_uuid(payload) if payload in self.special_payloads: payload, display_name = await self.special_payloads[payload](headers) file_path, contents = await self.read_file(payload) if packer: if packer in self.packers: file_path, contents = await self.get_payload_packer(packer).pack(file_path, contents) else: self.log.warning('packer <%s> not available for payload <%s>, returning unpacked' % (packer, payload)) if headers.get('xor_key'): xor_key = headers['xor_key'] contents = xor_bytes(contents, xor_key.encode()) if headers.get('name'): display_name = headers.get('name') if file_path.endswith('.xored'): display_name = file_path.replace('.xored', '') return file_path, contents, display_name
async def get_file(self, headers): if 'file' not in headers: raise KeyError('File key was not provided') display_name = payload = headers.get('file') if any(payload.endswith(x) for x in [y for y in self.special_payloads if y.startswith('.')]): payload, display_name = await self._operate_extension(payload, headers) if self.is_uuid4(payload): payload, display_name = self.get_payload_name_from_uuid(payload) if payload in self.special_payloads: payload, display_name = await self.special_payloads[payload](headers) file_path, contents = await self.read_file(payload) if headers.get('xor_key'): xor_key = headers['xor_key'] contents = xor_bytes(contents, xor_key.encode()) if headers.get('name'): display_name = headers.get('name') if file_path.endswith('.xored'): display_name = file_path.replace('.xored', '') return file_path, contents, display_name
async def get_file(self, headers): """ Retrieve file :param headers: headers dictionary. The `file` key is REQUIRED. :type headers: dict or dict-equivalent :return: File contents and optionally a display_name if the payload is a special payload :raises: KeyError if file key is not provided, FileNotFoundError if file cannot be found """ if 'file' not in headers: raise KeyError('File key was not provided') display_name = payload = headers.get('file') if self.is_uuid4(payload): payload, display_name = self.get_payload_name_from_uuid(payload) if payload in self.special_payloads: payload, display_name = await self.special_payloads[payload](headers) file_path, contents = await self.read_file(payload) if headers.get('xor_key'): xor_key = headers['xor_key'] contents = xor_bytes(contents, xor_key.encode()) if headers.get('name'): display_name = headers.get('name') return file_path, contents, display_name