首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Setuid到Perl脚本

Setuid到Perl脚本
EN

Stack Overflow用户
提问于 2012-05-10 17:29:22
回答 2查看 3.3K关注 0票数 2

我使用的是一个Perl脚本,它从sendmail的mqueue文件夹中删除数据。

当我通过setuid连接到该Perl脚本并试图从用户运行它时,它抛出以下消息:

代码语言:javascript
复制
Insecure dependency in chdir while running setuid at /file/find

如何解决这个问题,并以root权限成功运行脚本?

代码语言:javascript
复制
!/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";
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-05-10 17:35:20

“不安全的依赖”是一个Taint的东西:http://perldoc.perl.org/perlsec.html

因为您已经运行了脚本setuid,所以正在强制执行污点。您需要将untaint指定为文件::Find:的%Option键。

http://metacpan.org/pod/File::Find

代码语言:javascript
复制
my %options = (
    wanted => \&wanted,
    untaint => 1
);

find(\%options, $mqueue_directory);

您还应该查看File::Find的POD中的untaint_pattern

票数 4
EN

Stack Overflow用户

发布于 2012-05-10 19:33:11

您应该构建一个程序包装器。在几乎所有的unix系统上,脚本永远不能通过SetUID位获得根用户权限。你可以在这里找到一些有用的例子http://www.tuxation.com/setuid-on-shell-scripts.html

票数 -3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10531142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档