




| Resultats | security filesystem | Contact |
|
Manuel PHP
|
|
Table : .Introduction.General considerations .Installed as CGI binary .Installed as an Apache module .Filesystem Security .Database Security .Error Reporting .Using Register Globals .User Submitted Data .Magic Quotes .Hiding PHP .Keeping Current |
security filesystemFilesystem SecurityPHP is subject to the security built into most server systems with respect to permissions on a file and directory basis. This allows you to control which files in the filesystem may be read. Care should be taken with any files which are world readable to ensure that they are safe for reading by all users who have access to that filesystem. Since PHP was designed to allow user level access to the filesystem, it's entirely possible to write a PHP script that will allow you to read system files such as /etc/passwd, modify your ethernet connections, send massive printer jobs out, etc. This has some obvious implications, in that you need to ensure that the files that you read from and write to are the appropriate ones. Consider the following script, where a user indicates that they'd like to delete a file in their home directory. This assumes a situation where a PHP web interface is regularly used for file management, so the Apache user is allowed to delete files in the user home directories.
Example#1 Poor variable checking leads to....
<?phpExample#2 ... A filesystem attack
<?php
Example#3 More secure file name checking
<?phpExample#4 More secure file name checking
<?phpDepending on your operating system, there are a wide variety of files which you should be concerned about, including device entries (/dev/ or COM1), configuration files (/etc/ files and the .ini files), well known file storage areas (/home/, My Documents), etc. For this reason, it's usually easier to create a policy where you forbid everything except for what you explicitly allow. Null bytes related issuesAs PHP uses the underlying C functions for filesystem related operations, it may handle null bytes in a quite unexpected way. As null bytes denote the end of a string in C, strings containing them won't be considered entirely but rather only until a null byte occurs. The following example shows a vulnerable code that demonstrates this problem: Example#5 Script vulnerable to null bytes
<?phpTherefore, any tainted string that is used in a filesystem operation should always be validated properly. Here is a better version of the previous example: Example#6 Correctly validating the input
<?php |


PHP 手册