123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 ]; then
  51. if [ ${OPENSSH_CLIENT} -eq 1 ]; then
  52. :
  53. else
  54. exit 1
  55. fi
  56. else
  57. exit 1
  58. fi
  59. ;;
  60. sshd_status)
  61. if systemctl status sshd | grep "Active:.*(running)";then
  62. :
  63. else
  64. exit 1
  65. fi
  66. ;;
  67. ClientAliveInterval)
  68. if grep ClientAliveInterval /etc/ssh/sshd_config | grep -v "^#";then
  69. INTERVAL=`grep ClientAliveInterval /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  70. if [ ${INTERVAL} -lt 60 ];then
  71. exit 1
  72. fi
  73. else
  74. exit 1
  75. fi
  76. ;;
  77. RhostsRSAAuthentication)
  78. if grep RhostsRSAAuthentication /etc/ssh/sshd_config | grep -v "^#";then
  79. SETVALUE=`grep RhostsRSAAuthentication /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  80. if [ "${SETVALUE}" == "no" ];then
  81. exit 1
  82. fi
  83. else
  84. exit 1
  85. fi
  86. ;;
  87. ClientAliveCountMax)
  88. if grep ClientAliveCountMax /etc/ssh/sshd_config | grep -v "^#";then
  89. SETVALUE=`grep ClientAliveCountMax /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  90. if [ ${SETVALUE} -gt 3 ];then
  91. exit 1
  92. fi
  93. else
  94. exit 1
  95. fi
  96. ;;
  97. IgnoreRhosts)
  98. if grep IgnoreRhosts /etc/ssh/sshd_config | grep -v "^#";then
  99. SETVALUE=`grep IgnoreRhosts /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  100. if [ "${SETVALUE}" == "no" ];then
  101. exit 1
  102. fi
  103. else
  104. exit 1
  105. fi
  106. ;;
  107. PrintLastLog)
  108. if grep PrintLastLog /etc/ssh/sshd_config | grep -v "^#";then
  109. SETVALUE=`grep PrintLastLog /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  110. if [ "${SETVALUE}" != "yes" ];then
  111. exit 1
  112. fi
  113. else
  114. exit 1
  115. fi
  116. ;;
  117. IgnoreUserKnownHosts)
  118. if grep IgnoreUserKnownHosts /etc/ssh/sshd_config | grep -v "^#";then
  119. SETVALUE=`grep IgnoreUserKnownHosts /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  120. if [ "${SETVALUE}" != "yes" ];then
  121. exit 1
  122. fi
  123. else
  124. exit 1
  125. fi
  126. ;;
  127. macs)
  128. if grep -i "MACs.*hmac-sha2-256\|MACs.*hmac-sha2-512" /etc/ssh/sshd_config;then
  129. :
  130. else
  131. exit 1
  132. fi
  133. ;;
  134. pubkeypermissive)
  135. COUNT=`find /etc/ssh/ -type f -name "*.pub" -perm /133 -exec ls -l {} \; | wc -l`
  136. if [ ${COUNT} -eq 0 ];then
  137. :
  138. else
  139. exit 1
  140. fi
  141. ;;
  142. hostkeypermissive)
  143. COUNT=`find /etc/ssh/ -type f -name "*ssh_host*key" -perm /177 -exec ls -l {} \; | wc -l`
  144. if [ ${COUNT} -eq 0 ];then
  145. :
  146. else
  147. exit 1
  148. fi
  149. ;;
  150. GSSAPIAuthentication)
  151. if grep GSSAPIAuthentication /etc/ssh/sshd_config | grep -v "^#";then
  152. SETVALUE=`grep GSSAPIAuthentication /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  153. if [ "${SETVALUE}" != "no" ];then
  154. exit 1
  155. fi
  156. else
  157. exit 1
  158. fi
  159. ;;
  160. KerberosAuthentication)
  161. if grep KerberosAuthentication /etc/ssh/sshd_config | grep -v "^#";then
  162. SETVALUE=`grep KerberosAuthentication /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  163. if [ "${SETVALUE}" != "no" ];then
  164. exit 1
  165. fi
  166. else
  167. exit 1
  168. fi
  169. ;;
  170. StrictModes)
  171. if grep StrictModes /etc/ssh/sshd_config | grep -v "^#";then
  172. SETVALUE=`grep StrictModes /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  173. if [ "${SETVALUE}" != "yes" ];then
  174. exit 1
  175. fi
  176. else
  177. exit 1
  178. fi
  179. ;;
  180. UsePrivilegeSeparation)
  181. if grep UsePrivilegeSeparation /etc/ssh/sshd_config | grep -v "^#";then
  182. SETVALUE=`grep UsePrivilegeSeparation /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  183. if [ "${SETVALUE}" != "yes" -a "${SETVALUE}" != "sandbox" ];then
  184. exit 1
  185. fi
  186. else
  187. exit 1
  188. fi
  189. ;;
  190. Compression)
  191. if grep Compression /etc/ssh/sshd_config | grep -v "^#";then
  192. SETVALUE=`grep Compression /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  193. if [ "${SETVALUE}" != "no" -a "${SETVALUE}" != "delayed" ];then
  194. exit 1
  195. fi
  196. else
  197. exit 1
  198. fi
  199. ;;
  200. X11Forwarding)
  201. if grep X11Forwarding /etc/ssh/sshd_config | grep -v "^#";then
  202. SETVALUE=`grep X11Forwarding /etc/ssh/sshd_config | grep -v "^#" | awk '{printf $2}'`
  203. if [ "${SETVALUE}" != "no" ];then
  204. exit 1
  205. fi
  206. else
  207. exit 1
  208. fi
  209. ;;
  210. pam_python)
  211. if grep -q 'pam_python' /etc/pam.d/sshd; then
  212. exit 1
  213. fi
  214. ;;
  215. esac