Fixed SNMP Library
git-svn-id: file:///home/svn/framework3/trunk@6531 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
8f63fc27e3
commit
d62822a9fb
|
@ -25,7 +25,10 @@ module Exploit::Remote::SNMPClient
|
|||
[
|
||||
Opt::RHOST,
|
||||
Opt::RPORT(161),
|
||||
OptString.new('COMMUNITY', [ false, 'The snmp community to use', 'public' ])
|
||||
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 ])
|
||||
], Msf::Exploit::Remote::SNMPClient)
|
||||
end
|
||||
|
||||
|
@ -35,12 +38,19 @@ module Exploit::Remote::SNMPClient
|
|||
#
|
||||
def connect_snmp(global=true, opts={})
|
||||
s = connect_udp(false, opts)
|
||||
|
||||
version = :SNMPv1 if datastore['VERSION'] == '1'
|
||||
version = :SNMPv2c if datastore['VERSION'] == '2c'
|
||||
|
||||
snmp = ::SNMP::Manager.new(
|
||||
:Host => rhost,
|
||||
:Port => rport,
|
||||
:Socket => s,
|
||||
:Transport => ::SNMP::RexUDPTransport,
|
||||
:Community => community
|
||||
:Community => datastore['COMMUNITY'],
|
||||
:Version => version,
|
||||
:Timeout => datastore['TIMEOUT'],
|
||||
:Retries => datastore['RETRIES'],
|
||||
:Transport => SNMP::RexUDPTransport,
|
||||
:Socket => s
|
||||
)
|
||||
|
||||
@snmp = snmp if global
|
||||
|
@ -60,6 +70,14 @@ module Exploit::Remote::SNMPClient
|
|||
datastore['COMMUNITY'] || 'public'
|
||||
end
|
||||
|
||||
def timeout
|
||||
datastore['TIMEOUT'] || 1
|
||||
end
|
||||
|
||||
def retries
|
||||
datastore['RETRIES'] || 1
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
attr_accessor :snmp
|
||||
|
|
|
@ -22,8 +22,12 @@ class RequestTimeout < RuntimeError; end
|
|||
# using other transport types (e.g. TCP)
|
||||
#
|
||||
class UDPTransport
|
||||
def initialize
|
||||
@socket = UDPSocket.open
|
||||
def initialize(socket = nil)
|
||||
@socket = socket
|
||||
|
||||
if socket.nil?
|
||||
@socket = UDPSocket.open
|
||||
end
|
||||
end
|
||||
|
||||
def close
|
||||
|
@ -40,27 +44,29 @@ class UDPTransport
|
|||
end
|
||||
|
||||
|
||||
##
|
||||
# Wrap socket in a Metasploit friendly Rex compatibility layer
|
||||
#
|
||||
class RexUDPTransport
|
||||
def initialize(socket)
|
||||
def initialize(socket = nil)
|
||||
@socket = socket
|
||||
|
||||
if socket.nil?
|
||||
@socket = UDPSocket.open
|
||||
end
|
||||
end
|
||||
|
||||
def close
|
||||
@socket.close
|
||||
end
|
||||
|
||||
def send(data, host, port, flags=0)
|
||||
def send(data, host, port, flags = 0)
|
||||
@socket.sendto(data, host, port, flags)
|
||||
end
|
||||
|
||||
def recv(max_bytes)
|
||||
@socket.recvfrom(max_bytes)
|
||||
@socket.recv(max_bytes)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
##
|
||||
# Manage a request-id in the range 1..2**31-1
|
||||
#
|
||||
|
@ -146,7 +152,7 @@ class Manager
|
|||
:Host => 'localhost',
|
||||
:Port => 161,
|
||||
:TrapPort => 162,
|
||||
:Socket => nil,
|
||||
:Socket => nil,
|
||||
:Community => 'public',
|
||||
:WriteCommunity => nil,
|
||||
:Version => :SNMPv2c,
|
||||
|
@ -184,11 +190,7 @@ class Manager
|
|||
@snmp_version = @config[:Version]
|
||||
@timeout = @config[:Timeout]
|
||||
@retries = @config[:Retries]
|
||||
if(@socket)
|
||||
@transport = @config[:Transport].new(@socket)
|
||||
else
|
||||
@transport = @config[:Transport].new
|
||||
end
|
||||
@transport = @config[:Transport].new(@socket)
|
||||
@max_bytes = @config[:MaxReceiveBytes]
|
||||
@mib = MIB.new
|
||||
load_modules(@config[:MibModules], @config[:MibDir])
|
||||
|
@ -492,10 +494,10 @@ class Manager
|
|||
timeout(@timeout) do
|
||||
return get_response(request)
|
||||
end
|
||||
rescue ::Interrupt
|
||||
raise $!
|
||||
rescue Timeout::Error
|
||||
# no action - try again
|
||||
rescue ::Interrupt
|
||||
raise $!
|
||||
end
|
||||
end
|
||||
raise RequestTimeout, "host #{@config[:Host]} not responding", caller
|
||||
|
|
Loading…
Reference in New Issue