2010-07-10 20:19:49 +00:00
|
|
|
# $Id$
|
2010-07-11 01:22:29 +00:00
|
|
|
# $Revision: 9771 $
|
2010-07-10 20:19:49 +00:00
|
|
|
# Author: Carlos Perez at carlos_perez[at]darkoperator.com
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
################## Variable Declarations ##################
|
2010-07-11 01:22:29 +00:00
|
|
|
@client = client
|
2010-07-10 20:19:49 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
######################## Functions ########################
|
|
|
|
def ls_logged
|
|
|
|
sids = []
|
|
|
|
sids << registry_enumkeys("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList")
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => "Logged Users",
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
"SID",
|
|
|
|
"Profile Path"
|
|
|
|
])
|
|
|
|
sids.flatten.each do |sid|
|
|
|
|
profile_path = registry_getvaldata("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\#{sid}","ProfileImagePath")
|
|
|
|
tbl << [sid,profile_path]
|
|
|
|
end
|
|
|
|
print_line("\n" + tbl.to_s + "\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def ls_current
|
|
|
|
key_base, username = "",""
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => "Current Logged Users",
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
"SID",
|
|
|
|
"User"
|
|
|
|
])
|
|
|
|
registry_enumkeys("HKU").each do |sid|
|
|
|
|
case sid
|
|
|
|
when "S-1-5-18"
|
|
|
|
username = "SYSTEM"
|
|
|
|
tbl << [sid,username]
|
|
|
|
when "S-1-5-19"
|
|
|
|
username = "Local Service"
|
|
|
|
tbl << [sid,username]
|
|
|
|
when "S-1-5-20"
|
|
|
|
username = "Network Service"
|
|
|
|
tbl << [sid,username]
|
|
|
|
else
|
2010-07-11 01:22:29 +00:00
|
|
|
if sid =~ /S-1-5-21-\d*-\d*-\d*-\d*$/
|
|
|
|
key_base = "HKU\\#{sid}"
|
|
|
|
os = @client.sys.config.sysinfo['OS']
|
|
|
|
if os =~ /(Windows 7|2008|Vista)/
|
|
|
|
username = registry_getvaldata("#{key_base}\\Volatile Environment","USERNAME")
|
|
|
|
elsif os =~ /(2000|NET|XP)/
|
|
|
|
appdata_var = registry_getvaldata("#{key_base}\\Volatile Environment","APPDATA")
|
|
|
|
username = appdata_var.scan(/^\w\:\D*\\(\D*)\\\D*$/)
|
|
|
|
end
|
2010-07-10 20:19:49 +00:00
|
|
|
tbl << [sid,username]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print_line("\n" + tbl.to_s + "\n")
|
|
|
|
end
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
####################### Options ###########################
|
|
|
|
@@exec_opts = Rex::Parser::Arguments.new(
|
|
|
|
"-h" => [ false, "Help menu." ],
|
|
|
|
"-l" => [ false, "List SID's of users who have loged in to the host." ],
|
|
|
|
"-c" => [ false, "List SID's of currently loged on users." ]
|
|
|
|
)
|
|
|
|
@@exec_opts.parse(args) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when "-h"
|
|
|
|
print_line "Meterpreter Script for enumerating Current logged users and users that have loged in to the system."
|
|
|
|
print_line(@@exec_opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
when "-l"
|
|
|
|
ls_logged
|
|
|
|
when "-c"
|
|
|
|
ls_current
|
|
|
|
end
|
|
|
|
}
|
2010-09-09 16:09:27 +00:00
|
|
|
if client.platform =~ /win32|win64/
|
|
|
|
if args.length == 0
|
|
|
|
print_line "Meterpreter Script for enumerating Current logged users and users that have loged in to the system."
|
|
|
|
print_line(@@exec_opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print_error("This version of Meterpreter is not supported with this Script!")
|
2010-07-10 20:19:49 +00:00
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|