2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2010-02-22 21:05:08 +00:00
|
|
|
|
2011-06-20 20:54:46 +00:00
|
|
|
require 'shellwords'
|
|
|
|
|
2010-02-22 21:05:08 +00:00
|
|
|
module Msf
|
|
|
|
module Sessions
|
|
|
|
module MeterpreterOptions
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(info)
|
|
|
|
|
|
|
|
register_advanced_options(
|
|
|
|
[
|
|
|
|
OptBool.new('AutoLoadStdapi', [true, "Automatically load the Stdapi extension", true]),
|
2010-08-03 16:07:48 +00:00
|
|
|
OptString.new('InitialAutoRunScript', [false, "An initial script to run on session creation (before AutoRunScript)", '']),
|
|
|
|
OptString.new('AutoRunScript', [false, "A script to run automatically on session creation.", '']),
|
2010-03-10 22:02:27 +00:00
|
|
|
OptBool.new('AutoSystemInfo', [true, "Automatically capture system information on initialization.", true]),
|
2011-07-21 15:44:54 +00:00
|
|
|
OptBool.new('EnableUnicodeEncoding', [true, "Automatically encode UTF-8 strings as hexadecimal", true])
|
2010-02-22 21:05:08 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Once a session is created, automatically load the stdapi extension if the
|
|
|
|
# advanced option is set to true.
|
|
|
|
#
|
|
|
|
def on_session(session)
|
2010-04-20 07:01:46 +00:00
|
|
|
super
|
2010-02-23 20:56:44 +00:00
|
|
|
|
2011-04-30 18:51:50 +00:00
|
|
|
# Defer the session initialization to the Session Manager scheduler
|
|
|
|
framework.sessions.schedule Proc.new {
|
2011-06-20 20:54:46 +00:00
|
|
|
|
2011-07-21 15:44:54 +00:00
|
|
|
# Configure unicode encoding before loading stdapi
|
|
|
|
session.encode_unicode = ( datastore['EnableUnicodeEncoding'] ? true : false )
|
|
|
|
|
2010-05-20 23:47:49 +00:00
|
|
|
session.init_ui(self.user_input, self.user_output)
|
|
|
|
|
2010-02-22 21:05:08 +00:00
|
|
|
if (datastore['AutoLoadStdapi'] == true)
|
2010-09-20 04:58:25 +00:00
|
|
|
|
2010-02-22 21:05:08 +00:00
|
|
|
session.load_stdapi
|
2010-10-08 19:36:34 +00:00
|
|
|
|
2010-03-10 22:02:27 +00:00
|
|
|
if datastore['AutoSystemInfo']
|
|
|
|
session.load_session_info
|
|
|
|
end
|
2010-10-08 19:36:34 +00:00
|
|
|
|
2010-10-29 04:14:22 +00:00
|
|
|
=begin
|
2010-10-08 17:31:08 +00:00
|
|
|
admin = false
|
2010-09-20 04:58:25 +00:00
|
|
|
begin
|
2010-10-08 19:36:34 +00:00
|
|
|
::Timeout.timeout(30) do
|
2010-09-20 04:58:25 +00:00
|
|
|
if session.railgun and session.railgun.shell32.IsUserAnAdmin()["return"] == true
|
2010-10-08 17:31:08 +00:00
|
|
|
admin = true
|
2010-09-20 04:58:25 +00:00
|
|
|
session.info += " (ADMIN)"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue ::Exception
|
2010-09-16 21:44:25 +00:00
|
|
|
end
|
2010-10-29 04:14:22 +00:00
|
|
|
=end
|
2010-11-11 16:15:26 +00:00
|
|
|
if session.platform =~ /win32|win64/i
|
|
|
|
session.load_priv rescue nil
|
|
|
|
end
|
2010-02-22 21:05:08 +00:00
|
|
|
end
|
2011-06-20 20:54:46 +00:00
|
|
|
|
2011-01-17 23:48:19 +00:00
|
|
|
[ 'InitialAutoRunScript', 'AutoRunScript' ].each do |key|
|
|
|
|
if (datastore[key].empty? == false)
|
2011-06-20 20:54:46 +00:00
|
|
|
args = Shellwords.shellwords( datastore[key] )
|
2011-01-17 23:48:19 +00:00
|
|
|
print_status("Session ID #{session.sid} (#{session.tunnel_to_s}) processing #{key} '#{datastore[key]}'")
|
2011-01-19 02:24:21 +00:00
|
|
|
session.execute_script(args.shift, *args)
|
2011-01-17 23:48:19 +00:00
|
|
|
end
|
2010-02-22 21:05:08 +00:00
|
|
|
end
|
2011-06-20 20:54:46 +00:00
|
|
|
|
2011-04-30 18:51:50 +00:00
|
|
|
}
|
2010-02-22 21:05:08 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-02-23 20:16:45 +00:00
|
|
|
|