Sunday, August 4, 2013

A simple SNMP scanner in ruby

 #!/usr/bin/env ruby  
 require 'snmp'  
 unless ARGV[0]  
     puts "Please supply a file containing the target hosts"   
     exit  
 end  
 hosts = IO.readlines(ARGV[0])  
 comm_strings = ["public","private","0","0392a0","1234","2read","4changes","ANYCOM","Admin","C0de","CISCO","CR52401","IBM","ILMI","Intermec","NoGaH$@!","OrigEquipMfr","PRIVATE","PUBLIC","Private","Public","SECRET","SECURITY","SNMP","SNMP_trap","SUN","SWITCH","SYSTEM","Secret","Security","Switch","System","TENmanUFactOryPOWER","TEST","access","adm","admin","agent","agent_steal","all","all private","all public","apc","bintec","blue","c","cable-d","canon_admin","cc","cisco","community","core","debug","default","dilbert","enable","field","field-service","freekevin","fubar","guest","hello","hp_admin","ibm","ilmi","intermec","internal","l2","l3","manager","mngt","monitor","netman","network","none","openview","pass","password","pr1v4t3","proxy","publ1c","read","read-only","read-write","readwrite","red","regional","rmon","rmon_admin","ro","root","router","rw","rwa","san-fran","sanfran","scotty","secret","security","seri","snmp","snmpd","snmptrap","solaris","sun","superuser","switch","system","tech","test","test2","tiv0li","tivoli","trap","world","write","xyzzy","yellow"]  
 mib = ""  
 hosts.each do |host|  
  mib = ""  
  comm_strings.each do |comm|  
    break if mib != ""  
    SNMP::Manager.open(:Host => "#{host}", :community => "#{comm}", :retries => 0, :timeout => 1) do |manager|  
     begin  
      mib = manager.get_value("sysDescr.0")  
      puts "Detected community string: '#{comm}' with host: #{host}"  
     rescue Exception => msg  
      #puts msg  
     end  
    end  
  end  
 end  

No comments: