#NEWLINE# def runCommand( self ) : #NEWLINE# #INDENT# '\n        ' #NEWLINE# def runOrPrompt( ) : #NEWLINE# #INDENT# if len ( self . cmdpending ) : #NEWLINE# #INDENT# self . runCommand ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if self . interactive : #NEWLINE# #INDENT# self . showPrompt ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret = failure . Failure ( error . ProcessDone ( status = '' ) ) #NEWLINE# self . protocol . terminal . transport . processEnded ( ret ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not len ( self . cmdpending ) ) : #NEWLINE# #INDENT# if self . interactive : #NEWLINE# #INDENT# self . showPrompt ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret = failure . Failure ( error . ProcessDone ( status = '' ) ) #NEWLINE# self . protocol . terminal . transport . processEnded ( ret ) #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# cmdAndArgs = self . cmdpending . pop ( 0 ) #NEWLINE# cmd2 = copy . copy ( cmdAndArgs ) #NEWLINE# environ = copy . copy ( self . environ ) #NEWLINE# cmd = None #NEWLINE# while len ( cmdAndArgs ) : #NEWLINE# #INDENT# piece = cmdAndArgs . pop ( 0 ) #NEWLINE# if piece . count ( '=' ) : #NEWLINE# #INDENT# ( key , value ) = piece . split ( '=' , 1 ) #NEWLINE# environ [ key ] = value #NEWLINE# continue #NEWLINE# #UNINDENT# cmd = piece #NEWLINE# break #NEWLINE# #UNINDENT# args = cmdAndArgs #NEWLINE# if ( not cmd ) : #NEWLINE# #INDENT# runOrPrompt ( ) #NEWLINE# return #NEWLINE# #UNINDENT# rargs = [ ] #NEWLINE# for arg in args : #NEWLINE# #INDENT# matches = self . protocol . fs . resolve_path_wc ( arg , key . protocol . cwd ) #NEWLINE# if matches : #NEWLINE# #INDENT# rargs . extend ( matches ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rargs . append ( arg ) #NEWLINE# #UNINDENT# #UNINDENT# cmdclass = self . protocol . getCommand ( cmd , environ [ 'PATH' ] . split ( ':' ) ) #NEWLINE# if cmdclass : #NEWLINE# #INDENT# log . msg ( eventid = 'cowrie.command.success' , input = ' ' . join ( cmd2 ) , format = 'Command found: %(input)s' ) #NEWLINE# self . protocol . call_command ( cmdclass , * rargs ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# log . msg ( eventid = 'cowrie.command.failed' , input = ' ' . join ( cmd2 ) , format = 'Command not found: %(input)s' ) #NEWLINE# self . protocol . terminal . write ( ( 'bash: %s: command not found\n' % ( cmd , ) ) ) #NEWLINE# runOrPrompt ( )