| 470 | ''' |
| 471 | |
| 472 | def format_nmap_open_port(xmls, mode): |
| 473 | try: |
| 474 | import xml.etree.ElementTree |
| 475 | except: |
| 476 | sublime.message_dialog('[ERR] could not import xml.etree.ElementTree, please check and install') |
| 477 | return 'format failed' |
| 478 | |
| 479 | root = xml.etree.ElementTree.fromstring(xmls) |
| 480 | text, wafhosts = [], ['\n\n# WAF host:'] |
| 481 | |
| 482 | for host in root.findall('host'): |
| 483 | address = host.find('address').get('addr') |
| 484 | ports = host.find('ports').findall('port') |
| 485 | |
| 486 | if mode == "domain": |
| 487 | try: |
| 488 | address = host.find('hostnames').findall('hostname')[0].get('name') |
| 489 | except: |
| 490 | pass |
| 491 | |
| 492 | if len(ports) > 100: |
| 493 | wafhosts.append(address) |
| 494 | continue |
| 495 | |
| 496 | for port in ports: |
| 497 | port, state = port.get('portid'), port.find('state').get('state') |
| 498 | if state != 'open': |
| 499 | continue |
| 500 | try: |
| 501 | service = port.find('service').get('name') |
| 502 | except: |
| 503 | service = 'unknow' |
| 504 | |
| 505 | text.append(address + ':' + port) |
| 506 | |
| 507 | text = '\n'.join(list(set(text))) |
| 508 | if len(wafhosts) > 1: |
| 509 | text += '\n'.join(wafhosts) |
| 510 | |
| 511 | return text |
| 512 | |
| 513 | |
| 514 | def select_nmap_ports_from_xml(xmls, mode): |