1

root が所有し、setuid を持つ Perl スクリプトがあります。

このスクリプトでは、引数として渡されたファイルの所有者を変更しています。

しかし、このスクリプトを実行すると、

chown: changing ownership of `file': Operation not permitted

setuid が有効になっている場合、デフォルトで suidperl で実行されるスクリプトを誰かが教えてくれました。

しかし、私の場合はそうではないと思います。

誰でもこの問題で私を助けることができますか? Debian wheezy を使用しています。Perl のバージョンは 5.14.2 です。私は試した

apt-get install perl-suid

しかし、うまくいきませんでした。

apt-cache search perl

Perl の suid に関連する候補はありませんでした。

これは私のPerlプログラムです

#! /usr/bin/perl -T

use Cwd 'abs_path';

sub check_path {
  my $file = $_[0];

  $file = abs_path($file);
  if ($file =~ /^\/home\/abc\/dir1\//) {
    return 1;
  }
  else {
    return 0;
    print("You can only update permissions for files inside /home/abc/dir1/ directory\n");
  }
}

if (@ARGV == 1) {
  if (&check_path($ARGV[0]) == 1) {
    $ENV{PATH} = "/bin:/usr/bin";
    my $command = "chown abc:abc " . $ARGV[0];
    if ($command =~ /^(.*)$/) {
      $command = $1;
    }

    $result = `$command`;
  }
}
elsif ((@ARGV == 2) && ($ARGV[0] eq "-R")) {
  if (&check_path($ARGV[1]) == 1) {
    $ENV{PATH} = "/bin:/usr/bin";
    my $command = "chown -R abc:abc " . $ARGV[1];
    if ($command =~ /^(.*)$/) {
      $command = $1;
    }
    $result = `$command`;
  }
}
else {
  print("Sorry wrong syntax. Syntax: perl /home/abc/sbin/update_permission.pl [-R] file_path");
}
4

1 に答える 1

-1

おそらく手遅れですが、同じ問題があり、次の単純な C ラッパーを使用しました (恥知らずにhttp://www.blyberg.net/downloads/suid-wrapper.cから取得):

#include <unistd.h>
#include <errno.h>

main( int argc, char ** argv, char ** envp )
{
    if( setgid(getegid()) ) perror( "setgid" );
    if( setuid(geteuid()) ) perror( "setuid" );
    envp = 0; /* blocks IFS attack on non-bash shells */
    system( "/path/to/bash/script", argv, envp );
    perror( argv[0] );
    return errno;
}

C コードのパスをスクリプトへのパスに置き換え、次のようにコンパイルします。

gcc -o suid-wrapper suid-wrapper.c

で権限を設定します

chmod 6755 suid-wrapper

suidperl はもはやオプションではなく、perl 5.12 で置き換えなしで削除されました (perl5120delta、つまりhttp://search.cpan.org/~shay/perl-5.20.2/pod/perl5120delta.podを参照)。

于 2015-05-04T15:20:44.327 に答える