Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

The gem does not recognize a missing OID #65

Closed
jinxka opened this issue Mar 24, 2022 · 7 comments
Closed

The gem does not recognize a missing OID #65

jinxka opened this issue Mar 24, 2022 · 7 comments

Comments

@jinxka
Copy link
Contributor

jinxka commented Mar 24, 2022

Hello,

I've crossed an issue with one of my device where the gem does not understand that the OID is missing while the snmpget command does.

image

Instead of raising the usual IPAddr::AddressFamilyError, the gem detects an Integer:0. This is problematic for me because I use the presence/absence of specific OIDs to detect the type of product I'm dealing with.

The debug from snmpget

Sending 70 bytes to UDP: [141.94.173.41]:30007->[0.0.0.0]:42102
0000: 30 44 02 01  03 30 11 02  04 74 03 FB  CE 02 03 00    0D...0...t......
0016: FF E3 04 01  04 02 01 03  04 10 30 0E  04 00 02 01    ..........0.....
0032: 00 02 01 00  04 00 04 00  04 00 30 1A  04 00 04 06    ..........0.....
0048: 70 75 62 6C  69 63 A0 0E  02 04 24 6C  5E 79 02 01    public....$l^y..
0064: 00 02 01 00  30 00                                    ....0.


Received 131 byte packet from UDP: [141.94.173.41]:30007->[0.0.0.0]:42102
0000: 30 81 80 02  01 03 30 11  02 04 74 03  FB CE 02 03    0.....0...t.....
0016: 00 FF E3 04  01 00 02 01  03 04 26 30  24 04 15 80    ..........&0$...
0032: 00 4F B8 05  38 63 38 31  61 39 61 66  32 37 65 36    .O..8c81a9af27e6
0048: 00 07 C3 40  02 01 02 02  02 0B E4 04  00 04 00 04    ...@............
0064: 00 30 40 04  15 80 00 4F  B8 05 38 63  38 31 61 39    .0@....O..8c81a9
0080: 61 66 32 37  65 36 00 07  C3 40 04 06  70 75 62 6C    af27e6...@..publ
0096: 69 63 A8 1F  02 04 24 6C  5E 79 02 01  00 02 01 00    ic....$l^y......
0112: 30 11 30 0F  06 0A 2B 06  01 06 03 0F  01 01 04 00    0.0...+.........
0128: 41 01 10                                              A..


Sending 159 bytes to UDP: [141.94.173.41]:30007->[0.0.0.0]:42102
0000: 30 81 9C 02  01 03 30 11  02 04 74 03  FB CD 02 03    0.....0...t.....
0016: 00 FF E3 04  01 07 02 01  03 04 43 30  41 04 15 80    ..........C0A...
0032: 00 4F B8 05  38 63 38 31  61 39 61 66  32 37 65 36    .O..8c81a9af27e6
0048: 00 07 C3 40  02 01 02 02  02 0B E4 04  09 73 69 6D    ...@.........sim
0064: 75 6C 61 74  6F 72 04 0C  18 BC D5 F2  97 6C 77 D1    ulator.......lw.
0080: 5D 0B 6C EA  04 08 75 E6  7D 63 AA 0D  7D ED 04 3F    ].l...u.}c..}..?
0096: B2 99 78 DD  40 A8 2D 18  B8 73 7E 91  A3 1D 07 E9    ..x.@.-..s~.....
0112: 74 1C AC 55  43 68 14 C3  B5 83 89 BE  B9 2E DA D2    t..UCh..........
0128: 02 90 C1 D3  9C 4E C2 9E  87 9B 1D AF  F7 76 4E 93    .....N.......vN.
0144: F9 D3 77 AB  2C 96 94 FC  3E 5E 02 9E  99 80 B8       ..w.,...>^.....


Received 160 byte packet from UDP: [141.94.173.41]:30007->[0.0.0.0]:42102
0000: 30 81 9D 02  01 03 30 11  02 04 74 03  FB CD 02 03    0.....0...t.....
0016: 00 FF E3 04  01 03 02 01  03 04 43 30  41 04 15 80    ..........C0A...
0032: 00 4F B8 05  38 63 38 31  61 39 61 66  32 37 65 36    .O..8c81a9af27e6
0048: 00 07 C3 40  02 01 02 02  02 0B E4 04  09 73 69 6D    ...@.........sim
0064: 75 6C 61 74  6F 72 04 0C  0B F5 02 08  D9 E6 EA 17    ulator..........
0080: 69 E7 11 3A  04 08 D7 C5  4E CA C7 6F  25 81 04 40    i..:....N..o%..@
0096: 44 C9 4D 85  E5 05 E4 3D  36 6E 6E 13  63 10 BD 66    D.M....=6nn.c..f
0112: 21 5E A7 B2  10 1B 73 11  E5 01 AB 93  3D 60 0B A9    !^....s.....=`..
0128: A8 53 43 B6  6F 3A 21 09  DE CD DA CD  3C CF 51 36    .SC.o:!.....<.Q6
0144: 58 74 2F 9D  76 6E 85 BB  6E B8 39 10  C5 24 4F 22    Xt/.vn..n.9..$O"

iso.3.6.1.4.5.4.2.3 = No Such Instance currently exists at this OID

We are also able to give you an access to one of our test environment, if you can help us with this issue.

@jinxka
Copy link
Contributor Author

jinxka commented Mar 24, 2022

The debug from the gem:

test.get(oid: '1.3.6.1.4.5.4.2.3')

sending request...

encoding PDU in V3 message...

3081 9d02 0103 3011 0204 6d09 9ab7 0203
00ff e304 0107 0201 0304 4330 4104 1580
004f b805 3934 3766 6335 3466 3139 3033
0007 6c80 0201 0202 0206 d304 0973 696d
756c 6174 6f72 040c 0000 0000 0000 0000
0000 0000 0408 0000 0000 0000 0001 0440
70d0 1b28 1dbf c65d 4465 673b 5f82 8811
13e5 4758 b427 6fb1 ea80 704b f3d3 1ac0
359c d324 7d4f 06fb 36ef 75b5 67ed e322
190b c518 9d85 cd4d 1b99 1d74 abfc 3f84

signing V3 message...

3081 9d02 0103 3011 0204 6d09 9ab7 0203
00ff e304 0107 0201 0304 4330 4104 1580
004f b805 3934 3766 6335 3466 3139 3033
0007 6c80 0201 0202 0206 d304 0973 696d
756c 6174 6f72 040c b470 ce19 e203 1b5e
3194 541a 0408 0000 0000 0000 0001 0440
70d0 1b28 1dbf c65d 4465 673b 5f82 8811
13e5 4758 b427 6fb1 ea80 704b f3d3 1ac0
359c d324 7d4f 06fb 36ef 75b5 67ed e322
190b c518 9d85 cd4d 1b99 1d74 abfc 3f84

received encoded V3 message

3081 9d02 0103 3011 0204 6d09 9ab7 0203
00ff e304 0103 0201 0304 4330 4104 1580
004f b805 3934 3766 6335 3466 3139 3033
0007 6c80 0201 0202 0207 3b04 0973 696d
756c 6174 6f72 040c b149 e9e1 0138 f491
cd64 63a6 0408 bfd4 264a e8c3 2ede 0440
e564 fdcf 1413 7e17 bcc7 2b46 c3ec c9f4
5765 2161 28ba 64d8 b33e 15bc fd63 115a
d8aa 7f57 cc73 f433 7d3c f00b 2c30 be5c
4f3b cff2 cfaf 6186 dfe7 29e5 1374 2318

received response PDU
 => 0 

@HoneyryderChuck
Copy link
Collaborator

HoneyryderChuck commented Mar 25, 2022

hi @jinxka ,

Can you run the example above with NETSNMP_DEBUG=2 and post the payload here?

@jinxka
Copy link
Contributor Author

jinxka commented Mar 25, 2022

Hi @HoneyryderChuck ,

Thanks for the quick response, here is the payload:

test.get(oid: '1.3.6.1.4.5.4.2.3')

sending probe...

pdu: 3014
        engine_id: 0400 ("")
        context: 0400 ("")
        request: a00e
                request_id: 0204 5ed6 1523 ("1591088419")
                error: 0201 ("0")
                error_index: 0201 ("0")
                varbinds: 3000

encoding PDU in V3 message...

security_params: 3023
        engine_id: 0400 ("")
        engine_boots: 0201 ("0")
        engine_time: 0201 ("0")
        username: 0409 7369 6d75 6c61 746f ("simulator")
        auth_mask: 040c 0000 0000 0000 0000 0000 0000 ("\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000")
        OctetString: 0400 ("")

v3_message: 3053
        message_version: 0201 ("3")
        headers: 3011
                message_id: 0204 0203 aa4e ("33794638")
                max_message_size: 0203 00ff ("65507")
                message_flags: 0401 ("\x04")
                security_model: 0201 ("3")
        security_params: 0425 3023 0400 0201 0002 0100 0409 7369 6d75 6c61 746f 7204 0c00 0000 0000 0000 0000 0000 0004 ("0#\x04\x00\x02\x01\x00\x02\x01\x00\x04\tsimulator\x04\f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00")
        pdu: 3014
                engine_id: 0400 ("")
                context: 0400 ("")
                request: a00e
                        request_id: 0204 5ed6 1523 ("1591088419")
                        error: 0201 ("0")
                        error_index: 0201 ("0")
                        varbinds: 3000

3053 0201 0330 1102 0402 03aa 4e02 0300
ffe3 0401 0402 0103 0425 3023 0400 0201
0002 0100 0409 7369 6d75 6c61 746f 7204
0c00 0000 0000 0000 0000 0000 0004 0030
1404 0004 00a0 0e02 045e d615 2302 0100
0201 0030

received encoded V3 message

3081 8402 0103 3011 0204 0203 aa4e 0203
00ff e304 0100 0201 0304 3030 2e04 1580
004f b805 3934 3766 6335 3466 3139 3033
0007 6c80 0201 0202 0300 fcad 0409 7369
6d75 6c61 746f 7204 0004 0030 3a04 1580
004f b805 3934 3766 6335 3466 3139 3033
0007 6c80 0400 a81f 0204 5ed6 1523 0201
0002 0100 3011 300f 060a 2b06 0106 030f
0101 0400 4101

v3_message: 3081
        message_version: 0201 ("3")
        headers: 3011
                Integer: 0204 0203 aa4e ("33794638")
                Integer: 0203 00ff ("65507")
                message_flags: 0401 ("\x00")
                Integer: 0201 ("3")
        security_params: 0430 302e 0415 8000 4fb8 0539 3437 6663 3534 6631 3930 3300 076c 8002 0102 0203 00fc ad04 0973 696d 756c 6174 6f72 0400 0400 ("0.\x04\x15\x80\x00O\xB8\x05947fc54f1903\x00\al\x80\x02\x01\x02\x02\x03\x00\xFC\xAD\x04\tsimulator\x04\x00\x04\x00")
        pdu: 303a
                OctetString: 0415 8000 4fb8 0539 3437 6663 3534 6631 3930 3300 076c ("\x80\x00O\xB8\x05947fc54f1903\x00\al\x80")
                OctetString: 0400 ("")
                ASN1Data: a81f
                        Integer: 0204 5ed6 1523 ("1591088419")
                        Integer: 0201 ("0")
                        Integer: 0201 ("0")
                        Sequence: 3011
                                Sequence: 300f
                                        ObjectId: 060a 2b06 0106 030f 0101 0400 ("1.3.6.1.6.3.15.1.1.4.0")
                                        ASN1Data: 4101

security_params: 302e
        engine_id: 0415 8000 4fb8 0539 3437 6663 3534 6631 3930 3300 076c ("\x80\x00O\xB8\x05947fc54f1903\x00\al\x80")
        engine_boots: 0201 ("2")
        engine_time: 0203 00fc ("64685")
        username: 0409 7369 6d75 6c61 746f ("simulator")
        auth_param: 0400 ("")
        priv_param: 0400 ("")

received response PDU

pdu: 3025
        engine_id: 0400 ("")
        context: 0400 ("")
        request: a81f
                request_id: 0204 5ed6 1523 ("1591088419")
                error: 0201 ("0")
                error_index: 0201 ("0")
                varbinds: 3011
                        Sequence: 300f
                                ObjectId: 060a 2b06 0106 030f 0101 0400 ("1.3.6.1.6.3.15.1.1.4.0")
                                Integer: 0201 ("10")

sending request...

pdu: 303d
        engine_id: 0415 8000 4fb8 0539 3437 6663 3534 6631 3930 3300 076c ("\x80\x00O\xB8\x05947fc54f1903\x00\al\x80")
        context: 0406 7075 626c 6963 ("public")
        request: a01c
                request_id: 0204 357c d1ca ("897372618")
                error: 0201 ("0")
                error_index: 0201 ("0")
                varbinds: 300e
                        Sequence: 300c
                                ObjectId: 0608 2b06 0104 0504 0203 ("1.3.6.1.4.5.4.2.3")
                                Null: 0500

encoding PDU in V3 message...

security_params: 3042
        engine_id: 0415 8000 4fb8 0539 3437 6663 3534 6631 3930 3300 076c ("\x80\x00O\xB8\x05947fc54f1903\x00\al\x80")
        engine_boots: 0201 ("2")
        engine_time: 0203 00fc ("64685")
        username: 0409 7369 6d75 6c61 746f ("simulator")
        auth_mask: 040c 0000 0000 0000 0000 0000 0000 ("\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000")
        salt: 0408 0000 0000 0000 0000 ("\x00\x00\x00\x00\x00\x00\x00\x00")

v3_message: 3081
        message_version: 0201 ("3")
        headers: 3011
                message_id: 0204 6765 ee0e ("1734733326")
                max_message_size: 0203 00ff ("65507")
                message_flags: 0401 ("\a")
                security_model: 0201 ("3")
        security_params: 0444 3042 0415 8000 4fb8 0539 3437 6663 3534 6631 3930 3300 076c 8002 0102 0203 00fc ad04 0973 696d 756c 6174 6f72 040c 0000 0000 0000 0000 0000 0000 0408 0000 0000 0000 0000 ("0B\x04\x15\x80\x00O\xB8\x05947fc54f1903\x00\al\x80\x02\x01\x02\x02\x03\x00\xFC\xAD\x04\tsimulator\x04\f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\b\x00\x00\x00\x00\x00\x00\x00\x00")
        encrypted_pdu: 0440 bdc6 73e0 9921 eb4f c79e 620a c9ef aa84 1888 13ff 60c7 0fc3 7bdd 03d7 78ff 264f ad61 8955 a854 8dfe e009 e116 f0b8 3201 d478 20d5 8ef0 b265 2d28 16a4 9a39 773b ("\xBD\xC6s\xE0\x99!\xEBO\xC7\x9Eb\n\xC9\xEF\xAA\x84\x18\x88\x13\xFF`\xC7\x0F\xC3{\xDD\x03\xD7x\xFF&O\xADa\x89U\xA8T\x8D\xFE\xE0\t\xE1\x16\xF0\xB82\x01\xD4x \xD5\x8E\xF0\xB2e-(\x16\xA4\x9A9w;")

3081 9e02 0103 3011 0204 6765 ee0e 0203
00ff e304 0107 0201 0304 4430 4204 1580
004f b805 3934 3766 6335 3466 3139 3033
0007 6c80 0201 0202 0300 fcad 0409 7369
6d75 6c61 746f 7204 0c00 0000 0000 0000
0000 0000 0004 0800 0000 0000 0000 0004
40bd c673 e099 21eb 4fc7 9e62 0ac9 efaa
8418 8813 ff60 c70f c37b dd03 d778 ff26
4fad 6189 55a8 548d fee0 09e1 16f0 b832
01d4 7820 d58e f0b2 652d 2816 a49a 3977

signing V3 message...

auth: 040c b169 8d9b e16d a96e 454c 9684 ("\xB1i\x8D\x9B\xE1m\xA9nEL\x96\x84")

3081 9e02 0103 3011 0204 6765 ee0e 0203
00ff e304 0107 0201 0304 4430 4204 1580
004f b805 3934 3766 6335 3466 3139 3033
0007 6c80 0201 0202 0300 fcad 0409 7369
6d75 6c61 746f 7204 0cb1 698d 9be1 6da9
6e45 4c96 8404 0800 0000 0000 0000 0004
40bd c673 e099 21eb 4fc7 9e62 0ac9 efaa
8418 8813 ff60 c70f c37b dd03 d778 ff26
4fad 6189 55a8 548d fee0 09e1 16f0 b832
01d4 7820 d58e f0b2 652d 2816 a49a 3977

received encoded V3 message

3081 9e02 0103 3011 0204 6765 ee0e 0203
00ff e304 0103 0201 0304 4430 4204 1580
004f b805 3934 3766 6335 3466 3139 3033
0007 6c80 0201 0202 0300 fcad 0409 7369
6d75 6c61 746f 7204 0c89 b4cf 0fde b440
890d 4a84 fc04 08bf d426 4ae8 c32e df04
40e9 ec53 708e dad9 62c2 8a2f be5b 9bb2
6863 4643 78cc cc98 3870 dc50 0cd7 739a
d0cc e617 0946 4bd2 6b27 c08c 280a 7b03
93ff d679 d0b1 c1dc 812c c64c 9281 51fd

v3_message: 3081
        message_version: 0201 ("3")
        headers: 3011
                Integer: 0204 6765 ee0e ("1734733326")
                Integer: 0203 00ff ("65507")
                message_flags: 0401 ("\x03")
                Integer: 0201 ("3")
        security_params: 0444 3042 0415 8000 4fb8 0539 3437 6663 3534 6631 3930 3300 076c 8002 0102 0203 00fc ad04 0973 696d 756c 6174 6f72 040c 89b4 cf0f deb4 4089 0d4a 84fc 0408 bfd4 264a e8c3 2edf ("0B\x04\x15\x80\x00O\xB8\x05947fc54f1903\x00\al\x80\x02\x01\x02\x02\x03\x00\xFC\xAD\x04\tsimulator\x04\f\x89\xB4\xCF\x0F\xDE\xB4@\x89\rJ\x84\xFC\x04\b\xBF\xD4&J\xE8\xC3.\xDF")
        pdu: 0440 e9ec 5370 8eda d962 c28a 2fbe 5b9b b268 6346 4378 cccc 9838 70dc 500c d773 9ad0 cce6 1709 464b d26b 27c0 8c28 0a7b 0393 ffd6 79d0 b1c1 dc81 2cc6 4c92 8151 fd72 ("\xE9\xECSp\x8E\xDA\xD9b\xC2\x8A/\xBE[\x9B\xB2hcFCx\xCC\xCC\x988p\xDCP\f\xD7s\x9A\xD0\xCC\xE6\x17\tFK\xD2k'\xC0\x8C(\n{\x03\x93\xFF\xD6y\xD0\xB1\xC1\xDC\x81,\xC6L\x92\x81Q\xFDr")

security_params: 3042
        engine_id: 0415 8000 4fb8 0539 3437 6663 3534 6631 3930 3300 076c ("\x80\x00O\xB8\x05947fc54f1903\x00\al\x80")
        engine_boots: 0201 ("2")
        engine_time: 0203 00fc ("64685")
        username: 0409 7369 6d75 6c61 746f ("simulator")
        auth_param: 040c 89b4 cf0f deb4 4089 0d4a 84fc ("\x89\xB4\xCF\x0F\xDE\xB4@\x89\rJ\x84\xFC")
        priv_param: 0408 bfd4 264a e8c3 2edf ("\xBF\xD4&J\xE8\xC3.\xDF")

received response PDU

pdu: 3023
        engine_id: 0400 ("")
        context: 0400 ("")
        request: a21d
                request_id: 0204 357c d1ca ("897372618")
                error: 0201 ("0")
                error_index: 0201 ("0")
                varbinds: 300f
                        Sequence: 300d
                                ObjectId: 0608 2b06 0104 0504 0203 ("1.3.6.1.4.5.4.2.3")
                                Integer: 0201 ("0")
 => 0 

@HoneyryderChuck
Copy link
Collaborator

Ok, so if I interpret this correctly, you send the "1.3.6.1.4.5.4.2.3" OID, and expect smth else than 0 (0 here probably meaning, "nothing is defined").

I believe this is a corner case which will be difficult to resolve due to the relative limited capabilities of netsnmp's MIB parser, which is currently only used to provide a translation from "mib to OID", but not to infer semantics about the particular object to be received, which is what most robust MIB parsers do.

So I assume that, if you inspect the mib file for "iso.3.6.1.4.5.4.2.3", you'll see the object definition stating that the response should return an IPAddress (feel free to paste it here for documentation purposes). So net-snmp does the right thing by analysing the Object MIB, expecting an IPAddress, seeing 0 and returning an error, whereas netsnmp doesn't do this, and just returns the value (0).

I think you can workaround it by testing the returned value type, if you know it must be an IP Address:

val = test.get(oid: '1.3.6.1.4.5.4.2.3')
raise "no ip" unless val.is_a?(IPAddr)

I could provide this check as a "feature", i.e.:

val = test.get(oid: '1.3.6.1.4.5.4.2.3', value_type: :ipaddress) # would raise exception unless ipaddress ASN type would be returned

But doesn't look very valuable, considering that the workaround is quite short to write.

The real improvement would be to put in the time to improve the MIB parser in order to collect Object types information that could be used for validation purposes, unfortunately I don't have the time to work on it (writing the existing MIB parser was already quite involved as is).

@jinxka
Copy link
Contributor Author

jinxka commented Mar 29, 2022

Hello,

I did some research and the usual error IPAddr::AddressFamilyError we get when retrieving a non-existent oid comes from:

def convert_application_asn(asn)

I tested the gem with a "valid" device (which raises an error when retrieving a non-existent oid) and the convert_application_asn receives:
#<OpenSSL::ASN1::ASN1Data:0x000055bb9e6c8f40 @tag=0, @value="", @tag_class=:CONTEXT_SPECIFIC, @indefinite_length=false>
When tag=0 the gem tries to do IPAddr.new_ntoh(asn.value) with asn.value="" which is not a valid IpAddress, so an error is raised.

With the "faulty" device, the method receives:
#<OpenSSL::ASN1::ASN1Data:0x000055bb9e493dd8 @tag=1, @value="", @tag_class=:CONTEXT_SPECIFIC, @indefinite_length=false>.
But with tag=1, the method does unpack_32bit_integer(asn.value) instead of IPAddr.new_ntoh(asn.value) which obviously doesn't raise an error and returns 0.

I don't think the method convert_application_asn should handle ASN with an empty value.

I propose to add a validation in the method to check the value and raise an error like No Such Object available on this agent at this OID if it's empty.

@HoneyryderChuck What do you think?

@HoneyryderChuck
Copy link
Collaborator

ok, I see now. They're both faulty, i.e. the first one should have also raised the same error instead of "error parsing IPAddress".

For documentation sake, netsnmp only does what the rfc mandates, i.e. for application-specific OID data:

-- (this is a tagged type for historical reasons)
IpAddress ::=
    [APPLICATION 0]
        IMPLICIT OCTET STRING (SIZE (4))

-- this wraps
Counter32 ::=
    [APPLICATION 1]
        IMPLICIT INTEGER (0..4294967295)

-- this doesn't wrap
Gauge32 ::=
    [APPLICATION 2]
        IMPLICIT INTEGER (0..4294967295)

-- an unsigned 32-bit quantity
-- indistinguishable from Gauge32
Unsigned32 ::=
    [APPLICATION 2]
        IMPLICIT INTEGER (0..4294967295)

-- hundredths of seconds since an epoch
TimeTicks ::=
    [APPLICATION 3]
        IMPLICIT INTEGER (0..4294967295)

-- for backward-compatibility only
Opaque ::=
    [APPLICATION 4]
        IMPLICIT OCTET STRING

-- for counters that wrap in less than one hour with only 32 bits
Counter64 ::=
    [APPLICATION 6]
        IMPLICIT INTEGER (0..18446744073709551615)

so 0 means ipaddress, 1 means counter32. However, since both come "empty", both are wrong, and the error you mention should then be raised if there's nothing to unpack.

Could you then submit a patch for it? I think it's fine.

@HoneyryderChuck
Copy link
Collaborator

HoneyryderChuck commented Apr 4, 2022

released v0.6.3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants