-
Notifications
You must be signed in to change notification settings - Fork 16
/
app_demo.py
171 lines (147 loc) · 5.61 KB
/
app_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: jiajia
@file: demo.py
@time: 2020/7/28 16:56
"""
# __author__ = "zok" 362416272@qq.com
# Date: 2020/7/24 Python:3.7
# 找到一个大佬写的逆向app的
import requests
import time
import random
import json
import base64
import pyDes
from datetime import datetime
class TripleDesUtils:
def encryption(self, data: str, key, iv) -> str:
"""3des 加密
"""
_encryption_result = pyDes.triple_des(key, pyDes.CBC, iv, None, pyDes.PAD_PKCS5).encrypt(data)
_encryption_result = self._base64encode(_encryption_result).decode()
return _encryption_result
def decrypt(self, data: str, key, iv) -> str:
"""3des 解密
"""
data = self._base64decode(data)
_decrypt_result = pyDes.triple_des(key, pyDes.CBC, iv, None, pyDes.PAD_PKCS5).decrypt(data).decode('utf-8')
return _decrypt_result
@staticmethod
def _base64encode(data):
try:
_b64encode_result = base64.b64encode(data)
except Exception as e:
raise Exception(f"base64 encode error:{e}")
return _b64encode_result
@staticmethod
def _base64decode(data):
try:
_b64decode_result = base64.b64decode(data)
except Exception as e:
raise Exception(f"base64 decode error:{e}")
return _b64decode_result
class WenShu:
def __init__(self):
self.js = None
@staticmethod
def get_now_data():
"""时间
"""
return datetime.now().strftime('%Y%m%d')
@staticmethod
def random_key():
"""字符串
"""
random_str = ''
base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'
length = len(base_str) - 1
for i in range(24):
random_str += base_str[random.randint(0, length)]
return random_str
@staticmethod
def make_id():
"""id
"""
return datetime.now().strftime('%Y%m%d%H%M%S')
def make_cipher_text(self):
"""生成 ciphertext
"""
time_13 = str(int(round(time.time() * 1000)))
key = self.random_key()
now = self.get_now_data()
_str = des3.encryption(time_13, key, now)
_str = key + now + _str
new_str = ''
for i in _str:
if i != 1:
new_str += " "
new_str += str(bin(ord(i))[2:])
msg = """【key生成】: {key}\n【now生成】: {now}\n【_str生成】: {_str}\n【ciphertext生成】: {ciphertext}""".format(key=key,
now=now,
_str=_str,
ciphertext=new_str)
print(msg)
return new_str.strip()
def make_request(self):
"""生成明文的请求 data 内容
【这里需要根据实际需求修改请求内容】自行抓包研究!!
"""
info = {
"id": self.make_id(), # 年月日时分秒
"command": "queryDoc", # 固定
"params": {
"devid": "41d861ffe5b347d28454dc3f07dd4212", # 设备号
"devtype": "1",
"ciphertext": self.make_cipher_text(),
"pageSize": "20",
"sortFields": "s50:desc", # 固定
"pageNum": "1",
"queryCondition": [{
"key": "s8",
"value": "02"
}] # 关键词 + 搜索文本的类型;
}
}
return info
def to_index(self):
url = 'http://wenshuapp.court.gov.cn/appinterface/rest.q4w'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9; MIX 2 MIUI/V11.0.2.0.PDECNXM)',
'Host': 'wenshuapp.court.gov.cn',
'Connection': 'Keep-Alive',
'Accept-Encoding': 'gzip',
}
txt = str(self.make_request())
request = base64.b64encode(txt.encode('utf-8')).decode('utf-8')
data = {
'request': request
}
msg = """【明文请求体】: {txt}\n【密文请求体】: {data}\n【官网速度较慢,耐心等待】....""".format(txt=txt, data=data)
print(msg)
response = requests.post(url, headers=headers, data=data)
if 'HTTP Status 503' in response.text:
print('【服务器繁忙】 爬的人太多了, 请重试')
exit()
data = json.loads(response.text)
content = data.get('data').get('content')
key = data.get('data').get('secretKey')
iv = self.get_now_data()
msg = """【页面访问结果】: {text}\n【捕获key】:{key}\n【捕获iv】:{iv}\n【捕获content】:{content}""".format(text=response.text,
key=key, iv=iv,
content=content)
print(msg)
self.parse_html(content, key, iv)
def parse_html(self, content, key, iv):
_str = des3.decrypt(content, key, iv)
print("【解密返回结果】:", _str)
des3 = TripleDesUtils()
if __name__ == '__main__':
"""
《入门级安卓逆向 - 文书网app爬虫》
https://www.zhangkunzhi.com/index.php/archives/162/
"""
ws = WenShu()
ws.to_index()