Advertisement
opexxx

snmpsize.py

Feb 16th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #
  4. # A rudimentary snmpwalk-like with scapy. Useful to choose a good
  5. # OID to use during a SNMP reflected amplification DDos attack
  6. #
  7. # Usage: ./snmpsize.py 1.2.3.4 public 1.3.6.1.2.1 v1
  8. #
  9. # http://www.nothink.org
  10. #
  11.  
  12. import signal,sys
  13.  
  14. # Change log level to suppress annoying IPv6 error
  15. import logging
  16. logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
  17.  
  18. # Import scapy
  19. try:
  20.     from scapy.all import *
  21. except:
  22.     print "install scapy"
  23.     print "http://www.secdev.org/projects/scapy/"
  24.  
  25. # Turn down the verbosity of scapy
  26. conf.verb = 0
  27.  
  28. def signal_handler(signum,frame):
  29.     global interrupted
  30.     interrupted = True
  31.  
  32. def sendRequest(target,community,oid_prefix,version):
  33.  
  34.     nextoid = oid_prefix
  35.  
  36.     # best choices!
  37.     best_oid = ''
  38.     best_size = 0
  39.  
  40.     while True:
  41.    
  42.         p = IP(dst=target)/UDP(sport=161,dport=161)/SNMP(version=version,community=community,PDU=SNMPnext(varbindlist=[SNMPvarbind(oid=ASN1_OID(nextoid))]))
  43.        
  44.         #p.show()
  45.         r = sr1(p)
  46.    
  47.         if r:
  48.             # size
  49.             rle = r.len
  50.  
  51.             # next oid
  52.             oid = r[SNMPvarbind].oid.val
  53.  
  54.             if oid.startswith(oid_prefix):
  55.                 print oid + "\t" + str(rle) + " bytes"
  56.  
  57.                 if int(rle) > best_size:
  58.                     best_size = int(rle)
  59.                     best_oid = oid
  60.  
  61.             else:
  62.                 print "\n\nbest choices: %s %s bytes\n" % (best_oid,str(best_size))
  63.                 break
  64.            
  65.             nextoid = oid
  66.  
  67. if __name__ == "__main__":
  68.  
  69.     if len(sys.argv) <= 4:
  70.         print "Usage %s 1.2.3.4 public 1.3.6.1.2.1 v1" % sys.argv[0]
  71.         sys.exit(1)
  72.  
  73.     try:
  74.         sendRequest(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])
  75.  
  76.     except KeyboardInterrupt:
  77.         print "Exit..."
  78. Facebook Social Plugins
  79. Google Analytics
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement