zoukankan      html  css  js  c++  java
  • snmp协议详解

    一、总体把握

    1、基于TCP/IP的网络管理的四个组成部分

    (1)    管理信息库(MIB),包含代理进程可能被查询或修改的所有参数,即被管理对象的参数。

    (2)    管理信息结构(SMI),管理信息是一个被管理对象的集合,SMI定义了一个设备维护的规则集,用于对被管理对象进行命名和编码。

    (3)    SNMP协议,管理进程和代理进程之间的通信协议。SNMP协议是应用层协议,其下层协议一般为UDP,管理进程端口号为162,代理进程端口号为161。

    (4)    安全机制,在SNMPv1中安全机制很简单,v2和v3在安全机制上作了一些改善。

    2、管理信息库和管理信息结构

    (1)    管理信息结构之于管理信息库类似于模式之于数据库。管理信息结构定义了每一个对象“看上去像什么”,管理信息库则说明每个对象“是什么”。

    (2)    管理信息库的变量。有两种变量,一是简单变量,一是表格。简单变量对应于MIB树中的叶子结点,其标识方法是在其对象标识后面添加“.0”;表格的标识方法是采用联合索引的方式。

    3、SNMP协议和安全机制

    (1)    SNMP协议主要有五种报文get、getnext、set、getresponse,trap。其中前三种报文是管理进程发出的;后两种是代理进程发出的。

    (2)    安全机制,SNMPv1采用了“共同体”的字段作为管理进程和代理进程的鉴别密码,只有具有相应的“共同体名”,才有访问权限,这种方式只是简单的明文交换方式;SNMPv2 的安全机制没有本质的改进;SNMPv3提出了新的安全机制,同时还有一套专门的网络安全和访问控制规则。

    二、SNMP网络管理工具

    1、snmpget

    是管理进程从代理进程获取信息的命令。

    例如:snmpget -c public localhost system.sysDescr.0

    system.sysDescr.0 = Unknown

    -c 指明共同体字符串。

    2、snmpgetnext

    3、snmpset

    4、snmptrap

    5、snmpwalk

    6、snmptranslate

    三、SNMP体系结构

    1、体系结构可满足的应用需求

    (1)    只具有命令应答器和通知产生器应用程序的SNMP实体(传统的代理端Agent);

    (2)    具有代理转发应用程序的SNMP实体(传统的SNMP Proxy Agent);

    (3)    具有命令产生器和通知接收器应用程序的命令行驱动的SNMP实体(传统的管理端Manager);

    (4)    具有命令产生器和通知接收器应用程序,加上命令应答器和通知产生器应用程序的SNMP实体(传统的SNMP中间水平管理器或双重实体);

    (5)    具有命令产生器和通知接收器和其他为了管理大量被管节点的应用程序(传统的(网络)管理站)。

    2、本体系结构的目标

    (1)    尽可能多的利用现有资源;

    (2)    完善对安全机制的支持;

    (3)    

    3、三种安全需求

    (1)    主要安全威胁:篡改消息、伪装;

    (2)    次要安全威胁:篡改消息流、泄露;

    (3)    较小安全威胁:拒绝服务、通信量分解。

    4、文档概述

    图1所示文档结构定义了SNMP框架。

    5、SNMPv3的体系结构

    SNMPv3的一个目标是支持一种容易扩展的模块化体系结构,将以前版本中的代理和管理站统一为SNMP实体。SNMP实体由两部分组成:SNMP引擎和SNMP应用程序(如图2)。

    SNMP引擎。在同一管理域内,具有唯一的snmpEngineID,SNMP引擎与SNMP实体是一一对应的关系,它包含四个子系统。

    l         Dispatcher(调度程序):在一个SNMP引擎中,具有唯一的调度程序,它允许并发支持多版本SNMP消息。主要功能:

    1)       从网络上接收或向网络发送SNMP消息;

    2)       进行版本确认,并且同相应的消息处理模块交互;

    3)       为SNMP应用程序之间传送PDU提供抽象接口。

    l         Message Processing Subsystem(消息处理子系统):负责准备要发送的消息和从接收到的消息中提取数据。它包含多个消息处理模型(4个),各个模型对应一个SNMP版本,负责为特定的版本格式准备待发送的消息,和提取特定版本消息的数据。

    l         Security Subsystem(安全子系统):包括基于用户的安全模型和基于共同体的安全模型。提供了诸如鉴别、加解密等安全服务。安全子系统定义可防范的威胁,和提供安全服务使用的安全协议。安全协议界定实现机制和过程,以及提供诸如鉴别和加解密服务的MIB对象。

    l         Access Control Subsystem(访问控制子系统):包括基于视图的访问控制模型和其他访问控制模型。通过访问控制模型提供授权服务,即确定是否允许访问一个管理对象。访问控制模型为了支持访问权决策,详细定义了访问决策功能。

    Applications

    五种SNMP实体内部应用程序:

    l         Command Generator(命令生成器):生成收集或设置管理数据的SNMP命令;

    l         Command Responders(命令应答器):提供对管理数据的访问;

    l         Notification Originators(通知产生器):初始化Trap或Inform消息;

    l         Notification Receivers(通知接收器):接收并处理Trap或Inform消息;

    l         Proxy Forwarders(代理转发器):转发SNMP实体之间的消息。

    这些应用程序都使用SNMP引擎提供的服务。

    包含命令生成器、通知产生器、通知接收器的SNMP实体,即传统的SNMP管理站(如图3)

         包含一个或多个命令响应器、通知发生器、代理转发器的SNMP实体,即传统的SNMP代理(如图4)

    6、抽象服务接口(Abstract Service Interface)

    抽象服务接口描述了SNMP实体内各子系统之间概念接口的,它倾向有助于阐述SNMP实体的外部可见行为,而不倾向于约束内部执行的结构或组织形式,抽象服务接口不能认为是API,它由一组定义了所提供服务和抽象数据元素的原语所定义。

    (1)    Dispatcher Primitives(调度程序原语)

    调度程序的典型功能是通过PDU调度程序为SNMP应用程序提供服务。

    l         产生流出的(Outgoing)请求或通知

    PDU调度为应用程序提供如下原语用于向其他SNMP实体发送SNMP请求或通知:

    statusInformation = -- sendPduHandle if success

    -- errorIndication if failure

    sendPdu(

    IN transportDomain -- transport domain to be used

    IN transportAddress -- transport address to be used

    IN messageProcessingModel -- typically, SNMP version

    IN securityModel      -- Security Model to use

    IN securityName      -- on behalf of this principal

    IN securityLevel      -- Level of Security requested

    IN contextEngineID   -- data from/at this entity

    IN contextName      -- data from/in this context

    IN pduVersion       -- the version of the PDU

    IN PDU             -- SNMP Protocol Data Unit

    IN expectResponse    -- TRUE or FALSE

    )

    l         处理引入的(Incoming)请求或通知PDU

    PDU调度通过如下原语将SNMP PDU传送给应用程序

    processPdu(                  -- process Request/Notification PDU

    IN messageProcessingModel     -- typically, SNMP version

    IN securityModel              -- Security Model in use

    IN securityName               -- on behalf of this principal

    IN securityLevel               -- Level of Security

    IN contextEngineID            -- data from/at this SNMP entity

    IN contextName               -- data from/in this context

    IN pduVersion                -- the version of the PDU

    IN PDU                      -- SNMP Protocol Data Unit

    IN maxSizeResponseScopedPDU -- maximum size of the Response PDU

    IN stateReference              -- reference to state information

    )                            -- needed when sending a response

    l         产生流出的(Outgoing)响应

    PDU调度为应用程序返回SNMP响应PDU给PDU调度提供了如下原语:

    result   =                   -- SUCCESS or FAILURE

    returnResponsePdu(

    IN messageProcessingModel    -- typically, SNMP version

    IN securityModel             -- Security Model in use

    IN securityName              -- on behalf of this principal

    IN securityLevel              -- same as on incoming request

    IN contextEngineID            -- data from/at this SNMP entity

    IN contextName               -- data from/in this context

    IN pduVersion                -- the version of the PDU

    IN PDU                      -- SNMP Protocol Data Unit

    IN maxSizeResponseScopedPDU   -- maximum size sender can accept

    IN stateReference                -- reference to state information

    -- as presented with the request

    IN statusInformation              -- success or errorIndication

    )                              -- error counter OID/value if error

    l         处理引入的(Incoming)响应PDU

    PDU调度通过如下原语将引入的SNMP响应PDU传送给应用程序:

    processResponsePdu( -- process Response PDU

    IN messageProcessingModel -- typically, SNMP version

    IN securityModel -- Security Model in use

    IN securityName -- on behalf of this principal

    IN securityLevel -- Level of Security

    IN contextEngineID -- data from/at this SNMP entity

    IN contextName -- data from/in this context

    IN pduVersion -- the version of the PDU

    IN PDU -- SNMP Protocol Data Unit

    IN statusInformation -- success or errorIndication

    IN sendPduHandle -- handle from sendPdu

    )

    l         为操作的SNMP PDU注册职责(响应性)

    应用程序可以通过PDU调度的原语为一个特定的contextEngineID或特定的pduType注册或注销职责,可以注册的特定的pduType清单由Message Processing Model(消息处理模型)决定。

    statusInformation = -- success or errorIndication

    registerContextEngineID(

    IN contextEngineID -- take responsibility for this one

    IN pduType -- the pduType(s) to be registered

    )

    unregisterContextEngineID(

    IN contextEngineID -- give up responsibility for this one

    IN pduType -- the pduType(s) to be unregistered

    )

    注,实现registerContextEngineID或unregisterContextEngineID抽象服务接口,要为注册各种可能的contextEngineId或pduType参数值的应用程序提供具体实现方式。

    (2)    Message Processing Subsystem Primitives(消息处理子系统原语)

    调度程序为了处理特定版本的SNMP消息,同消息处理子系统进行交互。

    l         准备外流的SNMP请求或通知消息

    消息处理子系统提供了准备外流的SNMP请求或通知消息的服务原语。

    statusInformation =           -- success or errorIndication

    prepareOutgoingMessage(

    IN transportDomain           -- transport domain to be used

    IN transportAddress           -- transport address to be used

    IN messageProcessingModel    -- typically, SNMP version

    IN securityModel             -- Security Model to use

    IN securityName              -- on behalf of this principal

    IN securityLevel              -- Level of Security requested

    IN contextEngineID            -- data from/at this entity

    IN contextName               -- data from/in this context

    IN pduVersion                -- the version of the PDU

    IN PDU                      -- SNMP Protocol Data Unit

    IN expectResponse             -- TRUE or FALSE

    IN sendPduHandle              -- the handle for matching

    -- incoming responses

    OUT destTransportDomain        -- destination transport domain

    OUT destTransportAddress        -- destination transport address

    OUT outgoingMessage            -- the message to send

    OUT outgoingMessageLength      -- its length

    )

    l         准备外流的SNMP响应消息

    消息处理子系统提供准备外流的SNMP响应消息的服务原语。

    result =                        -- SUCCESS or FAILURE

    prepareResponseMessage(

    IN messageProcessingModel       -- typically, SNMP version

    IN securityModel                 -- same as on incoming request

    IN securityName                 -- same as on incoming request

    IN securityLevel                 -- same as on incoming request

    IN contextEngineID              -- data from/at this SNMP entity

    IN contextName                  -- data from/in this context

    IN pduVersion                   -- the version of the PDU

    IN PDU                         -- SNMP Protocol Data Unit

    IN maxSizeResponseScopedPDU     -- maximum size able to accept

    IN stateReference                  -- reference to state information

    -- as presented with the request

    IN statusInformation              -- success or errorIndication

    -- error counter OID/value if error

    OUT destTransportDomain         -- destination transport domain

    OUT destTransportAddress         -- destination transport address

    OUT outgoingMessage             -- the message to send

    OUT outgoingMessageLength        -- its length

    )

    l         从引入的SNMP消息准备数据元素

    消息处理子系统提供从引入的SNMP消息抽象数据元素的服务原语。

    result = -- SUCCESS or errorIndication

    prepareDataElements(

    IN transportDomain -- origin transport domain

    IN transportAddress -- origin transport address

    IN wholeMsg -- as received from the network

    IN wholeMsgLength -- as received from the network

    OUT messageProcessingModel -- typically, SNMP version

    OUT securityModel -- Security Model to use

    OUT securityName -- on behalf of this principal

    OUT securityLevel -- Level of Security requested

    OUT contextEngineID – data from/at this entity

    OUT contextName -- data from/in this context

    OUT pduVersion -- the version of the PDU

    OUT PDU -- SNMP Protocol Data Unit

    OUT pduType -- SNMP PDU type

    OUT sendPduHandle -- handle for matched request

    OUT maxSizeResponseScopedPDU -- maximum size sender can accept

    OUT statusInformation -- success or errorIndication

    -- error counter OID/value if error

    OUT stateReference -- reference to state information

    -- to be used for possible Response

    )

    (3)    Access Control Subsystem Primitives(访问控制子系统原语)

    应用程序相对于访问控制子系统服务是典型客户机程序。访问控制子系统通过如下原语检查是否允许某个访问。

    statusInformation = -- success or errorIndication

    isAccessAllowed(

    IN securityModel -- Security Model in use

    IN securityName -- principal who wants to access

    IN securityLevel -- Level of Security

    IN viewType -- read, write, or notify view

    IN contextName -- context containing variableName

    IN variableName -- OID for the managed object

    )

    (4)    Security Subsystem Primitives(安全子系统原语)

    消息处理子系统相对于安全子系统服务器是典型的客户机程序。

    l         产生一条请求或通知消息

    安全子系统通过如下原语产生一条请求或通知消息。

    statusInformation =

    generateRequestMsg(

    IN messageProcessingModel -- typically, SNMP version

    IN globalData -- message header, admin data

    IN maxMessageSize -- of the sending SNMP entity

    IN securityModel -- for the outgoing message

    IN securityEngineID -- authoritative SNMP entity

    IN securityName -- on behalf of this principal

    IN securityLevel -- Level of Security requested

    IN scopedPDU -- message (plaintext) payload

    OUT securityParameters -- filled in by Security Module

    OUT wholeMsg -- complete generated message

    OUT wholeMsgLength -- length of the generated message

    )

    l         处理引入的消息

    安全子系统通过如下原语处理引入的消息

    statusInformation = -- errorIndication or success

    -- error counter OID/value if error

    processIncomingMsg(

    IN messageProcessingModel -- typically, SNMP version

    IN maxMessageSize -- of the sending SNMP entity

    IN securityParameters -- for the received message

    IN securityModel -- for the received message

    IN securityLevel -- Level of Security

    IN wholeMsg -- as received on the wire

    IN wholeMsgLength -- length as received on the wire

    OUT securityEngineID -- authoritative SNMP entity

    OUT securityName -- identification of the principal

    OUT scopedPDU, -- message (plaintext) payload

    OUT maxSizeResponseScopedPDU -- maximum size sender can handle

    OUT securityStateReference -- reference to security state

    ) -- information, needed for response

    l         产生应答消息

    安全子系统通过如下原语产生应答消息。

    statusInformation =

    generateResponseMsg(

    IN messageProcessingModel -- typically, SNMP version

    IN globalData -- message header, admin data

    IN maxMessageSize -- of the sending SNMP entity

    IN securityModel -- for the outgoing message

    IN securityEngineID -- authoritative SNMP entity

    IN securityName -- on behalf of this principal

    IN securityLevel -- for the outgoing message

    IN scopedPDU -- message (plaintext) payload

    IN securityStateReference -- reference to security state

    -- information from original request

    OUT securityParameters -- filled in by Security Module

    OUT wholeMsg -- complete generated message

    OUT wholeMsgLength -- length of the generated message

    )

    (5)    公用原语(Common Primitives)

    如下原语是多个子系统公用的原语。

    l         Release State Reference Information(释放状态索引信息)

    所有传送状态索引信息的子系统同时提供了释放状态索引的原语,用于释放存放索引内存。

    stateRelease(

    IN stateReference -- handle of reference to be released

    )

    (6)方案图

    l         命令生成器或通知产生器

    这张图反映命令生成器或通知产生器应用程序如何请求、PDU如何发送以及应答如何返回给应用程序的。

    l         命令应答器应用程序的方案图

    本张图给出命令应答器或通知接收器应用程序如何注册PDUType处理,在接收到SNMP消息后如何将PDU调度到应用程序,以及响应如何回送到网络。

    7、SNMP管理框架被管对象的定义

    (1)SNMP管理框架中用到的文本协定

    l         SnmpEngineID:是一个SNMP引擎管理的唯一标识,它只用来标势不用于选址,即使使用了地址。它的值不能全0也不能全1或者为空,其初始值可由控制台配置,也可由算法生成,推荐使用算法生成方式。

    l         SnmpSecurityModel:是在一个SNMP管理体系中唯一标识安全模型的标识符。它的值通过如下方式分配:0不标识任何安全模型;1—255(包括255)保留给IANA;大于255分配给各个企业安全模型。

    l         SnmpMessageProcessingModel:是在一个SNMP管理体系中唯一标识消息处理模型的标识符。它的值通过如下方式分配:0—255(包括255)保留给IANA;大于255指派给各个企业消息处理模型。

    l         SnmpSecurityLevel:SNMP消息在哪个安全水平上可以被发送或被处理。它的值有:noAuthNoPriv,AuthNoPriv,AuthPriv。

    l         SnmpAdminString:一个包含管理信息可被人识别的八位字符串。

    (2)管理分配

    l         snmpFrameworkAdmin

    l         snmpFrameworkMIBObject

    l         snmpFrameworkConformance

    (3)snmpEngine组

    l         snmpEngine

    l         snmpEngineID:

    l         snmpEngineBoots

    l         snmpEngineTime

    l         snmpEngineMaxMessageSize

    (4)鉴别和加解密协议的注册点

    l         SnmpAuthProtocols

    l         SnmpPrivProtocols

    (5)一致性信息(conformance information)

    l         SnmpFrameworkMIBCompliances

    l         SnmpFrameworkMIBGroup 


    作者:古梅飞动
    公司:蜜团科技
    出处:http://www.mitsofts.com/index.php
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    C#微信开发
    3-4:字符串方法
    2-4-1 元组
    2-3-3 列表方法
    2-2-3:序列(字符串)乘法(p32)
    3-3字符串格式化(p47)
    2-2:分片
    2-1:Print date(p28)
    old.2.三次登录机会
    old.2.sum(1-2+3-4+...+99)
  • 原文地址:https://www.cnblogs.com/luhuan860/p/1736653.html
Copyright © 2011-2022 走看看