EH-04: Access Control Basics - Public vs Private Endpoints
Target: Memahami akses kontrol - endpoint mana yang publik dan mana yang privat
Tools:curl
Praktikum
cd ~ && mkdir -p eth-lab4 && cd eth-lab4
cat > server.py << 'PYEOF'
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/')
def home(): return 'Public homepage'
@app.route('/api/public')
def public_api(): return jsonify({"data": "Public data"})
@app.route('/api/admin')
def admin():
auth = request.headers.get('Authorization')
if auth != 'Bearer admin_token':
return jsonify({"error": "Forbidden"}), 403
return jsonify({"flag": "FLAG{Access_Control}"})
@app.route('/api/users')
def users():
auth = request.headers.get('Authorization')
if not auth:
return jsonify({"error": "No auth"}), 401
return jsonify([{"id": 1, "name": "admin", "role": "admin"}])
app.run(port=9002)
PYEOF
python3 server.py &
sleep 1
echo "=== 1. Public (200) ==*"
curl -s http://localhost:9002/api/public
echo ""
echo "=== 2. Admin No Auth (403) ==*"
curl -s http://localhost:9002/api/admin | grep -o 'error.*'
echo ""
echo "=== 3. Admin With Auth (200) ==*"
curl -s -H "Authorization: Bearer admin_token" http://localhost:9002/api/admin | grep -o 'flag{.*}'
echo ""
echo "=== 4. Users No Auth (401) ==*"
curl -s http://localhost:9002/api/users
echo ""
kill %1 2>/dev/null
Refleksi: Setiap endpoint harus punya access control. Jangan asumsikan user tidak akan menemukan endpoint admin. Security by obscurity bukan solusi.
Generated by @farishhz Agent Pentest Pipeline - TDCTF Security Academy