JS破解&&Android逆向

Python爬虫进阶之APP逆向(三)

2019-06-01  本文已影响33人  GoPython

最近有朋友在做新闻资讯类的 app 爬虫,也许大多数人都会认为,一个新闻资讯 app 不会有什么反爬吧。

恰恰相反,当你想爬一条新闻的时候都有请求参数加密,可见现在反爬的严重性。

分析

国际惯例先抓包,万幸抓包非常顺利,抓包结果如下:

image

<figcaption style="margin: 10px 0px 0px; padding: 0px; line-height: inherit; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">抓包结果</figcaption>

可以看到请求头里面有加密的参数,下面我们通过反编译来破解这个参数

同时用 Python 代码来实现加密,这样我们才能愉快的爬爬爬!

反编译破解

反编译之后我们就根据请求参数来寻找加密的源码,同时需要注意下搜索的技巧。比如同一个参数,如果加上引号会极大的减少我们的工作量。

image

<figcaption style="margin: 10px 0px 0px; padding: 0px; line-height: inherit; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">未加引号</figcaption>

<figcaption style="margin: 10px 0px 0px; padding: 0px; line-height: inherit; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">
</figcaption>

image

<figcaption style="margin: 10px 0px 0px; padding: 0px; line-height: inherit; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">加引号</figcaption>

可以看到同样一个参数,按后面的搜索结果来找加密源码,会大大减少我们的工作量。

最后在第三行找到了加密参数的出处!

image

<figcaption style="margin: 10px 0px 0px; padding: 0px; line-height: inherit; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">signature加密</figcaption>

其中在执行某某函数的地方可以点进去,结果如下:

image

<figcaption style="margin: 10px 0px 0px; padding: 0px; line-height: inherit; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">md5</figcaption>

md5 应该熟悉吧,剩下就是找出被加密的数据了。返回去再看,是三个数据组合的 md5!

image

<figcaption style="margin: 10px 0px 0px; padding: 0px; line-height: inherit; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">udid</figcaption>

粗略看一下这个参数是设备号,不做校验,我们可以直接取其默认值
IMEINNNNNNNNNNNNNNN-IMSI460NNNNNNNNNNNN

再加上时间戳,和一个 key。刚好和我们抓包里面的请求头那几个参数对应上

分析完之后,当然是先用代码验证一下,如果有问题再返回回来细看。

验证

下面是构造加密参数 signature 的算法

1encrypt = f"{uuid}&&{timestamp}&&f1190aca-d08e-4041-8666-29931cd89dde"

其中 udid 是手机设备号和随机数按特定的方式的组合,timestamp 是时间戳。

1signature = hashlib.md5(encrypt.encode("utf-8")).hexdigest()

上面就是 signature 的加密 。我们用代码请求一下来验证结果。

image

<figcaption style="margin: 10px 0px 0px; padding: 0px; line-height: inherit; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">结果</figcaption>

能 GET 到数据,说明用 Python 转换后的加密算法是对的!

推荐阅读

Python爬虫之JS逆向入门篇

用python一键生成你的微信好友头像墙

pyecharts可视化和微信的结合

python数据可视化神器--pyecharts 快速入门

上一篇 下一篇

猜你喜欢

热点阅读