• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from flask import Flask, request
2import requests
3import os
4
5# Forcing requests to use IPV4 addresses only currently
6requests.packages.urllib3.util.connection.HAS_IPV6 = False
7
8app = Flask(__name__)
9
10
11@app.route('/', methods=['GET'])
12def index():
13    return "Hello World!"
14
15
16# A simple route which is vulnerable to SSRF attack.
17# On normal usage, it uses an API service to get the server's public IP, this demonstrates outgoing connections from a web server
18# Extra read: https://portswigger.net/web-security/ssrf
19@app.route('/public_ip', methods=['GET'])
20def public_ip():
21    try:
22        api = request.args["api"]
23    except Exception as e:
24        return "Missing api argument"
25
26    # On expected connection to http://api.ipify.org the output here should be the server's public IP
27    server_ip = requests.get(api).content.decode()
28    return f"Server public IP is: {server_ip}"
29
30
31if __name__ == '__main__':
32    print(f"Web server running on PID: {str(os.getpid())}")
33    app.run(host="0.0.0.0", port=80)
34
35