Marionumber1

wait.sh

Apr 23rd, 2020
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.05 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ct_num=$1
  4. ip_addr=$2
  5.  
  6. # Wait time (in seconds)
  7. WAIT_TIME=300
  8.  
  9. if [ $ct_num -eq "101" ]; then
  10.     ct_ip="172.20.0.2"
  11. else
  12.     ct_ip="172.20.0.3"
  13. fi
  14.  
  15. # Wait for specified amount of time
  16. echo "Started waiting for timeout on container $ct_num"
  17. sleep $WAIT_TIME
  18.  
  19. # Check to see if malware.sh was created; if it was, block the user
  20. ct_files=$(ls -1 /var/lib/lxc/$ct_num/rootfs/root/)
  21. if echo $ct_files | grep "malware.txt"; then
  22.     # Permanently block attacker
  23.     iptables --table filter --insert FORWARD 1 --out-interface vmbr0 --source $ip_addr --destination $ct_ip --jump DROP
  24.     echo "Blocked attacker for ip $ip_addr"
  25. fi
  26.  
  27.  
  28. # Delete previously created rules
  29. iptables --table filter --delete FORWARD --protocol tcp --out-interface vmbr0 --source $ip_addr --destination $ct_ip --destination-port 22 --jump ACCEPT
  30. iptables --table filter --delete FORWARD --protocol tcp --out-interface vmbr0 --source 0.0.0.0/0 --destination $ct_ip --destination-port 22 --jump DROP
  31.  
  32. echo "Beginning recycle of $ct_num"
  33. /root/recycle.sh $ct_num &
  34. exit
Add Comment
Please, Sign In to add comment