本文整理汇总了Python中libnmap.process.NmapProcess方法的典型用法代码示例。如果您正苦于以下问题:Python process.NmapProcess方法的具体用法?Python process.NmapProcess怎么用?Python process.NmapProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libnmap.process
的用法示例。
在下文中一共展示了process.NmapProcess方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: nmap_scan
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def nmap_scan(hosts, output_dir):
"""
if user chooses to start from an nmap scan, run the scan and then return an nmap_report object
:param hosts:
:param output_dir:
:return:
"""
print("[+] Kicking off nmap scan. I don't have any feedback working, so just be patient")
nm = NmapProcess(hosts, options="-sC -sV -Pn -p1-65535")
rc = nm.run()
nmap_report = NmapParser.parse(nm.stdout)
nmap_xml = output_dir + "/" + hosts.replace("/","_") + "_nmap.xml"
f = open(nmap_xml, 'a')
f.write(nm.stdout)
f.close()
print("[+] Nmap scan saved to: {0}".format(nmap_xml))
return nmap_report
示例2: do_scan
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def do_scan(targets, options, fqp=None):
parsed = None
nm = NmapProcess(targets, options, fqp=fqp)
rc = nm.run()
if rc != 0:
print("nmap scan failed: {0}".format(nm.stderr))
try:
parsed = NmapParser.parse(nm.stdout)
except NmapParserException as e:
print("Exception raised while parsing scan: {0}".format(e.msg))
return parsed
# print scan results from a nmap report
示例3: do_scan
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def do_scan(host, options):
# uncomment line below to manually input target IP
#host = input("Enter Target Host Address: ")
parsed = None
nmproc = NmapProcess(host, options)
rc = nmproc.run()
if rc != 0:
print("nmap scan failed: {0}".format(nmproc.stderr))
print(type(nmproc.stdout))
try:
parsed = NmapParser.parse(nmproc.stdout)
except NmapParserException as e:
print("Exception raised while parsing scan: {0}".format(e.msg))
return parsed
示例4: scan_ranges
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def scan_ranges(ranges, dns=None):
'''
Performs a list scan on the provided ranges and returns an NmapReport object
'''
if dns is None:
dns = "-sL -R"
else:
dns = "-sL -R --dns-server " + dns
logger.info('DNS Value for scan_ranges: ' + str(dns))
logger.info('Provided Ranges for scan_ranges: ' + str(ranges))
print("Starting nmap scan against: " + ranges)
nm = NmapProcess(ranges, options=dns)
rc = nm.run()
# use the nmap parser to return an object containing all the hosts
parsed = NmapParser.parse(nm.stdout)
logger.info('Returning {} hosts from scan_ranges'.format(len(parsed.hosts)))
return parsed
示例5: nmap_follow_up_scan
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def nmap_follow_up_scan(hosts, port):
"""
This needs to be reworked. If nmap service scan can't determine the service, i run an nmap scan without service
detection to get the default port. I should just read the IANA ports file instead and grep for the port, or maybe
even the nmap version of the IANA ports list.
:param hosts:
:param port:
:return:
"""
nm = NmapProcess(hosts, options="-Pn -p %d" % port)
rc = nm.run()
nmap_report = NmapParser.parse(nm.stdout)
return nmap_report
示例6: do_scan
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def do_scan(self, targets, options):
"""
start a new nmap scan on localhost with some specific options
:param targets:
:param options:
:return:
"""
logger.info('do scan %s %s' % (targets, options))
parsed = None
if isinstance(options, basestring):
options = options.encode('utf-8')
if isinstance(targets, basestring):
targets = targets.encode('utf-8')
nmproc = NmapProcess(targets, options)
rc = nmproc.run()
if rc != 0:
logger.error("nmap scan failed: {0}".format(nmproc.stderr))
# print(type(nmproc.stdout))
try:
parsed = NmapParser.parse(nmproc.stdout)
except NmapParserException as e:
logger.error("Exception raised while parsing scan: {0}".format(e.msg))
self.done_data[targets] = parsed
return parsed
# print scan results from a nmap report
示例7: do_task
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def do_task(self,task):
"""
TODO: multiple ip address for same domain name
"""
try:
taskl=task.split('|')
nmap_task=NmapProcess(taskl[0],taskl[1]+' '+' '.join(self._args.nmap_options))
rc=nmap_task.run()
if rc!=0:
return '|'.join([taskl[0],'f',str(rc)+' '+nmap_task.stderr])
return '|'.join([taskl[0],'s',nmap_task.stdout])
# if there is no nmap on current host, quit quietly
except EnvironmentError, e:
raise SwarmUseException(str(e))
示例8: do_scan
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def do_scan(targets, options):
nm = NmapProcess(targets, options)
rc = nm.run()
if rc != 0:
print("nmap scan failed: {0}".format(nm.stderr))
try:
parsed = NmapParser.parse(nm.stdout)
except NmapParserException as e:
print("Exception raised while parsing scan: {0}".format(e.msg))
return parsed
# print scan results from a nmap report
示例9: make_nmproc_obj
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def make_nmproc_obj(targets, options):
return NmapProcess(targets=targets, options=options)
示例10: make_nmproc_obj
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def make_nmproc_obj(targets, options):
return NmapProcess(targets=targets, options=options)
示例11: nmap_scan
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [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
示例12: run
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def run(self):
# Wait until all active devices have been populated during boot
time.sleep(30)
while 1:
ip_list = ','.join(homenet.hosts.keys())
log.debug('FG-INFO: Port scan started')
nm = NmapProcess(targets=ip_list, options='-sU -sS --min-rate 5000 --max-retries 1 --max-rtt-timeout 100ms -p1-10000 ')
nm.run()
try:
nmap_report = NmapParser.parse(nm.stdout)
with lock:
for host in nmap_report.hosts:
if host.address in homenet.hosts.keys():
for serv in host.services:
if (serv.protocol == 'tcp') and (serv.state == 'open'):
if serv.port not in homenet.hosts[host.address].tcp_ports:
homenet.hosts[host.address].tcp_ports.append(serv.port)
if (serv.protocol == 'udp') and (serv.state == 'open'):
if serv.port not in homenet.hosts[host.address].udp_ports:
homenet.hosts[host.address].udp_ports.append(serv.port)
except Exception as e:
log.debug('FG-WARN: ' + str(e.__doc__) + " - " + str(e))
log.debug('FG-INFO: Port scan finished')
time.sleep(86400)
示例13: nmap_scan
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [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
示例14: run
# 需要导入模块: from libnmap import process [as 别名]
# 或者: from libnmap.process import NmapProcess [as 别名]
def run(self):
nm = NmapProcess(targets=str(self.artifact['name']), options='-sT -sV -Pn -T5 -p21,22,23,25,80,6667,1337')
nm.run()
if nm.is_successful():
report = NmapParser.parse_fromstring(nm.stdout)
for host in report.hosts:
if host.is_up():
results = {
'ports': host.get_open_ports(),
'services': []
}
for service in host.services:
if service.state == 'open':
serv = {
'banner': service.banner,
'protocol': service.protocol,
'service': service.service,
'port': service.port}
results['services'].append(serv)
if self.artifact['subtype'] == 'ipv4':
results['hostnames'] = host.hostnames
for h in host.hostnames:
self.artifact['children'].append({
'name': h,
'type': 'host',
'subtype': 'fqdn',
'source': 'Nmap'
})
elif self.artifact['subtype'] == 'fqdn':
results['ipv4'] = host.address
self.artifact['children'].append({
'name': host.address,
'type': 'host',
'subtype': 'ipv4',
'source': 'Nmap'
})
self.artifact['data']['nmap'] = results
else:
warning('Nmap scanner failed - no results')