Ejemplo n.º 1
0
    def callback_result(self, scan_result):

        tmp = scan_result

        for i in tmp['scan'].keys():

            host = i
            result = ''
            try:
                #                 result =  u"ip地址:%s 主机名:%s  ......  %s\n" %(host,tmp['scan'][host].get('hostnames','null'),tmp['scan'][host]['status'].get('state','null'))
                #                 self.sqlTool.connectdb()
                #                 print tmp['scan'][host].get('hostname','null')
                #                 if 'osclass' in tmp['scan'][host].keys():
                #                     result +=u"系统信息 : %s %s %s   准确度:%s  \n" % (str(tmp['scan'][host]['osclass'].get('vendor','null')),str(tmp['scan'][host]['osclass'].get('osfamily','null')),str(tmp['scan'][host]['osclass'].get('osgen','null')),str(tmp['scan'][host]['osclass'].get('accuracy','null')))
                #                 print result
                temphosts = str(host)
                localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
                self.getlocationtool.add_work([temphosts])
                try:

                    tempvendor = 'null'
                    temposfamily = 'null'
                    temposgen = 'null'
                    tempaccuracy = 'null'
                    if len(tmp['scan'][host]['osmatch']) > 0 and len(
                            tmp['scan'][host]['osmatch'][0]['osclass']) > 0:
                        tempvendor = str(
                            tmp['scan'][host]['osmatch'][0]['osclass'][0].get(
                                'vendor', 'null'))

                        temposfamily = str(
                            tmp['scan'][host]['osmatch'][0]['osclass'][0].get(
                                'osfamily', 'null'))

                        temposgen = str(
                            tmp['scan'][host]['osmatch'][0]['osclass'][0].get(
                                'osgen', 'null'))

                        tempaccuracy = str(
                            tmp['scan'][host]['osmatch'][0]['osclass'][0].get(
                                'accuracy', 'null'))

                    temphostname = ''
                    tempdecide = tmp['scan'][host].get('hostnames', [])
                    if len(tempdecide) > 0:
                        for y in tmp['scan'][host]['hostnames']:
                            temphostname += str(y.get('name', 'unknow')) + ' '

                    tempstate = str(tmp['scan'][host]['status'].get(
                        'state', 'null'))
                    #                 print temphosts,tempvendor,temposfamily,temposgen,tempaccuracy,localtime

                    #                 self.sqlTool.replaceinserttableinfo_byparams(table=self.config.iptable,select_params= ['ip','vendor','osfamily','osgen','accurate','updatetime','hostname','state'],insert_values= [(temphosts,tempvendor,temposfamily,temposgen,tempaccuracy,localtime,temphostname,tempstate)])
                    sqldatawprk = []
                    dic = {
                        "table":
                        self.config.iptable,
                        "select_params": [
                            'ip', 'vendor', 'osfamily', 'osgen', 'accurate',
                            'updatetime', 'hostname', 'state'
                        ],
                        "insert_values":
                        [(temphosts, tempvendor, temposfamily, temposgen,
                          tempaccuracy, localtime, temphostname, tempstate)]
                    }

                    tempwprk = Sqldata.SqlData(
                        'replaceinserttableinfo_byparams', dic)

                    sqldatawprk.append(tempwprk)
                    self.sqlTool.add_work(sqldatawprk)
                except Exception, e:
                    print 'nmap system error d ' + str(e)

                if 'tcp' in tmp['scan'][host].keys():
                    ports = tmp['scan'][host]['tcp'].keys()

                    for port in ports:
                        #                     portinfo = " port : %s  name:%s  state : %s  product : %s version :%s  script:%s \n" %(port,tmp['scan'][host]['tcp'][port].get('name',''),tmp['scan'][host]['tcp'][port].get('state',''),   tmp['scan'][host]['tcp'][port].get('product',''),tmp['scan'][host]['tcp'][port].get('version',''),tmp['scan'][host]['tcp'][port].get('script',''))
                        tempport = str(port)
                        tempportname = str(tmp['scan'][host]['tcp'][port].get(
                            'name', ''))
                        tempportstate = str(tmp['scan'][host]['tcp'][port].get(
                            'state', ''))
                        tempproduct = str(tmp['scan'][host]['tcp'][port].get(
                            'product', ''))
                        tempportversion = str(
                            tmp['scan'][host]['tcp'][port].get('version', ''))
                        tempscript = SQLTool.decodestr(
                            str(tmp['scan'][host]['tcp'][port].get(
                                'script', {})))

                        #                         self.sqlTool.replaceinserttableinfo_byparams(table=self.config.porttable,select_params= ['ip','port','timesearch','state','name','product','version','script'],insert_values= [(temphosts,tempport,localtime,tempportstate,tempportname,tempproduct,tempportversion,tempscript)])
                        sqldatawprk = []
                        dic = {
                            "table":
                            self.config.porttable,
                            "select_params": [
                                'ip', 'port', 'timesearch', 'state', 'name',
                                'product', 'version', 'script', 'portnumber'
                            ],
                            "insert_values":
                            [(temphosts, tempport, localtime, tempportstate,
                              tempportname, tempproduct, tempportversion,
                              tempscript, str(tempport))]
                        }
                        tempwprk = Sqldata.SqlData(
                            'replaceinserttableinfo_byparams', dic)

                        sqldatawprk.append(tempwprk)
                        self.sqlTool.add_work(sqldatawprk)
                        self.portscan.add_work([
                            (tempportname, temphosts, tempport, tempportstate,
                             tempproduct, tempscript)
                        ])

                elif 'udp' in tmp['scan'][host].keys():
                    ports = tmp['scan'][host]['udp'].keys()
                    for port in ports:
                        #                         portinfo = " port : %s  name:%s  state : %s  product : %s version :%s  script:%s \n" %(port,tmp['scan'][host]['udp'][port].get('name',''),tmp['scan'][host]['udp'][port].get('state',''),   tmp['scan'][host]['udp'][port].get('product',''),tmp['scan'][host]['udp'][port].get('version',''),tmp['scan'][host]['udp'][port].get('script',''))
                        #                         result = result + portinfo
                        tempport = str(port)
                        tempportname = str(tmp['scan'][host]['udp'][port].get(
                            'name', ''))
                        tempportstate = str(tmp['scan'][host]['udp'][port].get(
                            'state', ''))
                        tempproduct = str(tmp['scan'][host]['udp'][port].get(
                            'product', ''))
                        tempportversion = str(
                            tmp['scan'][host]['udp'][port].get('version', ''))
                        tempscript = str(tmp['scan'][host]['udp'][port].get(
                            'script', ''))

                        #                         self.sqlTool.replaceinserttableinfo_byparams(table=self.config.porttable,select_params= ['ip','port','timesearch','state','name','product','version','script'],insert_values= [(temphosts,tempport,localtime,tempportstate,tempportname,tempproduct,tempportversion,tempscript)])
                        sqldatawprk = []
                        dic = {
                            "table":
                            self.config.porttable,
                            "select_params": [
                                'ip', 'port', 'timesearch', 'state', 'name',
                                'product', 'version', 'script', 'portnumber'
                            ],
                            "insert_values":
                            [(temphosts, tempport, localtime, tempportstate,
                              tempportname, tempproduct, tempportversion,
                              tempscript, str(tempport))]
                        }
                        tempwprk = Sqldata.SqlData(
                            'replaceinserttableinfo_byparams', dic)

                        sqldatawprk.append(tempwprk)
                        self.sqlTool.add_work(sqldatawprk)
            except Exception, e:
                print 'nmap error' + str(e)
Ejemplo n.º 2
0
    def callback_result(self, scan_result):
        self.logger.info(
            "End scanaddress, execute sniffertool::callback_result store into DB."
        )
        tmp = scan_result
        for i in tmp['scan'].keys():
            host = i
            result = ''
            try:
                temphosts = str(host)
                localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
                self.getlocationtool.add_work(
                    [temphosts]
                )  #why add this operator? 在网页上没有执行zmap扫描,所以需要加入位置信息的判断,但是后端添加的任务,相当于执行了两次这个位置信息的扫描
                try:
                    tempvendor = ''
                    temposfamily = ''
                    temposgen = ''
                    tempaccuracy = ''
                    if len(tmp['scan'][host]['osmatch']) > 0 and len(
                            tmp['scan'][host]['osmatch'][0]['osclass']) > 0:
                        tempvendor = str(
                            tmp['scan'][host]['osmatch'][0]['osclass'][0].get(
                                'vendor', ''))
                        temposfamily = str(
                            tmp['scan'][host]['osmatch'][0]['osclass'][0].get(
                                'osfamily', ''))
                        temposgen = str(
                            tmp['scan'][host]['osmatch'][0]['osclass'][0].get(
                                'osgen', ''))
                        tempaccuracy = str(
                            tmp['scan'][host]['osmatch'][0]['osclass'][0].get(
                                'accuracy', ''))
                    temphostname = ''
                    tempdecide = tmp['scan'][host].get('hostnames', [])
                    if len(tempdecide) > 0:
                        for y in tmp['scan'][host]['hostnames']:
                            temphostname += str(y.get('name', 'unknow')) + ' '
                    tempstate = str(tmp['scan'][host]['status'].get(
                        'state', ''))

                    sqldatawprk = []
                    dic = {
                        "table":
                        self.config.iptable,
                        "select_params": [
                            'ip', 'vendor', 'osfamily', 'osgen', 'accurate',
                            'updatetime', 'hostname', 'state'
                        ],
                        "insert_values":
                        [(temphosts, tempvendor, temposfamily, temposgen,
                          tempaccuracy, localtime, temphostname, tempstate)]
                    }

                    tempwprk = Sqldata.SqlData(
                        'replaceinserttableinfo_byparams', dic)
                    sqldatawprk.append(tempwprk)
                    self.sqlTool.add_work(sqldatawprk)
                except Exception, e:
                    self.logger.error('Nmap system Error::' + str(e))


#                    print 'nmap system error d '+str(e)

                if 'tcp' in tmp['scan'][host].keys():
                    ports = tmp['scan'][host]['tcp'].keys()

                    for port in ports:
                        tempport = str(port)
                        tempportname = str(tmp['scan'][host]['tcp'][port].get(
                            'name', ''))
                        tempportstate = str(tmp['scan'][host]['tcp'][port].get(
                            'state', ''))
                        tempproduct = str(tmp['scan'][host]['tcp'][port].get(
                            'product', ''))
                        tempportversion = str(
                            tmp['scan'][host]['tcp'][port].get('version', ''))
                        tempscript = SQLTool.decodestr(
                            str(tmp['scan'][host]['tcp'][port].get(
                                'script', '')))

                        if tempportstate.find('open') == -1:
                            self.logger.info(
                                "[%s:%s] %s has been %s, passing...%s",
                                temphosts, tempport, tempportname,
                                tempportstate, tempproduct)
                            continue

                        sqldatawprk = []
                        dic = {
                            "table":
                            self.config.porttable,
                            "select_params": [
                                'ip', 'port', 'timesearch', 'state', 'name',
                                'product', 'version', 'script', 'portnumber'
                            ],
                            "insert_values":
                            [(temphosts, tempport, localtime, tempportstate,
                              tempportname, tempproduct, tempportversion,
                              tempscript, str(tempport))]
                        }
                        tempwprk = Sqldata.SqlData(
                            'replaceinserttableinfo_byparams', dic)

                        sqldatawprk.append(tempwprk)
                        self.sqlTool.add_work(sqldatawprk)
                        # 端口扫描(正常协议|非正常协议)
                        self.portscan.add_work([
                            (tempportname, temphosts, tempport, tempportstate,
                             tempproduct, tempscript)
                        ])
                elif 'udp' in tmp['scan'][host].keys():
                    ports = tmp['scan'][host]['udp'].keys()
                    for port in ports:
                        tempport = str(port)
                        tempportname = str(tmp['scan'][host]['udp'][port].get(
                            'name', ''))
                        tempportstate = str(tmp['scan'][host]['udp'][port].get(
                            'state', ''))
                        tempproduct = str(tmp['scan'][host]['udp'][port].get(
                            'product', ''))
                        tempportversion = str(
                            tmp['scan'][host]['udp'][port].get('version', ''))
                        tempscript = str(tmp['scan'][host]['udp'][port].get(
                            'script', ''))

                        sqldatawprk = []
                        dic = {
                            "table":
                            self.config.porttable,
                            "select_params": [
                                'ip', 'port', 'timesearch', 'state', 'name',
                                'product', 'version', 'script', 'portnumber'
                            ],
                            "insert_values":
                            [(temphosts, tempport, localtime, tempportstate,
                              tempportname, tempproduct, tempportversion,
                              tempscript, str(tempport))]
                        }
                        tempwprk = Sqldata.SqlData(
                            'replaceinserttableinfo_byparams', dic)
                        sqldatawprk.append(tempwprk)
                        self.sqlTool.add_work(sqldatawprk)
            except Exception, e:
                self.logger.error('Nmap Error' + str(e))
Ejemplo n.º 3
0
    def callback_result(self,scan_result):



        tmp=scan_result

        for i in tmp['scan'].keys():

            host=i
            result=''
            try:
#                 result =  u"ip地址:%s 主机名:%s  ......  %s\n" %(host,tmp['scan'][host].get('hostnames','null'),tmp['scan'][host]['status'].get('state','null'))
#                 self.sqlTool.connectdb()
#                 print tmp['scan'][host].get('hostname','null')
#                 if 'osclass' in tmp['scan'][host].keys():
#                     result +=u"系统信息 : %s %s %s   准确度:%s  \n" % (str(tmp['scan'][host]['osclass'].get('vendor','null')),str(tmp['scan'][host]['osclass'].get('osfamily','null')),str(tmp['scan'][host]['osclass'].get('osgen','null')),str(tmp['scan'][host]['osclass'].get('accuracy','null')))
#                 print result
                temphosts=str(host)
                localtime=str(time.strftime("%Y-%m-%d %X", time.localtime()))
                self.getlocationtool.add_work([temphosts])
                try :

                    tempvendor='null'
                    temposfamily='null'
                    temposgen='null'
                    tempaccuracy='null'
                    if len(tmp['scan'][host]['osmatch'])>0 and len(tmp['scan'][host]['osmatch'][0]['osclass'])>0:
                        tempvendor=str(tmp['scan'][host]['osmatch'][0]['osclass'][0].get('vendor','null'))

                        temposfamily=str(tmp['scan'][host]['osmatch'][0]['osclass'][0].get('osfamily','null'))
              
                        temposgen=str(tmp['scan'][host]['osmatch'][0]['osclass'][0].get('osgen','null'))
                  
                        tempaccuracy=str(tmp['scan'][host]['osmatch'][0]['osclass'][0].get('accuracy','null'))

                    temphostname=''
                    tempdecide=tmp['scan'][host].get('hostnames',[])
                    if len(tempdecide)>0:
                        for y in tmp['scan'][host]['hostnames']:
                            temphostname+=str(y.get('name','unknow'))+' '
                
                    tempstate=str(tmp['scan'][host]['status'].get('state','null'))
#                 print temphosts,tempvendor,temposfamily,temposgen,tempaccuracy,localtime

#                 self.sqlTool.replaceinserttableinfo_byparams(table=self.config.iptable,select_params= ['ip','vendor','osfamily','osgen','accurate','updatetime','hostname','state'],insert_values= [(temphosts,tempvendor,temposfamily,temposgen,tempaccuracy,localtime,temphostname,tempstate)])         
                    sqldatawprk=[]
                    dic={"table":self.config.iptable,"select_params": ['ip','vendor','osfamily','osgen','accurate','updatetime','hostname','state'],"insert_values": [(temphosts,tempvendor,temposfamily,temposgen,tempaccuracy,localtime,temphostname,tempstate)]}
                    tempwprk=Sqldata.SqlData('replaceinserttableinfo_byparams',dic)
                    sqldatawprk.append(tempwprk)
                    self.sqlTool.add_work(sqldatawprk)               
                except Exception,e:
                    print 'nmap system error d '+str(e)
                
                if 'tcp' in  tmp['scan'][host].keys():
                    ports = tmp['scan'][host]['tcp'].keys()

                    for port in ports:
#                     portinfo = " port : %s  name:%s  state : %s  product : %s version :%s  script:%s \n" %(port,tmp['scan'][host]['tcp'][port].get('name',''),tmp['scan'][host]['tcp'][port].get('state',''),   tmp['scan'][host]['tcp'][port].get('product',''),tmp['scan'][host]['tcp'][port].get('version',''),tmp['scan'][host]['tcp'][port].get('script',''))
                        tempport=str(port)
                        tempportname=str(tmp['scan'][host]['tcp'][port].get('name',''))
                        tempportstate=str(tmp['scan'][host]['tcp'][port].get('state',''))
                        tempproduct=str(tmp['scan'][host]['tcp'][port].get('product',''))
                        tempportversion=str(tmp['scan'][host]['tcp'][port].get('version',''))
                        tempscript=SQLTool.decodestr(str(tmp['scan'][host]['tcp'][port].get('script',{})))


#                         self.sqlTool.replaceinserttableinfo_byparams(table=self.config.porttable,select_params= ['ip','port','timesearch','state','name','product','version','script'],insert_values= [(temphosts,tempport,localtime,tempportstate,tempportname,tempproduct,tempportversion,tempscript)])         
                        sqldatawprk=[]
                        dic={"table":self.config.porttable,"select_params": ['ip','port','timesearch','state','name','product','version','script','portnumber'],"insert_values": [(temphosts,tempport,localtime,tempportstate,tempportname,tempproduct,tempportversion,tempscript,str(tempport))]}
                        tempwprk=Sqldata.SqlData('replaceinserttableinfo_byparams',dic)
                        sqldatawprk.append(tempwprk)
                        self.sqlTool.add_work(sqldatawprk)
                        self.portscan.add_work([(tempportname,temphosts,tempport,tempportstate,tempproduct,tempscript)])





                elif 'udp' in  tmp['scan'][host].keys():
                    ports = tmp['scan'][host]['udp'].keys()
                    for port in ports:
#                         portinfo = " port : %s  name:%s  state : %s  product : %s version :%s  script:%s \n" %(port,tmp['scan'][host]['udp'][port].get('name',''),tmp['scan'][host]['udp'][port].get('state',''),   tmp['scan'][host]['udp'][port].get('product',''),tmp['scan'][host]['udp'][port].get('version',''),tmp['scan'][host]['udp'][port].get('script',''))
#                         result = result + portinfo
                        tempport=str(port)
                        tempportname=str(tmp['scan'][host]['udp'][port].get('name',''))
                        tempportstate=str(tmp['scan'][host]['udp'][port].get('state',''))
                        tempproduct=str(tmp['scan'][host]['udp'][port].get('product',''))
                        tempportversion=str(tmp['scan'][host]['udp'][port].get('version',''))
                        tempscript=str(tmp['scan'][host]['udp'][port].get('script',''))
                        
#                         self.sqlTool.replaceinserttableinfo_byparams(table=self.config.porttable,select_params= ['ip','port','timesearch','state','name','product','version','script'],insert_values= [(temphosts,tempport,localtime,tempportstate,tempportname,tempproduct,tempportversion,tempscript)])         
                        sqldatawprk=[]
                        dic={"table":self.config.porttable,"select_params": ['ip','port','timesearch','state','name','product','version','script','portnumber'],"insert_values": [(temphosts,tempport,localtime,tempportstate,tempportname,tempproduct,tempportversion,tempscript,str(tempport))]}
                        tempwprk=Sqldata.SqlData('replaceinserttableinfo_byparams',dic)

                        sqldatawprk.append(tempwprk)
                        self.sqlTool.add_work(sqldatawprk)
            except Exception,e:
                print 'nmap error'+str(e)