Beispiel #1
0
def main_implementation():
    currentDT = datetime.datetime.now()
    #Se crean objetos para hacer la coneccion a base de datos
    myclient = pymongo.MongoClient("mongodb://localhost:27017/")
    mydb = myclient["proyect"]
    mycol = mydb["netflow"]
    mycolSummary = mydb["netflowSummary"]
    list = []
    ##Se corre el comando que lee los archivos de nfcap
    comando = "nfdump  -R /var/cache/nfdump -o fmt:'|%sap|%dap|%td|%pkt|%byt|%fl|%ts|%te|%td'"
    for line in consoleExecute.run_command(comando):
        #Se decodifica la linea leida
        lineDecoded = line.decode('utf-8').strip()
        if (not lineDecoded.startswith("Src")):
            if (lineDecoded.startswith("|")):
                data = lineDecoded.split("|")
                mydict = {
                    "source": data[1].strip(),
                    "destiny": data[2].strip(),
                    "duration": data[3].strip(),
                    "packets": data[4].strip(),
                    "bytes": data[5].strip(),
                    "flows": data[6].strip(),
                    "ts": data[7].strip(),
                    "te": data[8].strip(),
                    "d": data[9].strip(),
                    "date": currentDT.strftime("%Y-%m-%d %H:%M:%S")
                }
                list.append(mydict)
    return list
Beispiel #2
0
def main_implementation(param):
    print(param)
    comand = "echo 'get startup-config /tmp/{0}.backup' | tftp {0}"
    for line in consoleExecute.run_command(comand.format(param)):
        lineDecoded = line.decode('utf-8').strip()
        print(lineDecoded)
    return "/tmp/{0}.backup".format(param)
Beispiel #3
0
def telnet(host):
    ip = "{0}_bckp.txt\n".format(host)
    consoleExecute.run_command("sudo chmod -f 777 /tftpboot/" +
                               "{0}_bckp.txt".format(host))
    print("sudo chmod -f 777 /tftpboot/" + "{0}_bckp.txt".format(host))
    user = "******"
    password = "******"

    #Conexion Telnet
    tn = telnetlib.Telnet(host)

    #Conexion al router
    tn.read_until(b"Username: "******"\n")
    if password:
        tn.read_until(b"Password: "******"\n")

    #Colocamos los comandos
    tn.write(b"enable\n")
    tn.write(b"123a\n")
    tn.write(b"copy tftp: running-config\n")
    tn.read_until(b"Address or name of remote host ")
    tn.write(b"10.0.27.2\n")
    tn.read_until(b"Source filename")
    print(ip)
    tn.write(ip.encode('utf-8'))
    tn.read_until(b"Destination filename")
    tn.write(b"running-config\n")
    sleep(20)
    tn.write(b"wr\n")
    sleep(2)
    tn.write(b"y\n")
    sleep(2)
    tn.write(b"exit\n")

    #Escribimos y cerramos el archivo
    #print (tn.read_all().decode('ascii'))

    return {'message': 'Conexion al router {0} correcto!'.format(host)}
Beispiel #4
0
def scan_networks(networks):
    hosts = []
    command = " nmap --min-parallelism 100  {}   -sL --open  -oG -  "
    stringReturn = ""
    for line in consoleExecute.run_command(command.format(networks)):
        lineDecoded = line.decode('utf-8').strip()
        if (lineDecoded.startswith("Host:")):
            host = lineDecoded.split(" ")[1]
            if ((not host.endswith("0")) and (not host.endswith("3"))):
                hosts.append(host)

    hosts = list(dict.fromkeys(hosts))
    return hosts
Beispiel #5
0
def main_implementation(param):
    currentDT = datetime.datetime.now()
    #Se crean objetos para hacer la coneccion a base de datos
    myclient = pymongo.MongoClient("mongodb://localhost:27017/")
    mydb = myclient["proyect"]
    mycol = mydb["netflow"]
    mycolSummary = mydb["netflowSummary"]
    list = []
    ##Se corre el comando que lee los archivos de nfcap
    comando = "nfdump  -R /var/cache/nfdump  {0}"
    print (comando.format(param))
    for line in consoleExecute.run_command(comando.format(param)):
        #Se decodifica la linea leida
        lineDecoded = line.decode('utf-8').strip()
        if(not lineDecoded.startswith("Top")):
            if(lineDecoded.startswith("2")):
                dataAny = lineDecoded.split("any")
                dataTmp = dataAny[1].split("  ")
                data = []
                for e in filter(None, dataTmp):
                    data.append(e)

                dataTime = []
                for e in filter(None, dataAny[0].split()):
                    dataTime.append(e)


                mydict = { "dateFirstSeen": dataTime[0].strip(),
                           "timeFirstSeen": dataTime[1].strip(),
                           "duracion": dataTime[2].strip(),
                           "protocolo": "any",
                           "src": data[0].strip(),
                           "flows": data[1].strip(),
                           "paquetes": data[2].strip(),
                           "bytes": data[3].strip(),
                           "pps": data[4].strip(),
                           "bps": data[5].strip(),
                           "bpp": data[6].strip()}
                list.append(mydict)
    return list
Beispiel #6
0
def main_implementation(ipSource, ipTarget):
    print(ipSource)
    print(ipTarget)
    comand = "wdiff -3 -wd -xd -yi -zi /tmp/{0}.backup /tmp/{1}.backup"
    return consoleExecute.run_command(comand.format(ipSource, ipTarget))