Monday, January 27, 2020

Raspberry Pi - Cloud Based Motion Detection Surveillance System



This was a fun little project to make. I ended up with a really cool alternative to paying for a monthly cloud server fee to save my motion-detection videos and it's more secure because my data is being sent right from my Raspberry Pi to my Google Drive.

And so we begin with this little powerful device. The Raspberry Pi Zero W.

First we start with a Raspberry Pi. We will need to add a camera, a flashed ISO image on a little SD card and we will add some configuration.
This is me in my computer lab with one of my assistants.

I enlisted the help of one of my cats. This is not advisable. Cats are quite capable of chewing on and short circuiting your equipment. You may need to reorder parts if you follow this step.
This is everything exposed while we were doing our initial configuring, installing and troubleshooting.

Also be mindful of the parts you buy. I bought this recommended camera on Amazon and ended up with a cyberpunk look having circuits and a camera exposed to the elements of my living room. I will rewire this with a new camera that fits the case when I have extra money for additional Raspberry Pi projects.


Here is our cyberpunk looking Raspberry Pi camera keeping watch.



Next I had to download a copy of MotionEyeOS and flash a SD card with the ISO. I used Balena Etcher. All you do is simply download the operating system you will be using and use the GUI which you can log into once you've located your generated IP address. In this case we used MotionEyeOS from github for our operating system. Once we flashed our card with the Raspberry Pi operating system you just modify the configuration files to help it find your router, insert the card and then load everything into the case. I plugged the Raspberry Pi into my LED projecter using the HDMI port to look at everything on a system level and to make sure everything was configured and loading correctly.


This is the Raspberry Pi loading up on the LED projector.

This step of looking at the system with the projector helped me debug my initial and thankfully only big issue. The wpa_supplicant form was not being accepted. You have to be careful. My file's quotation marks were being turned into left back ticks by the text editor and this was causing an issue. Since we are configuring an operating system everything has to be quite exact. I re-uploaded a wpa_supplicant file as follows (see below). I also reformatted the drive as I reinstalled the operating system and configuration file to make sure everything runs cleanly. The system was hanging and I had to cut power which is not ideal. The reformatting step was just a precaution to avoid any issues with everything loading.

The wpa_supplicant.conf file that works for MotionEyeOS on the Raspberry Pi Zero W is as follows:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country="Your country you are using the device in"

network={
        ssid="Your home network"
        psk="Your password"
}


Once I got the camera online the next part was to login to the MotionEyeOS portal and finish the additional configurations for the actual motion-detection, video recording, photos and file uploads. I logged into my router to see the assigned IP address for my device and then navigated to the page that  was serving the streaming content from my Pi. Here is where this gets fun. I was able to configure the motion detection to give me instant e-mailed alerts when motion is detected. And then I got the camera to send a sequence of snapshots to a Google Drive whenever motion is detected. On top of all of that Google Drive is a free service so the only real one time expenditure was around $80 for the equipment and everything else is free for the life of the equipment. 


This is a sequence of images recorded by the motion detection system that were then automatically sent to my Google Drive.









FTP file uploading using a Macbook and an AWS EC2 Windows Server

Here I show how to use a Macbook to transfer files via FTP in the cloud between virtual windows machines running on AWS EC2 instances. We will also use a remote desktop connection to control our Windows VM.

You need to setup a few things to get this to work:

1. Instantiate an AWS EC2 Windows Server.

2. Next we install and configure Microsoft Remote Desktop ("MRD") which is the portal we use on our Mac to access our remote instance of Windows on the AWS cloud.

3. Once we are in the AWS EC2 cloud instance of Windows we install Filezilla and log in with the hostname, username and password of our FTP server.

Once we are in logged into our Filezilla FTP client in the cloud the file transfer process becomes very straightforward. On the left is the folder with files and sub-folders that we have access to from our Filezilla FTP server. On the right bottom window we have our remote Windows FTP client. As you see once we double click on trees.jpg and click "send" we then see it on the right and get a confirmation message that our file arrived successfully at our FTP server.


Here we have additional confirmation of receipt of our file to the FTP server. The FTP files are being sent to a folder called "FTP" on the Local Disk (C:). Below you can see the file below was indeed sent through as a clean .jpg when we check our FTP folder. This method can be used to send any type of file and we can setup Filezilla on our local machine or in the cloud as in this example.

Using CURL to send JSON requests & listening with an Ubuntu Netcat server

Here I show how to send a CURL request in a binary format containing JSON key/value pairs. On the other end I show how we are using an Ubuntu Netcat server to listen for our JSON key/value pairs..

I created the following key/value pairs to send through. It's just my e-mail a hashed number and the time of day.

This is a collection of JSON key/value pairs we will send .
Next we go into the terminal on the Macbook locally to use CURL so we can send our key/value pairs.

CURL is what we are using to send the JSON from the terminal
We explicitly state the source of the file on our desktop and the destination (the Netcat server). The command line is pretty straight forward in that the commands are essentially self-explanatory. You just have to be very specific with telling the computer what you are sending, how to send it and where to send it.


Here is a screenshot from the terminal on our cloud based Ubuntu Netcat listening server.
Here I am logged in via SSH to my cloud based Ubuntu Netcat listening server using a local Debian Linux virtual machine. After I sent the JSON POST request as binary data we can view it on the Netcat server. Before we sent our JSON POST we wrote the command "netcat -l 8080" in the terminal which told Netcat to create a listener on port 8080. When it received our request it not only received the data but also logged some information about who sent it. We can see that it was sent with curl as a JSON file via HTTP from a "Host" which is my Macbook Pro.

Automated Exploitation of a Bluetooth vulnerability that leads to 0-click code execution

This blog post covers an interesting vulnerability that was just discovered earlier this year and an open source free tool that was created ...