Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Add new interface for adding alive test methods #329

Merged
merged 7 commits into from
Oct 14, 2020
Merged
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions ospd/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,32 @@ def process_credentials_elements(cred_tree: Element) -> Dict:

return credentials

@staticmethod
def process_alive_test_methods(cred_tree: Element, options: Dict) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a more descriptive param name.

Suggested change
def process_alive_test_methods(cred_tree: Element, options: Dict) -> None:
def process_alive_test_methods(alive_test_tree: Element, options: Dict) -> None:

""" Receive an XML object with the alive test methods to run
a scan with. Methods are added to the options Dict.

@param
<alive_test_methods>
</icmp></icmp>
</tcp_ack></tcp_ack>
</tcp_syn></tcp_syn>
</arp></arp>
</consider_alive>0</consider_alive>
</alive_test_methods>
"""
for child in cred_tree:
if child.tag == 'icmp':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these methods optional? shouldn't be added only if they are set? Not sure if it make sense to add and empty element to the options dict.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the options (imcp, tcp_ack ...) are optional. For example if you do not want icmp then you can either leave it out completely, set it to '0' or leave it empty. Everything not '1' is treated as not wanted.

Should I check if child.text is None and not include it in the options dict?

Just an additional remark. If <alive_test> and <alive_test_methods> is provided, <alive_test> takes precedence over <alive_test_methods>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now added a test for None. So if there is no text it will not be included options dict.
I also changed the argument description in the function.

options['icmp'] = child.text
if child.tag == 'tcp_ack':
options['tcp_ack'] = child.text
if child.tag == 'tcp_syn':
options['tcp_syn'] = child.text
if child.tag == 'arp':
options['arp'] = child.text
if child.tag == 'consider_alive':
options['consider_alive'] = child.text

@classmethod
def process_target_element(cls, scanner_target: Element) -> Dict:
"""Receive an XML object with the target, ports and credentials to run
Expand Down Expand Up @@ -222,6 +248,9 @@ def process_target_element(cls, scanner_target: Element) -> Dict:
ports = child.text
if child.tag == 'credentials':
credentials = cls.process_credentials_elements(child)
if child.tag == 'alive_test_methods':
options['alive_test_methods'] = '1'
cls.process_alive_test_methods(child, options)
if child.tag == 'alive_test':
options['alive_test'] = child.text
if child.tag == 'alive_test_ports':
Expand Down