"Lying in a featherbed will bring you no fame, nor staying beneath the quilt, and he who uses up his life without achieving fame leaves no more vestige of himself on Earth than smoke in the air or foam upon the water." -Dante Alighieri
Published by: silconsystem, on 2013-05-09 19:55:31
I'm writing a little utitilty in Perl to combine words together to to generate password-like combinations and I'd like to write a bit about it to give a bit back to the community and get some feedback on my programming.
Practical Extraction and Reporting Language is what Perl stands for and its exactly what its good at; doing what-not with text files.
It can be used for many other things aswell and its a very handy language to know if your working with Linux which is the OS I'm using.
I use Vim for small programs and if it gets bigger Padre, a Perl IDE with lots of features and customizable plugins but any text editor will do the trick. For useful Perl tips&tuts go to perlmonks.org
What I want to achieve is a program that can take a dictionary/name file and a list of dates/years and combine them like this: user1957, penguin3104, bob0157, etc...
There's probably hundreds of these programs but its a good exercise to create one step by step.
When the program has generated thousands of combinations they can be used for creating hashes with coWPAtty/genpmk , drtgen/drcrack , Cain&Abel or good-old brute-force cracking.
the user should be able to input his name/dictionary, his year/date list, give a maximum value for results and a filename and a location to store the result.
also I'd like to add an option to weed out dictionary/names that have less than 4 and more then 8 or maybe 10 letters.
The ingredients for this program is a dictionary, this we can find easily in Linux by opening a terminal and issuing the 'whereis' command followed by dict which we want to find, in my case it resides here: /usr/share/dict, here I have: american-english and british-english so there's plenty of words to play around with. a list of names we have to google for.
You will probably find a lot of files containing the type of passwords I want to generate with this program aswell but where's the fun in that ??
First I want to make a list with years that you usually find in a datepicker, this spans some 100 years normally but it could be that someone has a password like 'future2030' so I want control over these numbers.
perl has a great feature to populate arrays, if we would make this script:
CODE :
#!/usr/bin/perl
@yearArray = (1900..2000);
print @yearArray;
perl will output this:
1900190119021903.(all the rest).2000
This output is not very handy for the program since its just a huge number so I want it formatted, for this we could add a delimiter by using 'join':
CODE :
#!/usr/bin/perl
@yearArray = (1900..2000);
# followed by the join keyword is our delimiter in single quotes
my $textFormat = join ' ', @yearArray;
print $textformat;
Now the script outputs this:
1900 1901 1902 1903 1904 ... 2000
Thats already better but I want every number on another line, for this we can use 'map' where I can use $_ followed by a delimiter of my choice to get the output I want:
CODE :
#!/usr/bin/perl
@yearArray = (1900..2000);
# now I've added map with qq option wich adds a newline as delimiter
my $textFormat = join ' ', map {qq/$_\n/} @yearArray;
print $textformat;
Now I've got the proper formatting and I want to write and create a textfile, I'll create a folder in the same directory as my program (or save in the same directory). There have to be read&write permissions on the directory aswell or writing will fail. In the terminal go back one directory (../) and use 'ls -la' to see if you got rw for each group, if not use (sudo) chmod 666 on the directory your program is in.
Now we will add this to the program:
CODE :
#!/usr/bin/perl
@yearArray = (1900..2000);
my $textFormat = join ' ', @yearArray;
# create a file location
my $file = "files/yearlist.txt";
# write to the file or die on error
unless(open FILE, '>' .$file)
{
# die or error
die "\nUnable to create $file: $!\n";
}
# and write it to file
print FILE $textFormat;
Thats it !! Before I said I wanted to have some control over the numbers and the filenames so I can make more combinations so here is the final code with some comments:
CODE :
#!/usr/bin/perl
# yearlist utility, by R. van Ardenne
# NOTE: I dont use strict here since it will give some errors
# NOTE: I do use warnings in case there is a slipup somewhere
use warnings;
# promt user
print "Yearlist generator, for HackThisSite.\n"
print "This program generates a list of years with user input";
print "Have fun !!\n";
# I've used sleep() to make the program a bit nicer, just a detail though
sleep(1);
# now I get the variables by user input
# NOTE: use chomp to get rid of any trailing nasties like a newline character
# http://perldoc.perl.org/functions/chomp.html
print "Please enter the year to start with: ";
my $startYear = <STDIN>;
chomp $startYear;
print "Please enter the end year: ";
my $endYear = <STDIN>;
chomp $endYear;
print "Enter the filename without extension: ";
my $fileName = <STDIN>;
chomp SfileName;
# now I populate the array with the given variables
@yearRange = ($startYear..$endYear);
print "populating array...\n";
sleep(1);
# format the output using join and map
my $textFormat = join ' ', map {qq/$_\n/} @yearRange;
print "formatting output...\n";
sleep(1);
# create the file (the directory is optional and changable offcourse)
my $file = "file/$fileName.txt";
print "creating file...\n";
sleep(1);
# open the file
unless(open FILE, '>' .$file)
{
# die on error ($! gives us info on the error)
die "\nUnable to create file: $!\n";
}
# write to the file
print FILE $textFormat;
print "writing to file...\n\n";
sleep(1);
close FILE;
print "file created !\n";
sleep(1);
exit 1;
And thats that, a fully functioning little Perl utility to generate sequencial numbers from user input, creating and writing it to file. This is a very simple program, and I'd like to extend it a bit further later so it can create dates in DDMM format aswell and write about weeding out a dictionary file for useful password candidates and concatinating strings to create new words.
I hope people had fun reading and will come back for the next part.
Cheers, Rob
Cast your vote on this article 10 - Highest, 1 - Lowest
Comments: Published: 2 comments.
HackThisSite is the collective work of the HackThisSite staff, licensed under a CC BY-NC license.
We ask that you inform us upon sharing or distributing.