Loading...
Loading...
Bypassing path traversal filters using double URL encoding.
1from flask import Flask, request, send_file2from urllib.parse import unquote3import os45app = Flask(__name__)67@app.route('/download')8def download():9 filename = request.args.get('file', '')1011 # Decode URL encoding12 filename = unquote(filename)1314 # Check for path traversal15 if '..' in filename:16 return "Invalid path", 4001718 filepath = os.path.join('/var/uploads', filename)19 return send_file(filepath)
Double encoding (%252e = %2e after first decode = . after second) bypasses filters that check after only one decode. Always validate the final resolved path.
Encode dots and slashes twice to bypass filters
%252e%252e%252f = ../ (double encoded)
%252e = %2e (after 1st decode) = . (after 2nd)
..%c0%af = ../ (overlong UTF-8)Bypasses filter, accesses /etc/passwd