gpt4 book ai didi

python - 如何在 Python 中清理 url 字符串?

转载 作者:行者123 更新时间:2023-12-01 01:03:13 26 4
gpt4 key购买 nike

我有一个 python 应用程序,可以使用 URL 列表并生成 bash 脚本作为输出。

如何清理 URL,以便恶意用户无法注入(inject)将在我的基础设施上执行的 bash 命令。

例如:

http://www.circl.lu/a.php?rm -Rf /etc

最佳答案

我猜 urllib 是解析 url 的选项,以转义有害字符。至少对于您的用例来说,它看起来是一个很好的资源。请参阅 url-quoting 的文档.

from urllib.parse import quote

quote('touch foo', safe='/')
quote('rm -Rf /etc', safe='/')
quote('http://www.circl.lu/a.php?rm -Rf /etc', safe='/:?&')

#'touch%20foo'
#'rm%20-Rf%20/etc'
#'http://www.circl.lu/a.php?rm%20-Rf%20/etc'

关于python - 如何在 Python 中清理 url 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55613607/

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