ticarpi / jwt_tool

:snake: A toolkit for testing, tweaking and cracking JSON Web Tokens
GNU General Public License v3.0
5.46k stars 670 forks source link

Codecmap issues because no encoding type specified in the lines [269, 1495] #62

Open AhmedAhmedEG opened 2 years ago

AhmedAhmedEG commented 2 years ago

This issue happened for me on Windows 10. JWT_Tool 2.2.5

The following error happened:-

Traceback (most recent call last):
  File "C:\Users\PC\Desktop\jwt_tool-2.2.5\jwt_tool-2.2.5\jwt_tool.py", line 2104, in <module>
    runScanning()
  File "C:\Users\PC\Desktop\jwt_tool-2.2.5\jwt_tool-2.2.5\jwt_tool.py", line 1697, in runScanning
    scanModePlaybook()
  File "C:\Users\PC\Desktop\jwt_tool-2.2.5\jwt_tool-2.2.5\jwt_tool.py", line 1496, in scanModePlaybook
    commonPass = commonPassList.readline().rstrip()
  File "C:\Users\PC\AppData\Local\Programs\Python\Python39\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 0x8f in position 1734: character maps to <undefined>

I fixed it by adding the argument "encoding='utf-8'" to the open() function in line 1495.

After that the following error happened:-

Traceback (most recent call last):
  File "C:\Users\PC\Desktop\jwt_tool-2.2.5\jwt_tool-2.2.5\jwt_tool.py", line 2104, in <module>
    runScanning()
  File "C:\Users\PC\Desktop\jwt_tool-2.2.5\jwt_tool-2.2.5\jwt_tool.py", line 1697, in runScanning
    scanModePlaybook()
  File "C:\Users\PC\Desktop\jwt_tool-2.2.5\jwt_tool-2.2.5\jwt_tool.py", line 1499, in scanModePlaybook
    jwtOut(newContents+"."+newSig, "Checking for alternative accepted HMAC signatures, based on common passwords. Testing: "+commonPass+"", "This token can exploit a hard-coded common password in the config")
  File "C:\Users\PC\Desktop\jwt_tool-2.2.5\jwt_tool-2.2.5\jwt_tool.py", line 261, in jwtOut
    setLog(token, genTime, logID, fromMod, curTargetUrl, additional)
  File "C:\Users\PC\Desktop\jwt_tool-2.2.5\jwt_tool-2.2.5\jwt_tool.py", line 270, in setLog
    logFile.write(logID+" - "+logLine+" - "+jwt+"\n")
  File "C:\Users\PC\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 152-182: character maps to <undefined>

I fixed it by adding the argument "encoding='utf-8'" to the open() function in line 269.

After that the script worked totally fine, the "encoding" argument should always be specified in any call for the "open()" function to prevent any confusion for characters that is not included in ASCII charset, other argument can be added to to ignore any characters that don't exist even in the utf-8 charset, the "ignore" parameter.