I want to perform a dictionary attack and for that I need word lists. How to generate word list from given characters of specific length ( or word length from min length to max length )? I have tried itertools.combinations_with_replacements and itertools.permutations, but it does not help. They does not have all the word lists that it should return. Any help will be greatly appreciated. Thank you.
Asked
Active
Viewed 2.5k times
4
Aamu
- 3,431
- 7
- 39
- 61
-
3I don't think you understand the concept behind a dictionary attack. The idea is to NOT generate all possible combinations (there are A LOT) but to use a file containing actual dictionary words (and other words that are likely passwords). – ThiefMaster Feb 04 '14 at 17:29
4 Answers
8
Use itertools.product:
>>> import itertools
>>>
>>> chrs = 'abc'
>>> n = 2
>>>
>>> for xs in itertools.product(chrs, repeat=n):
... print ''.join(xs)
...
aa
ab
ac
ba
bb
bc
ca
cb
cc
To get word from min length to max length:
chrs = 'abc'
min_length, max_length = 2, 5
for n in range(min_length, max_length+1):
for xs in itertools.product(chrs, repeat=n):
print ''.join(xs)
falsetru
- 357,413
- 63
- 732
- 636
2
This is a naïve implementation:
list='abcdefg'
depth=8
def generate(l,d):
if d<1:
return
for c in l:
if d==1:
yield c
else:
for k in generate(l,d-1):
yield c+k
for d in range(1,depth):
for c in generate(list,d):
print c
I don't have enough reputation to comment yet, so, to make a full list based on the itertools sample above:
import itertools
chrs='abc'
n=6
for i in range(1,n):
for xs in itertools.product(chrs, repeat=i):
print ''.join(xs)
This way, you have all words from length 1 up to n in your list.
Marco Costa
- 879
- 1
- 7
- 9
1
from itertools import product
def allwords(chars, length):
for letters in product(chars, repeat=length):
yield ''.join(letters)
def main():
letters = "abc"
for wordlen in range(3, 5):
for word in allwords(letters, wordlen):
print(word)
if __name__=="__main__":
main()
returns
aaa
aab
aac
aba
abb
...
ccbc
ccca
cccb
cccc
Hugh Bothwell
- 55,315
- 8
- 84
- 99
-1
def word_gen(start= 3,end= 3, elements = 1): """ Hud Seidu Daannaa Wordlist gen MSC InfoSec, CEH"
README
#for start&end
#e.g. start= 3,end= 3
#means first words to last words should be 3 characters
#for elements
1 is asci
2 is numbers
3 is asci&numbers
"""
import itertools
#types of elements
if elements ==1: elements= 'abcdefghijklmnopqrstuvwxyx'
if elements ==2: elements= '0123456789'
if elements== 3: elements= 'abcdefghijklmnopqrstuvwxyx0123456789'
else: pass
wl = []
for i in range(start,end+1):
for xs in itertools.product(elements, repeat=i):
wl.append(''.join(xs))
return wl