top of page
OTW

Hack to Spy: Building a Raspberry Spy Pi, Part 3

Updated: Dec 31, 2022


In my previous two posts in this series, I showed you how to set up a Raspberry Pi to be a spy device and then showed you how to use the Pi's software to capture still images from your newly created Spy Pi.

In this article, I will show you how to capture full video from your Raspberry Spy Pi and then create a script that will capture video at discrete intervals to save storage on your tiny spying device.

Step #1 Login to Your Spy Pi with SSH

The first step, of course, is to login to your Spy Pi remotely with SSH.

kali > ssh pi@192.168.1.102

Step #2 Capture Video

Now that we are logged in remotely to our Spy Pi, we can begin to capture video from it. Our Raspbian operating system has a utility named raspivid that is capable of capturing video from the attached raspberry pi camera. To do so, we simply type;

raspberrypi > raspivid -o spytest -t 1000

Where:

raspivid is the video capture command

-o designates the output

spytest is the name of the output file

1000 is the number of hundreds of seconds of video to capture (10s)

As you can see above, we were able to capture 10s of video in a file named spytest. Also, note that the captured video is 1.2M

Step #3 Create a BASH script to Capture Video at Discrete Intervals

As we saw in the previous step, our Spy Pi can capture video using the raspivid command. The problem with this technique is the amount of space that the video consumes. You can see that the 10 seconds video consumed 1.2M. This isn't a lot of space, but if we were trying to capture hours or days of video, we could easily fill terabytes of data space. Unless you attach an external hard drive to our Spy Pi, that will overwhelm our little Spying device.

Perhaps a better approach would be to capture chunks of video at discrete intervals. Maybe... only capture 10 seconds of video every minute. To do this we can write a simple BASH script.

Let's open nano remotely on the Spy Pi or you can open a GUI based text editor directly on the Spy Pi. I will be using nano as my text editor and I suggest you do the same as we will need to access this Spy Pi remotely in the future and a little practice with nano now, will go a long way later. Open nano by typing;

raspberrypi > nano

When it has opened, we can now enter our script.

Our script will look like this;

#! /bin/bash do raspivid -o spycam .$i -t 1000 sleep 60s done

You can see it below in nano.

Note that I have used the for loop integer, i, as a variable in the name of the output file, spycam.$i. In this way, each video capture will be numbered consecutively so that we can go back and view any minute's capture.

Now, hit CTL+X to exit, enter Y to save and give it a name of spyscript.

After we have saved the spyscript, we will need to give ourselves permission to execute it. We can use the chmod command to do so.

raspberrypi > chmod 755 spyscript

As we can see above, after we have changed the permissions and done a long listing, our spyscript now has execute permissions. We are ready to use our Spy Pi to capture hours of video!



Step #4 Run the Script

Now we are ready to run our script that will capture 10 seconds of video every minute. To do so, type;

raspberrypi> sudo ./spyscript

It will now begin to capture 10 seconds of video every minute and store it in files with consecutively numbered names such as spycam.1, spycam2, spycam3, etc. I interrupted mine after just 3 minutes to show you the output, but if you let it run, you will have files spycam.1 all the way to spycam.1000.

This will enable us to view any snippet of video in consecutive order. Obviously, if we wanted to see video from the second hour, we could simply view spycam.61, where 61 designates video from the 61st minute.

Step #5 Reduce Further your Storage Needs

Of course, even this much of video might overwhelm the storage in your tiny Spy Pi. If that is the case, you could increase the sleep time (say sleep 120s or 180s) or reduce the amount of video say to 500 (5s).

In future articles in this series, I will show how to view the video captures remotely as well as capture audio, so keep coming back to Hackers-Arise! and learn the most valuable skill set of the 21st century--hacking!


3,662 views
bottom of page