2011-01-12 00:10:32 +00:00
|
|
|
module Msf
|
|
|
|
class Post
|
|
|
|
|
|
|
|
module Common
|
|
|
|
|
2011-05-30 22:11:43 +00:00
|
|
|
# Execute given command as hidden and channelize, output of command given as a multiline string.
|
2011-01-15 05:08:42 +00:00
|
|
|
# For certain versions of Meterpreter options can not be included in the cmd var
|
2011-07-01 23:46:54 +00:00
|
|
|
def cmd_exec(cmd, opts=nil, time_out=15)
|
2011-05-30 22:11:43 +00:00
|
|
|
case session.type
|
|
|
|
when /meterpreter/
|
2011-07-05 17:17:27 +00:00
|
|
|
if opts.nil? and cmd =~ /\s*/
|
|
|
|
opts = Shellwords.shellwords(cmd)
|
|
|
|
cmd = opts.shift
|
2012-06-05 00:11:31 +00:00
|
|
|
opts = opts.join(" ")
|
2011-07-05 17:17:27 +00:00
|
|
|
end
|
2011-05-30 22:11:43 +00:00
|
|
|
session.response_timeout = time_out
|
2011-07-05 17:17:27 +00:00
|
|
|
process = session.sys.process.execute(cmd, opts, {'Hidden' => true, 'Channelized' => true})
|
2011-05-30 22:11:43 +00:00
|
|
|
o = ""
|
2011-07-05 17:17:27 +00:00
|
|
|
while (d = process.channel.read)
|
2011-05-30 22:11:43 +00:00
|
|
|
break if d == ""
|
2011-07-01 23:46:54 +00:00
|
|
|
o << d
|
2011-05-30 22:11:43 +00:00
|
|
|
end
|
2011-07-05 17:17:27 +00:00
|
|
|
process.channel.close
|
|
|
|
process.close
|
2011-05-30 22:11:43 +00:00
|
|
|
when /shell/
|
2011-07-01 23:46:54 +00:00
|
|
|
o = session.shell_command_token("#{cmd} #{opts}", time_out)
|
|
|
|
o.chomp! if o
|
2011-01-12 00:10:32 +00:00
|
|
|
end
|
2011-07-01 23:46:54 +00:00
|
|
|
return "" if o.nil?
|
2011-01-12 00:10:32 +00:00
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
2012-01-26 19:02:39 +00:00
|
|
|
def report_vm(vm)
|
|
|
|
return unless session
|
|
|
|
return unless vm
|
2012-02-26 08:09:44 +00:00
|
|
|
vm_normal = vm.to_s.strip
|
2012-01-26 19:02:39 +00:00
|
|
|
return if vm_normal.empty?
|
|
|
|
vm_data = {
|
|
|
|
:host => session.target_host,
|
|
|
|
:virtual_host => vm_normal
|
|
|
|
}
|
|
|
|
report_host(vm_data)
|
|
|
|
end
|
|
|
|
|
2011-01-12 00:10:32 +00:00
|
|
|
end
|
|
|
|
end
|
2011-07-01 23:46:54 +00:00
|
|
|
end
|