大数据 爬虫Python AI SqlIT@程序员猿媛

解密红薯中文网手机站点升级版CSS反爬

2019-07-19  本文已影响104人  Jkanon

今日有网友抛出一个小说网站,说是爬虫遇到了点障碍,兴趣使然我也去凑了个热闹,结果发现这个网站的反爬也是我平生第一次所见,在此记录下详细的破解过程。

问题

站点链接:传送门

思路分析

["65291", " 30339", " 12289", " 21015", " 20153", " 19967", " 20181", " 26160", " 19982", " 22311", " 26378", " 20101", " 30527", " 8222", " 8219", " 31167", " 22824", " 19977", " 36948", " 27461", " 20009", " 21518", " 19980", " 22319"]

    2.第二次解密
以下代码就是将secWords解密为最终的文字并保存到words数组中。
总结起来就是对于secWords的每个元素进行以下操作:
假设输入n,则输出

伪代码
var t = (n+3) % 2 === 0 ? (n+3)-2 : (n+3)-4       ==>    n % 2 === 0 ? n - 1 : n + 1
String.fromCharCode(t)
输出示例
secWords[0] => 65291 => 65292(65291+1) => ','(String.fromCharCode('65292'));
secWords[1] => 30339 => 30340(30339+1) => '的'(String.fromCharCode('30340'));
源代码
for (var i = 0x0; i < secWords[_0xea12('0x18')]; i++) {
    var _0x5420ee = '3|5|2|4|0|1' [_0xea12('0x17')]('|'),
    _0x9ff9d9 = 0x0;
    while ( !! []) {
        switch (_0x5420ee[_0x9ff9d9++]) {
        case '0':
            _0x423190 = _0x5796d9(_0x423190);
            continue;
        case '1':
            words[i] = String[_0xea12('0x25')](_0x423190);
            continue;
        case '2':
            var _0x5796d9 = function(_0x490c80) {
                var _0x1532b6 = {
                    'ifLSL': function _0x256992(_0x118bb, _0x36aa09) {
                        return _0x118bb + _0x36aa09;
                    }
                };
                return _0x1532b6[_0xea12('0x26')](_0x490c80, 0x3 * +!(typeof document === _0xea12('0x27')));
            };
            continue;
        case '3':
            var _0x423190 = secWords[i];
            continue;
        case '4':
            _0x423190 = _0x3e8e1e(_0x423190);
            continue;
        case '5':
            var _0x3e8e1e = function(_0xd024e1) {
                var _0x3e40d1 = {
                    'mPDrG': function _0x411e6f(_0xa8939, _0x278c20) {
                        return _0xa8939 % _0x278c20;
                    },
                    'DWwdv': function _0x1e0293(_0x5b15eb, _0x443876) {
                        return _0x5b15eb - _0x443876;
                    }
                };
                return _0x3e40d1[_0xea12('0x28')](_0xd024e1, 0x2) ? _0x3e40d1[_0xea12('0x29')](_0xd024e1, 0x2) : _0xd024e1 - 0x4;
            };
            continue;
        }
        break;
    }
}

    3.设置style
这一步就是样式设置的关键所在了,将根据上一步得到的words数组添加到styleSheets中(就是这一步导致了控制板面板上无法看到样式定义的源头

源代码
for (var i = 0x0; i < words[_0xea12('0x18')]; i++) {
    try {
        //document.styleSheets[0].addRule('.context_kw'+i + '::before',  'content:\x20\x22' + words[i] + '\x22')
        document[_0xea12('0x2a')][0x0][_0xea12('0x2b')]('.context_kw' + i + _0xea12('0x2c'), 'content:\x20\x22' + words[i] + '\x22');
    } catch(_0x527f83) {
        document['styleSheets'][0x0]['insertRule'](_0xea12('0x2d') + i + _0xea12('0x2e') + words[i] + '\x22}', document[_0xea12('0x2a')][0x0][_0xea12('0x2f')][_0xea12('0x18')]);
    }
}

爬虫思路

换了几个页面之后,我发现这个words列表并不是固定不变的,因此我们得寻找到一种方法得到words数组。

PC站点会更加复杂点,需要先通过ajax加载文章内容,然后解密文章文本,余下步骤与手机版一致。

上一篇 下一篇

猜你喜欢

热点阅读