| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # |
| 3 | # DigitalOcean Marketplace Image Validation Tool |
| 4 | # © 2018 DigitalOcean LLC. |
| 5 | # This code is licensed under MIT license (see LICENSE.txt for details) |
| 6 | # |
| 7 | VERSION="v. 1.5" |
| 8 | RUNDATE=$( datescip-shell system . . date. ) |
| 9 | |
| 10 | # Script should be run with SUDO |
| 11 | if [scip-shell system . . `[`. "$EUID" -ne 0 ] |
| 12 | then echoscip-shell system . . echo. "[Error] - This script must be run with sudo or as the root user." |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | STATUS=0 |
| 17 | PASS=0 |
| 18 | WARN=0 |
| 19 | FAIL=0 |
| 20 | |
| 21 | # $1 == command to check for |
| 22 | # returns: 0 == true, 1 == false |
| 23 | cmdExistsscip-shell shell shell-project 0.0.0 cmdExists().() { |
| 24 | if command -v "$1" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then |
| 25 | return 0 |
| 26 | else |
| 27 | return 1 |
| 28 | fi |
| 29 | } |
| 30 | |
| 31 | function getDistroscip-shell shell shell-project 0.0.0 getDistro(). { |
| 32 | if [scip-shell system . . `[`. -f /etc/os-releasescip-shell filesystem . . `/etc/os-release`. ]; then |
| 33 | # freedesktop.org and systemd |
| 34 | . /etc/os-releasescip-shell source . . `/etc/os-release`. |
| 35 | OS=$NAME |
| 36 | VER=$VERSION_ID |
| 37 | elif type lsb_release >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then |
| 38 | # linuxbase.org |
| 39 | OS=$(lsb_release -si) |
| 40 | VER=$(lsb_release -sr) |
| 41 | elif [scip-shell system . . `[`. -f /etc/lsb-releasescip-shell filesystem . . `/etc/lsb-release`. ]; then |
| 42 | # For some versions of Debian/Ubuntu without lsb_release command |
| 43 | . /etc/lsb-releasescip-shell source . . `/etc/lsb-release`. |
| 44 | OS=$DISTRIB_ID |
| 45 | VER=$DISTRIB_RELEASE |
| 46 | elif [scip-shell system . . `[`. -f /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then |
| 47 | # Older Debian/Ubuntu/etc. |
| 48 | OS=Debian |
| 49 | VER=$(catscip-shell system . . cat. /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`.) |
| 50 | elif [scip-shell system . . `[`. -f /etc/SuSe-releasescip-shell filesystem . . `/etc/SuSe-release`. ]; then |
| 51 | # Older SuSE/etc. |
| 52 | : |
| 53 | elif [scip-shell system . . `[`. -f /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`. ]; then |
| 54 | # Older Red Hat, CentOS, etc. |
| 55 | VER=$( catscip-shell system . . cat. /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`. | cutscip-shell system . . cut. -d" " -f3 | cutscip-shell system . . cut. -d "." -f1) |
| 56 | d=$( catscip-shell system . . cat. /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`. | cutscip-shell system . . cut. -d" " -f1 | cutscip-shell system . . cut. -d "." -f1) |
| 57 | if [[ $d == "CentOS" ]]; then |
| 58 | OS="CentOS Linux" |
| 59 | fi |
| 60 | else |
| 61 | # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc. |
| 62 | OS=$(unamescip-shell system . . uname. -s) |
| 63 | VER=$(unamescip-shell system . . uname. -r) |
| 64 | fi |
| 65 | } |
| 66 | function loadPasswordsscip-shell shell shell-project 0.0.0 loadPasswords(). { |
| 67 | SHADOW=$(catscip-shell system . . cat. /etc/shadowscip-shell filesystem . . `/etc/shadow`.) |
| 68 | } |
| 69 | |
| 70 | function checkAgentscip-shell shell shell-project 0.0.0 checkAgent(). { |
| 71 | # Check for the presence of the do-agent in the filesystem |
| 72 | if [scip-shell system . . `[`. -d /var/opt/digitalocean/do-agentscip-shell filesystem . . `/var/opt/digitalocean/do-agent`. ];then |
| 73 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m DigitalOcean Monitoring Agent detected.\n" |
| 74 | ((FAIL++)) |
| 75 | STATUS=2 |
| 76 | if [[ $OS == "CentOS Linux" ]]; then |
| 77 | echoscip-shell system . . echo. "The agent can be removed with 'sudo yum remove do-agent' " |
| 78 | elif [[ $OS == "Ubuntu" ]]; then |
| 79 | echoscip-shell system . . echo. "The agent can be removed with 'sudo apt-get purge do-agent' " |
| 80 | fi |
| 81 | else |
| 82 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m DigitalOcean Monitoring agent was not found\n" |
| 83 | ((PASS++)) |
| 84 | fi |
| 85 | } |
| 86 | |
| 87 | function checkLogsscip-shell shell shell-project 0.0.0 checkLogs(). { |
| 88 | cp_ignore="/var/log/cpanel-install.logscip-shell filesystem . . `/var/log/cpanel-install.log`." |
| 89 | echoscip-shell system . . echo. -en "\nChecking for log files in /var/log\n\n" |
| 90 | # Check if there are log archives or log files that have not been recently cleared. |
| 91 | for f in /var/log/*-????????; do |
| 92 | [[ -e $f ]] || break |
| 93 | if [scip-shell system . . `[`. $f != $cp_ignore ]; then |
| 94 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m Log archive ${f} found\n" |
| 95 | ((WARN++)) |
| 96 | if [[ $STATUS != 2 ]]; then |
| 97 | STATUS=1 |
| 98 | fi |
| 99 | fi |
| 100 | done |
| 101 | for f in /var/log/*.[0-9];do |
| 102 | [[ -e $f ]] || break |
| 103 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m Log archive ${f} found\n" |
| 104 | ((WARN++)) |
| 105 | if [[ $STATUS != 2 ]]; then |
| 106 | STATUS=1 |
| 107 | fi |
| 108 | done |
| 109 | for f in /var/log/*.log; do |
| 110 | [[ -e $f ]] || break |
| 111 | if [[ "${f}" = '/var/log/lfd.log' && "$( cat "${f}" | egrep -v '/var/log/messages has been reset| Watching /var/log/messages' | wc -c)" -gt 50 ]]; then |
| 112 | if [scip-shell system . . `[`. $f != $cp_ignore ]; then |
| 113 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m un-cleared log file, ${f} found\n" |
| 114 | ((WARN++)) |
| 115 | if [[ $STATUS != 2 ]]; then |
| 116 | STATUS=1 |
| 117 | fi |
| 118 | fi |
| 119 | elif [[ "${f}" != '/var/log/lfd.log' && "$( cat "${f}" | wc -c)" -gt 50 ]]; then |
| 120 | if [scip-shell system . . `[`. $f != $cp_ignore ]; then |
| 121 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m un-cleared log file, ${f} found\n" |
| 122 | ((WARN++)) |
| 123 | if [[ $STATUS != 2 ]]; then |
| 124 | STATUS=1 |
| 125 | fi |
| 126 | fi |
| 127 | fi |
| 128 | done |
| 129 | } |
| 130 | function checkTMPscip-shell shell shell-project 0.0.0 checkTMP(). { |
| 131 | # Check the /tmp directory to ensure it is empty. Warn on any files found. |
| 132 | return 1 |
| 133 | } |
| 134 | function checkRootscip-shell shell shell-project 0.0.0 checkRoot(). { |
| 135 | user="root" |
| 136 | uhome="/rootscip-shell filesystem . . `/root`." |
| 137 | for usr in $SHADOW |
| 138 | do |
| 139 | IFS=':' read -r -a u <<< "$usr" |
| 140 | if [[ "${u[0]}" == "${user}" ]]; then |
| 141 | if [[ ${u[1]} == "!" ]] || [[ ${u[1]} == "!!" ]] || [[ ${u[1]} == "*" ]]; then |
| 142 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m User ${user} has no password set.\n" |
| 143 | ((PASS++)) |
| 144 | else |
| 145 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m User ${user} has a password set on their account.\n" |
| 146 | ((FAIL++)) |
| 147 | STATUS=2 |
| 148 | fi |
| 149 | fi |
| 150 | done |
| 151 | if [scip-shell system . . `[`. -d ${uhome}/ ]; then |
| 152 | if [scip-shell system . . `[`. -d ${uhome}/.ssh/ ]; then |
| 153 | if lsscip-shell system . . ls. ${uhome}/.ssh/*> /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then |
| 154 | for key in ${uhome}/.ssh/* |
| 155 | do |
| 156 | if [scip-shell system . . `[`. "${key}" == "${uhome}/.ssh/authorized_keys" ]; then |
| 157 | |
| 158 | if [scip-shell system . . `[`. "$( catscip-shell system . . cat. "${key}" | wcscip-shell system . . wc. -c)" -gt 50 ]; then |
| 159 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m User \e[1m${user}\e[0m has a populated authorized_keys file in \e[93m${key}\e[0m\n" |
| 160 | akey=$(catscip-shell system . . cat. ${key}) |
| 161 | echoscip-shell system . . echo. "File Contents:" |
| 162 | echoscip-shell system . . echo. $akey |
| 163 | echoscip-shell system . . echo. "--------------" |
| 164 | ((FAIL++)) |
| 165 | STATUS=2 |
| 166 | fi |
| 167 | elif [scip-shell system . . `[`. "${key}" == "${uhome}/.ssh/id_rsa" ]; then |
| 168 | if [scip-shell system . . `[`. "$( catscip-shell system . . cat. "${key}" | wcscip-shell system . . wc. -c)" -gt 0 ]; then |
| 169 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m User \e[1m${user}\e[0m has a private key file in \e[93m${key}\e[0m\n" |
| 170 | akey=$(catscip-shell system . . cat. ${key}) |
| 171 | echoscip-shell system . . echo. "File Contents:" |
| 172 | echoscip-shell system . . echo. $akey |
| 173 | echoscip-shell system . . echo. "--------------" |
| 174 | ((FAIL++)) |
| 175 | STATUS=2 |
| 176 | else |
| 177 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m User \e[1m${user}\e[0m has empty private key file in \e[93m${key}\e[0m\n" |
| 178 | ((WARN++)) |
| 179 | if [[ $STATUS != 2 ]]; then |
| 180 | STATUS=1 |
| 181 | fi |
| 182 | fi |
| 183 | elif [scip-shell system . . `[`. "${key}" != "${uhome}/.ssh/known_hosts" ]; then |
| 184 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m User \e[1m${user}\e[0m has a file in their .ssh directory at \e[93m${key}\e[0m\n" |
| 185 | ((WARN++)) |
| 186 | if [[ $STATUS != 2 ]]; then |
| 187 | STATUS=1 |
| 188 | fi |
| 189 | else |
| 190 | if [scip-shell system . . `[`. "$( catscip-shell system . . cat. "${key}" | wcscip-shell system . . wc. -c)" -gt 50 ]; then |
| 191 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m User \e[1m${user}\e[0m has a populated known_hosts file in \e[93m${key}\e[0m\n" |
| 192 | ((WARN++)) |
| 193 | if [[ $STATUS != 2 ]]; then |
| 194 | STATUS=1 |
| 195 | fi |
| 196 | fi |
| 197 | fi |
| 198 | done |
| 199 | else |
| 200 | echoscip-shell system . . echo. -en "\e[32m[ OK ]\e[0m User \e[1m${user}\e[0m has no SSH keys present\n" |
| 201 | fi |
| 202 | else |
| 203 | echoscip-shell system . . echo. -en "\e[32m[ OK ]\e[0m User \e[1m${user}\e[0m does not have an .ssh directory\n" |
| 204 | fi |
| 205 | if [scip-shell system . . `[`. -f /root/.bash_historyscip-shell filesystem . . `/root/.bash_history`. ];then |
| 206 | |
| 207 | BH_S=$( catscip-shell system . . cat. /root/.bash_historyscip-shell filesystem . . `/root/.bash_history`. | wcscip-shell system . . wc. -c) |
| 208 | |
| 209 | if [[ $BH_S -lt 200 ]]; then |
| 210 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m ${user}'s Bash History appears to have been cleared\n" |
| 211 | ((PASS++)) |
| 212 | else |
| 213 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m ${user}'s Bash History should be cleared to prevent sensitive information from leaking\n" |
| 214 | ((FAIL++)) |
| 215 | STATUS=2 |
| 216 | fi |
| 217 | |
| 218 | return 1; |
| 219 | else |
| 220 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m The Root User's Bash History is not present\n" |
| 221 | ((PASS++)) |
| 222 | fi |
| 223 | else |
| 224 | echoscip-shell system . . echo. -en "\e[32m[ OK ]\e[0m User \e[1m${user}\e[0m does not have a directory in /home\n" |
| 225 | fi |
| 226 | echoscip-shell system . . echo. -en "\n\n" |
| 227 | return 1 |
| 228 | } |
| 229 | |
| 230 | function checkUsersscip-shell shell shell-project 0.0.0 checkUsers(). { |
| 231 | # Check each user-created account |
| 232 | for user in $(awkscip-shell system . . awk. -F: '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwdscip-shell filesystem . . `/etc/passwd`.;) |
| 233 | do |
| 234 | # Skip some other non-user system accounts |
| 235 | if [[ $user == "centos" ]]; then |
| 236 | : |
| 237 | elif [[ $user == "nfsnobody" ]]; then |
| 238 | : |
| 239 | else |
| 240 | echoscip-shell system . . echo. -en "\nChecking user: ${user}...\n" |
| 241 | for usr in $SHADOW |
| 242 | do |
| 243 | IFS=':' read -r -a u <<< "$usr" |
| 244 | if [[ "${u[0]}" == "${user}" ]]; then |
| 245 | if [[ ${u[1]} == "!" ]] || [[ ${u[1]} == "!!" ]] || [[ ${u[1]} == "*" ]]; then |
| 246 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m User ${user} has no password set.\n" |
| 247 | ((PASS++)) |
| 248 | else |
| 249 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m User ${user} has a password set on their account. Only system users are allowed on the image.\n" |
| 250 | ((FAIL++)) |
| 251 | STATUS=2 |
| 252 | fi |
| 253 | fi |
| 254 | done |
| 255 | #echo "User Found: ${user}" |
| 256 | uhome="/home/${user}" |
| 257 | if [scip-shell system . . `[`. -d "${uhome}/" ]; then |
| 258 | if [scip-shell system . . `[`. -d "${uhome}/.ssh/" ]; then |
| 259 | if lsscip-shell system . . ls. "${uhome}/.ssh/*"> /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then |
| 260 | for key in ${uhome}/.ssh/* |
| 261 | do |
| 262 | if [scip-shell system . . `[`. "${key}" == "${uhome}/.ssh/authorized_keys" ]; then |
| 263 | if [scip-shell system . . `[`. "$( catscip-shell system . . cat. "${key}" | wcscip-shell system . . wc. -c)" -gt 50 ]; then |
| 264 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m User \e[1m${user}\e[0m has a populated authorized_keys file in \e[93m${key}\e[0m\n" |
| 265 | akey=$(catscip-shell system . . cat. ${key}) |
| 266 | echoscip-shell system . . echo. "File Contents:" |
| 267 | echoscip-shell system . . echo. $akey |
| 268 | echoscip-shell system . . echo. "--------------" |
| 269 | ((FAIL++)) |
| 270 | STATUS=2 |
| 271 | fi |
| 272 | elif [scip-shell system . . `[`. "${key}" == "${uhome}/.ssh/id_rsa" ]; then |
| 273 | if [scip-shell system . . `[`. "$( catscip-shell system . . cat. "${key}" | wcscip-shell system . . wc. -c)" -gt 0 ]; then |
| 274 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m User \e[1m${user}\e[0m has a private key file in \e[93m${key}\e[0m\n" |
| 275 | akey=$(catscip-shell system . . cat. ${key}) |
| 276 | echoscip-shell system . . echo. "File Contents:" |
| 277 | echoscip-shell system . . echo. $akey |
| 278 | echoscip-shell system . . echo. "--------------" |
| 279 | ((FAIL++)) |
| 280 | STATUS=2 |
| 281 | else |
| 282 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m User \e[1m${user}\e[0m has empty private key file in \e[93m${key}\e[0m\n" |
| 283 | ((WARN++)) |
| 284 | if [[ $STATUS != 2 ]]; then |
| 285 | STATUS=1 |
| 286 | fi |
| 287 | fi |
| 288 | elif [scip-shell system . . `[`. "${key}" != "${uhome}/.ssh/known_hosts" ]; then |
| 289 | |
| 290 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m User \e[1m${user}\e[0m has a file in their .ssh directory named \e[93m${key}\e[0m\n" |
| 291 | ((WARN++)) |
| 292 | if [[ $STATUS != 2 ]]; then |
| 293 | STATUS=1 |
| 294 | fi |
| 295 | |
| 296 | else |
| 297 | if [scip-shell system . . `[`. "$( catscip-shell system . . cat. "${key}" | wcscip-shell system . . wc. -c)" -gt 50 ]; then |
| 298 | echoscip-shell system . . echo. -en "\e[93m[WARN]\e[0m User \e[1m${user}\e[0m has a known_hosts file in \e[93m${key}\e[0m\n" |
| 299 | ((WARN++)) |
| 300 | if [[ $STATUS != 2 ]]; then |
| 301 | STATUS=1 |
| 302 | fi |
| 303 | fi |
| 304 | fi |
| 305 | |
| 306 | |
| 307 | done |
| 308 | else |
| 309 | echoscip-shell system . . echo. -en "\e[32m[ OK ]\e[0m User \e[1m${user}\e[0m has no SSH keys present\n" |
| 310 | fi |
| 311 | else |
| 312 | echoscip-shell system . . echo. -en "\e[32m[ OK ]\e[0m User \e[1m${user}\e[0m does not have an .ssh directory\n" |
| 313 | fi |
| 314 | else |
| 315 | echoscip-shell system . . echo. -en "\e[32m[ OK ]\e[0m User \e[1m${user}\e[0m does not have a directory in /home\n" |
| 316 | fi |
| 317 | |
| 318 | # Check for an uncleared .bash_history for this user |
| 319 | if [scip-shell system . . `[`. -f "${uhome}/.bash_history" ]; then |
| 320 | BH_S=$( catscip-shell system . . cat. "${uhome}/.bash_history" | wcscip-shell system . . wc. -c ) |
| 321 | |
| 322 | if [[ $BH_S -lt 200 ]]; then |
| 323 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m ${user}'s Bash History appears to have been cleared\n" |
| 324 | ((PASS++)) |
| 325 | else |
| 326 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m ${user}'s Bash History should be cleared to prevent sensitive information from leaking\n" |
| 327 | ((FAIL++)) |
| 328 | STATUS=2 |
| 329 | |
| 330 | fi |
| 331 | echoscip-shell system . . echo. -en "\n\n" |
| 332 | fi |
| 333 | fi |
| 334 | done |
| 335 | } |
| 336 | function checkFirewallscip-shell shell shell-project 0.0.0 checkFirewall(). { |
| 337 | |
| 338 | if [[ $OS == "Ubuntu" ]]; then |
| 339 | fw="ufw" |
| 340 | ufwa=$(ufw status |headscip-shell system . . head. -1| sedscip-shell system . . sed. -e "s/^Status:\ //") |
| 341 | if [[ $ufwa == "active" ]]; then |
| 342 | FW_VER="\e[32m[PASS]\e[0m Firewall service (${fw}) is active\n" |
| 343 | ((PASS++)) |
| 344 | else |
| 345 | FW_VER="\e[93m[WARN]\e[0m No firewall is configured. Ensure ${fw} is installed and configured\n" |
| 346 | ((WARN++)) |
| 347 | fi |
| 348 | elif [[ $OS == "CentOS Linux" ]]; then |
| 349 | if [scip-shell system . . `[`. -f /usr/lib/systemd/system/csf.servicescip-shell filesystem . . `/usr/lib/systemd/system/csf.service`. ]; then |
| 350 | fw="csf" |
| 351 | if [[ $(systemctl status $fw >/dev/null 2>&1) ]]; then |
| 352 | |
| 353 | FW_VER="\e[32m[PASS]\e[0m Firewall service (${fw}) is active\n" |
| 354 | ((PASS++)) |
| 355 | elif cmdExistsscip-shell shell shell-project 0.0.0 cmdExists(). "firewall-cmd"; then |
| 356 | if [[ $(systemctl is-active firewalld >/dev/null 2>&1 && echo 1 || echo 0) ]]; then |
| 357 | FW_VER="\e[32m[PASS]\e[0m Firewall service (${fw}) is active\n" |
| 358 | ((PASS++)) |
| 359 | else |
| 360 | FW_VER="\e[93m[WARN]\e[0m No firewall is configured. Ensure ${fw} is installed and configured\n" |
| 361 | ((WARN++)) |
| 362 | fi |
| 363 | else |
| 364 | FW_VER="\e[93m[WARN]\e[0m No firewall is configured. Ensure ${fw} is installed and configured\n" |
| 365 | ((WARN++)) |
| 366 | fi |
| 367 | else |
| 368 | fw="firewalld" |
| 369 | if [[ $(systemctl is-active firewalld >/dev/null 2>&1 && echo 1 || echo 0) ]]; then |
| 370 | FW_VER="\e[32m[PASS]\e[0m Firewall service (${fw}) is active\n" |
| 371 | ((PASS++)) |
| 372 | else |
| 373 | FW_VER="\e[93m[WARN]\e[0m No firewall is configured. Ensure ${fw} is installed and configured\n" |
| 374 | ((WARN++)) |
| 375 | fi |
| 376 | fi |
| 377 | elif [[ "$OS" =~ Debian.* ]]; then |
| 378 | # user could be using a number of different services for managing their firewall |
| 379 | # we will check some of the most common |
| 380 | if cmdExistsscip-shell shell shell-project 0.0.0 cmdExists(). 'ufw'; then |
| 381 | fw="ufw" |
| 382 | ufwa=$(ufw status | sedscip-shell system . . sed. -e "s/^Status:\ //") |
| 383 | if [[ $ufwa == "active" ]]; then |
| 384 | FW_VER="\e[32m[PASS]\e[0m Firewall service (${fw}) is active\n" |
| 385 | ((PASS++)) |
| 386 | else |
| 387 | FW_VER="\e[93m[WARN]\e[0m No firewall is configured. Ensure ${fw} is installed and configured\n" |
| 388 | ((WARN++)) |
| 389 | fi |
| 390 | elif cmdExistsscip-shell shell shell-project 0.0.0 cmdExists(). "firewall-cmd"; then |
| 391 | fw="firewalld" |
| 392 | if [[ $(systemctl is-active --quiet $fw) ]]; then |
| 393 | FW_VER="\e[32m[PASS]\e[0m Firewall service (${fw}) is active\n" |
| 394 | ((PASS++)) |
| 395 | else |
| 396 | FW_VER="\e[93m[WARN]\e[0m No firewall is configured. Ensure ${fw} is installed and configured\n" |
| 397 | ((WARN++)) |
| 398 | fi |
| 399 | else |
| 400 | # user could be using vanilla iptables, check if kernel module is loaded |
| 401 | fw="iptables" |
| 402 | if [[ $(lsmod | grep -q '^ip_tables' 2>/dev/null) ]]; then |
| 403 | FW_VER="\e[32m[PASS]\e[0m Firewall service (${fw}) is active\n" |
| 404 | ((PASS++)) |
| 405 | else |
| 406 | FW_VER="\e[93m[WARN]\e[0m No firewall is configured. Ensure ${fw} is installed and configured\n" |
| 407 | ((WARN++)) |
| 408 | fi |
| 409 | fi |
| 410 | fi |
| 411 | |
| 412 | } |
| 413 | function checkUpdatesscip-shell shell shell-project 0.0.0 checkUpdates(). { |
| 414 | if [[ $OS == "Ubuntu" ]] || [[ "$OS" =~ Debian.* ]]; then |
| 415 | # Ensure /tmp exists and has the proper permissions before |
| 416 | # checking for security updates |
| 417 | # https://github.com/digitalocean/marketplace-partners/issues/94 |
| 418 | if [[ ! -d /tmp ]]; then |
| 419 | mkdirscip-shell system . . mkdir. /tmpscip-shell filesystem . . `/tmp`. |
| 420 | fi |
| 421 | chmodscip-shell system . . chmod. 1777 /tmpscip-shell filesystem . . `/tmp`. |
| 422 | |
| 423 | echoscip-shell system . . echo. -en "\nUpdating apt package database to check for security updates, this may take a minute...\n\n" |
| 424 | apt-getscip-shell system . . apt-get. -y update > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 425 | |
| 426 | uc=$(apt-getscip-shell system . . apt-get. --just-print upgrade | grepscip-shell system . . grep. -i "security" | wcscip-shell system . . wc. -l) |
| 427 | if [[ $uc -gt 0 ]]; then |
| 428 | update_count=$(( ${uc} / 2 )) |
| 429 | else |
| 430 | update_count=0 |
| 431 | fi |
| 432 | |
| 433 | if [[ $update_count -gt 0 ]]; then |
| 434 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m There are ${update_count} security updates available for this image that have not been installed.\n" |
| 435 | echoscip-shell system . . echo. -en |
| 436 | echoscip-shell system . . echo. -en "Here is a list of the security updates that are not installed:\n" |
| 437 | sleepscip-shell system . . sleep. 2 |
| 438 | apt-getscip-shell system . . apt-get. --just-print upgrade | grepscip-shell system . . grep. -i security | awkscip-shell system . . awk. '{print $2}' | awkscip-shell system . . awk. '!seen[$0]++' |
| 439 | echoscip-shell system . . echo. -en |
| 440 | ((FAIL++)) |
| 441 | STATUS=2 |
| 442 | else |
| 443 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m There are no pending security updates for this image.\n\n" |
| 444 | fi |
| 445 | elif [[ $OS == "CentOS Linux" ]]; then |
| 446 | echoscip-shell system . . echo. -en "\nChecking for available updates with yum, this may take a minute...\n\n" |
| 447 | |
| 448 | update_count=$(yum list updates -q | grepscip-shell system . . grep. -vc "Updated Packages") |
| 449 | if [[ $update_count -gt 0 ]]; then |
| 450 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m There are ${update_count} updates available for this image that have not been installed.\n" |
| 451 | ((FAIL++)) |
| 452 | STATUS=2 |
| 453 | else |
| 454 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m There are no pending security updates for this image.\n" |
| 455 | ((PASS++)) |
| 456 | fi |
| 457 | else |
| 458 | echoscip-shell system . . echo. "Error encountered" |
| 459 | exit 1 |
| 460 | fi |
| 461 | |
| 462 | return 1; |
| 463 | } |
| 464 | function checkCloudInitscip-shell shell shell-project 0.0.0 checkCloudInit(). { |
| 465 | |
| 466 | if hash cloud-init 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 467 | CI="\e[32m[PASS]\e[0m Cloud-init is installed.\n" |
| 468 | ((PASS++)) |
| 469 | else |
| 470 | CI="\e[41m[FAIL]\e[0m No valid verison of cloud-init was found.\n" |
| 471 | ((FAIL++)) |
| 472 | STATUS=2 |
| 473 | fi |
| 474 | return 1 |
| 475 | } |
| 476 | function checkMongoDBscip-shell shell shell-project 0.0.0 checkMongoDB(). { |
| 477 | # Check if MongoDB is installed |
| 478 | # If it is, verify the version is allowed (non-SSPL) |
| 479 | |
| 480 | if [[ $OS == "Ubuntu" ]] || [[ "$OS" =~ Debian.* ]]; then |
| 481 | |
| 482 | if [[ -f "/usr/bin/mongod" ]]; then |
| 483 | version=$(/usr/bin/mongodscip-shell filesystem . . `/usr/bin/mongod`. --version --quiet | grepscip-shell system . . grep. "db version" | sedscip-shell system . . sed. -e "s/^db\ version\ v//") |
| 484 | |
| 485 | if version_gtscip-shell shell shell-project 0.0.0 version_gt(). $version 4.0.0; then |
| 486 | if version_gtscip-shell shell shell-project 0.0.0 version_gt(). $version 4.0.3; then |
| 487 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m An SSPL version of MongoDB is present, ${version}" |
| 488 | ((FAIL++)) |
| 489 | STATUS=2 |
| 490 | else |
| 491 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m The version of MongoDB installed, ${version} is not under the SSPL" |
| 492 | ((PASS++)) |
| 493 | fi |
| 494 | else |
| 495 | if version_gtscip-shell shell shell-project 0.0.0 version_gt(). $version 3.6.8; then |
| 496 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m An SSPL version of MongoDB is present, ${version}" |
| 497 | ((FAIL++)) |
| 498 | STATUS=2 |
| 499 | else |
| 500 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m The version of MongoDB installed, ${version} is not under the SSPL" |
| 501 | ((PASS++)) |
| 502 | fi |
| 503 | fi |
| 504 | |
| 505 | |
| 506 | else |
| 507 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m MongoDB is not installed" |
| 508 | ((PASS++)) |
| 509 | fi |
| 510 | |
| 511 | elif [[ $OS == "CentOS Linux" ]]; then |
| 512 | |
| 513 | if [[ -f "/usr/bin/mongod" ]]; then |
| 514 | version=$(/usr/bin/mongodscip-shell filesystem . . `/usr/bin/mongod`. --version --quiet | grepscip-shell system . . grep. "db version" | sedscip-shell system . . sed. -e "s/^db\ version\ v//") |
| 515 | |
| 516 | |
| 517 | if version_gtscip-shell shell shell-project 0.0.0 version_gt(). $version 4.0.0; then |
| 518 | if version_gtscip-shell shell shell-project 0.0.0 version_gt(). $version 4.0.3; then |
| 519 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m An SSPL version of MongoDB is present" |
| 520 | ((FAIL++)) |
| 521 | STATUS=2 |
| 522 | else |
| 523 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m The version of MongoDB installed is not under the SSPL" |
| 524 | ((PASS++)) |
| 525 | fi |
| 526 | else |
| 527 | if version_gtscip-shell shell shell-project 0.0.0 version_gt(). $version 3.6.8; then |
| 528 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m An SSPL version of MongoDB is present" |
| 529 | ((FAIL++)) |
| 530 | STATUS=2 |
| 531 | else |
| 532 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m The version of MongoDB installed is not under the SSPL" |
| 533 | ((PASS++)) |
| 534 | fi |
| 535 | fi |
| 536 | |
| 537 | |
| 538 | |
| 539 | else |
| 540 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m MongoDB is not installed" |
| 541 | ((PASS++)) |
| 542 | fi |
| 543 | |
| 544 | else |
| 545 | echoscip-shell system . . echo. "ERROR: Unable to identify distribution" |
| 546 | ((FAIL++)) |
| 547 | STATUS 2 |
| 548 | return 1 |
| 549 | fi |
| 550 | |
| 551 | |
| 552 | } |
| 553 | |
| 554 | function version_gtscip-shell shell shell-project 0.0.0 version_gt().() { testscip-shell system . . test. "$(printfscip-shell system . . printf. '%s\n' "$@" | sortscip-shell system . . sort. -V | headscip-shell system . . head. -n 1)" != "$1"; } |
| 555 | |
| 556 | |
| 557 | clearscip-shell system . . clear. |
| 558 | echoscip-shell system . . echo. "DigitalOcean Marketplace Image Validation Tool ${VERSION}" |
| 559 | echoscip-shell system . . echo. "Executed on: ${RUNDATE}" |
| 560 | echoscip-shell system . . echo. "Checking local system for Marketplace compatibility..." |
| 561 | |
| 562 | getDistroscip-shell shell shell-project 0.0.0 getDistro(). |
| 563 | |
| 564 | echoscip-shell system . . echo. -en "\n\e[1mDistribution:\e[0m ${OS}\n" |
| 565 | echoscip-shell system . . echo. -en "\e[1mVersion:\e[0m ${VER}\n\n" |
| 566 | |
| 567 | ost=0 |
| 568 | osv=0 |
| 569 | |
| 570 | if [[ $OS == "Ubuntu" ]]; then |
| 571 | ost=1 |
| 572 | if [[ $VER == "20.04" ]]; then |
| 573 | osv=1 |
| 574 | elif [[ $VER == "18.04" ]]; then |
| 575 | osv=1 |
| 576 | elif [[ $VER == "16.04" ]]; then |
| 577 | osv=1 |
| 578 | else |
| 579 | osv=0 |
| 580 | fi |
| 581 | |
| 582 | elif [[ "$OS" =~ Debian.* ]]; then |
| 583 | ost=1 |
| 584 | case "$VER" in |
| 585 | 9) |
| 586 | osv=1 |
| 587 | ;; |
| 588 | 10) |
| 589 | osv=1 |
| 590 | ;; |
| 591 | *) |
| 592 | osv=2 |
| 593 | ;; |
| 594 | esac |
| 595 | |
| 596 | elif [[ $OS == "CentOS Linux" ]]; then |
| 597 | ost=1 |
| 598 | if [[ $VER == "8" ]]; then |
| 599 | osv=1 |
| 600 | elif [[ $VER == "7" ]]; then |
| 601 | osv=1 |
| 602 | elif [[ $VER == "6" ]]; then |
| 603 | osv=1 |
| 604 | else |
| 605 | osv=2 |
| 606 | fi |
| 607 | else |
| 608 | ost=0 |
| 609 | fi |
| 610 | |
| 611 | if [[ $ost == 1 ]]; then |
| 612 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m Supported Operating System Detected: ${OS}\n" |
| 613 | ((PASS++)) |
| 614 | else |
| 615 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m ${OS} is not a supported Operating System\n" |
| 616 | ((FAIL++)) |
| 617 | STATUS=2 |
| 618 | fi |
| 619 | |
| 620 | if [[ $osv == 1 ]]; then |
| 621 | echoscip-shell system . . echo. -en "\e[32m[PASS]\e[0m Supported Release Detected: ${VER}\n" |
| 622 | ((PASS++)) |
| 623 | elif [[ $ost == 1 ]]; then |
| 624 | echoscip-shell system . . echo. -en "\e[41m[FAIL]\e[0m ${OS} ${VER} is not a supported Operating System Version\n" |
| 625 | ((FAIL++)) |
| 626 | STATUS=2 |
| 627 | else |
| 628 | echoscip-shell system . . echo. "Exiting..." |
| 629 | exit 1 |
| 630 | fi |
| 631 | |
| 632 | checkCloudInitscip-shell shell shell-project 0.0.0 checkCloudInit(). |
| 633 | |
| 634 | echoscip-shell system . . echo. -en "${CI}" |
| 635 | |
| 636 | checkFirewallscip-shell shell shell-project 0.0.0 checkFirewall(). |
| 637 | |
| 638 | echoscip-shell system . . echo. -en "${FW_VER}" |
| 639 | |
| 640 | checkUpdatesscip-shell shell shell-project 0.0.0 checkUpdates(). |
| 641 | |
| 642 | loadPasswordsscip-shell shell shell-project 0.0.0 loadPasswords(). |
| 643 | |
| 644 | checkLogsscip-shell shell shell-project 0.0.0 checkLogs(). |
| 645 | |
| 646 | echoscip-shell system . . echo. -en "\n\nChecking all user-created accounts...\n" |
| 647 | checkUsersscip-shell shell shell-project 0.0.0 checkUsers(). |
| 648 | |
| 649 | echoscip-shell system . . echo. -en "\n\nChecking the root account...\n" |
| 650 | checkRootscip-shell shell shell-project 0.0.0 checkRoot(). |
| 651 | |
| 652 | checkAgentscip-shell shell shell-project 0.0.0 checkAgent(). |
| 653 | |
| 654 | checkMongoDBscip-shell shell shell-project 0.0.0 checkMongoDB(). |
| 655 | |
| 656 | |
| 657 | # Summary |
| 658 | echoscip-shell system . . echo. -en "\n\n---------------------------------------------------------------------------------------------------\n" |
| 659 | |
| 660 | if [[ $STATUS == 0 ]]; then |
| 661 | echoscip-shell system . . echo. -en "Scan Complete.\n\e[32mAll Tests Passed!\e[0m\n" |
| 662 | elif [[ $STATUS == 1 ]]; then |
| 663 | echoscip-shell system . . echo. -en "Scan Complete. \n\e[93mSome non-critical tests failed. Please review these items.\e[0m\e[0m\n" |
| 664 | else |
| 665 | echoscip-shell system . . echo. -en "Scan Complete. \n\e[41mOne or more tests failed. Please review these items and re-test.\e[0m\n" |
| 666 | fi |
| 667 | echoscip-shell system . . echo. "---------------------------------------------------------------------------------------------------" |
| 668 | echoscip-shell system . . echo. -en "\e[1m${PASS} Tests PASSED\e[0m\n" |
| 669 | echoscip-shell system . . echo. -en "\e[1m${WARN} WARNINGS\e[0m\n" |
| 670 | echoscip-shell system . . echo. -en "\e[1m${FAIL} Tests FAILED\e[0m\n" |
| 671 | echoscip-shell system . . echo. -en "---------------------------------------------------------------------------------------------------\n" |
| 672 | |
| 673 | if [[ $STATUS == 0 ]]; then |
| 674 | echoscip-shell system . . echo. -en "We did not detect any issues with this image. Please be sure to manually ensure that all software installed on the base system is functional, secure and properly configured (or facilities for configuration on first-boot have been created).\n\n" |
| 675 | exit 0 |
| 676 | elif [[ $STATUS == 1 ]]; then |
| 677 | echoscip-shell system . . echo. -en "Please review all [WARN] items above and ensure they are intended or resolved. If you do not have a specific requirement, we recommend resolving these items before image submission\n\n" |
| 678 | exit 1 |
| 679 | else |
| 680 | echoscip-shell system . . echo. -en "Some critical tests failed. These items must be resolved and this scan re-run before you submit your image to the marketplace.\n\n" |
| 681 | exit 1 |
| 682 | fi |