Пример #1
0
def storedata(ip='', port='', hackinfo=None):

    sqlTool = Sqldatatask.getObject()
    localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
    insertdata = []

    hackinfo = SQLTool.escapewordby(str(hackinfo))
    extra = ' on duplicate key update  disclosure=\'' + hackinfo + '\' , timesearch=\'' + localtime + '\''

    insertdata.append((str(ip), port, hackinfo, str(port)))
    dic = {
        "table": config.Config.porttable,
        "select_params": ['ip', 'port', 'disclosure', 'portnumber'],
        "insert_values": insertdata,
        "extra": extra
    }

    if islocalwork == 0:
        work = []
        tempdata = {"func": 'inserttableinfo_byparams', "dic": dic}
        jsondata = uploaditem.UploadData(
            url=webconfig.WebConfig.upload_ip_info,
            way='POST',
            params=tempdata)
        work.append(jsondata)
        temp = uploadtask.getObject()
        temp.add_work(work)

    else:

        sqldatawprk = []

        tempwprk = Sqldata.SqlData('inserttableinfo_byparams', dic)
        sqldatawprk.append(tempwprk)
        sqlTool.add_work(sqldatawprk)
        print 'fuzz 数据存储'
        pass
Пример #2
0
    def callback_result(self, scan_result):

        print '——————'
        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])  #查询ip地址
                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 = ''
                    for i in tmp['scan'][host]['hostnames']:
                        temphostname += str(i.get('name', 'null')) + ' '

                    tempstate = str(tmp['scan'][host]['status'].get(
                        'state', 'null'))
                    if self.islocalwork == 0:
                        work = []
                        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)
                             ]
                        }
                        tempdata = {
                            "func": 'replaceinserttableinfo_byparams',
                            "dic": dic
                        }
                        jsondata = uploaditem.UploadData(
                            url=self.webconfig.upload_ip_info,
                            way='POST',
                            params=tempdata)
                        work.append(jsondata)
                        self.uploadwork.add_work(work)

                    else:
                        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' + 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 = 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)])

                        if self.islocalwork == 0:
                            work = []
                            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))]
                            }
                            tempdata = {
                                "func": 'replaceinserttableinfo_byparams',
                                "dic": dic
                            }
                            jsondata = uploaditem.UploadData(
                                url=self.webconfig.upload_port_info,
                                way='POST',
                                params=tempdata)
                            work.append(jsondata)
                            self.uploadwork.add_work(work)
                        else:
                            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)])

                        if self.islocalwork == 0:
                            work = []
                            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))]
                            }
                            tempdata = {
                                "func": 'replaceinserttableinfo_byparams',
                                "dic": dic
                            }
                            jsondata = uploaditem.UploadData(
                                url=self.webconfig.upload_port_info,
                                way='POST',
                                params=tempdata)
                            work.append(jsondata)
                            self.uploadwork.add_work(work)
                        else:
                            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)
Пример #3
0
    def task(self, req, threadname):
        print threadname + '执行任务中' + str(datetime.datetime.now())

        #         print req[0],req[1],req[2],req[3]
        if req[3] != 'open':
            return ''
        ip = req[1]
        port = req[2]
        productname = req[4]
        nmapscript = req[5]
        head = None
        ans = None
        hackinfo = ''
        keywords = ''
        if req[0] == 'http' or req[0] == 'https':
            if ip[0:4] == 'http':
                address = ip + ':' + port
            else:
                if port == '443':
                    address = 'https' + '://' + ip + ':' + port
                else:

                    address = req[0] + '://' + ip + ':' + port
            print address
            head, ans = self.connectpool.getConnect(address)
            from template_identify import page_identify
            keywords, hackinfo = page_identify.identify_main(
                head=head,
                context=ans,
                ip=ip,
                port=port,
                productname=productname,
                protocol=req[0],
                nmapscript=nmapscript)
        else:
            head, ans, keywords, hackinfo = self.portscan.do_scan(
                head=head,
                context=ans,
                ip=ip,
                port=port,
                name=req[0],
                productname=productname,
                nmapscript=nmapscript)

        localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
        insertdata = []
        temp = str(ans)
        head = SQLTool.escapeword(head)
        msg = SQLTool.escapeword(temp)
        hackinfomsg = SQLTool.escapeword(hackinfo)
        keywords = SQLTool.escapewordby(keywords)
        insertdata.append((ip, port, localtime, str(head), msg, str(port),
                           hackinfomsg, keywords))

        extra = ' on duplicate key update  detail=\'' + msg + '\' ,head=\'' + str(
            head
        ) + '\', timesearch=\'' + localtime + '\',hackinfo=\'' + hackinfomsg + '\',keywords=\'' + str(
            keywords) + '\''
        sqldatawprk = []
        dic = {
            "table":
            self.config.porttable,
            "select_params": [
                'ip', 'port', 'timesearch', 'detail', 'head', 'portnumber',
                'hackinfo', 'keywords'
            ],
            "insert_values":
            insertdata,
            "extra":
            extra
        }

        if self.islocalwork == 0:
            tempdata = {"func": 'inserttableinfo_byparams', "dic": dic}
            jsondata = uploaditem.UploadData(
                url=self.webconfig.upload_port_info,
                way='POST',
                params=tempdata)
            sqldatawprk.append(jsondata)
            self.uploadwork.add_work(sqldatawprk)
        else:

            tempwprk = Sqldata.SqlData('inserttableinfo_byparams', dic)
            sqldatawprk.append(tempwprk)
            self.sqlTool.add_work(sqldatawprk)


#         inserttableinfo_byparams(table=self.config.porttable,select_params=['ip','port','timesearch','detail'],insert_values=insertdata,extra=extra)

#         self.sqlTool.closedb()
        print threadname + '任务结束' + str(datetime.datetime.now())

        return ans
Пример #4
0
    def task(self, req, threadname):
        print 'the ip is ' + req
        ip = req
        jsondata = webtool.getLocationinfo(req)
        country, country_id, area, area_id, region, region_id, city, city_id, county, county_id, isp, isp_id = getlocationjsondata(
            jsondata)
        localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))

        insertdata = []

        insertdata.append(
            (ip, country, country_id, area, area_id, region, region_id, city,
             city_id, county, county_id, isp, isp_id, localtime))

        extra = ' on duplicate key update  updatetime=' + SQLTool.formatstring(
            localtime) + ',country=' + SQLTool.formatstring(
                country) + ', country_id=' + SQLTool.formatstring(
                    country_id) + ',area=' + SQLTool.formatstring(
                        area) + ', area_id=' + SQLTool.formatstring(
                            area_id) + ',region=' + SQLTool.formatstring(
                                region
                            ) + ', region_id=' + SQLTool.formatstring(
                                region_id) + ',city=' + SQLTool.formatstring(
                                    city
                                ) + ', city_id=' + SQLTool.formatstring(
                                    city_id
                                ) + ',county=' + SQLTool.formatstring(
                                    county
                                ) + ', county_id=' + SQLTool.formatstring(
                                    county_id
                                ) + ',isp=' + SQLTool.formatstring(
                                    isp) + ', isp_id=' + SQLTool.formatstring(
                                        isp_id)

        sqldatawprk = []
        dic = {
            "table":
            self.config.iptable,
            "select_params": [
                'ip', 'country', 'country_id', 'area', 'area_id', 'region',
                'region_id', 'city', 'city_id', 'county', 'county_id', 'isp',
                'isp_id', 'updatetime'
            ],
            "insert_values":
            insertdata,
            "extra":
            extra
        }
        if self.islocalwork == 0:
            tempdata = {"func": 'inserttableinfo_byparams', "dic": dic}
            jsondata = uploaditem.UploadData(url=self.webconfig.upload_ip_info,
                                             way='POST',
                                             params=tempdata)
            sqldatawprk.append(jsondata)
            self.uploadwork.add_work(sqldatawprk)
        else:

            tempwprk = Sqldata.SqlData('inserttableinfo_byparams', dic)
            sqldatawprk.append(tempwprk)
            self.sqlTool.add_work(sqldatawprk)

        time.sleep(0.1)
        ans = ''
        return ans