新版知乎x-zse-86加密破解分析

知乎x-zse-86加密破解

新版知乎加密破解仅用于研究和学习使用

新版本知乎使用headers中的x-zse-86进行校验

URL :https://www.zhihu.com/api/v4/search_v3?t=general&q=怀孕失眠&correction=1&offset=0&limit=20&lc_idx=0&show_all_topics=0
这是搜索接口链接

我们来看一下Request Headers都有什么信息

我们可以看到很乱, 但是这里边的信息不是全部都有用,下面我来测试下那些有用哪写没有用
新版知乎x-zse-86加密破解分析_第1张图片
经过测试我们发先实际上有的信息就这么几个,看起来清晰多了。下面来这翻页测试看看哪些信息是变化的, 我们发现只有x-zse-86的信息是有变化的, 所以我们找到s-zse-86的生成方式就行了

全局搜索x-zse-86
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200723200804547.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDM1MjcxNQ==,size_16,color_FFFFFF,t_70

全局搜索x-zse-86
新版知乎x-zse-86加密破解分析_第2张图片
可以明显的看出x-zse-86是由Z和p做的字符串拼接,Z是写死的常量1.0, 所有p就是我们想要的,向上找可以发现p = f.signture,我们来找一下f.signture是什么
通过打点调试
新版知乎x-zse-86加密破解分析_第3张图片
我们找到signture = Y()(z()(f))

首先对这个Y()(z()(f))进行拆解 先看下找到参数f 可以看到方框上边的这行就是f的生成方式

f = [r, u, l, o, $(d) && d, i].filter(Boolean).join("+");

对这行进行打点调试可以知道r,u,l,o,d,i都是什么 然后通过join对列表进行字符串拼接使用+
结果:

"3_2.0+/api/v4/search_v3?t=general&q=%E6%80%80%E5%AD%95%E5%A4%B1%E7%9C%A0&correction=1&offset=0&limit=20&lc_idx=0&show_all_topics=0+https://www.zhihu.com/search?type=content&q=%E6%80%80%E5%AD%95%E5%A4%B1%E7%9C%A0+"AACSLMY7lBGPTo9fXdy2pmiGQ4ZVVUcqzC4=|1594785557""

其实就是请求头里的x-zse-83+url+referer+“cookie.d_c0”

然后来看z()(f), 通过断点调试出来的是个32位字符串,首先我们想到的就是md5

新版知乎x-zse-86加密破解分析_第4张图片
在这里插入图片描述
我们在console里测试下,发现这个z()就是做了一个md5的操作
最后一步是Y()的这个方法
在这里插入图片描述
在这里插入图片描述
可以看到Y这调用的是__g.encrypy(encodeURICOmponent®) 在console中点击是可以直接挑过去的
新版知乎x-zse-86加密破解分析_第5张图片
这的还js比较多无法通过猜来破解了, 所以直接把这块的js copy出来做一些修改直接通过execjs模块来调用, 这个封装的代码我就不自己写了,网上挺多的我直接找了一个略作修改,
如下:

创建一个g_encrypt.js的文件代码如下

const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`

Hello world

`
); window = dom.window; document = window.document; XMLHttpRequest = window.XMLHttpRequest; var exports = {} function t(e) { return (t = "function" == typeof Symbol && "symbol" == typeof Symbol.A ? function(e) { return typeof e } : function(e) { return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e } )(e) } Object.defineProperty(exports, "__esModule", { value: !0 }); var A = "2.0" , __g = {}; function s() {} function i(e) { this.t = (2048 & e) >> 11, this.s = (1536 & e) >> 9, this.i = 511 & e, this.h = 511 & e } function h(e) { this.s = (3072 & e) >> 10, this.h = 1023 & e } function a(e) { this.a = (3072 & e) >> 10, this.c = (768 & e) >> 8, this.n = (192 & e) >> 6, this.t = 63 & e } function c(e) { this.s = e >> 10 & 3, this.i = 1023 & e } function n() {} function e(e) { this.a = (3072 & e) >> 10, this.c = (768 & e) >> 8, this.n = (192 & e) >> 6, this.t = 63 & e } function o(e) { this.h = (4095 & e) >> 2, this.t = 3 & e } function r(e) { this.s = e >> 10 & 3, this.i = e >> 2 & 255, this.t = 3 & e } s.prototype.e = function(e) { e.o = !1 } , i.prototype.e = function(e) { switch (this.t) { case 0: e.r[this.s] = this.i; break; case 1: e.r[this.s] = e.k[this.h] } } , h.prototype.e = function(e) { e.k[this.h] = e.r[this.s] } , a.prototype.e = function(e) { switch (this.t) { case 0: e.r[this.a] = e.r[this.c] + e.r[this.n]; break; case 1: e.r[this.a] = e.r[this.c] - e.r[this.n]; break; case 2: e.r[this.a] = e.r[this.c] * e.r[this.n]; break; case 3: e.r[this.a] = e.r[this.c] / e.r[this.n]; break; case 4: e.r[this.a] = e.r[this.c] % e.r[this.n]; break; case 5: e.r[this.a] = e.r[this.c] == e.r[this.n]; break; case 6: e.r[this.a] = e.r[this.c] >= e.r[this.n]; break; case 7: e.r[this.a] = e.r[this.c] || e.r[this.n]; break; case 8: e.r[this.a] = e.r[this.c] && e.r[this.n]; break; case 9: e.r[this.a] = e.r[this.c] !== e.r[this.n]; break; case 10: e.r[this.a] = t(e.r[this.c]); break; case 11: e.r[this.a] = e.r[this.c]in e.r[this.n]; break; case 12: e.r[this.a] = e.r[this.c] > e.r[this.n]; break; case 13: e.r[this.a] = -e.r[this.c]; break; case 14: e.r[this.a] = e.r[this.c] < e.r[this.n]; break; case 15: e.r[this.a] = e.r[this.c] & e.r[this.n]; break; case 16: e.r[this.a] = e.r[this.c] ^ e.r[this.n]; break; case 17: e.r[this.a] = e.r[this.c] << e.r[this.n]; break; case 18: e.r[this.a] = e.r[this.c] >>> e.r[this.n]; break; case 19: e.r[this.a] = e.r[this.c] | e.r[this.n]; break; case 20: e.r[this.a] = !e.r[this.c] } } , c.prototype.e = function(e) { e.Q.push(e.C), e.B.push(e.k), e.C = e.r[this.s], e.k = []; for (var t = 0; t < this.i; t++) e.k.unshift(e.f.pop()); e.g.push(e.f), e.f = [] } , n.prototype.e = function(e) { e.C = e.Q.pop(), e.k = e.B.pop(), e.f = e.g.pop() } , e.prototype.e = function(e) { switch (this.t) { case 0: e.u = e.r[this.a] >= e.r[this.c]; break; case 1: e.u = e.r[this.a] <= e.r[this.c]; break; case 2: e.u = e.r[this.a] > e.r[this.c]; break; case 3: e.u = e.r[this.a] < e.r[this.c]; break; case 4: e.u = e.r[this.a] == e.r[this.c]; break; case 5: e.u = e.r[this.a] != e.r[this.c]; break; case 6: e.u = e.r[this.a]; break; case 7: e.u = !e.r[this.a] } } , o.prototype.e = function(e) { switch (this.t) { case 0: e.C = this.h; break; case 1: e.u && (e.C = this.h); break; case 2: e.u || (e.C = this.h); break; case 3: e.C = this.h, e.w = null } e.u = !1 } , r.prototype.e = function(e) { switch (this.t) { case 0: for (var t = [], n = 0; n < this.i; n++) t.unshift(e.f.pop()); e.r[3] = e.r[this.s](t[0], t[1]); break; case 1: for (var r = e.f.pop(), o = [], i = 0; i < this.i; i++) o.unshift(e.f.pop()); e.r[3] = e.r[this.s][r](o[0], o[1]); break; case 2: for (var a = [], c = 0; c < this.i; c++) a.unshift(e.f.pop()); e.r[3] = new e.r[this.s](a[0],a[1]) } } ; var k = function(e) { for (var t = 66, n = [], r = 0; r < e.length; r++) { var o = 24 ^ e.charCodeAt(r) ^ t; n.push(String.fromCharCode(o)), t = o } return n.join("") }; function Q(e) { this.t = (4095 & e) >> 10, this.s = (1023 & e) >> 8, this.i = 1023 & e, this.h = 63 & e } function C(e) { this.t = (4095 & e) >> 10, this.a = (1023 & e) >> 8, this.c = (255 & e) >> 6 } function B(e) { this.s = (3072 & e) >> 10, this.h = 1023 & e } function f(e) { this.h = 4095 & e } function g(e) { this.s = (3072 & e) >> 10 } function u(e) { this.h = 4095 & e } function w(e) { this.t = (3840 & e) >> 8, this.s = (192 & e) >> 6, this.i = 63 & e } function G() { this.r = [0, 0, 0, 0], this.C = 0, this.Q = [], this.k = [], this.B = [], this.f = [], this.g = [], this.u = !1, this.G = [], this.b = [], this.o = !1, this.w = null, this.U = null, this.F = [], this.R = 0, this.J = { 0: s, 1: i, 2: h, 3: a, 4: c, 5: n, 6: e, 7: o, 8: r, 9: Q, 10: C, 11: B, 12: f, 13: g, 14: u, 15: w } } Q.prototype.e = function(e) { switch (this.t) { case 0: e.f.push(e.r[this.s]); break; case 1: e.f.push(this.i); break; case 2: e.f.push(e.k[this.h]); break; case 3: e.f.push(k(e.b[this.h])) } } , C.prototype.e = function(A) { switch (this.t) { case 0: var t = A.f.pop(); A.r[this.a] = A.r[this.c][t]; break; case 1: var s = A.f.pop() , i = A.f.pop(); A.r[this.c][s] = i; break; case 2: var h = A.f.pop(); A.r[this.a] = eval(h) } } , B.prototype.e = function(e) { e.r[this.s] = k(e.b[this.h]) } , f.prototype.e = function(e) { e.w = this.h } , g.prototype.e = function(e) { throw e.r[this.s] } , u.prototype.e = function(e) { var t = this , n = [0]; e.k.forEach(function(e) { n.push(e) }); var r = function(r) { var o = new G; return o.k = n, o.k[0] = r, o.v(e.G, t.h, e.b, e.F), o.r[3] }; r.toString = function() { return "() { [native code] }" } , e.r[3] = r } , w.prototype.e = function(e) { switch (this.t) { case 0: for (var t = {}, n = 0; n < this.i; n++) { var r = e.f.pop(); t[e.f.pop()] = r } e.r[this.s] = t; break; case 1: for (var o = [], i = 0; i < this.i; i++) o.unshift(e.f.pop()); e.r[this.s] = o } } , G.prototype.D = function(e) { console.log(window.atob(e)); for (var t = window.atob(e), n = t.charCodeAt(0) << 8 | t.charCodeAt(1), r = [], o = 2; o < n + 2; o += 2) r.push(t.charCodeAt(o) << 8 | t.charCodeAt(o + 1)); this.G = r; for (var i = [], a = n + 2; a < t.length; ) { var c = t.charCodeAt(a) << 8 | t.charCodeAt(a + 1) , s = t.slice(a + 2, a + 2 + c); i.push(s), a += c + 2 } this.b = i } , G.prototype.v = function(e, t, n) { for (t = t || 0, n = n || [], this.C = t, "string" == typeof e ? this.D(e) : (this.G = e, this.b = n), this.o = !0, this.R = Date.now(); this.o; ) { var r = this.G[this.C++]; if ("number" != typeof r) break; var o = Date.now(); if (500 < o - this.R) return; this.R = o; try { this.e(r) } catch (e) { this.U = e, this.w && (this.C = this.w) } } } , G.prototype.e = function(e) { var t = (61440 & e) >> 12; new this.J[t](e).e(this) } , (new G).v("AxjgB5MAnACoAJwBpAAAABAAIAKcAqgAMAq0AzRJZAZwUpwCqACQACACGAKcBKAAIAOcBagAIAQYAjAUGgKcBqFAuAc5hTSHZAZwqrAIGgA0Q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PKToKDgAHMx8SGQUvMQABSAALORoVGCQgERcCAxoACAU3ABEXAgMaAAsFGDcAERcCAxoUCgABSQAGOA8LGBsPAAYYLwsYGw8AAU4ABD8QHAUAAU8ABSkbCQ4BAAFMAAktCh8eDgMHCw8AAU0ADT4TGjQsGQMaFA0FHhkAFz4TGjQsGQMaFA0FHhk1NBkCHgUbGBEPAAFCABg9GgkjIAEmOgUHDQ8eFSU5DggJAwEcAwUAAUMAAUAAAUEADQEtFw0FBwtdWxQTGSAACBwrAxUPBR4ZAAkqGgUDAwMVEQ0ACC4DJD8eAx8RAAQ5GhUYAAFGAAAABjYRExELBAACWhgAAVoAQAg/PTw0NxcQPCQ5C3JZEBs9fkcnDRcUAXZia0Q4EhQgXHojMBY3MWVCNT0uDhMXcGQ7AUFPHigkQUwQFkhaAkEACjkTEQspNBMZPC0ABjkTEQsrLQ=="); function b(e) { console.log(e); console.log(encodeURIComponent(e)); return __g._encrypt(encodeURIComponent(e)) };

测试zhihu_test.py 代码如下
需要安装jsdom, npm i jsdom -g 在调用的时候写路径不然会有问题

import requests
import execjs
import hashlib

url = "/api/v4/search_v3?t=general&q=%E6%80%80%E5%AD%95%E5%A4%B1%E7%9C%A0&correction=1&offset=0&limit=20&lc_idx=0&show_all_topics=0"

referer = "https://www.zhihu.com/search?type=content&q=%E6%80%80%E5%AD%95%E5%A4%B1%E7%9C%A0"

f = "+".join(["3_2.0", url, referer, '"AACSLMY7lBGPTo9fXdy2pmiGQ4ZVVUcqzC4=|1594785557"'])

fmd5 = hashlib.new('md5', f.encode()).hexdigest()

with open('g_encrypt.js', 'r') as f:
    ctx1 = execjs.compile(f.read(), cwd=r'/usr/local/lib/node_modules')
encrypt_str = ctx1.call('b', fmd5)

headers = {
    "referer": referer,
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36",
    "cookie": 'd_c0="AACSLMY7lBGPTo9fXdy2pmiGQ4ZVVUcqzC4=|1594785557";',
    "x-api-version": "3.0.91",
    "x-zse-83": "3_2.0",
    "x-zse-86": "1.0_%s" % encrypt_str,
}
print(headers)
r = requests.get("https://www.zhihu.com" + url, headers=headers)
print(r.text)

结果:
在这里插入图片描述








坐得住板凳,耐得住寂寞,守得住初心!

你可能感兴趣的:(Python爬虫,python)