dropbear.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 ]: "
  41. read rx
  42. [[ "$rx" = "" ]] && rx="999999999"
  43. echo -e " $(fun_trans "Cual es la tasa TX")"
  44. echo -ne "[ 1 - 999999999 ]: "
  45. read tx
  46. [[ "$tx" = "" ]] && tx="999999999"
  47. apt-get install ethtool -y >/dev/null 2>&1
  48. ethtool -G $eth rx $rx tx $tx >/dev/null 2>&1
  49. }
  50. msg -bar
  51. }
  52. }
  53. fun_bar() {
  54. comando="$1"
  55. _=$(
  56. $comando >/dev/null 2>&1
  57. ) &
  58. >/dev/null
  59. pid=$!
  60. while [[ -d /proc/$pid ]]; do
  61. echo -ne " \033[1;33m["
  62. for ((i = 0; i < 20; i++)); do
  63. echo -ne "\033[1;31m##"
  64. sleep 0.8
  65. done
  66. echo -ne "\033[1;33m]"
  67. sleep 1s
  68. echo
  69. tput cuu1 && tput dl1
  70. done
  71. echo -ne " \033[1;33m[\033[1;31m########################################\033[1;33m] - \033[1;32m100%\033[0m\n"
  72. sleep 1s
  73. }
  74. fun_dropbear() {
  75. [[ -e /etc/default/dropbear ]] && {
  76. msg -bar
  77. echo -e "\033[1;32m $(fun_trans ${id} "REMOVIENDO DROPBEAR")"
  78. msg -bar
  79. service dropbear stop &
  80. >/dev/null 2>&1
  81. fun_bar "apt-get remove dropbear -y"
  82. msg -bar
  83. echo -e "\033[1;32m $(fun_trans "Dropbear Removido")"
  84. msg -bar
  85. [[ -e /etc/default/dropbear ]] && rm /etc/default/dropbear
  86. return 0
  87. }
  88. msg -bar
  89. msg -tit
  90. echo -e "\033[1;32m $(fun_trans " INSTALADOR DROPBEAR | VPS-MX")"
  91. msg -bar
  92. 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"
  93. msg -bar
  94. echo -ne "\033[1;31m $(fun_trans "Digite Puertos"): \033[1;37m" && read DPORT
  95. tput cuu1 && tput dl1
  96. TTOTAL=($DPORT)
  97. for ((i = 0; i < ${#TTOTAL[@]}; i++)); do
  98. [[ $(mportas | grep "${TTOTAL[$i]}") = "" ]] && {
  99. echo -e "\033[1;33m $(fun_trans "Puerto Elegido:")\033[1;32m ${TTOTAL[$i]} OK"
  100. PORT="$PORT ${TTOTAL[$i]}"
  101. } || {
  102. echo -e "\033[1;33m $(fun_trans "Puerto Elegido:")\033[1;31m ${TTOTAL[$i]} FAIL"
  103. }
  104. done
  105. [[ -z $PORT ]] && {
  106. echo -e "\033[1;31m $(fun_trans "Ningun Puerto Valida Fue Elegido")\033[0m"
  107. return 1
  108. }
  109. #sysvar=$(cat -n /etc/issue |grep 1 |cut -d' ' -f6,7,8 |sed 's/1//' |sed 's/ //' | grep -o Ubuntu)
  110. [[ ! $(cat /etc/shells | grep "/bin/false") ]] && echo -e "/bin/false" >>/etc/shells
  111. echo -e "Port 22
  112. Protocol 2
  113. KeyRegenerationInterval 3600
  114. ServerKeyBits 1024
  115. SyslogFacility AUTH
  116. LogLevel INFO
  117. LoginGraceTime 120
  118. PermitRootLogin yes
  119. StrictModes yes
  120. RSAAuthentication yes
  121. PubkeyAuthentication yes
  122. IgnoreRhosts yes
  123. RhostsRSAAuthentication no
  124. HostbasedAuthentication no
  125. PermitEmptyPasswords no
  126. ChallengeResponseAuthentication no
  127. PasswordAuthentication yes
  128. PermitTunnel yes
  129. X11Forwarding yes
  130. X11DisplayOffset 10
  131. PrintMotd no
  132. PrintLastLog yes
  133. TCPKeepAlive yes
  134. #UseLogin no
  135. AcceptEnv LANG LC_*
  136. Subsystem sftp /usr/lib/openssh/sftp-server
  137. UsePAM yes" >/etc/ssh/sshd_config
  138. msg -bar
  139. echo -e "${cor[2]} $(fun_trans ${id} "Iniciando Instalacion dropbear")"
  140. msg -bar
  141. apt-get install dropbear -y &>/dev/null && echo -e "\033[1;33m[\033[1;31mINSTALANDO DROPBEAR\033[1;33m] - \033[1;32m100%\033[0m" | pv -qL10
  142. msg -bar
  143. [[ ! -d /etc/dropbear ]] && mkdir /etc/dropbear
  144. touch /etc/dropbear/banner
  145. msg -bar
  146. echo -e "${cor[2]} $(fun_trans ${id} "Configurando dropbear")"
  147. cat <<EOF >/etc/default/dropbear
  148. NO_START=0
  149. DROPBEAR_EXTRA_ARGS="VAR"
  150. DROPBEAR_BANNER="/etc/dropbear/banner"
  151. DROPBEAR_RECEIVE_WINDOW=65536
  152. EOF
  153. for dpts in $(echo $PORT); do
  154. sed -i "s/VAR/-p $dpts VAR/g" /etc/default/dropbear
  155. done
  156. sed -i "s/VAR//g" /etc/default/dropbear
  157. #fun_eth
  158. service ssh restart >/dev/null 2>&1
  159. service dropbear restart >/dev/null 2>&1
  160. echo -e "${cor[3]} $(fun_trans "Su dropbear ha sido configurado con EXITO")"
  161. msg -bar
  162. #UFW
  163. for ufww in $(mportas | awk '{print $2}'); do
  164. ufw allow $ufww >/dev/null 2>&1
  165. done
  166. }
  167. fun_dropbear