Linux Setuid到Perl脚本
我使用的是一个Perl脚本,它从sendmail的MQUE文件夹中删除数据 当我Linux Setuid到Perl脚本,linux,perl,Linux,Perl,我使用的是一个Perl脚本,它从sendmail的MQUE文件夹中删除数据 当我setuid调用该Perl脚本并尝试从用户运行它时,它会抛出以下消息: Insecure dependency in chdir while running setuid at /file/find 如何解决此问题并使用根权限成功运行脚本 !/usr/bin/perl use strict; my $qtool = "/usr/local/bin/qtool.pl"; my $mqueue_directory
setuid
调用该Perl脚本并尝试从用户运行它时,它会抛出以下消息:
Insecure dependency in chdir while running setuid at /file/find
如何解决此问题并使用根权限成功运行脚本
!/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";
/usr/bin/perl
严格使用;
my$qtool=“/usr/local/bin/qtool.pl”;
我的$mqueue_目录=“/var/spool/mqueue”;
my$messages_removed=0;
使用File::Find;
#递归查找$MQUE_目录中的所有文件和目录
查找(\&wanted,$mqueue\u目录);
通缉犯{
#这是qf*文件吗?
if(/^qf(\w{14})/){
我的$qf\u文件=$\u;
我的$queue_id=$1;
我的$deferred=0;
我的$from_postmaster=0;
我的$delivery\u failure=0;
我的$double_bounce=0;
打开(QF_文件,$_);
while(){
如果(/^MDeferred/),则$deferred=1;
$from_postmaster=1如果(/^S$/);
$delivery_failure=1,如果\
(/^H\?\?主题:传递失败:(用户|收件人)/);
如果($延迟和$从邮政局长和$交付失败){
$double_bounce=1;
最后;
}
}
关闭(QF_文件);
如果($double_bounce){
打印“正在删除$queue\u id…\n”;
系统“$qtool”、“-d”、$qf_文件;
$messages_removed++;
}
}
}
打印“\n$messages\u removed total\“double bounce\”已删除邮件”;
打印“邮件队列。\n”;
“不安全的依赖关系”是一种污点
东西:
正在强制执行污染,因为您已运行脚本setuid。您需要将untaint
指定为File::Find的%选项键:
您还应该查看File::Find的POD中的
untaint\u模式。您应该构建一个程序包装器。在几乎任何unix系统上,脚本都无法通过SetUID位获得root权限。您可以在这里找到一些有用的示例谢谢Goldilocks,但我仍然理解在哪里使用untaint,以及如何在我的代码中帮助Goldilocks提供了一个解决方案。另外,避免使用setuid可执行文件,并使用sudo
。您的审计人员会欣赏您的安全性,当某些软件拒绝获取升级权限时,您也不会感到惊讶,因为该过程是RUID!=EUID.构建包装器是什么?它是ant,它的名字是‘sudo’:P配置它是显而易见的。
my %options = (
wanted => \&wanted,
untaint => 1
);
find(\%options, $mqueue_directory);