Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement min/max len in permutation plugin #351

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions src/wfuzz/plugins/payloads/permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
@moduleman_plugin
class permutation(BasePayload):
name = "permutation"
author = ("Xavi Mendez (@xmendez)",)
version = "0.1"
author = ("Xavi Mendez (@xmendez)", "@[email protected]")
version = "0.2"
description = ()
summary = "Returns permutations of the given charset and length."
category = ["default"]
priority = 99

parameters = (("ch", "", True, "Charset and len to permute in the form of abc-2."),)
parameters = (("ch", "", True, "Charset and min/max len to permute, in the form of abc-1-8."),)

default_parameter = "ch"

Expand All @@ -25,15 +25,16 @@ def __init__(self, params):
try:
ran = self.params["ch"].split("-")
self.charset = ran[0]
self.width = int(ran[1])
self.min_length = int(ran[1])
self.max_length = int(ran[2])
except ValueError:
raise FuzzExceptBadOptions('Bad range format (eg. "0-ffa")')
raise FuzzExceptBadOptions('Bad range format (eg. "1-4-ffa")')

pset = []
for x in self.charset:
pset.append(x)

words = self.xcombinations(pset, self.width)
words = self.xcombinations(pset, self.min_length, self.max_length)
self.lista = []
for x in words:
self.lista.append("".join(x))
Expand All @@ -53,10 +54,23 @@ def get_next(self):
else:
raise StopIteration

def xcombinations(self, items, n):
if n == 0:
yield []
else:
for i in range(len(items)):
for cc in self.xcombinations(items[:i] + items[i:], n - 1):
yield [items[i]] + cc
def xcombinations(self, charset, min_length, max_length):
def product(pool, repeat):
n = len(pool)
indices = [0] * repeat
current_perm = [pool[0]] * repeat
while True:
yield ''.join(current_perm)
for i in reversed(range(repeat)):
indices[i] += 1
if indices[i] < n:
current_perm[i] = pool[indices[i]]
break
indices[i] = 0
current_perm[i] = pool[0]
else:
return

for length in range(min_length, max_length + 1):
for perm in product(charset, length):
yield perm