Module: Msf::Exploit::Remote::SNMPClient

Includes:
Udp
Defined in:
lib/msf/core/exploit/snmp.rb

Overview

This module exposes methods for querying a SNMP service

Instance Method Summary collapse

Methods included from Udp

#chost, #cleanup, #connect_udp, #cport, #disconnect_udp, #handler, #lhost, #lport, #rhost, #rport

Instance Method Details

#communityObject


70
71
72
# File 'lib/msf/core/exploit/snmp.rb', line 70

def community
  datastore['COMMUNITY'] || 'public'
end

#connect_snmp(global = true, opts = {}) ⇒ Object

This method wraps the snmp library and passes in the Rex UDP socket


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/msf/core/exploit/snmp.rb', line 40

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 => opts['PeerHost'] || rhost,
    :Port => opts['PeerPort'] || rport,
    :Community => datastore['COMMUNITY'],
    :Version => version,
    :Timeout => datastore['TIMEOUT'],
    :Retries => datastore['RETRIES'],
    :Transport => SNMP::RexUDPTransport,
    :Socket => s
  )

  @snmp = snmp if global
  snmp
end

#disconnect_snmpObject


61
62
63
64
# File 'lib/msf/core/exploit/snmp.rb', line 61

def disconnect_snmp
  @snmp.close if @snmp
  @snmp = nil
end

#initialize(info = {}) ⇒ Object

Creates an instance of a SNMP exploit module.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/msf/core/exploit/snmp.rb', line 21

def initialize(info = {})
  super

  # Register the options that all SNMP exploits may make use of.
  register_options(
    [
      Opt::RHOST,
      Opt::RPORT(161),
      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

#retriesObject


78
79
80
# File 'lib/msf/core/exploit/snmp.rb', line 78

def retries
  datastore['RETRIES'] || 1
end

#timeoutObject


74
75
76
# File 'lib/msf/core/exploit/snmp.rb', line 74

def timeout
  datastore['TIMEOUT'] || 1
end