Lvl4Sword / Killer

🔪 System tamper detector for USB, Bluetooth, AC, Battery, Disk Tray, and Ethernet.
https://pypi.org/project/killer/
GNU Affero General Public License v3.0
71 stars 11 forks source link

ScreamLock #33

Open 1989gironimo opened 5 years ago

1989gironimo commented 5 years ago

Shamelessly stolen from @PowerPress via github/usbkill: Have the app monitor the decibels coming from the microphone and let the user set a threshold. If the threshold is passed shut down the PC. Example being prevented from touching your PC but by screaming or a loud noise would trigger the shutdown allowing a hands free system.

Lvl4Sword commented 5 years ago

I had responded to that issue, and I'll reiterate more in-depth here. Killer is designed with being a tamper detector first and foremost. Anything that can be put into an untrusted state while your computer is locked, should be secured against. Including but not limited to, your:

These are physical things on your system, or in the case of Bluetooth, devices connecting to your system. While right now I don't believe that detecting audio levels is all that important, I don't have a problem examining this when the project is in a more feature complete state. Currently, detections are done by running a program in a constant loop with a specified sleep at the end, and checking the return status of the program if it's not what the user wants. In order to implement audio level checking there would need to be a program constantly running and that's not something that is currently possible with how the project is setup.

GhostofGoes commented 5 years ago

This would definitely be a cool feature to have, and I think it would be doable with a bit of work.

GhostofGoes commented 5 years ago

One approach off the top of my head is to have a worker process that monitors the decibel levels (however that is done for the given platform), by sampling at regular intervals. When the main killer process wakes up and checks everything, it can query the worker for the audio history since it last checked. If the history exceeded the threashold, it then calls the normal exit routines.

Another approach might be to register a callback for "kill the system" with the worker. As soon as it sees the audio level exceeded, it calls back, and the callback method handles the usual notification and shutdown.

Lvl4Sword commented 5 years ago

I labeled this "Custom Commands", as this'll be something that will be a lot easier to setup when custom commands are done. Any custom commands won't be officially supported, so any issues with them won't be addressed.

M47H3W commented 5 years ago

I believe that the following python code is able to achieve this. I have tested it and can confirm that it works on macOS and Windows. I've not had the time to test it on Linux.

It is worth noting is that this will probably not work correctly if the script is sleeping. The program will not be able to capture the noise level if it's when the sleep is sleeping.

import sounddevice as sd
import numpy as np

def print_sound(indata, outdata, frames, time, status):
    volume_norm = np.linalg.norm(indata)*10
    level = int(volume_norm)

    if(level > 750): # Threshold
     print("Too much!")
     exit()
    else:
        print(level)

with sd.Stream(callback=print_sound):
    sd.sleep(60 * 1000)
Lvl4Sword commented 5 years ago

@M47H3W While I appreciate your contribution, custom commands are not planned until 2.0 and the project has yet to release 1.0. If you'd like more information, please check out #47