Debian Codegraph @

examples/networking/tcp_mon_block/src/web_server.py

raw symbols SCIP
1 from flask import Flask, request
2 import requests
3 import os
4
5 # Forcing requests to use IPV4 addresses only currently
6 requests.packages.urllib3.util.connection.HAS_IPV6 = False
7
8 app = Flask(__name__)
9
10
11 @app.route('/', methods=['GET'])
12 def 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'])
20 def 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
31 if __name__ == '__main__':
32 print(f"Web server running on PID: {str(os.getpid())}")
33 app.run(host="0.0.0.0", port=80)
34