0

I want to verify the security performance of the su password. The way I think of is to execute the su command by setting up the child process, then enter the password, and then get the current UID to determine if it is equal to 0, but I don't know how to connect the IO now. Go to the script opened by the child process, is there any way to connect IO, or other methods to verify the security of su password, thank you very much:)

int main(){

pid_t pid;
if((pid = fork()) < 0){
    printf("fock error!\n");
}
else if(pid == 0){// child 
    execl("/bin/sh", "-sh", (char*)0);
    //Execute su and input password to become root user, but I dont know how to pass the command to my shell
    exit(1);

}
else{ // parents
    waitpid(pid, NULL, 1);
    //get my child process exec ' result
}
Q.laeen
  • 1
  • 1
  • Yes, read the man pages on `pipe` and `dup2`. The general idea is to open pipes before the fork, and because all file-handles are duplicated during a fork, you close one end on the parent process, and close the other end on the child, making a communication channel between them. Then you `dup2` the pipes over the child's file descriptors STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO (defined in ``). You have to do the `dup2` part in the child: after fork, before exec. Now you can remote-control the child and read it's console output via the pipes. – lockcmpxchg8b Aug 30 '18 at 02:59
  • thank u ,I just saw the source code of popen and found this method. – Q.laeen Aug 30 '18 at 03:03
  • Look at the `main` function in [this answer](https://stackoverflow.com/questions/47426472/how-to-remote-control-gdb-on-linux/47445907#47445907) for an example. It's a little complicated, because it launches a child, then forks a gdb to debug that child, remote-controlling the gdb. – lockcmpxchg8b Aug 30 '18 at 03:04

0 Answers0