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

bruteforce_sip-dip_threehash.py 2.3KB

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