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
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2011-01-12 18:29:56 +00:00
|
|
|
# http://metasploit.com/framework/
|
|
|
|
##
|
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
|
|
|
|
|
|
|
|
include Msf::Post::Registry
|
2011-01-24 17:25:52 +00:00
|
|
|
include Msf::Post::Accounts
|
2011-01-11 02:02:11 +00:00
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2011-02-25 21:00:33 +00:00
|
|
|
'Name' => 'Microsoft Windows Logged On User Enumeration (Registry)',
|
2011-01-11 02:02:11 +00:00
|
|
|
'Description' => %q{ This module will enumerate current and recent logged on users},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => [ 'windows' ],
|
|
|
|
'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-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")
|
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
|