Archive for January, 2012
Locking your screen using a MetaWatch
This is a simple way to control access to your Linux computer if you happen to own a MetaWatch.
You walk away, and screenlock is activated. You come back into the room, and (optionally) the screen unlocks.
It’s also an amusing way to drive someone crazy if they are using your computer with your permission.
Or if you can trick a friend to execute the script on his computer, when you are nearby. You just disable BlueTooth your MetaWatch, and the computer screenlocks.
How to use your MetaWatch for a proximity-detector and user authentication device
I wrote a perl script that would lock my Linux computer if I walked away. You need to enable BlueTooth on the MetaWatch, so it’s discoverable. This script could be used with any BlueTooth device, theoretically. Except that the device has to be discoverable. And most devices have to be put into discover mode. Also note that this script does not pair with the device. Here is another approach where the device is paired to the Linux system. One of these days I’d like to modify this script into a more versatile script. But I thought this script might be useful. Some of the perl code might be useful. I used the Perl Net::Bluetooth package. Since this package might not be installed, I added an error message that gives the user a clue how to fix this problem. The script can also unlock the screen if you get closer. So you can use this to both lock and unlock the screen. Adding an unlock feature is not secure, as anyone who can clone the BlueTooth address can unlock your screen.
The perl code to screenlock your computer when a BlueTooth device moves away
#!/usr/bin/perl -w # # KeepNear - this program wants to keep a BlueTooth device near the Linux system. # If the BlueTooth device leaves the vicinity, the system screenlocks. # If the device comes back, the system unlocks the screen # Written by Grymoire - Tue Jan 17 21:29:03 EST 2012 # # use strict; #User modifiable configuration parameters my $verbose=0; # set to 1 for more detail/debug my $address = "D0:37:61:3F:F0:0A"; # bluetooth address the system is looking for my $name = "MetaWatch"; # name of bluetooth device the system is looking for my $interval_between_samples = 10; # interval in seconds my $maximum_interval_before_
locking = 60*5; # 5 minutes; If device is gone for this time, exit with status=1;
my $starting_delay = 60*3; # 3 minutes - wait this amount of time to start the timer. If no device is found, exit with status=2;
my $unsafe = 0; # true if you want the bluetooth device to unlock the screen.
# naturally - any device that can spoof the BlueTooth address and name can unlock the computer.
# Use the unsafe mode at your own risk.
# Pick command to lock the screen
my $lock_command = "gnome-screensaver-command -l";
#my $lock_command = "xscreensaver-command -activate";
#my $lock_command = "dcop kdesktop KScreensaverIface lock";
# Is there a command to unlock the screen? - Warning - spoofing BT address can unlock the computer
my $unlock_command = "gnome-screensaver-command -d";
# other variables used
my $timestamp_last_time_device_was_seen;
my $timestamp_last_time_device_was_missing;
# Load the Bluetooth module - with friendly error
eval 'use Net::Bluetooth;';
if ($@) {
$verbose && print $@; # print the error message
print "Hmm. I cannot find the perl library for Bluetooth.\n";
print "If you do not mind, I have some suggestions that might help...\n";
print "\n";
print "If you have Ubuntu, try 'apt-get install libnet-bluetooth-perl'\n";
print "Otherwise, try installing Net::Bluetooth in one of the following directories: " . join(", ", @INC) . "\n";
print "If it's installed elsewhere, try adding the following line to the perl file: 'unshift \@INC \"/home/local\"'\n";
die "Sorry - I cannnot go any further. Aborting";
}
sub am_i_near() {
#### look at all of the remote bluetooth devices in the area
#### return 1 (found) or 0 (not found)
my $addr; # address of BT device we found
my $device_ref = get_remote_devices();
foreach $addr (keys %$device_ref) {
$verbose && printf("Name: %s, Address: %s\n", $addr, $device_ref->{$addr});
if (($addr =~ /$address/i) && (($device_ref->{$addr}) =~ /$name/i)) {
# Both the name and the BlueTooth address matches
return 1; # I found the device
} else {
$verbose && printf( "Device %s != %s, and/or BlueTooth Address %s != %s\n",
$addr, $address, $name, $device_ref->{$addr});
}
}
return 0; #device was not found
}
sub main() {
# the first time I start up, make sure I find the device
my $start=time();
my $interval = 0;
while ($interval<=$starting_delay && !defined($timestamp_last_time_device_was_seen)) {
$interval=time()-$start; # how long have I been waiting?
$verbose && print "I've been waiting $interval seconds so far\n";
if (&am_i_near()) {
$timestamp_last_time_device_was_seen = time();
} else {
printf(STDERR "Warning - Cannot find BlueTooth device with address $address, let me try again\n");
sleep($interval_between_samples);
}
}
if (defined($timestamp_last_time_device_was_seen)) {
$verbose && printf("I found the device after %f seconds\n", ($timestamp_last_time_device_was_seen-$start))
} else {
$verbose && printf("I waited $interval seconds, which is greater that %d, and I did not see BlueTooth address $address, so I am quiting\n", $starting_delay);
exit(2);
}
# I found it. Now we enter the main loop
printf(STDERR "Entering screenlock mode\n");
sleep($interval_between_samples); # once
# now start the main loop.
while (1) {
# is the device nearby?
if (&am_i_near()) {
$timestamp_last_time_device_was_seen = time(); # yes.
# perhaps unlock the screen - if the unsafe option is on
$unsafe && system($unlock_command);
}
$interval=time()-$timestamp_last_time_device_was_seen; # how long is the device missing?
if ($interval > $maximum_interval_before_locking) { # too long.
system($lock_command);
} else {
$verbose && printf(" %f < %f, wait again\n", $interval, $maximum_interval_before_locking);
}
sleep($interval_between_samples);
}
}
&main();
1; #exit properly
-
You are currently browsing the archives for January, 2012
Twitter posts
- McAfee-Intel eye critical infrastructure protection and "reference implementation" http://t.co/vff1DYaY
- Security researcher Justin Cacak said CCTV video surveillance systems are hackable http://t.co/VZjp0fyi
- Researchers from Kansas State Developing Self-Defending Networks http://t.co/HNax1bv9
- #GE announces security patches for PACSystems RX3i, PACSystems RX7i, Series 90-30, and Proficy Machine Edition-View http://t.co/Wm7cCpHz
- GE announces security patches for Proficy Historian, Proficy HMI/SCADA – iFIX, Proficy Pulse, Proficy Batch Execution, and SI7 I/O Driver
Tag Cloud
Alchemy Android Arduino ASUS authentication bent sata pins biometrics Breach China Crucial cybersecurity DO No Evil games Google Great Firewall of China Hacking Hauppauge HID HTPC Humor HVR-950Q hvr-1250 HVR-1255 IDS illegal iPhone kinect Linux Mastercard SecureCode metawatch microsoft monopoly Motherboard munin Mythtv netbooks parsing ASCII pay more and get less Paypal Perl Politics quoting regex scripting Security