猿人学内部练习平台第11题

第11题:人均会解jsl

控制台抓包可以看到,页面请求了两次 https://www.python-spider.com/challenge/11 第一次返回了一段js代码,第二次返回了所需数据:

对比两次请求参数发现,只有cookie中的__jsl_clearance发生了变化,其他参数均相同,因此该值应该是第一次返回的js生成的。清除cookie中的__jsl_clearance,打上script事件侦听器断点,单步调试,直至来到该js页面:

一步步调试至最后,发现eval的内容如下:

可以看到,里面有__jsl_clearance的生成逻辑,执行完该js文件后,控制台打印cookie,可以看到__jsl_clearance已经生成:

所以只需把该js代码放至本地运行即可生成__jsl_clearance
本地运行后,代码会卡住,即代码存在环境检测,单步调试后发现,代码卡在了

 eval(y.replace(/\b\w+\b/g, function(y) {
                return x[f(y, z) - 1] || ("_" + y)
            }));

刚刚我们已经知道了eval输出的内容是什么,将该部分内容复制出来,简单修改后控制台调试:

debugger;
var _N = function () {
    setTimeout('location.href=location.pathname+location.search.replace(/[\\?|&]captcha-challenge/,\'\')', 1500
)
    ;document.cookie = '__jsl_clearance=1714140907.524|0|' + (function () {
        var _t = [function (_N) {
            return _N
        }, function (_t) {
            return _t
        }, (function () {
            var _N = document.createElement('div');
            _N.innerHTML = '<a href=\' /\'>_1H</a>';
            _N = _N.firstChild.href;
            var _t = _N.match(/https?:\/\//)[0];_N=_N.substr(_t.length).toLowerCase();return function(_t){for(var _1H=0;_1H<_t.length;_1H++){_t[_1H]=_N.charAt(_t[_1H])};return _t.join('')}})(),function(_N){for(var _t=0;_t<_N.length;_t++){_N[_t]=parseInt(_N[_t]).toString(36)};return _N.join('')}],_N=['clD',[(-~~~{}<<-~~~{})+(-~~~{}<<-~~~{})],'V',[(-~[]+[]+[[]][0])+[-~-~{}]],'fq',[(-~[]+[]+[[]][0])+[-~[]-~[]-~!/!/+(-~[]-~[])*[-~[]-~[]]],(-~[]+[]+[[]][0])+(-~[-~-~{}]+[[]][0]),(-~[]+[]+[[]][0])+[(+!![[][[]]][1])]],'LBWywKW',[(2-~[-~-~{}]+[]+[[]][0])],'%2FZyf',[(-~[]+[]+[[]][0])+(-~[-~-~{}]+[[]][0])],'6',[(-~[]+[]+[[]][0])+(-~[-~-~{}]+[[]][0])],'_fa826e49bec0d5248d34e89755520aa8',(-~[-~-~{}]+[[]][0]),'D'];for(var _1H=0;_1H<_N.length;_1H++){_N[_1H]=_t[[1,0,1,2,1,3,1,2,1,2,1,3,1,0,1][_1H]](_N[_1H])};return _N.join('')})()+';Expires=Tue, 12-Dec-30 09:50:26 GMT;Path=/;'};if((function(){try{return !!window.addEventListener;}catch(e){return false;}})()){document.addEventListener('DOMContentLoaded',_N,false)}else{document.attachEvent('onreadystatechange',_N)}

可以看到,有一些环境检测:window.addEventListener,document.addEventListener,本地单步调试后发现,卡在document.addEventListener('DOMContentLoaded',_N,false)这一行`,可以百度查询其含义,表示文档完成初始的加载和解析之后执行_N函数。
补充对应环境后运行:

setTimeout = function (){}
window = {}
document = {}
window.addEventListener = '1'
document.addEventListener = function (a, b, c) {
    return b()
}
// js 代码

发现还是会卡住,继续调试_N函数:

debugger;
document.cookie = '__jsl_clearance=1714140907.524|0|' + (function() {
        var _t = [function(_N) {
            return _N
        }
        , function(_t) {
            return _t
        }
        , (function() {
            var _N = document.createElement('div');
            _N.innerHTML = '<a href=\' /\'>_1H</a>';
            _N = _N.firstChild.href;
            var _t = _N.match(/https?:\/\//)[0];
            _N = _N.substr(_t.length).toLowerCase();
            return function(_t) {
                for (var _1H = 0; _1H < _t.length; _1H++) {
                    _t[_1H] = _N.charAt(_t[_1H])
                }
                ;return _t.join('')
            }
        }
        )(), function(_N) {
            for (var _t = 0; _t < _N.length; _t++) {
                _N[_t] = parseInt(_N[_t]).toString(36)
            }
            ;return _N.join('')
        }
        ]
          , _N = ['clD', [(-~~~{} << -~~~{}) + (-~~~{} << -~~~{})], 'V', [(-~[] + [] + [[]][0]) + [-~-~{}]], 'fq', [(-~[] + [] + [[]][0]) + [-~[] - ~[] - ~!/!/ + (-~[] - ~[]) * [-~[] - ~[]]], (-~[] + [] + [[]][0]) + (-~[-~-~{}] + [[]][0]), (-~[] + [] + [[]][0]) + [(+!![[][[]]][1])]], 'LBWywKW', [(2 - ~[-~-~{}] + [] + [[]][0])], '%2FZyf', [(-~[] + [] + [[]][0]) + (-~[-~-~{}] + [[]][0])], '6', [(-~[] + [] + [[]][0]) + (-~[-~-~{}] + [[]][0])], '_fa826e49bec0d5248d34e89755520aa8', (-~[-~-~{}] + [[]][0]), 'D'];
        for (var _1H = 0; _1H < _N.length; _1H++) {
            _N[_1H] = _t[[1, 0, 1, 2, 1, 3, 1, 2, 1, 2, 1, 3, 1, 0, 1][_1H]](_N[_1H])
        }
        ;return _N.join('')
    }
    )() + ';Expires=Tue, 12-Dec-30 09:50:26 GMT;Path=/;'

document.createElement('div'); 处报错,根据上下文代码补充对应环境即可:

document = {
    'createElement': function (a) {
        if (a === 'div'){
            return {
                'firstChild': {
                    'href': "https://www.python-spider.com/"
                }
            }
        }
    }
}

再次运行,输出正确结果:

setTimeout = function (){}
window = {}
document = {
    'createElement': function (a) {
        if (a === 'div'){
            return {
                'firstChild': {
                    'href': "https://www.python-spider.com/"
                }
            }
        }
    }
}
window.addEventListener = '1'
document.addEventListener = function (a, b, c) {
    return b()
}
// 第一个11返回的 js 代码
console.log(document.cookie)


然后修改js代码,本地替换,并借用python调用即可,参考代码如下:
topic11.js

setTimeout = function () {
}
window = {};
window.addEventListener = '1';
document = {};
document.addEventListener = function (a, b, c) {
    return b()
}
document.createElement = function () {
    return {
        firstChild: {
            href: 'https://www.python-spider.com/'
        }
    }
}
// console.log(document.cookie)
__jscode

topic11.py

import execjs
import re
import requests
from lxml import etree


cookies = {
    'sessionid': 你的id
}

session = requests.Session()

response = session.get('https://www.python-spider.com/challenge/11', cookies=cookies)
with open('topic11.js', 'r', encoding='utf-8') as f:
    jscode = f.read().replace('__jscode', re.search('<script>(.*)</script>', response.text).group(1))

ctx = execjs.compile(jscode)
document_cookie = ctx.eval('document.cookie')
__jsl_clearance = re.search('__jsl_clearance=(.*?);', document_cookie).group(1)
cookies['__jsl_clearance'] = __jsl_clearance

response = session.get('https://www.python-spider.com/challenge/11', cookies=cookies)
print(response.text)
html = etree.HTML(response.text)
datas = html.xpath("//div['page-box layui-row']//td/text()")
print(datas)

total_num = 0
for data in datas:
    total_num += int(data.replace(' ', ''))
print(total_num)
posted @ 2024-04-26 23:06  脱下长日的假面  阅读(29)  评论(0编辑  收藏  举报