处理烧瓶会话cookie的简单python脚本

flask-session-cookie-manager的Python项目详细描述


烧瓶会话cookie解码器/编码器

原作者:Wilson Sumanang

修复和改进作者:Alexandre ZANNI

saruberoz.github.io导入

依赖性

安装

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="}}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
spring boot在使用Java 9的SprnigBoot中找不到org/slf4j/LoggerFactory   java如何查找对象中非空属性的数量   javascript AngularJS和REST:执行删除操作,发送要删除的许多项的数组   java WAS7和Axis获得ClassCastException:IBM Crypto的TDCNP与javax不兼容。加密。密码   当从多个线程以相反顺序执行equals()时,Java的同步集合出现问题   依赖java的spring启动应用程序启动,而不是主模块sbt   java@Async阻止一个线程继续,直到其他线程完成   java按钮故障   java thymeleaf,将模型属性绑定到多个表单元素   使用泛型的java查询   java Hibernate JPA侦听器未收到调用   java如何让我的监听器工作,并用物品位置显示吐司?   java未能延迟初始化角色集合:无法初始化代理无会话   java JBPM持久性示例恢复工作流   JavaSpring以json的形式获取对对象转换的响应   java如何使用Proguard成功地用Dagger 2.0混淆项目?   Android中的java字符串拆分错误   如何使用DockerJavaLibrary启动docker容器?   C++在java中是否有条件编译?