Learn Pentesting: Manual Testing for Insecure Direct Object References (IDOR) in Web Applications

In this installment of our “Learn Pentesting” series, we dive deep into one of the more common yet dangerous vulnerabilities found in web applications: Insecure Direct Object References (IDOR). In this post, we’ll cover the fundamentals of IDOR, demonstrate a manual testing methodology, and walk through practical code examples to aid penetration testers in identifying and exploiting these flaws in real-world scenarios.


Understanding IDOR

Insecure Direct Object References (IDOR) occur when an application exposes a reference to an internal implementation object, such as a file, database record, or key, without proper access control checks. This means that an attacker may be able to modify these references to access data or functionality that should be restricted.

Key Characteristics:


Common Scenarios and Impact

IDOR vulnerabilities are often found in:

The impact of exploiting an IDOR can be severe, potentially leading to unauthorized data disclosure, data manipulation, or even complete system compromise when combined with other vulnerabilities.


Manual Testing Methodology

Manual testing for IDOR involves several systematic steps:

  1. Identify Candidate Endpoints:
    Look for endpoints that use user-supplied parameters to retrieve resources. Typical places include:

    • Query strings (e.g., ?user_id=)
    • RESTful URL segments (e.g., /users/123)
    • Hidden form fields or cookies
  2. Analyze Application Behavior:
    Determine whether the parameter’s value is directly mapped to an internal resource. Investigate:

    • Response content differences when altering the parameter.
    • HTTP status codes and error messages that may hint at underlying logic.
  3. Parameter Manipulation:
    Manually modify the parameter value in the browser’s address bar or using tools like Burp Suite. Look for:

    • Changes in the response.
    • Consistent behavior when using valid identifiers from another session or enumeration.
  4. Automate with Code:
    For repetitive tests or bulk enumeration, use simple scripts to iterate through potential object identifiers and record the responses. This helps identify subtle differences that might indicate an IDOR.


Practical Code Examples

Example Using Curl

A quick manual test can be performed using curl. Suppose you have a vulnerable endpoint like:

https://vulnerable-app.com/profile?user_id=1001

You might try changing the user_id value to see if the application returns different data. For example:

# Test with the original user_id
curl -i "https://vulnerable-app.com/profile?user_id=1001"

# Test with a different user_id
curl -i "https://vulnerable-app.com/profile?user_id=1002"

Examine the HTTP headers and response bodies. A difference in content might indicate that the parameter is directly referencing an internal object without proper access control.


Example Using Python

For a more automated approach, consider the following Python script using the requests library:

import requests

# Define the base URL and the session cookies if needed
base_url = "https://vulnerable-app.com/profile?user_id="
session = requests.Session()

# Optionally set session cookies if authentication is required
# session.cookies.set('session_id', 'your_session_cookie_here')

def check_user_id(user_id):
    url = f"{base_url}{user_id}"
    response = session.get(url)
    return response

# Iterate over a range of user IDs to check for differences
start_id = 1000
end_id = 1010

for user_id in range(start_id, end_id):
    response = check_user_id(user_id)
    print(f"User ID {user_id} -> HTTP {response.status_code}")
    
    # Basic analysis: Check if the content length varies
    content_length = len(response.content)
    print(f"User ID {user_id} content length: {content_length}")

    # Optional: Save responses for further analysis
    # with open(f"user_{user_id}.html", "wb") as file:
    #     file.write(response.content)

Explanation:


Interpreting Responses and Next Steps

When analyzing your responses, look for:

If you find evidence of an IDOR, you should:

  1. Document the affected endpoints.
  2. Identify the sensitive data or functionality exposed.
  3. Report the findings to the appropriate stakeholders along with reproduction steps.

Mitigation and Best Practices

For developers looking to mitigate IDOR vulnerabilities, consider the following best practices:


Conclusion

IDOR vulnerabilities remain a significant risk for web applications, but with systematic manual testing and proper automation, penetration testers can reliably detect and report these flaws. By combining traditional testing methods with scripting and analysis tools, testers can provide actionable insights into how these vulnerabilities manifest and how they can be mitigated.

In this post, we’ve covered the step-by-step manual process for testing IDOR, showcased practical examples using both curl and Python, and outlined best practices for securing web applications. As you progress in your pentesting journey, remember that attention to detail and methodical testing are your best allies in uncovering hidden security flaws.

Ready to see how Numorian can help your business?

Contact us today to learn more about our services and how we can support your business.