Skip to content

Commit a6eee15

Browse files
committed
add -i parameter
1 parent d3c5a5d commit a6eee15

File tree

1 file changed

+85
-57
lines changed

1 file changed

+85
-57
lines changed

knowsmore/cmd/wordlist.py

Lines changed: 85 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class WordList(CmdBase):
3838
max_size = 32
3939
level = 3
4040
padding = False
41+
increment = False
4142
no_leets = False
4243
small = False
4344
unique_chars = []
@@ -72,10 +73,12 @@ def add_commands(self, cmds: _ArgumentGroup):
7273
help=Color.s('Write generate wordlist to a file'))
7374
cmds.add_argument('-min', '--min-lenght', default=1, type=int, dest='min_lenght',
7475
help='Minumin word lenght')
75-
cmds.add_argument('-max', '--max-lenght', default=32, type=int, dest='max_lenght',
76+
cmds.add_argument('-max', '--max-lenght', default=-1, type=int, dest='max_lenght',
7677
help='Maximum word lenght.')
7778
cmds.add_argument('-p', '--padding', action='store_true', dest='padding', default=False,
7879
help='Add padding to fill string to match minimun leght')
80+
cmds.add_argument('-i', '--increment', action='store_true', dest='increment', default=False,
81+
help='Add padding (one by one) to fill string to match maximum leght')
7982
cmds.add_argument('-nol', '--no-leets', action='store_true', dest='no_leets', default=False,
8083
help='No Leets')
8184
cmds.add_argument('-l', '--level', default=3, type=int, dest='level',
@@ -94,8 +97,13 @@ def load_from_arguments(self, args: Namespace) -> bool:
9497

9598
self.name = args.name
9699
self.min_size = int(args.min_lenght)
97-
self.max_size = int(args.max_lenght)
98-
self.padding = args.padding
100+
if args.max_lenght > self.min_size:
101+
self.max_size = int(args.max_lenght)
102+
self.increment = args.increment # Just mark this if --max-lenght had set
103+
else:
104+
self.max_size = 32 # Default value
105+
106+
self.padding = args.padding or self.increment
99107
self.no_leets = args.no_leets
100108
self.batch = args.batch
101109
self.append_file = args.append_file
@@ -234,23 +242,30 @@ def calculate(self) -> int:
234242

235243
s = len(self.name)
236244
leet_lines = np.prod([len([chars for chars in self.char_space.get(c)]) for c in self.name])
237-
padding_space = 0
238-
if len(self.name) < self.min_size and self.padding:
239-
s1 = self.min_size - len(self.name)
240-
if s1 > 0:
241-
pl = math.pow(len(self.unique_chars), s1)
242-
padding_space = (
243-
((pl * leet_lines) * (s1 + s + 1))
244-
+ (math.pow(self.unique_ch_b - len(self.unique_chars), s1) * (self.unique_ch_b - len(self.unique_chars)) * (s1 + 1))
245-
) * 2
246-
common_space = np.sum([len(line) + 1 for line in self.add_common(self.name)])
245+
padding_space = [0]
246+
if self.padding:
247+
n1 = self.min_size - len(self.name)
248+
n2 = n1 if not self.increment else self.max_size - len(self.name)
249+
if n1 > 0 or n2 > 0:
250+
if n1 < 1:
251+
n1 = 1
252+
for s1 in range(n1, n2 + 1):
253+
pl = math.pow(len(self.unique_chars), s1)
254+
padding_space += [(
255+
((pl * leet_lines) * (s1 + s + 1))
256+
+ (math.pow(self.unique_ch_b - len(self.unique_chars), s1) * (self.unique_ch_b - len(self.unique_chars)) * (s1 + 1))
257+
) * 2]
258+
247259

248-
r = int(
249-
float(s + 1)/1024.0 +
250-
float(leet_lines * (s + 1))/1024.0 +
251-
float((float(leet_lines)/1024.0) * (float(common_space)/1024.0))*1024.0 +
252-
float(padding_space)/1024.0
253-
)
260+
common_space = np.sum([len(line) + 1 for line in self.add_common(self.name)])
261+
r = 0
262+
for ps in padding_space:
263+
r += int(
264+
float(s + 1)/1024.0 +
265+
float(leet_lines * (s + 1))/1024.0 +
266+
float((float(leet_lines)/1024.0) * (float(common_space)/1024.0))*1024.0 +
267+
float(ps)/1024.0
268+
)
254269
if r < 0:
255270
r = 0
256271
return r
@@ -282,66 +297,79 @@ def generate(self, word, index) -> list:
282297
yield from self.generate(p, index + 1)
283298

284299
def add_padding(self, word):
285-
s1 = self.min_size - len(word)
286-
if s1 > 0:
287-
for c in list(self.permutation(self.unique_chars, s1)):
288-
yield "%s%s" % (word, c)
289-
yield "%s%s" % (c, word)
300+
n1 = self.min_size - len(self.name)
301+
n2 = n1 if not self.increment else self.max_size - len(self.name)
302+
if n1 > 0 or n2 > 0:
303+
if n1 < 1:
304+
n1 = 1
305+
for s1 in range(n1, n2 + 1):
306+
for c in list(self.permutation(self.unique_chars, s1)):
307+
yield "%s%s" % (word, c)
308+
yield "%s%s" % (c, word)
290309

291310
def add_common(self, word):
292311

293312
year = datetime.datetime.now().year
294313
y2 = int(str(year)[2:4])
295314

315+
tmp_list = []
316+
296317
for c in COMMON:
297-
if self.min_size <= len(word) + len(c) <= self.max_size:
298-
yield "%s%s" % (word, c)
299-
yield "%s%s" % (c, word)
318+
if self.min_size <= len(word) + len(c):
319+
tmp_list.append(self.cut("%s%s" % (word, c)))
320+
tmp_list.append( "%s%s" % (c, word))
300321

301-
if self.min_size <= len(word) + 1 <= self.max_size:
322+
if self.min_size <= len(word) + 1:
302323
for s in SPECIAL:
303-
yield "%s%s" % (word, s)
304-
yield "%s%s" % (s, word)
324+
tmp_list.append(self.cut("%s%s" % (word, s)))
325+
tmp_list.append(self.cut("%s%s" % (s, word)))
305326

306327
for c in COMMON:
307-
if self.min_size <= len(word) + 1 + len(c) <= self.max_size:
308-
yield "%s%s%s" % (word, s, c)
309-
yield "%s%s%s" % (c, s, word)
328+
if self.min_size <= len(word) + 1 + len(c):
329+
tmp_list.append(self.cut("%s%s%s" % (word, s, c)))
330+
tmp_list.append(self.cut("%s%s%s" % (c, s, word)))
310331
if not self.small and self.level >= 2:
311-
yield "%s%s%s" % (word, c, s)
312-
yield "%s%s%s" % (s, c, word)
332+
tmp_list.append(self.cut("%s%s%s" % (word, c, s)))
333+
tmp_list.append(self.cut("%s%s%s" % (s, c, word)))
313334

314-
if self.min_size <= len(word) + 3 <= self.max_size:
335+
if self.min_size <= len(word) + 3:
315336
for n in range(0, y2 + 15):
316-
yield "%s%s" % (word, n)
317-
yield "%s%s" % (n, word)
337+
tmp_list.append(self.cut("%s%s" % (word, n)))
338+
tmp_list.append(self.cut("%s%s" % (n, word)))
318339
for s in SPECIAL:
319-
yield "%s%s%s" % (word, s, n)
320-
yield "%s%s%s" % (n, s, word)
321-
yield "%s%s%02d" % (word, s, n)
322-
yield "%02d%s%s" % (n, s, word)
340+
tmp_list.append(self.cut("%s%s%s" % (word, s, n)))
341+
tmp_list.append(self.cut("%s%s%s" % (n, s, word)))
342+
tmp_list.append( self.cut("%s%s%02d" % (word, s, n)))
343+
tmp_list.append( self.cut("%02d%s%s" % (n, s, word)))
323344

324345
if not self.small and self.level >= 3:
325-
yield "%s%s%s" % (word, n, s)
326-
yield "%s%s%s" % (s, n, word)
327-
yield "%s%02d%s" % (word, n, s)
328-
yield "%s%02d%s" % (s, n, word)
346+
tmp_list.append( self.cut("%s%s%s" % (word, n, s)))
347+
tmp_list.append( self.cut("%s%s%s" % (s, n, word)))
348+
tmp_list.append( self.cut("%s%02d%s" % (word, n, s)))
349+
tmp_list.append( self.cut("%s%02d%s" % (s, n, word)))
329350

330-
if self.min_size <= len(word) + 5 <= self.max_size:
351+
if self.min_size <= len(word) + 5:
331352
for n in range(year - 15, year + 15):
332-
yield "%s%s" % (word, n)
333-
yield "%s%s" % (n, word)
353+
tmp_list.append( self.cut("%s%s" % (word, n)))
354+
tmp_list.append( self.cut("%s%s" % (n, word)))
334355
for s in SPECIAL:
335-
yield "%s%s%s" % (word, s, n)
336-
yield "%s%s%s" % (n, s, word)
337-
yield "%s%s%04d" % (word, s, n)
338-
yield "%04d%s%s" % (n, s, word)
356+
tmp_list.append( self.cut("%s%s%s" % (word, s, n)))
357+
tmp_list.append( self.cut("%s%s%s" % (n, s, word)))
358+
tmp_list.append( self.cut("%s%s%04d" % (word, s, n)))
359+
tmp_list.append( self.cut("%04d%s%s" % (n, s, word)))
339360

340361
if not self.small and self.level >= 3:
341-
yield "%s%s%s" % (word, n, s)
342-
yield "%s%s%s" % (s, n, word)
343-
yield "%s%04d%s" % (word, n, s)
344-
yield "%s%04d%s" % (s, n, word)
362+
tmp_list.append( self.cut("%s%s%s" % (word, n, s)))
363+
tmp_list.append( self.cut("%s%s%s" % (s, n, word)))
364+
tmp_list.append( self.cut("%s%04d%s" % (word, n, s)))
365+
tmp_list.append( self.cut("%s%04d%s" % (s, n, word)))
366+
367+
yield from set(tmp_list)
368+
369+
def cut(self, word) -> str:
370+
if len(word) <= self.max_size:
371+
return word
372+
return word[:self.max_size]
345373

346374
def permutation(self, char_space: list, size: int) -> list:
347375
if size <= 0:

0 commit comments

Comments
 (0)