Skip to content

Commit

Permalink
Added filters base - Issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Erwan Dupard committed Jun 25, 2018
1 parent e9f34cf commit d5a303a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
7 changes: 5 additions & 2 deletions fuzzy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ def parse_args(cls, argv):
# Filters
parser.add_argument("--hc", type=str, default=[], action=IntListAction, help="Hide given status code responses eg: --hc \"404, 400\" (default none)")
parser.add_argument("--sc", type=str, default=[], action=IntListAction, help="Show given status code responses eg: --sc \"404, 400\" (default none)")
parser.add_argument("--ht", type=str, help="Hide responses that match given str (default none)")
parser.add_argument("--st", type=str, help="Show responses that match given str (default none)")
parser.add_argument("--hw", type=str, help="Hide responses that match given str (default none)")
parser.add_argument("--sw", type=str, help="Show responses that match given str (default none)")

parser.add_argument("--filter-show", type=str, help="Advanced filters that shows matched requests", required=False)
parser.add_argument("--filter-hide", type=str, help="Advanced filters that hides matched requests", required=False)
return parser.parse_args(argv)

@classmethod
Expand Down
33 changes: 24 additions & 9 deletions fuzzy/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def __init__(self,
verbose,
timeout,
report,
hc, sc, ht, st,
hc, sc, hw, sw,
filter_show,
filter_hide,
tag,
disable_progress):

Expand All @@ -84,8 +86,10 @@ def __init__(self,
self._report = report
self._hc = hc
self._sc = sc
self._ht = ht
self._st = st
self._hw = hw
self._sw = sw
self._filter_show = filter_show
self._filter_hide = filter_hide
self._requests_did = 0
self._requests_todo = 0

Expand Down Expand Up @@ -140,7 +144,6 @@ async def stop(self):

async def handle_request_exceptions(self, request):


""" Handle the given requests errors !
:param request: The request to handle
Expand Down Expand Up @@ -174,9 +177,23 @@ async def call_request(self, request):
content = data['text']
if not self._disable_progress:
self.status(spent, request._word)
if Matching.is_matching(response.status, content, hc=self._hc, sc=self._sc, ht=self._ht, st=self._st):
if Matching.is_matching(response.status,
content,
hc=self._hc,
sc=self._sc,
hw=self._hw,
sw=self._sw,
a_filters_h=self._filter_hide,
a_filters_s=self._filter_show):
color = Printer.get_code_color(response.status)
Printer.one("'{}'".format(request._word if self._url_file is None else request._url), str(response.status), str(spent), str(len(content)), color, str(len(content.split(' '))), str(len(content.splitlines())), str(request._word in content))
Printer.one("'{}'".format(request._word if self._url_file is None else request._url),
str(response.status),
str(spent),
str(len(content)),
color,
str(len(content.split(' '))),
str(len(content.splitlines())),
str(request._word in content))
if self._delay > 0:
await asyncio.sleep(self._delay)
self._queue.task_done()
Expand All @@ -198,7 +215,6 @@ async def _fill_multiple_url(self):
await self._queue.put(request)
self._requests_todo = self._queue.qsize()


async def fill_queue(self):

""" Fill the tasks queue """
Expand Down Expand Up @@ -239,14 +255,13 @@ async def process(self):
await self.trigger_coros()
self.loop.stop()


def loop(self):

""" Launch the main fuzzy loop """

self.loop = asyncio.get_event_loop()
# self.loop.set_debug(True)
self.loop.set_exception_handler(exception_handler)
# self.loop.set_exception_handler(exception_handler)
try:
self.loop.run_until_complete(self.process())
except KeyboardInterrupt as e:
Expand Down
33 changes: 28 additions & 5 deletions fuzzy/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,24 @@ class Matching(object):

""" Is used to match the response to keep or to leave """

"""
TODO: We have to parse expressions ... in a efficient manner
(without permitting code injection since people use sudo pip install ...):
like: "status==404 and 'word' in content"
"(status!=404 or 'word' in content) and word_count != 113"
"""
@classmethod
def advanded_filter_show(cls, status, content, a_filters):
return True

@classmethod
def advanded_filter_hide(cls, status, content, a_filters):
return False

@classmethod
def is_matching(cls, status, content, hc=[], ht=None, st=None, sc=[]):
def is_matching(cls, status, content, hc=[], hw=None, sw=None, sc=[], a_filters_s=None, a_filters_h=None):

""" This classmethod is used to determinate if the given response match the given filters
Expand All @@ -20,13 +36,20 @@ def is_matching(cls, status, content, hc=[], ht=None, st=None, sc=[]):
:returns: a boolean -> True if the response has to be hide, False if it does not
"""

# if a_filters_s is not None:
# if cls.advanded_filter_show(status, content, a_filters_s):
# return True
# if a_filters_h is not None:
# if not cls.advanded_filter_hide(status, content, a_filters_h):
# return False

# Hide if ht is in response content
if ht is not None:
if ht in content:
if hw is not None:
if hw in content:
return False
# Show if st is in response content
if st is not None:
if st in content:
if sw is not None:
if sw in content:
return True
# Show if status code is in hc array
if len(sc) > 0:
Expand Down

0 comments on commit d5a303a

Please sign in to comment.