CWE-181 不正确的行为次序:在过滤之前验证

Incorrect Behavior Order: Validate Before Filter

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: unkown

基本描述

The software validates data before it has been filtered, which prevents the software from detecting data that becomes invalid after the filtering step.

扩展描述

This can be used by an attacker to bypass the validation and launch attacks that expose weaknesses that would otherwise be prevented, such as injection.

相关缺陷

  • cwe_Nature: ChildOf cwe_CWE_ID: 20 cwe_View_ID: 699 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 179 cwe_View_ID: 1000 cwe_Ordinal: Primary

适用平台

Language: {'cwe_Class': 'Language-Independent', 'cwe_Prevalence': 'Undetermined'}

常见的影响

范围 影响 注释
Access Control Bypass Protection Mechanism

可能的缓解方案

['Implementation', 'Architecture and Design']

策略:

Inputs should be decoded and canonicalized to the application's current internal representation before being filtered.

示例代码

This script creates a subdirectory within a user directory and sets the user as the owner.

bad PHP

function createDir($userName,$dirName){
$userDir = '/users/'. $userName;
if(strpos($dirName,'..') !== false){
echo 'Directory name contains invalid sequence';
return;
}
//filter out '~' because other scripts identify user directories by this prefix
$dirName = str_replace('~','',$dirName);
$newDir = $userDir . $dirName;
mkdir($newDir, 0700);
chown($newDir,$userName);
}

While the script attempts to screen for '..' sequences, an attacker can submit a directory path including ".~.", which will then become ".." after the filtering step. This allows a Path Traversal (CWE-21) attack to occur.

分析过的案例

标识 说明 链接
CVE-2002-0934 Directory traversal vulnerability allows remote attackers to read or modify arbitrary files via invalid characters between two . (dot) characters, which are filtered and result in a ".." sequence. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0934
CVE-2003-0282 Directory traversal vulnerability allows attackers to overwrite arbitrary files via invalid characters between two . (dot) characters, which are filtered and result in a ".." sequence. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2003-0282

Notes

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
PLOVER Validate-Before-Filter
OWASP Top Ten 2004 A1 CWE More Specific Unvalidated Input

相关攻击模式

  • CAPEC-120
  • CAPEC-267
  • CAPEC-3
  • CAPEC-43
  • CAPEC-78
  • CAPEC-79
  • CAPEC-80