我正在尝试使用此库:http://pastebin.com/xgPXpGtw(使用示例:http://pastebin.com/fNFAW3Fh
我有一些问题,因为我不想像他一样将数组中的所有字节拆分。

我的测试脚本如下所示:

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)


并实际上返回:

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


那么我应该怎么做才能在测试参数上使用该功能呢?

谢谢 !

最佳答案

代替pack = packet[:],使用pack = list(packet),然后最后使用return ''.join(pack)

您不能替换字符串的单个字节,但可以将其转换为字符列表,替换一项,然后再转换回。

关于python - 使用模糊库(Python),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3485989/

10-12 21:17