PHP program loopholes explain

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags default default value echo environment environment variables example network network programming

Several important php.ini options

Register Globals

php> = 4.2.0, the default value for php.ini's register_globals option is set to Off. When register_globals is set to On, the program can receive various environment variables from the server, including form submitted variables, and because PHP You do not have to initialize the value of the variable in advance, which leads to a great potential safety hazard.

example 1:

// check_admin () is used to check the current user permissions, if admin is set $ is_admin variable is true, and then determine whether this variable is true, and then perform some operations management

//ex1.php

if (check_admin ())

{

$ is_admin = true;

}

if ($ is_admin)

{

do_something ();

}

?>

This section of code does not initialize $ is_admin to Flase in advance. If register_globals is On, we can bypass check_admin () by submitting http://www.sectop.com/ex1.php?is_admin=true directly

Example 2:

//ex2.php

if (isset ($ _ SESSION ["username"]))

{

do_something ();

}

else

{

echo "You are not logged in!";

}

?>

//ex1.php

$ dir = $ _GET ["dir"];

if (isset ($ dir))

{

echo "

";

system ("ls -al". $ dir);

echo "

";

}

?>

mixed eval (string code_str) // eval injection generally occurs when the attacker can control the input string

//ex2.php

$ var = "var";

if (isset ($ _ GET ["arg"]))

{

$ arg = $ _GET ["arg"];

eval ("$ var = $ arg;");

echo "$ var =". $ var;

}

?>

Related Article

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.