mirror of
https://github.com/ovh/the-bastion.git
synced 2024-11-15 12:46:51 +08:00
546 lines
23 KiB
Perl
546 lines
23 KiB
Perl
|
#! /usr/bin/env perl
|
||
|
# vim: set filetype=perl ts=4 sw=4 sts=4 et:
|
||
|
use common::sense;
|
||
|
use Term::ANSIColor;
|
||
|
use IPC::Open2;
|
||
|
use MIME::Base64;
|
||
|
use Getopt::Long;
|
||
|
use File::Temp qw{ tempfile };
|
||
|
|
||
|
my $hideok = 0;
|
||
|
|
||
|
sub ko ## no critic (RequireArgUnpacking)
|
||
|
{
|
||
|
print colored("[ERR!] " . $_[0] . "\n", "red");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
sub ok ## no critic (RequireArgUnpacking)
|
||
|
{
|
||
|
$hideok and return 1;
|
||
|
print colored("[ ok ] " . $_[0] . "\n", "green");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
sub wrn ## no critic (RequireArgUnpacking)
|
||
|
{
|
||
|
print colored("[warn] " . $_[0] . "\n", "yellow");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
sub inf ## no critic (RequireArgUnpacking)
|
||
|
{
|
||
|
print colored("[info] " . $_[0] . "\n", "blue");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
my $generate_moduli;
|
||
|
GetOptions(
|
||
|
'hide-ok' => \$hideok,
|
||
|
'generate-moduli=i', \$generate_moduli
|
||
|
);
|
||
|
|
||
|
my (%h, %d);
|
||
|
|
||
|
# %h contains the sshd configuration for this host
|
||
|
# %d contains the default sshd configuration of this sshd version
|
||
|
|
||
|
my $fh_cmd;
|
||
|
open($fh_cmd, '-|', '/usr/sbin/sshd -T 2>/dev/null') or die($!);
|
||
|
while (<$fh_cmd>) {
|
||
|
/^(\S+)\s+(.+)$/ and push @{$h{$1}}, $2;
|
||
|
}
|
||
|
if (not keys %h) {
|
||
|
|
||
|
# newer openssh versions need some context to give their config
|
||
|
open($fh_cmd, '-|', '/usr/sbin/sshd -T -C user=root -C host=localhost -C addr=localhost 2>/dev/null') or die($!);
|
||
|
while (<$fh_cmd>) {
|
||
|
/^(\S+)\s+(.+)$/ and push @{$h{$1}}, $2;
|
||
|
}
|
||
|
}
|
||
|
close($fh_cmd);
|
||
|
open($fh_cmd, '-|', "/usr/sbin/sshd -T -f /dev/null 2>/dev/null") or die($!);
|
||
|
while (<$fh_cmd>) {
|
||
|
/^(\S+)\s+(.+)$/ and push @{$d{$1}}, $2;
|
||
|
}
|
||
|
close($fh_cmd);
|
||
|
|
||
|
# hacky way to find out ciphers/kex/macs on old sshd versions
|
||
|
if (not $d{ciphers} or not $d{kexalgorithms} or not $d{macs}) {
|
||
|
|
||
|
# hacky way
|
||
|
if (!open($fh_cmd, '-|', "strings /usr/sbin/sshd")) {
|
||
|
ko "Error trying to get the ciphers/kexs/macs list ($!)";
|
||
|
}
|
||
|
else {
|
||
|
my ($ciphers, $kexalgorithms, $macs);
|
||
|
while (<$fh_cmd>) {
|
||
|
/arcfour128,/ and $ciphers = $_;
|
||
|
/mac-sha1,/ and $macs = $_;
|
||
|
/diffie-hellman.*,.*diffie-hellman/ and $kexalgorithms = $_;
|
||
|
}
|
||
|
close($fh_cmd);
|
||
|
chomp($ciphers, $macs, $kexalgorithms);
|
||
|
$d{ciphers} or $d{ciphers}[0] = $ciphers;
|
||
|
$h{ciphers} or $h{ciphers}[0] = $ciphers;
|
||
|
$d{macs} or $d{macs}[0] = $macs;
|
||
|
$h{macs} or $h{macs}[0] = $macs;
|
||
|
$d{kexalgorithms} or $d{kexalgorithms}[0] = $kexalgorithms;
|
||
|
$h{kexalgorithms} or $h{kexalgorithms}[0] = $kexalgorithms;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
my @myciphers = split /,/, $h{ciphers}[0];
|
||
|
my %ciphers = (
|
||
|
"3des-cbc" => 1,
|
||
|
"blowfish-cbc" => 1,
|
||
|
"cast128-cbc" => 1,
|
||
|
"arcfour" => 1,
|
||
|
"arcfour128" => 1,
|
||
|
"arcfour256" => 1,
|
||
|
"aes128-cbc" => 2,
|
||
|
"aes192-cbc" => 2,
|
||
|
"aes256-cbc" => 2,
|
||
|
"rijndael-cbc\@lysator.liu.se" => 2,
|
||
|
"aes128-ctr" => 3,
|
||
|
"aes192-ctr" => 3,
|
||
|
"aes256-ctr" => 3,
|
||
|
"aes128-gcm\@openssh.com" => 3,
|
||
|
"aes256-gcm\@openssh.com" => 3,
|
||
|
"chacha20-poly1305\@openssh.com" => 3,
|
||
|
);
|
||
|
my %list;
|
||
|
foreach my $cipher (split /,/, $d{ciphers}[0]) {
|
||
|
if ($ciphers{$cipher} == 1) {
|
||
|
push @{$list{((grep { $cipher eq $_ } @myciphers) ? 'weakon' : 'weakoff')}}, $cipher;
|
||
|
}
|
||
|
elsif ($ciphers{$cipher} == 2) {
|
||
|
push @{$list{((grep { $cipher eq $_ } @myciphers) ? 'mediumon' : 'mediumoff')}}, $cipher;
|
||
|
}
|
||
|
elsif ($ciphers{$cipher} == 3) {
|
||
|
push @{$list{((grep { $cipher eq $_ } @myciphers) ? 'highon' : 'highoff')}}, $cipher;
|
||
|
}
|
||
|
else { push @{$list{'unknown'}}, $cipher }
|
||
|
}
|
||
|
$list{'weakon'} and wrn "ciphers: found enabled weak ciphers " . join(',', @{$list{'weakon'}});
|
||
|
$list{'weakoff'} and ok "ciphers: found disabled weak ciphers " . join(',', @{$list{'weakoff'}});
|
||
|
$list{'mediumon'} and ok "ciphers: found enabled medium-grade ciphers " . join(',', @{$list{'mediumon'}});
|
||
|
$list{'mediumoff'} and ok "ciphers: found disabled medium-grade ciphers " . join(',', @{$list{'mediumoff'}});
|
||
|
$list{'highon'} and ok "ciphers: found enabled high-grade ciphers " . join(',', @{$list{'highon'}});
|
||
|
$list{'highoff'} and wrn "ciphers: found disabled high-grade ciphers " . join(',', @{$list{'highoff'}});
|
||
|
|
||
|
my @mymacs = split /,/, $h{macs}[0];
|
||
|
my %macs = (
|
||
|
"hmac-sha1" => 1,
|
||
|
"hmac-sha1-96" => 1,
|
||
|
"hmac-sha2-256" => 2,
|
||
|
"hmac-sha2-512" => 2,
|
||
|
"hmac-md5" => 1,
|
||
|
"hmac-md5-96" => 1,
|
||
|
"hmac-ripemd160" => 1,
|
||
|
"hmac-ripemd160\@openssh.com" => 1,
|
||
|
"umac-64\@openssh.com" => 2,
|
||
|
"umac-128\@openssh.com" => 2,
|
||
|
"hmac-sha1-etm\@openssh.com" => 1,
|
||
|
"hmac-sha1-96-etm\@openssh.com" => 1,
|
||
|
"hmac-sha2-256-etm\@openssh.com" => 3,
|
||
|
"hmac-sha2-512-etm\@openssh.com" => 3,
|
||
|
"hmac-md5-etm\@openssh.com" => 1,
|
||
|
"hmac-md5-96-etm\@openssh.com" => 1,
|
||
|
"hmac-ripemd160-etm\@openssh.com" => 2,
|
||
|
"umac-64-etm\@openssh.com" => 2,
|
||
|
"umac-128-etm\@openssh.com" => 2,
|
||
|
"hmac-sha2-256-96" => 2,
|
||
|
"hmac-sha2-512-96" => 2
|
||
|
);
|
||
|
%list = ();
|
||
|
|
||
|
foreach my $mac (split /,/, $d{macs}[0]) {
|
||
|
if (not exists $macs{$mac}) {
|
||
|
wrn "Unknown mac $mac";
|
||
|
next;
|
||
|
}
|
||
|
if ($macs{$mac} == 1) {
|
||
|
push @{$list{((grep { $mac eq $_ } @mymacs) ? 'weakon' : 'weakoff')}}, $mac;
|
||
|
}
|
||
|
elsif ($macs{$mac} == 2) {
|
||
|
push @{$list{((grep { $mac eq $_ } @mymacs) ? 'mediumon' : 'mediumoff')}}, $mac;
|
||
|
}
|
||
|
elsif ($macs{$mac} == 3) {
|
||
|
push @{$list{((grep { $mac eq $_ } @mymacs) ? 'highon' : 'highoff')}}, $mac;
|
||
|
}
|
||
|
else { push @{$list{'unknown'}}, $mac }
|
||
|
}
|
||
|
$list{'weakon'} and wrn "macs: found enabled weak MACs " . join(',', @{$list{'weakon'}});
|
||
|
$list{'weakoff'} and ok "macs: found disabled weak MACs " . join(',', @{$list{'weakoff'}});
|
||
|
$list{'mediumon'} and ok "macs: found enabled medium-grade MACs " . join(',', @{$list{'mediumon'}});
|
||
|
$list{'mediumoff'} and ok "macs: found disabled medium-grade MACs " . join(',', @{$list{'mediumoff'}});
|
||
|
$list{'highon'} and ok "macs: found enabled high-grade MACs " . join(',', @{$list{'highon'}});
|
||
|
$list{'highoff'} and wrn "macs: found disabled high-grade MACs " . join(',', @{$list{'highoff'}});
|
||
|
|
||
|
my @mykexs = split /,/, $h{kexalgorithms}[0];
|
||
|
my %kexs = (
|
||
|
"diffie-hellman-group1-sha1" => 1,
|
||
|
"diffie-hellman-group14-sha1" => 1,
|
||
|
"diffie-hellman-group-exchange-sha1" => 1,
|
||
|
"diffie-hellman-group-exchange-sha256" => 3,
|
||
|
"ecdh-sha2-nistp256" => 2,
|
||
|
"ecdh-sha2-nistp384" => 2,
|
||
|
"ecdh-sha2-nistp521" => 2,
|
||
|
"curve25519-sha256\@libssh.org" => 3,
|
||
|
"curve25519-sha256" => 3,
|
||
|
"diffie-hellman-group16-sha512" => 3,
|
||
|
"diffie-hellman-group18-sha512" => 3,
|
||
|
"diffie-hellman-group14-sha256" => 3,
|
||
|
);
|
||
|
%list = ();
|
||
|
|
||
|
foreach my $kex (split /,/, $d{kexalgorithms}[0]) {
|
||
|
if (not exists $kexs{$kex}) {
|
||
|
wrn "Unknown kex $kex";
|
||
|
next;
|
||
|
}
|
||
|
if ($kexs{$kex} == 1) {
|
||
|
push @{$list{((grep { $kex eq $_ } @mykexs) ? 'weakon' : 'weakoff')}}, $kex;
|
||
|
}
|
||
|
elsif ($kexs{$kex} == 2) {
|
||
|
push @{$list{((grep { $kex eq $_ } @mykexs) ? 'mediumon' : 'mediumoff')}}, $kex;
|
||
|
}
|
||
|
elsif ($kexs{$kex} == 3) {
|
||
|
push @{$list{((grep { $kex eq $_ } @mykexs) ? 'highon' : 'highoff')}}, $kex;
|
||
|
}
|
||
|
else { push @{$list{'unknown'}}, $kex }
|
||
|
}
|
||
|
$list{'weakon'} and wrn "kexs: found enabled weak KEXs " . join(',', @{$list{'weakon'}});
|
||
|
$list{'weakoff'} and ok "kexs: found disabled weak KEXs " . join(',', @{$list{'weakoff'}});
|
||
|
$list{'mediumon'} and ok "kexs: found enabled medium-grade KEXs " . join(',', @{$list{'mediumon'}});
|
||
|
$list{'mediumoff'} and ok "kexs: found disabled medium-grade KEXs " . join(',', @{$list{'mediumoff'}});
|
||
|
$list{'highon'} and ok "kexs: found enabled high-grade KEXs " . join(',', @{$list{'highon'}});
|
||
|
$list{'highoff'} and wrn "kexs: found disabled high-grade KEXs " . join(',', @{$list{'highoff'}});
|
||
|
|
||
|
my $hasecdsa = 0;
|
||
|
my $hased25519 = 0;
|
||
|
my $hasrsa = 0;
|
||
|
foreach my $file (@{$h{hostkey}}) {
|
||
|
if (not -e $file) {
|
||
|
ko "hostkey: $file defined in config but not found on disk!";
|
||
|
next;
|
||
|
}
|
||
|
if (!open($fh_cmd, '-|', "ssh-keygen -lf $file.pub")) {
|
||
|
ko "hostkey: $file.pub can't be opened for verification!";
|
||
|
next;
|
||
|
}
|
||
|
my $out = <$fh_cmd>;
|
||
|
close($fh_cmd);
|
||
|
chomp $out;
|
||
|
if (not $out =~ m{^(\d+) .+ \((.+)\)$}) {
|
||
|
ko "hostkey: $file can't be parsed ($out)";
|
||
|
next;
|
||
|
}
|
||
|
my ($size, $algo) = ($1, $2); ## no critic (ProhibitCaptureWithoutTest)
|
||
|
if ($algo eq 'DSA') { ko "hostkey: DSA $size host key found, you should get rid of it" }
|
||
|
elsif ($algo eq 'RSA') {
|
||
|
$size >= 4096 and ok "hostkey: RSA $size host key found";
|
||
|
$size < 4096 and ko "hostkey: RSA $size host key found, this is too small (< 4096)";
|
||
|
$hasrsa = 1;
|
||
|
}
|
||
|
elsif ($algo eq 'ECDSA') {
|
||
|
ok "hostkey: ECDSA $size host key found";
|
||
|
$hasecdsa = 1;
|
||
|
}
|
||
|
elsif ($algo eq 'ED25519') {
|
||
|
ok "hostkey: Ed25519 $size host key found";
|
||
|
$hased25519 = 1;
|
||
|
}
|
||
|
else {
|
||
|
ko "hostkey: Unknown host key found ($file: $out)";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!$hasecdsa) {
|
||
|
if (grep { /_ecdsa_/ } @{$d{'hostkey'}}) {
|
||
|
ok "hostkey: You don't have any ECDSA key, maybe you don't like NIST curves, that's your right!";
|
||
|
}
|
||
|
else {
|
||
|
ok "hostkey: You don't have any ECDSA key (but it's not supported by your SSH)";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!$hased25519) {
|
||
|
if (grep { /_ed25519_/ } @{$d{'hostkey'}}) {
|
||
|
wrn "hostkey: You don't have any Ed25519 key, generate one!";
|
||
|
}
|
||
|
else {
|
||
|
ok "hostkey: You don't have any Ed25519 key (but it's not supported by your SSH)";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$hasrsa || wrn "hostkey: You don't have any RSA key, generate one!";
|
||
|
|
||
|
# loading known moduli
|
||
|
my $delimiterseen = 0;
|
||
|
my @xz;
|
||
|
my %knownmoduli;
|
||
|
my %foundmoduli;
|
||
|
open(my $fh_myself, '<', $0) or die $!;
|
||
|
while (<$fh_myself>) {
|
||
|
chomp;
|
||
|
$delimiterseen and push @xz, $_;
|
||
|
$delimiterseen++ if ($_ eq '__MODULI__');
|
||
|
}
|
||
|
close($fh_myself);
|
||
|
my $decoded = decode_base64(join("\n", @xz));
|
||
|
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'unxz', '-c'); #TODO get rid of this call
|
||
|
print CHLD_IN $decoded;
|
||
|
close(CHLD_IN);
|
||
|
my $rawlist;
|
||
|
while (<CHLD_OUT>) {
|
||
|
$rawlist .= $_;
|
||
|
}
|
||
|
waitpid($pid, 0);
|
||
|
my $child_exit_status = $? >> 8;
|
||
|
if ($child_exit_status != 0) {
|
||
|
ko "moduli: Error getting list of well known moduli";
|
||
|
}
|
||
|
else {
|
||
|
foreach (split /\n/, $rawlist) {
|
||
|
chomp;
|
||
|
$knownmoduli{$_} = 1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# now moduli stuff
|
||
|
if (!open(my $fh_moduli, '<', "/etc/ssh/moduli")) {
|
||
|
ko "Couldn't open /etc/ssh/moduli to check it ($!)";
|
||
|
}
|
||
|
else {
|
||
|
my %moduli;
|
||
|
my $atleast8191 = 0;
|
||
|
while (<$fh_moduli>) {
|
||
|
chomp;
|
||
|
/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ or next; ## no critic (ProhibitUnusedCapture)
|
||
|
push @{$moduli{$5}}, $1;
|
||
|
$foundmoduli{$1} = 1;
|
||
|
}
|
||
|
close($fh_moduli);
|
||
|
foreach my $size (sort keys %moduli) {
|
||
|
my $count = scalar @{$moduli{$size}};
|
||
|
my $nbknown = 0;
|
||
|
foreach my $mod (@{$moduli{$size}}) {
|
||
|
$nbknown++ if exists $knownmoduli{$mod};
|
||
|
}
|
||
|
if ($size < 2047) { ko "moduli: found $count weak moduli of size $size ($nbknown well-known)" }
|
||
|
elsif ($size < 4095) { wrn "moduli: found $count medium moduli of size $size ($nbknown well-known)" }
|
||
|
else { ok "moduli: found $count strong moduli of size $size ($nbknown well-known)" }
|
||
|
$size >= 8191 and $atleast8191++;
|
||
|
}
|
||
|
if (not $atleast8191) {
|
||
|
wrn "moduli: found no moduli of size of at least 8191";
|
||
|
}
|
||
|
my $wellknown = 0;
|
||
|
foreach my $mod (sort keys %foundmoduli) {
|
||
|
exists $knownmoduli{$mod} and $wellknown++;
|
||
|
}
|
||
|
if ($wellknown == 0) {
|
||
|
ok "moduli: None of your moduli is well-known (searched for " . (scalar keys %knownmoduli) . " well-known moduli), nice!";
|
||
|
}
|
||
|
else {
|
||
|
my $nbmod = scalar keys %foundmoduli;
|
||
|
wrn "moduli: Found $wellknown/$nbmod well-known moduli in your file ("
|
||
|
. ($wellknown * 100.0 / $nbmod)
|
||
|
. "%), looked for "
|
||
|
. (scalar keys %knownmoduli)
|
||
|
. " well-known moduli";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub check_config_value {
|
||
|
my $key = shift;
|
||
|
my $default = shift;
|
||
|
my $expected = shift;
|
||
|
|
||
|
my $current_value = $default;
|
||
|
if (exists $h{lc($key)}) {
|
||
|
$current_value = $h{lc($key)}[0];
|
||
|
}
|
||
|
else {
|
||
|
if (open(my $fh_config, '<', '/etc/ssh/sshd_config')) {
|
||
|
while (<$fh_config>) {
|
||
|
chomp;
|
||
|
/^\Q$key \E(.+)$/i or next;
|
||
|
$current_value = $1;
|
||
|
ok "config(debug): parsed from conf $key as '$current_value'";
|
||
|
last;
|
||
|
}
|
||
|
close($fh_config);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ref $expected ne 'ARRAY' and $expected = [$expected];
|
||
|
if (grep { $current_value eq $_ } @$expected) {
|
||
|
ok "config: $key is set to '$current_value'";
|
||
|
}
|
||
|
else {
|
||
|
wrn "config: $key is set to '$current_value', expected one of: " . join(',', @$expected);
|
||
|
}
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
check_config_value 'UsePAM', 'no', [qw{ yes 1 }];
|
||
|
check_config_value 'LoginGraceTime', 120, [(1 .. 120)];
|
||
|
check_config_value 'MaxAuthTries', 6, [(1 .. 15)];
|
||
|
check_config_value 'IgnoreRHosts', 'no', 'yes';
|
||
|
check_config_value 'StrictModes', 'yes', 'yes';
|
||
|
check_config_value 'PermitRootLogin', 'yes', [qw{ no without-password forbid-password }];
|
||
|
check_config_value 'PermitEmptyPasswords', 'no', 'no';
|
||
|
check_config_value 'UsePrivilegeSeparation', 'yes', [qw{ yes sandbox }];
|
||
|
check_config_value 'PermitTunnel', 'yes', [qw{ 0 no }];
|
||
|
check_config_value 'AllowAgentForwarding', 'yes', 'no';
|
||
|
check_config_value 'AllowTcpForwarding', 'yes', 'no';
|
||
|
|
||
|
# check passwords
|
||
|
foreach (qx{passwd -Sa}) ## no critic (ProhibitBacktickOperators)
|
||
|
{
|
||
|
/^(\S+)\s+(\S+)/ or next;
|
||
|
my ($login, $status) = ($1, $2);
|
||
|
if ($status eq "P") {
|
||
|
wrn "passwd: account $login has a usable password! maybe run usermod -L $login";
|
||
|
}
|
||
|
elsif ($status eq "NP") {
|
||
|
wrn "passwd: account $login has an empty password!!! set one or run usermod -L $login";
|
||
|
}
|
||
|
elsif ($status ne "L") {
|
||
|
wrn "passwd: account $login has a weird passwd status ($status)";
|
||
|
}
|
||
|
elsif ($login eq 'root') {
|
||
|
ok "password: account $login has a locked password";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# get a list of valid shells
|
||
|
my %shells;
|
||
|
if (open(my $fh_shells, '<', '/etc/shells')) {
|
||
|
while (<$fh_shells>) {
|
||
|
chomp;
|
||
|
/^#/ and next;
|
||
|
$shells{$_} = 1;
|
||
|
}
|
||
|
close($fh_shells);
|
||
|
}
|
||
|
|
||
|
# then check for ssh keys on valid shells
|
||
|
if (open(my $fh_passwd, '<', '/etc/passwd')) {
|
||
|
while (<$fh_passwd>) {
|
||
|
chomp;
|
||
|
my @tokens = split /:/;
|
||
|
my $shell = $tokens[6];
|
||
|
next unless exists $shells{$shell};
|
||
|
my $login = $tokens[0];
|
||
|
|
||
|
# has a valid shell
|
||
|
my $home = $tokens[5];
|
||
|
foreach my $file ("$home/.ssh/authorized_keys", "$home/.ssh/authorized_keys2") {
|
||
|
next unless -e $file;
|
||
|
if (open(my $fh_auth, '<', $file)) {
|
||
|
while (<$fh_auth>) {
|
||
|
chomp;
|
||
|
/^\s*#/ and next;
|
||
|
/^\s*$/ and next;
|
||
|
my $short = $_;
|
||
|
length($short) > 99 and $short = substr($short, 0, 45) . '...' . substr($short, length($short) - 45);
|
||
|
inf "sshkey: login $login has a shell ($shell) and a key: $short";
|
||
|
}
|
||
|
close($fh_auth);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
close($fh_passwd);
|
||
|
}
|
||
|
|
||
|
# check umask
|
||
|
my $umaskFound = undef;
|
||
|
if (open(my $fh_login, '<', '/etc/login.defs')) {
|
||
|
while (<$fh_login>) {
|
||
|
/^UMASK\s+(.+)/ or next;
|
||
|
if ($1 ne '027' or not defined $umaskFound) {
|
||
|
$umaskFound = $1;
|
||
|
}
|
||
|
}
|
||
|
close($fh_login);
|
||
|
if (not $umaskFound) {
|
||
|
wrn "umask: no value found, expected 027 in /etc/login.defs";
|
||
|
}
|
||
|
elsif ($umaskFound ne '027') {
|
||
|
wrn "umask: bad value found ($umaskFound), need 027 in /etc/login.defs";
|
||
|
}
|
||
|
else {
|
||
|
ok "umask: expected 027 value found";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (open(my $fh_pam, '<', '/etc/pam.d/common-session')) {
|
||
|
my $umaskOk = 0;
|
||
|
while (<$fh_pam>) {
|
||
|
/^\s*session\s+optional\s+pam_umask\.so\s+umask=0?027/ or next;
|
||
|
ok "umask: correct umask found in pam.d";
|
||
|
$umaskOk = 1;
|
||
|
last;
|
||
|
}
|
||
|
close($fh_pam);
|
||
|
if (not $umaskOk) {
|
||
|
wrn "umask: no pam.d umask configuration found or bad one";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (defined $generate_moduli and $generate_moduli > 0) {
|
||
|
my ($fh, $file_unchecked) = tempfile("moduli.unchecked.$generate_moduli.XXXXXX", SUFFIX => '.txt', TMPDIR => 1);
|
||
|
local $SIG{'INT'} = sub { unlink($file_unchecked); };
|
||
|
print "Generating candidates of size $generate_moduli...\n";
|
||
|
system("nice ssh-keygen -G $file_unchecked -b $generate_moduli");
|
||
|
print "Validating generated candidates of size $generate_moduli...\n";
|
||
|
system("nice ssh-keygen -T /tmp/moduli.checked.$generate_moduli.pid$$.txt -f $file_unchecked");
|
||
|
unlink($file_unchecked);
|
||
|
}
|
||
|
|
||
|
__END__
|
||
|
|
||
|
__MODULI__
|
||
|
/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4H38EaRdAAUJiSlag5YALZsrn4vX1kL+swvtsDNqbhi5jgRqer9uFoOL/l1RVa2n1UisIBkstmyQX2e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