Last active
August 22, 2016 11:36
-
-
Save spacelatte/75288878f51f6755a64cf488ef0e0e35 to your computer and use it in GitHub Desktop.
tmux guest session
This file contains 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
// tmux.c | |
// compile using: cc -o tmux tmux.c | |
// makeit setuid executable by: chmod +s tmux | |
// also change owner to desired user: [sudo] chown {usernamehere} tmux | |
// give it to guests' shell (passwd entry): guest::9999:99:guest user:/tmp:/opt/tmux | |
// you can delete password with passwd -du {login} | |
// allow empty passwords with PermitEmptyPasswords yes in sshd_config | |
// update (18 aug 2016): added dynamic owner change, for security ofc :) | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <sys/stat.h> | |
#define BUFFER_SIZE 80 | |
int main(int argc, char **argv) | |
{ | |
// get owner of current executable | |
struct stat fstat; | |
stat(argv[0],&fstat); | |
setuid(fstat.st_uid); | |
// allocate buffer to set commandline | |
char buf[BUFFER_SIZE]; | |
// set tmux parameters to attach | |
sprintf(buf,"/usr/bin/tmux -S /tmp/tmux-%d/default attach -r || echo failed;",fstat.st_uid); | |
// execute! | |
execlp("/bin/sh","$SHELL","-c",buf,NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment