PDA

View Full Version : Another password/wordlist generator in python


Siph0n
05-26-2008, 02:13 PM
It works pretty well for me. You can give it a min and max for the password length. You also get to choose what (numbers, lowercase letters, uppercase letters) to include in it. Adding symbols would be pretty easy also. Just make a new list with the ascii characters for all the symbols you want to include. I saw this done in C in another thread, but it looked like it could be improved on.

f=open('wordlist', 'w')

def xselections(items, n):
if n==0: yield []
else:
for i in xrange(len(items)):
for ss in xselections(items, n-1):
yield [items[i]]+ss

# Numbers = 48 - 57
# Capital = 65 - 90
# Lower = 97 - 122
numb = range(48,58)
cap = range(65,91)
low = range(97,123)
choice = 0
while int(choice) not in range(1,8):
choice = raw_input('''
1) Numbers
2) Capital Letters
3) Lowercase Letters
4) Numbers + Capital Letters
5) Numbers + Lowercase Letters
6) Numbers + Capital Letters + Lowercase Letters
7) Capital Letters + Lowercase Letters
: ''')

choice = int(choice)
poss = []
if choice == 1:
poss += numb
elif choice == 2:
poss += cap
elif choice == 3:
poss += low
elif choice == 4:
poss += numb
poss += cap
elif choice == 5:
poss += numb
poss += low
elif choice == 6:
poss += numb
poss += cap
poss += low
elif choice == 7:
poss += cap
poss += low

bigList = []
for i in poss:
bigList.append(str(chr(i)))

MIN = raw_input("What is the min size of the word? ")
MIN = int(MIN)
MAX = raw_input("What is the max size of the word? ")
MAX = int(MAX)
for i in range(MIN,MAX+1):
for s in xselections(bigList,i): f.write(''.join(s) + '\n')

bofh28
05-28-2008, 11:17 AM
It looks fine to me, but then I don't know how to code python.

A good feature to add would be file size. Most programs have a problem with wordlists that are greater than 2GB in size. Adding some logic to close a file at say 1.95GB and start a new one would be nice. I know the split command could do this, but that requires having 2x the generated file filesize. I.E. a 10GB generated file needs another 10GB of free space for the split files. By adding the logic into generator, you save user's time, disk space, and processing time.
The filename might be something like starting letter-ending letter.txt i.e. a-aaaaaaz.txt
Since I am making suggestions, add support for telling the generator where to start. Say I am in the middle of generating a file and have to stop. The program should figure out where it left off, or just prompt the user what phrase it should start at.

I know this beyond the scope of this topic. I really like the code you contributed. Please don't take this posting as nickpicking. The 2GB problem is something all coders should be aware of. Just trying to help.

Thanks,

=Tron=
05-28-2008, 11:44 AM
Thank you for the script Siph0n. The code does seem pretty clean to me and it does seem to outperform the other scripts I have found posted here, at the very least in usability.

Siph0n
05-29-2008, 11:09 AM
Thanks for the suggestions! I will work on that tonight.

Siph0n
05-29-2008, 08:39 PM
Version 2. It now splits the file into a certain space... currently 100 MB. It is easy to change in the code. Also it times it, so you can alter the code to try and make it faster. I also forgot to close out the file at the end. When it does start a new file, it tells you, and also the "word" it is on. It checks the size of the current file every 1000 "words". I plan to add the ability to restart the program at a certain point next. Suggests and comments are welcome! :)


'''
UPDATES:
Forgot to close the file after I opened it.
It now splits the files after a set limit.
It checks the file size after ever 1000 words. Easy to change.

TO DO:
Add in a way to restart the program from where it left off.
'''
import os
import time
numFile = 0
f=open('wordlist-' + str(numFile) + '.txt', 'w')

def xselections(items, n):
if n==0: yield []
else:
for i in xrange(len(items)):
for ss in xselections(items, n-1):
yield [items[i]]+ss

# Numbers = 48 - 57
# Capital = 65 - 90
# Lower = 97 - 122
numb = range(48,58)
cap = range(65,91)
low = range(97,123)
choice = 0
while int(choice) not in range(1,8):
choice = raw_input('''
1) Numbers
2) Capital Letters
3) Lowercase Letters
4) Numbers + Capital Letters
5) Numbers + Lowercase Letters
6) Numbers + Capital Letters + Lowercase Letters
7) Capital Letters + Lowercase Letters
: ''')

choice = int(choice)
poss = []
if choice == 1:
poss += numb
elif choice == 2:
poss += cap
elif choice == 3:
poss += low
elif choice == 4:
poss += numb
poss += cap
elif choice == 5:
poss += numb
poss += low
elif choice == 6:
poss += numb
poss += cap
poss += low
elif choice == 7:
poss += cap
poss += low

bigList = []
for i in poss:
bigList.append(str(chr(i)))

MIN = raw_input("What is the min size of the word? ")
MIN = int(MIN)
MAX = raw_input("What is the max size of the word? ")
MAX = int(MAX)
MAX_SIZE_MB = 100
MAX_SIZE_BYTES = MAX_SIZE_MB * 1024 * 1024
HOW_OFTEN_CHECK = 1000
count = 0
START_TIME = time.time()
for i in range(MIN,MAX+1):
for s in xselections(bigList,i):
count += 1
f.write(''.join(s) + '\n')
if count >= HOW_OFTEN_CHECK:
size = os.path.getsize('wordlist-' + str(numFile) + '.txt')
if size > MAX_SIZE_BYTES:
f.close()
numFile += 1
f=open('wordlist-' + str(numFile) + '.txt', 'w')
count = 0
print 'New File. Current word: ', ''.join(s)

f.close()
END_TIME = time.time()
print 'Time it took to compute files:', END_TIME - START_TIME, 'seconds'

intertan
06-02-2008, 09:57 PM
interesting now how about the rest of the asscii syllables?


guess I shouldn't jump the gun, I am just starting to lean python are some of your code is making sence.

Siph0n
06-03-2008, 10:02 AM
intertan, thats easy enough.... make a new variable called asc

asc = [12,14,16]

Instead of 12, 14, and 16, put in whatever the ascii values are.... I don't feel like looking ;)

Than in the while loop, add another choice

8) Ascii Symbols

Than in the if/else if statements below that, add:

elif choice == 8:
poss += asc

I mostly didn't put that in their because, 1) I didn't want to put all the different combinations of Lower Case and Symbols, Upper Case and Symbols, etc... and 2) I don't see the point in making a list of all possible combiniations anymore :)... Anyone else can continue this program if they like. I also started on having it possible to continue where you left off, but didn't get far... Good luck!

s1lang
06-04-2008, 02:52 PM
Theoretically say a 12 character password list with anything from the keyboard.
What size would the overall file be?

And would it be quicker to run this file in a dictionary attack over a brute force attack??

Cheers :)

Siph0n
06-04-2008, 03:19 PM
I don't know how many possible keys are on the keyboard, but with just uppercase, lowercase, and numbers, there are (26+26+10)**12 characters in that file. I found this equation to work 62**12 * 13 to get how many bytes. Than divide that by 1024 to get the KB, and divide that by 1024 to get the MB. I think that equation is right, it looks like 39,061,035,878,185 GB. Though like I said, I am not 100% on the size, though 62**12 is definitely how many total characters are in the file. Also this is only for 12 character passwords, not 11 or 10 etc....

** = power