Example #1
0
    def do_scan(self, port="80", num="10", needdetail="0"):
        path = os.getcwd()
        #         p= Popen(" ./zmap -B  4M -p "+port+" -N "+num+"   -q -O json", stdout=PIPE, shell=True,cwd=path+'/zmap-2.1.0/src')

        p = Popen(
            " zmap -w /root/github/Scan-T/spidermanage/spidertool/iparea.json -B  1M -p "
            + port
            + " -N "
            + num
            + "   -q -O json",
            stdout=PIPE,
            shell=True,
        )
        #        'sudo zmap -p 80 -B 10M -N 50 -q --output-fields=classification,saddr,daddr,sport,dport,seqnum,acknum,cooldown,repeat  -o - '+
        #        '| sudo ./forge-socket -c 50 -d http-req > http-banners.out'

        # p= Popen(" ./zmap -B 10M -p 80 -n 100000 ", stdout=PIPE, shell=True,cwd=path+'/zmap-2.1.0/src')

        p.wait()
        retcode = p.returncode
        if retcode == 0:
            returnmsg = p.stdout.read()
            p = re.compile(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
            list = p.findall(returnmsg)
            #             self.sqlTool.connectdb()
            localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
            insertdata = []
            jobs = []
            for i in list:
                insertdata.append((str(i), port, localtime, "open", str(port)))
                self.getlocationtool.add_work([str(i)])

                if needdetail == "0":
                    global portname
                    nowportname = portname.get(port, "")
                    self.portscan.add_work([(nowportname, str(i), port, "open", "", "")])
                else:

                    ajob = job.Job(jobaddress=str(i), jobport="", forcesearch="0", isjob="0")
                    jobs.append(ajob)
            if needdetail != "0":
                tasktotally = sniffertask.getObject()

                tasktotally.add_work(jobs)
            extra = " on duplicate key update  state='open' , timesearch='" + localtime + "'"

            #             self.sqlTool.inserttableinfo_byparams(table=self.config.porttable,select_params=['ip','port','timesearch','state'],insert_values=insertdata,extra=extra)
            sqldatawprk = []
            dic = {
                "table": self.config.porttable,
                "select_params": ["ip", "port", "timesearch", "state", "portnumber"],
                "insert_values": insertdata,
                "extra": extra,
            }
            tempwprk = Sqldata.SqlData("inserttableinfo_byparams", dic)
            sqldatawprk.append(tempwprk)
            self.sqlTool.add_work(sqldatawprk)
    def do_scan(self, port='8080', num='10', needdetail='0'):
        path = os.getcwd()
        locate = os.path.split(os.path.realpath(__file__))[0]
        cmd = "zmap -w " + locate + "/iparea.json -B 50M -p " + port + " -q -O json"
        import commandtool

        if True:
            returnmsg = commandtool.command(cmd=cmd)
            # print "returnmsg:", returnmsg
            p = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
            ip_list = p.findall(returnmsg)
            localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
            insertdata = []
            jobs = []
            print "\n\nzmaptool get port:%s, open ip: %d个\n\n" % (str(port),
                                                                  len(ip_list))
            for i in ip_list:
                insertdata.append((str(i), port, localtime, 'open', str(port)))
                print("zmaptool scan ip:%s" % i)
                self.getlocationtool.add_work([
                    str(i)
                ])  # save ip info(get from ip.taobao.com) to ip_maindata

                if needdetail == '0':
                    global portname
                    nowportname = portname.get(port, '')
                    self.portscan.add_work([(nowportname, str(i), port, 'open',
                                             '', '')])
                else:
                    # 执行zmap的时候开放后,默认nmap扫描全部端口;但是通过页面添加任务的时候如果指定了端口,不会扫描全部端口
                    ajob = job.Job(jobaddress=str(i),
                                   jobport='',
                                   forcesearch='0',
                                   isjob='0')
                    jobs.append(ajob)
            if needdetail != '0':
                tasktotally = sniffertask.getObject()
                tasktotally.add_work(jobs)
            extra = ' on duplicate key update  state=\'open\' , timesearch=\'' + localtime + '\''
            #             self.sqlTool.inserttableinfo_byparams(table=self.config.porttable,select_params=['ip','port','timesearch','state'],insert_values=insertdata,extra=extra)
            sqldatawprk = []
            dic = {
                "table":
                self.config.porttable,
                "select_params":
                ['ip', 'port', 'timesearch', 'state', 'portnumber'],
                "insert_values":
                insertdata,
                "extra":
                extra
            }
            tempwprk = Sqldata.SqlData('inserttableinfo_byparams', dic)
            sqldatawprk.append(tempwprk)
            self.sqlTool.add_work(sqldatawprk)
Example #3
0
    def do_scan(self,port='80',num='10',needdetail='0'):
        path=os.getcwd()
        locate=os.path.split(os.path.realpath(__file__))[0]
#         p= Popen(" ./zmap -B  4M -p "+port+" -N "+num+"   -q -O json", stdout=PIPE, shell=True,cwd=path+'/zmap-2.1.0/src')
        cmd=" zmap -w "+locate+"/iparea.json  -B  1M -p "+port+" -N "+num+"   -q -O json"
        # p= Popen(" zmap -w /root/github/Scan-T/spidermanage/spidertool/iparea.json -B  1M -p "+port+" -N "+num+"   -q -O json", stdout=PIPE, shell=True)

        import commandtool



#        'sudo zmap -p 80 -B 10M -N 50 -q --output-fields=classification,saddr,daddr,sport,dport,seqnum,acknum,cooldown,repeat  -o - '+
#        '| sudo ./forge-socket -c 50 -d http-req > http-banners.out'

#p= Popen(" ./zmap -B 10M -p 80 -n 100000 ", stdout=PIPE, shell=True,cwd=path+'/zmap-2.1.0/src')

        # p.wait()
        # retcode= p.returncode
        # if retcode==0:
        #     returnmsg=p.stdout.read()
        if True:
            returnmsg=commandtool.command(cmd=cmd)
            p = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
            list= p.findall(returnmsg)
#             self.sqlTool.connectdb()
            localtime=str(time.strftime("%Y-%m-%d %X", time.localtime()))
            insertdata=[]
            jobs=[]
            for i in list:
                insertdata.append((str(i),port,localtime,'open',str(port)))
                self.getlocationtool.add_work([str(i)])

                if needdetail=='0':
                    global portname
                    nowportname=portname.get(port,'')
                    self.portscan.add_work([(nowportname,str(i),port,'open','','')])
                else:
                    
                    ajob=job.Job(jobaddress=str(i),jobport='',forcesearch='0',isjob='0')
                    jobs.append(ajob)
            if needdetail!='0':
                tasktotally=sniffertask.getObject()

                tasktotally.add_work(jobs)
            extra=' on duplicate key update  state=\'open\' , timesearch=\''+localtime+'\''
            
            
#             self.sqlTool.inserttableinfo_byparams(table=self.config.porttable,select_params=['ip','port','timesearch','state'],insert_values=insertdata,extra=extra)
            sqldatawprk=[]
            dic={"table":self.config.porttable,"select_params":['ip','port','timesearch','state','portnumber'],"insert_values":insertdata,"extra":extra}
            tempwprk=Sqldata.SqlData('inserttableinfo_byparams',dic)
            sqldatawprk.append(tempwprk)
            self.sqlTool.add_work(sqldatawprk)
Example #4
0
    def __init__(self):

        self.connectpool = connectpool.getObject()
        self.maintask = sniffertask.getObject()
Example #5
0
    def do_scan(self, port='80', num='10', needdetail='0'):
        path = os.getcwd()
        #         p= Popen(" ./zmap -B  4M -p "+port+" -N "+num+"   -q -O json", stdout=PIPE, shell=True,cwd=path+'/zmap-2.1.0/src')
        cmd = " zmap -w /root/github/Scan-T/spidermanage/spidertool/iparea.json  -B  1M -p " + port + " -N " + num + "   -q -O json"
        # p= Popen(" zmap -w /root/github/Scan-T/spidermanage/spidertool/iparea.json -B  1M -p "+port+" -N "+num+"   -q -O json", stdout=PIPE, shell=True)

        import commandtool

        #        'sudo zmap -p 80 -B 10M -N 50 -q --output-fields=classification,saddr,daddr,sport,dport,seqnum,acknum,cooldown,repeat  -o - '+
        #        '| sudo ./forge-socket -c 50 -d http-req > http-banners.out'

        #p= Popen(" ./zmap -B 10M -p 80 -n 100000 ", stdout=PIPE, shell=True,cwd=path+'/zmap-2.1.0/src')

        # p.wait()
        # retcode= p.returncode
        # if retcode==0:
        #     returnmsg=p.stdout.read()
        if True:
            returnmsg = commandtool.command(cmd=cmd)
            p = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
            list = p.findall(returnmsg)
            #             self.sqlTool.connectdb()
            localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
            insertdata = []
            jobs = []
            for i in list:
                insertdata.append((str(i), port, localtime, 'open', str(port)))
                self.getlocationtool.add_work([str(i)])

                if needdetail == '0':
                    global portname
                    nowportname = portname.get(port, '')
                    self.portscan.add_work([(nowportname, str(i), port, 'open',
                                             '', '')])
                else:

                    ajob = job.Job(jobaddress=str(i),
                                   jobport='',
                                   forcesearch='0',
                                   isjob='0')
                    jobs.append(ajob)
            if needdetail != '0':
                tasktotally = sniffertask.getObject()

                tasktotally.add_work(jobs)
            extra = ' on duplicate key update  state=\'open\' , timesearch=\'' + localtime + '\''

            #             self.sqlTool.inserttableinfo_byparams(table=self.config.porttable,select_params=['ip','port','timesearch','state'],insert_values=insertdata,extra=extra)
            sqldatawprk = []
            dic = {
                "table":
                self.config.porttable,
                "select_params":
                ['ip', 'port', 'timesearch', 'state', 'portnumber'],
                "insert_values":
                insertdata,
                "extra":
                extra
            }
            tempwprk = Sqldata.SqlData('inserttableinfo_byparams', dic)
            sqldatawprk.append(tempwprk)
            self.sqlTool.add_work(sqldatawprk)
Example #6
0
    def do_scan(self, port='8080', num='10', needdetail='0'):
        path = os.getcwd()
        locate = os.path.split(os.path.realpath(__file__))[0]
        cmd = "masscan -c " + locate + "/iparea.conf --source-port 60000"

        import commandtool

        if True:
            returnmsg = commandtool.command(cmd=cmd, timeout=0)
            p = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
            ip_list = p.findall(returnmsg)
            localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
            insertdata = []
            jobs = []
            address_cnt = len(ip_list)

            print "\n\n%s masscantool get open ip: %d个\n\n" % (str(localtime),
                                                               address_cnt)

            a = open(r"data_source_list.txt", "w")
            a.write(json.dumps(ip_list))
            a.close()

            if address_cnt < 1:
                return False

            for i in ip_list:
                ip = str(i).strip()
                insertdata.append((ip, port, localtime, 'open', str(port)))
                # print ("masscantool scan ip:%s"%i)
                self.getlocationtool.add_work([
                    ip
                ])  # save ip info(get from ip.taobao.com) to ip_maindata

                if needdetail == '0':
                    global portname
                    nowportname = portname.get(port, '')
                    # use masscan can know which port is open, so we can use this result to scan port\'s result and detect dangerous
                    self.portscan.add_work([(nowportname, ip, port, 'open', '',
                                             '')])
                else:
                    # 执行masscan的时候开放后,默认nmap扫描全部端口;但是通过页面添加任务的时候如果指定了端口,不会扫描全部端口
                    ajob = job.Job(jobaddress=ip,
                                   jobport='',
                                   forcesearch='0',
                                   isjob='0')
                    jobs.append(ajob)

            # execute nmap scan, should range threadnum
            if needdetail != '0':
                tasktotally = sniffertask.getObject()
                #                tasktotally = sniffertask.getObject(address_cnt/50)
                tasktotally.add_work(jobs)
            extra = ' on duplicate key update  state=\'open\' , timesearch=\'' + localtime + '\''
            #             self.sqlTool.inserttableinfo_byparams(table=self.config.porttable,select_params=['ip','port','timesearch','state'],insert_values=insertdata,extra=extra)
            sqldatawork = []
            dic = {
                "table":
                self.config.porttable,
                "select_params":
                ['ip', 'port', 'timesearch', 'state', 'portnumber'],
                "insert_values":
                insertdata,
                "extra":
                extra
            }
            tempwork = Sqldata.SqlData('inserttableinfo_byparams', dic)
            sqldatawork.append(tempwork)
            self.sqlTool.add_work(sqldatawork)
Example #7
0
    def __init__(self):

        self.connectpool=connectpool.getObject()
        self.maintask=sniffertask.getObject()