SUID not working with shell script

前端 未结 2 1791
青春惊慌失措
青春惊慌失措 2020-12-01 19:02

I have created a small shell script with the following content:

cat /usr/bin/checksuid.sh

!/bin/bash
echo \"Hello\" > /etc/myfile.cnf

ls -l /usr/bin/che         


        
相关标签:
2条回答
  • 2020-12-01 19:56

    From http://www.tuxation.com/setuid-on-shell-scripts.html:

    "the truth is actually that the setuid bit is disabled on a lot of *nix implementations due the massive security holes it incurs"

    An alternative approach - wrap the script in something that can use setuid, like this example c program. There are obviously differences to simply calling your script vs using a wrapper like this (e.g. ignored exit codes) but this should give you an idea anyway.

    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <unistd.h>
    
    int main()
    {
       setuid( 0 );
       system( "/path/to/script.sh" );
    
       return 0;
    }
    
    0 讨论(0)
  • 2020-12-01 20:00

    Shell scripts can't be SUID. See http://www.faqs.org/faqs/unix-faq/faq/part4/section-7.html

    0 讨论(0)
提交回复
热议问题