PHP anti-CC attack and prevent Quick Refresh page Example

Source: Internet
Author: User

CC Attack Reason

The principle of the CC attack is that the attacker controls some hosts to keep sending a large number of packets to the other server, causing the server to run out of resources until downtime crashes. CC is primarily used to attack pages, everyone has this experience: when a Web page visits a very large number of times, open the page is slow, CC is to simulate multiple users (how many threads are many users) Non-stop access to those who need a lot of data operations (that is, the need for a large amount of CPU time) of the page, Cause the waste of server resources, CPU for a long time in 100%, always have to deal with the connection until the network congestion, normal access was aborted.


CC Attack Refresh page does not make any sense to us, to say meaningful is to use our website resources.

Defense cc attacks can be done in a variety of ways, prohibit the site proxy access, as far as possible to make the site static page, limit the number of connections, modify the maximum timeout time.

Example

The code is as follows Copy Code

<?php

Proxy IP exit directly
Empty ($_server[' Http_via ') or exit (' Access Denied ');
Prevent quick Flushes
Session_Start ();
$seconds = ' 3 '; Time period [sec]
$refresh = ' 5 '; Refresh Times
Setting up monitoring variables
$cur _time = time ();
if (Isset ($_session[' last_time ')) {
$_session[' refresh_times '] + + 1;
}else{
$_session[' refresh_times '] = 1;
$_session[' last_time ' = $cur _time;
}
Process monitoring Results
if ($cur _time-$_session[' last_time '] < $seconds) {
if ($_session[' refresh_times '] >= $refresh) {
Jump to the attacker's server address
Header (sprintf (' location:%s ', ' http://127.0.0.1 '));
Exit (' Access Denied ');
}
}else{
$_session[' refresh_times '] = 0;
$_session[' last_time ' = $cur _time;
}
?>

The firewall is a very good solution to the CC attack, not only does it have any impact on the server but also effectively prevents CC attacks

The

Recommended small webmaster can use a security dog to do a CC attack or use Linux iptalbs to prevent CC attacks, as well as my server has a computer room firewall will automatically intercept these types of attacks oh.

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.