And now you can execute an arbitrary Perl script, as root, without installing anything. (Assuming that you have the password.) You can do the same thing over ssh.open(my $shell, "|-", "sudo perl") or die "Can't pipe to bash: $!"; print $shell "$password\n"; sleep(1); # Make sure that Perl has started. This is likely unneeded. print $shell $some_perl_script; close($shell) or die $! ? "Error closing pipe: $!" : "Exit status $? from perl child";
Of course this is very much the wrong way to do it. Your root password is now available to anyone who can read the script. A much, much better approach is to find standard, more secure, ways to get a passwordless escalation. For instance locally use setuid. Remotely you can follow the advice at http://www.debian-administration.org/articles/152 and set up secure passwordless logins that use secure public keys. (If you're doing this from a shared box, you may want to set those up from some privileged account, and then have setuid scripts that can run as that account.)
In reply to Re^5: Automating sudo actions
by tilly
in thread Automating sudo actions
by rastoboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |