我使用的是一个Perl脚本,它从sendmail的mqueue文件夹中删除数据。
当我通过setuid连接到该Perl脚本并试图从用户运行它时,它抛出以下消息:
Insecure dependency in chdir while running setuid at /file/find如何解决这个问题,并以root权限成功运行脚本?
!/usr/bin/perl
use strict;
my $qtool = "/usr/local/bin/qtool.pl";
my $mqueue_directory = "/var/spool/mqueue";
my $messages_removed = 0;
use File::Find;
# Recursively find all files and directories in $mqueue_directory
find(\&wanted, $mqueue_directory);
sub wanted {
# Is this a qf* file?
if ( /^qf(\w{14})/ ) {
my $qf_file = $_;
my $queue_id = $1;
my $deferred = 0;
my $from_postmaster = 0;
my $delivery_failure = 0;
my $double_bounce = 0;
open (QF_FILE, $_);
while(<QF_FILE>) {
$deferred = 1 if ( /^MDeferred/ );
$from_postmaster = 1 if ( /^S<>$/ );
$delivery_failure = 1 if \
( /^H\?\?Subject: DELIVERY FAILURE: (User|Recipient)/ );
if ( $deferred && $from_postmaster && $delivery_failure ) {
$double_bounce = 1;
last;
}
}
close (QF_FILE);
if ($double_bounce) {
print "Removing $queue_id...\n";
system "$qtool", "-d", $qf_file;
$messages_removed++;
}
}
}
print "\n$messages_removed total \"double bounce\" message(s) removed from ";
print "mail queue.\n";发布于 2012-05-10 17:35:20
“不安全的依赖”是一个Taint的东西:http://perldoc.perl.org/perlsec.html。
因为您已经运行了脚本setuid,所以正在强制执行污点。您需要将untaint指定为文件::Find:的%Option键。
http://metacpan.org/pod/File::Find
my %options = (
wanted => \&wanted,
untaint => 1
);
find(\%options, $mqueue_directory);您还应该查看File::Find的POD中的untaint_pattern。
发布于 2012-05-10 19:33:11
您应该构建一个程序包装器。在几乎所有的unix系统上,脚本永远不能通过SetUID位获得根用户权限。你可以在这里找到一些有用的例子http://www.tuxation.com/setuid-on-shell-scripts.html
https://stackoverflow.com/questions/10531142
复制相似问题