1 Attack analysis
Clevercode's OPS colleague told me that when he looked at MySQL's error log, he found a lot of errors, so someone was attacking an address. A large number of this error occurs because MySQL does not support negative numbers at limit. Usually when we split the page, the URL is generally written as http://xxx.com?page=1&pageSize=20, that is, to get the first page of data. 20 rows per page. But if http://xxx.com?page=-1&pageSize=20 is passed in. The following error will occur.
2 Problematic PHP code
function Getuserloginlog ($page, $pageSize) { //parameter Check if (!is_int ($page) | |!is_int ($pageSize)) { return; } $start = ($page-1) * $pageSize; $SQLSTR = "SELECT * from User_login_log the ORDER by id desc limit $start, $pageSize"; Execute SQL statement //... .. If page=-1,pagesize=20, the above statement becomes //$sqlStr = "SELECT * from User_login_log ORDER BY id desc limit-40,20";
3 PHP code to prevent attacks
You only need to judge $page, $pageSize is a positive integer.
function Getuserloginlog ($page, $pageSize) { //parameter Check if (!is_int ($page) | |!is_int ($pageSize)) { return; } //Positive integer check if ($page < 1 | | $pageSize < 1) { return; } $start = ($page-1) * $pageSize; $SQLSTR = "SELECT * from User_login_log the ORDER by id desc limit $start, $pageSize"; Execute SQL statement //... }
Copyright Notice:
1) original works, from "Clevercode's blog" , please be sure to mention the following original address when reproduced , otherwise hold the copyright legal responsibility.
2) Original address : http://blog.csdn.net/clevercode/article/details/45935593 ( reprint must indicate this address ).
3) Category address: http://blog.csdn.net/clevercode/article/category/3262205 ( Blog continues to increase, concern please collection )
4) welcome everyone to pay attention to my blog more wonderful content: Http://blog.csdn.net/CleverCode.
MySQL paging negative SQL attack