微信小程序域名收集工具开发
字数 1012 2025-08-09 13:33:54
微信小程序域名收集工具开发指南
0X00 前言
微信小程序作为企业常用的服务入口,往往包含大量业务接口,是安全测试的重要目标。本工具旨在帮助安全研究人员快速收集特定微信小程序关联的域名,为后续渗透测试提供目标资产清单。
0X01 技术背景
接口演变历史
- 旧接口:
https://mp.weixin.qq.com/mp/waverifyinfo(已失效) - 新接口:
https://mp.weixin.qq.com/wxawap/waverifyinfo(当前有效)
核心原理
- 通过微信搜索API获取小程序的APPID列表
- 使用APPID查询小程序配置的合法域名
- 对结果进行过滤和整理
0X02 工具开发详解
一、环境准备
- Python 3环境
- 请求库:
requests - 微信PC客户端
- 抓包工具:Burp Suite或Fiddler
二、核心代码解析
1. 获取APPID列表
def Get_App_Id_List(query, number, cookie):
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36..."}
url = "https://mp.weixin.qq.com/wxa-cgi/innersearch/subsearch"
params = "query=" + query + "&cookie=" + cookie + '&subsys_type=1&offset_buf={"page_param":[{"subsys_type":1,"server_offset":0,"server_limit":' + str(number) + ',"index_step":' + str(number) + ',"index_offset":0}],"client_offset":0,"client_limit":' + str(number) + '}'
response = requests.post(url=url, params=params, headers=headers, timeout=10).text
Apps_Json = json.loads(response)
# 解析获取APPID和名称
2. 获取域名信息
def Get_Domain(X_APP_ID):
headers = {"User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; MuMu Build/V417IR; wv)"}
url = "https://mp.weixin.qq.com/wxawap/waverifyinfo?"
params = "action=get&wx_header=1&appid=" + X_APP_ID
response = requests.get(url=url, params=params, headers=headers).text
resp = response.replace(' ', '').replace('\n', '').replace('\t', '').replace("\"", "")
# 解析域名信息
3. 域名黑名单过滤
def black_domain_filter(res_domain_list):
black_domain_list = ['qq.com', 'gov.cn']
real_domian_list = []
for res in res_domain_list:
flag = 0
for bl in black_domain_list:
if bl in res:
flag = 1
if flag == 0:
real_domian_list.append(res)
return real_domian_list
4. 结果输出
def write_domain_list(query, all_domain_list, all_domain_list2):
t = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
# 批量测试用文件
with open(query + '批量用'+ t + '.txt', 'w+', encoding='utf-8') as f:
for l in set(all_domain_list):
f.writelines(l+'\n')
# 查询用文件
with open(query + '查询用'+ t + '.txt', 'w+', encoding='utf-8') as f:
f.writelines('如果想查询某个域名属于哪个小程序,请访问地址:https://mp.weixin.qq.com/wxawap/waverifyinfo?action=get&appid=加上域名列表前的APPID即可')
for l in all_domain_list2:
str1 = ''
for i in l:
str1 = str1+i+','
f.writelines(str1+'\n')
三、工具使用步骤
-
配置抓包环境
- 设置微信PC客户端代理为127.0.0.1:8080
- 配置Burp Suite或Fiddler监听该端口
-
获取Cookie
- 在微信PC端搜索目标小程序
- 从抓包数据中提取
wxa-cgi/innersearch/subsearch请求的Cookie
-
运行工具
python wechat_miniprogram_domain_collector.py- 输入要搜索的小程序名称
- 输入要返回的小程序数量
- 输入获取到的Cookie信息
-
结果文件
[查询词]批量用[时间].txt:去重后的域名列表,用于批量测试[查询词]查询用[时间].txt:包含APPID与域名的对应关系
0X03 注意事项
- 法律合规:仅用于授权测试,非法使用后果自负
- 接口变更:微信可能随时调整接口,需保持工具更新
- 请求频率:适当添加延迟,避免被封禁
- 黑名单配置:根据实际需求调整
black_domain_list
0X04 完整代码
[此处应包含完整的Python脚本代码,因篇幅限制略去,可参考原文中的完整代码]
0X05 扩展思路
- 多线程优化:加快大批量查询速度
- 自动更新Cookie:实现Cookie过期自动获取
- 结果自动验证:对收集的域名进行存活验证
- 历史记录比对:建立域名变更追踪机制
通过本工具,安全研究人员可以高效收集微信小程序相关域名资产,为后续安全测试提供基础数据支持。使用时请遵守相关法律法规,仅在授权范围内使用。