From f2f8341e2c12c10e2daf3abb9fb84e4ba76d666e Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Fri, 19 Apr 2024 20:11:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- match/test_dangerous_functions.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 match/test_dangerous_functions.py diff --git a/match/test_dangerous_functions.py b/match/test_dangerous_functions.py new file mode 100644 index 0000000..aa36836 --- /dev/null +++ b/match/test_dangerous_functions.py @@ -0,0 +1,28 @@ +""" +危险函数测试 +""" + +import os + +# 潜在的危险函数调用示例 +os.system("ls") +eval("2 + 2") +exec("print('Executing dangerous exec function')") +popen_result = os.popen('echo "Hello World"').read() +print(popen_result) + +# 一些正常操作 +print("This is a safe print statement.") +result = sum([1, 2, 3]) +print("Sum result:", result) + +# 尝试使用 subprocess 以更安全的方式调用外部命令 +import subprocess + +subprocess.run(["echo", "Subprocess run is safer than os.system"]) + +# 错误的函数调用尝试 +try: + os.system("rm -rf /") # 非常危险的调用,应避免在实际环境中使用 +except: + print("Failed to execute dangerous system call.")