处理烧瓶会话cookie的简单python脚本
flask-session-cookie-manager的Python项目详细描述
烧瓶会话cookie解码器/编码器
原作者:Wilson Sumanang
修复和改进作者:Alexandre ZANNI
依赖性
- python 2或python 3
- itsdangerous
- Flask
安装
archlinux
Python3
# pacman -S python
# pacman -S python-itsdangerous python-flask --asdep
Python2
# pacman -S python2
# pacman -S python2-itsdangerous python2-flask --asdep
其他发行版
使用包管理器找到方法,在虚拟环境中使用pip或使用pyenv。
用法
对python 3使用flask_session_cookie_manager3.py
,对python 2使用flask_session_cookie_manager2.py
。
usage: flask_session_cookie_manager{2,3}.py [-h] {encode,decode} ...
Flask Session Cookie Decoder/Encoder
positional arguments:
{encode,decode} sub-command help
encode encode
decode decode
optional arguments:
-h, --help show this help message and exit
编码
usage: flask_session_cookie_manager{2,3}.py encode [-h] -s <string> -t <string>
optional arguments:
-h, --help show this help message and exit
-s <string>, --secret-key <string>
Secret key
-t <string>, --cookie-structure <string>
Session cookie structure
解码
usage: flask_session_cookie_manager.py decode [-h] [-s <string>] -c <string>
optional arguments:
-h, --help show this help message and exit
-s <string>, --secret-key <string>
Secret key
-c <string>, --cookie-value <string>
Session cookie value
示例
编码
$ python{2,3} flask_session_cookie_manager{2,3}.py encode -s '.{y]tR&sp&77RdO~u3@XAh#TalD@Oh~yOF_51H(QV};K|ghT^d' -t '{"number":"326410031505","username":"admin"}'
eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw
注意:会话cookie结构必须是有效的python字典
解码
带密钥:
$ python{2,3} flask_session_cookie_manager{2,3}.py decode -c 'eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw' -s '.{y]tR&sp&77RdO~u3@XAh#TalD@Oh~yOF_51H(QV};K|ghT^d'
{u'username': 'admin', u'number': '326410031505'}
没有密钥(不太漂亮的输出):
$ python{2,3} flask_session_cookie_manager{2,3}.py decode -c 'eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw'
{"number":{" b":"MzI2NDEwMDMxNTA1"},"username":{" b":"YWRtaW4="}}