new modes : rainbow & remote computer

This commit is contained in:
Sam 2021-04-30 02:11:12 +02:00
parent 7a22dc6d7f
commit 75c2d4b247
6 changed files with 257 additions and 52 deletions

View File

@ -17,11 +17,17 @@ Physical buttons :
* Func button : GPIO 23 (->pin 16) / GND pin 14
* Down button : GPIO 24 (->pin 18) / GND pin 20
Default port websocket server : 8081
# Control
2 physical buttons and Webpage. Choose your webserver, edit config.js (to your pi webadress) and copy www directory. Browse to pi address.
# Modes
* 'scapy' : listen to local network interface
* 'rainbow' : rainbow animation
* 'remote' : use termspy to listen a remote computer and send to nerves for display
# Install
@ -53,9 +59,7 @@ cd nerves
sudo cp /home/pi/nerves/autorun.conf /etc/supervisor/conf.d/
sudo supervisorctl reload
to stop autorun
sudo supervisorctl stop nerves
# Based on :

View File

@ -11,6 +11,12 @@ Down button : GPIO 24 (->pin 18) / ground 20
When button is pressed : button.value -> False
Functions "modes" :
-1 cls
0 Scappy
1 Rainbow
'''
@ -41,9 +47,7 @@ def runforever():
while True:
#print(funcbutton.value, funcstate, crtfunc, downbutton.value)
#print(funcbutton.value, funcstate)
# Functions button
if not funcbutton.value:
if debug > 0:
@ -51,7 +55,7 @@ def runforever():
sleep(0.2)
# Launch on button release
# Change functions on button release
if funcbutton.value and funcstate == False :
crtfunc +=1
@ -62,23 +66,34 @@ def runforever():
leds.mode = 0
if crtfunc == 1:
leds.mode = 1
if crtfunc == 2:
leds.mode = 2
sleep(0.2)
funcstate = funcbutton.value
# Shutdown button
if not downbutton.value:
if debug > 0:
print("down button pressed")
import os
print('will shutdown...')
#sendWSall("/players Cls...")
leds.mode = -1
leds.cls()
#sendWSall("/players Stopping...")
os.system("systemctl poweroff")
# Animate Rainbow mode
if leds.mode == 1:
#pass
leds.rainbow_mode(wait = 0.001)
# Animate OSC mode
if leds.mode == 2:
pass
sleep(0.005)

51
leds.py
View File

@ -7,12 +7,12 @@ Neopixel GPIO D18 #(-> pin 12)
Ground pin 9
5 V pin 4
Modes :
Modes/functions :
-1 cls
0 Scappy
1 Rainbow
2 Remote
'''
@ -59,6 +59,30 @@ pixels = neopixel.NeoPixel(
# mode 0 : scapy
mode = 0
modes = ["scappy", "rainbow", "Remote"]
nerves = [[0,7],[1,3],[2,9],[4,13],[5,11],[6,12],[8,10]]
influx = [0]*(len(nerves)*2)
counter = 0
def nextnerve(zzzport):
global counter
#print("nerve",counter)
zzz = zzzport % nbcolor # zzz = led color
influx[nerves[counter][0]] = zzz
influx[nerves[counter][1]] = zzz
#print("nerve",counter,"influx", influx)
display(influx)
#print(len(nerves), "nerves")
if counter +1 == len(nerves):
counter = 0
else:
counter += 1
#print("next nerve", counter)
def wheel(pos):
# Input a value 0 to 255 to get a color value.
@ -85,23 +109,28 @@ def wheel(pos):
def rainbow_cycle(wait):
if mode == 1:
for j in range(255):
for rstep in range(255):
for i in range(num_pixels):
pixel_index = (i * 256 // num_pixels) + j
pixel_index = (i * 256 // num_pixels) + rstep
pixels[i] = wheel(pixel_index & 255)
pixels.show()
time.sleep(wait)
# rainbow mode
# rainbow mode frame
rstep = 0
def rainbow_mode(wait = 0.001):
global rstep
if mode == 1:
for j in range(255):
for i in range(num_pixels):
pixel_index = (i * 256 // num_pixels) + j
pixels[i] = wheel(pixel_index & 255)
pixels.show()
time.sleep(wait)
rstep +=1
if rstep == 255:
rstep =0
for i in range(num_pixels):
pixel_index = (i * 256 // num_pixels) + rstep
pixels[i] = wheel(pixel_index & 255)
pixels.show()
time.sleep(wait)
def cls():

View File

@ -53,44 +53,21 @@ import ws
#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("-x","--xcol",help="number of columns (8 by default)",type=int)
parser.add_argument("-y","--ycol",help="number of rows (8 by default)",type=int)
parser.add_argument("-f","--filter",help="tcpdump filter")
parser.add_argument("-c","--color",help="number of color",type=int)
parser.add_argument("-d","--display",help="type of side display",choices=["colors", "ports"])
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.xcol:
xmax=args.xcol
else:
xmax=8
if args.ycol:
ymax=args.ycol
else:
ymax=8
if args.color:
nbcolor=args.color
else:
nbcolor=15
if args.display:
sidedisplay=args.display
else:
sidedisplay="ports"
if args.ephemeralportmin:
ephemeralportmin = args.ephemeralportmin
@ -102,7 +79,11 @@ if args.ephemeralportmax:
else:
ephemeralportmax = 61000
def sendled(zzzport):
leds.nextnerve(zzzport)
'''
def sendled(zzzport):
global counter
@ -121,6 +102,7 @@ def sendled(zzzport):
else:
counter += 1
#print("next nerve", counter)
'''
def print_summary(pkt):
@ -206,6 +188,7 @@ def main():
# Start sniffing
leds.mode = 0
ws.sendWSall("/players Sniffing")
if platform == 'darwin':
print("Running on", platform, "-> en0")
#sniff(iface='en0', prn=print_summary, store=0)

156
termspy.py Normal file
View File

@ -0,0 +1,156 @@
'''
termspy.py : sniff packets from interface en1 using python module scapy (2.3.1)
Use WS port 8081
v0.1
By Sam Neurohack
LICENCE : BY NC
'''
import log
print("")
log.infog("Termspy")
log.infog("v0.1b")
print("Loading...")
from time import sleep
import types
import random
from scapy.all import *
import traceback
import websocket
try:
import thread
except ImportError:
import _thread as thread
counter = 0
serverIP = "192.168.2.189"
#serverIP = "127.0.0.1"
wsPORT = 8081
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.ephemeralportmin:
ephemeralportmin = args.ephemeralportmin
else:
ephemeralportmin = 32768
if args.ephemeralportmax:
ephemeralportmax = args.ephemeralportmax
else:
ephemeralportmax = 61000
def sendled(zzzport):
# zzzport
ws.send('/termspy '+str(zzzport))
def print_summary(pkt):
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 on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def run(*args):
try:
if platform == 'darwin':
print("Running on", platform, "-> en0")
#sniff(iface='en0', prn=print_summary, store=0, filter= args.filter)
sniff(iface='en0', prn=print_summary, store=0)
else:
print("Running on", platform, "-> eth0")
sniff(iface='eth0', prn=print_summary, store=0)
except Exception:
traceback.print_exc()
finally:
ws.close()
print("Termspy WS terminating...")
def on_open(ws):
print("WS connection opened")
thread.start_new_thread(run, ())
if __name__ == "__main__":
try:
print("Connecting to WS server...")
websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://"+str(serverIP)+":"+str(wsPORT),
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
except Exception:
traceback.print_exc()
finally:
#ws.close()
print("Termspy terminating...")

32
ws.py
View File

@ -16,10 +16,10 @@ import _thread, time
from websocket_server import WebsocketServer
import argparse
import leds
#import leds
import traceback
debug = 1
debug = 0
Players=0
clientmode = False
broadcast = True
@ -63,7 +63,7 @@ def Start(serverIP, wsPORT):
def runforever():
print("Running WS server...")
leds.mode = 0
#leds.mode = 0
wserver.run_forever()
@ -134,8 +134,15 @@ def message_received(client, wserver, message):
if crtfunc == len(funcs):
crtfunc = 0
print('Launch func', crtfunc)
sendWSall("/players Function:"+leds.modes[crtfunc])
sendWSall("/players Function:"+str(crtfunc))
print('Launch func', crtfunc)
if crtfunc == 0:
leds.mode = 0
if crtfunc == 1:
leds.mode = 1
if crtfunc == 2:
leds.mode = 2
# shutdown : /down 1
elif wscommand[1] == "down":
@ -148,7 +155,18 @@ def message_received(client, wserver, message):
leds.cls()
os.system("systemctl poweroff")
# incoming termspy : /termspy portnumber
elif wscommand[1] == "termspy":
print('incoming port', str(wspath[1]),'from termspy')
'''
if leds.mode == 2:
# port = int(wspath[1])
if int(wspath[1]) != wsPORT:
leds.nextnerve(int(wspath[1]))
'''
'''
# CC : /device/cc/2 127
elif wscommand[2] == "cc":
ccvr=int(wscommand[3]) #cc variable
@ -159,7 +177,7 @@ def message_received(client, wserver, message):
crtvalueOCS2[ccvr]=ccvl
else:
crtvalueMMO3[ccvr]=ccvl
'''
# Loop back : WS Client -> server -> WS Client
#sendWSall(message)
@ -182,7 +200,7 @@ def sendWSall(message):
print("WS sending to all %s" % (message))
wserver.send_message_to_all(message)
'''
# /send all current cc values
def sendallcurrentccvalues(nozoid):
@ -196,7 +214,7 @@ def sendallcurrentccvalues(nozoid):
else:
for ccnumber in range(0,32):
sendWSall("/ocs2/cc/"+str(ccnumber)+" "+str(crtvalueOCS2[ccnumber]))
'''
if __name__ == '__main__':