【发布时间】:2018-08-08 09:28:54
【问题描述】:
这可行,但 shell 注入存在安全风险
p = subprocess.Popen(['mv ./*.pdf ./target.pdf'], shell=True)
这不起作用,因为 * 不会全局化
p = subprocess.Popen(['mv', './*.pdf', './target.pdf'])
我在看一个目录。如何在不影响安全性的情况下将到达的 pdf 重命名为 target.pdf?
【问题讨论】:
-
为什么不先在你的 python 脚本中使用
glob来查找文件名。 -
既然可以使用
shutil.move(),为什么还要使用subprocess -
@FlyingTeller 我正在使用看门狗将任何到达的 pdf 文件重命名为 target.pdf,该文件由 subprocess.Popen 传递给 tika-parser 那么我将如何首先 glob?
-
@nauer 我是初学者。谢谢你的提示。我将发布我的笨拙的解决方案,我确信可以做得更好......
-
@user1613312 在您发布的答案中使用 listdir 的方式相同。只需
sources = glob.glob('*.pdf')
标签: python shell subprocess code-injection