222 lines
5.0 KiB
Python
222 lines
5.0 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
Nerves
|
|
v 0.1
|
|
|
|
A termeal version with fiber optics on raspberry pi
|
|
|
|
|
|
By Sam Neurohack
|
|
LICENCE : CC
|
|
|
|
'''
|
|
import log
|
|
|
|
print("")
|
|
print("")
|
|
log.infog("Nerves")
|
|
log.infog("v0.1b")
|
|
print("Loading...")
|
|
|
|
import adafruit_blinka.agnostic as agnostic
|
|
import board
|
|
import sys
|
|
|
|
print(
|
|
"Found system type: %s (sys.platform %s implementation %s) "
|
|
% (agnostic.board_id, sys.platform, sys.implementation.name)
|
|
)
|
|
|
|
from sys import platform
|
|
from time import sleep
|
|
import types
|
|
import random
|
|
from scapy.all import *
|
|
from threading import Thread
|
|
import traceback
|
|
|
|
import leds
|
|
import buttons
|
|
import ws
|
|
|
|
# from Adafruit_GPIO import Platform
|
|
# print("Platform = ", Platform.platform_detect(), Platform.pi_version())
|
|
|
|
#print("board contents: ", dir(board))
|
|
|
|
'''
|
|
nerves = [[0,7],[1,3],[2,9],[4,13],[5,11],[6,12],[8,10]]
|
|
influx = [0]*(len(nerves)*2)
|
|
print(influx)
|
|
|
|
counter = 0
|
|
'''
|
|
import argparse
|
|
parser = argparse.ArgumentParser(description="A Scanner Interface Darkly")
|
|
parser.add_argument("-i","--interface", help="interface to scan")
|
|
parser.add_argument("-f","--filter",help="tcpdump filter")
|
|
parser.add_argument("-epi","--ephemeralportmin",help="ephemeral port min to exclude (32768 by default), set to 65536 to include all ports",type=int)
|
|
parser.add_argument("-epa","--ephemeralportmax",help="ephemeral port max to exclude (61000 by default)",type=int)
|
|
args = parser.parse_args()
|
|
|
|
if args.filter:
|
|
filters = args.filter
|
|
else:
|
|
filters = None
|
|
|
|
print('Filter :',filters)
|
|
|
|
if args.interface == None:
|
|
|
|
if platform == 'darwin':
|
|
ifn='en0'
|
|
else:
|
|
ifn='eth0'
|
|
|
|
else:
|
|
iface = args.interface
|
|
|
|
|
|
if args.ephemeralportmin:
|
|
ephemeralportmin = args.ephemeralportmin
|
|
else:
|
|
ephemeralportmin = 32768
|
|
|
|
if args.ephemeralportmax:
|
|
ephemeralportmax = args.ephemeralportmax
|
|
else:
|
|
ephemeralportmax = 61000
|
|
|
|
def sendled(zzzport):
|
|
|
|
leds.nextnerve(zzzport)
|
|
|
|
'''
|
|
def sendled(zzzport):
|
|
global counter
|
|
|
|
#print("nerve",counter)
|
|
zzz = zzzport % leds.nbcolor # zzz = led color
|
|
|
|
influx[nerves[counter][0]] = zzz
|
|
influx[nerves[counter][1]] = zzz
|
|
#print("nerve",counter,"influx", influx)
|
|
|
|
leds.display(influx)
|
|
|
|
#print(len(nerves), "nerves")
|
|
if counter +1 == len(nerves):
|
|
counter = 0
|
|
else:
|
|
counter += 1
|
|
#print("next nerve", counter)
|
|
'''
|
|
|
|
def print_summary(pkt):
|
|
|
|
if leds.mode == 0:
|
|
|
|
if IP in pkt:
|
|
ip_src=pkt[IP].src
|
|
ip_dst=pkt[IP].dst
|
|
|
|
|
|
if TCP in pkt:
|
|
tcp_sport=pkt[TCP].sport
|
|
tcp_dport=pkt[TCP].dport
|
|
|
|
if tcp_sport < 50000:
|
|
print (" IP src " + str(ip_src) + " TCP sport " + str(tcp_sport) )
|
|
sendled(tcp_sport)
|
|
if tcp_dport < 50000:
|
|
print (" IP dst " + str(ip_dst) + " TCP dport " + str(tcp_dport))
|
|
sendled(tcp_dport)
|
|
|
|
if UDP in pkt:
|
|
udp_sport=pkt[UDP].sport
|
|
udp_dport=pkt[UDP].dport
|
|
|
|
if udp_sport < 50000:
|
|
print (" IP src " + str(ip_src) + " UDP sport " + str(udp_sport) )
|
|
sendled(udp_sport)
|
|
|
|
if udp_dport < 50000:
|
|
print (" IP dst " + str(ip_dst) + " UDP dport " + str(udp_dport))
|
|
sendled(udp_dport)
|
|
|
|
|
|
if ARP in pkt and pkt[ARP].op in (1,2):
|
|
print (" ARP")
|
|
sendled(67)
|
|
|
|
|
|
|
|
def handle_error(self,request,client_address): # All callbacks
|
|
pass
|
|
|
|
'''
|
|
def main():
|
|
|
|
print("Testing leds...")
|
|
leds.cls()
|
|
leds.demo()
|
|
leds.cls()
|
|
|
|
if platform == 'darwin':
|
|
print("Running on", platform, "-> en0")
|
|
#sniff(iface='en0', prn=print_summary, store=0)
|
|
sniff(iface='en0', prn=print_summary, store=0,filter=args.filter)
|
|
|
|
else:
|
|
print("Running on", platform, "-> eth0")
|
|
sniff(iface='eth0', prn=print_summary, store=0)
|
|
'''
|
|
|
|
def main():
|
|
|
|
ws.Start(ws.serverIP, ws.wsPORT)
|
|
|
|
try:
|
|
|
|
ws_thread = Thread(target=ws.runforever, args=())
|
|
ws_thread.setDaemon(True)
|
|
ws_thread.start()
|
|
|
|
print("Launching buttons thread...")
|
|
buttons_thread = Thread(target=buttons.runforever, args=())
|
|
buttons_thread.setDaemon(True)
|
|
buttons_thread.start()
|
|
|
|
ws.sendWSall("/players Demo")
|
|
print("Testing leds...")
|
|
leds.cls()
|
|
leds.demo()
|
|
leds.cls()
|
|
|
|
# Start sniffing
|
|
leds.mode = 0
|
|
ws.sendWSall("/players Sniffing")
|
|
|
|
|
|
if filters != None:
|
|
print('with filters', filters)
|
|
sniff(iface=ifn, prn=print_summary, store=0, filter= filters)
|
|
else:
|
|
print('without filter')
|
|
sniff(iface=ifn, prn=print_summary, store=0)
|
|
|
|
|
|
except Exception:
|
|
traceback.print_exc()
|
|
|
|
finally:
|
|
leds.cls()
|
|
ws_thread.join()
|
|
buttons_thread.join()
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|