Beispiel #1
0
def test_uploadopenport():
    #cmd = "sudo /home/leo/Desktop/sslcloud/masscan/bin/masscan --ports 1-65535  172.32.1.147 --max-rate 3000  --source-port 60000 -oX /tmp/scanoutput.xml"
    # cmd ='whoami'
    # #logger.info(cmd)
    # print cmd
    # proc = Popen(cmd.split(),shell=False,cwd=masscan_dir).wait()
    data = {
        'domain': 'x.x.x.x',
        'project_id': '1',
        'data': '80-427-443-902-5989-8000-8100'
    }

    serverurl = 'http://' + master_server + '/portmonitor/uploadopenport'
    postHttp(serverurl, data)
Beispiel #2
0
def hostalive(ip_addr, project_id):
    try:
        #http://www.lijiejie.com/nmap-fast-scan-large-networks/
        # ping 主机 1024线程  nmap -v -sn -PE -n --min-hostgroup 1024 --min-parallelism 1024 -oX nmap_output.xml www.xxx.com/16
        cmd =  "sudo " + nmap_dir +"/nmap -v -sn -PE -n --min-hostgroup 100 --min-parallelism 100 -oX /tmp/nmap_output.xml "  + ip_addr
        logger.info(cmd)
        Popen(cmd.split(),shell=False, cwd=nmap_dir).wait()


        fname = "/tmp/nmap_output.xml"
        try:
            doc = xml.dom.minidom.parse(fname)
        except IOError:
            print "%s: error: file  doesn't exist\n" % ( fname)

        except xml.parsers.expat.ExpatError:
            print "%s: error: file  doesn't seem to be XML\n" % ( fname)

        alive_host_list = []
        for host in doc.getElementsByTagName("host"):
            try:
                address = host.getElementsByTagName("address")[0]
                ip = address.getAttribute("addr")
            except:
                # move to the next host since the IP is our primary key
                continue
            try:
                status = host.getElementsByTagName("status")[0]
                state = status.getAttribute("state")
            except:
                state = ""

            if state == 'up':
                alive_host_list.append(ip)


        _all_ip = '-'.join(alive_host_list)
        logger.info(_all_ip)
        serverurl = 'http://'+ master_server+'/web/upload_alive_host'
        #{u'project_id':  11 , u'project_id': [u'271'], u'data': [u'33147-22147-63886-30147-6379-21147']}
        logger.info(serverurl)

        data = {'project_id':project_id, 'data': _all_ip}
        logger.info(data)
        postHttp(serverurl, data)
        time.sleep(1)

    except Exception,e:
        logger.error(e)
        return
Beispiel #3
0
def test():
    #cmd = "sudo /home/leo/Desktop/porteye/masscan/bin/masscan --ports 1-65535  172.32.1.147 --max-rate 3000  --source-port 60000 -oX /tmp/scanoutput.xml"
    # cmd ='whoami'
    # #logger.info(cmd)
    # print cmd
    # proc = Popen(cmd.split(),shell=False,cwd=masscan_dir).wait()
    serverurl = 'http://' + master_server + '/web/upload_open_port'
    #{u'domain': [u'172.32.1.100'], u'project_id': [u'271'], u'data': [u'33147-22147-63886-30147-6379-21147']}
    logger.info(serverurl)
    data = {
        'ip_addr':
        '127.0.0.1',
        'project_id':
        333,
        'data':
        '49666-9421-15485-445-902-62806-65412-65325-49665-49182-65453-9088-9088-49668-49669-912-23401-135-49664-65452-49667'
    }
    logger.info(data)
    postHttp(serverurl, data)
Beispiel #4
0
def main(ip_addr, project_id):
    logger.info('checkmasscantasking')
    try:
        cmd = "sudo " + masscan_dir + "bin/masscan --ports 1-65535  " + ip_addr + " --max-rate 3000  --source-port 60000 -oX /tmp/scanoutput.xml"
        logger.info(cmd)
        proc = Popen(cmd.split(), shell=False, cwd=masscan_dir).wait()
        try:
            f = open("/tmp/scanoutput.xml")
        except:
            return

        parsed_file_data = xmltodict.parse(f)
        tmp_list = []
        for element in parsed_file_data['nmaprun']['host']:
            tmp_list.append(
                '{}:{}'.format(element['address']['@addr'],
                               element['ports']['port']['@portid']))

        sort_dic = sort_masscan(tmp_list)

        for _ip in sort_dic:
            _all_ports = '-'.join(sort_dic[_ip])
            logger.info(_all_ports)
            serverurl = 'http://' + master_server + '/portmonitor/uploadopenport'
            #{u'domain': [u'172.32.1.100'], u'project_id': [u'271'], u'data': [u'33147-22147-63886-30147-6379-21147']}
            logger.info(serverurl)

            data = {
                'domain': _ip,
                'project_id': project_id,
                'data': _all_ports
            }
            logger.info(data)
            postHttp(serverurl, data)
            time.sleep(1)

    except Exception, e:
        logger.error(e)
        #continue
        return
Beispiel #5
0
def run_fnascan(project_id, ip_addr, port_list):
    #####run fnascan
    default_need_scan = [
        '21', '22', '23', '24', '25', '80', '81', '82', '83', '84', '85', '86',
        '87', '88', '89', '110', '143', '443', '513', '873', '1080', '1433',
        '1521', '1158', '3306', '3307', '3308', '3389', '3690', '5900', '6379',
        '7001', '8000-8090', '9000', '9418', '27017', '27018', '27019',
        '50060', '111', '11211', '2049', '53', '139', '389', '445', '465',
        '993', '995', '1723', '4440', '5432', '5800', '8000', '8001', '8080',
        '8081', '8888', '9200', '9300', '9080', '9999'
    ]
    if isinstance(port_list, list):
        for p in port_list:
            if p not in default_need_scan:
                default_need_scan.append(p)

    logger.info("FNASCAN PORT : " + str(default_need_scan))
    need_scan_port = ','.join(list_int2str(default_need_scan))
    jsonfilename = ip_addr + '.html'

    fnascan_dir = cpath + '/tools/fnascan'

    cmd = xpython + ' ' + fnascan_dir + '/fnascan.py  -h ' + ip_addr + ' -p ' + need_scan_port
    logger.info(cmd)
    Popen(cmd.split(), shell=False, cwd=fnascan_dir).wait()

    try:
        result_file = open('fnascan_dir/' + jsonfilename)
        postdata = result_file.read()
        data = {'domain': ip_addr, 'project_id': project_id, 'data': postdata}
        result_file.close()
        os.remove('fnascan_dir/' + jsonfilename)
        serverurl = 'http://' + master_server + '/web/upload_fnascan_result'
        logger.info(serverurl)
        postHttp(serverurl, data)
    except Exception, e:
        logger.error(e)
Beispiel #6
0
def run_fnascan(project_id, ip_addr, _open_port):
    #####run fnascan
    logger.info("FNASCAN PORT : " + str(_open_port))
    need_scan_port = ','.join(list_int2str(_open_port))
    jsonfilename = ip_addr + '.html'
    os.chdir(cpath + 'fnascan/')
    cmd = xpython + ' ' + cpath + 'fnascan/fnascan.py  -h ' + ip_addr + ' -p ' + need_scan_port
    logger.info(cmd)
    os.system(cmd)
    try:
        ff = open('./' + jsonfilename)
        postdata = ff.read()
    except:
        postdata = {}
    data = {'domain': ip_addr, 'project_id': project_id, 'data': postdata}
    try:
        ff.close()
        os.remove('./' + jsonfilename)
    except:
        pass
    os.chdir(cpath)
    serverurl = 'http://' + master_server + '/portmonitor/uploadfnascanresult'
    logger.info(serverurl)
    postHttp(serverurl, data)
Beispiel #7
0
    try:
        newest_insert_time = ResultPorts.objects.filter(
            address=ip_addr).values_list('inserted',
                                         flat=True).order_by('-inserted')[0]
        _open_port = ResultPorts.objects.filter(
            inserted=newest_insert_time).values_list('port',
                                                     flat=True).distinct()
    except Exception, e:
        logger.error(e)
        pass
    _open_port = list_int2str(_open_port)
    _all_ports = '-'.join(_open_port)
    data = {'domain': ip_addr, 'project_id': project_id, 'data': _all_ports}
    logger.info(data)
    serverurl = 'http://' + master_server + '/portmonitor/uploadopenport'
    postHttp(serverurl, data)

    run_fnascan(project_id=project_id, ip_addr=ip_addr, _open_port=_open_port)


def main():
    #while True:
    allip = OpenPort.objects.values_list(
        'ip', flat=True).order_by('last_checkdetail_time').distinct()
    task_length = len(allip)
    #['21', '22', '23', '24', '25', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '110', '143', '443', '513', '873', '1080', '1433', '1521', '1158', '3306', '3307', '3308', '3389', '3690', '5900', '6379', '7001', '8000-8090', '9000', '9418', '27017', '27018', '27019', '50060', '111', '11211', '2049', '53', '139', '389', '445', '465', '993', '995', '1723', '4440', '5432', '5800', '8000', '8001', '8080', '8081', '8888', '9200', '9300', '9080', '9999']
    logger.info('checkdetail.py')
    for i in range(0, task_length):
        ip_addr = allip[i]

        scan_single_ip(ip_addr=ip_addr)