文章声明:本篇文章内容部分选取网络,如有侵权,请告知删除。
Convert curl commands to python, javascript and more:
https://curlconverter.com/
时效性参数: boss
每次请求都是需要生成新的cookie
每次都是需要新的参数 动态参数
页面当中的 document(dom) ---> bom (window)
document['cookie'] = xxx
document.cookie = xxx
加密参数: js的某一个方法或者函数生成
get_cookie(cookie) 从服务器获取cookie
set_cookie(cookie) 生成cookie进行赋值
js逆向加密定位: 关键字搜索(不可以是很泛) 堆栈分析(请求加密过程) hook(监听dom对象当中的cookie进行set操作 debugger)
浏览器开发者工具源代码-->代码段-->+新代码段:
加入代码(自执行函数,不需要调用):
// 精准定位某一关键字
(function () {
'use strict';
var cookieTemp = '';
// 监听document cookie 执行set操作,并且有值,执行debugger
Object.defineProperty(document, 'cookie', {
set: function (val) {
if (val.indexOf('v') != -1) {
debugger;
}
// 上面,核心代码
console.log('Hook捕获到cookie设置->', val);
cookieTemp = val;
return val;
},
get: function () {
return cookieTemp;
},
});
})();
点击执行:
点击分页到第三页:
通过堆栈,向上走
走到 o,发现 v 的值变为 t :
t 值为上一个方法/函数传入的,再上走到 D:
n 变量来自 rt.update()
每次执行都是不同的值。在这里我们已经找到了我们想要的值的赋值位置。
这时候我们就不需要再向上找了,直接进入赋值位置。
进入 rt.update() 原有位置:
这是一个整体的函数:
可以直接全部复制粘贴下来:
因为 O() 函数是 D() 函数调用的,所以要找到 D(),搜索的话有很多,要一个一个判断:
在首部加上:
window = global;
这个作用域里加入
window.AAAA = D;
最后加入代码:
console.log(window.AAAA())
补好环境就可以输出值了。
为什么要补环境:
浏览器执行环境 | node 执行环境 | |
相同点 | v8 执行引擎 | v8 执行引擎 |
不同点 | bom 和 dom | nodejs api |
现在不知道代码依赖于哪些环境,需要加入环境代理检测代码:
functionget_enviroment(proxy_array) {
for(var i=0; i<proxy_array.length; i++){
handler = '{n' +
' get: function(target, property, receiver) {n' +
' console.log("方法:", "get ", "对象:", ' +
'"' + proxy_array[i] + '" ,' +
'" 属性:", property, ' +
'" 属性类型:", ' + 'typeof property, ' +
// '" 属性值:", ' + 'target[property], ' +
'" 属性值类型:", typeof target[property]);n' +
' return target[property];n' +
' },n' +
' set: function(target, property, value, receiver) {n' +
' console.log("方法:", "set ", "对象:", ' +
'"' + proxy_array[i] + '" ,' +
'" 属性:", property, ' +
'" 属性类型:", ' + 'typeof property, ' +
// '" 属性值:", ' + 'target[property], ' +
'" 属性值类型:", typeof target[property]);n' +
' return Reflect.set(...arguments);n' +
' }n' +
'}'
eval('try{n' + proxy_array[i] + ';n'
+ proxy_array[i] + '=new Proxy(' + proxy_array[i] + ', ' + handler + ')}catch (e) {n' + proxy_array[i] + '={};n'
+ proxy_array[i] + '=new Proxy(' + proxy_array[i] + ', ' + handler + ')}')
}
}
proxy_array = ['window', 'document', 'location', 'navigator', 'history','screen', 'aaa', 'target' ]
get_enviroment(proxy_array)
执行后,显示了相关信息,但有两个未定义,第二个未定义报错,在浏览器中执行:
document.getElementsByTagName
加入代码执行:
出现这个问题,就需要补一下 head 了。
刷新一下页面,全局搜索:
r[51].getElementsByTagName(p + d) ,动态 JS,需要重新使用 cookie2hook 代码,点击第三页,才能搜索到。
查看相关值
null 的都不用管,也没有特殊的参数要加进去,直接:
head = {}
执行:
都是方法:
加入代码:
getElementsByTagName:function (arg) {
console.log("对象:document======>方法:getElementsByTagName ===> 参数:", arg)
},
createElement:function (arg) {
console.log("对象:document======>方法:createElement ===> 参数:", arg)
}
缺少 onwheel ,查看下面代码所在位置:
t + X in s[66].createElement(s[171])
s[171] --> div
t + X --> "onwheel"
dir(t + X in s[66].createElement(s[171]))
加入代码:
div = {
onwheel: null
}
getElementsByTagName:function (arg) {
console.log("对象:document======>方法:getElementsByTagName ===> 参数:", arg)
},
createElement:function (arg) {
console.log("对象:document======>方法:createElement ===> 参数:", arg)
if(arg === 'div'){
return div
}
},
是个方法:
补上方法:
getElementsByTagName:function (arg) {
console.log("对象:document======>方法:getElementsByTagName ===> 参数:", arg)
},
createElement:function (arg) {
console.log("对象:document======>方法:createElement ===> 参数:", arg)
if(arg === 'div'){
return div
}
},
addEventListener:function (arg) {
console.log("对象:document======>方法:addEventListener ===> 参数:", arg)
}
在浏览器中输入回车查看,
发现有很多参数,直接右键复制,再代码中写入:plugins:" ",复制在引号中。
接着补环境:
补的是加密 cookie 环境,不需要在代码里补 cookie 的值。
最后加入代码:
console.log(window.AAAA())
运行 py 代码:
完成基础的补环境。
https://github.com/PickHeBin/Python-111
原文始发于微信公众号(安全君呀):JS逆向 | cookie加密处理
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论