home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Texts / klogd-1_3-22-bof.txt < prev    next >
Text File  |  1999-11-04  |  3KB  |  78 lines

  1. Date: Thu, 10 Sep 1998 10:26:06 +0200
  2. From: Michal Zalewski <lcamtuf@IDS.PL>
  3. To: BUGTRAQ@netspace.org
  4. Subject: [Linux] klogd 1.3-22 buffer overflow
  5.  
  6. Good morning,
  7.  
  8. This time - buffer overflow in Linux klogd daemon from sysklogd-1.3
  9. package (up to release 22 - affects Red Hat 5.x and Slackware 3.x, no data
  10. about other distributions).
  11.  
  12. The problem:
  13.  
  14. Kernel messages are stored in 4 kB cyclic printk ring. Klogd reads this
  15. buffer using /proc/kmsg to 4 kB long buffer, that's good. But then, data
  16. is split into lines, by copying data until '\n' is reached. What a pity,
  17. line buffer is only 1 kB long - sometimes, it's not enough... Exploitable?
  18. Could be...
  19.  
  20. Impact:
  21.  
  22. To exploit this security hole, we have to generate very long kernel
  23. message (or a lot of short messages with no '\n' inside). There are two
  24. potential ways of doing this:
  25.  
  26. a) In kernel source (or any of installed modules), find printk not
  27.    terminated with '\n'. There are some old, obscure messages both in
  28.    2.0.xx and 2.1.xxx. Yep, but what now? You have to generate it :-S
  29.    It's especially easy when poking with strange network packets
  30.    (so it's possible to perform remote DoS attack). Unfortunately, DoS
  31.    if probably all you can do - enjoy SEGV in klogd daemon, or (better?),
  32.    by overwriting fd to /proc/kmsg lyingo on the stack, increase LA and
  33.    generate enormous amount of error messages like 'Cannot read /proc
  34.    filesystem', apparently from kernel.
  35.  
  36. b) ...or, in kernel (2.1.xxx is more interesting), locate any printk with
  37.    %s in format string, where substituted string depends in some way on
  38.    luser (process/filename?). Then, you should be able to parse arbitrary
  39.    shellcode into buffer, obtaining root privledges.
  40.  
  41. Solution:
  42.  
  43. In klog.c, at the beginning, there are two '#define's. First one is
  44. responsible for main buffer size - don't change it, 4096 should be ok. The
  45. next one is line buffer size - hmm, replace 1024 with 4096, for example...
  46. Or, better, implement some range checking ;>
  47.  
  48. Quick vunerability test:
  49.  
  50. -- gcc -c -O3 test.c; insmod test; rmmod test --
  51. #define MODULE
  52. #define __KERNEL__
  53.  
  54. #include <linux/module.h>
  55. #include <linux/kernel.h>
  56. #include <linux/types.h>
  57. #include <linux/string.h>
  58. #include <linux/malloc.h>
  59. #include <asm/unistd.h>
  60. #include <linux/version.h>
  61. #include <asm/string.h>
  62.  
  63. int init_module(void) {
  64.   printk("INSERT_ABOUT_2000_BYTES_OF_JUNK_HERE\n"); return 0;
  65. }
  66.  
  67. void cleanup_module(void) {}
  68. --
  69.  
  70. Modify this source by increasing amount of junk after printk, compile,
  71. insmod and watch out what happened to klogd.
  72.  
  73. _______________________________________________________________________
  74. Michal Zalewski [lcamtuf@ids.pl] [ENSI / marchew] [dione.ids.pl SYSADM]
  75. [http://linux.lepszy.od.kobiety.pl/~lcamtuf/] <=--=> bash$ :(){ :|:&};:
  76. [voice phone: +48 (0) 22 813 25 86] ? [pager (MetroBip): 0 642 222 813]
  77. Iterowac jest rzecza ludzka, wykonywac rekursywnie - boska [P. Deutsch]
  78.