Pārlūkot izejas kodu

Updating Folder Organization

SaraBeatriz 5 gadus atpakaļ
vecāks
revīzija
5acaa65dca

+ 111
- 0
Programas/Fedora/bruteforce_reduction.py Parādīt failu

@@ -0,0 +1,111 @@
1
+#Itera a la vez el sip y el dip y guarda en un hash los puertos
2
+
3
+from silk import *
4
+
5
+
6
+startDate = "2009/04/20"
7
+endDate = "2009/04/22"
8
+#Para filtrar por puertos. Pero no queremos todavia
9
+#minPort = 20
10
+#maxPort = 5000
11
+
12
+
13
+def ipConversion(number, position):
14
+    mystr = ''
15
+    ipadd = number.split(".") #Devuelve un arreglo
16
+    for i in range(position+1):
17
+        if i ==position:
18
+            mystr = mystr + ipadd[i]
19
+        else:
20
+            mystr = mystr + ipadd[i] + '.'
21
+    return mystr #devuelve los numeros en notacion string
22
+
23
+
24
+def PrimerAnalisis(flowHash, num):
25
+    dportHash={}
26
+    flow_Counter=0
27
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
28
+        for rec in silkfile_open(filename, READ):#reading the flow file
29
+
30
+            if (':' in str(rec.sip)) or (num != 0 and ipConversion(str(rec.sip), num-1) not in flowHash): #Si en el paso anterior se vio que no
31
+                                                                         #tiene el length de puertos requerido, se ignora
32
+                continue
33
+            else: #agrega a un hash cada puerto con un counter de sus destination ips
34
+                dip = ipConversion(str(rec.dip), num)
35
+                sip = ipConversion(str(rec.sip), num)
36
+                dport= rec.dport
37
+                if sip in dportHash:
38
+                    if dip in dportHash[sip]:
39
+                        dportHash[sip][dip] += 1
40
+                    else:
41
+                        dportHash[sip][dip] = 1
42
+                else:
43
+                    dportHash[sip] = { dip: 1 }
44
+
45
+    #print flow_Counter
46
+    return dportHash
47
+
48
+
49
+def UltimoAnalisis(flowHash, num):
50
+    dportHash={}
51
+    flow_Counter=0
52
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
53
+        for rec in silkfile_open(filename, READ):#reading the flow file
54
+            if (':' in str(rec.sip)) or (num != 0 and ipConversion(str(rec.sip), num-1) not in flowHash): #Si en el paso anterior se vio que no
55
+                                                                         #tiene el length de puertos requerido, se ignora
56
+                continue
57
+            else: #agrega a un hash cada puerto con un counter de sus destination ips
58
+                dip = ipConversion(str(rec.dip), num)
59
+                sip = ipConversion(str(rec.sip), num)
60
+                dport= rec.dport
61
+                if sip in dportHash:
62
+                    if dip in dportHash[sip]:
63
+                        dportHash[sip][dip].append(dport)
64
+                    else:
65
+                        dportHash[sip][dip] = [dport]
66
+                else:
67
+                    dportHash[sip] = { dip: [dport] }
68
+
69
+    #print flow_Counter
70
+    return dportHash
71
+
72
+
73
+
74
+
75
+#main
76
+
77
+myNum = 0
78
+otherHash = {}
79
+while myNum <3: #Se itera las cuatro veces de acuerdo con la notacion de ipv4
80
+    flowHash= PrimerAnalisis(otherHash, myNum)
81
+    otherHash = {} #Se borra el hash para agregar elementos nuevos con la nueva etapa de la busqueda
82
+    for sips in flowHash: #se itera por todos los dip y sus counters o puertos
83
+        for dips, dports in flowHash[sips].items():
84
+            if dports >= 100: #si la cantidad de puertos es mayor o igual a 100, nos interesan
85
+                                    #y por lo tanto se guardan en un hash
86
+                if sips in otherHash:
87
+                    otherHash[sips][dips] = dports
88
+                else:
89
+                    otherHash[sips] = {dips: dports}
90
+    myNum += 1
91
+
92
+    #print (flowHash)
93
+
94
+#print otherHash
95
+#Ultimo chequeo, utilizando el ip completo
96
+counter = 0
97
+flowHash = UltimoAnalisis(otherHash, myNum)
98
+otherHash = {} #Se borra el hash para agregar elementos nuevos con la nueva etapa de la busqueda
99
+for sips in flowHash: #se itera por todos los dip y sus counters o puertos
100
+    for dips, dports in flowHash[sips].items():
101
+        if len(dports) >= 100: #si la cantidad de puertos es mayor o igual a 100, nos interesan
102
+                                #y por lo tanto se guardan en un hash
103
+            if sips in otherHash:
104
+                otherHash[sips][dips] = dports
105
+            else:
106
+                otherHash[sips] = {dips: dports}
107
+
108
+for dips, dports in otherHash.items():
109
+    counter +=1 #para contar los elementos del hash
110
+
111
+print (counter)

+ 114
- 0
Programas/Fedora/bruteforce_reduction_sip.py Parādīt failu

@@ -0,0 +1,114 @@
1
+#Itera por sip /16 y cuenta numero de puertos por cada dip
2
+
3
+from silk import *
4
+
5
+
6
+startDate = "2009/04/20"
7
+endDate = "2009/04/22"
8
+#Para filtrar por puertos. Pero no queremos todavia
9
+#minPort = 20
10
+#maxPort = 5000
11
+
12
+
13
+def ipConversion(number, position):
14
+    mystr = ''
15
+    ipadd = number.split(".") #Devuelve un arreglo
16
+    for i in range(position+1):
17
+        if i ==position:
18
+            mystr = mystr + ipadd[i]
19
+        else:
20
+            mystr = mystr + ipadd[i] + '.'
21
+    return mystr #devuelve los numeros en notacion string
22
+
23
+
24
+def PrimerAnalisis(flowHash, num):
25
+    dportHash={}
26
+    flow_Counter=0
27
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
28
+        for rec in silkfile_open(filename, READ):#reading the flow file
29
+            if (':' in str(rec.sip)) or (num != 0 and ipConversion(str(rec.sip), num-1) not in flowHash): #Si en el paso anterior se vio que no
30
+                                                                         #tiene el length de puertos requerido, se ignora
31
+                continue
32
+            else: #agrega a un hash cada puerto con un counter de sus destination ips
33
+                dip = str(rec.dip)
34
+                sip = ipConversion(str(rec.sip), num)
35
+                dport= rec.dport
36
+                if sip in dportHash:
37
+                    if dip in dportHash[sip]:
38
+                        dportHash[sip][dip] += 1
39
+                    else:
40
+                        dportHash[sip][dip] = 1
41
+                else:
42
+                    dportHash[sip] = { dip: 1 }
43
+
44
+    #print flow_Counter
45
+    return dportHash
46
+
47
+
48
+def UltimoAnalisis(flowHash, num):
49
+    dportHash={}
50
+    flow_Counter=0
51
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
52
+        for rec in silkfile_open(filename, READ):#reading the flow file
53
+            if (':' in str(rec.sip)) or (num != 0 and ipConversion(str(rec.sip), num-1) not in flowHash): #Si en el paso anterior se vio que no
54
+                                                                         #tiene el length de puertos requerido, se ignora
55
+                continue
56
+            else: #agrega a un hash cada puerto con un counter de sus destination ips
57
+                dip = ipConversion(str(rec.dip), num)
58
+                sip = ipConversion(str(rec.sip), num)
59
+                dport= rec.dport
60
+                if sip in dportHash:
61
+                    if dip in dportHash[sip]:
62
+                        dportHash[sip][dip].append(dport)
63
+                    else:
64
+                        dportHash[sip][dip] = [dport]
65
+                else:
66
+                    dportHash[sip] = { dip: [dport] }
67
+
68
+    #print flow_Counter
69
+    return dportHash
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+#main
79
+
80
+myNum = 0
81
+otherHash = {}
82
+while myNum <3: #Se itera las cuatro veces de acuerdo con la notacion de ipv4
83
+    flowHash= PrimerAnalisis(otherHash, myNum)
84
+    otherHash = {} #Se borra el hash para agregar elementos nuevos con la nueva etapa de la busqueda
85
+    for sips in flowHash: #se itera por todos los dip y sus counters o puertos
86
+        for dips, dports in flowHash[sips].items():
87
+            if dports >= 100: #si la cantidad de puertos es mayor o igual a 100, nos interesan
88
+                                    #y por lo tanto se guardan en un hash
89
+                if sips in otherHash:
90
+                    otherHash[sips][dips] = dports
91
+                else:
92
+                    otherHash[sips] = {dips: dports}
93
+    myNum += 1
94
+
95
+    #print (flowHash)
96
+
97
+#print otherHash
98
+#Ultimo chequeo, utilizando el ip completo
99
+counter = 0
100
+flowHash = UltimoAnalisis(otherHash, myNum)
101
+otherHash = {} #Se borra el hash para agregar elementos nuevos con la nueva etapa de la busqueda
102
+for sips in flowHash: #se itera por todos los dip y sus counters o puertos
103
+    for dips, dports in flowHash[sips].items():
104
+        if len(dports) >= 100: #si la cantidad de puertos es mayor o igual a 100, nos interesan
105
+                                #y por lo tanto se guardan en un hash
106
+            if sips in otherHash:
107
+                otherHash[sips][dips] = dports
108
+            else:
109
+                otherHash[sips] = {dips: dports}
110
+
111
+for dips, dports in otherHash.items():
112
+    counter +=1 #para contar los elementos del hash
113
+
114
+print counter

+ 50
- 0
Programas/Fedora/bruteforce_sip-dip-ports.py Parādīt failu

@@ -0,0 +1,50 @@
1
+# Guarda lista de puertos de cada dip por cada sip
2
+
3
+from silk import *
4
+
5
+
6
+startDate = "2009/04/20"
7
+endDate = "2009/04/22"
8
+#Para filtrar por puertos. Pero no queremos todavia
9
+#minPort = 20
10
+#maxPort = 5000
11
+
12
+
13
+def verify_type():
14
+    dportHash = {} #contains amount of dport per each sip
15
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
16
+        for rec in silkfile_open(filename, READ):#reading the flow file
17
+            sip = str(rec.sip)
18
+            dip = str(rec.dip)
19
+            dport = rec.dport
20
+            if (':' in sip): #Si en el paso anterior se vio que no
21
+                                                                #tiene el length de puertos requerido, se ignora
22
+                continue
23
+            else:
24
+                if sip in dportHash:
25
+                    if dip in dportHash[sip]:
26
+                        dportHash[sip][dip].append(dport)
27
+                    else:
28
+                        dportHash[sip][dip] = [dport]
29
+                else:
30
+                    dportHash[sip] = { dip: [dport] }
31
+    return dportHash
32
+
33
+
34
+#MAIN
35
+otherHash = {}
36
+counter = 0
37
+flowHash = verify_type()
38
+for sips in flowHash: #se itera por todos los dip y sus counters o puertos
39
+    for dips, dports in flowHash[sips].items():
40
+        if len(dports) >= 100: #si la cantidad de puertos es mayor o igual a 100, nos interesan
41
+                                #y por lo tanto se guardan en un hash
42
+            if sips in otherHash:
43
+                otherHash[sips][dips] = dports
44
+            else:
45
+                otherHash[sips] = {dips: dports}
46
+
47
+for dips, dports in otherHash.items():
48
+    counter +=1 #para contar los elementos del hash
49
+
50
+print (counter)

+ 50
- 0
Programas/Fedora/fedora_code_ps_no_reduc.py Parādīt failu

@@ -0,0 +1,50 @@
1
+###########################################################
2
+#    Port Scanner
3
+#    Cuenta total de puertos desinatarios por cada sip
4
+#     Despliega lista de puertos por cada destination ip
5
+############################################################
6
+from silk import *
7
+
8
+
9
+startDate = "2009/04/20"
10
+endDate = "2009/04/22"
11
+minPort = 20
12
+maxPort = 60000
13
+counter = 0
14
+
15
+def UltimoAnalisis():
16
+    sampleHash = {}
17
+    flow_Counter = 0
18
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
19
+        for rec in silkfile_open(filename, READ):#reading the flow file
20
+            flow_Counter +=1
21
+            dport = rec.dport
22
+	    posA = str(rec.dip)
23
+           # print posA, dport
24
+            if (dport >= 1 and dport < minPort) or dport > maxPort: #verifica que sean puertos validos (creo que se dice asi)
25
+               # print "Im here"
26
+                continue
27
+            else: # Como es el caso de la ultima busqueda, se agrega una lista de los puertos
28
+                if posA in sampleHash:
29
+                    sampleHash[posA].append(dport)
30
+                else:
31
+                    sampleHash[posA] = [dport]
32
+                #print sampleHash
33
+    #print flow_Counter
34
+    return sampleHash
35
+
36
+dip_hash = UltimoAnalisis()
37
+#print dip_hash
38
+otherHash = {} #Se borra el hash para agregar elementos nuevos con la nueva etapa de la busqueda
39
+for dips, dports in dip_hash.items():
40
+    if len(dports)>= 100: #si la cantidad de puertos es mayor o igual a 100, nos interesan
41
+                                #y por lo tanto se guardan en un hash
42
+        otherHash[dips] = dports
43
+
44
+
45
+for dips, dports in otherHash.items():
46
+    counter +=1 #para contar los elementos del hash
47
+
48
+    #print otherHash
49
+
50
+#print counter

+ 119
- 0
Programas/Fedora/fedora_code_ps_reduc.py Parādīt failu

@@ -0,0 +1,119 @@
1
+###########################################################
2
+#    Reduction Port Scanner
3
+#    Cuenta total de puertos desinatarios por cada sip
4
+#     Despliega lista de puertos por cada destination ip
5
+############################################################
6
+
7
+from silk import *
8
+
9
+
10
+startDate = "2009/04/20"
11
+endDate = "2009/04/22"
12
+minPort = 20
13
+maxPort= 60000
14
+flowHash={}
15
+otherHash= {}
16
+myNum = 0
17
+counter = 0
18
+
19
+
20
+
21
+#Funcion que convierte el int ipaddress en notacion string y devuelve los numeros
22
+#hasta la posicion del punto dada en los parametros
23
+def ipConversion(number, position):
24
+    mystr = ''
25
+    ipadd = number.split(".") #Devuelve un arreglo
26
+    for i in range(position+1):
27
+        if i ==position:
28
+            mystr = mystr + ipadd[i]
29
+        else:
30
+            mystr = mystr + ipadd[i] + '.'
31
+    return mystr #devuelve los numeros en notacion string
32
+
33
+
34
+#Funcion que verifica los flows y guarda su dip y, primero un counter de sus puertos,
35
+#y luego los puertos, en un hash. Recibe dos parametros, un hash para verificar
36
+#si ignorar o no el flow (dado en el main), y un numero para la idea de reduccion
37
+def PrimerAnalisis(flowHash, num):
38
+    sampleHash={}
39
+    flow_Counter=0
40
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
41
+        for rec in silkfile_open(filename, READ):#reading the flow file
42
+            flow_Counter+=1
43
+            dport= rec.dport
44
+            #print "First", str(rec.sip), str(rec.dip)
45
+            if (':' in str(rec.dip)) or (num != 0 and ipConversion(str(rec.dip), num-1) not in flowHash): #Si en el paso anterior se vio que no
46
+                                                                         #tiene el length de puertos requerido, se ignora
47
+                continue
48
+
49
+            elif (dport >= 1 and dport < minPort) or dport > maxPort: #verifica que sean puertos validos (creo que se dice asi)
50
+                continue
51
+            else: #agrega a un hash cada puerto con un counter de sus destination ips
52
+                posA = ipConversion(str(rec.dip), num) #devuelve la primera clase del ip en notacion string
53
+                if posA in sampleHash:
54
+                    sampleHash[posA] += 1
55
+                    #print (posA)
56
+                else:
57
+                    sampleHash[posA] = 1
58
+                    #print (posA)
59
+
60
+    print flow_Counter
61
+    return sampleHash
62
+
63
+
64
+def UltimoAnalisis(flowHash, num):
65
+    sampleHash = {}
66
+    flow_counter = 0
67
+    #print flowHash
68
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
69
+        for rec in silkfile_open(filename, READ):#reading the flow file
70
+            flow_counter +=1
71
+            dport = rec.dport
72
+	    print "Ultimo", str(rec.sip), str(rec.dip)
73
+
74
+            if (':' in str(rec.dip)) or (num != 0 and ipConversion(str(rec.dip), num-1) not in flowHash): #Si en el paso anterior se vio que no
75
+                                                                             #tiene el length de puertos requerido, se ignora
76
+
77
+                continue
78
+            elif (dport >= 1 and dport < minPort) or dport > maxPort: #verifica que sean puertos validos (creo que se dice asi)
79
+                continue
80
+            else: # Como es el caso de la ultima busqueda, se agrega una lista de los puertos
81
+                posA = ipConversion(str(rec.dip), num) #devuelve la primera clase del ip en notacion string
82
+                print posA
83
+                if posA in sampleHash:
84
+                    sampleHash[posA].append(dport)
85
+                else:
86
+                    sampleHash[posA] = [dport]
87
+    print flow_counter
88
+    return sampleHash
89
+
90
+
91
+
92
+#MAIN:
93
+
94
+while myNum <3: #Se itera las cuatro veces de acuerdo con la notacion de ipv4
95
+    flowHash= PrimerAnalisis(otherHash, myNum)
96
+    otherHash = {} #Se borra el hash para agregar elementos nuevos con la nueva etapa de la busqueda
97
+    for dips, dports in flowHash.items(): #se itera por todos los dip y sus counters o puertos
98
+        if dports >= 100: #si la cantidad de puertos es mayor o igual a 100, nos interesan
99
+                                    #y por lo tanto se guardan en un hash
100
+            otherHash[dips] = dports
101
+    myNum += 1
102
+
103
+    #print (flowHash)
104
+
105
+print otherHash
106
+#Ultimo chequeo, utilizando el ip completo
107
+
108
+flowHash = UltimoAnalisis(otherHash, myNum)
109
+otherHash = {} #Se borra el hash para agregar elementos nuevos con la nueva etapa de la busqueda
110
+for dips, dports in flowHash.items():
111
+    print dports
112
+    if len(dports)>= 1: #si la cantidad de puertos es mayor o igual a 100, nos interesan
113
+                                #y por lo tanto se guardan en un hash
114
+        otherHash[dips] = dports
115
+
116
+for dips, dports in otherHash.items():
117
+    counter +=1 #para contar los elementos del hash
118
+
119
+print (counter)

+ 58
- 0
Programas/Fedora/fedora_code_scanner.py Parādīt failu

@@ -0,0 +1,58 @@
1
+##########################################################
2
+
3
+#  NS or PS Verifier
4
+
5
+# Receives a List of Source IP Addresses, and depending on the
6
+
7
+#  ratio of dips and dports, classifies the ip address as ps or ns
8
+
9
+#########################################################
10
+
11
+
12
+
13
+from silk import *
14
+
15
+
16
+startDate = "2009/04/20"
17
+endDate = "2009/04/22"
18
+minPort = 20
19
+maxPort = 5000
20
+verifyHash = {}
21
+
22
+def verify_type():
23
+    dportHash = {} #contains amount of dport per each sip
24
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
25
+        for rec in silkfile_open(filename, READ):#reading the flow file
26
+            sip = str(rec.sip)
27
+            dip = str(rec.dip)
28
+            if (rec.dport >= 1 and rec.dport < minPort) or rec.dport > maxPort: #verifica que sean puertos validos (creo que se dice asi)
29
+                    continue
30
+            else: #agrega a un hash cada puerto con un counter de sus destination ips
31
+                  if sip in dportHash:
32
+                      if dip in dportHash[sip]:
33
+                          dportHash[sip][dip] += 1
34
+                      else:
35
+                          dportHash[sip][dip] = 1
36
+                  else:
37
+                      dportHash[sip] = { dip: 1 }
38
+    return dportHash
39
+total_dports = 0
40
+total_dips = 0
41
+sipList = ' ' #esta lista viene de los codigos de trw
42
+verifyHash = verify_type()
43
+psList = [] #list of ip adresses of port scanners
44
+nsList = [] #list of ip adresses of network scanners
45
+for sip in verifyHash: #itera por cada ip address y sus puertos
46
+    for i in verifyHash[sip]:
47
+        total_dports = total_dports + verifyHash[sip][i]
48
+    total_dips = len(verifyHash[sip])
49
+    #check if it is network scan or port scan
50
+    #casoA        mas dports que dips por mucho. Que el ratio sea 100:1 o mas
51
+    if total_dports / total_dips >= 5:
52
+            #print ("something suspicious...")
53
+        #print "This IP Adress %s is a Port Scanner "
54
+        psList.append(sip)
55
+    #caso B mas dports que dips pero que el ratio sea 5:1 o menos
56
+    elif total_dports / total_dips <= 5:
57
+        #print "This IP Adress %s is a Network Scanner "
58
+        nsList.append(sip)

+ 59
- 0
Programas/Fedora/fedora_code_trw.py Parādīt failu

@@ -0,0 +1,59 @@
1
+##################################
2
+#   TRW sin reduccion           #
3
+#      Para Silk's Data Set     #
4
+################################
5
+
6
+
7
+
8
+from silk import *
9
+startDate = "2009/04/20"
10
+endDate = "2009/04/22"
11
+p = 2
12
+
13
+def Analisis():
14
+    counter = 0 # borrar luego
15
+    sampleHash={} #hash para contener los dip con el numero de conecciones y failed coneccciones
16
+    flow_counter = 0
17
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
18
+        for rec in silkfile_open(filename, READ):#reading the flow file
19
+            flow_counter += 1
20
+            if (':' in str(rec.sip)):
21
+				continue
22
+	    	else:
23
+            	connection = [0] * 2 #Lista para contener los valores de conecciones failed y conecciones buenas
24
+            	sip = str(rec.sip) #Devuelve el ip en notacion punto-decimal
25
+            	flags = str(rec.tcpflags)
26
+            #print sip, flags
27
+	    #counter +=1
28
+            	if 'A' in flags: ####arreglar
29
+                	connection[1]=1 #good conections
30
+                else:
31
+                	connection [0] =1 #failed conections
32
+            	if sip in sampleHash:
33
+	                sampleHash[sip][0]+= connection[0]
34
+	                sampleHash[sip][1]+= connection[1]
35
+            	else:
36
+                	sampleHash[sip] = [connection[0], connection[1]]
37
+	    #print sampleHash
38
+    #print flow_counter
39
+    return sampleHash
40
+
41
+sip_connections_list = Analisis()
42
+#print sip_connections_list
43
+sipList = []
44
+for sip in sip_connections_list:
45
+          if (sip_connections_list[sip][1] != 0) and ((sip_connections_list[sip][0] / sip_connections_list[sip][1])  < 1) : #si la cantidad de succesful
46
+                                #b                #g                    #connections es mas que failed connections
47
+                      #not scanner, ignore
48
+                      continue
49
+          elif (sip_connections_list[sip][1] != 0) and ((sip_connections_list[sip][0] / sip_connections_list[sip][1])  < p): #mas failed que succesful, pero no llega al threshold
50
+                      #not scanner, ignore
51
+                      continue                          #se debe tener en cuenta que es suspicious pero no taaanto
52
+          elif (sip_connections_list[sip][1] == 0 and sip_connections_list[sip][0] > 10): #el ratio de failed a succesful llega al threshold pautado
53
+                            #scanner, oh oh
54
+                    sipList.append(sip)
55
+          else:
56
+                            #scanner, oh oh
57
+                    sipList.append(sip)
58
+
59
+#print len(sipList)

+ 82
- 0
Programas/Fedora/fedora_code_trw_reduc.py Parādīt failu

@@ -0,0 +1,82 @@
1
+from silk import *
2
+
3
+myNum = 0
4
+sipList=[]
5
+sip_hash = {}
6
+startDate = "2009/04/20"
7
+endDate = "2009/04/22"
8
+p = 2
9
+##################################
10
+
11
+#   TRW con reduccion           #
12
+
13
+#      Para Silk's Data Set     #
14
+
15
+#################################
16
+
17
+
18
+def ipConversion(number, position):
19
+    mystr = ''
20
+    ipadd = number.split(".") #Devuelve un arreglo
21
+    #print ipadd
22
+    for i in range(position+1):
23
+        if i == position:
24
+            #print ipadd[i]
25
+            mystr = mystr + ipadd[i]
26
+        else:
27
+           # print ipadd[i]
28
+            mystr = mystr + ipadd[i] + '.'
29
+    return mystr #devuelve los numeros en notacion string
30
+
31
+
32
+def AnalisisReduciendo(sipList, num):
33
+    sip_hash = {}
34
+    #print sipList
35
+    flow_counter = 0
36
+    for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
37
+        for rec in silkfile_open(filename, READ):#reading the flow file
38
+            flow_counter += 1
39
+            if (':' in str(rec.sip)) or (num != 0 and ipConversion(str(rec.sip), num-1) not in sipList):#Si en el paso anterior se vio que no
40
+                                                               #tiene el length de puertos requerido, se ignora
41
+		       continue
42
+            else:
43
+                connection = [0] * 2 #Lista para contener los valores de conecciones fallidas y conecciones buenas
44
+                sip = ipConversion(str(rec.sip), num) #Devuelve el ip en notacion punto-decimal
45
+                flags = str(rec.tcpflags)  #array of all tcp flags that are set
46
+                if 'A' in flags: #if the acknowledge flag is set
47
+                    connection[1]=1 #good conections
48
+                else:
49
+                    connection [0] =1 #failed conections
50
+                if sip in sip_hash: #si sip esta en ratioHash => que posA esta en sampleHash
51
+                                            #por lo tanto ya se puede sumar las conecciones al ratio del dip
52
+                    sip_hash[sip][0]+=connection[0]
53
+                    sip_hash[sip][1] += connection[1]
54
+                else: #si sip no esta en ratioHash tampoco
55
+                    sip_hash[sip] = [connection[0], connection[1]]
56
+                #print sip_hash
57
+    #print flow_counter
58
+    return sip_hash
59
+
60
+
61
+while myNum <4:
62
+      sip_connections_list = AnalisisReduciendo(sipList, myNum)
63
+      sipList = []
64
+      for sip in sip_connections_list:
65
+          if (sip_connections_list[sip][1] != 0) and ((sip_connections_list[sip][0] / sip_connections_list[sip][1])  < 1) : #si la cantidad de succesful
66
+                                #b                #g                    #connections es mas que failed connections
67
+                      #not scanner, ignore
68
+                      continue
69
+          elif (sip_connections_list[sip][1] != 0) and ((sip_connections_list[sip][0] / sip_connections_list[sip][1])  < p): #mas failed que succesful, pero no llega al threshold
70
+                      #not scanner, ignore
71
+                      continue                          #se debe tener en cuenta que es suspicious pero no taaanto
72
+          elif (sip_connections_list[sip][1] == 0 and sip_connections_list[sip][0] > 10): #el ratio de failed a succesful llega al threshold pautado
73
+                            #scanner, oh oh
74
+                    sipList.append(sip)
75
+          else:
76
+                            #scanner, oh oh
77
+                    sipList.append(sip)
78
+      #print sipList
79
+
80
+      #print myNum
81
+      myNum += 1
82
+#print len(sipList)

+ 18
- 0
Programas/erase.py Parādīt failu

@@ -0,0 +1,18 @@
1
+
2
+flowHash = {'hola':{'wassup':900, 'eh':9000}}
3
+sip = 'hola'
4
+dip = 'wassup'
5
+dport = 90
6
+otherHash = {}
7
+
8
+for sips in flowHash: #se itera por todos los dip y sus counters o puertos
9
+    for dips, dports in flowHash[sips].items():
10
+        if dports >= 100: #si la cantidad de puertos es mayor o igual a 100, nos interesan
11
+                                #y por lo tanto se guardan en un hash
12
+            print dports
13
+            if sips in otherHash:
14
+                otherHash[sips][dips] = dports
15
+            else:
16
+                otherHash[sips] = {dips: dports}
17
+
18
+print otherHash

+ 9
- 0
Programas/otherHash.py Parādīt failu

@@ -0,0 +1,9 @@
1
+newHash = {}
2
+
3
+dip = "hola"
4
+if dip in newHash:
5
+    newHash[dip] +=1
6
+else:
7
+    newHash[dip] = 1
8
+
9
+print newHash

+ 2
- 2
Programas/trw_real.py Parādīt failu

@@ -33,7 +33,6 @@ def ipConversion(number, position):
33 33
 
34 34
 
35 35
 def AnalisisReduciendo(sipList, num):
36
-    connection = [0] * 2 #Lista para contener los valores de conecciones fallidas y conecciones buenas
37 36
     for i in flow["flows"]: #itera por cada elemento del diccionario de flows
38 37
         sip = ipConversion(i["sip"], num) #Devuelve el ip en notacion punto-decimal
39 38
         flags = i["tcpflags"].split(",")  #array of all tcp flags that are set
@@ -41,6 +40,7 @@ def AnalisisReduciendo(sipList, num):
41 40
                                                                      #tiene el length de puertos requerido, se ignora
42 41
             continue
43 42
         else:
43
+            connection = [0] * 2 #Lista para contener los valores de conecciones fallidas y conecciones buenas
44 44
             if 'A' in flags: #if the acknowledge flag is set
45 45
             connection[1]=1 #good conections
46 46
             else:
@@ -51,7 +51,7 @@ def AnalisisReduciendo(sipList, num):
51 51
                 ratioHash[sip][1] += connection[1]]
52 52
             else: #si sip no esta en ratioHash tampoco
53 53
                 ratioHash= {sip: [connection[0], connection[1]]}
54
-
54
+            print (ratioHash)
55 55
 
56 56
     return ratioHash
57 57
 

+ 4
- 0
flows_code.py Parādīt failu

@@ -0,0 +1,4 @@
1
+import silk
2
+
3
+for filename in FGlob(classname="all", type="all", start_date=startDate, end_date=endDate, site_config_file="/data/silk.conf", data_rootdir="/data"):
4
+  for rec in silkfile_open(filename, READ): #reading the flow file