suid pit

Beginners of Linux must have been exposed to suid and know its function, but it has a pit when it is used, and I wrote it here after tossing it all night.

1. Introduction to suid (if you know it, you can skip it): Setting suid to an executable file allows other users to temporarily have the permission of the owner of the file when executing it. For example, passwd modifies the password file of the system, which undoubtedly belongs to root, but any user can execute passwd to successfully modify the password file. It is because of the s in the permissions

2. Step on a pit!

     Seeing this, someone must be eager to try it, and write a bash script immediately!

     For example, to view the root home directory:

     Add permissions:

     Can't wait to switch normal user execution, however. . . . :

3. Change the way of writing:

    Then try writing it in C language?

    Compile, execute:

    This time it worked. . . . .

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324725040&siteId=291194637