当前位置: 首页>>代码示例>>Python>>正文


Python NmapParser.parse_fromfile方法代码示例

本文整理汇总了Python中libnmap.parser.NmapParser.parse_fromfile方法的典型用法代码示例。如果您正苦于以下问题:Python NmapParser.parse_fromfile方法的具体用法?Python NmapParser.parse_fromfile怎么用?Python NmapParser.parse_fromfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在libnmap.parser.NmapParser的用法示例。


在下文中一共展示了NmapParser.parse_fromfile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_osmatches_new

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def test_osmatches_new(self):
        rep = NmapParser.parse_fromfile(self.flist_os['nv6']['file'])
        hlist = []
        hlist.append(rep.hosts.pop())
        hlist.append(rep.hosts.pop())

        baseline = [[{'line': 6014, 'accuracy': 100, 'name': 'Apple Mac OS X 10.8 - 10.8.1 (Mountain Lion) (Darwin 12.0.0 - 12.1.0) or iOS 5.0.1'}],
                    [{'line': 52037, 'accuracy': 100, 'name': 'Microsoft Windows Server 2008 Beta 3'},
                    {'line': 52938, 'accuracy': 100, 'name': 'Microsoft Windows 7 Professional'},
                    {'line': 54362, 'accuracy': 100, 'name': 'Microsoft Windows Phone 7.5'},
                    {'line': 54897, 'accuracy': 100, 'name': 'Microsoft Windows Vista SP0 or SP1, Windows Server 2008 SP1, or Windows 7'},
                    {'line': 55210, 'accuracy': 100, 'name': 'Microsoft Windows Vista SP2, Windows 7 SP1, or Windows Server 2008'}]
                ]
        i=0
        j=0
        for h in hlist:
            for om in h.os.osmatches:
                tdict = {'line': om.line, 'accuracy': om.accuracy, 'name': om.name}
                self.assertEqual(baseline[i][j], tdict)
                j+=1
            j=0
            i+=1 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:24,代码来源:test_fp.py

示例2: test_fpv5

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def test_fpv5(self):
        fpval = 'OS:SCAN(V=5.21%D=5/8%OT=22%CT=1%CU=37884%PV=Y%DS=0%DC=L%G=Y%TM=536BFE32%P=x\nOS:86_64-unknown-linux-gnu)SEQ(SP=100%GCD=1%ISR=106%TI=Z%CI=Z%II=I%TS=8)SEQ\nOS:(SP=101%GCD=1%ISR=107%TI=Z%CI=Z%II=I%TS=8)OPS(O1=M400CST11NW3%O2=M400CST\nOS:11NW3%O3=M400CNNT11NW3%O4=M400CST11NW3%O5=M400CST11NW3%O6=M400CST11)WIN(\nOS:W1=8000%W2=8000%W3=8000%W4=8000%W5=8000%W6=8000)ECN(R=Y%DF=Y%T=40%W=8018\nOS:%O=M400CNNSNW3%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(\nOS:R=Y%DF=Y%T=40%W=8000%S=O%A=S+%F=AS%O=M400CST11NW3%RD=0%Q=)T4(R=Y%DF=Y%T=\nOS:40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0\nOS:%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z\nOS:%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G\nOS:%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)\n'
        fparray = ['OS:SCAN(V=5.21%D=5/8%OT=22%CT=1%CU=37884%PV=Y%DS=0%DC=L%G=Y%TM=536BFE32%P=x\nOS:86_64-unknown-linux-gnu)SEQ(SP=100%GCD=1%ISR=106%TI=Z%CI=Z%II=I%TS=8)SEQ\nOS:(SP=101%GCD=1%ISR=107%TI=Z%CI=Z%II=I%TS=8)OPS(O1=M400CST11NW3%O2=M400CST\nOS:11NW3%O3=M400CNNT11NW3%O4=M400CST11NW3%O5=M400CST11NW3%O6=M400CST11)WIN(\nOS:W1=8000%W2=8000%W3=8000%W4=8000%W5=8000%W6=8000)ECN(R=Y%DF=Y%T=40%W=8018\nOS:%O=M400CNNSNW3%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(\nOS:R=Y%DF=Y%T=40%W=8000%S=O%A=S+%F=AS%O=M400CST11NW3%RD=0%Q=)T4(R=Y%DF=Y%T=\nOS:40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0\nOS:%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z\nOS:%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G\nOS:%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)\n']
        rep = NmapParser.parse_fromfile(self.flist_os['nv5']['file'])
        h1 = rep.hosts[4]
        self.assertEqual(h1.os.fingerprint, fpval)
        self.assertEqual(h1.os.fingerprints, fparray) 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:9,代码来源:test_fp.py

示例3: nmap_parser

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def nmap_parser(nmap_xml):
    """
    If user chooses to start from nmap.xml, read the xml and return an nmap_report object
    :param nmap_xml:
    :return:
    """
    try:
        nmap_report = NmapParser.parse_fromfile(nmap_xml)
        return nmap_report
    except:
        print("\n[!] Error reading {0}. Does it exist?\n".format(nmap_xml))
        exit() 
开发者ID:sethsec,项目名称:celerystalk,代码行数:14,代码来源:utils.py

示例4: nessus_parser

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def nessus_parser(nessus_db):
    """
    If user chooses to start from scan.nessus, read the xml and return an nessus_report object
    :param nessus_db:
    :return: nessus_report
    """
    try:
        nessus_report = report = NessusParser.parse_fromfile(nessus_db)
        return nessus_report
    except:
        print("\n[!] Error reading {0}. Does it exist?\n".format(nessus_db))
        exit() 
开发者ID:sethsec,项目名称:celerystalk,代码行数:14,代码来源:utils.py

示例5: test_diff_host_list

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def test_diff_host_list(self):
        fdir = os.path.dirname(os.path.realpath(__file__))
        r1 = NmapParser.parse_fromfile("%s/%s" % (fdir, 'files/1_hosts.xml'))
        r2 = NmapParser.parse_fromfile("%s/%s" % (fdir, 'files/2_hosts.xml'))
        r3 = NmapParser.parse_fromfile("%s/%s" % (fdir, 'files/1_hosts.xml'))
        r4 = NmapParser.parse_fromfile("%s/%s" % (fdir,
                                                  'files/2_hosts_achange.xml'))

        d1 = r1.diff(r2)
        self.assertEqual(d1.changed(), set(['hosts_total', 'commandline',
                                            'hosts_up', 'scan_type',
                                            'elapsed']))
        self.assertEqual(d1.unchanged(), set(['hosts_down', 'version',
                                              'NmapHost::127.0.0.1']))
        self.assertEqual(d1.removed(), set(['NmapHost::74.207.244.221']))

        d2 = r1.diff(r3)
        self.assertEqual(d2.changed(), set([]))
        self.assertEqual(d2.unchanged(), set(['hosts_total',
                                              'commandline',
                                              'hosts_up',
                                              'NmapHost::127.0.0.1',
                                              'elapsed',
                                              'version',
                                              'scan_type',
                                              'hosts_down']))
        self.assertEqual(d2.added(), set([]))
        self.assertEqual(d2.removed(), set([]))

        d3 = r2.diff(r4)
        self.assertEqual(d3.changed(), set(['NmapHost::127.0.0.1']))
        self.assertEqual(d3.unchanged(), set(['hosts_total',
                                              'commandline',
                                              'hosts_up',
                                              'NmapHost::74.207.244.221',
                                              'version',
                                              'elapsed',
                                              'scan_type',
                                              'hosts_down']))
        self.assertEqual(d3.added(), set([]))
        self.assertEqual(d3.removed(), set([])) 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:43,代码来源:test_report_diff.py

示例6: test_fp

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def test_fp(self):
        for file_e in self.flist_full:
            rep = NmapParser.parse_fromfile(file_e['file'])
            for _host in rep.hosts:
                if file_e['os'] != 0:
                    self.assertTrue(_host.os_fingerprinted)
                elif file_e['os'] == 0:
                    self.assertFalse(_host.os_fingerprinted)
                else:
                    raise Exception 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:12,代码来源:test_fp.py

示例7: test_osclasses_new

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def test_osclasses_new(self):
        oclines = [[[{'type': 'general purpose', 'accuracy': 100, 'vendor': 'Apple', 'osfamily': 'Mac OS X', 'osgen': '10.8.X'},
                    {'type': 'phone', 'accuracy': 100, 'vendor': 'Apple', 'osfamily': 'iOS', 'osgen': '5.X'},
                    {'type': 'media device', 'accuracy': 100, 'vendor': 'Apple', 'osfamily': 'iOS', 'osgen': '5.X'}]],
                    [
                        [{'type': 'general purpose', 'accuracy': 100, 'vendor': 'Microsoft', 'osfamily': 'Windows', 'osgen': '2008'}],
                        [{'type': 'general purpose', 'accuracy': 100, 'vendor': 'Microsoft', 'osfamily': 'Windows', 'osgen': '7'}],
                        [{'type': 'phone',           'accuracy': 100, 'vendor': 'Microsoft', 'osfamily': 'Windows', 'osgen': 'Phone'}],
                        [{'type': 'general purpose', 'accuracy': 100, 'vendor': 'Microsoft', 'osfamily': 'Windows', 'osgen': 'Vista'},
                        {'type': 'general purpose', 'accuracy': 100, 'vendor': 'Microsoft', 'osfamily': 'Windows', 'osgen': '2008'},
                        {'type': 'general purpose', 'accuracy': 100, 'vendor': 'Microsoft', 'osfamily': 'Windows', 'osgen': '7'}],
                        [{'type': 'general purpose', 'accuracy': 100, 'vendor': 'Microsoft', 'osfamily': 'Windows', 'osgen': 'Vista'},
                        {'type': 'general purpose', 'accuracy': 100, 'vendor': 'Microsoft', 'osfamily': 'Windows', 'osgen': '7'},
                        {'type': 'general purpose', 'accuracy': 100, 'vendor': 'Microsoft', 'osfamily': 'Windows', 'osgen': '2008'}]]
        ]
        rep = NmapParser.parse_fromfile(self.flist_os['nv6']['file'])
        hlist = []
        hlist.append(rep.hosts.pop())
        hlist.append(rep.hosts.pop())
        i=0
        j=0
        k=0
        for h in hlist:
            for om in h.os.osmatches:
                for oc in om.osclasses:
                    tdict = {'type': oc.type, 'accuracy': oc.accuracy, 'vendor': oc.vendor, 'osfamily': oc.osfamily, 'osgen': oc.osgen}
                    self.assertEqual(oclines[i][j][k], tdict)
                    k+=1
                j+=1
                k=0
            j=0
            i+=1 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:34,代码来源:test_fp.py

示例8: test_osmatches_old

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def test_osmatches_old(self):
        rep = NmapParser.parse_fromfile(self.flist_os['nv5']['file'])
        h1 = rep.hosts[4]
        h1osmatches = [{'line': -1, 'accuracy': 95, 'name': 'general purpose:Linux:Linux'},
            {'line': -1, 'accuracy': 90, 'name': 'WAP:Gemtek:embedded'},
            {'line': -1, 'accuracy': 89, 'name': 'general purpose:Nokia:Linux'},
            {'line': -1, 'accuracy': 88, 'name': 'webcam:AXIS:Linux'}]

        j=0
        for om in h1.os.osmatches:
            tdict = {'line': om.line, 'accuracy': om.accuracy, 'name': om.name}
            self.assertEqual(h1osmatches[j], tdict)
            j+=1 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:15,代码来源:test_fp.py

示例9: test_cpeservice

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def test_cpeservice(self):
        cpelist = ['cpe:/a:openbsd:openssh:5.9p1','cpe:/o:linux:linux_kernel']
        rep = NmapParser.parse_fromfile(self.flist_os['fullscan']['file'])
        h1 = rep.hosts.pop()
        s = h1.services[0]
        self.assertEqual(s.cpelist[0].cpestring, cpelist[0])
        self.assertEqual(s.cpelist[1].cpestring, cpelist[1]) 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:9,代码来源:test_fp.py

示例10: test_os_class_probabilities

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def test_os_class_probabilities(self):
        p = NmapParser.parse_fromfile(self.fos_class_probabilities)
        h = p.hosts.pop()
        osc = h.os_class_probabilities().pop()
        self.assertEqual(osc.type, "general purpose")
        self.assertEqual(osc.vendor, "Linux")
        self.assertEqual(osc.osfamily, "Linux")
        self.assertEqual(osc.osgen, "3.X")
        self.assertEqual(osc.accuracy, 100)

        #<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="3.X" accuracy="100"><cpe>cpe:/o:linux:linux_kernel:3</cpe></osclass> 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:13,代码来源:test_fp.py

示例11: nmap_scan

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def nmap_scan(hosts):
    '''
    Do Nmap scan
    '''
    nmap_args = '-sS -T4 --script smb-vuln-ms17-010,smb-vuln-ms08-067 -n --max-retries 5 -p 445 -oA smb-scan'
    nmap_proc = NmapProcess(targets=hosts, options=nmap_args, safe_mode=False)
    rc = nmap_proc.sudo_run_background()
    nmap_status_printer(nmap_proc)
    report = NmapParser.parse_fromfile(os.getcwd()+'/smb-scan.xml')

    return report 
开发者ID:DanMcInerney,项目名称:smb-autopwn,代码行数:13,代码来源:smb-autopwn.py

示例12: urls_from_nmap_xml

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def urls_from_nmap_xml(nmap_file):
        if not path.exists(nmap_file):
            return

        report = NmapParser.parse_fromfile(nmap_file)
        urls = []

        for host in report.hosts:
            #Skip hosts with errors
            if host.address.find(':') != -1:
                continue

            if len(host.hostnames):
                tmp_host = host.hostnames.pop()
            else:
                tmp_host = host.address

            # print("Nmap scan report for {0} ({1})".format(tmp_host, host.address))
            # print("Host is {0}.".format(host.status))
            # print("  PORT     STATE         SERVICE")

            for serv in host.services:
                # pserv = "{0:>5s}/{1:3s}  {2:12s}  {3}".format(
                #     str(serv.port),
                #     serv.protocol,
                #     serv.state,
                #     serv.service)
                # if len(serv.banner):
                #     pserv += " ({0})".format(serv.banner)
                #print(pserv)
                svc = serv.service.lower()
                if serv.state == 'open' and svc.find('http') != -1:
                    if svc.find('ssl'):
                        proto = 'https'
                    else:
                        proto = 'http'

                    urls.append('%s://%s:%i/' % (proto, host.address, serv.port))
                    if tmp_host != host.address:
                        urls.append('%s://%s:%i/' % (proto, tmp_host, serv.port))
        return urls 
开发者ID:0x90,项目名称:pentest,代码行数:43,代码来源:screenz.py

示例13: parse_nmap

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def parse_nmap(args):
    '''
    Either performs an Nmap scan or parses an Nmap xml file
    Will either return the parsed report or exit script
    '''
    if args.xml:
        try:
            report = NmapParser.parse_fromfile(args.xml)
        except IOError:
            print_bad('Host file not found: {}'.format(args.xml))
            sys.exit()

    elif args.hostlist:
        hosts = []
        with open(args.hostlist, 'r') as hostlist:
            host_lines = hostlist.readlines()
            for line in host_lines:
                line = line.strip()
                try:
                    if '/' in line:
                        hosts += [str(ip) for ip in IPNetwork(line)]
                    elif '*' in line:
                        print_bad('CIDR notation only in the host list, e.g. 10.0.0.0/24')
                        sys.exit()
                    else:
                        hosts.append(line)
                except (OSError, AddrFormatError):
                    print_bad('Error importing host list file. Are you sure you chose the right file?')
                    sys.exit()

        report = nmap_scan(hosts, 'autopwn-scan', args.nmap_args)

    else:
        print_bad('Specify hostlist with: -l <hostlist.txt>')
        sys.exit()

    return report 
开发者ID:DanMcInerney,项目名称:msf-autopwn,代码行数:39,代码来源:msf-autopwn.py

示例14: nmap_scan

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def nmap_scan(hosts, outfile, add_args):
    '''
    Do Nmap scan
    '''
    nmap_args = '-sS -O -T4 -sV -n {} --max-retries 5 -oA {}'.format(add_args, outfile)
    print_info('Running: nmap {}'.format(nmap_args))
    nmap_proc = NmapProcess(targets=hosts, options=nmap_args, safe_mode=False)
    rc = nmap_proc.sudo_run_background()
    nmap_status_printer(nmap_proc)
    report = NmapParser.parse_fromfile(os.getcwd()+'/{}.xml'.format(outfile))

    return report 
开发者ID:DanMcInerney,项目名称:msf-autopwn,代码行数:14,代码来源:msf-autopwn.py

示例15: read_hosts_from_file

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse_fromfile [as 别名]
def read_hosts_from_file(nmapxmlfile):
    '''
    Reads from a provided nmap XML file and returns an NmapReport object
    '''
    logger.info('Reading hosts from file: ' + str(nmapxmlfile))
    return NmapParser.parse_fromfile(nmapxmlfile) 
开发者ID:lixmk,项目名称:Concierge,代码行数:8,代码来源:hostname-discovery.py


注:本文中的libnmap.parser.NmapParser.parse_fromfile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。