为什么没有安全措施来防止通过 X11 在其他应用程序 windows 上进行绘制?

Why are there no security measures to protect against drawing on other application windows via X11?

我最近一直在研究 X 窗口系统,我发现利用另一个进程创建的 window 是相当简单的。您只需要 window ID。我不确定 window ID 和其他现有 window 信息是如何通过 X11 核心协议检索的,但这显然是可能的,因为有一个名为 xwininfo 的简单 X11 实用程序正是这样做的。

xwininfo 不需要 root 权限,也不需要 root 权限来使用其他应用程序创建的 windows。事实上,我只是直接在现有终端 window 上绘制像素,而没有从 user-space.

获得任何提升的权限

这不是安全问题吗?任何应用程序都可以利用任何其他应用程序的 windows 这一事实似乎会引发问题,例如恶意软件绘制的不可关闭的广告。

这是什么原因?很容易为每个 window 生成一个共享 HMAC 密钥,并让客户端对每个请求进行签名。

我的第一个猜测显然是性能——如果为了在 window 中绘制几个像素而对客户端请求进行签名和验证,可能会有明显的延迟。然而,对于许多简单的桌面应用程序来说,延迟可能仍然可以忽略不计,那么为什么没有任何类型的安全措施,甚至是可选的措施呢?我错过了什么吗?

X11 是一种允许远程显示图形用户界面的协议。如今,通常,X 服务器(负责与 "window manager" 或 "desktop environment" 通信的服务器)运行 主要位于本地桌面,并且 运行 作为 root。除其他原因外,这意味着 X 服务器可以访问其下的所有内容 运行ning 并且由于应用程序之间没有隔离(请注意,由于各种实际原因通常不会这样做),您可以做任何你想做的事,尽管客户端应用程序 运行 作为非特权用户。

引用美国国家安全局“Securing the X Window System With SELinux”的完整性部分:

The current X server offers little protection for the integrity of client program data. The X server does not interact directly with the data of the client. Clients can draw directly into another client’s window and can send input,or any other type of event, directly to a client. A malicious client can cause another client to present false information to the user. Or an attacker could insert malicious commands into the input stream of a terminal emulator. These types of attacks can cause an application to violate the system’s integrity policy, and the protections presented in this paper are designed to protect the integrity of X clients.

这就是为什么在 Mir 或 Wayland 等替代 X 显示系统上开始工作的一些原因。后者是大多数 Linux 台式机的目标。

如果您想了解有关 X Window 系统安全性的更多信息,上面来自 NSA 的论文是一个很好的资源。

一些历史:X11 是在 80 年代开发的。目标之一是允许多个程序在单个显示器上协同工作。那时,有 little/no 黑客攻击、远程访问等。另外,请记住,那时候还没有 openssl,大多数连接都使用明文(ftp、telnet)。安全问题和功能 (ssh) 出现得晚得多。

达到系统运行稳定的地步是一项重大成就。回想起来,扩展设计以支持客户端之间的保护是个好主意。