Skip to content

Commit

Permalink
gre operator
Browse files Browse the repository at this point in the history
  • Loading branch information
xmendez committed Apr 3, 2019
1 parent 279a60d commit 269459e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/user/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ value|decode('decoder', 'value') value|d('dec', 'val') Returns encoder.decode(
value|replace('what', 'with') value|r('what', 'with') Returns value replacing what for with
value|unique() value|u() Returns True if a value is unique.
value|startswith('value') value|sw('value') Returns true if the value string starts with param
value|gregex('expression') value|gre('exp') Returns first regex group that matches in value
================================ ======================= =============================================

* When a FuzzResult is available, you could perform runtime introspection of the objects using the following symbols
Expand Down
9 changes: 8 additions & 1 deletion src/wfuzz/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, ffilter=None, filter_string=None):

basic_primitives = int_values | quoted_str_value

operator_names = oneOf("m d e un u r l sw unique startswith decode encode unquote replace lower upper").setParseAction(lambda s, l, t: [(l, t[0])])
operator_names = oneOf("m d e un u r l sw gre gregex unique startswith decode encode unquote replace lower upper").setParseAction(lambda s, l, t: [(l, t[0])])

fuzz_symbol = (Suppress("FUZ") + Optional(Word("23456789"), 1).setParseAction(lambda s, l, t: [int(t[0]) - 1]) + Suppress("Z")).setParseAction(self._compute_fuzz_symbol)
operator_call = Group(Suppress("|") + operator_names + Suppress("(") + Optional(basic_primitives, None) + Optional(Suppress(",") + basic_primitives, None) + Suppress(")"))
Expand Down Expand Up @@ -160,6 +160,7 @@ def __compute_bbb_value(self, tokens):

def __compute_perl_value(self, tokens):
leftvalue, exp = tokens
# import pdb; pdb.set_trace()

if exp:
loc_op, middlevalue, rightvalue = exp
Expand All @@ -179,6 +180,12 @@ def __compute_perl_value(self, tokens):
return leftvalue.upper()
elif op == "lower" or op == "l":
return leftvalue.lower()
elif op == 'gregex' or op == "gre":
regex = re.compile(middlevalue, re.MULTILINE | re.DOTALL)
search_res = regex.search(leftvalue)
if search_res is None:
return ''
return search_res.group(1)
elif op == 'startswith' or op == "sw":
return leftvalue.strip().startswith(middlevalue)
elif op == 'unique' or op == "u":
Expand Down

0 comments on commit 269459e

Please sign in to comment.