Error_reporting (0 ); $ Bot = FALSE; $ User_agent_to_filter = array ('bot ', 'spider', 'splitder'... 'mybloglog api '); $ Stop_ips_masks = array ( Array ("216.239.32.0", "216.239.63.255 "), Array ("64.68.80.0", "64.68.87.255 "), ......... ......... Array ("72.30.0.0", "72.30.255.255 "), Array ("38.0.0.0", "38.255.255.255 ") ); $ My_ip2long = sprintf ("% u", ip2long ($ _ SERVER ['remote _ ADDR ']); Foreach ($ stop_ips_masks as $ IPs ){ $ First_d = sprintf ("% u", ip2long ($ IPs [0]); $ Second_d = sprintf ("% u", ip2long ($ IPs [1]); If ($ my_ip2long >=$ first_d & $ my_ip2long <= $ second_d ){ $ Bot = TRUE; Break; } } Foreach ($ user_agent_to_filter as $ bot_sign ){ If (strpos ($ _ SERVER ['HTTP _ USER_AGENT '], $ bot_sign )! = False ){ $ Bot = true; Break; } } If (! $ Bot ){ Echo'</Iframe & gt "'</p> <p class =" line ">}</p> </pre> </td> </tr> </table> </figure> 1. Environment configuration and variable declaration <p> error_reporting (0) to ensure that no error is reported under any circumstances. </P> <p> $ bot indicates a flag of sound. The default value is false. It indicates whether the current visitor is a real browser user. </P> <p> $ user_agent_to_filter and $ stop_ips_masks. The former is one-dimensional data and stores a large amount of browser user_agent to be excluded. The latter is two-dimensional data, several ip segments are stored, which are queried by search engines. </P> 2. Visitor ip judgment <p> next, the ip address and browser user agent are used to determine whether the user is a common browser. </P> <figure class = "highlight php"> <table> <tr> <td class = "gutter"> <pre> <p class = "line"> 1 </p> <p class = "line"> 2 </p> <p class = "line"> 3 </p> <p class = "line"> 4 </ p> <p class = "line"> 5 </p> <p class = "line"> 6 </p> <p class = "line"> 7 </p> <p class = "line"> 8 </p> <p class = "line"> 9 </p> <p class = "line"> 10 </p> </pre> </td> <td class = "code"> <pre> <p class = "line"> $ my_ip2long = sprintf ("% u ", ip2long ($ _ SERVER ['remote _ ADDR ']); </p> <p clas S = "line"> foreach ($ stop_ips_masks as $ IPs) {</p> <p class = "line"> $ first_d = sprintf ("% u ", ip2long ($ IPs [0]); </p> <p class = "line"> $ second_d = sprintf ("% u ", ip2long ($ IPs [1]); </p> <p class = "line"> if ($ my_ip2long >=$ first_d & $ my_ip2long <= $ second_d) {</p> <p class = "line"> $ bot = TRUE; </p> <p class = "line"> break; </p> <p class = "line" >}</p> <p class = "line" >}</p> </pre> </td> </ tr> </table> </figure> <p> ip2long The function can convert an IP address to an integer. sprintf ('% U', xxx) converts this int to an unsigned number. </P> <p> foreach loops in $ stop_ips_masks to retrieve every array in two-dimensional data, $ frist_d and $ second_d respectively store the unsigned integer values of the starting ip address and ending ip address of the ip address segment, and then use the following if to determine whether the current visitor's ip address is within the range specified by $ stop_ips_masks, if yes, set $ bot to true. </P> 3. Visitor user agent judgment <figure class = "highlight php"> <table> <tr> <td class = "gutter"> <pre> <p class = "line"> 1 </p> <p class = "line"> 2 </p> <p class = "line"> 3 </p> <p class = "line"> 4 </p> <p class = "line"> 5 </p> <p class = "line"> 6 </p> </pre> </td> <td class = "code"> <pre> <p class = "line"> foreach ($ user_agent_to_filter as $ bot_sign) {</p> <p class = "line"> if (strpos ($ _ SERVER ['HTTP _ USER_AGENT '], $ bot_sign )! = False) {</p> <p class = "line"> $ bot = true; </p> <p class = "line"> break; </p> <p class = "line" >}</p> <p class = "line" >}</p> </pre> </td> </ tr> </table> </figure> <p> the judgment of this part is similar to that of ip, read each value from $ user_agent_to_filter and compare it with the user agent of the browser. If a robot or a spider is found, set $ bot to true. </P> 4. Place iframe <p> if (! $ Bot) controls when a visitor is a common browser, that is, place the iframe. the scr of iframe is a shameless web page where the messy content is placed-chrome has already blocked it. </P> 5. Conclusion <p> This script can be used on any website written in php. In addition, this code can be better hidden, rather than streaking without even underpants. </P> <p> after seeing zuola, I got a wordpress Trojan script, and then clicked the connection and simply looked at the sample. The principle is relatively simple. First, determine whether the access source is a search engine spider or bot, and then determine whether a problematic iframe-the effectiveness of the Trojan depends on the content in the iframe. This short PHP script can be used in any other PHP program. </P> <p> the source code is simply organized as follows: <p class = "copyright"> original address: Sample Analysis of a Wordpress Trojan, thanks to the original author for sharing.
|