Dedecms background SQL injection vulnerability(CVE-2023-27733)
Recurrence Process
Visit /dede
to login to the website background.
An web-shell can be written in this page.
Code Audit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| else if($dopost=="query") { csrf_check(); $sqlquery = trim(stripslashes($sqlquery)); if(preg_match("#drop(.*)table#i", $sqlquery) || preg_match("#drop(.*)database#", $sqlquery)) { echo "<span style='font-size:10pt'>删除'数据表'或'数据库'的语句不允许在这里执行。</span>"; exit(); } if(preg_match("#^select #i", $sqlquery)) { $dsql->SetQuery($sqlquery); $dsql->Execute(); if($dsql->GetTotalRow()<=0) { echo "运行SQL:{$sqlquery},无返回记录!"; } else { echo "运行SQL:{$sqlquery},共有".$dsql->GetTotalRow()."条记录,最大返回100条!"; } $j = 0; while($row = $dsql->GetArray()) { $j++; if($j > 100) { break; } echo "<hr size=1 width='100%'/>"; echo "记录:$j"; echo "<hr size=1 width='100%'/>"; foreach($row as $k=>$v) { echo "<font color='red'>{$k}:</font>{$v}<br/>\r\n"; } } exit(); } if($querytype==2) { $sqlquery = str_replace("\r","",$sqlquery); $sqls = preg_split("#;[ \t]{0,}\n#",$sqlquery); $nerrCode = ""; $i=0; foreach($sqls as $q) { $q = trim($q); if($q=="") { continue; } $dsql->ExecuteNoneQuery($q); $errCode = trim($dsql->GetError()); if($errCode=="") { $i++; } else { $nerrCode .= "执行: <font color='blue'>$q</font> 出错,错误提示:<font color='red'>".$errCode."</font><br>"; } } echo "成功执行{$i}个SQL语句!<br><br>"; echo $nerrCode; } else { $dsql->ExecuteNoneQuery($sqlquery); $nerrCode = trim($dsql->GetError()); echo "成功执行1个SQL语句!<br><br>"; echo $nerrCode; } exit(); }
|
The sql statement only prohibits database deletion, and does not prohibit shell writing through the SQL statement.