Created
July 25, 2020 14:20
-
-
Save spacelatte/85af73259e23f09d02ba2fd41b4e4255 to your computer and use it in GitHub Desktop.
#tmux #read #only #session this setuid executable allows you to connect other people's sessions as a readonly viewer
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 <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <unistd.h> | |
| #include <sys/stat.h> | |
| #include <dlfcn.h> | |
| #include <dirent.h> | |
| int main(int argc, char **argv) { | |
| if(argc < 2) { | |
| printf( | |
| "Usage: %s <uid> [socket_name]\n" | |
| "Example: %s 2214 mysock\n" | |
| "\t'mysock' may be omitted (uses 'default')\n", | |
| argv[0], argv[0], NULL | |
| ); | |
| return 1; | |
| } | |
| char buf[1024]; | |
| struct stat fstat; | |
| stat(argv[0], &fstat); | |
| if(setuid(fstat.st_uid)) { | |
| //printf("Error: %s\n", strerror(errno)); | |
| perror("Error (setuid)"); | |
| }; | |
| snprintf(buf, sizeof(buf), "/tmp/tmux-%d/%s", | |
| (argc > 1) ? atoi(argv[1]) : fstat.st_uid, | |
| (argc > 2) ? argv[2] : "default", | |
| NULL | |
| ); | |
| //execlp("tmux", "tmux.readonly", "-S", buf, "attach", "-r", NULL); | |
| char **args = (char**) calloc(6 + argc, sizeof(char*)); | |
| // printf("argc: %d\n", argc); | |
| args[0] = "tmux"; | |
| args[1] = "tmux.readonly"; | |
| args[2] = "-S"; | |
| args[3] = buf; | |
| args[4] = "attach"; | |
| args[5] = "-r"; | |
| if(argc > 2) memcpy(args+6, argv+3, sizeof(char*) * (argc-2)); | |
| // for(char **arg=args; arg && *arg; arg++) printf("%s\n", *arg); | |
| execvp(args[0], args+1); | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment