Fixes #3531, Use new accounts mixin to resolve SID->Account Names

git-svn-id: file:///home/svn/framework3/trunk@11630 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Joshua Drake 2011-01-24 17:25:52 +00:00
parent 0af8915fd5
commit 29b03701d1
1 changed files with 22 additions and 27 deletions

View File

@ -12,10 +12,12 @@
require 'msf/core' require 'msf/core'
require 'rex' require 'rex'
require 'msf/core/post/windows/registry' require 'msf/core/post/windows/registry'
require 'msf/core/post/windows/accounts'
class Metasploit3 < Msf::Post class Metasploit3 < Msf::Post
include Msf::Post::Registry include Msf::Post::Registry
include Msf::Post::Accounts
def initialize(info={}) def initialize(info={})
super( update_info( info, super( update_info( info,
@ -40,20 +42,26 @@ class Metasploit3 < Msf::Post
sids = [] sids = []
sids << registry_enumkeys("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList") sids << registry_enumkeys("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList")
tbl = Rex::Ui::Text::Table.new( tbl = Rex::Ui::Text::Table.new(
'Header' => "Logged Users", 'Header' => "Recently Logged Users",
'Indent' => 1, 'Indent' => 1,
'Columns' => 'Columns' =>
[ [
"SID", "SID",
"Profile Path" "Profile Path"
]) ])
sids.flatten.each do |sid| sids.flatten.map do |sid|
info = resolve_sid(sid)
if !info.nil? && info[:type] == :user
profile_path = registry_getvaldata("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\#{sid}","ProfileImagePath") profile_path = registry_getvaldata("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\#{sid}","ProfileImagePath")
tbl << [sid,profile_path] tbl << [sid,profile_path]
end end
end
print_line("\n" + tbl.to_s + "\n") print_line("\n" + tbl.to_s + "\n")
end end
def ls_current def ls_current
key_base, username = "","" key_base, username = "",""
tbl = Rex::Ui::Text::Table.new( tbl = Rex::Ui::Text::Table.new(
@ -64,34 +72,21 @@ class Metasploit3 < Msf::Post
"SID", "SID",
"User" "User"
]) ])
registry_enumkeys("HKU").each do |sid| registry_enumkeys("HKU").each do |maybe_sid|
case sid # There is junk like .DEFAULT we want to avoid
when "S-1-5-18" if maybe_sid =~ /^S(?:-\d+){2,}$/
username = "SYSTEM" info = resolve_sid(maybe_sid)
tbl << [sid,username]
when "S-1-5-19" if !info.nil? && info[:type] == :user
username = "Local Service" username = info[:domain] << '\\' << info[:name]
tbl << [sid,username]
when "S-1-5-20" tbl << [maybe_sid,username]
username = "Network Service"
tbl << [sid,username]
else
if sid =~ /S-1-5-21-\d*-\d*-\d*-\d*$/
key_base = "HKU\\#{sid}"
os = session.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
tbl << [sid,username]
end end
end end
end end
print_line("\n" + tbl.to_s + "\n")
end
print_line("\n" + tbl.to_s + "\n")
end
def run def run
print_status("Running against session #{datastore['SESSION']}") print_status("Running against session #{datastore['SESSION']}")