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

  1. /*
  2.  * From:    CERT Tools <cert-tools-request@cert.org>
  3.  * To:      cert-tools@cert.org
  4.  * Subject: Quiet list
  5.  * Date:    Wed, 31 Aug 1994 10:37:16 -0400
  6.  *
  7.  * Its been quiet, here is something to stir things up a little :-)
  8.  *
  9.  *                - Shawn
  10.  * Shawn F. Mckay                   phone: 617-253-2583
  11.  * Dept. of Electrical Eng. & Computer Science       email: shawn@eddie.mit.edu
  12.  * M.I.T. / room 38-388 / Cambridge, MA  02139 / USA
  13.  * ** PGP Key available on request **
  14.  *
  15.  */
  16.  
  17. /*
  18.  * Dummy "su" program. Intended to help an intruder who does not
  19.  * know the system (many work from "cheat sheets") to trip alarms
  20.  * so the rightful sysadmin folks can charge to the rescue.
  21.  *
  22.  * Author: Shawn F. Mckay (shawn@aradia.uucp)
  23.  * Revision Date: 94-08-29
  24.  * Version: 1.1
  25.  * Copyright (c) 1989-1994 Shawn F. Mckay, All Rights Reserved.
  26.  * May not be sold for profit without written concent of author.
  27.  * No warranty of ANY KIND is implied, use at your own risk!
  28.  *
  29.  * Installation Notes:
  30.  *   a) Create a directory in a secret place mode 770 (group whlcp)
  31.  *   b) Move your real copy of "su" to this new location
  32.  *      Make it also group whlcp and mode 4510
  33.  *   c) Now, install this here su into the old location of your
  34.  *      systems su program. (mode 4511) (usually /bin or /usr/bin).
  35.  *      This program needs to be setuid root to be beleived, but as
  36.  *      you can see, it does NOT run as root, it runs as daemon as
  37.  *      soon as its run.
  38.  *   d) Finally, make sure to add yourself to whlcp group as needed.
  39.  *   e) Act quickly if you detect a violation of any kind
  40.  *
  41.  *   Also note, you will probably need to modify /etc/crontab to
  42.  *   advise any system shell scripts where the "real" su went. You
  43.  *   should probably try and ensure these places are also non-world
  44.  *   readable.
  45.  *
  46.  * The above should work for almost ANY UNIX system. As always, use
  47.  * your judgement.
  48.  */
  49.  
  50. #include <stdio.h>
  51. #include <syslog.h>
  52.  
  53. char uname[10], tname[20];
  54. extern char *getlogin(), *ttyname();
  55.  
  56. main (argc, argv)
  57. char **argv;
  58. {
  59.     char *key, *t;
  60.  
  61.     /*
  62.      * If an intruder is to buy this, we must LOOK like a
  63.      * real copy of "/bin/su"
  64.      */
  65.  
  66.     if (geteuid ()) {
  67.         fprintf (stderr, "su: not properly installed\n");
  68.         exit (1);
  69.     } else {
  70.         /*
  71.          * Become daemon, "Right away!"
  72.          */
  73.  
  74.         setgid (1);
  75.         setuid (1);
  76.     }
  77.  
  78.     /*
  79.      * Discover our uname / location
  80.      */
  81.  
  82.     if ((t = getlogin ()) == NULL)
  83.         strcpy (uname, "unknown");
  84.     else
  85.         strcpy (uname, t);
  86.  
  87.     if ((t = ttyname(2)) == NULL)
  88.         strcpy (tname, "unknown");
  89.     else
  90.         strcpy (tname, t);
  91.  
  92.     /*
  93.      * Open log, and gripe!
  94.      */
  95.  
  96. #ifdef LOG_AUTH
  97.     openlog ("su", LOG_PID, LOG_AUTH);
  98. #else
  99.     openlog ("su", LOG_PID);
  100. #endif
  101.     syslog (LOG_NOTICE, "SU attempt failed by %s on %s\n",
  102.     uname, tname);
  103.      syslog (LOG_NOTICE, "User tried to become %s using su\n",
  104.     (argc > 1 ? argv[1] : "root"));
  105.  
  106.     /*
  107.      * Query for a password, to look real
  108.      */
  109.  
  110.     key = (char *)getpass ("Password: ");
  111.  
  112.     /*
  113.      * Also, send email here, to add to the "feel" of delay...
  114.      */
  115.  
  116.     sendmail (argc, argv);
  117.     (void)crypt (key, "XX");/* Look and feel tactic */
  118.  
  119.     /*
  120.      * Of course, we knew this was coming!
  121.      */
  122.  
  123.     printf ("Sorry\n");
  124.     
  125.     exit (1);
  126. }
  127.  
  128. /*
  129.  * sendmail()
  130.  *    Blast off an email message about this attempt. Quick and sweet
  131.  */
  132.  
  133. sendmail (argc, argv)
  134. char **argv;
  135. {
  136.     FILE    *pbuf;
  137.     long    Clock;
  138.  
  139.     if (access ("/usr/bin/mail", 0))
  140.         return (0);
  141.  
  142.     if ((pbuf = popen ("/usr/bin/mail root", "w")) == NULL) 
  143.         return (0);
  144.  
  145.     time (&Clock);
  146.  
  147.     fprintf (pbuf, "\nSECURITY VIOLATION NOTICE:\n\n");
  148.     fprintf (pbuf, "Attempt failed to run su by %s from %s %s",
  149.     uname, tname, ctime (&Clock));
  150.  
  151.      fprintf (pbuf, "User tried to become %s using su\n",
  152.     (argc > 1 ? argv[1] : "root"));
  153.  
  154.     fprintf (pbuf, "\n.\n");
  155.     pclose (pbuf);
  156.  
  157.     return (1);
  158. }
  159.