Bonjour,
Ayant des petits problèmes de gestion de dictionnaires
(dans le cadre des
bruteforces ), j'ai décidé de faire un petit script en Perl afin de pouvoir ajouter des mots dans un dictionnaire à partir d'un autre fichier
.
Cela permet de créer un plus gros dictionnaire(et plus complet) à partir de tout ceux que vous pouvez trouver a droite et a gauche en evitant les doublons dus au copié collé.
C'est la première fois que je touche a du perl donc si vous avez des idées d'amélioration , je suis tout à fait preneur
.
Je n'ai pas fini encore le code , je vais ajouter une fonction pour trier le dictionnaire par ordre alphabétique ou par taille. Et je dois aussi implémenter la gestion des Erreurs.La suite sera posté quand elle sera fini(Mais la pour le moment c'est deux semaines d'exams qui m'attende ...).
Après une journée à s'arracher les cheveux à cause d'une erreur d'algo ca donne :
#!/usr/bin/perl
#dictionnary_update.py by MrStotch
use strict;
my $start_time=time();
my $end_time;
my $run_time;
#if no argument has been passed in the commande line
if(!$ARGV[0])
{
print "you have to enter files\n" ;
print "enter \"--help\" for more help about the prog\n";
}
#if the user
elsif($ARGV[0] eq '--help' || $ARGV[0] eq '-h' || $ARGV[0] eq '?'){
print "Usage:\n";
print "\t -u is to update a file\n";
print "\tdictionary tools original_dictionary_path new_dictionary_path\n\n";
print "\t-d to dectect the double in the file\n";
print "\tdictionary_tools -d file\n\n";
print "\t-s to sort the words in the file\n";
print "\tdictionary_tool -s file\n\n";
}
#this part of the programme will check if a word
#is two times in the dictionary
#Permit to sort the dictionnary
elsif($ARGV[0] eq '-s')
{
print "Sorting the dictionary\n";
print "To complete\n";
}
elsif($ARGV[0] eq '-u'){
#$old_diction take the value of the second arg that is the
#name of the dictionary which will be update
my $old_diction=$ARGV[1];
#$new_diction will take the value of the third arg that is
#the name of the dictionary which contains the new passwords
my $new_diction=$ARGV[2];
open (OLDDICO, "$old_diction");
open (NEWDICO, $new_diction);
open (OLDDICOWRITE, ">>$old_diction");
#initializasion of $lineold and $linenew
my $lineold="";
my $linenew="";
#this var is used to know if the word is or not
#in the dictionnary
#if it is find $find=1 if not $find=0
my $find=0;
print "\n\nChecking if new passwords from $old_diction have be added to $new_diction\n";
#wile we can read the diction with the new passwords
while(<NEWDICO>)
{
#initialize the value of $find at each start of the loop
$find=0;
#divide the file in line
chomp;
#$linenew take the value of the current line
$linenew=$_;
#while we can read the file
while(<OLDDICO>)
{
#divide the file in line
chomp;
#$lineold take the value of the current line
$lineold=$_;
#if the ẁord is find in the dictionnary
if ($linenew eq $lineold)
{
#$find change its statut to true because the word
#has benn found
$find=1;
#break the loop
last;
}
}
#if the word is not find it will be added
#at the end of the file
if($find==0)
{
#update the dictio by writing the word
#at the end of the dictionnary
print OLDDICOWRITE "$linenew\n";
print "----> \"$linenew\" has been added\n";
}
#Go back to the start of the dictionnary
seek (OLDDICO,0,0);
}
#Close all files used
close (OLDDICOWRITE);
close(OLDDICO);
close(NEWDICO);
$end_time=time();
$run_time=$end_time-$start_time;
print "the running time =>$run_time second\n";
}
Pour l'utilisation , il suffit de faire:
./dictionary_update.pl -u "nom_du_dictionnaire_a mettre_a_jour" "nom_du_dictionnaire_que_vous venez_de_trouver"
Les mots de passes seront ajoutés à la fin de votre fichier.