upload kissy code

This commit is contained in:
Magdalunaa 2025-11-17 17:46:00 +01:00
commit c15c5c5a7c

94
kissy.c Normal file
View file

@ -0,0 +1,94 @@
/* KISSY (KISSY Interface for Sapphic Smooching over ttY) v1.0 by Magdalunaa
This file needs to:
- be owned by the tty group (or whatever group owns the terminal devices in your system)
- have setgid set
- be group executable
- not be world writeable
You can probably just use 2755 permissions. those work
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>
#include <pwd.h>
// mreowww meow nya :3
int main (int argc, char **argv) {
// are we running with setgid?
struct stat stat_self;
stat("/proc/self/exe", &stat_self);
if (!(stat_self.st_mode & S_ISGID && !(stat_self.st_mode & S_IWOTH))) {
printf("%s\n", "setgid is not set, or this file is world writeable.");
return 3;
}
// check we have at least one argument
if (argc < 2) {
printf("%s\n", "Not enough arguments!\nUsage: kissy [target] <message>");
return 0;
}
// try to find the target's uid
struct passwd *pw = getpwnam(argv[1]);
if (pw == NULL) {
printf("%s\n", "Cannot find target");
return 1;
}
int target = pw->pw_uid;
// get current username
struct passwd *pw2 = getpwuid(getuid());
if (pw == NULL) {
printf("%s\n", "Cannot find user");
return 2;
}
char* user = pw2->pw_name;
// if we have a second argument, set a custom kiss message
char* kiss;
if (argc >= 3)
kiss = argv[2];
else
kiss = "*mwah*";
short kissed = 0;
// iterate over all files in directory
DIR *dir = opendir("/dev/pts");
while (1) {
struct dirent *ent = readdir (dir);
if (ent == NULL)
break;
char filepath[strlen("/dev/pts/") + strlen(ent->d_name) + 1];
strcpy(filepath, "/dev/pts/");
strcat(filepath, ent->d_name);
struct stat stats;
stat (filepath, &stats);
// find all terminals with the correct user and that are group-writable
if (stats.st_mode & S_IWGRP && stats.st_uid == target) {
kissed = 1;
if (stats.st_gid != getegid()) { // are we running as the tty user?
printf("%s\n", "Mismatch between file owner group and current effective group. Make sure this program is running with setgid.");
} else {
FILE *tty = fopen(filepath, "a"); // write to terminal!
fprintf(tty, "\n%s\n--%s\n", kiss, user);
fclose(tty);
}
}
}
// print a message if a suitable terminal couldn't be found
if (!kissed)
printf("%s\n", "Couldn't find any suitable terminals. User is not logged in or has not enabled messages.");
}