Skip to content

Commit acb766e

Browse files
authored
Limit permissions dummy.conf and www.conf prevent permission escalation (hestiacp#4095)
* Apply changes to default config If users want less stricter system they can undo it * Make changes for new install * Fix few sed commands * And CLI as well * Update script * Replace dummy.conf with unix socket Use correct file Add comment on changes
1 parent 7a7c55a commit acb766e

File tree

7 files changed

+49
-7
lines changed

7 files changed

+49
-7
lines changed

bin/v-add-web-php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fi
5050
# Check if php version is supported
5151
if [[ ! "$multiphp_v" =~ $version ]]; then
5252
echo "ERROR: Specified PHP version is not supported or does not exist."
53-
exit "$E_INVALID";
53+
exit "$E_INVALID"
5454
fi
5555

5656
# Perform verification if read-only mode is enabled
@@ -131,14 +131,25 @@ update-rc.d php$version-fpm defaults > /dev/null 2>&1
131131
v_tpl=${version//./}
132132
rm -f /etc/php/$version/fpm/pool.d/*
133133
cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/php/$version/fpm/pool.d/
134-
sed -i "s/9999/99$v_tpl/g" /etc/php/$version/fpm/pool.d/dummy.conf
134+
sed -i "s/%backend_version%/$version/g" /etc/php/$version/fpm/pool.d/dummy.conf
135135
cp -f $HESTIA_INSTALL_DIR/php-fpm/php-fpm.conf /etc/php/$version/fpm/
136136
sed -i "s/fpm_v/$version/g" /etc/php/$version/fpm/php-fpm.conf
137137

138138
# Increase max upload and max post size
139139
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 100M/g" /etc/php/$version/fpm/php.ini
140140
sed -i "s/post_max_size = 8M/post_max_size = 100M/g" /etc/php/$version/fpm/php.ini
141141
sed -i "s/max_execution_time = 30/max_execution_time = 60/g" /etc/php/$version/fpm/php.ini
142+
sed -i "s/;max_input_vars = 1000/max_input_vars = 4000/g" /etc/php/$version/fpm/php.ini
143+
144+
# Disable exec and other harmfull php functions
145+
sed -i "s/disable_functions =.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,exec,system,passthru,shell_exec,proc_open,popen/g" /etc/php/$version/fpm/php.ini
146+
147+
sed -i "s/disable_functions =.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,exec,system,passthru,shell_exec,proc_open,popen/g" /etc/php/$version/cli/php.ini
148+
149+
# Other use full changes
150+
sed -i "s/;opcache.enable=1/opcache.enable=1/g" /etc/php/$version/fpm/php.ini
151+
sed -i "s/;opcache.memory_consumption=128/opcache.memory_consumption=512/g" /etc/php/$version/fpm/php.ini
152+
sed -i "s/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=100000/g" /etc/php/$version/fpm/php.ini
142153

143154
# Install backend template
144155
cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \

install/deb/php-fpm/dummy.conf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
; origin-src: deb/php-fpm/dummy.conf
22

3-
[www]
4-
listen = 127.0.0.1:9999
5-
listen.allowed_clients = 127.0.0.1
3+
[wwww]
4+
listen = /run/php/php%backend_version%-fpm.dummy.sock
5+
listen.owner = hestiamail
6+
listen.group = www-data
7+
listen.mode = 0660
68

7-
user = www-data
9+
;"hestiamail" user created to prevent users from abusing this config
10+
user = hestiamail
811
group = www-data
912

1013
pm = ondemand

install/deb/php-fpm/www.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
listen = 127.0.0.1:9000
55
listen.allowed_clients = 127.0.0.1
66

7-
user = www-data
7+
;"hestiamail" user created to prevent users from abusing this config
8+
user = hestiamail
89
group = www-data
910

1011
pm = ondemand

install/hst-install-debian.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,9 @@ random_password=$(gen_pass '32')
11271127
# do not allow login into hestiaweb user
11281128
echo hestiaweb:$random_password | sudo chpasswd -e
11291129

1130+
# Create user for php-fpm configs
1131+
/usr/sbin/useradd "hestiamail" -c "$email" --no-create-home
1132+
11301133
# Enable SFTP subsystem for SSH
11311134
sftp_subsys_enabled=$(grep -iE "^#?.*subsystem.+(sftp )?sftp-server" /etc/ssh/sshd_config)
11321135
if [ -n "$sftp_subsys_enabled" ]; then

install/hst-install-ubuntu.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,9 @@ random_password=$(gen_pass '32')
10951095
# do not allow login into hestiaweb user
10961096
echo hestiaweb:$random_password | sudo chpasswd -e
10971097

1098+
# Create user for php-fpm configs
1099+
/usr/sbin/useradd "hestiamail" -c "$email" --no-create-home
1100+
10981101
# Enable SFTP subsystem for SSH
10991102
sftp_subsys_enabled=$(grep -iE "^#?.*subsystem.+(sftp )?sftp-server" /etc/ssh/sshd_config)
11001103
if [ -n "$sftp_subsys_enabled" ]; then
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# info: Secure websites FPM / CLI against basic executions if you use such functions remove them form the list
3+
4+
sed -i "s/disable_functions =.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,exec,system,passthru,shell_exec,proc_open,popen/g" /etc/php/*/fpm/php.ini
5+
6+
sed -i "s/disable_functions =.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,exec,system,passthru,shell_exec,proc_open,popen/g" /etc/php/*/cli/php.ini

install/upgrade/versions/1.8.9.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,18 @@ if [ -f /etc/nginx/nginx.conf ]; then
3333
echo "[ * ] Mitigate HTTP/2 Rapid Reset Attack via Nginx CVE CVE-2023-44487"
3434
sed -i -E 's/(.*keepalive_requests\s{1,})10000;/\11000;/' /etc/nginx/nginx.conf /usr/local/hestia/nginx/conf/nginx.conf
3535
fi
36+
37+
# Fix security issue wit FPM pools
38+
if [ -z "$(grep ^hestiamail: /etc/passwd)" ]; then
39+
echo "[ * ] Limit permissions www.conf and dummy.conf"
40+
/usr/sbin/useradd "hestiamail" -c "$email" --no-create-home
41+
42+
sed -i "s/user = www-data/user = hestiamail/g" /etc/php/*/fpm/pool.d/www.conf
43+
44+
php_versions=$($BIN/v-list-sys-php plain)
45+
# Substitute php-fpm service name formats
46+
for version in $php_versions; do
47+
cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/php/$version/fpm/pool.d/
48+
sed -i "s/%backend_version%/$version/g" /etc/php/$version/fpm/pool.d/dummy.conf
49+
done
50+
fi

0 commit comments

Comments
 (0)