Beispiel #1
0
def portScanRanges(db, footprint_id):
    #while dbfunctions.countHostsToPortScan(db, footprint_id) > 0:
    #if dbfunctions.countHostsToPortScan(db, footprint_id) > 0:

    if True:
        os.popen('echo "" > nmap_temp/portscan_ranges')
        ranges = []
        count = 0
        for range in dbfunctions.listRangesToPortScan(db, footprint_id):
            os.popen("echo {0} >> nmap_temp/portscan_ranges".format(range))
            count = count + 1
            ranges.append(range)
            #print "portscanning range {0}".format(range)

        if count == 0:
            time.sleep(1)
            return

        #os.popen("nmap -iL nmap_temp/portscan_ranges -n -p 21,22,80,443,445,1433,3389,5800,5900,8080-8090,9090-9099 -oG nmap_temp/portscan_ranges_out -vv")
        os.popen(
            "nmap -iL nmap_temp/portscan_ranges -n -p 21,22,80,135,443,445,1433,3389,5800,5900,8080-8090,9090-9099 -oG nmap_temp/portscan_ranges_out -vv"
        )

        for line in open('nmap_temp/portscan_ranges_out'):
            if line[:1] == "#":
                continue
            if line.find("Status") == -1:
                host = line[6:]
                host = host[:host.find(" ")]

                items = line[line.find("Ports") + 7:]
                for item in items.split(", "):
                    data = item.split("/")
                    port = data[0]
                    status = data[1]
                    if status == "open":
                        #print "host: {0} port: {1}".format(host,  port)
                        dbfunctions.addIP(db, footprint_id, host)
                        dbfunctions.insertPort(db, host, port)
            elif line.find("Status: Down") != -1:
                status = "down"
            else:
                continue
            #print "host:" + host
            #db.cursor().execute('update host_data set port_scan_done = 1 where footprint_id = %s and ip_address = %s', (footprint_id, host))

        for range in ranges:
            cursor = db.cursor()
            cursor.execute(
                'update ranges set port_scans_done = 1 where footprint_id = %s and net_range = %s',
                (footprint_id, range))
            #print "finished port scanning range " + range
            cursor.close()
def portScanRanges(db, footprint_id):
    #while dbfunctions.countHostsToPortScan(db, footprint_id) > 0:
    #if dbfunctions.countHostsToPortScan(db, footprint_id) > 0:

    if True:
        os.popen('echo "" > nmap_temp/portscan_ranges')
        ranges = []
        count = 0
        for range in dbfunctions.listRangesToPortScan(db, footprint_id):
            os.popen("echo {0} >> nmap_temp/portscan_ranges".format(range))
            count = count + 1
            ranges.append(range)
            #print "portscanning range {0}".format(range)

        if count == 0:
            time.sleep(1)
            return

        #os.popen("nmap -iL nmap_temp/portscan_ranges -n -p 21,22,80,443,445,1433,3389,5800,5900,8080-8090,9090-9099 -oG nmap_temp/portscan_ranges_out -vv")
        os.popen("nmap -iL nmap_temp/portscan_ranges -n -p 21,22,80,135,443,445,1433,3389,5800,5900,8080-8090,9090-9099 -oG nmap_temp/portscan_ranges_out -vv")

        for line in open('nmap_temp/portscan_ranges_out'):
            if line[:1] == "#":
                continue
            if line.find("Status") == -1:
                host = line[6:]
                host = host[:host.find(" ")]

                items = line[line.find("Ports")+7:]
                for item in items.split(", "):
                    data = item.split("/")
                    port = data[0]
                    status = data[1]
                    if status == "open":
                        #print "host: {0} port: {1}".format(host,  port)
                        dbfunctions.addIP(db,  footprint_id,  host)
                        dbfunctions.insertPort(db, host, port)
            elif line.find("Status: Down") != -1:
                status = "down"
            else:
                continue
            #print "host:" + host
            #db.cursor().execute('update host_data set port_scan_done = 1 where footprint_id = %s and ip_address = %s', (footprint_id, host))

        for range in ranges:
            cursor = db.cursor()
            cursor.execute('update ranges set port_scans_done = 1 where footprint_id = %s and net_range = %s', (footprint_id, range))
            #print "finished port scanning range " + range
            cursor.close()
Beispiel #3
0
def portScanHosts(db, footprint_id):
    if True:
        os.popen('echo "" > nmap_temp/portscan_hosts')

        count = 0
        for host in dbfunctions.listHostsToPortScan(db, footprint_id):
            os.popen("echo {0} >> nmap_temp/portscan_hosts".format(host))
            count = count + 1

        if count == 0:
            time.sleep(3)
            return

        os.popen(
            "nmap -iL nmap_temp/portscan_hosts -n -p 21,22,80,135,443,445,1433,3389,5800,5900,8080-8090,9090-9099 -oG nmap_temp/portscan_hosts_out -Pn -vv"
        )

        hosts = []
        for line in open('nmap_temp/portscan_hosts_out'):
            if line[:1] == "#":
                continue

            if line.find("Status") == -1:
                host = line[6:]
                host = host[:host.find(" ")]
                hosts.append(host)

                items = line[line.find("Ports") + 7:]
                for item in items.split(", "):
                    data = item.split("/")
                    port = data[0]
                    status = data[1]
                    if status == "open":
                        dbfunctions.insertPort(db, host, port)
            elif line.find("Status: Down") != -1:
                host = line[6:]
                host = host[:host.find(" ")]
                hosts.append(host)
            else:
                continue

        for host in hosts:
            cursor = db.cursor()
            cursor.execute(
                'update host_data set port_scan_done = 1 where footprint_id = %s and ip_address = %s',
                (footprint_id, host))
            cursor.close()
def portScanHosts(db, footprint_id):
    if True:
        os.popen('echo "" > nmap_temp/portscan_hosts')

        count = 0
        for host in dbfunctions.listHostsToPortScan(db, footprint_id):
            os.popen("echo {0} >> nmap_temp/portscan_hosts".format(host))
            count = count + 1


        if count == 0:
            time.sleep(3)
            return

        os.popen("nmap -iL nmap_temp/portscan_hosts -n -p 21,22,80,135,443,445,1433,3389,5800,5900,8080-8090,9090-9099 -oG nmap_temp/portscan_hosts_out -Pn -vv")

        hosts = []
        for line in open('nmap_temp/portscan_hosts_out'):
            if line[:1] == "#":
                continue

            if line.find("Status") == -1:
                host = line[6:]
                host = host[:host.find(" ")]
                hosts.append(host)

                items = line[line.find("Ports")+7:]
                for item in items.split(", "):
                    data = item.split("/")
                    port = data[0]
                    status = data[1]
                    if status == "open":
                        dbfunctions.insertPort(db, host, port)
            elif line.find("Status: Down") != -1:
                host = line[6:]
                host = host[:host.find(" ")]
                hosts.append(host)
            else:
                continue

        for host in hosts:
            cursor = db.cursor()
            cursor.execute('update host_data set port_scan_done = 1 where footprint_id = %s and ip_address = %s', (footprint_id, host))
            cursor.close()