使用python-nmap不出https踩到的坑
2018-01-19 15:21
274 查看
今天在使用python-nmap来进行扫描入库的时候发现https端口硬生生的给判断成了http
仔细测试了好几次都是这样子。后来果断的不服气,仔细看了下扫描的参数。发现python-nmap调用的时候会强制加上-ox -这个参数正常扫描是
nmap 45.33.49.119 -p T:443 -Pn -sV --script=banner
然而经过python-nmap以后就是
经过格式化以后看到的内容是
其中的一个参数tunnel.但是看了下https://bitbucket.org/xael/python-nmap/raw/8ed37a2ac20d6ef26ead60d36f739f4679fcdc3e/nmap/nmap.py这里的内容。发现没有与之关联的。
试想下如果把name以及tunnel取出来同时匹配不就好了。于是对此进行修改。410-440行
还有在654-670行里面增加我们添加的tunnel
然后我们import这个文件。在获取的内容里面进行判断.如果name为http的同时tunnel为ssl,则判断为https
仔细测试了好几次都是这样子。后来果断的不服气,仔细看了下扫描的参数。发现python-nmap调用的时候会强制加上-ox -这个参数正常扫描是
nmap 45.33.49.119 -p T:443 -Pn -sV --script=banner
然而经过python-nmap以后就是
其中的一个参数tunnel.但是看了下https://bitbucket.org/xael/python-nmap/raw/8ed37a2ac20d6ef26ead60d36f739f4679fcdc3e/nmap/nmap.py这里的内容。发现没有与之关联的。
for dport in dhost.findall('ports/port'): # protocol proto = dport.get('protocol') # port number converted as integer port = int(dport.get('portid')) # state of the port state = dport.find('state').get('state') # reason reason = dport.find('state').get('reason') # name, product, version, extra info and conf if any name = product = version = extrainfo = conf = cpe = '' for dname in dport.findall('service'): name = dname.get('name') if dname.get('product'): product = dname.get('product') if dname.get('version'): version = dname.get('version') if dname.get('extrainfo'): extrainfo = dname.get('extrainfo') if dname.get('conf'): conf = dname.get('conf') for dcpe in dname.findall('cpe'): cpe = dcpe.text # store everything if not proto in list(scan_result['scan'][host].keys()): scan_result['scan'][host][proto] = {} scan_result['scan'][host][proto][port] = {'state': state, 'reason': reason, 'name': name, 'product': product, 'version': version, 'extrainfo': extrainfo, 'conf': conf, 'cpe': cpe}
试想下如果把name以及tunnel取出来同时匹配不就好了。于是对此进行修改。410-440行
name = product = version = extrainfo = conf = cpe = tunnel ='' for dname in dport.findall('service'): name = dname.get('name') if dname.get('product'): product = dname.get('product') if dname.get('version'): version = dname.get('version') if dname.get('extrainfo'): extrainfo = dname.get('extrainfo') if dname.get('conf'): conf = dname.get('conf') if dname.get('tunnel'): tunnel = dname.get('tunnel') for dcpe in dname.findall('cpe'): cpe = dcpe.text # store everything if not proto in list(scan_result['scan'][host].keys()): scan_result['scan'][host][proto] = {} scan_result['scan'][host][proto][port] = {'state': state, 'reason': reason, 'name': name, 'product': product, 'version': version, 'extrainfo': extrainfo, 'conf': conf, 'tunnel':tunnel, 'cpe': cpe}
还有在654-670行里面增加我们添加的tunnel
csv_ouput = csv.writer(fd, delimiter=';') csv_header = [ 'host', 'hostname', 'hostname_type', 'protocol', 'port', 'name', 'state', 'product', 'extrainfo', 'reason', 'version', 'conf', 'tunnel', 'cpe' ]
然后我们import这个文件。在获取的内容里面进行判断.如果name为http的同时tunnel为ssl,则判断为https
for targetHost in scanner.all_hosts(): if scanner[targetHost].state() == 'up' and scanner[targetHost]['tcp']: for targetport in scanner[targetHost]['tcp']: #print(scanner[targetHost]['tcp'][int(targetport)]) if scanner[targetHost]['tcp'][int(targetport)]['state'] == 'open' and scanner[targetHost]['tcp'][int(targetport)]['product']!='tcpwrapped': if scanner[targetHost]['tcp'][int(targetport)]['name']=='http' and scanner[targetHost]['tcp'][int(targetport)]['tunnel'] == 'ssl': scanner[targetHost]['tcp'][int(targetport)]['name'] = 'https' else: scanner[targetHost]['tcp'][int(targetport)]['name'] = scanner[targetHost]['tcp'][int(targetport)]['name'] print(domain+'\t'+targetHosts+'\t'+str(targetport) + '\t' + scanner[targetHost]['tcp'][int(targetport)]['name'] + '\t' + scanner[targetHost]['tcp'][int(targetport)]['product']+scanner[targetHost]['tcp'][int(targetport)]['version']) #if scanner[targetHost]['tcp'][int(targetport)]['name'] in ["https","http"]:改造后的文件扫描结果
相关文章推荐
- 使用nmap或者python-nmap时出现错误
- 简单介绍python-nmap 模块的使用
- python使用nmap管理网络的编程初探
- 简单端口扫描器Python实现(附Python-Nmap简单使用)
- python-nmap使用及案例
- Python使用urlib添加头部实现https请求 同时使用PyExecJS-1.4.0触发JS
- 端口扫描工具python-nmap的使用
- Python使用Socket(Https)Post登录百度的实现代码
- 使用pip install时报错:ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed
- 解决Python 2.7.x 使用Requests发起https请求时报Warning的问题
- 问题的原因是“SSL: CERTIFICATE_VERIFY_FAILED”。 Python 升级到 2.7.9 之后引入了一个新特性,当使用urllib.urlopen打开一个 https 链接时,
- 使用Python请求http/https时设置失败重试次数
- Python使用requests模块访问HTTPS网站报错`certificate verify failed`
- 对python使用http、https代理的实例讲解
- Python urllib2的使用点滴: cookie, https, put, 500/403的处理 | 半瓶墨水 - 任中方
- Python 使用python-nmap模块实现端口扫描器 推荐
- python 使用urllib2进行https请求时出现'ascii' codec can't decode byte 0xe9 错误
- Python使用Socket(Https)Post登录百度的实现代码
- windows10下使用pyopenssl, pycurl 访问https网站(python)
- python使用requests时报错requests.exceptions.SSLError: HTTPSConnectionPool