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

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

Overview

This module exposes methods for querying a SNMP service

Instance Attribute Summary collapse

Attributes included from Udp

#udp_sock

Instance Method Summary collapse

Methods included from Udp

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

Instance Attribute Details

#snmpObject (protected)

Returns the value of attribute snmp.



65
66
67
# File 'lib/msf/core/exploit/remote/snmp_client.rb', line 65

def snmp
  @snmp
end

Instance Method Details

#communityObject



69
70
71
# File 'lib/msf/core/exploit/remote/snmp_client.rb', line 69

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



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

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['RHOST'] || rhost,
    :Port => opts['RPORT'] || 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



60
61
62
63
# File 'lib/msf/core/exploit/remote/snmp_client.rb', line 60

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

#initialize(info = {}) ⇒ Object

Creates an instance of a SNMP exploit module.



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

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



77
78
79
# File 'lib/msf/core/exploit/remote/snmp_client.rb', line 77

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

#timeoutObject



73
74
75
# File 'lib/msf/core/exploit/remote/snmp_client.rb', line 73

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