猿人学第四题-CSS加密【雪碧图、样式干扰】

练习链接:http://match.yuanrenxue.com/match/4
学习链接:
https://bbs.tampermonkey.net.cn/thread-203-1-2.html
http://www.qishunwang.net/news_show_7882.aspx

猿人学第四题-CSS加密【雪碧图、样式干扰】_第1张图片

04.js文件:

猿人学第四题-CSS加密【雪碧图、样式干扰】_第2张图片

04.py文件

import execjs
import os,json,time,re
from requests_html import HTMLSession,HTML
session = HTMLSession()

# 获取最后的30个字符
num_dict = {
     
    "H/AOyW6SvqnweCAAAAAElFTkSuQmCC":0,
    "kYAKYHOb9g+7HMAAAAAElFTkSuQmCC":1,
    "8BJlTqZkAngxQAAAAASUVORK5CYII=":2,
    "D/AbAv8WdRHzjKAAAAAElFTkSuQmCC":3,
    "UL4d3X/AgqvQAAAABJRU5ErkJggg==":4,
    "B/3J2gmVZucHAAAAAASUVORK5CYII=":5,
    "gL80YzEyuMQpQAAAAASUVORK5CYII=":6,
    "LwC1sVsHrJiVs0AAAAAElFTkSuQmCC":7,
    "L8BvLZG6cpuRANAAAAAElFTkSuQmCC":8,
    "4ApbEnkB6qHqsAAAAASUVORK5CYII=":9,
}
headers = {
     
    'Host': 'match.yuanrenxue.com',
    'user-agent':'yuanrenxue.project',
    'Referer': 'http://match.yuanrenxue.com/match/4',
}
def parse(source, j_key):
    info = []
    html = HTML(html=source)
    for td in html.find('td'):
        # 1.获取数字和数字偏移值
        num_list = []
        for img in td.find('img'):
            mi_class, mi_style, mi_src = img.attrs['class'], img.attrs['style'], img.attrs['src']
            if j_key not in mi_class:
                left = float(re.findall(":(.*?)px",mi_style,re.S)[0]) / 11.5
                num_list.append((num_dict[mi_src[-30:]], int(left)))
        # 坐标偏移操作
        i = 0
        new_num_list = ['', '', '', '', '']
        for num, off in num_list:
            new_num_list[off + i] = str(num)
            i += 1
        info.append(int(''.join(new_num_list)))
    print(f"\n\n数据:{info} \t总和为:{sum(info)}")
    return info
    

def main():
    """
    key:WFKftevolz 
    value:ebglsfv3Wd 
    j_key:5011e193df5414ac8e1caada63eac9ea 
    datas:
    """
    with open(r'./04.js', encoding='utf-8', mode='r') as f:
        infos = []
        JsData = f.read()
        for page in range(1,6):
            url = f"http://match.yuanrenxue.com/api/match/4?page={page}"
            data = session.get(url, headers=headers).json()
            source, key, value = data['info'], data['key'], data['value']
            # 获取加密的隐藏值`j_key`
            j_key = execjs.compile(JsData).call('run_key', key, value)
            # 解析加密的HTML文档内容
            info = parse(source, j_key)
            infos.extend(info)
            # 获取解密的HTML文档内容
            datas = execjs.compile(JsData).call('run_html', source, key, value)
            print(f"key:{key}\nvalue:{value}\nj_key:{j_key}\n解密的HTML文档内容:{datas}")
        print("\n\n这5页的全部数字,计算加和:",sum(infos))
main()

欢迎关注,谢谢哟

猿人学第四题-CSS加密【雪碧图、样式干扰】_第3张图片

你可能感兴趣的:(JS逆向)