home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Texts / cron96.txt < prev    next >
Text File  |  1999-11-04  |  10KB  |  330 lines

  1.  
  2.             ######    ##   ##    ######
  3.             ##        ###  ##      ##
  4.             ######    ## # ##      ##
  5.                 ##    ##  ###      ##
  6.             ###### .  ##   ## .  ######.
  7.  
  8.                 Secure Networks Inc.
  9.  
  10.                  Security Advisory
  11.                  December 23, 1996
  12.  
  13.              Vulnerabilities in Default Cron Jobs
  14.  
  15. We have become aware of serious problems relating to the handling of 
  16. temporary files by the default BSD cron jobs /etc/security and later 
  17. became aware of an equally serious problem in /etc/daily.  In addition, 
  18. the 4.4BSDlite2 version of /etc/security passes unchecked data to a 
  19. shell.  These bugs make it possible for unpriviliged users to obtain root 
  20. access, EVEN IF THERE ARE NO SETUID PROGRAMS ON THE SYSTEM.
  21.  
  22. Technical Details
  23. ~~~~~~~~~~~~~~~~~
  24. The first problem with /etc/security is that it passes unchecked data to 
  25. a shell.  If a user creates a file whose name contains shell 
  26. metacharacters and makes it executable and setuid, /etc/security will 
  27. gladly execute commands specified in the name of the file as root.
  28. The problem is the big find line used to search for setuid files, 
  29. which in 4.4BSDlite2 reads:
  30. (find / ! -fstype local -a -prune -o \
  31.     \( -perm -u+s -o -perm -g+s -o ! -type d -a ! -type f -a ! -type l -a \
  32.        ! -type s \) | \
  33. sort | sed -e 's/^/ls -ldgT /' | sh > $LIST) 2> $OUTPUT
  34.  
  35.  
  36. The second problem with /etc/security is its poor use of temporary 
  37. files.  In 4.4BSDLite2 /etc/security uses six temporary files unsafely.  
  38. They are all named /tmp/_secure?.$$, where ? is a number in the range 
  39. 1 through 6, and $$ is replaced with the process id of the shell 
  40. interpreting /etc/security at run time.  A malicious user needs merely 
  41. to run an at job a minute before /etc/security which creates symlinks 
  42. named /tmp/_secure?.$$, and wait for the cron job to overwrite the file 
  43. of his choice.  In addition, the user has much control over the contents 
  44. of some of these temporary files, allowing users to obtain root access.
  45.  
  46. Similarly, the /etc/daily script search for core files to be deleted can 
  47. be induced to corrupt arbitrary files, and even create valid .rhosts 
  48. files.  By creating files with names like:
  49. + + #.core
  50. and leaving an appropriate symbolic link in /tmp, users can obtain 
  51. root priviliges.
  52.  
  53. These are doubtless not the only shell scripts with /tmp problems, and 
  54. 4.4BSD is certainly not alone in having these kinds of problems.  However, 
  55. given the wide availiblity of source to shell scripts which ship with 
  56. operating systems, it is fairly easy for the informed system 
  57. administrator to determine whether scripts on his system are vulnerable.
  58.  
  59. Impact
  60. ~~~~~~
  61. Users with a valid account can obtain root priviliges even if there are 
  62. no setuid programs on the system.
  63.  
  64. Vulnerable Systems
  65. ~~~~~~~~~~~~~~~~~~
  66. 4.4BSDlite derived unixes are likely to be vulnerable to the particular 
  67. default cron job problems described here.  
  68.  
  69. OpenBSD 2.0 is vulnerable to the /etc/daily problem, which is fixed
  70.     in OpenBSD-current.  OpenBSD 2.0 is not vulnerable to any of the
  71.     problems in /etc/security.
  72. FreeBSD 2.1.5 is vulnerable to the /tmp problems in /etc/security and
  73.     but does not pass unchecked data to a shell in /etc/security,
  74.     or have a /tmp related problem in /etc/daily.
  75. BSD/OS 2.0 is vulnerable to the problems in /etc/security, but not
  76.     the problem in /etc/daily.  We have not checked a more recent
  77.     release of BSD/OS.
  78. NetBSD 1.2 is vulnerable to all three problems.
  79. 4.4BSDlite2 is vulnerable to all three problems.
  80.  
  81. Note that the vulnerability information for BSD/OS, NetBSD, and 
  82. 4.4BSDlite2 is based exclusively on source inspection.
  83.  
  84. Be aware that even if not vulnerable to these specific problems, virtually
  85. every operating system has at least one shell script which does not
  86. safely handle temporary files.  Given the availibility of source code
  87. to shell scripts, operating system vendors would do well to make them
  88. a showcase of good programming practices.  
  89.  
  90.  
  91. Fix Information
  92. ~~~~~~~~~~~~~~~
  93. The version of /etc/security in OpenBSD 2.0 appears safe, as does the 
  94. version of /etc/daily in OpenBSD-current.  On most operating systems, 
  95. mkdir is both atomic, and does not follow symbolic links.  Therefore it 
  96. is possible to use mkdir in a shell script to write portable and secure 
  97. code.
  98.  
  99. # A viable /etc/security, which requires OpenBSD or GNU
  100. # find and xargs.
  101. # note that this version lacks features found in the 4.4Lite2
  102. # /etc/security.
  103. #------------------------- cut here -----------------------------
  104.  
  105.  
  106. #!/bin/sh 
  107. #
  108. PATH=/sbin:/bin:/usr/bin
  109. LC_ALL=C; export LC_ALL
  110.  
  111. host=`hostname -s`
  112. echo "Subject: $host security check output"
  113.  
  114. LOG=/var/log
  115. umask 077
  116. TDIR=/tmp/_secure.$$
  117. if ! mkdir $TDIR ; then
  118.     echo $TDIR already exists
  119.     ls -alF $TDIR
  120.     exit 1
  121. fi
  122.  
  123. TMP=$TDIR/secure
  124. trap 'rm -rf $TDIR' 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15
  125.  
  126. echo "checking setuid files and devices:"
  127.  
  128.     find / -fstype local -and -type f -and \
  129.            \( -perm 4000 -or -perm 2000 \) -print0 | sort  \
  130.         | xargs -0 ls -lgTd > $TMP
  131.  
  132. if [ ! -f $LOG/setuid.today ] ; then
  133.     echo "no $LOG/setuid.today"
  134.     cp $TMP $LOG/setuid.today
  135. fi
  136. if cmp $LOG/setuid.today $TMP >/dev/null; then :; else
  137.     echo "$host setuid diffs:"
  138.     diff -b $LOG/setuid.today $TMP
  139.     mv $LOG/setuid.today $LOG/setuid.yesterday
  140.     mv $TMP $LOG/setuid.today
  141. fi
  142. rm -f $TMP
  143.  
  144.  
  145. #------------------------- cut here -----------------------------
  146. # A viable /etc/daily based around the OpenBSD one:
  147. #------------------------- cut here -----------------------------
  148.  
  149.  
  150. #!/bin/sh -
  151. PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local
  152. host=`hostname -s`
  153. echo "Subject: $host daily run output"
  154.  
  155. if [ -f /etc/daily.local ];then
  156.     echo ""
  157.     echo "Running daily.local:"
  158.     . /etc/daily.local
  159. fi
  160.  
  161. UMASK=`umask`
  162. umask 077
  163.  
  164. TDIR=/tmp/_daily.$$
  165. if ! mkdir $TDIR ; then
  166.   echo $TDIR already exists
  167.   echo ls -ldgT $TDIR
  168.   exit 1
  169. fi
  170. umask $UMASK
  171.  
  172. TMP=$TDIR/daily
  173.  
  174. trap 'rm -rf $TDIR' 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15
  175.  
  176. echo ""
  177. echo "NOT Removing scratch and junk files."
  178.  
  179. find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
  180.      -o -fstype kernfs -o -fstype procfs \) -a -prune -o \
  181.      -name 'lost+found' -a -prune -o \
  182.      -name '*.core' -a -print > $TMP
  183.  
  184. if egrep -q '\.core$' $TMP; then
  185.     echo ""
  186.     echo "Possible core dumps:"
  187.     egrep '\.core$' $TMP
  188.  
  189. fi
  190.  
  191. msgs -c
  192.  
  193. if [ -f /etc/news.expire ]; then
  194.      /etc/news.expire
  195. fi
  196.  
  197. if [ -f /var/account/acct ]; then
  198.      echo "" ;
  199.      echo "Purging accounting records:" ;
  200.      mv /var/account/acct.2 /var/account/acct.3 ;
  201.      mv /var/account/acct.1 /var/account/acct.2 ;
  202.      mv /var/account/acct.0 /var/account/acct.1 ;
  203.      cp /var/account/acct /var/account/acct.0 ;
  204.      sa -sq ;
  205. fi
  206.  
  207. echo ""
  208. if [ -d /var/yp/binding -a ! -d /var/yp/`domainname` ]; then
  209.      echo "Not running calendar, (yp client)."
  210. else
  211.      echo "Running calendar."
  212.      calendar -a
  213. fi
  214.  
  215. # Rotation of mail log now handled automatically by cron and 'newsyslog'
  216.  
  217. if [ -d /var/spool/uucp -a -f /etc/uuclean.daily ]; then
  218.      echo ""
  219.      echo "Cleaning up UUCP:"
  220.      echo /etc/uuclean.daily | su daemon
  221. fi
  222.  
  223. echo ""
  224. echo "Checking subsystem status:"
  225. echo ""
  226. echo "disks:"
  227. df -k
  228. echo ""
  229. dump W
  230. echo ""
  231.  
  232. mailq > $TMP
  233. if ! grep -q "^Mail queue is empty$" $TMP; then
  234.      echo ""
  235.      echo "mail:"
  236.      cat $TMP
  237. fi
  238.  
  239. if [ -d /var/spool/uucp ]; then
  240.      uustat -a > $TMP
  241.      if [ -s $TMP ]; then
  242.      echo ""
  243.      echo "uucp:"
  244.      cat $TMP
  245.      fi
  246. fi
  247.  
  248. echo ""
  249. echo "network:"
  250. netstat -i
  251. echo ""
  252.  
  253. t=/var/rwho/*
  254. if [ "$t" != '/var/rwho/*' ]; then
  255.      ruptime
  256. fi
  257.  
  258. echo ""
  259. echo "NOT checking filesystems."
  260. #echo "Checking filesystems:"
  261. #fsck -n | grep -v '^\*\* Phase'
  262.  
  263. echo ""
  264. if [ -f /etc/Distfile ]; then
  265.      echo "Running rdist:"
  266.      rdist -f /etc/Distfile
  267. fi
  268.  
  269. sh /etc/security 2>&1 | mail -s "$host daily insecurity output" root
  270. #------------------------- cut here -----------------------------
  271.  
  272. Additional Information
  273. ~~~~~~~~~~~~~~~~~~~~~~
  274. You can find Secure Networks papers at ftp://ftp.secnet.com/pub/papers
  275. and advisories at ftp://ftp.secnet.com/pub/advisories
  276.  
  277. If you have questions or comments about this advisory, please contact
  278. David Sacerdote, davids@secnet.com.
  279.  
  280. -----BEGIN PGP PUBLIC KEY BLOCK-----
  281. Version: 2.6.2
  282.  
  283. mQCNAzJ4qJAAAAEEAOgB7mooQ6NgzcUSIehKUufGsyojutC7phVXZ+p8FnHLLZNB
  284. BLQEtj5kmfww2A2pR29q4rgPeqEUOjWPlLNdSLby3NI8yKz1AQSQLHAwIDXt/lku
  285. 8QXClaV6pNIaQSN8cnyyvjH6TYF778yZhYz0mwLqW6dU5whHtP93ojDw1UhtAAUR
  286. tCtEYXZpZCBTYWNlcmRvdGUgPGRhdmlkc0BzaWxlbmNlLnNlY25ldC5jb20+
  287. =LtL9
  288. -----END PGP PUBLIC KEY BLOCK-----
  289.  
  290.  
  291. Copyright Notice
  292. ~~~~~~~~~~~~~~~~
  293. The contents of this advisory are Copyright (C) 1996 Secure Networks Inc, 
  294. and may be distributed freely provided that no fee is charged for
  295. distribution, and proper credit is given.  Source code distributed
  296. with this advisory falls under the following license:
  297.  
  298. Copyright (c) 1989, 1993, 1994
  299.      The Regents of the University of California.  All rights reserved.
  300.  
  301. Redistribution and use in source and binary forms, with or without
  302. modification, are permitted provided that the following conditions
  303. are met:
  304. 1. Redistributions of source code must retain the above copyright
  305.    notice, this list of conditions and the following disclaimer.
  306. 2. Redistributions in binary form must reproduce the above copyright
  307.    notice, this list of conditions and the following disclaimer in the
  308.    documentation and/or other materials provided with the distribution.
  309. 3. All advertising materials mentioning features or use of this software
  310.    must display the following acknowledgement:
  311.      This product includes software developed by the University of
  312.      California, Berkeley and its contributors.
  313. 4. Neither the name of the University nor the names of its contributors
  314.    may be used to endorse or promote products derived from this software
  315.    without specific prior written permission.
  316. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  317. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  318. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  319. ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  320. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  321. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  322. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  323. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  324. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  325. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  326. SUCH DAMAGE.
  327.  
  328.  
  329.  
  330.