gpt4 book ai didi

python - PyYAML 给出构造函数错误?

转载 作者:行者123 更新时间:2023-12-01 01:47:53 28 4
gpt4 key购买 nike

所以我目前正在尝试模拟不安全反序列化攻击。这是我正在使用的代码:

import yaml

with open('malicious.yml') as yaml_file:
contents = yaml.load(yaml_file)
print(contents['foo'])

文件恶意.yml 包含以下内容:

foo: !!python/object/apply:subprocess.check_output ['ls']

但是,当我运行脚本时,出现以下错误:

yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/object/apply:subprocess.check_output'
in "malicious.yml", line 1, column 6

我环顾四周,但还是找不到原因。任何帮助将不胜感激。

最佳答案

如果您尝试模拟不安全的反序列化攻击,则应该使用

contents = yaml.danger_load(yaml_file)

或使用旧版本的 PyYAML ( pip install pyyaml<4 )。 API 在 4.1 版本中进行了更改,没有任何文档更改。

关于python - PyYAML 给出构造函数错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51062807/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com