3

所以我们知道,如果您正在编写 bash 脚本,则必须注意文件名中的特殊字符,例如空格、引号和换行符。我记得在某处读到显示/回显/打印某些文件名的事件在 bash 中可能很危险。这是真的?

如果文件名被显示/打印/回显等,是否有任何字符可以放入文件名中,这将是安全问题?

假设我在 linux 系统上运行 bash。

这实际上不是我现在遇到的问题,也不是我需要解决的问题,这更多是为了好奇,看看这是不是真的

4

3 回答 3

1

在配置错误的终端和语言环境中,UTF-8 也可能很危险。几年来,我使用的设置打印 UTF-8 文本会导致在我输入的下一个命令前添加几个字符。

$ cat file.txt
šómé ǧářbáǧě
$ 1;21

键入后ls,结果是

$ 1;21ls
1: command not found
21ls: command not found
于 2012-11-29T11:39:26.870 回答
1

When echoing the worst thing that can happen to you is break of '' and then with the help of ; you can have arbitrary program execution vulnerability. This is the list of bash special chars:

" $ & ' () * ; < > ? [ \ ] ` { | } ~ space tab cr lf

Those could present a potential threat depending of their usage context.

于 2012-11-29T11:07:22.427 回答
0

考虑到文件调用,除了字符之外,命令名称也可能是一个问题rm

$ ls               # List files 
rm  somefile  

$ `ls`             # Why aren't my file listed?

$ ls               # Opps where did somefile go?
rm 

backticks使用或时,请注意您在脚本中的实际操作eval

前导连字符:

$ ls
-dumbfile

$ rm -dumbfile
rm: invalid option -- 'd'

$ rm -- -dumbfile   # use -- to delete files containing leading -
于 2012-11-29T11:12:28.550 回答