Hi everybody,
In this post, I would like to discuss concerns about SuExec from the point of view of security.
I am well aware that SuExec was invented to provided more security in a shared hosting environment. However, I have concerns about how Virtualmin uses this tool (or maybe about the very nature of SuExec). The public_html folder is owned by the virtual server owner (say “admin”). The group would also be “admin” and the permissions are 0750. So far good.
Now, let’s say I have a complex application and I was careless enough to not check user input thoroughly. Here is my complex application:
/home/testserver/public_html/test1.php: (Owner: “admin”, Group: “admin”, Permissions: 0640)
?>
/home/testserver/public_html/test3.php: (Owner: “admin”, Group: “admin”, Permissions: 0640)
So, the “hacker” will access http://www.testserver.com/test1.php. Since test1.php is executed using “admin” (because of SuExec), test2.php will be created in the public_html folder. The owner of this file will be “admin.” Then the hacker will go to http://www.testserver.com/test2.php, and my test3.php will be deleted. I have actually tested this situation.
This is, of course, an extremely naive and simplistic scenario. However, to me, the mere possibility of modifying the structure of the virtual server using publicly-accessible scripts represents a disadvantage. It seems that this is possible due to the fact that by default, the owner of the public_html folder is the same as the user used to execute PHP scripts, and apparently SuExec requires this.
This might not be a problem if programmers use good security measures in their scripts. May be there is a good reason to have this setup. Here are two solutions that I have thought of so far:
-
Don’t use SuExec at all: if the scripts are run as “apache,” then they won’t be able to alter the structure of the virtual server unless you explicitly create a folder where “apache” can write files. Of course, this means that other virtual server owners can write to this folder.
-
Leave SuExec alone, but instead of using “admin” as the owner of public_html, create another user (admin-webuser) that will be the owner of this folder. The group for this folder can be left as “admin.” This way, admin-webuser can upload and change files to public_html, and PHP scripts can be executed using SuExec. However, I think this still leaves other parts of the virtual server vulnerable (/home/tcs/*).
I would love to hear opinions. I am a big fan of Virtualmin (I am using Virtualmin 3.83.gpl), and it would be great to understand it in greater detail.
Thank you for reading this long post!