Created
October 23, 2022 11:47
-
-
Save alirezaarzehgar/d6d0ca01eb0948b5ada3fe189b53c08a to your computer and use it in GitHub Desktop.
su command example for learning setuid & setgid in c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CC = cc | |
| SRC = $(wildcard *.c) | |
| OBJ = $(SRC:.c=.o) | |
| TARGET = su | |
| all: $(TARGET) | |
| $(TARGET): $(OBJ) | |
| $(CC) $(OBJ) -o $(TARGET) | |
| %.o: %.c | |
| $(CC) -c $< -o $@ | |
| install: $(TARGET) | |
| chown root:root $(TARGET) | |
| chmod 4755 $(TARGET) | |
| clean: | |
| rm -rf $(TARGET) $(OBJ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <unistd.h> | |
| #include <pwd.h> | |
| int main(int argc, char const *argv[]) | |
| { | |
| struct passwd *pw = getpwnam("root"); | |
| setgid(0); | |
| setuid(0); | |
| execlp(pw->pw_shell, pw->pw_shell, NULL); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment