Showing posts with label raspbmc. Show all posts
Showing posts with label raspbmc. Show all posts

Sunday, February 2, 2014

Wifi break-in notifier

Intro

You've grown paranoid of people who could be stealing your Wifi ?
You have the securest form of Wifi encryption ... still wouldn't you like to know STRAIGHT AWAY if someone managed to crack into your network?
Here's a home baked solution ( not suitable for work ) your mileage may vary depending on your Wifi access point.

Concept

Every 5 minutes, a script checks your Wifi access point for unknown Wifi devices.
If one of these devices isn't included in a list of Wifi devices you defined, you get an alert on your iPad/iPhone every day until you add it to your list of known Wifi devices.

Requirements


  • Raspberry Pi running RaspBMC, powered on & connected to your Wifi 24/7
  • Prowl
  • Prowl API key
  • iOS device - iPhone/iPad
  • understanding of Bash/shell scripting
  • you need to make a list of your wifi devices as csv
To add devices to this list, use this command
echo "device_owner;device_name;00:23:68:BE:E7:62" >> known_wifi_devices.csv


You need to understand how to get MAC addresses from your modem/router - i have a Zhone router with Adamo, not much I can help you with here, you need to master curl and grep !

The script

nano rogue_devices.sh


# check if all Wifi devices on the router are known MAC addresses

# if unknown, send a notification via Prowl

# run this as "cron job"

APIKEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



#get the list of MAC addresses from the webpage of my Wifi access point.

html=$(curl -u user:user http://192.168.1.1/wlstationlist.cmd)

echo "$html" | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'| while read mac

do

# check if MAC address is known

 if grep -i -q $mac /home/pi/known_wifi_devices.csv; then

  echo "OK - $mac is known wifi device"

 else

  #if station in logfile in the last day, just log it.

  if grep -E "^$(/bin/date +"%a %b %d")..............$(/bin/date  +"%Y")" -q /var/log/rogue_wifi_monitor; then

   echo "$(/bin/date +"%a %b %d %T %Z %Y") --- $mac is not a known Wifi device on this network" | tee -a /var/log/rogue_wifi_monitor

  else # log it and notify via Prowl

   echo "$(/bin/date +"%a %b %d %T %Z %Y") --- $mac is not a known Wifi device on this network, admin notified" | tee -a  /var/log/rogue_wifi_monitor

   curl https://api.prowlapp.com/publicapi/add \

       -F apikey=$APIKEY \

       -F application="XBMC Rpi" \

      -F event="Rogue Wifi device detected" \

      -F description="MAC Address $mac is unknown !"

  fi

 fi

done


Configure cron

Configure Cron for the script to run every 5 minutes.
crontab -e


*/5 * * * * /home/pi/rogue_devices.sh


If you're curious about what 'cron' does, I recommend this tutorial

Enable cron

Since cron is disabled in RaspBMC, you must enable it.

nano .xbmc/userdata/addon_data/script.raspbmc.settings/settings.xml

change sys.service.cron to "true"

Start cron
service cron start


Possible improvements

rotate or truncate log file
log when Wifi device is recognized after being added.


Post your questions in the comments :-)


Monday, October 28, 2013

Raspbmc - control XBMC over VNC


I switched my media center from Windows XP to Raspbmc 10 months ago.
As advertised
Raspbmc is a minimal Linux distribution based on Debian that brings XBMC to your Raspberry Pi. This device has an excellent form factor and enough power to handle media playback, making it an ideal component in a low HTPC setup, yet delivering the same XBMC experience that can be enjoyed on much more costly platforms.
The switch from double clicking a movie and navigating folders in Windows XP to pure media center  system XBMC is a major shift ! Although in the long run, XBMC is just "better", there are so many concepts to grasp, and I won't even mention the fact that it's all on Linux  :-) (if you're not familiar with it)

Since I use my media center on a projector, I need quick access to  XBMC without turning on the projector every time (whereas people using it with TV don't have this dilemma)
My wishes were fulfilled with Raspbmc's "July Update" as it includes a VNC server

Setup your Raspberry Pi
Create the vncserver script
nano vncserver
Paste the script of "Hiro Protagonist" from his post #3 (the script in post #1 didn't work for me)
Make it executable
chmod +x vncserver
Move it
sudo mv vncserver /usr/local/sbin
You can now start the VNC server
vncserver start
If you want to check if it's running, check if vnc_dispmanx has the default VNC port open (5900)
pi@raspbmc:~$ sudo netstat -lnptu |grep vnc
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      3687/vnc_dispmanx

tcp6       0      0 :::5900                 :::*                    LISTEN      3687/vnc_dispmanx

When you're done, you should turn it off, as it's quite CPU hungry
vncserver stop
Connecting with VNC viewer
Unsucessful
  • from my iPad - using PocketCloud remote desktop
  • from my Mac - using screen sharing (see http://www.tech-recipes.com/rx/2837/ from quick instructions) ... this crashed the VNC service and "Screen sharing" never times out.
Successful

  • from my Mac - using RealVNC viewer
  • didn't try from Windows 7 - guessing it would work fine with RealVNC


Conclusion
Although the performance is appalling, it's very useful to play around settings, and of course you're not going to watch a movie through VNC :-)

Don't have a Raspberry Pi ? It's a bargain for a media center, I highly recommend and you get to learn Linux on the way.