Use ereg in PHP to implement regular expression matching ip addresses

Source: Internet
Author: User
Tags ereg

Let's take a look at the code snippet:
Copy codeThe Code is as follows:
$ Ip = "1.1.1.255". chr (0). "haha ";
If (ereg ("^ [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3} $ ", $ ip )){
Echo $ ip;
} Else {
Echo "unknown ";
}
This ereg Regular Expression limits the data of $ ip to xxx. xxx. xxx. in the form of xxx, the above Code should output "unknown", but "1.1.1.255haha" is actually output, because the ereg function has the NULL Truncation Vulnerability, which causes Regular Expression Filter Bypass. 4 \ 2 n + Y6 |; Z7 O

6 e & b6 C5 F-W-F $ z we must introduce \ x00 (% 00) when using it ), when GPC is ON, % 00 will be escaped and cannot be used. But what if ereg () processes the data that $ _ SERVER (can bypass GPC in PHP5) or is processed by functions such as urldecode that cause GPC to be bypassed? For example, some programs use the above method to verify the IP address submitted by $ _ SERVER. Then we can use NULL truncation to bypass regular filtering to construct the data we need :)

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.