From 54ec8e30530717d979e618a3cad199d2778329e0 Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:41:43 +0100 Subject: [PATCH 01/15] Update MYSQLAudit.sh --- MYSQLAudit.sh | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/MYSQLAudit.sh b/MYSQLAudit.sh index f0594f3..6e0bf16 100644 --- a/MYSQLAudit.sh +++ b/MYSQLAudit.sh @@ -45,6 +45,9 @@ echo "DATABASES" >> results/Databases.txt echo 'show databases'| mysql -u$username -p$password >> results/Databases.txt echo 'show databases'| mysql -u$username -p$password |grep -v Database>> results/mysql_databases +echo "TLS VERSION" >> results/Databases.txt +echo 'select @@tls_version'| mysql -u$username -p$password >> results/Databases.txt + echo "ALL TABLES FROM ALL DATABASES" >> results/Tables_from_databases.txt echo 'select table_schema, table_name from information_schema.tables'| mysql -u$username -p$password >> results/Tables_from_databases.txt echo 'select table_schema, table_name from information_schema.tables'| mysql -u$username -p$password >> results/mysql_tables @@ -57,10 +60,16 @@ echo "SELECT table_schema, table_name FROM information_schema.tables WHERE table echo "Starting of MYSQL Audit" > results/MYSQLAudit.txt echo "################################" >> results/MYSQLAudit.txt echo " " >> results/MYSQLAudit.txt -echo "Auditing Guidance for section 1.6" >> results/MYSQLAudit.txt -echo "show variables like 'datadir'" | mysql -u$username -p$password >> results/MYSQLAudit.txt +echo "Auditing Guidance for section 3.1" >> results/MYSQLAudit.txt +echo "show variables where variable_name = 'datadir'" | mysql -u$username -p$password >> results/MYSQLAudit.txt +echo " " >> results/MYSQLAudit.txt +echo "################################" >> results/MYSQLAudit.txt + +echo "Auditing Guidance for section 3.2" >> results/MYSQLAudit.txt +echo "show variables like 'log_bin_basename'" | mysql -u$username -p$password >> results/MYSQLAudit.txt echo " " >> results/MYSQLAudit.txt echo "################################" >> results/MYSQLAudit.txt + echo "Auditing Guidance for section 2.2" >> results/MYSQLAudit.txt echo "show variables like 'basedir'" | mysql -u$username -p$password >> results/MYSQLAudit.txt echo "################################" >> results/MYSQLAudit.txt @@ -68,17 +77,39 @@ echo " " >> results/MYSQLAudit.txt echo "Logging" >> results/MYSQLAudit.txt echo "################################" >> results/MYSQLAudit.txt echo " " >> results/MYSQLAudit.txt -echo "Auditing Guidance for section 3.1" >> results/MYSQLAudit.txt +echo "Auditing Guidance for section 3.3" >> results/MYSQLAudit.txt echo "show variables like 'log_error'" | mysql -u$username -p$password >> results/MYSQLAudit.txt echo "################################" >> results/MYSQLAudit.txt echo " " >> results/MYSQLAudit.txt -echo "Auditing Guidance for section 3.3 & 3.4 " >> results/MYSQLAudit.txt +echo "Auditing Guidance for section 3.3" >> results/MYSQLAudit.txt echo "show variables like 'log_bin'" | mysql -u$username -p$password >> results/MYSQLAudit.txt echo "################################" >> results/MYSQLAudit.txt echo " " >> results/MYSQLAudit.txt -echo "show variables like 'log_bin'" | mysql -u$username -p$password >> results/MYSQLAudit.txt +echo "Auditing Guidance for section 3.4 " >> results/MYSQLAudit.txt +echo "show variables like 'slow_query_log'" | mysql -u$username -p$password >> results/MYSQLAudit.txt +echo "################################" >> results/MYSQLAudit.txt +echo " " >> results/MYSQLAudit.txt + +echo "Auditing Guidance for section 3.5 " >> results/MYSQLAudit.txt +echo "show variables like 'relay_log_basename'" | mysql -u$username -p$password >> results/MYSQLAudit.txt echo "################################" >> results/MYSQLAudit.txt echo " " >> results/MYSQLAudit.txt + +echo "Auditing Guidance for section 4.9 " >> results/MYSQLAudit.txt +echo "SHOW VARIABLES LIKE 'sql_mode'" | mysql -u$username -p$password >> results/MYSQLAudit.txt +echo "################################" >> results/MYSQLAudit.txt +echo " " >> results/MYSQLAudit.txt + +echo "Auditing Guidance for section 7.5 " >> results/MYSQLAudit.txt +echo "SHOW VARIABLES LIKE 'default_password_lifetime'" | mysql -u$username -p$password >> results/MYSQLAudit.txt +echo "################################" >> results/MYSQLAudit.txt +echo " " >> results/MYSQLAudit.txt + +echo "Auditing Guidance for section 7.6 " >> results/MYSQLAudit.txt +echo "SHOW VARIABLES LIKE 'validate_password%'" | mysql -u$username -p$password >> results/MYSQLAudit.txt +echo "################################" >> results/MYSQLAudit.txt +echo " " >> results/MYSQLAudit.txt + echo "Auditing Guidance for section 4.5" >> results/MYSQLAudit.txt echo "select user from mysql.user where user = 'root'" | mysql -u$username -p$password >> results/MYSQLAudit.txt echo "################################" >> results/MYSQLAudit.txt From 1781c19ae91602d2d8da20322b262d28f9873794 Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:26:38 +0100 Subject: [PATCH 02/15] Create MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 259 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 MYSQL-CIS-Audit.ps1 diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 new file mode 100644 index 0000000..4ac02d5 --- /dev/null +++ b/MYSQL-CIS-Audit.ps1 @@ -0,0 +1,259 @@ +# SecureLayer7 MYSQL Audit Script +# Developed and Modified By Sandeep Kamble for the official purpose only +# This configuration review script is developed according to specific needs. +# Last Update Data: 7 July, 2016 +# Use following command to run this script +# Set-ExecutionPolicy Unrestricted +# ./MYSQL-CIS-Audit.ps1 + +Write-Host "Enter your username for mysql (root recommended)" +$username = Read-Host + +Write-Host "Enter password (password not shown)" +$password = Read-Host -AsSecureString +$passwordText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) + +# CREATING DIRECTORIES: RESULTS +Write-Host "CREATING DIRECTORIES : RESULTS" +New-Item -ItemType Directory -Path "results" -Force | Out-Null + +# General Information for MYSQL Audit +Write-Host "SecureLayer7 MYSQL Audit Started" + +# Time and Date +Add-Content -Path "results/System_info.txt" -Value "Time and Date" +mysql -u$username -p$passwordText -e 'select NOW()' | Out-File -Append -FilePath "results/System_info.txt" + +# MYSQL VERSION +Add-Content -Path "results/System_info.txt" -Value "MYSQL VERSION" +mysql -u$username -p$passwordText -e 'show variables like "%version%"' | Out-File -Append -FilePath "results/System_info.txt" + +# USERS +Add-Content -Path "results/Users.txt" -Value "USERS" +mysql -u$username -p$passwordText -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results/Users.txt" + +# CURRENT USERS +Add-Content -Path "results/Users.txt" -Value "CURRENT USERS" +mysql -u$username -p$passwordText -e 'show processlist' | Out-File -Append -FilePath "results/Users.txt" + +# ALL VARIABLES +Add-Content -Path "results/All_variables.txt" -Value "ALL VARIABLES" +mysql -u$username -p$passwordText -e 'show variables' | Out-File -Append -FilePath "results/All_variables.txt" + +# DATABASES +Add-Content -Path "results/Databases.txt" -Value "DATABASES" +mysql -u$username -p$passwordText -e 'show databases' | Out-File -Append -FilePath "results/Databases.txt" +mysql -u$username -p$passwordText -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results/mysql_databases.txt" + +# TLS VERSION +Add-Content -Path "results/Databases.txt" -Value "TLS VERSION" +mysql -u$username -p$passwordText -e 'select @@tls_version' | Out-File -Append -FilePath "results/Databases.txt" + +# ALL TABLES FROM ALL DATABASES +Add-Content -Path "results/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" +mysql -u$username -p$passwordText -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/Tables_from_databases.txt" +mysql -u$username -p$passwordText -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/mysql_tables.txt" + +# TABLES FROM ALL DATABASES EXCEPT INTERNAL +Add-Content -Path "results/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" +mysql -u$username -p$passwordText -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results/Not_system_tables.txt" + +# Operating System Level Configuration +Add-Content -Path "results/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" +mysql -u$username -p$passwordText -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" + +# Auditing Guidance for section 3.2 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" +mysql -u$username -p$passwordText -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" + +# Auditing Guidance for section 2.2 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" +mysql -u$username -p$passwordText -e 'show variables like "basedir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Logging +Add-Content -Path "results/MYSQLAudit.txt" -Value "Logging" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 3.3 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -e 'show variables like "log_error"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 3.3 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 3.4 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" +mysql -u$username -p$passwordText -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 3.5 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" +mysql -u$username -p$passwordText -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 4.9 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 7.5 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" +mysql -u$username -p$passwordText -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 7.6 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" +mysql -u$username -p$passwordText -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 4.5 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" +mysql -u$username -p$passwordText -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 4.9 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 4.10 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" +mysql -u$username -p$passwordText -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 4.11 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" +mysql -u$username -p$passwordText -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# MySQL Permissions +Add-Content -Path "results/MYSQLAudit.txt" -Value "MySQL Permissions" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 5.1 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" +mysql -u$username -p$passwordText -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 5.2 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" +mysql -u$username -p$passwordText -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 5.3 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" +mysql -u$username -p$passwordText -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 5.4 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" +mysql -u$username -p$passwordText -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 5.5 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" +mysql -u$username -p$passwordText -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" + +# Blank line +Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " +mysql -u$username -p$passwordText -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# MySQL Configuration +Add-Content -Path "results/MYSQLAudit.txt" -Value "MySQL Configuration" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 6.2 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" +mysql -u$username -p$passwordText -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 6.3 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" +mysql -u$username -p$passwordText -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 6.4 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" +mysql -u$username -p$passwordText -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 6.5 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" +mysql -u$username -p$passwordText -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 6.6 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" +mysql -u$username -p$passwordText -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 6.7 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" +mysql -u$username -p$passwordText -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 6.8 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" +mysql -u$username -p$passwordText -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 6.10 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" +mysql -u$username -p$passwordText -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# SSL Configuration +Add-Content -Path "results/MYSQLAudit.txt" -Value "SSL Configuration" +Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results/MYSQLAudit.txt" -Value " " + +# Auditing Guidance for section 7.2 +Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" +mysql -u$username -p$passwordText -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +Add-Content -Path "results/MYSQLAudit.txt" -Value "##################END AUDIT##############" +Write-Host "##################END MYSQL AUDIT##############" +Write-Host "ZIP the result folder and email to consultant" From 0c5c5ab3e3de7d5850302d772b7bcd205664a94b Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Mon, 27 Nov 2023 15:32:47 +0100 Subject: [PATCH 03/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 92 ++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index 4ac02d5..e2bb4c4 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -9,6 +9,12 @@ Write-Host "Enter your username for mysql (root recommended)" $username = Read-Host +Write-Host "Enter database ip adress :" +$ipaddr = Read-Host + +Write-Host "Enter database port :" +$port = Read-Host + Write-Host "Enter password (password not shown)" $password = Read-Host -AsSecureString $passwordText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) @@ -22,60 +28,60 @@ Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date Add-Content -Path "results/System_info.txt" -Value "Time and Date" -mysql -u$username -p$passwordText -e 'select NOW()' | Out-File -Append -FilePath "results/System_info.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select NOW()' | Out-File -Append -FilePath "results/System_info.txt" # MYSQL VERSION Add-Content -Path "results/System_info.txt" -Value "MYSQL VERSION" -mysql -u$username -p$passwordText -e 'show variables like "%version%"' | Out-File -Append -FilePath "results/System_info.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "%version%"' | Out-File -Append -FilePath "results/System_info.txt" # USERS Add-Content -Path "results/Users.txt" -Value "USERS" -mysql -u$username -p$passwordText -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results/Users.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results/Users.txt" # CURRENT USERS Add-Content -Path "results/Users.txt" -Value "CURRENT USERS" -mysql -u$username -p$passwordText -e 'show processlist' | Out-File -Append -FilePath "results/Users.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show processlist' | Out-File -Append -FilePath "results/Users.txt" # ALL VARIABLES Add-Content -Path "results/All_variables.txt" -Value "ALL VARIABLES" -mysql -u$username -p$passwordText -e 'show variables' | Out-File -Append -FilePath "results/All_variables.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables' | Out-File -Append -FilePath "results/All_variables.txt" # DATABASES Add-Content -Path "results/Databases.txt" -Value "DATABASES" -mysql -u$username -p$passwordText -e 'show databases' | Out-File -Append -FilePath "results/Databases.txt" -mysql -u$username -p$passwordText -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results/mysql_databases.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show databases' | Out-File -Append -FilePath "results/Databases.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results/mysql_databases.txt" # TLS VERSION Add-Content -Path "results/Databases.txt" -Value "TLS VERSION" -mysql -u$username -p$passwordText -e 'select @@tls_version' | Out-File -Append -FilePath "results/Databases.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select @@tls_version' | Out-File -Append -FilePath "results/Databases.txt" # ALL TABLES FROM ALL DATABASES Add-Content -Path "results/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u$username -p$passwordText -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/Tables_from_databases.txt" -mysql -u$username -p$passwordText -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/mysql_tables.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/Tables_from_databases.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL Add-Content -Path "results/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u$username -p$passwordText -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results/Not_system_tables.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results/Not_system_tables.txt" # Operating System Level Configuration Add-Content -Path "results/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u$username -p$passwordText -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value " " Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u$username -p$passwordText -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value " " Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u$username -p$passwordText -e 'show variables like "basedir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "basedir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " @@ -86,67 +92,67 @@ Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -e 'show variables like "log_error"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "log_error"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u$username -p$passwordText -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u$username -p$passwordText -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u$username -p$passwordText -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u$username -p$passwordText -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u$username -p$passwordText -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u$username -p$passwordText -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u$username -p$passwordText -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " @@ -157,38 +163,38 @@ Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u$username -p$passwordText -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -mysql -u$username -p$passwordText -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u$username -p$passwordText -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u$username -p$passwordText -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u$username -p$passwordText -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u$username -p$passwordText -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" # Blank line Add-Content -Path "results/MYSQLAudit.txt" -Value " " Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u$username -p$passwordText -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " @@ -199,49 +205,49 @@ Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u$username -p$passwordText -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u$username -p$passwordText -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u$username -p$passwordText -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u$username -p$passwordText -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u$username -p$passwordText -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u$username -p$passwordText -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u$username -p$passwordText -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u$username -p$passwordText -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # SSL Configuration @@ -251,9 +257,9 @@ Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u$username -p$passwordText -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -mysql -u$username -p$passwordText -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -mysql -u$username -p$passwordText -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From 388b9f8fc04e72c432fa494c86218f68e8d28612 Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:22:16 +0100 Subject: [PATCH 04/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 90 ++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index e2bb4c4..6606e3f 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -9,8 +9,8 @@ Write-Host "Enter your username for mysql (root recommended)" $username = Read-Host -Write-Host "Enter database ip adress :" -$ipaddr = Read-Host +Write-Host "Enter name database :" +$dbname = Read-Host Write-Host "Enter database port :" $port = Read-Host @@ -28,60 +28,60 @@ Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date Add-Content -Path "results/System_info.txt" -Value "Time and Date" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select NOW()' | Out-File -Append -FilePath "results/System_info.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select NOW()' | Out-File -Append -FilePath "results/System_info.txt" # MYSQL VERSION Add-Content -Path "results/System_info.txt" -Value "MYSQL VERSION" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "%version%"' | Out-File -Append -FilePath "results/System_info.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results/System_info.txt" # USERS Add-Content -Path "results/Users.txt" -Value "USERS" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results/Users.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results/Users.txt" # CURRENT USERS Add-Content -Path "results/Users.txt" -Value "CURRENT USERS" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show processlist' | Out-File -Append -FilePath "results/Users.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show processlist' | Out-File -Append -FilePath "results/Users.txt" # ALL VARIABLES Add-Content -Path "results/All_variables.txt" -Value "ALL VARIABLES" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables' | Out-File -Append -FilePath "results/All_variables.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables' | Out-File -Append -FilePath "results/All_variables.txt" # DATABASES Add-Content -Path "results/Databases.txt" -Value "DATABASES" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show databases' | Out-File -Append -FilePath "results/Databases.txt" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results/mysql_databases.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show databases' | Out-File -Append -FilePath "results/Databases.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results/mysql_databases.txt" # TLS VERSION Add-Content -Path "results/Databases.txt" -Value "TLS VERSION" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select @@tls_version' | Out-File -Append -FilePath "results/Databases.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results/Databases.txt" # ALL TABLES FROM ALL DATABASES Add-Content -Path "results/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/Tables_from_databases.txt" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/mysql_tables.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/Tables_from_databases.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL Add-Content -Path "results/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results/Not_system_tables.txt" +mysql -u$username -p$passwordText -P$port $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results/Not_system_tables.txt" # Operating System Level Configuration Add-Content -Path "results/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value " " Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value " " Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "basedir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " @@ -92,67 +92,67 @@ Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "log_error"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " @@ -163,38 +163,38 @@ Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" # Blank line Add-Content -Path "results/MYSQLAudit.txt" -Value " " Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " @@ -205,49 +205,49 @@ Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value " " # SSL Configuration @@ -257,9 +257,9 @@ Add-Content -Path "results/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -mysql --host=$ipaddr --port=$port -u $username -p $passwordText -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" Add-Content -Path "results/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From 53a5eceaa17427cec50aa8bfa2129036a6a277ab Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:38:25 +0100 Subject: [PATCH 05/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 304 ++++++++++++++++++++++---------------------- 1 file changed, 152 insertions(+), 152 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index 6606e3f..c4f5806 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -27,239 +27,239 @@ New-Item -ItemType Directory -Path "results" -Force | Out-Null Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date -Add-Content -Path "results/System_info.txt" -Value "Time and Date" -mysql -u$username -p$passwordText -P$port $dbname -e 'select NOW()' | Out-File -Append -FilePath "results/System_info.txt" +Add-Content -Path "results_$dbname/System_info.txt" -Value "Time and Date" +mysql -u$username -p$passwordText -P$port $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # MYSQL VERSION -Add-Content -Path "results/System_info.txt" -Value "MYSQL VERSION" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results/System_info.txt" +Add-Content -Path "results_$dbname/System_info.txt" -Value "MYSQL VERSION" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # USERS -Add-Content -Path "results/Users.txt" -Value "USERS" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results/Users.txt" +Add-Content -Path "results_$dbname/Users.txt" -Value "USERS" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" # CURRENT USERS -Add-Content -Path "results/Users.txt" -Value "CURRENT USERS" -mysql -u$username -p$passwordText -P$port $dbname -e 'show processlist' | Out-File -Append -FilePath "results/Users.txt" +Add-Content -Path "results_$dbname/Users.txt" -Value "CURRENT USERS" +mysql -u$username -p$passwordText -P$port $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" # ALL VARIABLES -Add-Content -Path "results/All_variables.txt" -Value "ALL VARIABLES" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables' | Out-File -Append -FilePath "results/All_variables.txt" +Add-Content -Path "results_$dbname/All_variables.txt" -Value "ALL VARIABLES" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" # DATABASES -Add-Content -Path "results/Databases.txt" -Value "DATABASES" -mysql -u$username -p$passwordText -P$port $dbname -e 'show databases' | Out-File -Append -FilePath "results/Databases.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results/mysql_databases.txt" +Add-Content -Path "results_$dbname/Databases.txt" -Value "DATABASES" +mysql -u$username -p$passwordText -P$port $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" # TLS VERSION -Add-Content -Path "results/Databases.txt" -Value "TLS VERSION" -mysql -u$username -p$passwordText -P$port $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results/Databases.txt" +Add-Content -Path "results_$dbname/Databases.txt" -Value "TLS VERSION" +mysql -u$username -p$passwordText -P$port $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES -Add-Content -Path "results/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u$username -p$passwordText -P$port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/Tables_from_databases.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results/mysql_tables.txt" +Add-Content -Path "results_$dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" +mysql -u$username -p$passwordText -P$port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL -Add-Content -Path "results/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u$username -p$passwordText -P$port $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results/Not_system_tables.txt" +Add-Content -Path "results_$dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" +mysql -u$username -p$passwordText -P$port $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" # Operating System Level Configuration -Add-Content -Path "results/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Logging -Add-Content -Path "results/MYSQLAudit.txt" -Value "Logging" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Logging" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" +mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" +mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # MySQL Permissions -Add-Content -Path "results/MYSQLAudit.txt" -Value "MySQL Permissions" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "MySQL Permissions" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Blank line -Add-Content -Path "results/MYSQLAudit.txt" -Value " " -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " +mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # MySQL Configuration -Add-Content -Path "results/MYSQLAudit.txt" -Value "MySQL Configuration" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "MySQL Configuration" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # SSL Configuration -Add-Content -Path "results/MYSQLAudit.txt" -Value "SSL Configuration" -Add-Content -Path "results/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "SSL Configuration" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 -Add-Content -Path "results/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results/MYSQLAudit.txt" -Add-Content -Path "results/MYSQLAudit.txt" -Value "##################END AUDIT##############" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From 792d9f8fb2d2fb3271c01a20c9ad3ad84efcc43a Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:39:53 +0100 Subject: [PATCH 06/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index c4f5806..506609b 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -21,7 +21,7 @@ $passwordText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([Syste # CREATING DIRECTORIES: RESULTS Write-Host "CREATING DIRECTORIES : RESULTS" -New-Item -ItemType Directory -Path "results" -Force | Out-Null +New-Item -ItemType Directory -Path "results_$dbname" -Force | Out-Null # General Information for MYSQL Audit Write-Host "SecureLayer7 MYSQL Audit Started" From cc31733f669a8961cec6e1f11454c276b0ff77d0 Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:49:30 +0100 Subject: [PATCH 07/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index 506609b..61a4b16 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -28,60 +28,60 @@ Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date Add-Content -Path "results_$dbname/System_info.txt" -Value "Time and Date" -mysql -u$username -p$passwordText -P$port $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # MYSQL VERSION Add-Content -Path "results_$dbname/System_info.txt" -Value "MYSQL VERSION" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # USERS Add-Content -Path "results_$dbname/Users.txt" -Value "USERS" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" # CURRENT USERS Add-Content -Path "results_$dbname/Users.txt" -Value "CURRENT USERS" -mysql -u$username -p$passwordText -P$port $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" # ALL VARIABLES Add-Content -Path "results_$dbname/All_variables.txt" -Value "ALL VARIABLES" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" # DATABASES Add-Content -Path "results_$dbname/Databases.txt" -Value "DATABASES" -mysql -u$username -p$passwordText -P$port $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" # TLS VERSION Add-Content -Path "results_$dbname/Databases.txt" -Value "TLS VERSION" -mysql -u$username -p$passwordText -P$port $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES Add-Content -Path "results_$dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u$username -p$passwordText -P$port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL Add-Content -Path "results_$dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u$username -p$passwordText -P$port $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" +mysql -u$username -p$passwordText -P $port $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" # Operating System Level Configuration Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -92,67 +92,67 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u$username -p$passwordText -P$port $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -163,38 +163,38 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Blank line Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u$username -p$passwordText -P$port $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -205,49 +205,49 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # SSL Configuration @@ -257,9 +257,9 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P$port $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From 46aed53cd29d3ec5dc8c4ef401b30b9499c8d2ee Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:47:29 +0100 Subject: [PATCH 08/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 311 ++++++++++++++++++++++---------------------- 1 file changed, 154 insertions(+), 157 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index 61a4b16..cfa2fbc 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -10,10 +10,7 @@ Write-Host "Enter your username for mysql (root recommended)" $username = Read-Host Write-Host "Enter name database :" -$dbname = Read-Host - -Write-Host "Enter database port :" -$port = Read-Host +-P3399 $dbname = Read-Host Write-Host "Enter password (password not shown)" $password = Read-Host -AsSecureString @@ -21,245 +18,245 @@ $passwordText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([Syste # CREATING DIRECTORIES: RESULTS Write-Host "CREATING DIRECTORIES : RESULTS" -New-Item -ItemType Directory -Path "results_$dbname" -Force | Out-Null +New-Item -ItemType Directory -Path "results_-P3399 $dbname" -Force | Out-Null # General Information for MYSQL Audit Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date -Add-Content -Path "results_$dbname/System_info.txt" -Value "Time and Date" -mysql -u$username -p$passwordText -P $port $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +Add-Content -Path "results_-P3399 $dbname/System_info.txt" -Value "Time and Date" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_-P3399 $dbname/System_info.txt" # MYSQL VERSION -Add-Content -Path "results_$dbname/System_info.txt" -Value "MYSQL VERSION" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +Add-Content -Path "results_-P3399 $dbname/System_info.txt" -Value "MYSQL VERSION" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_-P3399 $dbname/System_info.txt" # USERS -Add-Content -Path "results_$dbname/Users.txt" -Value "USERS" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" +Add-Content -Path "results_-P3399 $dbname/Users.txt" -Value "USERS" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_-P3399 $dbname/Users.txt" # CURRENT USERS -Add-Content -Path "results_$dbname/Users.txt" -Value "CURRENT USERS" -mysql -u$username -p$passwordText -P $port $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" +Add-Content -Path "results_-P3399 $dbname/Users.txt" -Value "CURRENT USERS" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_-P3399 $dbname/Users.txt" # ALL VARIABLES -Add-Content -Path "results_$dbname/All_variables.txt" -Value "ALL VARIABLES" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" +Add-Content -Path "results_-P3399 $dbname/All_variables.txt" -Value "ALL VARIABLES" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables' | Out-File -Append -FilePath "results_-P3399 $dbname/All_variables.txt" # DATABASES -Add-Content -Path "results_$dbname/Databases.txt" -Value "DATABASES" -mysql -u$username -p$passwordText -P $port $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" -mysql -u$username -p$passwordText -P $port $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" +Add-Content -Path "results_-P3399 $dbname/Databases.txt" -Value "DATABASES" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show databases' | Out-File -Append -FilePath "results_-P3399 $dbname/Databases.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_-P3399 $dbname/mysql_databases.txt" # TLS VERSION -Add-Content -Path "results_$dbname/Databases.txt" -Value "TLS VERSION" -mysql -u$username -p$passwordText -P $port $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +Add-Content -Path "results_-P3399 $dbname/Databases.txt" -Value "TLS VERSION" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_-P3399 $dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES -Add-Content -Path "results_$dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u$username -p$passwordText -P $port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" -mysql -u$username -p$passwordText -P $port $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" +Add-Content -Path "results_-P3399 $dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_-P3399 $dbname/Tables_from_databases.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_-P3399 $dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL -Add-Content -Path "results_$dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u$username -p$passwordText -P $port $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" +Add-Content -Path "results_-P3399 $dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" +mysql -u$username -p$passwordText -P3399 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_-P3399 $dbname/Not_system_tables.txt" # Operating System Level Configuration -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Logging -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Logging" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Logging" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P $port $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u$username -p$passwordText -P $port $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" +mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u$username -p$passwordText -P $port $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" +mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # MySQL Permissions -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "MySQL Permissions" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "MySQL Permissions" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" # Blank line -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u$username -p$passwordText -P $port $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # MySQL Configuration -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "MySQL Configuration" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "MySQL Configuration" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # SSL Configuration -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "SSL Configuration" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "SSL Configuration" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P $port $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" +Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From 086f27c99f703078e162cf08047823617c98506d Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:50:08 +0100 Subject: [PATCH 09/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 308 ++++++++++++++++++++++---------------------- 1 file changed, 154 insertions(+), 154 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index cfa2fbc..acb6a3d 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -10,7 +10,7 @@ Write-Host "Enter your username for mysql (root recommended)" $username = Read-Host Write-Host "Enter name database :" --P3399 $dbname = Read-Host +$dbname = Read-Host Write-Host "Enter password (password not shown)" $password = Read-Host -AsSecureString @@ -18,245 +18,245 @@ $passwordText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([Syste # CREATING DIRECTORIES: RESULTS Write-Host "CREATING DIRECTORIES : RESULTS" -New-Item -ItemType Directory -Path "results_-P3399 $dbname" -Force | Out-Null +New-Item -ItemType Directory -Path "results_$dbname" -Force | Out-Null # General Information for MYSQL Audit Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date -Add-Content -Path "results_-P3399 $dbname/System_info.txt" -Value "Time and Date" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_-P3399 $dbname/System_info.txt" +Add-Content -Path "results_$dbname $dbname/System_info.txt" -Value "Time and Date" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname $dbname/System_info.txt" # MYSQL VERSION -Add-Content -Path "results_-P3399 $dbname/System_info.txt" -Value "MYSQL VERSION" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_-P3399 $dbname/System_info.txt" +Add-Content -Path "results_$dbname $dbname/System_info.txt" -Value "MYSQL VERSION" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname $dbname/System_info.txt" # USERS -Add-Content -Path "results_-P3399 $dbname/Users.txt" -Value "USERS" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_-P3399 $dbname/Users.txt" +Add-Content -Path "results_$dbname $dbname/Users.txt" -Value "USERS" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname $dbname/Users.txt" # CURRENT USERS -Add-Content -Path "results_-P3399 $dbname/Users.txt" -Value "CURRENT USERS" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_-P3399 $dbname/Users.txt" +Add-Content -Path "results_$dbname $dbname/Users.txt" -Value "CURRENT USERS" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname $dbname/Users.txt" # ALL VARIABLES -Add-Content -Path "results_-P3399 $dbname/All_variables.txt" -Value "ALL VARIABLES" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables' | Out-File -Append -FilePath "results_-P3399 $dbname/All_variables.txt" +Add-Content -Path "results_$dbname $dbname/All_variables.txt" -Value "ALL VARIABLES" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname $dbname/All_variables.txt" # DATABASES -Add-Content -Path "results_-P3399 $dbname/Databases.txt" -Value "DATABASES" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show databases' | Out-File -Append -FilePath "results_-P3399 $dbname/Databases.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_-P3399 $dbname/mysql_databases.txt" +Add-Content -Path "results_$dbname $dbname/Databases.txt" -Value "DATABASES" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname $dbname/Databases.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname $dbname/mysql_databases.txt" # TLS VERSION -Add-Content -Path "results_-P3399 $dbname/Databases.txt" -Value "TLS VERSION" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_-P3399 $dbname/Databases.txt" +Add-Content -Path "results_$dbname $dbname/Databases.txt" -Value "TLS VERSION" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname $dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES -Add-Content -Path "results_-P3399 $dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_-P3399 $dbname/Tables_from_databases.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_-P3399 $dbname/mysql_tables.txt" +Add-Content -Path "results_$dbname $dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname $dbname/Tables_from_databases.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname $dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL -Add-Content -Path "results_-P3399 $dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u$username -p$passwordText -P3399 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_-P3399 $dbname/Not_system_tables.txt" +Add-Content -Path "results_$dbname $dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" +mysql -u$username -p$passwordText -P3316 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname $dbname/Not_system_tables.txt" # Operating System Level Configuration -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Logging -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Logging" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Logging" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" +mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # MySQL Permissions -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "MySQL Permissions" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "MySQL Permissions" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" # Blank line -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # MySQL Configuration -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "MySQL Configuration" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "MySQL Configuration" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # SSL Configuration -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "SSL Configuration" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "SSL Configuration" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_-P3399 $dbname/MYSQLAudit.txt" -Add-Content -Path "results_-P3399 $dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From 9a9276105d85fdfdc2512acc927fd6c239b6fe69 Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:51:49 +0100 Subject: [PATCH 10/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 304 ++++++++++++++++++++++---------------------- 1 file changed, 152 insertions(+), 152 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index acb6a3d..bc7e2c2 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -24,239 +24,239 @@ New-Item -ItemType Directory -Path "results_$dbname" -Force | Out-Null Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date -Add-Content -Path "results_$dbname $dbname/System_info.txt" -Value "Time and Date" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname $dbname/System_info.txt" +Add-Content -Path "results_$dbname/System_info.txt" -Value "Time and Date" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # MYSQL VERSION -Add-Content -Path "results_$dbname $dbname/System_info.txt" -Value "MYSQL VERSION" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname $dbname/System_info.txt" +Add-Content -Path "results_$dbname/System_info.txt" -Value "MYSQL VERSION" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # USERS -Add-Content -Path "results_$dbname $dbname/Users.txt" -Value "USERS" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname $dbname/Users.txt" +Add-Content -Path "results_$dbname/Users.txt" -Value "USERS" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" # CURRENT USERS -Add-Content -Path "results_$dbname $dbname/Users.txt" -Value "CURRENT USERS" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname $dbname/Users.txt" +Add-Content -Path "results_$dbname/Users.txt" -Value "CURRENT USERS" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" # ALL VARIABLES -Add-Content -Path "results_$dbname $dbname/All_variables.txt" -Value "ALL VARIABLES" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname $dbname/All_variables.txt" +Add-Content -Path "results_$dbname/All_variables.txt" -Value "ALL VARIABLES" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" # DATABASES -Add-Content -Path "results_$dbname $dbname/Databases.txt" -Value "DATABASES" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname $dbname/Databases.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname $dbname/mysql_databases.txt" +Add-Content -Path "results_$dbname/Databases.txt" -Value "DATABASES" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" # TLS VERSION -Add-Content -Path "results_$dbname $dbname/Databases.txt" -Value "TLS VERSION" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname $dbname/Databases.txt" +Add-Content -Path "results_$dbname/Databases.txt" -Value "TLS VERSION" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES -Add-Content -Path "results_$dbname $dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname $dbname/Tables_from_databases.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname $dbname/mysql_tables.txt" +Add-Content -Path "results_$dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL -Add-Content -Path "results_$dbname $dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u$username -p$passwordText -P3316 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname $dbname/Not_system_tables.txt" +Add-Content -Path "results_$dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" +mysql -u$username -p$passwordText -P3316 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" # Operating System Level Configuration -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Logging -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Logging" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Logging" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" +mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # MySQL Permissions -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "MySQL Permissions" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "MySQL Permissions" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Blank line -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # MySQL Configuration -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "MySQL Configuration" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "MySQL Configuration" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # SSL Configuration -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "SSL Configuration" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "################################" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value " " +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "SSL Configuration" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname $dbname/MYSQLAudit.txt" -Add-Content -Path "results_$dbname $dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From 58c26d986a71e05f2c681c2d56d4c7166b5724d0 Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:53:01 +0100 Subject: [PATCH 11/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index bc7e2c2..62b0ffb 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -25,60 +25,60 @@ Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date Add-Content -Path "results_$dbname/System_info.txt" -Value "Time and Date" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # MYSQL VERSION Add-Content -Path "results_$dbname/System_info.txt" -Value "MYSQL VERSION" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # USERS Add-Content -Path "results_$dbname/Users.txt" -Value "USERS" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" # CURRENT USERS Add-Content -Path "results_$dbname/Users.txt" -Value "CURRENT USERS" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" # ALL VARIABLES Add-Content -Path "results_$dbname/All_variables.txt" -Value "ALL VARIABLES" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" # DATABASES Add-Content -Path "results_$dbname/Databases.txt" -Value "DATABASES" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" # TLS VERSION Add-Content -Path "results_$dbname/Databases.txt" -Value "TLS VERSION" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES Add-Content -Path "results_$dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL Add-Content -Path "results_$dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u$username -p$passwordText -P3316 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" # Operating System Level Configuration Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -89,67 +89,67 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -160,38 +160,38 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Blank line Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -202,49 +202,49 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # SSL Configuration @@ -254,9 +254,9 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From b8bcca30fecc1ab79bf51af16becaeaaa5a5e88e Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:55:30 +0100 Subject: [PATCH 12/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index 62b0ffb..bc7e2c2 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -25,60 +25,60 @@ Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date Add-Content -Path "results_$dbname/System_info.txt" -Value "Time and Date" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # MYSQL VERSION Add-Content -Path "results_$dbname/System_info.txt" -Value "MYSQL VERSION" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # USERS Add-Content -Path "results_$dbname/Users.txt" -Value "USERS" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" # CURRENT USERS Add-Content -Path "results_$dbname/Users.txt" -Value "CURRENT USERS" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" # ALL VARIABLES Add-Content -Path "results_$dbname/All_variables.txt" -Value "ALL VARIABLES" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" # DATABASES Add-Content -Path "results_$dbname/Databases.txt" -Value "DATABASES" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" # TLS VERSION Add-Content -Path "results_$dbname/Databases.txt" -Value "TLS VERSION" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES Add-Content -Path "results_$dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL Add-Content -Path "results_$dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u$username -p$passwordText -P3399 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" # Operating System Level Configuration Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -89,67 +89,67 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u$username -p$passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -160,38 +160,38 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Blank line Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u$username -p$passwordText -P3399 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -202,49 +202,49 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # SSL Configuration @@ -254,9 +254,9 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3399 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From 91327bac4649f9038534aec1206427e14b768510 Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:10:56 +0100 Subject: [PATCH 13/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index bc7e2c2..a931add 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -25,60 +25,60 @@ Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date Add-Content -Path "results_$dbname/System_info.txt" -Value "Time and Date" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # MYSQL VERSION Add-Content -Path "results_$dbname/System_info.txt" -Value "MYSQL VERSION" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # USERS Add-Content -Path "results_$dbname/Users.txt" -Value "USERS" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" # CURRENT USERS Add-Content -Path "results_$dbname/Users.txt" -Value "CURRENT USERS" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" # ALL VARIABLES Add-Content -Path "results_$dbname/All_variables.txt" -Value "ALL VARIABLES" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" # DATABASES Add-Content -Path "results_$dbname/Databases.txt" -Value "DATABASES" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" # TLS VERSION Add-Content -Path "results_$dbname/Databases.txt" -Value "TLS VERSION" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES Add-Content -Path "results_$dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL Add-Content -Path "results_$dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u$username -p$passwordText -P3316 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" # Operating System Level Configuration Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -89,67 +89,67 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u$username -p$passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -160,38 +160,38 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Blank line Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u$username -p$passwordText -P3316 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -202,49 +202,49 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # SSL Configuration @@ -254,9 +254,9 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u$username -p$passwordText -P3316 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From 7c4a1cfaa2ec532f3a3196190c3684d715a12ae8 Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:11:52 +0100 Subject: [PATCH 14/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index a931add..b444757 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -25,60 +25,60 @@ Write-Host "SecureLayer7 MYSQL Audit Started" # Time and Date Add-Content -Path "results_$dbname/System_info.txt" -Value "Time and Date" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # MYSQL VERSION Add-Content -Path "results_$dbname/System_info.txt" -Value "MYSQL VERSION" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" # USERS Add-Content -Path "results_$dbname/Users.txt" -Value "USERS" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" # CURRENT USERS Add-Content -Path "results_$dbname/Users.txt" -Value "CURRENT USERS" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" # ALL VARIABLES Add-Content -Path "results_$dbname/All_variables.txt" -Value "ALL VARIABLES" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" # DATABASES Add-Content -Path "results_$dbname/Databases.txt" -Value "DATABASES" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" # TLS VERSION Add-Content -Path "results_$dbname/Databases.txt" -Value "TLS VERSION" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES Add-Content -Path "results_$dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL Add-Content -Path "results_$dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u $username -p $passwordText -P3316 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" # Operating System Level Configuration Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -89,67 +89,67 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u $username -p $passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u $username -p $passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u $username -p $passwordText -P3316 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -160,38 +160,38 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Blank line Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u $username -p $passwordText -P3316 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -202,49 +202,49 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # SSL Configuration @@ -254,9 +254,9 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u $username -p $passwordText -P3316 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant" From cdd2fa51f115d048110bcdfdc78dd116f52cbff8 Mon Sep 17 00:00:00 2001 From: Adrien B <49166384+0x307845@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:43:38 +0100 Subject: [PATCH 15/15] Update MYSQL-CIS-Audit.ps1 --- MYSQL-CIS-Audit.ps1 | 100 ++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/MYSQL-CIS-Audit.ps1 b/MYSQL-CIS-Audit.ps1 index b444757..b4f77f9 100644 --- a/MYSQL-CIS-Audit.ps1 +++ b/MYSQL-CIS-Audit.ps1 @@ -9,12 +9,17 @@ Write-Host "Enter your username for mysql (root recommended)" $username = Read-Host +Write-Host "Databse ip adress" +$ipaddr = Read-Host + Write-Host "Enter name database :" $dbname = Read-Host -Write-Host "Enter password (password not shown)" -$password = Read-Host -AsSecureString -$passwordText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) +Write-Host "Enter database port :" +$port = Read-Host + +Write-Host "Enter password (password will show on prompt)" +$password = Read-Host # CREATING DIRECTORIES: RESULTS Write-Host "CREATING DIRECTORIES : RESULTS" @@ -23,62 +28,65 @@ New-Item -ItemType Directory -Path "results_$dbname" -Force | Out-Null # General Information for MYSQL Audit Write-Host "SecureLayer7 MYSQL Audit Started" +$connectionString = "mysql -h $ipaddr -u $username -p$password -P$port $dbname -e" +Write-Host $connectionString + # Time and Date Add-Content -Path "results_$dbname/System_info.txt" -Value "Time and Date" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select NOW()' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +Invoke-Expression "$connectionString `"`SELECT NOW()`"" | Out-File -Append -FilePath "results_$dbname/System_info.txt" # MYSQL VERSION Add-Content -Path "results_$dbname/System_info.txt" -Value "MYSQL VERSION" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "%version%"' | Out-File -Append -FilePath "results_$dbname/System_info.txt" +Invoke-Expression "$connectionString `"`show variables like '%version%'`""| Out-File -Append -FilePath "results_$dbname/System_info.txt" # USERS Add-Content -Path "results_$dbname/Users.txt" -Value "USERS" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user,host from mysql.user' | Out-File -Append -FilePath "results_$dbname/Users.txt" +Invoke-Expression "$connectionString `"`select user,host from mysql.user`""| Out-File -Append -FilePath "results_$dbname/Users.txt" # CURRENT USERS Add-Content -Path "results_$dbname/Users.txt" -Value "CURRENT USERS" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show processlist' | Out-File -Append -FilePath "results_$dbname/Users.txt" +Invoke-Expression "$connectionString `"`show processlist`"" | Out-File -Append -FilePath "results_$dbname/Users.txt" # ALL VARIABLES Add-Content -Path "results_$dbname/All_variables.txt" -Value "ALL VARIABLES" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables' | Out-File -Append -FilePath "results_$dbname/All_variables.txt" +Invoke-Expression "$connectionString `"`show variables`"" | Out-File -Append -FilePath "results_$dbname/All_variables.txt" # DATABASES Add-Content -Path "results_$dbname/Databases.txt" -Value "DATABASES" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show databases' | Out-File -Append -FilePath "results_$dbname/Databases.txt" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show databases' | Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" +Invoke-Expression "$connectionString `"`show databases`""| Out-File -Append -FilePath "results_$dbname/Databases.txt" +Invoke-Expression "$connectionString `"`show databases`""| Select-String -Pattern "Database" -NotMatch | Out-File -FilePath "results_$dbname/mysql_databases.txt" # TLS VERSION Add-Content -Path "results_$dbname/Databases.txt" -Value "TLS VERSION" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select @@tls_version' | Out-File -Append -FilePath "results_$dbname/Databases.txt" +Invoke-Expression "$connectionString `"`select @@tls_version`""| Out-File -Append -FilePath "results_$dbname/Databases.txt" # ALL TABLES FROM ALL DATABASES Add-Content -Path "results_$dbname/Tables_from_databases.txt" -Value "ALL TABLES FROM ALL DATABASES" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select table_schema, table_name from information_schema.tables' | Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" +Invoke-Expression "$connectionString `"`select table_schema, table_name from information_schema.tables`""| Out-File -Append -FilePath "results_$dbname/Tables_from_databases.txt" +Invoke-Expression "$connectionString `"`select table_schema, table_name from information_schema.tables`""| Out-File -Append -FilePath "results_$dbname/mysql_tables.txt" # TABLES FROM ALL DATABASES EXCEPT INTERNAL Add-Content -Path "results_$dbname/Not_system_tables.txt" -Value "TABLES FROM ALL DATABASES EXCEPT INTERNAL" -mysql -u $username -p $passwordText -P3399 $dbname -e "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')" | Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" +Invoke-Expression "$connectionString `"`SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql')`""| Out-File -Append -FilePath "results_$dbname/Not_system_tables.txt" # Operating System Level Configuration Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Starting of MYSQL Audit" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.1" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables where variable_name = "datadir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables where variable_name = 'datadir'`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 3.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.2" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "log_bin_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'log_bin_basename'`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Auditing Guidance for section 2.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 2.2" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "basedir"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'basedir'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -89,67 +97,67 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "log_error"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'log_error'`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.3" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "log_bin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'log_bin'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.4" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "slow_query_log"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'slow_query_log'`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 3.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 3.5" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "relay_log_basename"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'relay_log_basename'`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u $username -p $passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "sql_mode"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`SHOW VARIABLES LIKE 'sql_mode'`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.5" -mysql -u $username -p $passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "default_password_lifetime"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`SHOW VARIABLES LIKE 'default_password_lifetime'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.6" -mysql -u $username -p $passwordText -P3399 $dbname -e 'SHOW VARIABLES LIKE "validate_password%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`SHOW VARIABLES LIKE 'validate_password%'`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.5" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user from mysql.user where user = "root"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user from mysql.user where user = 'root'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.9 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.9" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user from mysql.user where host = "%"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user from mysql.user where host = '%'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.10" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, password from mysql.user where length(password) = 0 or password is null' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user, password from mysql.user where length(password) = 0 or password is null`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 4.11 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 4.11" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user from mysql.user where user = ""' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user from mysql.user where user = ''`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -160,38 +168,38 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.1 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.1" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where (Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y")' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.db where db = "mysql" and ((Select_priv = "Y") or (Insert_priv = "Y") or (Update_priv = "Y") or (Delete_priv = "Y") or (Create_priv = "Y") or (Drop_priv = "Y"))' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user, host from mysql.user where (Select_priv = 'Y') or (Insert_priv = 'Y') or (Update_priv = 'Y') or (Delete_priv = 'Y') or (Create_priv = 'Y') or (Drop_priv = 'Y')`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user, host from mysql.db where db = 'mysql' and ((Select_priv = 'Y') or (Insert_priv = 'Y') or (Update_priv = 'Y') or (Delete_priv = 'Y') or (Create_priv = 'Y') or (Drop_priv = 'Y'))`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.2" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where File_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user, host from mysql.user where File_priv = 'Y'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.3" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where Process_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user, host from mysql.user where Process_priv = 'Y'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.4" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where Super_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user, host from mysql.user where Super_priv = 'Y'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 5.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.5" -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where Shutdown_priv ="Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user, host from mysql.user where Shutdown_priv ='Y'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" # Blank line Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 5.6 " -mysql -u $username -p $passwordText -P3399 $dbname -e 'select user, host from mysql.user where Create_user_priv = "Y"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`select user, host from mysql.user where Create_user_priv = 'Y'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " @@ -202,49 +210,49 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.2" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "local_infile"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'local_infile'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.3 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.3" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "old_passwords"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'old_passwords'`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.4 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.4" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "safe_show_database"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'safe_show_database'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.5 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.5" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "secure_auth"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'secure_auth'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.6 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.6" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "skip_grant_table"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'skip_grant_table'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.7 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.7" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "have_merge_engin"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'have_merge_engin'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.8 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.8" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "skip_networking"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like skip_networking'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "################################" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 6.10 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 6.10" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "have_symlink"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'have_symlink'`"" | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # SSL Configuration @@ -254,9 +262,9 @@ Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value " " # Auditing Guidance for section 7.2 Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "Auditing Guidance for section 7.2" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "have_openssl"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "ssl_key"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" -mysql -u $username -p $passwordText -P3399 $dbname -e 'show variables like "ssl_ca"' | Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'have_openssl'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'ssl_key'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" +Invoke-Expression "$connectionString `"`show variables like 'ssl_ca'`""| Out-File -Append -FilePath "results_$dbname/MYSQLAudit.txt" Add-Content -Path "results_$dbname/MYSQLAudit.txt" -Value "##################END AUDIT##############" Write-Host "##################END MYSQL AUDIT##############" Write-Host "ZIP the result folder and email to consultant"