知乎搜索接口解密 您所在的位置:网站首页 api接口加密破解 知乎搜索接口解密

知乎搜索接口解密

2024-06-02 06:38| 来源: 网络整理| 查看: 265

文章目录 前言传参解密分析

前言

最近接到了一个知乎搜索的采集要求,所以研究了一下知乎的搜索接口加密。

传参

在这里插入图片描述 研究了一下,只有cookie、x-zse-93和x-zse-96是必传的,93是固定值,96是用的加密的方式,话不多说,直接开始解密分析。

解密分析

全局搜索。可以发现在 在这里插入图片描述 去source里找到对应文件,打上断点,运行 在这里插入图片描述 一路点进去可以看到这个函数 在这里插入图片描述 再点进去可以看到一个G.v函数 在这里插入图片描述 基本这个就是最终加密了,使用的是将query+cookie+version拼接之后先base64转码之后再调用自己的js加密的方式,直接上代码

import execjs import sys import hashlib import urllib.parse import json import random import requests import pandas as pd from db_config import engine_zhihu from utils import iooo import time query="/api/v4/search_v3?t=general&q={}&correction=1&offset=0&limit=20&filter_fields=&lc_idx=0&show_all_topics=0&search_source=Filter&sort=created_time&time_interval=a_day" cookie_format="\"AgBQb9bVUBSPTvIsEEM6EqLhxleZUfM2F3o=|164180{}{}{}{}\"" version="101_3_2.0" with open("g_encrypt.js", 'r', encoding='utf-8') as f: # ctx1 = execjs.compile(f.read()) ctx1 = execjs.compile(f.read(), cwd="node_modules") if __name__ == '__main__': while True: try: sql_keyword="select keyword from ety_zhihu_keyword where status=0" for keyword in pd.read_sql(sql_keyword,engine_zhihu())['keyword']: keyword=urllib.parse.quote(keyword) query_now = query.format(keyword) url = "https://www.zhihu.com" + query_now cookie_now = cookie_format.format(random.randint(1, 9), random.randint(1, 9), random.randint(1, 9), random.randint(1, 9)) payload = {} str = version + "+" + query_now + "+" + cookie_now hl = hashlib.md5() hl.update(str.encode(encoding='utf-8')) fmd5 = hl.hexdigest() encrpt_str = ctx1.call('b', fmd5) headers = { 'cookie': 'd_c0={}; '.format(cookie_now), 'x-zse-93': version, 'x-zse-96': '2.0_{}'.format(encrpt_str), 'User-Agent': 'PostmanRuntime/7.28.4' } r = requests.request("GET", url, headers=headers, data=payload) r.encoding = 'utf-8' html = r.text resp = json.loads(html) list_data=[] for dict_data in resp['data']: if dict_data['type']=='relevant_query': continue data={} try: data['summary']=dict_data['highlight']['description'] except Exception: data['summary']=None data['title']=dict_data['highlight']['title'] try: data['content']=dict_data['object']['content'] except Exception: data['content']=None try: data['url']=dict_data['object']['url'] except Exception: data['url']=dict_data['object']['video_url'] try: timeArray = time.localtime(dict_data['object']['updated_time']) except Exception: timeArray = time.localtime(dict_data['object']['created_at']) data['publish_time'] =time.strftime( "%Y-%m-%d %H:%M:%S" , timeArray) try: data['author_name']=dict_data['object']['author']['name'] except Exception: data['author_name']=None list_data.append(data) insert_df=pd.DataFrame(list_data) iooo.to_sql("ety_zhihu_article",engine_zhihu(),insert_df) time.sleep(60*60*4-120) except Exception as e: print(e) time.sleep(60*5) continue

g_encrpt.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 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 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 3: e.u = e.r[this.a] 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 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 console.log(window.atob(e)); for (var t = window.atob(e), n = t.charCodeAt(0) 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 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("AxjgB5MAnACoAJwBpAAAABAAIAKcAqgAMAq0AzRJZAZwUpwCqACQACACGAKcBKAAIAOcBagAIAQYAjAUGgKcBqFAuAc5hTSHZAZwqrAIGgA0QJEAJAAYAzAUGgOcCaFANRQ0R2QGcOKwChoANECRACQAsAuQABgDnAmgAJwMgAGcDYwFEAAzBmAGcSqwDhoANECRACQAGAKcD6AAGgKcEKFANEcYApwRoAAxB2AGcXKwEhoANECRACQAGAKcE6AAGgKcFKFANEdkBnGqsBUaADRAkQAkABgCnBagAGAGcdKwFxoANECRACQAGAKcGKAAYAZx+rAZGgA0QJEAJAAYA5waoABgBnIisBsaADRAkQAkABgCnBygABoCnB2hQDRHZAZyWrAeGgA0QJEAJAAYBJwfoAAwFGAGcoawIBoANECRACQAGAOQALAJkAAYBJwfgAlsBnK+sCEaADRAkQAkABgDkACwGpAAGAScH4AJbAZy9rAiGgA0QJEAJACwI5AAGAScH6AAkACcJKgAnCWgAJwmoACcJ4AFnA2MBRAAMw5gBnNasCgaADRAkQAkABgBEio0R5EAJAGwKSAFGACcKqAAEgM0RCQGGAYSATRFZAZzshgAtCs0QCQAGAYSAjRFZAZz1hgAtCw0QCQAEAAgB7AtIAgYAJwqoAASATRBJAkYCRIANEZkBnYqEAgaBxQBOYAoBxQEOYQ0giQKGAmQABgAnC6ABRgBGgo0UhD/MQ8zECALEAgaBxQBOYAoBxQEOYQ0gpEAJAoYARoKNFIQ/zEPkAAgChgLGgkUATmBkgAaAJwuhAUaCjdQFAg5kTSTJAsQCBoHFAE5gCgHFAQ5hDSCkQAkChgBGgo0UhD/MQ+QACAKGAsaCRQCOYGSABoAnC6EBRoKN1AUEDmRNJMkCxgFGgsUPzmPkgAaCJwvhAU0wCQFGAUaCxQGOZISPzZPkQAaCJwvhAU0wCQFGAUaCxQMOZISPzZPkQAaCJwvhAU0wCQFGAUaCxQSOZISPzZPkQAaCJwvhAU0wCQFGAkSAzRBJAlz/B4FUAAAAwUYIAAIBSITFQkTERwABi0GHxITAAAJLwMSGRsXHxMZAAk0Fw8HFh4NAwUABhU1EBceDwAENBcUEAAGNBkTGRcBAAFKAAkvHg4PKz4aEwIAAUsACDIVHB0QEQ4YAAsuAzs7AAoPKToKDgAHMx8SGQUvMQABSAALORoVGCQgERcCAxoACAU3ABEXAgMaAAsFGDcAERcCAxoUCgABSQAGOA8LGBsPAAYYLwsYGw8AAU4ABD8QHAUAAU8ABSkbCQ4BAAFMAAktCh8eDgMHCw8AAU0ADT4TGjQsGQMaFA0FHhkAFz4TGjQsGQMaFA0FHhk1NBkCHgUbGBEPAAFCABg9GgkjIAEmOgUHDQ8eFSU5DggJAwEcAwUAAUMAAUAAAUEADQEtFw0FBwtdWxQTGSAACBwrAxUPBR4ZAAkqGgUDAwMVEQ0ACC4DJD8eAx8RAAQ5GhUYAAFGAAAABjYRExELBAACWhgAAVoAQAg/PTw0NxcQPCQ5C3JZEBs9fkcnDRcUAXZia0Q4EhQgXHojMBY3MWVCNT0uDhMXcGQ7AUFPHigkQUwQFkhaAkEACjkTEQspNBMZPC0ABjkTEQsrLQ=="); function b(e) { console.log(e); console.log(encodeURIComponent(e)); return __g._encrypt(encodeURIComponent(e)) };

注意一开始的

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

Hello world

`); window = dom.window; document = window.document; XMLHttpRequest = window.XMLHttpRequest;

这个需要通过nodejs安装jsdom,具体安装方法就不列在这里了 最终运行计算出的加密函数结果如下 在这里插入图片描述



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有