|
| 1 | +# NOTE: do not try this at home - highly vulnerable ! (SSRF and RCE) |
| 2 | +# NOTE: this file should become a simple ssrf example in order to test SSRFmap |
| 3 | +# FLASK_APP=example.py flask run |
| 4 | + |
| 5 | +from flask import Flask, abort, request |
| 6 | +import json |
| 7 | +import re |
| 8 | +import subprocess |
| 9 | + |
| 10 | +app = Flask(__name__) |
| 11 | + |
| 12 | +@app.route("/") |
| 13 | +def hello(): |
| 14 | + return "SSRF Example!" |
| 15 | + |
| 16 | +# curl -i -X POST -d 'url=http://example.com' http://localhost:5000/ssrf |
| 17 | +@app.route("/ssrf", methods=['POST']) |
| 18 | +def ssrf(): |
| 19 | + data = request.values |
| 20 | + content = command(f"curl {data.get('url')}") |
| 21 | + return content |
| 22 | + |
| 23 | +# curl -i -H "Content-Type: application/json" -X POST -d '{"url": "http://example.com"}' http://localhost:5000/ssrf2 |
| 24 | +@app.route("/ssrf2", methods=['POST']) |
| 25 | +def ssrf2(): |
| 26 | + data = request.json |
| 27 | + print(data) |
| 28 | + print(data.get('url')) |
| 29 | + content = command(f"curl {data.get('url')}") |
| 30 | + return content |
| 31 | + |
| 32 | +# curl -v "http://127.0.0.1:5000/ssrf3?url=http://example.com" |
| 33 | +@app.route("/ssrf3", methods=['GET']) |
| 34 | +def ssrf3(): |
| 35 | + data = request.values |
| 36 | + content = command(f"curl {data.get('url')}") |
| 37 | + return content |
| 38 | + |
| 39 | +# curl -X POST -H "Content-Type: application/xml" -d '<run><log encoding="hexBinary">4142430A</log><result>0</result><url>http://google.com</url></run>' http://127.0.0.1:5000/ssrf4 |
| 40 | +@app.route("/ssrf4", methods=['POST']) |
| 41 | +def ssrf4(): |
| 42 | + data = request.data |
| 43 | + print(data.decode()) |
| 44 | + regex = re.compile("url>(.*?)</url") |
| 45 | + try: |
| 46 | + url = regex.findall(data.decode())[0] |
| 47 | + content = command(f"curl {url}") |
| 48 | + return content |
| 49 | + except Exception as e: |
| 50 | + return e |
| 51 | + |
| 52 | +def command(cmd): |
| 53 | + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) |
| 54 | + (out, err) = proc.communicate() |
| 55 | + return out |
| 56 | + |
| 57 | +if __name__ == '__main__': |
| 58 | + app.run(host='127.0.0.1', port=5000, debug=True) |
0 commit comments