felmoltor

Kippo - New malware dropped email alert

Jan 16th, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.96 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Author: Felipe Molina (@felmoltor)
  4. # Date: January 2015
  5. # Purpose: This scripts checks for new binaries captured by kippo and send an email when an attacker drops a new one
  6. #          Setup a cronjob to execute this script every 1 minute to receive the email _almost_ in real time, for example:
  7. #          $ crontab -e
  8. #          0/1 * * * * cd /home/<user>/honey/ && ./checkbinaries.sh
  9.  
  10. #############################
  11.  
  12. LASTLS='lastls.txt'
  13. CURRENTLS='currentls.txt'
  14. KIPPODLFOLDER='/home/<user>/honey/kippo/dl/'
  15. NEWMALWAREBASENAME='droppedfiles.7z'
  16. NEWMALWAREZIP="$(date +%s).$(hostname -f).$NEWMALWAREBASENAME"
  17.  
  18. #############################
  19.  
  20. # Cleanup previous sent malware zip file
  21. rm *.$NEWMALWAREBASENAME 2> /dev/null
  22.  
  23. # If last "ls -l" file does not exists, create a new one
  24. if [[ ! -f $LASTLS ]]; then
  25.     echo "Creating $LASTLS file"
  26.     find $KIPPODLFOLDER -maxdepth 1 -type f ! -samefile $0 ! -name $LASTLS ! -name $CURRENTLS ! -name "*.$NEWMALWAREBASENAME" -ls  > $LASTLS   
  27. fi
  28.  
  29. # Diff with last "ls -l" done
  30. find  $KIPPODLFOLDER -maxdepth 1 -type f ! -samefile $0 ! -name $LASTLS ! -name $CURRENTLS ! -name "*.$NEWMALWAREBASENAME" -ls > $CURRENTLS
  31. # If there is a deleted file in the difference, the script will try to send the deleted file, so we filter also with the "<" sign
  32. # < 49818517 1724 -rw-r--r--   1 <user> <user> 1763484 Dec 31 01:00 ./deleted.tgz
  33. newfiles=$(diff $LASTLS $CURRENTLS | grep -vE "^< " | awk '{print $12}')
  34.  
  35. if [[ ${#newfiles} > 0 ]]; then
  36.     # Compress with password the new file to send attached
  37.     7z a -pmalware $NEWMALWAREZIP $newfiles > /dev/null
  38.     # Send an email alerting of the new binary file captured
  39.     echo "New files were captured, sending alert mail"
  40.     echo "Captured binaries (password is 'malware'):  $newfiles" | mutt -s "New files captured in $(hostname -f)" $DSTEMAIL -a $NEWMALWAREZIP
  41. else
  42.     echo "No new bad guy was fooled here :-("
  43. fi
  44.  
  45. cat $CURRENTLS > $LASTLS
  46. rm $CURRENTLS
Advertisement
Add Comment
Please, Sign In to add comment