check-ssh.sh 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #!/bin/bash
  2. case $1 in
  3. Protocol)
  4. if [ "$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' /etc/ssh/sshd_config | grep -w "^Protocol" | awk '{print $2}')" -ne 2 ];then
  5. exit 1
  6. fi
  7. ;;
  8. rhosts)
  9. if [ "$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' /etc/ssh/sshd_config | grep -i IgnoreRhosts | awk '{print $2}')" != "yes" ];then
  10. exit 1
  11. fi
  12. ;;
  13. hostauth)
  14. if [ "$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' /etc/ssh/sshd_config | grep -i HostbasedAuthentication | awk '{print $2}')" != "no" ];then
  15. exit 1
  16. fi
  17. ;;
  18. permitroot)
  19. if [ "$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' /etc/ssh/sshd_config | grep -i PermitRootLogin | awk '{print $2}')" != "no" ];then
  20. exit 1
  21. fi
  22. ;;
  23. emptypassword)
  24. if [ "$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' /etc/ssh/sshd_config | grep -i PermitEmptyPasswords | awk '{print $2}')" != "no" ];then
  25. exit 1
  26. fi
  27. ;;
  28. emptypasswordenvironment)
  29. if [ "$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' /etc/ssh/sshd_config | grep -i PermitEmptyPasswords | awk '{print $2}')" != "no" ];then
  30. exit 1
  31. fi
  32. ;;
  33. ciphers)
  34. if grep -i "Ciphers.*aes128-ctr\|Ciphers.*aes256-ctr\|Ciphers.*aes192-ctr" /etc/ssh/sshd_config;then
  35. :
  36. else
  37. exit 1
  38. fi
  39. ;;
  40. banner)
  41. if grep -i banner /etc/ssh/sshd_config | grep -v "^#";then
  42. :
  43. else
  44. exit 1
  45. fi
  46. ;;
  47. installed)
  48. OPENSSH_SERVER=`dpkg -s openssh-server | grep -i "Status:.*install.*ok.*installed" | wc -l`
  49. OPENSSH_CLIENT=`dpkg -s openssh-client | grep -i "Status:.*install.*ok.*installed" | wc -l`
  50. if [ ${OPENSSH_SERVER} -eq 1 -a ${OPENSSH_CLIENT} -eq 1 ];then
  51. :
  52. else
  53. exit 1
  54. fi
  55. ;;
  56. sshd_status)
  57. if systemctl status sshd | grep "Active:.*(running)";then
  58. :
  59. else
  60. exit 1
  61. fi
  62. ;;
  63. ClientAliveInterval)
  64. if grep ClientAliveInterval /etc/ssh/sshd_config | grep -v "^#";then
  65. INTERVAL=`grep ClientAliveInterval /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  66. if [ ${INTERVAL} -lt 60 ];then
  67. exit 1
  68. fi
  69. else
  70. exit 1
  71. fi
  72. ;;
  73. RhostsRSAAuthentication)
  74. if grep RhostsRSAAuthentication /etc/ssh/sshd_config | grep -v "^#";then
  75. SETVALUE=`grep RhostsRSAAuthentication /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  76. if [ "${SETVALUE}" == "no" ];then
  77. exit 1
  78. fi
  79. else
  80. exit 1
  81. fi
  82. ;;
  83. ClientAliveCountMax)
  84. if grep ClientAliveCountMax /etc/ssh/sshd_config | grep -v "^#";then
  85. SETVALUE=`grep ClientAliveCountMax /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  86. if [ ${SETVALUE} -gt 3 ];then
  87. exit 1
  88. fi
  89. else
  90. exit 1
  91. fi
  92. ;;
  93. IgnoreRhosts)
  94. if grep IgnoreRhosts /etc/ssh/sshd_config | grep -v "^#";then
  95. SETVALUE=`grep IgnoreRhosts /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  96. if [ "${SETVALUE}" == "no" ];then
  97. exit 1
  98. fi
  99. else
  100. exit 1
  101. fi
  102. ;;
  103. PrintLastLog)
  104. if grep PrintLastLog /etc/ssh/sshd_config | grep -v "^#";then
  105. SETVALUE=`grep PrintLastLog /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  106. if [ "${SETVALUE}" != "yes" ];then
  107. exit 1
  108. fi
  109. else
  110. exit 1
  111. fi
  112. ;;
  113. IgnoreUserKnownHosts)
  114. if grep IgnoreUserKnownHosts /etc/ssh/sshd_config | grep -v "^#";then
  115. SETVALUE=`grep IgnoreUserKnownHosts /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  116. if [ "${SETVALUE}" != "yes" ];then
  117. exit 1
  118. fi
  119. else
  120. exit 1
  121. fi
  122. ;;
  123. macs)
  124. if grep -i "MACs.*hmac-sha2-256\|MACs.*hmac-sha2-512" /etc/ssh/sshd_config;then
  125. :
  126. else
  127. exit 1
  128. fi
  129. ;;
  130. pubkeypermissive)
  131. COUNT=`find /etc/ssh/ -type f -name "*.pub" -perm /133 -exec ls -l {} \; | wc -l`
  132. if [ ${COUNT} -eq 0 ];then
  133. :
  134. else
  135. exit 1
  136. fi
  137. ;;
  138. hostkeypermissive)
  139. COUNT=`find /etc/ssh/ -type f -name "*ssh_host*key" -perm /177 -exec ls -l {} \; | wc -l`
  140. if [ ${COUNT} -eq 0 ];then
  141. :
  142. else
  143. exit 1
  144. fi
  145. ;;
  146. GSSAPIAuthentication)
  147. if grep GSSAPIAuthentication /etc/ssh/sshd_config | grep -v "^#";then
  148. SETVALUE=`grep GSSAPIAuthentication /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  149. if [ "${SETVALUE}" != "no" ];then
  150. exit 1
  151. fi
  152. else
  153. exit 1
  154. fi
  155. ;;
  156. KerberosAuthentication)
  157. if grep KerberosAuthentication /etc/ssh/sshd_config | grep -v "^#";then
  158. SETVALUE=`grep KerberosAuthentication /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  159. if [ "${SETVALUE}" != "no" ];then
  160. exit 1
  161. fi
  162. else
  163. exit 1
  164. fi
  165. ;;
  166. StrictModes)
  167. if grep StrictModes /etc/ssh/sshd_config | grep -v "^#";then
  168. SETVALUE=`grep StrictModes /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  169. if [ "${SETVALUE}" != "yes" ];then
  170. exit 1
  171. fi
  172. else
  173. exit 1
  174. fi
  175. ;;
  176. UsePrivilegeSeparation)
  177. if grep UsePrivilegeSeparation /etc/ssh/sshd_config | grep -v "^#";then
  178. SETVALUE=`grep UsePrivilegeSeparation /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  179. if [ "${SETVALUE}" != "yes" -a "${SETVALUE}" != "sandbox" ];then
  180. exit 1
  181. fi
  182. else
  183. exit 1
  184. fi
  185. ;;
  186. Compression)
  187. if grep Compression /etc/ssh/sshd_config | grep -v "^#";then
  188. SETVALUE=`grep Compression /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  189. if [ "${SETVALUE}" != "no" -a "${SETVALUE}" != "delayed" ];then
  190. exit 1
  191. fi
  192. else
  193. exit 1
  194. fi
  195. ;;
  196. X11Forwarding)
  197. if grep X11Forwarding /etc/ssh/sshd_config | grep -v "^#";then
  198. SETVALUE=`grep X11Forwarding /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  199. if [ "${SETVALUE}" != "no" ];then
  200. exit 1
  201. fi
  202. else
  203. exit 1
  204. fi
  205. ;;
  206. pam_python)
  207. if grep -q 'pam_python' /etc/pam.d/sshd; then
  208. exit 1
  209. fi
  210. ;;
  211. esac