Skip to content
This repository was archived by the owner on Mar 2, 2024. It is now read-only.
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions nxapi/nxlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def explain_nxlog(nxlog):
:return str: A textual explaination of the `nxlog`
"""

explain = "Peer <strong>{}</strong> performed a request to <strong>{}</strong> on URI <strong>{}</strong> ".format(
explain = "Peer *{}* performed a request to *{}* on URI *{}* ".format(
nxlog['ip'], nxlog['server'], nxlog['uri'])

scores = list()
cpt = 0
while "cscore{}".format(cpt) in nxlog:
cscore = "cscore{}".format(cpt)
score = "score{}".format(cpt)
scores.append("that reached a <strong>{}</strong> score of <strong>{}</strong> ".format(
scores.append("that reached a *{}* score of *{}* ".format(
nxlog[cscore], nxlog[score]))
cpt += 1
explain += ' and '.join(scores)
Expand All @@ -58,10 +58,10 @@ def explain_nxlog(nxlog):
_var_name = "var_name{}".format(cpt)
_zone = "zone{}".format(cpt)
if "var_name{}".format(cpt) in nxlog:
named.append("id <strong>{}</strong> in var named <strong>{}</strong> of zone <strong>{}</strong>".format(
named.append("id *{}* in var named *{}* of zone *{}*".format(
nxlog[_id], nxlog[_var_name], nxlog[_zone]))
else:
named.append("id <strong>{}</strong> in zone <strong>{}</strong>".format(nxlog[_id], nxlog[_zone]))
named.append("id *{}* in zone *{}*".format(nxlog[_id], nxlog[_zone]))
cpt += 1
explain += ' and '.join(named)

Expand Down
14 changes: 7 additions & 7 deletions nxapi/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ def explain(rule):
"""
translation = {'ARGS': 'argument', 'BODY': 'body', 'URL': 'url', 'HEADER': 'header',
'HEADER:Cookie': 'cookies'}
explanation = 'The rule number <strong>{0}</strong> is '.format(rule['sid'])
explanation = 'The rule number *{0}* is '.format(rule['sid'])
if rule['negative']:
explanation += '<strong>not</strong> '
explanation += '*not* '
explanation += 'setting the '

scores = []
for score in rule['score'].split(','):
scores.append('<strong>{0}</strong> score to <strong>{1}</strong> '.format(*score.split(':', 1)))
scores.append('*{0}* score to *{1}* '.format(*score.split(':', 1)))
explanation += ', '.join(scores) + 'when it '
if rule['detection'].startswith('str:'):
explanation += 'finds the string <strong>{}</strong> '.format(rule['detection'][4:])
explanation += 'finds the string *{}* '.format(rule['detection'][4:])
else:
explanation += 'matches the regexp <strong>{}</strong> in '.format(rule['detection'][3:])
explanation += 'matches the regexp *{}* in '.format(rule['detection'][3:])

zones = []
for mz in rule['mz'].split('|'):
Expand All @@ -66,11 +66,11 @@ def explain(rule):
else:
regexp = "matching regex" if current_zone.endswith("_X") else ""
if zone_name == 'header' and arg.lower() == 'cookie':
zones.append('in the <strong>cookies</strong>')
zones.append('in the *cookies*')
else:
zones.append("in the var with name {} '{}' of {} ".format(regexp, arg, zone_name))
else:
zones.append('the <strong>{0}</strong>'.format(translation[mz]))
zones.append('the *{0}*'.format(translation[mz]))
return explanation + ' ' + ', '.join(zones) + '.'


Expand Down
12 changes: 6 additions & 6 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def test_short_str(self):
def test_explain(self):
rule = {'negative': True, 'detection': 'str:pif', 'msg': 'test msg', 'mz': 'BODY', 'score': '$XSS:3', 'sid': 5}
self.assertEqual(rules.explain(rule),
'The rule number <strong>5</strong> is <strong>not</strong> setting the <strong>$XSS</strong>'
' score to <strong>3</strong> when it finds the string <strong>pif</strong>'
' the <strong>body</strong>.')
'The rule number *5* is *not* setting the *$XSS*'
' score to *3* when it finds the string *pif*'
' the *body*.')
rule = {'negative': True, 'detection': 'str:pif', 'msg': 'test msg', 'mz': 'BODY|URL', 'score': '$XSS:3', 'sid': 5}
self.assertEqual(rules.explain(rule),
'The rule number <strong>5</strong> is <strong>not</strong> setting the <strong>$XSS</strong>'
' score to <strong>3</strong> when it finds the string <strong>pif</strong>'
' the <strong>body</strong>, the <strong>url</strong>.')
'The rule number *5* is *not* setting the *$XSS*'
' score to *3* when it finds the string *pif*'
' the *body*, the *url*.')

def test_parse(self):
rule = 'MainRule negative "str:a" "msg:t" "mz:BODY" "s:$XSS:3" id:5 ;'
Expand Down