-
Notifications
You must be signed in to change notification settings - Fork 3
[nmap] fix: correct parser when target selector key is manual (#4412) #124
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
904c45e
[nmap] fix: correct parser when target selector key is manual
savacano28 5f1a762
[nmap] test: add tests for parse function
savacano28 2bde965
[nmap] test: add tests for parse function
savacano28 09e6354
[nmap] test: add tests for parse function
savacano28 490ea7e
[nmap] fix: correct asset list for manual targets
savacano28 3e73b56
[injector-common] chore: refact code
savacano28 10fbda7
[nmap] chore: refact code
savacano28 2637957
[nmap] chore: clean code
savacano28 a8a56e3
[nmap] chore: clean code
savacano28 4906059
[nmap] chore: clean code
savacano28 bc12494
[nmap] chore: clean code
savacano28 b792ac4
[nmap] chore: clean code
savacano28 56343da
[nmap] chore: clean code
savacano28 a4b3304
[nmap] chore: clean code
savacano28 a506720
[nmap] chore: clean code
savacano28 aca7ae4
[nmap] chore: clean code
savacano28 7acfb55
[nmap] chore: clean code
savacano28 d91a3f5
[nmap] chore: clean code
savacano28 691ee4e
[nmap] chore: fix tests
savacano28 a26ea52
[nmap] chore: clean code
savacano28 745fe50
[nmap] chore: clean code
savacano28 515bf91
[nmap] chore: clean code
savacano28 b5e49c5
integrate tests in CI
antoinemzs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
savacano28 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| from unittest import TestCase | ||
|
|
||
| from src.helpers.nmap_output_parser import NmapOutputParser | ||
|
|
||
| parse = NmapOutputParser() | ||
savacano28 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class NmapOutputParserTest(TestCase): | ||
| def setUp(self): | ||
| self.data_assets = { | ||
| "injection": {"inject_content": {"target_selector": "assets"}} | ||
| } | ||
|
|
||
| self.data_no_assets = { | ||
| "injection": {"inject_content": {"target_selector": "other"}} | ||
| } | ||
|
|
||
| self.result_multiple_hosts = { | ||
| "nmaprun": { | ||
| "host": [ | ||
| { | ||
| "address": {"@addr": "10.0.0.1"}, | ||
| "ports": { | ||
| "port": [ | ||
| { | ||
| "@portid": "22", | ||
| "state": {"@state": "open"}, | ||
| "service": {"@name": "ssh"}, | ||
| }, | ||
| { | ||
| "@portid": "80", | ||
| "state": {"@state": "closed"}, | ||
| "service": {"@name": "http"}, | ||
| }, | ||
| ] | ||
| }, | ||
| }, | ||
| { | ||
| "address": {"@addr": "10.0.0.2"}, | ||
| "ports": { | ||
| "port": [ | ||
| { | ||
| "@portid": "443", | ||
| "state": {"@state": "open"}, | ||
| "service": {"@name": "https"}, | ||
| } | ||
| ] | ||
| }, | ||
| }, | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| self.result_single_host = { | ||
| "nmaprun": { | ||
| "host": { | ||
| "address": {"@addr": "172.16.5.10"}, | ||
| "ports": { | ||
| "port": [ | ||
| { | ||
| "@portid": "21", | ||
| "state": {"@state": "open"}, | ||
| "service": {"@name": "ftp"}, | ||
| } | ||
| ] | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # ------------------------------- | ||
| # Tests | ||
| # ------------------------------- | ||
|
|
||
| def test_parse_target_assets(self): | ||
| """Ensure target_selector='assets' uses asset_list and sets asset_id.""" | ||
| data = {"injection": {"inject_content": {"target_selector": "assets"}}} | ||
|
|
||
| result = parse(data, self.result_single_host, ["asset-123"]) | ||
savacano28 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| scan = result["outputs"]["scan_results"][0] | ||
|
|
||
| self.assertEqual(scan["asset_id"], "asset-123") | ||
| self.assertEqual(scan["host"], "172.16.5.10") | ||
| self.assertEqual(scan["port"], 21) | ||
| self.assertEqual(scan["service"], "ftp") | ||
|
|
||
| def test_parse_target_asset_groups(self): | ||
| """Ensure target_selector='asset-groups' also uses asset_list.""" | ||
| data = {"injection": {"inject_content": {"target_selector": "asset-groups"}}} | ||
|
|
||
| result = parse(data, self.result_single_host, ["group-asset-555"]) | ||
|
|
||
| scan = result["outputs"]["scan_results"][0] | ||
|
|
||
| self.assertEqual(scan["asset_id"], "group-asset-555") | ||
| self.assertEqual(scan["host"], "172.16.5.10") | ||
| self.assertEqual(scan["port"], 21) | ||
| self.assertEqual(scan["service"], "ftp") | ||
|
|
||
| def test_parse_target_manual(self): | ||
| """Ensure target_selector='manual' sets asset_id=None.""" | ||
| data = {"injection": {"inject_content": {"target_selector": "manual"}}} | ||
|
|
||
| result = parse(data, self.result_single_host, ["ignored"]) | ||
|
|
||
| scan = result["outputs"]["scan_results"][0] | ||
|
|
||
| self.assertIsNone(scan["asset_id"]) | ||
| self.assertEqual(scan["host"], "172.16.5.10") | ||
| self.assertEqual(scan["port"], 21) | ||
| self.assertEqual(scan["service"], "ftp") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.