Module: Msf::Session::Scriptable

Included in:
Msf::Sessions::CommandShell, Msf::Sessions::Meterpreter
Defined in:
lib/msf/base/sessions/scriptable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


7
8
9
# File 'lib/msf/base/sessions/scriptable.rb', line 7

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#execute_fileObject

Override

Raises:

  • (NotImplementedError)

50
51
52
# File 'lib/msf/base/sessions/scriptable.rb', line 50

def execute_file
  raise NotImplementedError
end

#execute_script(script_name, *args) ⇒ Object

Executes the supplied script or Post module with arguments args

Will search the script path.


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/msf/base/sessions/scriptable.rb', line 59

def execute_script(script_name, *args)
  mod = framework.modules.create(script_name)
  if (mod and mod.type == "post")
    # Don't report module run events here as it will be taken care of
    # in +Post.run_simple+
    opts = { 'SESSION' => self.sid }
    args.each do |arg|
      k,v = arg.split("=", 2)
      opts[k] = v
    end
    mod.run_simple(
      # Run with whatever the default stance is for now.  At some
      # point in the future, we'll probably want a way to force a
      # module to run in the background
      #'RunAsJob' => true,
      'LocalInput'  => self.user_input,
      'LocalOutput' => self.user_output,
      'Options'     => opts
    )
  else
    full_path = self.class.find_script_path(script_name)

    # No path found?  Weak.
    if full_path.nil?
      print_error("The specified script could not be found: #{script_name}")
      return true
    end
    framework.events.on_session_script_run(self, full_path)
    execute_file(full_path, args)
  end
end