回顾与预告
在上一篇文章中,我们了解了 SRP 协议的基本原理和 Apple 实现的特殊之处。本篇将深入探讨 Apple 网页 SRP 登录的第一个关键环节:如何从复杂的网页结构中提取必要的认证参数,并完成会话初始化。
Apple 登录页面的复杂性
与传统的简单登录表单不同,Apple 的登录页面采用了多层安全架构:
1. 多域名跳转机制
# 初始访问Apple商店页面
init_country_url = f"https://secure.store.apple.com/{
country_code}/shop/giftcard/balance"
# 重定向到认证域名
auth_signin_url = "https://idmsa.apple.com/appleauth/auth/authorize/signin"
这种跨域设计不仅提高了安全性,还能根据用户地理位置进行智能路由。
2. 动态参数生成
Apple 会在页面加载时动态生成多个关键参数:
# 客户端生成的框架ID
client_generated_initial_frame_id = f"auth-{
generate_random_string_for_client_info(8)}-{
generate_random_string_for_client_info(4)}-{
generate_random_string_for_client_info(4)}-{
generate_random_string_for_client_info(4)}-{
generate_random_string_for_client_info(12)}"
这些 ID 确保每次登录会话的唯一性,防止会话劫持攻击。
关键参数提取技术
1. ServiceKey(客户端标识)提取
ServiceKey 是 Apple 用来识别客户端类型的重要参数。它通常嵌套在网页的 JSON 数据中:
def extract_nested_value_from_html_script_json(html_content: str, script_id: str, path: list[str]) -> Optional[str]:
"""从网页脚本的JSON数据中提取嵌套值"""
try:
# 查找指定ID的script标签
script_pattern = re.compile(
rf'<script[^>]*id=["\']?{
re.escape(script_id)}["\']?[^>]*>(.*?)</script>',
re.IGNORECASE | re.DOTALL
)
match = script_pattern.search(html_content)
if not match:
return None
script_content = match.group(1).strip()
# 解析JSON并按路径提取值
json_data = json.loads(script_content)
current_level = json_data
for key_part in path:
if isinstance(current_level, dict) and key_part in current_level:
current_level = current_level[key_part]
else:
return None
return str(current_level) if current_level else None
except (json.JSONDecodeError, KeyError, AttributeError
3043


:网页参数提取与会话初始化&spm=1001.2101.3001.11974&articleId=148452103&d=1&t=3&u=6d7f7b2c78784bb78a2c66084331e3d4)

被折叠的 条评论
为什么被折叠?



