CRITICAL SECURITY FIXES: Address comprehensive audit findings
SECURITY FIXES: 1. Remove unsafe eval() function (launcher.sh:88-99) - eval() function removed entirely (was a code injection risk) - Function was unused but posed security liability 2. Fix SQL injection in database queries (reference-db.sh:225-229) - Properly escape single quotes in database names - Changed from incorrect backtick escaping to proper SQL escaping - Database names now safely used in WHERE clauses 3. Fix credential exposure (reference-db.sh:199-235) - MYSQL_PWD no longer exported (visible to child processes) - Password kept in local variable only - Set MYSQL_PWD only for individual mysql commands - Credentials immediately unset after use - Password never visible in 'ps aux' or /proc/environ 4. Refactored database queries - Each mysql command gets password set independently - Uses here-string (<<<) instead of process substitution for safety - Proper error handling per query All critical vulnerabilities addressed Syntax validation: PASS
This commit is contained in:
-18
@@ -80,24 +80,6 @@ run_module() {
|
|||||||
read -p "Press Enter to continue..."
|
read -p "Press Enter to continue..."
|
||||||
}
|
}
|
||||||
|
|
||||||
#############################################################################
|
|
||||||
# TERMINAL INPUT HELPER
|
|
||||||
#############################################################################
|
|
||||||
|
|
||||||
# Safe read that handles both interactive and piped scenarios
|
|
||||||
safe_read() {
|
|
||||||
local prompt="$1"
|
|
||||||
local varname="$2"
|
|
||||||
|
|
||||||
if [ -t 0 ]; then
|
|
||||||
# Terminal available, normal read
|
|
||||||
read -p "$prompt" "$varname"
|
|
||||||
else
|
|
||||||
# No terminal (piped stdin), accept input or skip
|
|
||||||
read -p "$prompt" "$varname" 2>/dev/null || eval "$varname=''"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# SYSTEM INFO DISPLAY (Quick View)
|
# SYSTEM INFO DISPLAY (Quick View)
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|||||||
+40
-11
@@ -198,15 +198,30 @@ build_databases_section() {
|
|||||||
|
|
||||||
# Build MySQL command with credentials if needed
|
# Build MySQL command with credentials if needed
|
||||||
local mysql_cmd="mysql"
|
local mysql_cmd="mysql"
|
||||||
|
local plesk_password=""
|
||||||
if [ "$SYS_CONTROL_PANEL" = "plesk" ] && [ -f /etc/psa/.psa.shadow ]; then
|
if [ "$SYS_CONTROL_PANEL" = "plesk" ] && [ -f /etc/psa/.psa.shadow ]; then
|
||||||
export MYSQL_PWD=$(cat /etc/psa/.psa.shadow)
|
plesk_password=$(cat /etc/psa/.psa.shadow)
|
||||||
mysql_cmd="mysql -uadmin"
|
# DO NOT export password - keep it in variable only
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local total_dbs=$($mysql_cmd -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" | wc -l)
|
# Query databases - set MYSQL_PWD only for this command
|
||||||
|
local total_dbs
|
||||||
|
if [ -n "$plesk_password" ]; then
|
||||||
|
total_dbs=$(MYSQL_PWD="$plesk_password" mysql -u admin -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" | wc -l)
|
||||||
|
else
|
||||||
|
total_dbs=$(mysql -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" | wc -l)
|
||||||
|
fi
|
||||||
local current=0
|
local current=0
|
||||||
|
|
||||||
# Use process substitution instead of pipe to avoid subshell shadowing (fixes current variable loss)
|
# Use process substitution instead of pipe to avoid subshell shadowing (fixes current variable loss)
|
||||||
|
# Get database list - set MYSQL_PWD only for this command
|
||||||
|
local databases
|
||||||
|
if [ -n "$plesk_password" ]; then
|
||||||
|
databases=$(MYSQL_PWD="$plesk_password" mysql -u admin -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$")
|
||||||
|
else
|
||||||
|
databases=$(mysql -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$")
|
||||||
|
fi
|
||||||
|
|
||||||
while IFS= read -r db; do
|
while IFS= read -r db; do
|
||||||
[ -z "$db" ] && continue
|
[ -z "$db" ] && continue
|
||||||
current=$((current + 1))
|
current=$((current + 1))
|
||||||
@@ -215,21 +230,35 @@ build_databases_section() {
|
|||||||
local owner=$(get_database_owner "$db")
|
local owner=$(get_database_owner "$db")
|
||||||
local domain=$(get_database_domain "$db")
|
local domain=$(get_database_domain "$db")
|
||||||
|
|
||||||
local size_mb=$($mysql_cmd -Ns -e "SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 2)
|
# Escape single quotes in database name for SQL safety
|
||||||
FROM information_schema.TABLES
|
local db_escaped="${db//\'/\'\'}"
|
||||||
WHERE table_schema=\`$db\`" 2>/dev/null)
|
|
||||||
|
# Query database size - set MYSQL_PWD only for this command
|
||||||
|
local size_mb
|
||||||
|
if [ -n "$plesk_password" ]; then
|
||||||
|
size_mb=$(MYSQL_PWD="$plesk_password" mysql -u admin -Ns -e "SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 2)
|
||||||
|
FROM information_schema.TABLES
|
||||||
|
WHERE table_schema='$db_escaped'" 2>/dev/null)
|
||||||
|
else
|
||||||
|
size_mb=$(mysql -Ns -e "SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 2)
|
||||||
|
FROM information_schema.TABLES
|
||||||
|
WHERE table_schema='$db_escaped'" 2>/dev/null)
|
||||||
|
fi
|
||||||
[ -z "$size_mb" ] && size_mb=0
|
[ -z "$size_mb" ] && size_mb=0
|
||||||
|
|
||||||
local table_count=$($mysql_cmd -Ns "$db" -e "SHOW TABLES" 2>/dev/null | wc -l)
|
# Query table count - set MYSQL_PWD only for this command
|
||||||
|
local table_count
|
||||||
|
if [ -n "$plesk_password" ]; then
|
||||||
|
table_count=$(MYSQL_PWD="$plesk_password" mysql -u admin -Ns "$db" -e "SHOW TABLES" 2>/dev/null | wc -l)
|
||||||
|
else
|
||||||
|
table_count=$(mysql -Ns "$db" -e "SHOW TABLES" 2>/dev/null | wc -l)
|
||||||
|
fi
|
||||||
|
|
||||||
echo "DB|$db|$owner|$domain|$size_mb|$table_count" >> "$SYSREF_DB"
|
echo "DB|$db|$owner|$domain|$size_mb|$table_count" >> "$SYSREF_DB"
|
||||||
done < <($mysql_cmd -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$")
|
done <<< "$databases"
|
||||||
|
|
||||||
finish_progress
|
finish_progress
|
||||||
echo "" >> "$SYSREF_DB"
|
echo "" >> "$SYSREF_DB"
|
||||||
|
|
||||||
# Clean up password environment variable
|
|
||||||
unset MYSQL_PWD
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check domain HTTP/HTTPS status codes
|
# Check domain HTTP/HTTPS status codes
|
||||||
|
|||||||
Reference in New Issue
Block a user