一个PC上的“WormHole”漏洞

xlab · 2015/11/05 12:38

[email protected]

0x00 前言


最近安全界关注的焦点WormHole是一类不安全的开发习惯所导致的,在PC上类似问题也毫不罕见,只不过很多风险被微软默认自带的防火墙缓解了。希望本文和众多关于WormHole的讨论能获多或少地提高一些开发人员的安全意识。

下面要介绍的问题可导致的后果和WormHole非常类似:影响上亿用户、访问一个端口发送一条指令就可以让目标系统下载一个程序并执行。

该问题已于2015年9月29日被修复。在修复前,存在于所有使用预装Windows系统的ThinkPad、ThinkCentre、ThinkStation以及Lenovo V/B/K/E系列电脑。

0x01 背景


联想ThinkVantage System Update软件用于帮助用户从联想的服务器中直接下载并安装软件、驱动、BIOS的更新,极大的简化了用户更新系统的难度和工作量。其被默认预装在联想的多款产品中。

Lenovo System Update可根据不同的网络环境及配置通过多种方式下载软件及更新,其中一种方式为通过文件共享下载,而UNCServer.exe则是完成此功能的主程序,UNCServer.exe随System Update主程序启动,并建立本地服务端等待主程序连接。在早期版本中,甚至System Update主程序退出后,UNCServer.exe也仍然保持运行状态。

0x02 问题描述


在System Update的5.6.0.34版本中,UNCServer.exe通过.NET的Remoting机制,通过TCP服务器提供多种功能。

.NET Remoting发展自DCOM,是一项比较老的.NET分布式处理技术。它序列化服务端的对象和数据并导出,客户端通过HTTP、TCP、IPC信道跨越进程边界实现对服务端对象的引用。然而Remoting的序列化机制会隐式导出对象所有的方法和属性,客户端一旦获得服务端导出的对象引用,即可调用服务端对象提供的所有方法。因此Remoting机制容易引入安全漏洞,且不建议将Remoting服务终端导出给不受信任的客户端。

UNCServer导出的Connector对象提供Connect、DownloadBean、IsFileExist、IsFolderExist、GetFilesInFolder、GetSubFolder、QueryFile、LaunchIE功能。客户端可以连接并获取其引出对象,进行文件下载、应用程序执行等操作。

其中LaunchIE并未对参数进行任何验证,可以用来启动任意进程,其实现代码如下:

case UNCAction.LaunchIE:
        string fileName = (string) eventObj;
        try{
            Process.Start(fileName);
        }
        catch{
        }
        this.connector.Current = (object) true;
    break;
复制代码

同时,虽然System Update在防火墙策略中只添加了UNCServer的出站规则,但由于UNCServer缺少必要的配置,使其绑定在0.0.0.0:20050上。因此在缺乏防火墙保护的情况下,任何机器都可与其建立连接,最终使用其提供的DownloadBean和LaunchIE功能实现远程下载程序并执行。

UNCServer建立服务端信道并导出对象的代码如下:

IDictionary properties = (IDictionary) new Hashtable();
properties[(object) "name"] = (object) "tvsuuncchannel";
properties[(object) "priority"] = (object) 2;
properties[(object) "port"] = (object) 20050;
this.channel = new TcpServerChannel(properties, (IServerChannelSinkProvider) new BinaryServerFormatterSinkProvider());
ChannelServices.RegisterChannel((IChannel) this.channel, false);
this.status = new object();
this.connector = new Connector();
RemotingServices.Marshal((MarshalByRefObject) this.connector, "Connector");
this.connector.UNCEvent += new Connector.UNCEventHandler(this.connector_UNCEvent);
复制代码

0x03 修复


联想在2015/9/29日放出的System Update 5.7.0.13修复了包括此问题在内的多个漏洞。其重新实现了LaunchIE、LaunchHelp功能,对其创建进程的参数进行了验证。并加强了服务端的配置,使其绑定在127.0.0.1:20050,阻止了远程请求。修复后的部分代码如下:

case UNCAction.LaunchIE:
        try{
            tring str = (string) eventObj;
            Uri result;
            if (Uri.TryCreate(str, UriKind.Absolute, out result) && (result.Scheme == Uri.UriSchemeHttp || result.Scheme == Uri.UriSchemeHttps))
                Process.Start(str);
        }
        catch{
        }
        this.connector.Current = (object) true;
    break;    


IDictionary properties = (IDictionary) new Hashtable();
properties[(object) "name"] = (object) "tvsuuncchannel";
properties[(object) "priority"] = (object) 2;
properties[(object) "port"] = (object) 20050;
properties[(object) "rejectRemoteRequests"] = (object) true;
properties[(object) "bindTo"] = (object) "127.0.0.1";
this.channel = new TcpServerChannel(properties, (IServerChannelSinkProvider) new BinaryServerFormatterSinkProvider());
ChannelServices.RegisterChannel((IChannel) this.channel, false);
this.status = new object();
this.connector = new Connector();
RemotingServices.Marshal((MarshalByRefObject) this.connector, "Connector");
this.connector.UNCEvent += new Connector.UNCEventHandler(this.connector_UNCEvent);
复制代码

0x04 小结


Remoting作为上一代的.NET分布式处理技术,由于设计时的安全缺陷早已被微软的WCF技术取代。如果应用程序仍在使用Remoting技术进行分布式处理或通信,应意识到其潜在的安全问题,稍有不当则可能引入安全漏洞。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是完整的代码流程: ```javascript const Ftp = require('ftp'); const fs = require('fs'); const path = require('path'); const sendToWormhole = require('stream-wormhole'); const awaitWriteStream = require('await-stream-ready').write; const Controller = require('egg').Controller; class FileController extends Controller { async download() { const { ctx } = this; const client = new Ftp(); const filePath = ctx.query.filePath; // 文件在ftp服务器上的路径 const fileName = path.basename(filePath); // 文件名 const writeStream = fs.createWriteStream(fileName); // 创建本地文件写入流 // 连接ftp服务器 client.connect({ host: 'ftp.example.com', user: 'username', password: 'password', }); client.on('ready', () => { client.get(filePath, (err, stream) => { if (err) { client.end(); ctx.status = 500; ctx.body = 'Failed to get file'; return; } // 使用stream-wormhole处理异常 stream.once('error', error => { sendToWormhole(stream); client.end(); ctx.status = 500; ctx.body = 'Failed to get file'; }); // 将文件流pipe到本地写入流 stream.pipe(writeStream); // 完成本地写入后,返回文件给前端 writeStream.on('finish', async () => { const fileStream = fs.createReadStream(fileName); // 使用await-stream-ready等待流完成 await awaitWriteStream(fileStream); // 设置响应头,告诉浏览器返回的是文件流 ctx.set('Content-disposition', `attachment; filename=${fileName}`); ctx.set('Content-Type', 'application/octet-stream'); ctx.body = fileStream; // 关闭ftp连接 client.end(); }); }); }); client.on('error', error => { ctx.status = 500; ctx.body = 'Failed to connect ftp server'; }); } } module.exports = FileController; ``` 在上面的代码中,我们首先连接ftp服务器,然后使用ftp库获取文件流。由于获取的流是一个Socket对象,我们无法直接将其赋值给ctx.body返回给前端,因此需要将其pipe到本地文件写入流中,等待写入完成后再将其返回给前端。在写入完成后,我们需要手动设置响应头告诉浏览器返回的是文件流,并关闭ftp连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值