dropbear.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #!/bin/bash
  2. #25/01/2021
  3. clear
  4. clear
  5. SCPdir="/etc/VPS-MX"
  6. SCPfrm="${SCPdir}/herramientas" && [[ ! -d ${SCPfrm} ]] && exit
  7. SCPinst="${SCPdir}/protocolos"&& [[ ! -d ${SCPinst} ]] && exit
  8. declare -A cor=( [0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m" )
  9. mportas () {
  10. unset portas
  11. portas_var=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
  12. while read port; do
  13. var1=$(echo $port | awk '{print $1}') && var2=$(echo $port | awk '{print $9}' | awk -F ":" '{print $2}')
  14. [[ "$(echo -e $portas|grep "$var1 $var2")" ]] || portas+="$var1 $var2\n"
  15. done <<< "$portas_var"
  16. i=1
  17. echo -e "$portas"
  18. }
  19. fun_ip () {
  20. if [[ -e /etc/VPS-MX/MEUIPvps ]]; then
  21. IP="$(cat /etc/VPS-MX/MEUIPvps)"
  22. else
  23. MEU_IP=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
  24. MEU_IP2=$(wget -qO- ipv4.icanhazip.com)
  25. [[ "$MEU_IP" != "$MEU_IP" ]] && IP="$MEU_IP2" || IP="$MEU_IP"
  26. echo "$MEU_IP" > /etc/VPS-MX/MEUIPvps
  27. fi
  28. }
  29. fun_eth () {
  30. eth=$(ifconfig | grep -v inet6 | grep -v lo | grep -v 127.0.0.1 | grep "encap:Ethernet" | awk '{print $1}')
  31. [[ $eth != "" ]] && {
  32. msg -bar
  33. echo -e "${cor[3]} $(fun_trans "Aplicar Mejoras Para Mejorar Paquetes SSH?")"
  34. echo -e "${cor[3]} $(fun_trans "Opcion Para Usuarios Avanzados")"
  35. msg -bar
  36. read -p " [S/N]: " -e -i n sshsn
  37. [[ "$sshsn" = @(s|S|y|Y) ]] && {
  38. echo -e "${cor[1]} $(fun_trans "Correccion de problemas de paquetes en SSH...")"
  39. echo -e " $(fun_trans "Cual es la tasa RX")"
  40. echo -ne "[ 1 - 999999999 ]: "; read rx
  41. [[ "$rx" = "" ]] && rx="999999999"
  42. echo -e " $(fun_trans "Cual es la tasa TX")"
  43. echo -ne "[ 1 - 999999999 ]: "; read tx
  44. [[ "$tx" = "" ]] && tx="999999999"
  45. apt-get install ethtool -y > /dev/null 2>&1
  46. ethtool -G $eth rx $rx tx $tx > /dev/null 2>&1
  47. }
  48. msg -bar
  49. }
  50. }
  51. fun_bar () {
  52. comando="$1"
  53. _=$(
  54. $comando > /dev/null 2>&1
  55. ) & > /dev/null
  56. pid=$!
  57. while [[ -d /proc/$pid ]]; do
  58. echo -ne " \033[1;33m["
  59. for((i=0; i<20; i++)); do
  60. echo -ne "\033[1;31m##"
  61. sleep 0.8
  62. done
  63. echo -ne "\033[1;33m]"
  64. sleep 1s
  65. echo
  66. tput cuu1 && tput dl1
  67. done
  68. echo -ne " \033[1;33m[\033[1;31m########################################\033[1;33m] - \033[1;32m100%\033[0m\n"
  69. sleep 1s
  70. }
  71. fun_dropbear () {
  72. [[ -e /etc/default/dropbear ]] && {
  73. msg -bar
  74. echo -e "\033[1;32m $(fun_trans ${id} "REMOVIENDO DROPBEAR")"
  75. msg -bar
  76. service dropbear stop & >/dev/null 2>&1
  77. fun_bar "apt-get remove dropbear -y"
  78. msg -bar
  79. echo -e "\033[1;32m $(fun_trans "Dropbear Removido")"
  80. msg -bar
  81. [[ -e /etc/default/dropbear ]] && rm /etc/default/dropbear
  82. return 0
  83. }
  84. msg -bar
  85. msg -tit
  86. echo -e "\033[1;32m $(fun_trans " INSTALADOR DROPBEAR | VPS-MX By @Kalix1")"
  87. msg -bar
  88. echo -e "\033[1;31m $(fun_trans "Seleccione Puertos Validados en orden secuencial:\n")\033[1;32m 22 80 81 82 85 90\033[1;37m"
  89. msg -bar
  90. echo -ne "\033[1;31m $(fun_trans "Digite Puertos"): \033[1;37m" && read DPORT
  91. tput cuu1 && tput dl1
  92. TTOTAL=($DPORT)
  93. for((i=0; i<${#TTOTAL[@]}; i++)); do
  94. [[ $(mportas|grep "${TTOTAL[$i]}") = "" ]] && {
  95. echo -e "\033[1;33m $(fun_trans "Puerto Elegido:")\033[1;32m ${TTOTAL[$i]} OK"
  96. PORT="$PORT ${TTOTAL[$i]}"
  97. } || {
  98. echo -e "\033[1;33m $(fun_trans "Puerto Elegido:")\033[1;31m ${TTOTAL[$i]} FAIL"
  99. }
  100. done
  101. [[ -z $PORT ]] && {
  102. echo -e "\033[1;31m $(fun_trans "Ningun Puerto Valida Fue Elegido")\033[0m"
  103. return 1
  104. }
  105. sysvar=$(cat -n /etc/issue |grep 1 |cut -d' ' -f6,7,8 |sed 's/1//' |sed 's/ //' | grep -o Ubuntu)
  106. [[ ! $(cat /etc/shells|grep "/bin/false") ]] && echo -e "/bin/false" >> /etc/shells
  107. [[ "$sysvar" != "" ]] && {
  108. echo -e "Port 22
  109. Protocol 2
  110. KeyRegenerationInterval 3600
  111. ServerKeyBits 1024
  112. SyslogFacility AUTH
  113. LogLevel INFO
  114. LoginGraceTime 120
  115. PermitRootLogin yes
  116. StrictModes yes
  117. RSAAuthentication yes
  118. PubkeyAuthentication yes
  119. IgnoreRhosts yes
  120. RhostsRSAAuthentication no
  121. HostbasedAuthentication no
  122. PermitEmptyPasswords no
  123. ChallengeResponseAuthentication no
  124. PasswordAuthentication yes
  125. X11Forwarding yes
  126. X11DisplayOffset 10
  127. PrintMotd no
  128. PrintLastLog yes
  129. TCPKeepAlive yes
  130. #UseLogin no
  131. AcceptEnv LANG LC_*
  132. Subsystem sftp /usr/lib/openssh/sftp-server
  133. UsePAM yes" > /etc/ssh/sshd_config
  134. msg -bar
  135. echo -e "${cor[2]} $(fun_trans ${id} "Instalando dropbear")"
  136. msg -bar
  137. fun_bar "apt-get install dropbear -y"
  138. apt-get install dropbear -y > /dev/null 2>&1
  139. msg -bar
  140. touch /etc/dropbear/banner
  141. msg -bar
  142. echo -e "${cor[2]} $(fun_trans ${id} "Configurando dropbear")"
  143. cat <<EOF > /etc/default/dropbear
  144. NO_START=0
  145. DROPBEAR_EXTRA_ARGS="VAR"
  146. DROPBEAR_BANNER="/etc/dropbear/banner"
  147. DROPBEAR_RECEIVE_WINDOW=65536
  148. EOF
  149. for dpts in $(echo $PORT); do
  150. sed -i "s/VAR/-p $dpts VAR/g" /etc/default/dropbear
  151. done
  152. sed -i "s/VAR//g" /etc/default/dropbear
  153. } || {
  154. echo -e "Port 22
  155. Protocol 2
  156. KeyRegenerationInterval 3600
  157. ServerKeyBits 1024
  158. SyslogFacility AUTH
  159. LogLevel INFO
  160. LoginGraceTime 120
  161. PermitRootLogin yes
  162. StrictModes yes
  163. RSAAuthentication yes
  164. PubkeyAuthentication yes
  165. IgnoreRhosts yes
  166. RhostsRSAAuthentication no
  167. HostbasedAuthentication no
  168. PermitEmptyPasswords no
  169. ChallengeResponseAuthentication no
  170. PasswordAuthentication yes
  171. X11Forwarding yes
  172. X11DisplayOffset 10
  173. PrintMotd no
  174. PrintLastLog yes
  175. TCPKeepAlive yes
  176. #UseLogin no
  177. AcceptEnv LANG LC_*
  178. Subsystem sftp /usr/lib/openssh/sftp-server
  179. UsePAM yes" > /etc/ssh/sshd_config
  180. echo -e "${cor[2]} $(fun_trans "Instalando dropbear")"
  181. msg -bar
  182. fun_bar "apt-get install dropbear -y"
  183. touch /etc/dropbear/banner
  184. msg -bar
  185. echo -e "${cor[2]} $(fun_trans "Configurando dropbear")"
  186. msg -bar
  187. cat <<EOF > /etc/default/dropbear
  188. NO_START=0
  189. DROPBEAR_EXTRA_ARGS="VAR"
  190. DROPBEAR_BANNER="/etc/dropbear/banner"
  191. DROPBEAR_RECEIVE_WINDOW=65536
  192. EOF
  193. for dpts in $(echo $PORT); do
  194. sed -i "s/VAR/-p $dpts VAR/g" /etc/default/dropbear
  195. done
  196. sed -i "s/VAR//g" /etc/default/dropbear
  197. }
  198. fun_eth
  199. service ssh restart > /dev/null 2>&1
  200. service dropbear restart > /dev/null 2>&1
  201. echo -e "${cor[3]} $(fun_trans "Su dropbear ha sido configurado con EXITO")"
  202. msg -bar
  203. #UFW
  204. for ufww in $(mportas|awk '{print $2}'); do
  205. ufw allow $ufww > /dev/null 2>&1
  206. done
  207. }
  208. fun_dropbear