有些站点仍在使用StaticFile CDN,关于投毒事件可以看一下吾爱论坛的帖子【BootCDN/Staticfile投毒分析】供应链投毒后,我们的选择还剩下哪些?。
现在该CDN的地址已被uBlock Origin列为恶意软件风险拦截列表,使用该脚本可以在网站管理员不修复的情况下替换自己访问网站的CDN为cloudflare或其他CDN。
修改代码中的SOURCE_CDN和TARGET_CDN即可针对不同链接进行替换。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
(function() { 'use strict';
const SOURCE_CDN = 'https://cdn.staticfile.org/'; const TARGET_CDN = 'https://cdnjs.cloudflare.com/ajax/libs/';
document.addEventListener('beforefetch', function(event) { const requestUrl = event.request.url; if (requestUrl.startsWith(SOURCE_CDN)) { const newUrl = TARGET_CDN + requestUrl.substring(SOURCE_CDN.length); event.preventDefault(); const newRequest = new Request(newUrl, event.request); fetch(newRequest).then(function(response) { return response; }); } });
function replaceLinks() { document.querySelectorAll(`script[src^="${SOURCE_CDN}"]`).forEach(function(script) { script.src = script.src.replace(SOURCE_CDN, TARGET_CDN); }); document.querySelectorAll(`link[href^="${SOURCE_CDN}"]`).forEach(function(link) { link.href = link.href.replace(SOURCE_CDN, TARGET_CDN); }); } replaceLinks();
const observer = new MutationObserver(replaceLinks); observer.observe(document, { childList: true, subtree: true });})();
|
本文作者 : hank9999
版权声明 :本站所有文章除特别声明外,均采用 BY-NC-SA 4.0 许可协议。转载请注明出处!
本文链接 : https://blog.hank.ltd/replace-poisoned-staticfile-cdn-with-tampermonkey-script/