Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. from scapy.all import *
  2. import re
  3. import ipaddress
  4. from threading import Thread
  5. from Queue import Queue, Empty
  6. ovhSupernet = [
  7. "10.0.0.0/8",
  8. "172.16.0.0/12",
  9. "192.168.0.0/16",
  10. "5.39.0.0/17",
  11. "5.135.0.0/16",
  12. "5.196.0.0/16",
  13. "37.59.0.0/16",
  14. "37.187.0.0/16",
  15. "46.105.0.0/16",
  16. "51.38.0.0/16",
  17. "51.68.0.0/16",
  18. "51.75.0.0/16",
  19. "51.77.0.0/16",
  20. "51.254.0.0/15",
  21. "54.36.0.0/16",
  22. "54.37.0.0/16",
  23. "54.38.0.0/16",
  24. "79.137.0.0/17",
  25. "87.98.128.0/17",
  26. "91.121.0.0/16",
  27. "91.134.0.0/16",
  28. "92.222.0.0/16",
  29. "94.23.0.0/16",
  30. "109.190.0.0/16",
  31. "137.74.0.0/16",
  32. "145.239.0.0/16",
  33. "147.135.128.0/17",
  34. "149.202.0.0/16",
  35. "151.80.0.0/16",
  36. "151.127.0.0/16",
  37. "164.132.0.0/16",
  38. "167.114.224.0/19",
  39. "176.31.0.0/16",
  40. "178.32.0.0/15",
  41. "185.15.68.0/22",
  42. "188.165.0.0/16",
  43. "193.70.0.0/17",
  44. "213.32.0.0/17",
  45. "213.186.32.0/19",
  46. "213.251.128.0/18",
  47. "217.182.0.0/16",
  48. "8.7.244.0/24",
  49. "8.18.128.0/24",
  50. "8.18.172.0/24",
  51. "8.20.110.0/24",
  52. "8.21.41.0/24",
  53. "8.24.8.0/21",
  54. "8.26.94.0/24",
  55. "8.29.224.0/24",
  56. "8.30.208.0/21",
  57. "8.33.96.0/21",
  58. "8.33.128.0/21",
  59. "8.33.136.0/24",
  60. "8.33.137.0/24",
  61. "54.39.0.0/16",
  62. "66.70.128.0/17",
  63. "103.5.12.0/22",
  64. "139.99.0.0/17",
  65. "139.99.128.0/17",
  66. "142.4.192.0/19",
  67. "142.44.128.0/17",
  68. "144.217.0.0/16",
  69. "147.135.0.0/24",
  70. "149.56.0.0/16",
  71. "158.69.0.0/16",
  72. "167.114.0.0/17",
  73. "167.114.128.0/18",
  74. "167.114.192.0/19",
  75. "192.95.0.0/18",
  76. "192.99.0.0/16",
  77. "198.27.64.0/18",
  78. "198.50.128.0/17",
  79. "198.100.144.0/20",
  80. "198.245.48.0/20",
  81. "147.135.0.0/17",
  82. "23.92.224.0/19",
  83. "107.189.64.0/18",
  84. "144.2.32.0/19",
  85. "192.240.152.0/21",
  86. "46.244.32.0/20",
  87. "92.246.224.0/19",
  88. "185.45.160.0/22",
  89. "8.43.192.0/24",
  90. "205.217.189.0/24",
  91. "205.217.190.0/24",
  92. "205.217.191.0/24",
  93. "205.218.49.0/24",
  94. "208.50.139.0/24",
  95. "208.50.140.0/24",
  96. "208.50.141.0/24",
  97. "216.32.192.0/24",
  98. "216.32.194.0/24",
  99. "216.32.213.0/24",
  100. "216.32.216.0/24",
  101. "216.32.218.0/24",
  102. "216.32.220.0/24",
  103. "216.136.198.0/24",
  104. "51.83.0.0/16",
  105. "51.89.0.0/16",
  106. "51.79.0.0/17",
  107. "51.79.128.0/17",
  108. "51.81.0.0/17",
  109. "51.81.128.0/17",
  110. "51.91.0.0/16"
  111. ]
  112. threads = 7
  113. thread = 0
  114. thread_finished = 0
  115. iface = 'eth0'
  116. def dump(obj):
  117. for attr in dir(obj):
  118. if hasattr( obj, attr ):
  119. print( "obj.%s = %s" % (attr, getattr(obj, attr)))
  120.  
  121. def sniffData(pkt):
  122. if pkt.haslayer(ARP):
  123. if pkt['ARP'].op == 1:
  124. arpDst = ipaddress.ip_network(unicode(pkt['ARP'].pdst))
  125. isAnOVHIP = None
  126. for supernet in ovhSupernet:
  127. ovhSupernet2 = ipaddress.ip_network(unicode(supernet))
  128. if (arpDst.overlaps(ovhSupernet2) is True):
  129. isAnOVHIP = 1
  130. break
  131. if isAnOVHIP is None:
  132. print 'Router: {} IP: {} ({}) on VLAN {} is misconfigured. An ARP request has been seen on an non-OVH IP: {}'.format(pkt[IP].src, pkt['ARP'].psrc, pkt['ARP'].hwsrc, pkt[ERSPAN].vlan, pkt['ARP'].pdst)
  133. # if pkt.haslayer(IP) and not pkt.haslayer(ARP):
  134. # if pkt[ERSPAN][Ether][0].dst == 'ff:ff:ff:ff:ff:ff':
  135. # print 'Router: {} MAC:{} on VLAN {} is sending broadcast: {}'.format(pkt[IP].src, pkt[ERSPAN][Ether][0].src, pkt[ERSPAN].vlan, pkt[ERSPAN].summary)
  136. #
  137.  
  138.  
  139. def print_summary(pkt):
  140. print pkt.summary()
  141.  
  142. def threaded_sniff_target(q):
  143. global thread, thread_finished
  144. thread += 1
  145. print "Launch thread #{}".format(thread)
  146. sniff(iface = iface, filter = "proto 47", prn = lambda x : q.put(x))
  147. thread_finished += 1
  148. print "Thread #{} finished".format(thread_finished)
  149.  
  150. def threaded_sniff():
  151. q = Queue()
  152. while thread <= threads:
  153. sniffer = Thread(target = threaded_sniff_target, args = (q,))
  154. sniffer.daemon = True
  155. sniffer.start()
  156. while thread_finished <= threads:
  157. try:
  158. pkt = q.get()
  159. # sniffData(pkt)
  160. print_summary(pkt)
  161. except Empty:
  162. pass
  163.  
  164. threaded_sniff()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement