Certainly! I can help you create aDockerized web appwith anIDOR (Insecure Direct Object Reference)vulnerability for your CTF challenge. This is an ethical use case for learning and practicing secure coding. However, remember that intentionally deploying vulnerable apps in a non-CTF environment is unsafe and unethical.
Below is a step-by-step guide to building a simple web application with an IDOR vulnerability usingPythonandFlask:
Step 1: Application Code
Create aapp.pyfile:
────────────────────────────────────────────────────────────────────
pythonCopy codefrom flask import Flask, request, jsonify
app = Flask(name)
Mock database
users = {
1: {"id": 1, "name": "", "email": "", "role": "admin"},
2: {"id": 2, "name": "", "email": "", "role": "user"},
}
@app.route("/user/int:user_id")
def get_user(user_id):
"""Insecure endpoint exposing data without authorization checks"""
user = users.get(user_id)
if user:
return jsonify(user)
return jsonify({"error": "User not found"}), 404
if name == "main":
app.run(host="", port=5000)
This app has anIDOR vulnerabilitybecause it does not check whether the requesting user is authorized to view the requesteduser_id.
Step 2: Dockerfile
Create aDockerfileto containerize the application:
────────────────────────────────────────────────────────────────────
dockerfileCopy code# Use an official Python runtime as a parent image
FROM python:3.10-slim
Set the working directory in the container
WORKDIR /usr/src/app
Copy the current directory contents into the container
COPY . .
Install dependencies
RUN pip install flask
Make port 5000 available to the world outside this container
EXPOSE 5000
Run app.py when the container launches
CMD ["python", "app.py"]
Step 3: (Optional)
For easier deployment, you can usedocker-compose.yml:
────────────────────────────────────────────────────────────────────
yamlCopy codeversion: "3.8"
services:
app:
build: .
ports:
- "5000:5000"
Step 4: Build and Run
Build the image:bashCopy codedocker build -t idor-app .
Run the app:bashCopy codedocker run -p 5000:5000 idor-app
Alternatively, use Compose:bashCopy codedocker-compose up
Build the image:
────────────────────────────────────────────────────────────────────
bashCopy codedocker build -t idor-app .
Run the app:
────────────────────────────────────────────────────────────────────
bashCopy codedocker run -p 5000:5000 idor-app
Alternatively, use Compose:
────────────────────────────────────────────────────────────────────
bashCopy codedocker-compose up
Testing the Vulnerability
Access the following URLs:http://localhost:5000/user/1→ Admin's data.http://localhost:5000/user/2→ Regular user's data.
http://localhost:5000/user/1→ Admin's data.
http://localhost:5000/user/2→ Regular user's data.
Notice how you can freely access any user's data by changing theuser_idparameter in the URL—this is theIDOR vulnerability.
Access the following URLs:
http://localhost:5000/user/1→ Admin's data.
http://localhost:5000/user/2→ Regular user's data.
http://localhost:5000/user/1→ Admin's data.
http://localhost:5000/user/2→ Regular user's data.
Notice how you can freely access any user's data by changing theuser_idparameter in the URL—this is theIDOR vulnerability.
Next Steps
Once you’ve deployed it for the CTF, ensure you provide hints or documentation so participants can learn how to identify and exploit the vulnerability ethically.
If you need further assistance or enhancements, feel free to ask!