字体反爬篇

2021-01-22  本文已影响0人  一只酸柠檬精

一、总体思路

1、获取字体文件
2、base64解密文件分别保存为woff文件与xml文件
3、查看映射关系创建映射字典
4、通过映射字典,第二次获取响应时替换成实际数据

二、解析过程

image.png

1、获取字体文件

在开发者工具中查找"font-face",如图所示

image.png

获取到base64字符串并删除头部信息,在这里就是data:application/font-ttf;charset=utf-8;base64, 逗号也要删除,这样就获取到了字体信息,这一段密文就是加密后的字体文件

T1RUTwAJAIAAAwAQQ0ZGICGSe1oAAATUAAAEd09TLzJlNl+eAAABAAAAAGBjbWFwACoGOwAABAQAAACwaGVhZBf2b3IAAACcAAAANmhoZWEA3wBNAAAA1AAAACRobXR4B/AAAAAACUwAAAAkbWF4cAAJUAAAAAD4AAAABm5hbWUKXYQxAAABYAAAAqNwb3N0AAMAAAAABLQAAAAgAAEAAAABAACCl4DfXw889QADAQAAAAAA3DAYYwAAAADcMBhjAAf//wB4ALUAAAADAAIAAAAAAAAAAQAAAN3/xQAAAH4AAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAkAAFAAAAkAAAADAH4B9AAFAAACigK7AAAAjAKKArsAAAHfADEBAgAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAACBYWFhYAEAATgBVAN3/xQAAALUAAQAAAAEAAAAAAG8AtQAAAAAAAAAAACIBngABAAAAAAAAAAEAQgABAAAAAAABAAwAAAABAAAAAAACAAYAJAABAAAAAAADABUAxgABAAAAAAAEABMANgABAAAAAAAFAAsApQABAAAAAAAGABIAbwABAAAAAAAHAAEAQgABAAAAAAAIAAEAQgABAAAAAAAJAAEAQgABAAAAAAAKAAEAQgABAAAAAAALAAEAQgABAAAAAAAMAAEAQgABAAAAAAANAAEAQgABAAAAAAAOAAEAQgABAAAAAAAQAAwAAAABAAAAAAARAAYAJAADAAEECQAAAAIAYQADAAEECQABABgADAADAAEECQACAAwAKgADAAEECQADACoA2wADAAEECQAEACYASQADAAEECQAFABYAsAADAAEECQAGACQAgQADAAEECQAHAAI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vXDFZGLBYtWBSOLBYuSBbrCBZyfk6CLogiLiwWLoIOVeosIi4sFfIx+f39zCIuLBYSNBZSvnZ2liwiLiwWniZp7jG0Ii4sFjHmAdnRyCIuLBWRfBb+LBZaKkpWOoQiLiwUOAAQAAAAAfgAAAH4AAAB+AAAAfgAAAH4AAAB+AAAAfgAAAH4AAA==

进行base64解码(为什么是bs64呢,因为font-face中标明了是base64)并分别保存为woff文件与xml文件

 # base64解密
    font_content = base64.b64decode(base64_str)
    # TTFont打开从内存读取的二进制woff数据
    font = TTFont(io.BytesIO(font_content))
    # 将woff文件转换为xml文件
    font.save('ts.woff')
    font.saveXML('ts.xml')

使用Fontcreator打开woff文件,就可以看到字形与实际字体的对应关系,也就是映射

image.png

这就知道了结果,然后打开xml文件,通过结果查找映射关系就事半功倍了。

image.png

至于创建映射字典和替换数据都是体力活了,就不一一介绍了。

其他内容

将base64格式的字体信息解码成可用的字体文件

上一篇下一篇

猜你喜欢

热点阅读