Home

Sriram's Weblog

In the most Linux distributions, setuiddoesn’t work on shell scripts because of the security issues associated with it.

But you can use the setuid on binary files and from there you can execute the shell script as root user. And the following steps will help you to do that.

1) Copy the following C program to a file named « runasroot.c » and this program simply runs a script which is passed as command-line argument.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {                                              
  if (argc != 2) {                                                              
    printf("Usage: %s /path/to/scriptn", argv[0]);                             
    printf("Note: '/path/to/script' can be either relative or absolute path.nE
xamples:n%s ./build.sh n%s /tmp/test.shn", argv[0], argv[0]);                
  } else {                                                                      
    printf("Running the script '%s' as root user...n", argv[1]);               
    setuid(0);                                                                  
    system(argv[1]);                                                            
  }                                                                             
   return 0;                                                                    
}

2) Compile it.

gcc…

View original post 145 mots de plus

Advertisements

Laisser un commentaire

Choisissez une méthode de connexion pour poster votre commentaire:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s