Source Code for network and port scanner, TRW algorithm, and reduction method implementations.

bruteforce_sip-dip-ports.py 1.8KB

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