Analysis process
This comes from some projects. It is common and frequently used to obtain user IP and record user operation behavior. Most friends will see the following general method of obtaining an IP address.
通过刚刚分析我们发现,其实这些变量,来自http请求的:x-forword-for字段,以及client-ip字段。 正常代理服务器,当然会按rfc规范来传入这些值。但是,当一个用户直接构造该x-forword-for值,发送给用户用户,那将会怎么样呢?
图(1)
第2步,修改x-forword-fox值,我们看看结果
第三步,我们再修改下看看会怎么样?
Haha, did you see the above result? x-forwarded-for can not only set the value by itself, but also can set the value in any format. In this way, it is like having a field that can write any value. And the server directly reads, or writes to the database, or displays. It will bring danger, just like operating the data source without any filtering and testing on the input. And it is easy to bring concealment.
Conclusion:The above getip function, except that the client can forge IP at will, and can pass in IP in any format. This will cause two major problems. First, if you set up a certain page and impose IP restrictions. The other party can easily change the IP and continuously request the page. Secondly, if you use this kind of data directly, it will bring vulnerabilities such as SQL registration and cross-site attacks. As for the first one, you can set restrictions on the business, and it is best not to use IP restrictions. For the second one, this type can bring huge cyber risks. We must correct it.
Getip needs to be modified to obtain a safe getip function.
Such problems are actually very easy to occur. I have used this to defraud a large number of fake votes in the past. It has its hiddenness. In fact, as long as we understand the ins and outs of certain values. Once you understand how it works, it will be very easy to fix this type of bug.
Off topic, there are three steps to do technology. First, you must be able to do it and solve it; secondly, you must think about why you want to do it, what are the reasons and principles; finally, how to do it, and are there any other methods? Ask yourself more and you will find that you are getting closer to the technical truth. You will become more and more comfortable in doing things!
Author: chengmo QQ:8292669