Analyses NMAP xml scan ouput May raise PortScannerError exception if nmap output was not xml Test existance of the following key to know if something went wrong : ['nmap']['scaninfo']['error'] If not present, everything was ok. :param nmap_xml_output: xml
( # NOQA: CFQ001, C901
self,
nmap_xml_output=None,
nmap_err="",
nmap_err_keep_trace="",
nmap_warn_keep_trace="",
)
| 311 | ) |
| 312 | |
| 313 | def analyse_nmap_xml_scan( # NOQA: CFQ001, C901 |
| 314 | self, |
| 315 | nmap_xml_output=None, |
| 316 | nmap_err="", |
| 317 | nmap_err_keep_trace="", |
| 318 | nmap_warn_keep_trace="", |
| 319 | ): |
| 320 | """ |
| 321 | Analyses NMAP xml scan ouput |
| 322 | |
| 323 | May raise PortScannerError exception if nmap output was not xml |
| 324 | |
| 325 | Test existance of the following key to know if something went wrong : ['nmap']['scaninfo']['error'] |
| 326 | If not present, everything was ok. |
| 327 | |
| 328 | :param nmap_xml_output: xml string to analyse |
| 329 | :returns: scan_result as dictionnary |
| 330 | """ |
| 331 | |
| 332 | # nmap xml output looks like : |
| 333 | # <host starttime="1267974521" endtime="1267974522"> |
| 334 | # <status state="up" reason="user-set"/> |
| 335 | # <address addr="192.168.1.1" addrtype="ipv4" /> |
| 336 | # <hostnames><hostname name="neufbox" type="PTR" /></hostnames> |
| 337 | # <ports> |
| 338 | # <port protocol="tcp" portid="22"> |
| 339 | # <state state="filtered" reason="no-response" reason_ttl="0"/> |
| 340 | # <service name="ssh" method="table" conf="3" /> |
| 341 | # </port> |
| 342 | # <port protocol="tcp" portid="25"> |
| 343 | # <state state="filtered" reason="no-response" reason_ttl="0"/> |
| 344 | # <service name="smtp" method="table" conf="3" /> |
| 345 | # </port> |
| 346 | # </ports> |
| 347 | # <hostscript> |
| 348 | # <script id="nbstat" output="NetBIOS name: GROSTRUC, NetBIOS user: <unknown>, NetBIOS MAC: <unknown>
" /> # NOQA: E501 |
| 349 | # <script id="smb-os-discovery" output=" 
 OS: Unix (Samba 3.6.3)
 Name: WORKGROUP\Unknown
 System time: 2013-06-23 15:37:40 UTC+2
" /> # NOQA: E501 |
| 350 | # <script id="smbv2-enabled" output="Server doesn't support SMBv2 protocol" /> |
| 351 | # </hostscript> |
| 352 | # <times srtt="-1" rttvar="-1" to="1000000" /> |
| 353 | # </host> |
| 354 | |
| 355 | # <port protocol="tcp" portid="25"> |
| 356 | # <state state="open" reason="syn-ack" reason_ttl="0"/> |
| 357 | # <service name="smtp" product="Exim smtpd" version="4.76" hostname="grostruc" method="probed" conf="10"> |
| 358 | # <cpe>cpe:/a:exim:exim:4.76</cpe> |
| 359 | # </service> |
| 360 | # <script id="smtp-commands" output="grostruc Hello localhost [127.0.0.1], SIZE 52428800, PIPELINING, HELP, 
 Commands supported: AUTH HELO EHLO MAIL RCPT DATA NOOP QUIT RSET HELP "/> # NOQA: E501 |
| 361 | # </port> |
| 362 | |
| 363 | if nmap_xml_output is not None: |
| 364 | self._nmap_last_output = nmap_xml_output |
| 365 | |
| 366 | scan_result = {} |
| 367 | |
| 368 | try: |
| 369 | dom = ET.fromstring(self._nmap_last_output) |
| 370 | except Exception: |
no test coverage detected