X-forwarded-for security risks of obtaining IP addresses and storing them into the database

Source: Internet
Author: User

Reprinted from: safe121
 
Recently, I have been exploring a program vulnerability with a hacker. One of them is the message board. The message board code is as follows:
 
$ Ip = $ _ SERVER ['HTTP _ X_FORWARDED_FOR '];
$ Content = safe ($ _ POST ["content"]);
 
Then write the data to the database ..
 
Although the post content is verified, the function "safe" is also fully filtered. Later I remembered a previous article about using php to forge IP addresses, after reading the code, we simulate sending HTTP_X_FORWARDED_FOR. Since this is not filtered, we can perform SQL injection.
 
 
 
Local Environment Simulation:
 
 
 
 
 
Google has a piece of php with forged ip addresses and forged SQL Injection statements .. In this way, SQL injection is formed ..
 
 

 
 
 
Repair Method:
 
Verify the obtained IP address. If a special character is displayed, it is not allowed to be submitted.
 

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.