From 42186297581fa9ed4f4f69e30cb5dfdf07f7a4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=9C=E6=96=B9=E6=9C=89=E9=B1=BC=E5=90=8D=E4=B8=BA?= =?UTF-8?q?=E5=92=B8?= Date: Thu, 28 Nov 2019 20:56:36 +0800 Subject: [PATCH] Create masscan+nmap.py --- tools/masscan+nmap.py | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tools/masscan+nmap.py diff --git a/tools/masscan+nmap.py b/tools/masscan+nmap.py new file mode 100644 index 0000000..c403a1a --- /dev/null +++ b/tools/masscan+nmap.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +# -*- coding: UTF-8 -*- +# __author__: www.t00ls.net-rabbittb +# modified by mrxn +# you must needed install python-nmap first then nmap with pip3 or pip +import os +import time +import json +import nmap +import sys + +PORT_list = [ + 80, 8080, 8089, 23, 21, 5001, 7001 - 7010, 8888, 6666, 1080, 27017, 6379, + 1433, 3306, 1352, 1521, 11211, 9200, 9300, 9090, 8069, 5900, 443, 5432, + 5632, 4848, 2181 +] + +ports = "80,8080,8089,23,21,5001,7001-7010,8888,6666,1080,27017,6379,1433,3306,1352,1521,11211,9200,9300,9090,8069,5900,443,5432,5632,4848,2181" + + +def masScan(ip_file, ports): + ip_file = ip_file + json_name = str(time.time()) + "_masscan.log" + payload = "masscan -iL {0} -p {2} -oJ {1} --rate 3000".format( + ip_file, json_name, ports) + print(payload) + os.system(payload) + return masscan_parse(json_name) + + +def masscan_parse(log_name): + res_dic = {} + with open(log_name) as f: + for line in f: + if line.startswith('{'): + temp = json.loads(line[:-2]) + if temp['ip'] in res_dic.keys(): + res_dic[temp['ip']].append(str(temp['ports'][0]['port'])) + else: + res_dic[temp['ip']] = [str(temp['ports'][0]['port'])] + return res_dic + + +def callback_result(host, scan_result): + if host in scan_result['scan'].keys( + ) and 'tcp' in scan_result['scan'][host]: + for x in scan_result['scan'][host]['tcp']: + res = { + 'host': host, + 'port': x, + 'service': scan_result['scan'][host]['tcp'][x]['name'], + 'product': scan_result['scan'][host]['tcp'][x]['product'], + 'version': scan_result['scan'][host]['tcp'][x]['version'] + } + print(res) + return res + + +def nmapScan(target_list): + scanner = nmap.PortScannerAsync() + + for target in target_list: + scanner.scan(target, + arguments='-sV -PS -p' + ','.join(target_list[target]), + callback=callback_result) + + while scanner.still_scanning(): + scanner.wait(2) + + +if __name__ == "__main__": + ports = "80,8080,8089,23,21,5001,7001-7010,8888,6666,1080,27017,6379,1433,3306,1352,1521,11211,9200,9300,9090,8069,5900,443,5432,5632,4848,2181" + start = time.time() + # res = masScan("1.txt", ports) + if len(sys.argv) == 2: + res = masScan("{ipfile}".format(ipfile=sys.argv[1]), ports) + nmapScan(res) + elif len(sys.argv) == 1: + print('please input iplist file') + else: + print('error') + print(time.time() - start)