Ruby on Rails - how to run a bash script as root?

What I want to do is use "button_to" and friends to run different scripts on linux server. Not all scripts should be root, but some will, since they will run apt-get dist-upgrade, etc.

PassengerDefaultUser set www-data to apache2.conf

I have already tried running scripts from the controller that deal with things like writing to text files, etc., so that I know that Rails executes the script correctly. (in other words, I know how to run a script from a controller). But I cannot figure out how to run a script that requires root access. Can anyone give me an edge?

Security Note: Thank you for all the hacking warnings that were provided. However, you do not need to sleep because A) the web application is not accessible from the public Internet, it will only be on private intranets, B) the application is password protected and C) because the user will not be able to provide user input, only make selections from the form which will be passed as a variable to the script. However, since I say that this does not mean that I do not pay attention to your safety recommendations, I will consider them very carefully in my design.

+3
source share
1 answer

setuid sudo. Bash. Setuid , sudo. sudo setuid, root. setuid ( ) .

, , , , . Ruby Perl , script , , . Taint mode. Bash taint.

Taint , .

:

chmod script, 4755, root:

$ chmod 4755 script.rb
$ chown root script.rb

script, . setuid script, root. .

. Ruby taint, Ruby, , . perlsec faq, , Perl.

. , root . Bash! Ruby Perl Bash. Taint .

+6

Source: https://habr.com/ru/post/1720946/


All Articles