Example #1
0
    def getIplist(self,startip,endip):
        ip_list = []
        res = ()
        res = self.iprange(startip,endip)
        if res < 0:
            print 'endip must be bigger than startone'
            return 
        else:
            jobs=[]
            ipsize=int(res[2])+1

            for x in xrange(ipsize):
                startipnum = self.ip2num(startip)
                startipnum = startipnum + x
                ip=self.num2ip(startipnum)
#                 self.getlocationtool.add_work([str(ip)])
                ajob=job.Job(jobaddress=str(ip),jobport='',forcesearch='0',isjob='0')

#                 tasktotally=taskcontrol.getObject()
#                 
#                 tasktotally.add_work([ajob])

                jobs.append(ajob)
                if len(jobs)==10 or x==ipsize-1:
                    tasktotally=taskcontrol.getObject()
                 
                    tasktotally.add_work(jobs)
                    time.sleep(1)
                    jobs=[]
Example #2
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  4M -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'))
                self.getlocationtool.add_work([str(i)])

                if needdetail == '0':
                    global portname
                    nowportname = portname.get(port, 'http')
                    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 = taskcontrol.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'],
                "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 #4
0
        hosts=req.getJobaddress();
        ports=req.getPort()
        arguments=req.getArgument()
        isjob=req.getisJob()
        if isjob=='1':
            tempresult=jobcontrol.jobupdate(jobstatus='3',taskid=jobid,starttime=webtool.getlocaltime())
        ans = self.sniffer.scanaddress([hosts], [str(ports)], arguments)
        self.logger and self.logger.info('%sNMAP 扫描任务结束%s', threadname,str(datetime.datetime.now()))

        if isjob=='1':
            tempresult=jobcontrol.jobupdate(jobstatus='5',taskid=jobid,finishtime=webtool.getlocaltime())
        return ans
    
if __name__ == "__main__":   
    links = []
    temp= job.Job(jobaddress='www.bnuz.edu.cn',jobport='400-800',jobname='task1')
    temp1=  job.Job(jobaddress='localhost',jobport='400-800',jobname='task2')
    temp2=  job.Job(jobaddress='www.cctv.com',jobport='400-800',jobname='task3')
    temp3=  job.Job(jobaddress='www.vip.com',jobport='400-800',jobname='task4')
    links.append(temp)
    links.append(temp1)
    links.append(temp2)
    links.append(temp3)
    S_produce= snifferTask(1)#表示创建的是线程
    S_produce.set_deal_num(10)
    starttime = datetime.datetime.now()



    S_produce.add_work(links)
#     while S_produce.has_work_left():
Example #5
0
    def getIplist(self, startip, endip, taskid, taskport, isjob, username,
                  command, status):
        ip_list = []

        res = ()
        res = self.iprange(startip, endip)
        if res < 0:
            print 'endip must be bigger than startone'
            return
        else:
            jobs = []
            ipsize = int(res[2]) + 1
            insertdata = []
            for x in xrange(ipsize):
                startipnum = self.ip2num(startip)
                startipnum = startipnum + x
                ip = self.num2ip(startipnum)

                if isjob == '0':
                    ajob = job.Job(jobaddress=str(ip),
                                   jobport='',
                                   forcesearch='0',
                                   isjob='0')
                else:
                    if command == 'create':
                        ajob = job.Job(jobname=taskid,
                                       jobaddress=str(ip),
                                       username=username,
                                       groupsid=taskid,
                                       jobport=taskport,
                                       isjob='1')
                    else:
                        jobitems, count, pagecount = jobcontrol.jobshow(
                            jobname=taskid,
                            username=username,
                            groupid=taskid,
                            jobaddress=str(ip))
                        ajob = jobitems[0]
                        print ajob.getJobid()

                if command == 'create':

                    insertdata.append(
                        (username, ajob.getJobid(), ajob.getJobname(),
                         ajob.getPriority(), ajob.getStatus(),
                         ajob.getJobaddress(), ajob.getPort(),
                         ajob.getCreatetime(), ajob.getForcesearch(),
                         ajob.getGroupsid()))

                    while True:
                        if self.sqlTool.get_length() > 500:
                            time.sleep(30)
                        else:
                            break
                    if len(insertdata) == 10 or x == ipsize - 1:
                        sqldatawprk = []
                        dic = {
                            "table":
                            self.config.tasktable,
                            "select_params": [
                                'username', 'taskid', 'taskname', 'taskprior',
                                'taskstatus', 'taskaddress', 'taskport',
                                'createtime', 'forcesearch', 'groupsid'
                            ],
                            "insert_values":
                            insertdata
                        }
                        tempwprk = Sqldata.SqlData('inserttableinfo_byparams',
                                                   dic)
                        sqldatawprk.append(tempwprk)
                        self.sqlTool.add_work(sqldatawprk)
                        sqldatawprk = []
                        insertdata = []
                        pass
                elif command == 'work':
                    tasktotally = taskcontrol.getObject()
                    self.getlocationtool.add_work([str(ip)])
                    jobs.append(ajob)
                    while True:
                        if tasktotally.get_length() > 50:
                            time.sleep(60 * 5)
                        else:
                            break

                    # updatedata = []
                    # dic = {
                    #     "table": [self.config.tasktable],
                    #     "select_params": ['taskstatus'],
                    #     "set_params": [status],
                    #     "request_params": ['groupsid'],
                    #     "equal_params": [taskid]
                    # }
                    # updateitem = Sqldata.SqlData('updatetableinfo_byparams', dic)
                    # updatedata.append(updateitem)
                    # self.sqlTool.add_work(updatedata)
                    if status == '3' or isjob == '0':
                        if len(jobs) == 10 or x == ipsize - 1:

                            tasktotally.add_work(jobs)

                            jobs = []
                        else:
                            pass
            if isjob == '1':
                setvalue = "(select count(*) from taskdata where groupsid='" + str(
                    taskid) + "')"
                dic = {
                    "table": [self.config.taskstable],
                    "select_params": ['num'],
                    "set_params": [setvalue],
                    "request_params": ['tasksid'],
                    "equal_params": ['\'' + str(taskid) + '\'']
                }
                updateitem = Sqldata.SqlData('updatetableinfo_byparams', dic)
                updatedata = []
                updatedata.append(updateitem)
                self.sqlTool.add_work(updatedata)
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
                "select_params": ['status'],
                "set_params": ['5'],
                "request_params": ['num'],
                "equal_params": ['completenum']
            }
            statusitem = Sqldata.SqlData('updatetableinfo_byparams', statusdic)
            updatedata.append(statusitem)
            self.sqlTool.add_work(updatedata)
        # ans=''
        return ans


if __name__ == "__main__":
    links = []
    temp = job.Job(jobaddress='www.bnuz.edu.cn',
                   jobport='400-402',
                   jobname='task1')
    #    temp1 = job.Job(jobaddress='localhost',jobport='400-402',jobname='task2')
    temp2 = job.Job(jobaddress='www.ykgs.gov.cn',
                    jobport='400-402',
                    jobname='task3')
    #    temp3 = job.Job(jobaddress='www.vip.com',jobport='400-402',jobname='task4')
    links.append(temp)
    #    links.append(temp1)
    links.append(temp2)
    #    links.append(temp3)

    S_produce = snifferTask(1)  #表示创建的是线程
    S_produce.set_deal_num(10)  #进程数?
    starttime = datetime.datetime.now()