|
@@ -0,0 +1,274 @@
|
|
|
+#include <stdio.h>
|
|
|
+#include <string.h>
|
|
|
+#include <unistd.h>
|
|
|
+
|
|
|
+#include <pty.h>
|
|
|
+#include <termios.h>
|
|
|
+#include <fcntl.h>
|
|
|
+
|
|
|
+#include <sys/select.h>
|
|
|
+#include <sys/wait.h>
|
|
|
+
|
|
|
+#include <signal.h> // handle Ctrl-C/SIGINT
|
|
|
+
|
|
|
+#include <time.h> // usleep(), nanonsleep() ?
|
|
|
+#include <strings.h> // strcasecmp
|
|
|
+
|
|
|
+#include <stdlib.h> // random()
|
|
|
+
|
|
|
+#define TARGET "./mySTIC"
|
|
|
+#define BSIZE 1024
|
|
|
+#define LOGGING
|
|
|
+
|
|
|
+const char * it_is_now(void) {
|
|
|
+ static char buffer[100];
|
|
|
+ time_t timer;
|
|
|
+ struct tm* tm_info;
|
|
|
+
|
|
|
+ timer = time(NULL);
|
|
|
+ tm_info = localtime(&timer);
|
|
|
+ strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tm_info);
|
|
|
+ return buffer;
|
|
|
+}
|
|
|
+
|
|
|
+void slow_write(int fd, int speed, char * buffer, int len) {
|
|
|
+ int x;
|
|
|
+ for( x = 0; x < len; x++) {
|
|
|
+ usleep(speed);
|
|
|
+ write( fd, &buffer[x], 1);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void harry_event(int fd) {
|
|
|
+
|
|
|
+ char clear[] = "\b \b";
|
|
|
+ int x;
|
|
|
+ char haha[] = "Hahaha hahaha!!!";
|
|
|
+ char beep = '\a';
|
|
|
+
|
|
|
+ slow_write(fd, 11500, haha, strlen(haha) );
|
|
|
+ write(fd, &beep, 1);
|
|
|
+ sleep(3);
|
|
|
+ for( x = 0; x < strlen(haha); x++ ) {
|
|
|
+ write(fd, clear, strlen(clear) );
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+NOTE: Logging is single file, don't use in production!
|
|
|
+It won't handle multiple writers.
|
|
|
+*/
|
|
|
+char * username = NULL;
|
|
|
+char * fullname = NULL;
|
|
|
+
|
|
|
+void pcopy(char * pstring, char * str) {
|
|
|
+ int len = (int)*pstring;
|
|
|
+ strncpy( str, pstring+1, len );
|
|
|
+ str[len] = 0;
|
|
|
+}
|
|
|
+
|
|
|
+int locate_user(const char *alias) {
|
|
|
+ FILE * user;
|
|
|
+ char buffer[0x600];
|
|
|
+ char temp[100];
|
|
|
+
|
|
|
+ user = fopen("data/users.dat", "rb");
|
|
|
+ if (user == NULL)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+
|
|
|
+ while (fread(buffer, 0x600, 1, user) == 1) {
|
|
|
+ pcopy( buffer + 0x6d, temp );
|
|
|
+ if ( strcasecmp( temp, username) == 0) {
|
|
|
+ pcopy(buffer + 0x8c, temp );
|
|
|
+ fullname = strdup(temp);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("Alias: %s\n", temp);
|
|
|
+ pcopy(buffer + 0x8c, temp );
|
|
|
+ printf("Full Name: %s\n", temp );
|
|
|
+ */
|
|
|
+ }
|
|
|
+ fclose(user);
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void mangle( char * buffer ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+int main(int argc, char * argv[])
|
|
|
+{
|
|
|
+ int master;
|
|
|
+ pid_t pid;
|
|
|
+
|
|
|
+#ifdef LOGGING
|
|
|
+ FILE * fp;
|
|
|
+
|
|
|
+ fp = fopen("mystic_pipe.data", "wb");
|
|
|
+ if ( fp == NULL ) {
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ srandom(time(NULL));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (int x = 0; x < argc; x++) {
|
|
|
+ if (strncmp("-U", argv[x], 2) == 0) {
|
|
|
+ username = argv[x] + 2;
|
|
|
+#ifdef LOGGING
|
|
|
+ fprintf(fp, "Username: [%s]\n", username);
|
|
|
+#endif
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (username != NULL) {
|
|
|
+ locate_user(username);
|
|
|
+#ifdef LOGGING
|
|
|
+ fprintf(fp, "Username: [%s] A.K.A. [%s]\n", username, fullname);
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ pid = forkpty(&master, NULL, NULL, NULL);
|
|
|
+
|
|
|
+
|
|
|
+ if (pid < 0) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ else if (pid == 0) {
|
|
|
+ char *args[20];
|
|
|
+ int x;
|
|
|
+ args[0] = TARGET;
|
|
|
+
|
|
|
+ for ( x = 1; x < argc; x++ ) {
|
|
|
+ args[x] = argv[x];
|
|
|
+ };
|
|
|
+ args[x] = NULL;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ execvp( TARGET, args);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ else {
|
|
|
+
|
|
|
+
|
|
|
+ struct termios tios, orig1;
|
|
|
+ struct timeval timeout;
|
|
|
+ int last_event;
|
|
|
+
|
|
|
+ tcgetattr(master, &tios);
|
|
|
+ tios.c_lflag &= ~(ECHO | ECHONL | ICANON );
|
|
|
+ tcsetattr(master, TCSAFLUSH, &tios);
|
|
|
+
|
|
|
+ tcgetattr(1, &orig1);
|
|
|
+ tios = orig1;
|
|
|
+ tios.c_iflag &= ~(ICRNL | IXON);
|
|
|
+
|
|
|
+ tios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ tcsetattr(1, TCSAFLUSH, &tios);
|
|
|
+
|
|
|
+
|
|
|
+ for (;;) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ fd_set read_fd;
|
|
|
+ fd_set write_fd;
|
|
|
+ fd_set except_fd;
|
|
|
+
|
|
|
+
|
|
|
+ FD_ZERO(&read_fd);
|
|
|
+ FD_ZERO(&write_fd);
|
|
|
+ FD_ZERO(&except_fd);
|
|
|
+
|
|
|
+
|
|
|
+ FD_SET(master, &read_fd);
|
|
|
+
|
|
|
+ FD_SET(STDIN_FILENO, &read_fd);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ timeout.tv_sec = 10;
|
|
|
+ timeout.tv_usec = 0;
|
|
|
+
|
|
|
+
|
|
|
+ if ( select(master+1, &read_fd, &write_fd, &except_fd, &timeout) == 0 ) {
|
|
|
+
|
|
|
+ harry_event(STDOUT_FILENO);
|
|
|
+#ifdef LOGGING
|
|
|
+ fprintf(fp, "%s : TICK\n", it_is_now());
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ char input[BSIZE + 1];
|
|
|
+ char output[BSIZE + 1];
|
|
|
+ int total;
|
|
|
+
|
|
|
+
|
|
|
+ if (FD_ISSET(master, &read_fd))
|
|
|
+ {
|
|
|
+
|
|
|
+ if ((total = read(master, &output, BSIZE)) != -1) {
|
|
|
+
|
|
|
+ output[total] = 0;
|
|
|
+
|
|
|
+ if (random() % 20 < 3) {
|
|
|
+ mangle( output );
|
|
|
+ }
|
|
|
+
|
|
|
+ write(STDOUT_FILENO, &output, total);
|
|
|
+
|
|
|
+
|
|
|
+#ifdef LOGGING
|
|
|
+ fprintf(fp, ">> [%s]\n", output);
|
|
|
+#endif
|
|
|
+ } else
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (FD_ISSET(STDIN_FILENO, &read_fd))
|
|
|
+ {
|
|
|
+
|
|
|
+ total = read(STDIN_FILENO, &input, BSIZE);
|
|
|
+ input[total] = 0;
|
|
|
+
|
|
|
+ write(master, &input, total);
|
|
|
+
|
|
|
+
|
|
|
+#ifdef LOGGING
|
|
|
+ fprintf(fp, "<< [%s]\n", input);
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tcsetattr(1, TCSAFLUSH, &orig1);
|
|
|
+#ifdef LOGGING
|
|
|
+ fclose(fp);
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|