All pastes #48909 Raw Edit

Anonymous

public c v1 · immutable
#48909 ·published 2006-04-10 18:49 UTC
rendered paste body
/* This is a simple script meant to help debug scripts supposed to run in chroot. * stuff run in chroot usually isn't run as root, but it can be hard to debug * such stuff. By using this small util you can execute what you want, with the * uid of your choice. *  * How to compile: * gcc -static -o /glftpd/bin/droproot droproot.c *  * How to run: * chroot /glftpd /bin/droproot <number> "something to run" *  * Number must be between 1 and 65535. * The "" is only needed if you wish to pass args to the script you wish to * test. * Examples: * chroot /glftpd /bin/droproot 200 /bin/my_script.sh             <- valid - no args * chroot /glftpd /bin/droproot 200 /bin/my_script.sh l33tuser    <- invalid - arg will not be passed. * chroot /glftpd /bin/droproot 200 "/bin/my_script.sh l33tuser"  <- valid - arg will be passed. */ #include <stdlib.h>#include <stdio.h>#include <sys/types.h>#include <unistd.h>int main(int argc, char **argv) {        int number;        if ( argc < 3 ) {                printf("syntax: %s <number> \"<command to run>\"\n", argv[0]);                return 1;        }        number = atoi(argv[1]);        if ( number <1 || number >65535 ) {                printf("syntax: %s <number> \"<command to run>\"\n", argv[0]);                printf("<number> must be between 1 and 65535\n");                return 1;        }        setuid(number);        setgid(number);        seteuid(number);        setegid(number);        return system(argv[2]);}