kitty
kitty copied to clipboard
Need handler string encoder error
Python Version 2.7.16
String encoder error will break fuzzing progress.
Running this script will raise UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 11: ordinal not in range(128)
from kitty.model import *
from kitty.interfaces import WebInterface
from kitty.fuzzers import ServerFuzzer
from kitty.model import GraphModel
from katnip.targets.file import FileTarget
t1 = Template(name='str_encoder_test', fields=[
String(name='bString', value='hello_kitty', encoder=StrEncodeEncoder('utf_16_le'), max_size=254 / 2)
]
)
target = FileTarget('FileTarget', './tmp', 'fuzzed', 'bin')
model = GraphModel()
model.connect(t1)
fuzzer = ServerFuzzer()
fuzzer.set_interface(WebInterface(port=26001))
fuzzer.set_model(model)
fuzzer.set_target(target)
fuzzer.set_range(1, 10)
fuzzer.start()
This problem can be reproduced with the code show below .
from kitty.model import *
test = String(name='bString', value='hello_kitty', encoder=StrEncodeEncoder('utf_16_le'), max_size=254 / 2)
test.mutate()
test.mutate()
test.mutate()
print(test.render())
To fix this issue I changed py2_str_encoder_func function in kitty/model/low_level/encoder.py as follows:
def py2_str_encoder_func(encoding):
if encoding not in _py2_str_encoder_funcs_cache:
_py2_str_encoder_funcs_cache[encoding] = lambda x: strToUtf8(x).encode(encoding)
return _py2_str_encoder_funcs_cache[encoding]
So x is encoded in utf8 first and then it's encoded with the requested encoding (the decoding is already performed by Python in the encode() function)
Honestly I'm not sure that's a valid solution, I've executed few/poorly tests and only with utf_16_le and utf_16_be encodings.