Skip to content

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 33: character maps to <undefined> #409

@abdulx01

Description

@abdulx01

This issue I am getting when I run xsstrike with payload to scan url

PS D:\Tools\XSStrike-master> python .\xsstrike.py -u "https://example.com/?s=FUZZ" -f xss-payload.txt

        XSStrike v3.1.5

Traceback (most recent call last):
  File "D:\Tools\XSStrike-master\xsstrike.py", line 149, in <module>
    payloadList = list(filter(None, reader(args_file)))
                                    ^^^^^^^^^^^^^^^^^
  File "D:\Tools\XSStrike-master\core\utils.py", line 205, in reader
    result = [line.rstrip(
             ^^^^^^^^^^^^^
  File "D:\Tools\XSStrike-master\core\utils.py", line 205, in <listcomp>
    result = [line.rstrip(
             ^^^^^^^^^^^^^
  File "C:\Python311\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 33: character maps to <undefined>

Code from utils.py

def reader(path):
    with open(path, 'r') as f:
        result = [line.rstrip('\n').encode('utf-8').decode('utf-8') for line in f]
    return result

The issue lies in the encoding used when reading the file. Since you're encountering a UnicodeDecodeError, it should explicitly set the encoding when opening the file.

FIX

def reader(path):
    with open(path, 'r', encoding='utf-8') as f:
        result = [line.rstrip('\n').encode('utf-8').decode('utf-8') for line in f]
    return result

image

Thanks : )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions