ytti / netcrawl

LLDP/CDP crawler
60 stars 12 forks source link

crash on ipv6 adresses #5

Open olanystrom opened 4 years ago

olanystrom commented 4 years ago

I dont know if the error is in netcrawl or ruby-snmp. But if you get a CDP Neigbour with ipv6 adress you get an error.

# netcrawl -d -a 10.123.3.1
Expected four octets separated by dots, not "\xFE\x80\x00\x00\x00\x00\x00\x00\x06\xEB@\xFF\xFE\xD9\xDC\x05"
/usr/local/share/gems/gems/snmp-1.3.2/lib/snmp/varbind.rb:345:in `parse_string': Expected four octets separated by dots, not "\xFE\x80\x00\x00\x00\x00\x00\x00\x06\xEB@\xFF\xFE\xD9\xDC\x05" (SNMP::InvalidIpAddress)
        from /usr/local/share/gems/gems/snmp-1.3.2/lib/snmp/varbind.rb:291:in `initialize'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl/snmp.rb:132:in `new'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl/snmp.rb:132:in `as_ip'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl/method/cdp.rb:21:in `block in make_peers'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl/method/cdp.rb:17:in `each'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl/method/cdp.rb:17:in `make_peers'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl/method/xdp.rb:15:in `poll'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl/method/xdp.rb:10:in `peers'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl.rb:19:in `block in get'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl.rb:18:in `each'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl.rb:18:in `get'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl.rb:28:in `recurse'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl.rb:10:in `crawl'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/lib/netcrawl/cli.rb:10:in `run'
        from /usr/local/share/gems/gems/netcrawl-0.1.0/bin/netcrawl:5:in `<top (required)>'
        from /usr/local/bin/netcrawl:23:in `load'
        from /usr/local/bin/netcrawl:23:in `<main>'

The SNMP output from snmpwalk of the relevant part is

SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10101.2 = Hex-STRING: 0A 7B 03 02
SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10102.3 = Hex-STRING: AC 1A 19 22
SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10110.1 = Hex-STRING: FE 80 00 00 00 00 00 00 06 EB 40 FF FE D9 DC 05
SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10117.4 = Hex-STRING: 0A 7B 03 06
SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10121.5 = Hex-STRING: 0A 7B 03 04
ytti commented 4 years ago

https://github.com/ytti/netcrawl/blob/master/lib/netcrawl/snmp.rb#L131-L133

This would have to detect if value is v4 or v6 and return correct object. Detection could be simple as value.size