我收到了 WHM 實例發送的一些警報訊息,警告我的影子檔案權限無效。然而,實際的權限(0400
)似乎是正確的,而且它報告的權限似乎非常大......數字?
從今天早上開始:
/etc/shadow has non default permissions. Expected: 2401450770, Actual: 0400.
Review the permissions on /etc/shadow to ensure they are safe
從今天晚上開始:
/etc/shadow has non default permissions. Expected: 3377602730, Actual: 0400.
Review the permissions on /etc/shadow to ensure they are safe
這些報告的權限意味著什麼,為什麼 WHM 不滿意0400
?
答案1
看源碼。嘗試設定權限 0200 或 0600。
sub _check_for_unsafe_permissions {
my ($self) = @_;
my %test_files = (
'/etc/shadow' => { 'perms' => [ 0200, 0600 ], 'uid' => 0, 'gid' => 0 },
'/etc/passwd' => { 'perms' => [0644], 'uid' => 0, 'gid' => 0 }
);
for my $file ( keys %test_files ) {
my $expected_attributes = $test_files{$file};
my ( $current_mode, $uid, $gid ) = ( stat($file) )[ 2, 4, 5 ];
my $perms_ok = 0;
foreach my $allowed_perms ( @{ $expected_attributes->{'perms'} } ) {
if ( ( $allowed_perms & 07777 ) == ( $current_mode & 07777 ) ) {
$perms_ok = 1;
last;
}
}
if ( !$perms_ok ) {
my $expected_mode = sprintf( "%04o", $expected_attributes->{'perms'} );
my $actual_mode = sprintf( "%04o", $current_mode & 07777 );
$self->add_warn_advice(
'text' => ["$file has non default permissions. Expected: $expected_mode, Actual: $actual_mode."],
'suggestion' => ["Review the permissions on $file to ensure they are safe"]
);
}
if ( $uid != $expected_attributes->{'uid'} or $gid != $expected_attributes->{'gid'} ) {
$self->add_warn_advice(
'text' => ["$file has non root user and/or group"],
'suggestion' => ["Review the ownership permissions
預期的權限輸出應該是 4 個字元的八進位格式的值,但看起來 Perl 的 sprint 函數未正確顯示顯示垃圾的多維數組值。
來源(安全顧問位於 WHM 的安全中心 - Cpanel) https://github.com/bdraco/addon_securityadvisor https://github.com/bdraco/addon_securityadvisor/blob/master/pkg/Cpanel/Security/Advisor/Assessors/Permissions.pm