def call(self): """ """ if len(self.args) == 0: self.help() return line = ' '.join(self.args) cmd = self.args[0] cmdclass = self.protocol.getCommand(cmd, self.environ['PATH'].split(':')) if cmdclass: log.msg(eventid='cowrie.command.success', input=line, format='Command found: %(input)s') command = StdOutStdErrEmulationProtocol(self.protocol,cmdclass,self.args[1:],self.input_data,None) # Workaround for the issue: #352 # https://github.com/fe7ch/cowrie/commit/9b33509 # For an unknown reason inserted command won't be invoked later, if it's followed by an invalid command # so lets just call the command in question # self.protocol.pp.insert_command(command) self.protocol.call_command(command, cmdclass, *self.args[1:]) # Place this here so it doesn't write out only if last statement if self.input_data: self.write(self.input_data) else: self.write(b'{}: applet not found\n'.format(cmd))
def call(self): """ """ if len(self.args) and self.args[0].strip() == '-c': line = ' '.join(self.args) cmd = self.args[1] cmdclass = self.protocol.getCommand( cmd, self.environ['PATH'].split(':')) if cmdclass: log.msg(eventid='cowrie.command.success', input=line, format='Command found: %(input)s') command = StdOutStdErrEmulationProtocol( self.protocol, cmdclass, self.args[2:], self.input_data, None) self.protocol.pp.insert_command(command) # Place this here so it doesn't write out only if last statement if self.input_data: self.write(self.input_data) else: log.msg(eventid='cowrie.command.failed', input=''.join(cmd), format='Command not found: %(input)s') self.write('bash: %s: command not found\n' % (cmd))
def start(self): """ """ start_value = None parsed_arguments = [] for count in range(0, len(self.args)): class_found = self.protocol.getCommand( self.args[count], self.environ['PATH'].split(':')) if class_found: start_value = count break if start_value is not None: for index_2 in range(start_value, len(self.args)): parsed_arguments.append(self.args[index_2]) try: optlist, args = getopt.getopt( self.args[0:start_value], 'bEeHhKknPSVva:C:g:i:l:p:r:s:t:U:u:') except getopt.GetoptError as err: self.errorWrite('sudo: illegal option -- ' + err.opt + '\n') self.short_help() return for o, a in optlist: if o in ("-V"): self.version() return elif o in ("-h"): self.long_help() return if len(parsed_arguments) > 0: line = ' '.join(parsed_arguments) cmd = parsed_arguments[0] cmdclass = self.protocol.getCommand( cmd, self.environ['PATH'].split(':')) if cmdclass: log.msg(eventid='cowrie.command.success', input=line, format='Command found: %(input)s') command = StdOutStdErrEmulationProtocol( self.protocol, cmdclass, parsed_arguments[1:], None, None) self.protocol.pp.insert_command(command) # this needs to go here so it doesn't write it out.... if self.input_data: self.write(self.input_data) self.exit() else: self.short_help() else: self.short_help()
def call(self): """ """ if len(self.args) == 0: self.help() return line = ' '.join(self.args) cmd = self.args[0] cmdclass = self.protocol.getCommand(cmd, self.environ['PATH'].split(':')) if cmdclass: log.msg(eventid='cowrie.command.success', input=line, format='Command found: %(input)s') command = StdOutStdErrEmulationProtocol(self.protocol,cmdclass,self.args[1:],self.input_data,None) self.protocol.pp.insert_command(command) # Place this here so it doesn't write out only if last statement if self.input_data: self.write(self.input_data) else: self.write('{}: applet not found\n'.format(cmd))
def call(self): """ """ start_value = None parsed_arguments = [] for count in range(0, len(self.args)): class_found = self.protocol.getCommand( self.args[count], self.environ['PATH'].split(':')) if class_found: start_value = count break if start_value is not None: for index_2 in range(start_value, len(self.args)): parsed_arguments.append(self.args[index_2]) if len(parsed_arguments) > 0: line = ' '.join(parsed_arguments) cmd = parsed_arguments[0] cmdclass = self.protocol.getCommand( cmd, self.environ['PATH'].split(':')) if cmdclass: log.msg(eventid='cowrie.command.success', input=line, format='Command found: %(input)s') command = StdOutStdErrEmulationProtocol( self.protocol, cmdclass, parsed_arguments[1:], self.input_data, None) self.protocol.pp.insert_command(command) # Place this here so it doesn't write out only if last statement if self.input_data: self.write(self.input_data) else: self.help() else: self.help()