Skip to content

Instantly share code, notes, and snippets.

@tarqd
Created September 24, 2016 21:28
Show Gist options
  • Save tarqd/faed25aa2c7bdcfd3309773f228364dd to your computer and use it in GitHub Desktop.
Save tarqd/faed25aa2c7bdcfd3309773f228364dd to your computer and use it in GitHub Desktop.
MySQL Vulnerability Security Checker
#!/bin/bash
# Try and find where my.cnf are loaded from, otherwise guess
MYSQLD_OUT=$(mysqld --help --verbose 2>/dev/null)
DATADIR=$(echo "$MYSQLD_OUT" | grep "datadir " | tr -s ' ' | cut -d' ' -f 2)
DATADIR=${DATADIR:=/var/lib/mysql}
FILES=$(echo "$MYSQLD_OUT" | awk 'f{print;f=0} /Default options are read/{f=1}')
FILES=${FILES:=/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf}
FILES="$FILES $DATADIR/my.cnf $DATADIR/.my.cnf"
DIRS=$(dirname $FILES | sort | uniq)
COMMON_INCLUDE_DIRS="/etc/mysql /etc/my.cnf.d /usr/etc/mysql /usr/etc/my.cnf.d /usr/local/etc/my.cnf.d /usr/local/etc/mysql $DATADIR"
echo 'Writable Configuration Files:'
(cd / ; sudo -u mysql find $FILES -type f -writable ; sudo -u mysql find $COMMON_INCLUDE_DIRS -type f -name "*.cnf" -writable ) 2>/dev/null
echo
echo "Missing Configuration Files: "
for file in $FILES; do if [ ! -e "$file" ]; then echo $file; fi; done;
@softins
Copy link

softins commented Oct 9, 2016

Line 11, DIRS=$(dirname $FILES | sort | uniq), gives an error, because dirname only takes a single name as argument, whereas $FILES contains multiple names.

But in any case, the value of $DIRS does not appear to be used anywhere later in the script!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment