Slides Insecure Direct Object Reference
Slides Insecure Direct Object Reference
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 1
Table of Contents
Introduction
Principles
Tampering HTTP parameters
Vulnerability
Examples of Attacks
Protection
Conclusion
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 2
Introduction
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 3
Insecure Direct Object Reference
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 4
Which parameters can be tainted?
HTTP GET parameters
Directly inside the URL
Example:
http://www.mysite.com/index.php?viewaccount=23456
Change the URL :
http://www.mysite.com/index.php?viewaccount=1234
Gives access to the account 1234
HTTP POST parameters
In the body of the POST request,
Often URL encoded (other encoding are possible).
Other HTTP headers
The cookies (are included in each HTTP header)
Languages (in the header: Accept-Language)
User-Agent (to determine which browser is reading the page)
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 5
Internal objects?
Data Base objects
Reference to records in a table
Primary key used to refere to a page
www.vicitim.com/page?pageId=345 to access page with Id
345
File (or directory)
Reference to a file is done in the parameter
The file may be loaded
include($_GET[’language’].’.php’);
Or it may be moved, copied, etc.
Keys
a key may be shown as a parameter (or cookie).
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 6
Principles
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 7
Presentation of the Vulnerability
Insecure Direct Object Reference
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 8
Example
View the account of a client
Suppose we have the following html in the menu of a client
The client can see each of his or her accounts
<div class="menu">
<div class="menu-item"><a href="/index.php?&
→account=23456}">account 23456</a></div>
</div>
When the client clicks on the link:
GET https://www.mybank.com/index.php?account&
→=23456 HTTP/1.1
Host: www.mybank.com
...
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 9
Example (Cont.)
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 10
Another Example
Access secret content
Suppose you have a JavaScript application with the
following request for a JSON object
GET /resource?item=12345 HTTP/1.1
Host: www.mysite.com
Cookie: SESSIONID=239e98d32c98b23a
....
The application will respond with the following kind of answer:
{ id: 12345,
name: ’benoist’,
firstname: ’emmanuel’,
accountnumber: ’1234543245900’,
balance: ’2090’,
currency: ’CHF’}
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 11
Another Example (Cont.)
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 12
Example: Upload form
Suppose we found the following upload form
<form action="upload.php" method="post" enctype=&
→"multipart/form-data">
</form>
File to upload is copied into the directory uploaded
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 13
Example: Upload form (Cont.)
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 14
Tampering HTTP parameters
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 15
Tampering without browser
HTTP is an open protocol
Requests can be generated manually
Parameters can be set arbitrary
GET Request
Insert parameters in the Query string
Parameters need to be URL encoded
GET /program.php?param=fake¶m2=new+text%00 HTTP/1.1
Host: www.vicitim.org
POST Request
Parameters are in the body of the request
POST /program.php HTTP/1.1
Host: www.victim.org
Content-Length: 52
Content-Type: application/x-www-form-urlencoded
username=bie1&email=bie1@bfh.org&submit=Submit+me%21
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 16
Tampering inside a browser
Some web applications generate complicated requests
Cookies, Url referer,
AJAX requests
JSON requests
Not so easy to generate manually
Use tools to manipulate Requests generated by the
browser
ZAP Zed Attack Proxy
OWASP tool
Proxy of the browser,
intercepts requests that can be manipulated (and much more)
Tamper Data
Firefox plugin
Modify the requests inside the browser
Browser - Web Developper mode
Allows to manipulate GET and POST requests.
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 17
Vulnerability
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 18
Vulnerability?
Applications expose their internal object references to
users
Attacker use parameter tampering to change references
they can violate security policy if it is unenforced
Example
If the application uses a parameter which contains a filename
or a path
It can be changed to access other resources
viewpage.php?document=mydoc
displays the content of the file
/home/bie1/myfiles/mydoc.pdf
the input could be manipulated into accessing another file
viewpage.php?document=../../frc1/otherDocument
will show the file /home /frc1/otherDocument.pdf
Also known as : Path Traversal
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 19
Examples of Attacks
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 20
Access tax declaration
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 21
Modify internal keys
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 22
Read files
Accessing a file
File directly accessible
Suppose you have the following URL
www.victim.org/resources/BIE1.pdf
You know that BIE1 is your ID in the system.
You know your boss’s ID is DUE1,
www.victim.org/resources/DUE1.pdf
more easy if www.victim.org/resources/ shows the index
of the directory
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 23
Read files (Cont.)
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 24
Read file
Program
<?php
if(isset($_SESSION[’userID’])){
$homepage = file_get_contents($_GET[’file’]);
echo $homepage;
}
?>
Works with the following URL 1 :
http://www.victim.org/file=bie1.pdf
But also with
http://www.victim.org/file=/etc/passwd
Could also work with
http://www.victim.org/file=http:
//192.168.1.24/restrictedResource
1
all requests parameters should be URL encoded
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 25
Protection
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 26
How to protect yourself?
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 27
Authorizations
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 28
Indirect object reference map
Where a parital filename was used, prefere a hash of the
partial reference
Instead of
<select name="language">
<option value="english">English</option>
Use
<select name="language">
<option value="2c8283b7743646a2a72e626437484"&
→>
English
</option>
Alternatively, use 1, 2, 3 as array reference
check array bounds to detect parameter tampering
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 29
Use explicit taint checking
mechanisms
If included in language
JSF or Struts
Otherwise, consider a variable naming scheme
$hostile = &$_POST;
$safe[’filename’] = validate_file_name($hostile[&
→’unsafe_filename’]);
// Good:
require_once($safe[’filename’].’inc.php’);
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 30
Protection (Cont.)
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 31
Conclusion
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 32
Conclusion
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 33
Conclusion (Cont.)
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 34
References
Berner Fachhochschule | Haute école spécialisée bernoise | Berne University of Applied Sciences 35