2011-01-12 18:29:56 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
2011-01-11 02:02:11 +00:00
|
|
|
|
2011-01-12 18:29:56 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2011-01-11 02:02:11 +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/
|
2011-01-12 18:29:56 +00:00
|
|
|
##
|
2011-01-11 02:02:11 +00:00
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
2011-01-12 00:11:43 +00:00
|
|
|
require 'msf/core/post/windows/registry'
|
2011-01-24 17:25:52 +00:00
|
|
|
require 'msf/core/post/windows/accounts'
|
2011-01-11 02:02:11 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
2011-06-21 00:38:04 +00:00
|
|
|
include Msf::Post::Windows::Registry
|
|
|
|
include Msf::Post::Windows::Accounts
|
2011-01-11 02:02:11 +00:00
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2011-04-27 16:25:15 +00:00
|
|
|
'Name' => 'Windows Gather Logged On User Enumeration (Registry)',
|
2011-02-26 02:47:40 +00:00
|
|
|
'Description' => %q{ This module will enumerate current and recently logged on Windows users},
|
2011-01-11 02:02:11 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
|
|
|
'Version' => '$Revision$',
|
2012-10-23 18:33:01 +00:00
|
|
|
'Platform' => [ 'win' ],
|
2011-01-11 02:02:11 +00:00
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptBool.new('CURRENT', [ true, 'Enumerate currently logged on users', true]),
|
|
|
|
OptBool.new('RECENT' , [ true, 'Enumerate Recently logged on users' , true])
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def ls_logged
|
2011-01-11 22:30:40 +00:00
|
|
|
sids = []
|
|
|
|
sids << registry_enumkeys("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList")
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
2011-01-24 17:25:52 +00:00
|
|
|
'Header' => "Recently Logged Users",
|
2011-01-11 02:02:11 +00:00
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
2011-01-12 23:25:00 +00:00
|
|
|
[
|
2011-01-11 02:02:11 +00:00
|
|
|
"SID",
|
|
|
|
"Profile Path"
|
|
|
|
])
|
2011-01-24 17:25:52 +00:00
|
|
|
sids.flatten.map do |sid|
|
2011-01-26 15:55:35 +00:00
|
|
|
profile_path = registry_getvaldata("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\#{sid}","ProfileImagePath")
|
|
|
|
tbl << [sid,profile_path]
|
2011-01-12 17:33:46 +00:00
|
|
|
end
|
|
|
|
print_line("\n" + tbl.to_s + "\n")
|
2011-11-20 01:53:25 +00:00
|
|
|
store_loot("host.users.recent", "text/plain", session, tbl.to_s, "recent_users.txt", "Recent Users")
|
2011-01-11 02:02:11 +00:00
|
|
|
end
|
|
|
|
|
2011-01-24 17:25:52 +00:00
|
|
|
|
2011-01-11 02:02:11 +00:00
|
|
|
def ls_current
|
2011-01-11 22:30:40 +00:00
|
|
|
key_base, username = "",""
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
2011-01-11 02:02:11 +00:00
|
|
|
'Header' => "Current Logged Users",
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
2011-01-12 23:25:00 +00:00
|
|
|
[
|
2011-01-11 02:02:11 +00:00
|
|
|
"SID",
|
|
|
|
"User"
|
|
|
|
])
|
2011-01-24 17:25:52 +00:00
|
|
|
registry_enumkeys("HKU").each do |maybe_sid|
|
|
|
|
# There is junk like .DEFAULT we want to avoid
|
|
|
|
if maybe_sid =~ /^S(?:-\d+){2,}$/
|
|
|
|
info = resolve_sid(maybe_sid)
|
|
|
|
|
|
|
|
if !info.nil? && info[:type] == :user
|
|
|
|
username = info[:domain] << '\\' << info[:name]
|
|
|
|
|
|
|
|
tbl << [maybe_sid,username]
|
2011-01-11 02:02:11 +00:00
|
|
|
end
|
|
|
|
end
|
2011-01-12 17:33:46 +00:00
|
|
|
end
|
2011-01-24 17:25:52 +00:00
|
|
|
|
2011-01-12 17:33:46 +00:00
|
|
|
print_line("\n" + tbl.to_s + "\n")
|
2012-02-20 20:22:05 +00:00
|
|
|
p = store_loot("host.users.active", "text/plain", session, tbl.to_s, "active_users.txt", "Active Users")
|
|
|
|
print_status("Results saved in: #{p}")
|
2011-01-11 02:02:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
print_status("Running against session #{datastore['SESSION']}")
|
|
|
|
|
|
|
|
if datastore['CURRENT']
|
|
|
|
ls_current
|
|
|
|
end
|
|
|
|
|
|
|
|
if datastore['RECENT']
|
|
|
|
ls_logged
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|