Search code examples
pythonstringfuzzing

Using fuzzing lib (python)


I'm trying to use this library : http://pastebin.com/xgPXpGtw (an example of use: http://pastebin.com/fNFAW3Fh) I have some issues since I dont want to split in an array all the byte as he does.

My test script looks like this:

import random
from random import *

def onerand(packet):
    pack  = packet[:]
    byte = str(chr(choice(range(256))))
    pack[choice(range(len(packet)))]= byte
    print "fuzzing rand byte:%s\n" % (byte.encode("hex"))
    return pack

test = "\x63\x63\x63\x63\x63\x63\x63\x63\x63\x63\x63\x63\x63\x63"

while True:
   print onerand(test)

And actually returns :

Traceback (most recent call last):
  File "test.py", line 14, in <module> 
    print onerand(test)
  File "test.py", line 7, in onerand
    pack[choice(range(len(packet)))]= byte
TypeError: 'str' object does not support item assignment

So what should i do to be able to use that function on the test parameters ?

Thanks !


Solution

  • instead of pack = packet[:], use pack = list(packet), and then return ''.join(pack) at the end.

    you can't replace a single byte of a string, but you can convert it to a list of characters, replace one item, and then convert back.