* when the xml parsed failed * match port by regexp
(xmls, mode)
| 512 | |
| 513 | |
| 514 | def select_nmap_ports_from_xml(xmls, mode): |
| 515 | ''' |
| 516 | * when the xml parsed failed |
| 517 | * match port by regexp |
| 518 | ''' |
| 519 | text, wafhosts = "", ['\n\n# WAF host:'] |
| 520 | hosts = re.findall(r'<host.*?</host>', xmls, flags=re.DOTALL) |
| 521 | |
| 522 | for host in hosts: |
| 523 | address, ports = '', [] |
| 524 | for line in host.split("\n"): |
| 525 | if "<address" in line: |
| 526 | address = re.findall(r'<address addr="(.*?)" addrtype', line)[0] |
| 527 | break |
| 528 | |
| 529 | if address == '': |
| 530 | continue |
| 531 | |
| 532 | match = re.search(r'<hostname name="(.*?)" type=', host) |
| 533 | if match is not None and mode == "domain": |
| 534 | address = match.group(1) |
| 535 | |
| 536 | for line in host.split("\n"): |
| 537 | if "<port protocol" in line: |
| 538 | port = re.findall(r'<port protocol="tcp" portid="(.*?)">', line)[0] |
| 539 | ports.append(address + ":" + port) |
| 540 | |
| 541 | if len(ports) > 100: |
| 542 | ports = [] |
| 543 | wafhosts.append(address) |
| 544 | break |
| 545 | |
| 546 | if len(ports) > 0: |
| 547 | text += ("\n".join(ports)) + "\n" |
| 548 | |
| 549 | if len(wafhosts) > 1 : |
| 550 | text += '\n'.join(wafhosts) |
| 551 | |
| 552 | return text |
| 553 | |
| 554 | |
| 555 | def format_httpx_result(text): |