mirror of
https://github.com/k4m4/kickthemout.git
synced 2024-11-24 14:04:24 +01:00
Scan method updated to nmap
This commit is contained in:
parent
c58a2e19ca
commit
0a8c70d5e7
20
README.rst
20
README.rst
@ -23,30 +23,38 @@ Authors: `Nikolaos Kamarinakis <mailto:nikolaskam@gmail.com>`_ & `David Schütz
|
||||
|
||||
-------------
|
||||
|
||||
Installation
|
||||
-------------
|
||||
Linux Installation
|
||||
----------------------
|
||||
|
||||
You can download KickThemOut by cloning the `Git Repo <https://github.com/k4m4/kickthemout>`_ 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 <http://brew.sh/>`_ installed before running the Mac OS installation.
|
||||
|
||||
Demo
|
||||
|
@ -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:
|
||||
|
@ -1 +1,2 @@
|
||||
scapy
|
||||
scapy
|
||||
python-nmap
|
75
scan.py
75
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
|
Loading…
Reference in New Issue
Block a user