Calling a script from a setuid root C program - script does not run as root

前端 未结 5 821
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 02:14

I need to run a bash script as root (passwordless sudo or su not viable) and since you cannot setuid a script in Linux, I thought about calling it from an executable and mak

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 03:12

    Why is sudo not viable? It avoids raging security holes such as:

    bash-3.2$ cat test
    #!/bin/bash
    echo ima shell script durp durp
    bash-3.2$ chmod +x test
    bash-3.2$ ./test
    heh heh
    bash-3.2$ 
    

    Due to the environment not being properly sanitized, for example in this case:

    export echo='() { builtin echo heh heh; }'
    

    sudo sanitizes this case, and perhaps other edge cases and gotchas that would be well not to write into a custom suid wrapper.

提交回复
热议问题