
In the following lines I will present a
Simple Network Management Protocol v2 "dissection". Thou the current SNMP version is 3, which brings many security enhancements, version 2 is still widely used, and besides that, is the version of the subjects I'm working with.
The SNMP arhitecture requires a management station to query and get the information, and an agent, to send the requested information. In my case, the management station will be
AutoScan , which will discover and automatically query, snmp enabled devices. Also, there are other well known tools, like SNMP walk, Snmpcheck, Snmp enum, or Mib browser.
A snmp message consists of a version identifier, an snmp community name(which actually acts like a authentication mechanism, allowing read,read-write, or only write acces on snmp enabled devices), and a protocol data unit (PDU).
In conformation with RFC 1157, is mandatory that all implementations of SNMP support the five PDU's: GetRequest, GetNextRequest, GetResponse, SetRequest and Trap. I think that is clearly what each PDU does, the name says all, only one mention here: GetNextRequest will request the following variable (OBJECT IDENTIFIER) in lexicographical order. We will see a bit later, how an Oid looks like.
Now, let's see exactly how snmp is represented in rfc 1157, for a better "visualization":
RFC1157-SNMP DEFINITIONS ::= BEGIN
IMPORTS
ObjectName, ObjectSyntax, NetworkAddress, IpAddress, TimeTicks
FROM RFC1155-SMI;
-- 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
}
-- the individual PDUs and commonly used
-- data types will be defined later
END
In our example, we will work with
GetRequest,
GetNextRequest,
GetResponse.
So, I fire up Wireshark, set the filter on udp.port == 161, setup
Autoscan, and start exploring the network.
GetRequest+-+Wireshark.png)
We can observe in the packet the version,
version-1, which coresponds to
RFC 1157, with a value of
0, which is ok, because a value different from 0, means error.
Next follows the comunity name: public, the default value, which acts like a authentication mechanism, as I stated before, and travels the network in plain text. After all,
Simple Network Management Protocol, was not designed with security in mind. Next, the
error-status and the
error-index show that everything is ok, and no error occured. About the
request-id, I will talk a bit later.
Next, we can see that the snmp packet, is querying 4 Oid's:
1.3.6.1.2.1.2.2.1.10.393218, 1.3.6.1.2.1.2.2.1.16.393218,
1.3.6.1.2.1.1.3.0, 1.3.6.1.2.1.1.5.0; while the first two variables are not standard they are formed with standard variables:
1.3.6.1.2.1.2.2.1.10 (IfInoctets-the total number of octets recived on the interface), and 1.3.6.1.2.1.2.2.1.16 (IfOutOctets-the total number of octets transmitted out of the interface); I think that this is a custom OID made by Autoscan Tool, you can register your own OID's
here . The next two OID's represent
SysUptime and sysName; basically we are asking for de device's uptime and his name.
GetNextRequest
We see here, how the management station sends a request after the
1.3.6.1.2.1.1.5 variable binding (Oid), which is
sysName, meaning that the management station is querying to find out the name of the snmp enabled device. It's ok that the
valueType is unSpecified, because the packet is not returning any value. And here is the response of the agent, returning the value:
GetResponse
Notice that the request id remains
1915072317 same, in the GetNextRequest packet and in the GetResponse packet. In the next GetNextRequest packet, querying for the next Oid,
1.3.6.1.2.1.1.1 (
sysDescr), in our case, the request id will be incremented by one. (
1915072318)
Something else to notice is that the packet returns the value of the Object Identifier requested,
sysName, which is in our case, the octet string BOX.
A few example's of OID's:
- 1.3.6.1.2.1.25.1.1.0 -> hrSystemUptime ;
- 1.3.6.1.2.1.25.2.2.0 -> hrMemorySize ;
- 1.3.6.1.2.1.4.1.0 -> IpForwarding;
- 1.3.6.1.2.1.4.2.0 -> ipDefaultTTL;
- 1.3.6.1.2.1.4.13.0 -> ipReasmTimeout;
- 1.3.6.1.2.1.4.3.0 -> ipInReceives;
- 1.3.6.1.2.1.4.10.0 -> ipOutRequests;
However I used Autoscan, to automate snmp request's, there are tools like snmpwalk to help you control the snmp request flow and search after specific OID's. It uses the freely avaible Net-SNMP library, and you could use it to make your own snmp tool, before you have in depth knowledge of the protocol.
Interesting sources avaible on the Internet: