pycookiecheat icon indicating copy to clipboard operation
pycookiecheat copied to clipboard

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 0: invalid continuation byte

Open brianjmurrell opened this issue 1 year ago • 5 comments

  • Operating system and version: Fedora 40

  • Python version: 3.12.6

  • pycookiecheat version: __version__ = "v0.7.0"

My Issue

$ pycookiecheat -v -v -v -v -v -v -u https://secure.example.com -b Chrome
{'key_material': '[redacted]', 'iterations': 1, 'cookie_file': PosixPath('~/.config/google-chrome/Default/Cookies')}
Traceback (most recent call last):
  File "/home/brian/.local/bin/pycookiecheat", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/brian/.local/lib/python3.12/site-packages/pycookiecheat/__main__.py", line 53, in main
    cookies = chrome_cookies(
              ^^^^^^^^^^^^^^^
  File "/home/brian/.local/lib/python3.12/site-packages/pycookiecheat/chrome.py", line 343, in chrome_cookies
    row["value"] = chrome_decrypt(
                   ^^^^^^^^^^^^^^^
  File "/home/brian/.local/lib/python3.12/site-packages/pycookiecheat/chrome.py", line 91, in chrome_decrypt
    return clean(decrypted)
           ^^^^^^^^^^^^^^^^
  File "/home/brian/.local/lib/python3.12/site-packages/pycookiecheat/chrome.py", line 53, in clean
    return decrypted[:-last].decode("utf8")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 0: invalid continuation byte

WHYT

I've looked through various issues describing the error message but not finding anything particularly relevant. I did print the value of config right before https://github.com/n8henrie/pycookiecheat/blob/42941d935ee8ee48b0e7fe9acbe1cce447497baa/src/pycookiecheat/chrome.py#L280

and can see that 'key_material' is the same as the key that seahorse shows me for Chrome Safe Storage.

I'm happy to sprinkle print()s wherever else is needed to gather whatever info is needed.


Please make sure you've taken these steps before submitting a new issue:

  • [x] Include the Python and pycookiecheat version in your issue
  • [x] Ensure you're running a supported version of Python
  • [x] Run pycookiecheat in debug mode if applicable and include relevant output
  • [x] Search the existing (including closed) issues
  • [x] Please use codeblocks for any code, config, program output, etc.

brianjmurrell avatar Sep 17 '24 20:09 brianjmurrell

Is there anything I can add to this report to make it more actionable?

brianjmurrell avatar Sep 23 '24 14:09 brianjmurrell

Sorry, just busy.

And unfortunately these errors are always hard to debug; as you'll likely see from the several other similar issues, it's usually an issue of the user's configuration, which makes it really hard for me to sort out on my end.

Errors like this on Linux are often due to missing dependencies to get secrets from the the desktop environment's keyring, although in your case I'm less confident (since you report that key_material seems to be correct).

What desktop environment are you using? Do you know what backend Chrome is using to store your secrets?

n8henrie avatar Sep 23 '24 18:09 n8henrie

I'm using Fedora 40 with GNOME 46. I'm not sure how to answer your question about which backend Chrome is using for secrets. I have not done anything in Chrome to make any kind of selection in that regard so whatever Chrome does by default on GNOME I would assume is my case. I'm happy to dig into that if there is something that tells me how to do that.

brianjmurrell avatar Sep 23 '24 18:09 brianjmurrell

I'm not sure how to answer your question about which backend Chrome is using for secrets.

Totally fair, but I'm also not sure how to answer it; I don't use Gnome. I think by default it uses something called gnome keyring.

I set up a test Gnome environment back in May: https://github.com/n8henrie/pycookiecheat/issues/64#issuecomment-2119359076 -- do you already have the dependencies from that comment installed?

n8henrie avatar Sep 23 '24 18:09 n8henrie

OK. So https://github.com/n8henrie/pycookiecheat/issues/64#issuecomment-2119359076 was helpful to get me to get this working in Chromium. Probably given that, I might be able to run with this and get somewhere.

I notice that python -m pycookiecheat --url dumps a JSON that is just cookie name/value pairs. I don't suppose there is an option to dump a requests session cookie JSON structure is there? I.e. :

[
                      {
                                        "domain": …,
                                        "hostOnly": true,
                                        "httpOnly": true,
                                        "name": "JSESSIONID",
                                        "path": "/",
                                        "sameSite": null,
                                        "secure": true,
                                        "session": true,
                                        "storeId": null,
                                        "value": …

etc.

brianjmurrell avatar Sep 23 '24 19:09 brianjmurrell

Sorry for delay in response.

I notice that python -m pycookiecheat --url dumps a JSON that is just cookie name/value pairs.

It just prints the dictionary

I don't suppose there is an option to dump a requests session cookie JSON structure is there? I.e. :

I'm not familiar with this format.

n8henrie avatar Oct 31 '24 11:10 n8henrie

Yeah, no worries. With #71 I'm afraid this project doesn't help in the situation I was in but moreover I'm not even in that situation anymore so not really in need of what this project achieves, as cool as it is.

Let me take a moment though to express my gratitude for your time and efforts here. Keep up the great work.

brianjmurrell avatar Oct 31 '24 12:10 brianjmurrell

Thanks for your kind words! The community is what makes open source so great.

If you think of it and are able, I'd love you have you report back with the stack that eventually works for your purpose -- I'm sure there are others with similar use cases!

n8henrie avatar Oct 31 '24 20:10 n8henrie

Haha. I voted with my wallet and closed the accounts at the website I needed to steal the session from and moved to a more open service with an API, so unfortunately I don't have anything that helps anyone in this regard.

brianjmurrell avatar Oct 31 '24 20:10 brianjmurrell

Good for you!

n8henrie avatar Nov 01 '24 09:11 n8henrie