From 0a8c70d5e75854edd12aeb4c0b96c55ee5a528b4 Mon Sep 17 00:00:00 2001 From: xdavidhu Date: Sat, 11 Mar 2017 10:53:38 +0100 Subject: [PATCH 1/4] Scan method updated to nmap --- README.rst | 20 +++++++++---- kickthemout.py | 9 ++++-- requirements.txt | 3 +- scan.py | 75 ++++++++---------------------------------------- 4 files changed, 34 insertions(+), 73 deletions(-) diff --git a/README.rst b/README.rst index 9645b48..5deef2a 100644 --- a/README.rst +++ b/README.rst @@ -23,30 +23,38 @@ Authors: `Nikolaos Kamarinakis `_ & `David Schütz ------------- -Installation -------------- +Linux Installation +---------------------- You can download KickThemOut by cloning the `Git Repo `_ and simply installing its requirements:: + $ sudo apt-get update && sudo apt-get install nmap + $ git clone https://github.com/k4m4/kickthemout.git $ cd kickthemout/ - - $ sudo pip install -r requirements.txt + + $ sudo python pip install -r requirements.txt Mac OS X Installation ---------------------- If you would like to install KickThemOut on a Mac, please run the following:: - $ sudo pip install pcapy - + $ sudo python pip install pcapy + + $ brew install nmap + $ brew install libdnet scapy **Keep in mind** that you might be asked to run some commands after executing the previous step. Moving on:: $ git clone https://github.com/k4m4/kickthemout.git + $ cd kickthemout/ + + $ sudo python pip install -r requirements.txt + **NOTE**: You need to have `Homebrew `_ installed before running the Mac OS installation. Demo diff --git a/kickthemout.py b/kickthemout.py index 8a5f7bb..e1bffa6 100644 --- a/kickthemout.py +++ b/kickthemout.py @@ -111,7 +111,7 @@ def regenOnlineIPs(): def scanNetwork(): global hostsList try: - hostsList = scan.scanNetwork() + hostsList = scan.scanNetwork(getDefaultInterface(True)) except KeyboardInterrupt: print('\n\n{0}Thanks for dropping by.\nCatch ya later!{1}').format(GREEN, END) raise SystemExit @@ -286,7 +286,7 @@ def kickalloff(): time.sleep(0.5) print("{0}Re-arped{1} targets successfully.{2}").format(RED, GREEN, END) -def getDefaultInterface(): +def getDefaultInterface(returnNet=False): def long2net(arg): if (arg <= 0 or arg >= 0xFFFFFFFF): raise ValueError("illegal netmask value", hex(arg)) @@ -307,7 +307,10 @@ def getDefaultInterface(): if interface != scapy.config.conf.iface: continue if net: - return interface + if returnNet: + return net + else: + return interface def getGatewayIP(): try: diff --git a/requirements.txt b/requirements.txt index 93b351f..751c072 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -scapy \ No newline at end of file +scapy +python-nmap \ No newline at end of file diff --git a/scan.py b/scan.py index d3f904b..e85aa37 100644 --- a/scan.py +++ b/scan.py @@ -1,69 +1,18 @@ #!/usr/bin/env python # -.- coding: utf-8 -.- # scan.py -# author: Benedikt Waldvogel (MIT Licensed) -# edited by: k4m4 & xdavidhu -import logging -logging.getLogger("scapy.runtime").setLevel(logging.ERROR) -import scapy.config, scapy.layers.l2, scapy.route, socket, math, errno +def scanNetwork(network): + returnlist = [] + import nmap + nm = nmap.PortScanner() + a = nm.scan(hosts=network, arguments='-sP') -def scanNetwork(): + for k, v in a['scan'].iteritems(): + if str(v['status']['state']) == 'up': + try: + returnlist.append([str(v['addresses']['ipv4']), str(v['addresses']['mac'])]) + except: + pass - 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 - - def scan_and_print_neighbors(net, interface, timeout=1): - hostsList = [] - try: - ans, unans = scapy.layers.l2.arping(net, iface=interface, timeout=timeout, verbose=False) - for s, r in ans.res: - mac = r.sprintf("%Ether.src%") - ip = r.sprintf("%ARP.psrc%") - line = r.sprintf("%Ether.src% %ARP.psrc%") - hostsList.append([ip, mac]) - try: - hostname = socket.gethostbyaddr(r.psrc) - line += "," + hostname[0] - except socket.herror: - pass - except socket.error as e: - if e.errno == errno.EPERM: # Operation not permitted - exit() - else: - raise - return hostsList - - for network, netmask, _, interface, address in scapy.config.conf.route.routes: - - # skip loopback network and default gw - 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 - - # Skip APIPA network (corresponds to the 169.254.0.0/16 address range) - # See https://fr.wikipedia.org/wiki/Automatic_Private_Internet_Protocol_Addressing for more details - if network == 2851995648: - continue - - net = to_CIDR_notation(network, netmask) - - if interface != scapy.config.conf.iface: - # see http://trac.secdev.org/scapy/ticket/537 - continue - - if net: - return scan_and_print_neighbors(net, interface) + return returnlist \ No newline at end of file From 5540dc489b55a34554acf65265e5ea6e14aa06d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sch=C3=BCtz?= Date: Sat, 11 Mar 2017 10:55:00 +0100 Subject: [PATCH 2/4] Update README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 5deef2a..69c795b 100644 --- a/README.rst +++ b/README.rst @@ -23,7 +23,7 @@ Authors: `Nikolaos Kamarinakis `_ & `David Schütz ------------- -Linux Installation +Installation on Debian based systems ---------------------- You can download KickThemOut by cloning the `Git Repo `_ and simply installing its requirements:: @@ -36,7 +36,7 @@ You can download KickThemOut by cloning the `Git Repo Date: Sat, 11 Mar 2017 10:56:27 +0100 Subject: [PATCH 3/4] Update README.rst --- README.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 69c795b..4712341 100644 --- a/README.rst +++ b/README.rst @@ -34,18 +34,16 @@ You can download KickThemOut by cloning the `Git Repo `_ installed before running the Mac OS installation. From 9f5642e02136b0d53968819466b973962c2ea6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sch=C3=BCtz?= Date: Sat, 11 Mar 2017 11:02:12 +0100 Subject: [PATCH 4/4] Scan method updated to nma --- scan.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scan.py b/scan.py index e85aa37..5889d16 100644 --- a/scan.py +++ b/scan.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -.- coding: utf-8 -.- -# scan.py +# scan.py +# author: xdavidhu def scanNetwork(network): returnlist = [] @@ -15,4 +16,4 @@ def scanNetwork(network): except: pass - return returnlist \ No newline at end of file + return returnlist