Endorphin
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    [Note] SNMP learning note === ###### tags: `note`, `protocol`, `SNMP`, `SNMP v1, v2c, v3`, `MIB`, `OID`, `Trap` [Toc] # Introduction SNMP is - an abbreviation of Simple Network Management Protocol which is used for network management. - a client/server protocol. - a manager/agent protocol in SNMP terminology. - a request/response protocol. - currently used with three versions - v1 (RFC 1157) - v2 (RFC 1902) - v3 (RFC 2271~2275) - used to manage objects such as NIC, Ports or Vlan by OID and these OID is tree-identified and stored in MIB (Management Information Base). - a in the application layer of OSI model based on UDP. - using UDP port 161 to communicate between SNMP manager and SNMP agent while using UDP port 162 to receive a trap from the agent. - encoding its PDU by ASN-1 (Abstract Syntax Notation - One) > [^first]The agent (the server) runs on the device being managed, which is called the Managed Network Entity. The agent monitors the status of the device and reports that status to the manager. > The manager (the client) runs on the Network Management Station (NMS). The NMS collects information from all of the different devices that are being managed, consolidates it, and presents it to the network administrator. ![](https://i.imgur.com/YZt8PGO.png) # Protocol Specification ## PDU format ### Overview All implementations of the SNMP support the five PDUs: 1. GetRequest-PDU 2. GetNextRequest-PDU 3. GetResponse-PDU 4. SetRequest-PDU 5. Trap-PDU. >| Operation[^fifth]| Description | >| -------- | ------------------------------------------------------------------------------------------------ >| GET | Retrieve data from a network node >| GETNEXT | Retrieve the next element from a network node (more on this later) >| SET | Send configuration or control commands to a network node >| TRAP | A network node can send a notification to the management station >| INFORM | An acknowledged trap (network nodes can try and send it again if no acknowledgement is received) Below figure[^second] shows PDU formats of SNMPv1 and SNMPv2. >![](https://i.imgur.com/juyylql.png) ``` javascript -- top-level message Message ::= SEQUENCE { version -- version-1 for this RFC INTEGER { version-1(0) }, community -- community name OCTET STRING, data -- e.g., PDUs if trivial ANY -- authentication is being used } -- protocol data units PDUs ::= CHOICE { get-request GetRequest-PDU, get-next-request GetNextRequest-PDU, get-response GetResponse-PDU, set-request SetRequest-PDU, trap Trap-PDU } ``` ### 0. Common Structure **SNMPv1** PDU type includes 4 as shown below table. | Type | Action | | ---- | ---------------- | | 0 | Get-Request | | 1 | Get-Next-Request | | 2 | Set Request | | 3 | Get-Response | **SNMPv2** PDU type includes 7 as shown below table. | Type | Action | | ---- | ---------------- | | 0 | Get-Request | | 1 | Get-Next-Request | | 2 | Set Request | | 3 | Get-Response | | 4 | Reserved | | 5 | Get-Bulk-Request | | 6 | Inform-Request | | 7 | SNMPv2 Trap | #### Error Status In SNMPv1, there are 5 Error Status defined. In SNMPv2, it adds the other 13 ones. | Type | Name | | ---- | ------------------- | | 0 | noError | | 1 | tooBig | | 2 | noSuchName | | 3 | badValue | | 4 | readOnly | | 5 | GenErr | | 6 | noAccess | | 7 | wrongType | | 8 | wrongLength | | 9 | wrongEncoding | | 10 | wrongValue | | 11 | noCreation | | 12 | inconsistentValue | | 13 | resourceUnavailable | | 14 | commitFailed | | 15 | undoFailed | | 16 | authorizationError | | 17 | notWritable | | 18 | inconsistentName | ``` javascript -- request/response information RequestID ::= INTEGER ErrorStatus ::= INTEGER { noError(0), tooBig(1), noSuchName(2), badValue(3), readOnly(4) genErr(5) } ErrorIndex ::= INTEGER -- variable bindings VarBind ::= SEQUENCE { name ObjectName, value ObjectSyntax } VarBindList ::= SEQUENCE OF VarBind ``` ### 1. GetRequest-PDU ``` javascript GetRequest-PDU ::= IMPLICIT SEQUENCE { request-id RequestID, error-status -- always 0 ErrorStatus, error-index -- always 0 ErrorIndex, variable-bindings VarBindList } ``` ### 2. GetNextRequest-PDU ``` javascript GetNextRequest-PDU ::= IMPLICIT SEQUENCE { request-id RequestID, error-status -- always 0 ErrorStatus, error-index -- always 0 ErrorIndex, variable-bindings VarBindList } ``` ### 3. GetResponse-PDU ``` javascript GetResponse-PDU ::= IMPLICIT SEQUENCE { request-id RequestID, error-status ErrorStatus, error-index ErrorIndex, variable-bindings VarBindList } ``` ### 4. SetRequest-PDU ``` javascript SetRequest-PDU ::= IMPLICIT SEQUENCE { request-id RequestID, error-status -- always 0 ErrorStatus, error-index -- always 0 ErrorIndex, variable-bindings VarBindList } ``` ### 5. Trap-PDU ``` javascript Trap-PDU ::= IMPLICIT SEQUENCE { enterprise -- type of object generating -- trap OBJECT IDENTIFIER, agent-addr -- address of object generating NetworkAddress, -- trap generic-trap -- generic trap type INTEGER { coldStart(0), warmStart(1), linkDown(2), linkUp(3), authenticationFailure(4), egpNeighborLoss(5), enterpriseSpecific(6) }, specific-trap -- specific code, present even INTEGER, -- if generic-trap is not -- enterpriseSpecific time-stamp -- time elapsed between the last TimeTicks, -- (re)initialization of the network -- entity and the generation of the trap variable-bindings -- "interesting" information VarBindList } ``` ## SNMP operating procedure >![](https://i.imgur.com/phXYDpQ.png) :::info A **SNMP Manager** might be a NMS; A **SNMP Agent** might be a DUT. </br> ```sequence Note over SNMP Manager: Set SNMP Manager->SNMP Agent: set-request Note right of SNMP Agent: UDP:161 SNMP Agent-->SNMP Manager: get-response Note over SNMP Manager: Get/GetNext SNMP Manager->SNMP Agent: get-request Note right of SNMP Agent: UDP:161 SNMP Agent-->SNMP Manager: get-response Note over SNMP Agent: Trap SNMP Agent->SNMP Manager: trap Note left of SNMP Manager: UDP:162 ``` ::: ## SNMP trap > [^third]SNMP Traps are alert messages sent from a remote SNMP-enabled device to a central collector, the "SNMP manager". In more technical terms, SNMP Traps are asynchronous, unacked messages used to notify an entity, i.e. central management, of significant issues and events. > Below figure is **a traditional SNMP poll (left) vs an async SNMP trap (right)** > ![](https://i.imgur.com/j5hWaF7.png) > A Trap might tell you that a device is overheating, for example. (As you'll recall, SNMP is one possible protocol that devices can use to communicate.) Trap messages are the main form of communication between an SNMP Agent and an SNMP Manager. They are used to inform an SNMP manager when an important event happens at the Agent level. A benefit of using Traps for reporting alarms is that they trigger instantaniously, rather than waiting for a status request from the manager. # MIB (Management Information Base) MIB is used to describe the data structure of managed SNMP objects. Each SNMP object is described in an Ojbect Identified Tree. In a MIB tree, each node stands for management group such as internet, private and snmp or management object like system, ip and tcp. And the leaf is the information of SNMP object with an OID as shown below figure. > ![](https://i.imgur.com/Mnc6wl5.png) # Demo Here, I will show the captured packets of SNMP v1, v2c and v3 through Wireshark. And these PDUs including GetRequest, GetResponse and SetRequest. In this demonstration, I will utilize MG-SOFT MIB browser as the manager while a L2 management switch as the agent, and with below operation: 1. Get the value of *rstpHelloTime*. 2. Set the value of *rstpHelloTime* to 4. 3. Set the value of *rstpHelloTime* to an invalid value 1314520. ![](https://i.imgur.com/XuL3Rwg.png) BTW, there is a question that **how do it check if the value we set to *rstpHelloTime* is valid or invalid**? In fact, the agent here is running net-snmp, and in the path *net-snmp/agent/xxxMIB/rstp.c* we should do this like[^fourth] ``` C= int write_rstpXXXX (int action, u_char * var_val, u_char var_val_type, size_t var_val_len, u_char * statP, oid * name, size_t name_len) { switch(action) { case xxxx: if (var_val_type != ASN_INTEGER) { DEBUGMSGTL(("snmpRSTP", "write to rstpHelloTime not ASN_INTEGER\n")); return SNMP_ERR_WRONGTYPE; } if (*(long *)(var_val < 1) || *(long *)(var_val > 10)) return SNMP_ERR_WRONGVALUE; } } ``` Besides, this object *rstpHelloTime* is defined in a MIB as shown below. ```javascript rstpHelloTime OBJECT-TYPE SYNTAX Integer32 MAX-ACCESS read-write STATUS current DESCRIPTION "The number of seconds between the transmission of Spanning-Tree Protocol configuration messages. Enter a number 1 through 10 Note: 2*(Forward Delay Time-1) should be greater than or equal to the Max Age. The Max Age should be greater than or equal to 2*(Hello Time + 1). This item can't be modified, if rstpStatus was disabled." ::= { rstp 4 } ``` ## SNMPv1 **Operation Sequence** ![](https://i.imgur.com/MNuFzC7.png) ### GetRequest PDU This PDU is a request to get the value of *rstpHelloTime*. ![](https://i.imgur.com/EDSFAS5.png) ### GetResponse PDU This PDU is a response after the request to get the value of *rstpHelloTime* = 2. ![](https://i.imgur.com/Jjpzy8s.png) ### SetRequest PDU #### 1. SetRequest without an error This PDU is a request to set the value = 4 of *rstpHelloTime*. ![](https://i.imgur.com/2CUogQo.png) This PDU is a response without an error after above SetRequest. ![](https://i.imgur.com/ZqM9aAC.png) #### 2. SetRequest with an error This PDU is a request to set the value of *rstpHelloTime* with an invalid value = 1314520. ![](https://i.imgur.com/S8QaZ8h.png) This PDU is a response with an error after above SetRequest. ![](https://i.imgur.com/xu203Wi.png) ### Trap PDU #### 1. Link down ![](https://i.imgur.com/yA0dWRM.png) #### 2. Link up ![](https://i.imgur.com/wekaeaP.png) ## SNMPv2c **Operation Sequence** ![Uploading file..._68n18bv6c]() ### GetRequest PDU This PDU is a request to get the value of *rstpHelloTime*. ![](https://i.imgur.com/SAUFzeJ.png) ### GetResponse PDU This PDU is a response after the request to get the value of *rstpHelloTime* = 2. ![](https://i.imgur.com/Si25fMs.png) ### Trap PDU #### 1. Link down ![](https://i.imgur.com/B5uaTJ9.png) #### 2. Link up ![](https://i.imgur.com/WIJlaT1.png) ### SetRequest PDU #### 1. SetRequest without an error This PDU is a request to set the value = 5 of *rstpHelloTime*. ![](https://i.imgur.com/T7NW0ZM.png) This PDU is a response without an error after above SetRequest. ![](https://i.imgur.com/CSoXjBe.png) #### 2. SetRequest with an error This PDU is a request to set the value of *rstpHelloTime* with an invalid value = 1314520. ![](https://i.imgur.com/d05CLn6.png) This PDU is a response with an error after above SetRequest. ![](https://i.imgur.com/qm72n4Q.png) ## SNMPv3 Configuration in SNMP agent. ``` javascript User Name: test Security Level: Authentication Authentication Level: MD5 Authentication Password: ******** ``` **Operation Sequence** ![](https://i.imgur.com/sehnGtg.png) ### GetRequest PDU This PDU is a request to get the value of *rstpHelloTime*. ![](https://i.imgur.com/TRxcFmg.png) ### GetResponse PDU This PDU is a response after the request to get the value of *rstpHelloTime* = 2. ![](https://i.imgur.com/WHuhxbV.png) ### SetRequest PDU #### 1. SetRequest without an error This PDU is a request to set the value = 6 of *rstpHelloTime*. ![](https://i.imgur.com/EoQQvF4.png) This PDU is a response without an error after above SetRequest. ![](https://i.imgur.com/o1fTmFl.png) #### 2. SetRequest with an error This PDU is a request to set the value of *rstpHelloTime* with an invalid value = 1314520. ![](https://i.imgur.com/j9aeMv3.png) This PDU is a response with an error after above SetRequest. ![](https://i.imgur.com/utYy6jE.png) ### Trap >![](https://i.imgur.com/OsqgNqs.png)[^trap] [Download these captured PDUs here.](https://drive.google.com/open?id=11SrQ01_cKUfnCh7sE9RFlK--L0PX2mRH) # Security From above demo, we can obvious see that it is insecure in SNMP v1 and v2c because community strings are clear-text passwords. We can retrieve them easily. It could enable a man-in-the-middle or replay attack. Therefore, SNMP v3 was later developed to secure this protocol. Below figure shows SNMPv3 architecture. > ![](https://i.imgur.com/JMJsmhG.png) Our DUT only supports USM[^last] here. VACM[^vacm] is View Access Control Model. In this model, there are four steps. > 1. Map the community name (COMMUNITY) into a security name. > 2. Map the security names into group names. > 3. Create a view for us to let the groups have rights to > 4. Grant the groups access to their views ```cs= #### # First, map the community name (COMMUNITY) into a security name # (local and mynetwork, depending on where the request is coming # from): # sec.name source community com2sec local localhost secret42 com2sec cust1_sec 192.168.1.0/24 public com2sec cust2_sec 192.168.2.0/24 public #### # Second, map the security names into group names: # sec.model sec.name group MyRWGroup v1 local group MyRWGroup v2c local group cust1_grp v1 cust1_sec group cust1_grp v2c cust1_sec group cust2_grp v1 cust2_sec group cust2_grp v2c cust2_sec #### # Third, create a view for us to let the groups have rights to: # incl/excl subtree mask view all included .1 view cust1_v excluded .1 view cust1_v included sysUpTime.0 view cust1_v included interfaces.ifTable.ifEntry.ifIndex.1 ff.a0 view cust2_v excluded .1 view cust2_v included sysUpTime.0 view cust2_v included interfaces.ifTable.ifEntry.ifIndex.2 ff.a0 #### # Finally, grant the groups access to their views: # context sec.model sec.level match read write notif access MyRWGroup "" any noauth exact all all none access cust1_grp "" any noauth exact cust1_v none none access cust2_grp "" any noauth exact cust2_v none none ``` For more information of SNMPv3, you can reference to this[^this]. # Reference [^first]: http://web.deu.edu.tr/doc/oreily/networking/tcpip/ch11_09.htm [^second]: http://www.tsnien.idv.tw/Internet_WebBook/Book_PDF/%E7%AC%AC%E5%8D%81%E5%85%AD%E7%AB%A0%20SNMP%20%E7%B6%B2%E8%B7%AF%E7%AE%A1%E7%90%86%E5%8D%94%E5%AE%9A.pdf [^third]: https://www.dpstele.com/snmp/trap-basics.php [^fourth]: https://github.com/haad/net-snmp/blob/master/agent/mibgroup/snmpv3/snmpEngine.c [^fifth]: http://net-snmp.sourceforge.net/wiki/index.php/Tutorials [^last]: http://www.etop.org.tw/index.php?c=adm11252&m=getReportFile&d=adm&i=245177 [^this]:http://net-snmp.sourceforge.net/wiki/index.php/TUT:Security [^vacm]: http://net-snmp.sourceforge.net/wiki/index.php/Vacm [^trap]: https://prng0.wordpress.com/2013/06/18/wireshark-v1-6-7-supports-snmp-v3-traps-decode/

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully