Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need handler string encoder error #89

Open
dark-lbp opened this issue Aug 13, 2019 · 1 comment
Open

Need handler string encoder error #89

dark-lbp opened this issue Aug 13, 2019 · 1 comment

Comments

@dark-lbp
Copy link
Contributor

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())
@dfiloni
Copy link

dfiloni commented Apr 21, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants