CWE-36 绝对路径遍历

admin 2022年1月2日04:09:21CWE(弱点枚举)评论16 views7007字阅读23分21秒阅读模式

CWE-36 绝对路径遍历

Absolute Path Traversal

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: unkown

基本描述

The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize absolute path sequences such as "/abs/path" that can resolve to a location that is outside of that directory.

扩展描述

This allows attackers to traverse the file system to access files or directories that are outside of the restricted directory.

相关缺陷

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

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

适用平台

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

常见的影响

范围 影响 注释
['Integrity', 'Confidentiality', 'Availability'] Execute Unauthorized Code or Commands The attacker may be able to create or overwrite critical files that are used to execute code, such as programs or libraries.
Integrity Modify Files or Directories The attacker may be able to overwrite or create critical files, such as programs, libraries, or important data. If the targeted file is used for a security mechanism, then the attacker may be able to bypass that mechanism. For example, appending a new account at the end of a password file may allow an attacker to bypass authentication.
Confidentiality Read Files or Directories The attacker may be able read the contents of unexpected files and expose sensitive data. If the targeted file is used for a security mechanism, then the attacker may be able to bypass that mechanism. For example, by reading a password file, the attacker could conduct brute force password guessing attacks in order to break into an account on the system.
Availability DoS: Crash, Exit, or Restart The attacker may be able to overwrite, delete, or corrupt unexpected critical files such as programs, libraries, or important data. This may prevent the software from working at all and in the case of a protection mechanisms such as authentication, it has the potential to lockout every user of the software.

示例代码

In the example below, the path to a dictionary file is read from a system property and used to initialize a File object.

bad Java

String filename = System.getProperty("com.domain.application.dictionaryFile");
File dictionaryFile = new File(filename);

However, the path is not validated or modified to prevent it from containing absolute path sequences before creating the File object. This allows anyone who can control the system property to determine what file is used. Ideally, the path should be resolved relative to some kind of application or user home directory.

The following code demonstrates the unrestricted upload of a file with a Java servlet and a path traversal vulnerability. The action attribute of an HTML form is sending the upload file request to the Java servlet.

good HTML

Choose a file to upload:

When submitted the Java servlet's doPost method will receive the request, extract the name of the file from the Http request header, read the file contents from the request and output the file to the local upload directory.

bad Java

public class FileUploadServlet extends HttpServlet {

...

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
String contentType = request.getContentType();

// the starting position of the boundary header
int ind = contentType.indexOf("boundary=");
String boundary = contentType.substring(ind+9);

String pLine = new String();
String uploadLocation = new String(UPLOAD_DIRECTORY_STRING); //Constant value

// verify that content type is multipart form data
if (contentType != null && contentType.indexOf("multipart/form-data") != -1) {

// extract the filename from the Http header
BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
...
pLine = br.readLine();
String filename = pLine.substring(pLine.lastIndexOf(""), pLine.lastIndexOf("""));
...

// output the file to the local upload directory
try {

BufferedWriter bw = new BufferedWriter(new FileWriter(uploadLocation+filename, true));
for (String line; (line=br.readLine())!=null; ) {

if (line.indexOf(boundary) == -1) {

bw.write(line);
bw.newLine();
bw.flush();

}

} //end of for loop
bw.close();

} catch (IOException ex) {...}
// output successful upload response HTML page

}
// output unsuccessful upload response HTML page
else
{...}

}

...

}

As with the previous example this code does not perform a check on the type of the file being uploaded. This could allow an attacker to upload any executable file or other file with malicious code.

Additionally, the creation of the BufferedWriter object is subject to relative path traversal (CWE-22, CWE-23). Depending on the executing environment, the attacker may be able to specify arbitrary files to write to, leading to a wide variety of consequences, from code execution, XSS (CWE-79), or system crash.

分析过的案例

标识 说明 链接
CVE-2002-1345 Multiple FTP clients write arbitrary files via absolute paths in server responses https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1345
CVE-2001-1269 ZIP file extractor allows full path https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2001-1269
CVE-2002-1818 Path traversal using absolute pathname https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1818
CVE-2002-1913 Path traversal using absolute pathname https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1913
CVE-2005-2147 Path traversal using absolute pathname https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-2147
CVE-2000-0614 Arbitrary files may be overwritten via compressed attachments that specify absolute path names for the decompressed output. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2000-0614
CVE-1999-1263 Mail client allows remote attackers to overwrite arbitrary files via an e-mail message containing a uuencoded attachment that specifies the full pathname for the file to be modified. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-1999-1263
CVE-2003-0753 Remote attackers can read arbitrary files via a full pathname to the target file in config parameter. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2003-0753
CVE-2002-1525 Remote attackers can read arbitrary files via an absolute pathname. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1525
CVE-2001-0038 Remote attackers can read arbitrary files by specifying the drive letter in the requested URL. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2001-0038
CVE-2001-0255 FTP server allows remote attackers to list arbitrary directories by using the "ls" command and including the drive letter name (e.g. C:) in the requested pathname. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2001-0255
CVE-2001-0933 FTP server allows remote attackers to list the contents of arbitrary drives via a ls command that includes the drive letter as an argument. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2001-0933
CVE-2002-0466 Server allows remote attackers to browse arbitrary directories via a full pathname in the arguments to certain dynamic pages. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0466
CVE-2002-1483 Remote attackers can read arbitrary files via an HTTP request whose argument is a filename of the form "C:" (Drive letter), "//absolute/path", or ".." . https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1483
CVE-2004-2488 FTP server read/access arbitrary files using "C:" filenames https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-2488
CVE-2001-0687 FTP server allows a remote attacker to retrieve privileged web server system information by specifying arbitrary paths in the UNC format (computernamesharename). https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2001-0687

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
PLOVER Absolute Path Traversal
Software Fault Patterns SFP16 Path Traversal

相关攻击模式

  • CAPEC-597

引用

文章来源于互联网:scap中文网

特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月2日04:09:21
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  CWE-36 绝对路径遍历 http://cn-sec.com/archives/612901.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: