Skip to content

Commit c7cc79a

Browse files
authored
Merge pull request #904 from greenbone/update_grammar
Change: Extend Grammar plugin regex. Add relevant test cases.
2 parents a71b163 + 8174a5c commit c7cc79a

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

tests/plugins/test_grammar.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,58 @@ def test_grammar10(self):
328328
results[0].message,
329329
)
330330

331+
def test_grammar11(self):
332+
nasl_file = Path(__file__).parent / "test.nasl"
333+
content = (
334+
' script_tag(name:"cvss_base", value:"4.0");\n'
335+
' script_tag(name:"impact", value:"Inadequate checks in '
336+
"com_contact could allowed mail submission\n"
337+
' script_tag(name:"solution_type", value:"VendorFix");\n'
338+
)
339+
340+
fake_context = self.create_file_plugin_context(
341+
nasl_file=nasl_file, file_content=content
342+
)
343+
plugin = CheckGrammar(fake_context)
344+
345+
results = list(plugin.run())
346+
347+
self.assertEqual(len(results), 1)
348+
self.assertIsInstance(results[0], LinterError)
349+
self.assertEqual(
350+
"VT/Include has the following grammar problem:\n"
351+
"- Hit: could allowed\n"
352+
'- Full line: script_tag(name:"impact", value:"Inadequate checks '
353+
"in com_contact could allowed mail submission",
354+
results[0].message,
355+
)
356+
357+
def test_grammar12(self):
358+
nasl_file = Path(__file__).parent / "test.nasl"
359+
content = (
360+
' script_tag(name:"cvss_base", value:"4.0");\n'
361+
' script_tag(name:"impact", value:"This allow an attacker to gain '
362+
"administrative access to the\n"
363+
' script_tag(name:"solution_type", value:"VendorFix");\n'
364+
)
365+
366+
fake_context = self.create_file_plugin_context(
367+
nasl_file=nasl_file, file_content=content
368+
)
369+
plugin = CheckGrammar(fake_context)
370+
371+
results = list(plugin.run())
372+
373+
self.assertEqual(len(results), 1)
374+
self.assertIsInstance(results[0], LinterError)
375+
self.assertEqual(
376+
"VT/Include has the following grammar problem:\n"
377+
"- Hit: This allow\n"
378+
'- Full line: script_tag(name:"impact", value:"This allow an '
379+
"attacker to gain administrative access to the",
380+
results[0].message,
381+
)
382+
331383
def test_grammar_fp(self):
332384
nasl_file = Path(__file__).parent / "test.nasl"
333385
content = (
@@ -383,3 +435,21 @@ def test_grammar_fp2(self):
383435
results = list(plugin.run())
384436

385437
self.assertEqual(len(results), 0)
438+
439+
def test_grammar_fp3(self):
440+
nasl_file = Path(__file__).parent / "test.nasl"
441+
content = (
442+
' script_tag(name:"cvss_base", value:"4.0");\n'
443+
' script_tag(name:"insight", value:"*snip* connection string to '
444+
'provide\nproperties that are not on this allow list.");\n'
445+
' script_tag(name:"solution_type", value:"VendorFix");\n'
446+
' script_tag(name:"solution", value:"meh");\n'
447+
)
448+
fake_context = self.create_file_plugin_context(
449+
nasl_file=nasl_file, file_content=content
450+
)
451+
plugin = CheckGrammar(fake_context)
452+
453+
results = list(plugin.run())
454+
455+
self.assertEqual(len(results), 0)

troubadix/plugins/grammar.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@
4343
# From several Ubuntu LSCs like e.g.:
4444
# 2021/ubuntu/gb_ubuntu_USN_4711_1.nasl
4545
TextCheck("An attacker with access to at least one LUN in a multiple"),
46-
# nb: The regex to catch "this files" might catch this wrongly...
47-
PatternCheck(r"th(is|ese)\s+filesystem", re.IGNORECASE),
46+
# nb:
47+
# - The regex to catch e.g. "this files" or "This allow an attacker" might
48+
# catch this wrongly...
49+
# - Cases like "this filesystem" vs. "these filesystems" are also handled /
50+
# excluded here
51+
PatternCheck(r'this\s+(filesystem|allow\s+list)[\s.",]+', re.IGNORECASE),
52+
PatternCheck(r'these\s+(filesystem|allow\s+list)s[\s.",]+', re.IGNORECASE),
4853
# Like seen in e.g. 2008/freebsd/freebsd_mod_php4-twig.nasl
4954
PatternCheck(r'(\s+|")[Aa]\s+multiple\s+of'),
5055
# WITH can be used like e.g. the following which is valid:
@@ -183,6 +188,12 @@ def get_grammer_pattern() -> re.Pattern:
183188
# Successful exploitation may allows an attacker to run arbitrary
184189
# An error in INSTALL_JAR procedure might allows remote authenticated
185190
r"(could|may|will|might|should|can)\s+allows\s+|"
191+
# e.g.:
192+
# - Inadequate checks in com_contact could allowed mail submission
193+
r"(could|may|will|might|should|can)\s+allowed\s+|"
194+
# e.g.:
195+
# This allow an attacker to gain administrative access to the
196+
r"This\s+allow\s+|"
186197
# nb: Next few could happen when copy'n'paste some text parts around
187198
# like e.g.:
188199
# is prone to a to a remote denial-of-service vulnerability

0 commit comments

Comments
 (0)