[lug] Passing User Execution to Root

rm at mamma.varadinet.de rm at mamma.varadinet.de
Mon Jan 1 14:35:05 MST 2001


On Mon, Jan 01, 2001 at 01:35:02PM -0700, D. Stimits wrote:
> SoloCDM wrote:
> > 
> > Is it possible to pass an executed program over to the super-user
> > from a user?  I tried nohup and the ampersand in X as a user,
> > but once the terminal closes -- the command terminates.

No, you can't 'give' a program to the superuser (that would be a nice,
hackerfriendly feature :-) Mind running this trojan for me?

> 
> That seems a bit odd that you can't background it. Would the command
> terminate in error if it didn't have access to stdio? Do you know if the
> command simply terminated, versus crashed?
>

That is strange, indeed. BTW, putting a program in the background
with your shells jobcontrol won't save it from recieving a hangup
signal (SIGHUP) when the shell from which you started it recieves
a SIGHUP (normally when you log out or close the xterm window).
This signal will be sent to all jobs, foreground or background,
active or stopped (stopped jobs are woken up by sending a SIGCONT).
There are several ways to keep this signal from reaching your
program:

  - trap the signal with a subshell or by running your 
    program from a shell wrapper script:
*-----------------------------------------------
|   
|   ralf at edoras:~$ sleep 5000 &
|   [1] 553
|   ralf at edoras:~$ kill -HUP 553
|   ralf at edoras:~$ ps
|    PID TTY          TIME CMD
|    517 ttyp3    00:00:00 bash
|    554 ttyp3    00:00:00 ps
|   [1]+  Hangup                  sleep 5000
|   ralf at edoras:~$ (trap "" SIGHUP; sleep 5000) &
|   [1] 555
|   ralf at edoras:~$ kill -HUP 555
|   ralf at edoras:~$ ps
|    PID TTY          TIME CMD
|    517 ttyp3    00:00:00 bash
|    555 ttyp3    00:00:00 bash
|    556 ttyp3    00:00:00 sleep
|    557 ttyp3    00:00:00 ps
|   ralf at edoras:~$ 
|

 - use the bash building command 'disown':

*-------------------------------------------
|  
|   ralf at edoras:~$ sleep 5000 &
|   [1] 570
|   ralf at edoras:~$ disown  -h 570
|  

There is one important difference here: disown will only
keep the shell from sending SIGHUP to the program, it won't
keep other processes from sending the signal to your program
(this is important if the program is a daemon that is controlled
by sending signal).

Of course you could modify your program an block SIGHUP.
If it's not SIGHUP that kill your program you might want to
write a little wrapper script that traps all signals and 
logs them so you can see what's causing the problems.

D. Stimits is right, some program aren't happy about running
in the background or loosing their controlling terminal.


  Ralf






More information about the LUG mailing list