CWE-348 使用不可信的源

Use of Less Trusted Source

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: unkown

基本描述

The software has two different sources of the same data or information, but it uses the source that has less support for verification, is less trusted, or is less resistant to attack.

相关缺陷

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

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

适用平台

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

常见的影响

范围 影响 注释
Access Control ['Bypass Protection Mechanism', 'Gain Privileges or Assume Identity'] An attacker could utilize the untrusted data source to bypass protection mechanisms and gain access to sensitive data.

示例代码

This code attempts to limit the access of a page to certain IP Addresses. It checks the 'HTTP_X_FORWARDED_FOR' header in case an authorized user is sending the request through a proxy.

bad PHP

$requestingIP = '0.0.0.0';
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
$requestingIP = $_SERVER['HTTP_X_FORWARDED_FOR'];

else{
$requestingIP = $_SERVER['REMOTE_ADDR'];
}

if(in_array($requestingIP,$ipWhitelist)){
generatePage();
return;
}
else{
echo "You are not authorized to view this page";
return;
}

The 'HTTP_X_FORWARDED_FOR' header can be user controlled and so should never be trusted. An attacker can falsify the header to gain access to the page.

This fixed code only trusts the 'REMOTE_ADDR' header and so avoids the issue:

good PHP

$requestingIP = '0.0.0.0';
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
echo "This application cannot be accessed through a proxy.";
return;

else{
$requestingIP = $_SERVER['REMOTE_ADDR'];
}
...

Be aware that 'REMOTE_ADDR' can still be spoofed. This may seem useless because the server will send the response to the fake address and not the attacker, but this may still be enough to conduct an attack. For example, if the generatePage() function in this code is resource intensive, an attacker could flood the server with fake requests using an authorized IP and consume significant resources. This could be a serious DoS attack even though the attacker would never see the page's sensitive content.

分析过的案例

标识 说明 链接
CVE-2001-0860 Product uses IP address provided by a client, instead of obtaining it from the packet headers, allowing easier spoofing. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2001-0860
CVE-2004-1950 Web product uses the IP address in the X-Forwarded-For HTTP header instead of a server variable that uses the connecting IP address, allowing filter bypass. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-1950
BID:15326 Similar to CVE-2004-1950 http://www.securityfocus.com/bid/15326/info
CVE-2001-0908 Product logs IP address specified by the client instead of obtaining it from the packet headers, allowing information hiding. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2001-0908
CVE-2006-1126 PHP application uses IP address from X-Forwarded-For HTTP header, instead of REMOTE_ADDR. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-1126

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
PLOVER Use of Less Trusted Source

相关攻击模式

  • CAPEC-141
  • CAPEC-142
  • CAPEC-73
  • CAPEC-76
  • CAPEC-85