【JS逆向系列】某船舶物资采购平台动态cookie

176 阅读1分钟

前言

目标网站:aHR0cDovL3RkLmVidXkuY3NlbWMuY29tL2V4cC9xdWVyeWJ1c2luZXNzL2NvbW1vbi94amdnSW5mby5kbz9mcGhtPVhKMDIxMDQyMzAwMTE5


一、页面分析

先把cookie清楚,然后重新加载页面,可以看到经过了两次访问,第一次访问是生产cookie,然后第二次携带cookie访问 在这里插入图片描述 cookie值就是这个_ydclearance 在这里插入图片描述

二、获取cookie

我们不携带cookie,给他发个请求,返回这个么东西 在这里插入图片描述 那么这个方法就是生产cookie的方法了 在这里插入图片描述

我们吧最后的eval,注释掉,直接输出po看看,就可以的到cookie的值,以及跳转的连接 在这里插入图片描述


三、模拟请求

根据正则匹配相关参数,实现自己获取cookie的方法 在这里插入图片描述

import re

import requests,execjs

headers = {
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-cache',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Referer': 'http://td.ebuy.csemc.com/exp/querybusiness/common/xjggInfo.do?fphm=XJ021041200316',
    'Accept-Language': 'zh-CN,zh;q=0.9',
}


txt = requests.get('http://td.ebuy.csemc.com/exp/querybusiness/common/xjggInfo.do?fphm=XJ021042300119', headers=headers, verify=False).text
js_function = re.findall('; (.*?) </script>',txt)[0]
js_function = js_function.replace('eval("qo=eval;qo(po);");','return po;')
func_call = re.findall('window.onload=setTimeout("(.*?)", 200',txt)[0]
js_function += ';function get_cookie(){ return '+func_call+';}'
print('正则匹配后的JS',js_function)
js_func = execjs.compile(js_function)
cookies = js_func.call('get_cookie')
print(cookies)
_ydclearance = re.findall('_ydclearance=(.*?);',cookies)[0]
location = 'http://td.ebuy.csemc.com'+re.findall("location='(.*?)'",cookies)[0]

print('生产的cookie:',_ydclearance)
print('跳转链接',location)

res = requests.get(location, headers=headers,cookies={'_ydclearance':_ydclearance}, verify=False).text
print(res)