学习文章:
- https://blog.csdn.net/YungGuo/article/details/109818327
- https://www.cnblogs.com/re-is-good/p/mafengwo_version2_ast_cookie.html
1.请求步骤
第一次请求18252205.html:
- 1.Response Headers:
- cookie中的__jsluid_s
- 2.响应内容【是cookie中的__jsl_clearance_s】:
第二次请求18252205.html【携带第一次请求的cookie参数】:
- 响应内容【是cookie中的__jsl_clearance_s】:
第三次请求18252205.html【正确得到页面源码】:
2.对第二次请求响应,进行__jsl_clearance_s参数逆向
1.对返回的响应内容进行反混淆【工具:猿人学 - ob混淆专解测试版V0.1】
2.本地运行发现需要添加游览器的一些变量
- var window = {};
- window.navigator = {};
- window.navigator.userAgent = “你的浏览器UA地址”;
3.对js代码进行一些修改:
// setTimeout(function () {
// document["cookie"] = _0x350875["tn"] + "=" + _0x313b33[0] + ";Max-age=" + _0x350875["vt"] + "; path = /";
// location["href"] = location["pathname"] + location["search"];
// }, _0xa56d57);
// 上面注释的修改成这样就行
return _0x350875["tn"] + "=" + _0x313b33[0] + ";Max-age=" + _0x350875["vt"] + "; path = /";
4.响应内容中返回了三套js加密文件,分别为md5、sha1、sha256
# 提取js代码中的参数并转字典
parameter = json.loads(re.findall(r'};go\((.*?)\)</script>', response.text)[0])
js_file = ''
# 判断需要使用的js代码
if parameter['ha'] == 'sha1':
js_file = 'sha1.js'
elif parameter['ha'] == 'sha256':
js_file = 'sha256.js'
elif parameter['ha'] == 'md5':
js_file = 'md5.js'
import re
import json
import execjs
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 关闭ssl验证提示
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
session = requests.session()
url = "https://********/RRSdy/index.html" # 修改URL
headers = {
自己添加headers
}
def get__jsl_clearance_s_1(info):
"""
第一次获取__jsl_clearance_s
"""
info = re.findall(r".*cookie=(.*?);location.*",info)[0]
return execjs.eval(info).split(";")[0]
def get__jsl_clearance_s_2(info):
"""
第二次获取__jsl_clearance_s
"""
global session,url,headers,__jsluid_s
# 提取返回js代码中提取全部参数,并转化为字典
parameters = json.loads(re.findall(r'};go\((.*?)\)</script>', info)[0])
# 判断需要使用的js代码
if parameters['ha'] == 'sha1':
js_file = 'sha1.js'
elif parameters['ha'] == 'sha256':
js_file = 'sha256.js'
elif parameters['ha'] == 'md5':
js_file = 'md5.js'
# 读取加密js文件,执行相应的__jsl_clearance_s【cookie中的cookie】
with open(js_file,'r') as f:
cmp = execjs.compile(f.read())
__jsl_clearance_s = cmp.call('go',parameters)
headers.update({'cookie':f"{__jsluid_s}; {__jsl_clearance_s};"})
print(__jsl_clearance_s)
def get_cookie():
global session,url,headers,__jsluid_s
# 第一次请求不要传入cookie,不然浏览器不会在请求头中写入我们需要的字段
r = session.get(url, headers=headers)
__jsl_clearance_s = get__jsl_clearance_s_1(r.text)
__jsluid_s = r.headers["Set-Cookie"].split(";")[0]
headers.update({'cookie':f"{__jsluid_s}; {__jsl_clearance_s};"})
print(f"__jsluid_s: {__jsluid_s} \n__jsl_clearance_s: {__jsl_clearance_s};")
def main():
get_cookie()
r = session.get(url, headers=headers)
get__jsl_clearance_s_2(r.text)
r = session.get(url, headers=headers)
print(r.text)
if __name__ == '__main__':
main()