今天给你分享一下篇反反爬的实例。
一个思路,也许给你带来些许启发..
也许你会遇到这样的请款:
打开某个网站,可以看到页面是正常显示的,但是当你通过 Python
去请求的时候,你会得到一堆无厘头的 JS..
像这样的操作,应该怎么玩呢?接下来由【小帅b的朋友:lin】给大家演示一下。
当你使用 requests 请求的时候,得到的是这样的:

这时候就要看看是不是用啥了,是不是协议头问题呢?

通过不断的测试 最终确定是 cookie 中 acw_sc__v2 的问题。
那不就好办了 我们使用一个hook:
1 | (function () { |
这段hook有俩种使用方式:一是油猴、二是fd插件。看各位的喜好啦!
打上 hook,打开 F12 调试器,刷新网页,先是遇到了无限debugger:

常规的做法是在 debugger 一行左边右键选择 never pause here:

接着F8放行断点就行了
如果没有断下来 先清除cookie在刷新网页:

很快就能看到cookie被hook下来了
接着在 call stack 往上找:

到 reload 这里看到 x 是我们需要的值,然后再往上堆栈就进入了虚拟机:

通过观察原来是在settimeout里面做了操作:

所以我们所需要分析的逻辑就变为了:
var _0x23a392 = arg1
_0x55f3(‘0x19’, ‘\x50\x67\x35\x34’);
arg2 = _0x23a392
_0x55f3(‘0x1b’, ‘\x7a\x35\x4f\x26’);
不懂的人会看不懂这种混淆代码,其实这是一种ob混淆,可以看到很多函数名变量名基本被混淆了的。
但是不用慌 我们可以通过 AST 的方法或者硬刚的方法来解决:

可以看到只需要把解密函数的代码圈起来就能拿到解密后的值,我们就可以按照这个来分析改写了。
这里使用了arg1:

arg1就在页面上层能找到:

然后整个圈起来:

扣和改就行了 工作量不会很大:

还原改写后运行试试看,会看到报一个错,缺少提示的变量,那我们就去 js 里面找这个值:

找到这一段值补上即可,通过几次刷新尝试,发现这段值是固定的,所以可以写死。

补完后运行:

发现和网页计算的一模一样,那我们这个值就正确啦。

最后我们用python实现:

完美!撒花~~