zl程序教程

您现在的位置是:首页 >  Javascript

当前栏目

js逆向-猿人学(12-13)简易Js

2023-03-15 22:04:27 时间

猿人学爬虫比赛第十二题

地址: http://match.yuanrenxue.com/match/12

后面的题其实不想看了,索然无味。码字花的时间比看题的时间要久。

开无痕窗口,打开控制台,访问链接,分析数据包发现有一个m参数。

通过堆栈进入断点。

m= btoa(‘yuanrenxue’ + window.page) window.page 是当前页码 btoa() 是一个nativa方法,用于创建一个 base-64 编码的字符串。

用python生成:

import base64
for page in range(1,6):
    kw = f"yuanrenxue{page}"
    result = base64.b64encode(kw.encode("utf-8"))
    print(result)

猿人学爬虫比赛第十三题

地址: http://match.yuanrenxue.com/match/13

开无痕窗口,打开控制台,访问链接,分析数据包发现cookie有两个参数

一个sessionid是服务端set进去的,另一个yuanrenxue_cookie可能是本地生成的。

通过程序访问了下,sessionid可以通过response的headers获取

import requests
res = requests.get('http://match.yuanrenxue.com/match/13')
print(res.headers['Set-Cookie'])

接着就看一下yuanrenxue_cookie

为了方便点,直接使用扩展程序来找参数,

var code = function(){
    var org = document.cookie.__lookupSetter__('cookie');
    document.__defineSetter__("cookie",function(cookie){
        if(cookie.indexOf('yuanrenxue_cookie')>-1){
            debugger;
        }
        org = cookie;
    });
    document.__defineGetter__("cookie",function(){return org;});
}
var script = document.createElement('script');
script.textContent = '(' + code + ')()';
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);

先在控制台把已经有的cookie清空

再刷新页面,断点已经拦到参数

F11继续往下走,

到这之后发现走不下去了。但是并没有找到关键点,于是改用全局搜索搜关键词,还是没有搜到。

那么问题就在第一次set-cookie时的响应内容了,用程序打印出 response.text之后,输出的script和我们刚看到的一样。

<script>document.cookie=('y')+('u')+('a')+('n')+('r')+('e')+('n')+('x')+('u')+('e')+('_')+('c')+('o')+('o')+('k')+('i')+('e')+('=')+('1')+('6')+('1')+('1')+('7')+('3')+('6')+('2')+('5')+('6')+('|')+('N')+('b')+('g')+('U')+('F')+('L')+('z')+('a')+('k')+('3')+('n')+('x')+('o')+('h')+('x')+('u')+('d')+('B')+('I')+('T')+('5')+('J')+('X')+('E')+('Y')+('T')+('i')+('c')+('q')+('7')+('c')+('F')+('E')+('O')+('F')+('z')+('A')+('B')+('R')+('U')+('a')+('9')+('h')+('9')+('M')+('2')+('p')+('F')+('l')+('T')+('f')+('S')+('l')+('5')+('s')+('Q')+('e')+('D')+('S')+('Y')+('y')+('h')+('B')+('h')+('Q')+('Z')+('s')+('c')+('I')+('t')+('j')+('0')+('V')+('F')+('M')+('8')+('m')+('O')+('y')+('o')+('5')+('1')+('0')+('Z')+('4')+('Q')+('0')+('Q')+('d')+('X')+('2')+('D')+';path=/';location.href=location.pathname+location.searchscript>

所以在 res.headers[‘Set-Cookie’] 中获得 sessionid ,res.text中可生成 yuanrenxue_cookie。

import requests
res = requests.get('http://match.yuanrenxue.com/match/13')
print(res.text)	
print(res.headers['Set-Cookie'])

节省时间,讲解到这里吧,具体就不多写了。