Difference between revisions of "Resource Injection"

From OWASP
Jump to: navigation, search
(Added contents provided by Fortify.)
m (Add to Injection subcategory)
 
(16 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{Template:Attack}}
 
{{Template:Attack}}
{{Template:Fortify}}
+
<br>
 +
[[Category:OWASP ASDR Project]]
  
==Abstract==
 
  
Allowing user input to control resource identifiers may enable an attacker to access or modify otherwise protected system resources.
+
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''
  
 
==Description==
 
==Description==
 +
This attack consists of changing resource identifiers used by an application in order to perform a malicious task. When an application permits a user input to define a resource, like a file name or port number, this data can be manipulated to execute or access different resources.
 +
<br>
 +
In order to be properly executed, the attacker must have the possibility to specify a resource identifier through the  application form and the application must permit its execution.
  
A resource injection issue occurs when the following two conditions are met:
+
The resource type affected by user input indicates the content type that may be exposed. For example, an application that permits input of special characters like period, slash, and backslash is risky when used in methods that interact with the file system.
  
# An attacker can specify the identifier used to access a system resource. For example, an attacker might be able to specify part of the name of a file to be opened or a port number to be used.  
+
The resource injection attack focuses on accessing other resources than the local filesystem, which is different attack technique known as a [[Path Manipulation]] attack.<br>
# By specifying the resource, the attacker gains a capability that would not otherwise be permitted. For example, the program may give the attacker the ability to overwrite the specified file or run with a configuration controlled by the attacker.
+
 
 +
== Risk Factors==
 +
TBD
  
 
==Examples ==
 
==Examples ==
  
 
===Example 1===
 
===Example 1===
 +
The following examples represent an application which gets a port number from an HTTP request and creates a socket with this port number without any validation. A user using a proxy can modify this port and obtain a direct connection (socket) with the server.
 +
<br><br>
  
The following Java code uses input from an HTTP request to create a file name. The programmer has not considered the possibility that an attacker could provide a file name such as "../../tomcat/conf/server.xml", which causes the application to delete one of its own configuration files.
+
'''Java code:'''
  
<pre>
+
String rPort = request.getParameter("remotePort");
String rName = request.getParameter("reportName");
+
...
File rFile = new File("/usr/local/apfr/reports/" + rName);
+
ServerSocket srvr = new ServerSocket(rPort);
...
+
Socket skt = srvr.accept();
rFile.delete();
+
...
</pre>
+
 
 +
<br>
 +
'''.Net code:'''
 +
 
 +
int rPort = Int32.Parse(Request.get_Item("remotePort "));
 +
...
 +
IPEndPoint endpoint = new IPEndPoint(address,rPort);
 +
socket = new Socket(endpoint.AddressFamily,
 +
SocketType.Stream, ProtocolType.Tcp);
 +
socket.Connect(endpoint);
 +
...
  
 
===Example 2===
 
===Example 2===
 +
This example is same as previous, but it gets port number from CGI requests using C++:
 +
 +
char* rPort = getenv("remotePort ");
 +
...
 +
serv_addr.sin_port = htons(atoi(rPort));
 +
if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0)
 +
error("ERROR connecting");
 +
...
  
The following C++ code uses input from the command line to determine which file to open and echo back to the user. If the program runs with privileges and malicious users can create soft links to the file, they can use the program to read the first part of any file on the system.
+
===Example 3===
 +
This example in PLSQL / TSQL gets a URL path from a CGI and downloads the file contained in it. If a user modifies the path or filename, it’s possible to download arbitrary files from server:
 +
...
 +
filename := SUBSTR(OWA_UTIL.get_cgi_env('PATH_INFO'), 2);
 +
WPG_DOCLOAD.download_file(filename);
 +
...
  
<pre>
+
==Related [[Threat Agents]]==
ifstream ifs(argv[0]);
+
* [[:Category:Logical Attacks]]
string s;
+
* [[:Category: Information Disclosure]]
ifs >> s;
+
cout << s;
+
</pre>
+
  
The kind of resource the data affects indicates the kind of content that may be dangerous. For example, data containing special characters like period, slash, and backslash, are risky when used in methods that interact with the file system. (Resource injection, when it is related to file system resources, sometimes goes by the name "path manipulation.") Similarly, data that contains URLs and URIs is risky for functions that create remote connections.
+
==Related [[Attacks]]==
 +
* [[Path Traversal]]
 +
* [[Path Manipulation]]
 +
* [[Relative Path Traversal]]
 +
* [[:Category:Injection Attack | Injection Attacks]]
  
==Related Threats==
+
==Related [[Vulnerabilities]]==
 +
* [[:Category:Input Validation Vulnerability]]
  
==Related Attacks==
+
==Related [[Controls]]==
 +
* [[:Category:Input Validation]]
  
==Related Vulnerabilities==
+
==References==
[[:Category:Input Validation Vulnerability]]
+
* http://samate.nist.gov/SRD/view_testcase.php?tID=1734
 +
* http://cwe.mitre.org/data/definitions/99.html
 +
* http://capec.mitre.org/data/index.html#Definition
 +
* http://www.fortifysoftware.com/vulncat/
 +
* G. Hoglund and G. McGraw. Exploiting Software. Addison-Wesley, 2004.
  
==Related Countermeasures==
 
[[:Category:Input Validation]]
 
  
==Categories==
+
[[Category: Injection]]
[[Category:Injection Attack]]
+
[[Category: Attack]]
[[Category:Java]]
+
[[Category:Code Snippet]]
+
[[Category:Implementation]]
+

Latest revision as of 18:17, 8 December 2011

This is an Attack. To view all attacks, please see the Attack Category page.




Last revision (mm/dd/yy): 12/8/2011

Description

This attack consists of changing resource identifiers used by an application in order to perform a malicious task. When an application permits a user input to define a resource, like a file name or port number, this data can be manipulated to execute or access different resources.
In order to be properly executed, the attacker must have the possibility to specify a resource identifier through the application form and the application must permit its execution.

The resource type affected by user input indicates the content type that may be exposed. For example, an application that permits input of special characters like period, slash, and backslash is risky when used in methods that interact with the file system.

The resource injection attack focuses on accessing other resources than the local filesystem, which is different attack technique known as a Path Manipulation attack.

Risk Factors

TBD

Examples

Example 1

The following examples represent an application which gets a port number from an HTTP request and creates a socket with this port number without any validation. A user using a proxy can modify this port and obtain a direct connection (socket) with the server.

Java code:

String rPort = request.getParameter("remotePort");
...
ServerSocket srvr = new ServerSocket(rPort);
Socket skt = srvr.accept(); 
...


.Net code:

int rPort = Int32.Parse(Request.get_Item("remotePort "));
...
IPEndPoint endpoint = new IPEndPoint(address,rPort);
socket = new Socket(endpoint.AddressFamily, 
SocketType.Stream, ProtocolType.Tcp);
socket.Connect(endpoint);
...

Example 2

This example is same as previous, but it gets port number from CGI requests using C++:

char* rPort = getenv("remotePort ");
...
serv_addr.sin_port = htons(atoi(rPort));
if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) 
error("ERROR connecting");
...

Example 3

This example in PLSQL / TSQL gets a URL path from a CGI and downloads the file contained in it. If a user modifies the path or filename, it’s possible to download arbitrary files from server:

...
filename := SUBSTR(OWA_UTIL.get_cgi_env('PATH_INFO'), 2);
WPG_DOCLOAD.download_file(filename); 
...

Related Threat Agents

Related Attacks

Related Vulnerabilities

Related Controls

References