Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2009
1,763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.75 KB | None | 0 0
  1. #!/usr/bin/python
  2. import random, sys,logging,os
  3. from random import *
  4. from scapy.all import *
  5. logging.getLogger("scapy").setLevel(1)
  6.  
  7. ##fuzzer core##
  8. def onerand(packet):
  9.     pack  = packet[:]
  10.     byte = str(chr(choice(range(256))))
  11.     pack[choice(range(len(packet)))]= byte
  12.     print "fuzzing rand byte:%s\n" % (byte.encode("hex"))
  13.     return pack
  14.  
  15. def doublerand(packet):
  16.     pack  = packet[:]
  17.     byte = str(chr(choice(range(256))))
  18.     byte2 = str(chr(choice(range(256))))
  19.     pack[choice(range(len(packet)))]= byte
  20.     pack[choice(range(len(packet)))]= byte2
  21.     print "fuzzing rand byte:%s byte2:%s\n" % (byte.encode("hex"),byte2.encode("hex"))
  22.     return pack
  23.  
  24. def longrand(packet):
  25.     pack  = packet[:]
  26.     byte = str(chr(choice(range(256))))
  27.     lon = randrange(0,600)
  28.     pack[choice(range(len(packet)))]= byte*lon
  29.     print "fuzzing rand byte:%s len:%s\n" % (byte.encode("hex"),lon)
  30.     return pack
  31.  
  32. def longerrand(packet):
  33.     pack  = packet[:]
  34.     byte = str(chr(choice(range(256))))
  35.     lon = randrange(0,600)
  36.     pack[choice(range(len(packet)))]= byte
  37.     pack[choice(range(len(packet)))]= byte*lon
  38.     print "fuzzing rand byte:%s len:%s\n" % (byte.encode("hex"),lon)
  39.     return pack
  40.  
  41. def longerrandnull(packet):
  42.     pack  = packet[:]
  43.     byte = str(chr(choice(range(256))))
  44.     lon = randrange(0,600)
  45.     pack[choice(range(len(packet)))]= byte
  46.     pack[choice(range(len(packet)))]= byte+"\x00"*lon
  47.     print "fuzzing rand byte:%s len:%s\n" % (byte.encode("hex"),lon)
  48.     return pack
  49.  
  50. def opnum(packet):
  51.     pack  = packet[:]
  52.     byte = str(chr(choice(range(0,2))))
  53.     pack[choice(range(len(packet)))]= byte
  54.     print "fuzzing opnum:%s\n" % (byte.encode("hex"))
  55.     return pack
  56.  
  57. def doubleopnum(packet):
  58.     pack  = packet[:]
  59.     byte = str(chr(choice(range(0,2))))
  60.     byte2 = str(chr(choice(range(0,2))))
  61.     pack[choice(range(len(packet)))]= byte
  62.     pack[choice(range(len(packet)))]= byte2
  63.     print "fuzzing opnum:%s et opnum no-2:%s\n" % (byte.encode("hex"),byte2.encode("hex"))
  64.     return pack
  65.  
  66. def remove1(packet):
  67.     pack  = packet[:]
  68.     i = randrange(0, len(pack)-1)
  69.     b = pack[:i] + pack[i+1:]
  70.     print "remove one char fuzz, removed :%s"%(pack[i].encode("hex"))
  71.     return b
  72.  
  73. def changenull(packet):
  74.     pack = packet[:]
  75.     null = [i for i in range(len(pack)) if pack[i] == '\x00']
  76.     byte = str(chr(choice(range(256))))
  77.     pack[choice(null)] = byte
  78.     print "replaced one null by a %s"%(byte.encode("hex"))
  79.     return pack
  80.  
  81.  
  82. def removenull(packet):
  83.     pack = packet[:]
  84.     null = [i for i in range(len(pack)) if pack[i] == '\x00']
  85.     num = choice(null)
  86.     del pack[choice(null)]
  87.     print "deleted null no-:%s"%(num)
  88.     return pack
  89.  
  90. def randfunc(packet):
  91.     func = choice([onerand,doublerand,longrand,longerrand,longerrandnull,removenull,changenull,remove1,doubleopnum,opnum])
  92.     print "using %s fuzzing type (HARD)"%(func.__name__)
  93.     return func(packet)
  94.  
  95. def zenfunc(packet):
  96.     func = choice([onerand,removenull,changenull,remove1,doubleopnum,opnum])
  97.     print "using %s fuzzing type (ZEN)"%(func.__name__)
  98.     return func(packet)
  99.  
  100. ##End fuzzer core##
  101.  
  102. ip = [chr(int(a, 16)) for a in """
  103. 4e fe 01 08 00 00 40 00 fa 01 00 00 c0 a8 02 64
  104. c0 a8 02 65 44 24 0d 01 c0 a8 02 64 04 80 30 77
  105. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  106. 00 00 00 00 00 00 00 00""".split()]
  107.  
  108. icmp = [chr(int(a, 16)) for a in """
  109. 08 00 00 00 00 00 00 04 75 54 08 4b 00 00 00 00
  110. 04 6b 0d 00 00 00 00 00 20 20 20 20 20 20 20 20
  111. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  112. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  113. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  114. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  115. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  116. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  117. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  118. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  119. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  120. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  121. 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  122. """.split()]
  123.  
  124. def longueur(payload):
  125.    length = struct.pack(">i", len(''.join(payload)))
  126.    a= length[2:4]
  127.    pack = payload[:]
  128.    pack[2:4]= a
  129.    return pack
  130.  
  131. def OpIP(packet):
  132.     pack = packet[:]
  133.     num = str(chr(choice(range(1,9))))
  134.     num1 = str(chr(choice(range(0,150))))
  135.     #pack[0] = num
  136.     #pack[9] = num1
  137.     print "fuzzing version OPNUM no-:%s and nh OPNUM no-:%s"%(num.encode("hex"),num1.encode("hex"))
  138.     return pack  
  139.  
  140. def OpIcmp(packet):
  141.     pack = packet[:]
  142.     num = str(chr(choice(range(0,42))))
  143.     pack[0] = num
  144.     print "fuzzing ICMP OPNUM no-:%s"%(num.encode("hex"))
  145.     return pack
  146.  
  147. ##checksum calculation and replacement##
  148. ##checksum() ripped from scapy, hard to do better...
  149. def checksum(pkt):
  150.     pkt=str(pkt)
  151.     s=0
  152.     if len(pkt) % 2 == 1:
  153.         pkt += "\0"
  154.     for i in range(len(pkt)/2):
  155.         s = s +  (struct.unpack("!H",pkt[2*i:2*i+2])[0])
  156.     s = (s >> 16) + (s & 0xffff)
  157.     s += s >> 16
  158.     return  ~s & 0xffff
  159. ##/checksum() ripped from scapy, hard to do better...
  160.  
  161. def add_checksum(packet):
  162.     a = struct.pack(">i",checksum(''.join(packet)))
  163.     b =  a[2:4]
  164.     pack = packet[:]
  165.     pack[2:4]=b
  166.     return pack
  167.  
  168. def add_ip_checksum(packet):
  169.     a = struct.pack(">i",checksum(''.join(packet)))
  170.     b =  a[2:4]
  171.     pack = packet[:]
  172.     pack[10:12]=b
  173.     return pack
  174.  
  175. ##checksum calculation and replacement##
  176.  
  177. ### snort is an example of hookin' a prog in your fuzzin'
  178.  
  179. pid = os.system("pidof snort")
  180. while os.system("pidof snort") == pid:
  181.  
  182.     a = longueur(zenfunc(ip)+add_checksum(randfunc(icmp)))
  183.     b = ''.join(add_ip_checksum(a))
  184.     packet = (Ether(dst="ff:ff:ff:ff:ff:ff",type=0x0800)/b)
  185.     print "packet IP:%s\n"%(b.encode("hex"))
  186.     sendp(packet)
  187.  
  188.     ##enjoy !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement