Shell scripts and security

前端 未结 4 752
攒了一身酷
攒了一身酷 2021-01-13 05:17

TLDP\'s Advanced Bash Scripting Guide states that shell scripts shouldn\'t be used for \"situations where security is important, where you need to guarantee the integrity of

4条回答
  •  生来不讨喜
    2021-01-13 05:31

    I would disagree with that statement, as there is nothing about scripts that make them inherently unsafe. Bash scripting are perfectly safe if some simple guidelines are followed:

    • Does the script contain info that others shouldn't be able to view? If so, make sure it's only readable by the owner.
    • Does the script depend on input data from somewherE? If so, ensure that input data can not be tainted in any way, or that tainted data can be detected and discarded.
    • Does it matter if others were to try and run the script? If so, as with the first point, ensure that nobody can execute it, and preferably not read from it. chmod 0700 is generally a good idea for scripts that perform system functions.
    • And the cases where you'd want a script to have a setuid (via its interpreter) are extremely rare

    The two points that separate a script from a compiled program would be that the source is visible, and that an interpreter executes it. As long as the interpreter hasn't been compromised (such as having a setuid bit on it), you'd be fine.

    When writing scripts to do system tasks, typos and screwups and general human error when writing it do to some extent represent a potential security failure, but that would also be the case with compiled programs (and a lot of people tend to ignore the fact that compiled programs can also be disassembled)

    It is worth noting that in most (if not all) linux flavors, most (if not all, in fact, can't think of any that aren't) services are started via a shellscript.

提交回复
热议问题