[UNIX] Options Parsing Tool Shared Library Vulnerability
support_at_securiteam.com
Date: 04/28/03
- Previous message: support_at_securiteam.com: "[NT] JBoot Password Bypassing Vulnerability"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
To: list@securiteam.com Date: 28 Apr 2003 11:19:40 +0200
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
In the US?
Contact Beyond Security at our new California office
housewarming rates on automated network vulnerability
scanning. We also welcome ISPs and other resellers!
Please contact us at: 323-882-8286 or ussales@beyondsecurity.com
- - - - - - - - -
Options Parsing Tool Shared Library Vulnerability
------------------------------------------------------------------------
SUMMARY
<http://nis-www.lanl.gov/~jt/Software/> OPT is "a subroutine library
which facilitates the convenient input of parameters to a C or C++
program". An error message displayed by the program contains an
exploitable buffer overflow allowing local attackers to execute arbitrary
code.
DETAILS
Vulnerable systems:
* OPT version 3.18 and prior
Immune systems:
* OPT version 3.19
The error messages in opt pass through one of several functions in order
to print the error to the screen. Either opt_warn_1(), opt_warn_2(),
opt_warn_3(), opt_fatal_1(), opt_fatal_2(), or opt_fatal_3() will be used
when an error occurs. Several similar functions could cause issues with
buffer overflows.
This simple test will show the problems associated with using <= opt-3.18
[dotslash@vegeta test]$ cat > test.c
main(int *argc, char **argv)
{
/* use lubc atoi() */
int x = atoi(argv[1]);
printf("atoi(): %i\n", x);
/* use OPT opt_atoi() */
int y = opt_atoi(argv[2]); printf("opt_atoi(): %i\n", y);
}
[dotslash@vegeta test]$ cc -o test test.c ../src/libopt.a
[dotslash@vegeta test]$ ./test 1 2
atoi(): 1
opt_atoi(): 2
[dotslash@vegeta test]$ ./test `perl -e 'print "A" x 986'` B
atoi(): 0
OPT Warning: String [B] is not a valid integer, will use [0]
opt_atoi(): 0
[dotslash@vegeta test]$ ./test A `perl -e 'print "A" x 986'`
atoi(): 0
OPT Warning: String
[AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
is not a valid integer, will use [0]
opt_atoi(): 0
Segmentation fault
strace tells us that we are able to overwrite the EIP.
[41414141] --- SIGSEGV (Segmentation fault) @ 0 (0) ---
This occurs because of the following code is triggered when reading input
from the user.
long
opt_atoi(char *s)
{
int valid;
long x;
x = (long)atof(s); /* Call atof() whether or not string is valid,
* because some strings, eg '15x' can still be
* interpreted as numeric. But give a warning
* unless the string really is valid
*/
valid = opt_isvalidnumber(s);
if (!valid || (valid & OPT_NUM_FLOAT)) {
opt_warn_2("String [%s] is not a valid integer, will use [%ld]",s,x);
}
return x;
}
This particular segfault was caused by the opt_warn_2 definition in
opt_p.h. You can see that the data passed on by the user is used in a
sprintf() into a static sized buffer.
#define OPT_ERRMAXSTRLEN 1024 /* shouldn't be fixed length, but it is! */
..
#define opt_warn_2(fmt,var1,var2) do { \
char gstr[OPT_ERRMAXSTRLEN]; sprintf(gstr,fmt,var1,var2); \
opt_warning(gstr); } while(0)
A diff with the new version shows the implementation of snprintf as a
valid fix.
< char gstr[OPT_ERRMAXSTRLEN]; sprintf(gstr,fmt,var1,var2,var3); \
---
> char gstr[OPT_ERRMAXSTRLEN]; \
> opt_snprintf_3(gstr,OPT_ERRMAXSTRLEN,fmt,var1,var2,var3); \
A quick test compile against the new version of libopt.a appears to take
care of the problem.
[dotslash@vegeta test]$ pwd
/home/dotslash/opt/opt-3.19/test
[dotslash@vegeta test]$ cc -o test test.c ../src/libopt.a
[dotslash@vegeta test]$ ltrace ./test A `perl -e 'print "A" x 1986'`
..
snprintf("String [AAAAAAAAAAAAAAAAAAAAAAAA"..., 1024, "String [%s] is not
a valid integ"...
Patch or Workaround:
Re-link applications that use libopt.a against the new version of opt at
<http://nis-www.lanl.gov/~jt/Software/opt/opt-3.19.tar.gz>
http://nis-www.lanl.gov/~jt/Software/opt/opt-3.19.tar.gz
Vendor Status:
Author has responded and applied a fix to the problem.
ADDITIONAL INFORMATION
The information has been provided by <mailto:research@secnetops.com>
Strategic Reconnaissance Team.
========================================
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.
- Previous message: support_at_securiteam.com: "[NT] JBoot Password Bypassing Vulnerability"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]