2009-05-08 04:18:31 +00:00
|
|
|
require 'msf/core'
|
|
|
|
require 'snmp'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This module exposes methods for querying a SNMP service
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Exploit::Remote::SNMPClient
|
|
|
|
|
|
|
|
|
|
|
|
include Exploit::Remote::Udp
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Creates an instance of a SNMP exploit module.
|
|
|
|
#
|
|
|
|
def initialize(info = {})
|
|
|
|
super
|
|
|
|
|
|
|
|
# Register the options that all SNMP exploits may make use of.
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RHOST,
|
|
|
|
Opt::RPORT(161),
|
2009-05-08 19:56:32 +00:00
|
|
|
OptString.new('COMMUNITY', [ true, 'SNMP Community String', 'public' ]),
|
|
|
|
OptString.new('VERSION', [ true, 'SNMP Version <1/2c>', '1' ]),
|
|
|
|
OptInt.new('TIMEOUT', [ true, 'SNMP Timeout', 1 ]),
|
|
|
|
OptInt.new('RETRIES', [ true, 'SNMP Retries', 1 ])
|
2009-05-08 04:18:31 +00:00
|
|
|
], Msf::Exploit::Remote::SNMPClient)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# This method wraps the snmp library and passes in
|
|
|
|
# the Rex UDP socket
|
|
|
|
#
|
|
|
|
def connect_snmp(global=true, opts={})
|
|
|
|
s = connect_udp(false, opts)
|
2009-05-08 19:56:32 +00:00
|
|
|
|
|
|
|
version = :SNMPv1 if datastore['VERSION'] == '1'
|
|
|
|
version = :SNMPv2c if datastore['VERSION'] == '2c'
|
|
|
|
|
2009-05-08 04:18:31 +00:00
|
|
|
snmp = ::SNMP::Manager.new(
|
2010-12-11 23:36:37 +00:00
|
|
|
:Host => opts['PeerHost'] || rhost,
|
|
|
|
:Port => opts['PeerPort'] || rport,
|
2009-05-08 19:56:32 +00:00
|
|
|
:Community => datastore['COMMUNITY'],
|
|
|
|
:Version => version,
|
|
|
|
:Timeout => datastore['TIMEOUT'],
|
|
|
|
:Retries => datastore['RETRIES'],
|
2009-05-08 20:27:40 +00:00
|
|
|
:Transport => SNMP::RexUDPTransport,
|
|
|
|
:Socket => s
|
2009-05-08 04:18:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@snmp = snmp if global
|
|
|
|
snmp
|
|
|
|
end
|
|
|
|
|
|
|
|
def disconnect_snmp
|
|
|
|
@snmp.close if @snmp
|
|
|
|
@snmp = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def snmp
|
|
|
|
@snmp
|
|
|
|
end
|
|
|
|
|
|
|
|
def community
|
|
|
|
datastore['COMMUNITY'] || 'public'
|
|
|
|
end
|
|
|
|
|
2009-05-08 19:56:32 +00:00
|
|
|
def timeout
|
|
|
|
datastore['TIMEOUT'] || 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def retries
|
|
|
|
datastore['RETRIES'] || 1
|
|
|
|
end
|
|
|
|
|
2009-05-08 04:18:31 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
attr_accessor :snmp
|
|
|
|
end
|
|
|
|
end
|