Safe_mode设置为True时激活不安全的选项(libnmap)

时间:2016-02-01 16:35:32

标签: python nmap

我试图nmap IP和主机名,但我一直收到错误,"在safe_mode设置为True"时激活了不安全的选项。我已尝试将safe_mode = False和safe_mode = True,以及nmap扫描中没有选项。这是我的代码:

from libnmap.parser import NmapParser
from libnmap.process import NmapProcess

def menu():
    print "Enter 1 for IP input, 2 for Hostname input"
    return input ("Number: ")

#Begin NMAP scan
def nmaprun():
    print ip
    nm = NmapProcess(ip, options="-sV -oX test.xml safe_mode=False")
    rc = nm.run()

def nmapparse():
    print "Nmap Information: "
    rep = NmapParser.parse_fromfile('test.xml')

#Parses the NMAP Information in a readable format
    for _host in rep.hosts:
            if _host.is_up():
                print("Host: {0} {1}".format(_host.address,
                                       " "      .join(_host.hostnames)))

        # get CPE from service if available
            for s in _host.services:
                    print("    Service: {0}/{1} ({2}) ({3}) {4}".format(s.port,
                                                                s.protocol,
                                                                s.state,
                                        s.service,
                                        s.banner))
            # NmapService.cpelist returns an array of CPE objects
                    for _serv_cpe in s.cpelist:
                        print("        CPE: {0}".format(_serv_cpe.cpestring))



            if _host.os_fingerprinted:
                    print("  OS Fingerprints")
                    for osm in _host.os.osmatches:
                        print("    Found Match:{0} ({1}%)".format(osm.name,
                                                          osm.accuracy))
                # NmapOSMatch.get_cpe() method return an array of string
                # unlike NmapOSClass.cpelist which returns an array of CPE obj
                        for cpe in osm.get_cpe():
                                print("\t    CPE: {0}".format(cpe))

loop = 1
while loop == 1:
    choice = menu()
    if choice == 1:
        ip = raw_input("Enter your IP: \n")
        loop = 0
    elif choice == 2:
        hostname = raw_input("Enter your hostname: \n")
        loop = 0
    elif choice > 2 or choice < 1:
        print "No options selected"
        loop = 0

nmaprun()
nmapparse()

1 个答案:

答案 0 :(得分:1)

safe_modeNmapProcess的参数,不是选项:

nm = NmapProcess(ip, options="-sV -oX test.xml", safe_mode=False)

我通过查看source code

来找出答案
class NmapProcess(Thread):
    def __init__(self, targets="127.0.0.1",
                 options="-sT", event_callback=None, safe_mode=True, fqp=None):